configurable render quality

This commit is contained in:
bancika
2011-02-06 16:01:57 +00:00
parent 99d38feb1c
commit e2b3ed1b0e
13 changed files with 291 additions and 39 deletions
@@ -11,6 +11,7 @@ import java.util.Set;
import org.diylc.core.IDIYComponent;
import org.diylc.core.Project;
import org.diylc.swing.plugins.edit.ComponentTransferable;
import com.diyfever.gui.simplemq.IMessageListener;
import com.diyfever.gui.simplemq.MessageDispatcher;
@@ -29,8 +30,9 @@ import com.diyfever.gui.update.VersionNumber;
* @see EventType
*/
public interface IPlugInPort {
public static final String CHECK_BOX_MENU_ITEM = "org.diylc.checkBoxMenuItem";
public static final String ANTI_ALIASING_KEY = "antiAliasing";
public static final String HI_QUALITY_RENDER_KEY = "hiQualityRender";
/**
* Returns size of the canvas that takes project dimensions into account as
@@ -328,4 +330,9 @@ public interface IPlugInPort {
* Brings each of the selected components one step to front.
*/
void bringSelectionToFront();
/**
* Causes the display to refresh.
*/
void refresh();
}
@@ -21,6 +21,8 @@ public interface IView {
public static final int NO_OPTION = 1;
public static final int CANCEL_OPTION = 2;
public static final int OK_OPTION = 0;
public static final String CHECK_BOX_MENU_ITEM = "org.diylc.checkBoxMenuItem";
void showMessage(String message, String title, int messageType);
@@ -0,0 +1,114 @@
package org.diylc.core;
import java.awt.Color;
import java.io.Serializable;
public class Theme implements Serializable {
private static final long serialVersionUID = 1L;
private String name;
private Color bgColor;
private Color gridColor;
private Color componentBodyColor;
private Color componentBorderColor;
private Color componentLabelColor;
public Theme(String name, Color bgColor, Color gridColor, Color componentBodyColor,
Color componentBorderColor, Color componentLabelColor) {
super();
this.name = name;
this.bgColor = bgColor;
this.gridColor = gridColor;
this.componentBodyColor = componentBodyColor;
this.componentBorderColor = componentBorderColor;
this.componentLabelColor = componentLabelColor;
}
public String getName() {
return name;
}
public Color getBgColor() {
return bgColor;
}
public Color getGridColor() {
return gridColor;
}
public Color getComponentBodyColor() {
return componentBodyColor;
}
public Color getComponentBorderColor() {
return componentBorderColor;
}
public Color getComponentLabelColor() {
return componentLabelColor;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((bgColor == null) ? 0 : bgColor.hashCode());
result = prime * result
+ ((componentBodyColor == null) ? 0 : componentBodyColor.hashCode());
result = prime * result
+ ((componentBorderColor == null) ? 0 : componentBorderColor.hashCode());
result = prime * result
+ ((componentLabelColor == null) ? 0 : componentLabelColor.hashCode());
result = prime * result + ((gridColor == null) ? 0 : gridColor.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Theme other = (Theme) obj;
if (bgColor == null) {
if (other.bgColor != null)
return false;
} else if (!bgColor.equals(other.bgColor))
return false;
if (componentBodyColor == null) {
if (other.componentBodyColor != null)
return false;
} else if (!componentBodyColor.equals(other.componentBodyColor))
return false;
if (componentBorderColor == null) {
if (other.componentBorderColor != null)
return false;
} else if (!componentBorderColor.equals(other.componentBorderColor))
return false;
if (componentLabelColor == null) {
if (other.componentLabelColor != null)
return false;
} else if (!componentLabelColor.equals(other.componentLabelColor))
return false;
if (gridColor == null) {
if (other.gridColor != null)
return false;
} else if (!gridColor.equals(other.gridColor))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
@Override
public String toString() {
return name;
}
}
@@ -21,6 +21,7 @@ import org.diylc.common.DrawOption;
import org.diylc.common.EventType;
import org.diylc.common.GridType;
import org.diylc.common.IComponentFiler;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
@@ -101,19 +102,38 @@ public class DrawingManager {
}
G2DWrapper g2dWrapper = new G2DWrapper(g2d);
if (drawOptions.contains(DrawOption.ANTIALIASING)
&& ConfigurationManager.getInstance().readBoolean(ANTIALIASING_KEY, true)) {
if (drawOptions.contains(DrawOption.ANTIALIASING)) {
g2d
.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
} else {
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_OFF);
}
if (ConfigurationManager.getInstance()
.readBoolean(IPlugInPort.HI_QUALITY_RENDER_KEY, false)) {
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
RenderingHints.VALUE_COLOR_RENDER_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
} else {
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);
g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
RenderingHints.VALUE_COLOR_RENDER_SPEED);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
}
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);
g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
RenderingHints.VALUE_COLOR_RENDER_SPEED);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
double zoom = 1d;
if (drawOptions.contains(DrawOption.ZOOM)) {
@@ -977,6 +977,11 @@ public class Presenter implements IPlugInPort {
messageDispatcher.dispatchMessage(EventType.REPAINT);
}
}
@Override
public void refresh() {
messageDispatcher.dispatchMessage(EventType.REPAINT);
}
/**
* Updates the selection with the specified {@link ComponentTransferable}.
@@ -16,6 +16,7 @@ import org.diylc.common.IPlugInPort;
import org.diylc.common.ITask;
import org.diylc.common.PropertyWrapper;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IView;
import org.diylc.images.IconLoader;
import org.diylc.swing.gui.DialogFactory;
import org.diylc.swing.gui.editor.PropertyEditorDialog;
@@ -28,6 +29,7 @@ import org.diylc.swing.plugins.file.FileFilterEnum;
import com.diyfever.gui.ButtonDialog;
import com.diyfever.gui.IDrawingProvider;
import com.diyfever.gui.export.DrawingExporter;
import com.diyfever.gui.miscutils.ConfigurationManager;
import com.rits.cloning.Cloner;
public class ActionFactory {
@@ -133,6 +135,13 @@ public class ActionFactory {
return new BringToFrontAction(plugInPort);
}
// Config actions.
public ConfigAction createConfigAction(IPlugInPort plugInPort, String title, String configKey,
boolean defaultValue) {
return new ConfigAction(plugInPort, title, configKey, defaultValue);
}
// File menu actions.
public static class NewAction extends AbstractAction {
@@ -789,4 +798,31 @@ public class ActionFactory {
plugInPort.bringSelectionToFront();
}
}
public static class ConfigAction extends AbstractAction {
private static final long serialVersionUID = 1L;
private IPlugInPort plugInPort;
private String configKey;
public ConfigAction(IPlugInPort plugInPort, String title, String configKey,
boolean defaultValue) {
super();
this.plugInPort = plugInPort;
this.configKey = configKey;
putValue(AbstractAction.NAME, title);
putValue(IView.CHECK_BOX_MENU_ITEM, true);
putValue(AbstractAction.SELECTED_KEY, ConfigurationManager.getInstance().readBoolean(
configKey, defaultValue));
}
@Override
public void actionPerformed(ActionEvent e) {
LOG.info(getValue(AbstractAction.NAME) + " triggered");
ConfigurationManager.getInstance().writeValue(configKey,
getValue(AbstractAction.SELECTED_KEY));
plugInPort.refresh();
}
}
}
@@ -33,10 +33,12 @@ import org.diylc.common.EventType;
import org.diylc.common.IPlugIn;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ITask;
import org.diylc.core.IView;
import org.diylc.images.IconLoader;
import org.diylc.presenter.Presenter;
import org.diylc.swing.ISwingUI;
import org.diylc.swing.plugins.canvas.CanvasPlugin;
import org.diylc.swing.plugins.config.ConfigPlugin;
import org.diylc.swing.plugins.edit.EditMenuPlugin;
import org.diylc.swing.plugins.file.FileMenuPlugin;
import org.diylc.swing.plugins.help.HelpMenuPlugin;
@@ -78,6 +80,7 @@ public class MainFrame extends JFrame implements ISwingUI {
presenter.installPlugin(new ToolBox(this));
presenter.installPlugin(new FileMenuPlugin(this));
presenter.installPlugin(new EditMenuPlugin(this));
presenter.installPlugin(new ConfigPlugin(this));
presenter.installPlugin(new LayersMenuPlugin(this));
// presenter.installPlugin(new OnlineManager());
presenter.installPlugin(new HelpMenuPlugin(this));
@@ -113,7 +116,7 @@ public class MainFrame extends JFrame implements ISwingUI {
// setGlassPane(new CustomGlassPane());
// getGlassPane().setVisible(true);
}
public Presenter getPresenter() {
return presenter;
}
@@ -235,7 +238,7 @@ public class MainFrame extends JFrame implements ISwingUI {
if (action == null) {
menu.addSeparator();
} else {
Boolean isCheckBox = (Boolean) action.getValue(IPlugInPort.CHECK_BOX_MENU_ITEM);
Boolean isCheckBox = (Boolean) action.getValue(IView.CHECK_BOX_MENU_ITEM);
if (isCheckBox != null && isCheckBox) {
menu.add(new JCheckBoxMenuItem(action));
} else {
@@ -34,6 +34,7 @@ import org.diylc.swing.gui.DialogFactory;
import org.diylc.swing.gui.editor.PropertyEditorDialog;
import com.diyfever.gui.ButtonDialog;
import com.diyfever.gui.miscutils.ConfigurationManager;
/**
* GUI class used to draw onto.
@@ -52,6 +53,8 @@ class CanvasPanel extends JComponent implements Autoscroll {
private static boolean USE_HARDWARE_ACCELLERATION = false;
static final EnumSet<DrawOption> DRAW_OPTIONS = EnumSet.of(DrawOption.GRID,
DrawOption.SELECTION, DrawOption.ZOOM, DrawOption.CONTROL_POINTS);
static final EnumSet<DrawOption> DRAW_OPTIONS_ANTI_ALIASING = EnumSet.of(DrawOption.GRID,
DrawOption.SELECTION, DrawOption.ZOOM, DrawOption.ANTIALIASING,
DrawOption.CONTROL_POINTS);
@@ -75,7 +78,8 @@ class CanvasPanel extends JComponent implements Autoscroll {
private void initializeDnD() {
// Initialize drag source recognizer.
DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(this,
DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK, new CanvasGestureListener(plugInPort));
DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK,
new CanvasGestureListener(plugInPort));
// Initialize drop target.
new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE,
new CanvasTargetListener(plugInPort), true);
@@ -104,7 +108,9 @@ class CanvasPanel extends JComponent implements Autoscroll {
bufferImage = createImage(getWidth(), getHeight());
}
Graphics2D g2d = (Graphics2D) bufferImage.getGraphics();
plugInPort.draw(g2d, DRAW_OPTIONS, null);
plugInPort.draw(g2d, ConfigurationManager.getInstance().readBoolean(
IPlugInPort.ANTI_ALIASING_KEY, true) ? DRAW_OPTIONS_ANTI_ALIASING : DRAW_OPTIONS,
null);
}
@Override
@@ -116,7 +122,9 @@ class CanvasPanel extends JComponent implements Autoscroll {
createBufferImage();
} else {
Graphics2D g2d = (Graphics2D) bufferImage.getGraphics();
plugInPort.draw(g2d, DRAW_OPTIONS, null);
plugInPort.draw(g2d, ConfigurationManager.getInstance().readBoolean(
IPlugInPort.ANTI_ALIASING_KEY, true) ? DRAW_OPTIONS_ANTI_ALIASING
: DRAW_OPTIONS, null);
}
if (USE_HARDWARE_ACCELLERATION) {
VolatileImage volatileImage = (VolatileImage) bufferImage;
@@ -125,10 +133,11 @@ class CanvasPanel extends JComponent implements Autoscroll {
if (volatileImage.contentsLost()) {
createBufferImage();
}
// int validation = volatileImage.validate(screenGraphicsConfiguration);
// if (validation == VolatileImage.IMAGE_INCOMPATIBLE) {
// createBufferImage();
// }
// int validation =
// volatileImage.validate(screenGraphicsConfiguration);
// if (validation == VolatileImage.IMAGE_INCOMPATIBLE) {
// createBufferImage();
// }
g.drawImage(bufferImage, 0, 0, this);
} catch (NullPointerException e) {
createBufferImage();
@@ -136,7 +145,7 @@ class CanvasPanel extends JComponent implements Autoscroll {
} while (volatileImage == null || volatileImage.contentsLost());
} else {
g.drawImage(bufferImage, 0, 0, this);
// bufferImage.flush();
// bufferImage.flush();
}
}
@@ -154,18 +163,18 @@ class CanvasPanel extends JComponent implements Autoscroll {
invalidate();
}
});
// addKeyListener(new KeyAdapter() {
//
// @Override
// public void keyPressed(KeyEvent e) {
// if (e.getKeyCode() == KeyEvent.VK_DELETE) {
// plugInPort.deleteSelectedComponents();
// }
// // plugInPort.mouseMoved(getMousePosition(), e.isControlDown(),
// // e.isShiftDown(), e
// // .isAltDown());
// }
// });
// addKeyListener(new KeyAdapter() {
//
// @Override
// public void keyPressed(KeyEvent e) {
// if (e.getKeyCode() == KeyEvent.VK_DELETE) {
// plugInPort.deleteSelectedComponents();
// }
// // plugInPort.mouseMoved(getMousePosition(), e.isControlDown(),
// // e.isShiftDown(), e
// // .isAltDown());
// }
// });
addMouseMotionListener(new MouseAdapter() {
@Override
@@ -217,8 +226,8 @@ class CanvasPanel extends JComponent implements Autoscroll {
// Save default values.
for (PropertyWrapper property : editor.getDefaultedProperties()) {
if (property.getValue() != null) {
plugInPort.setSelectionDefaultPropertyValue(property.getName(),
property.getValue());
plugInPort.setSelectionDefaultPropertyValue(property
.getName(), property.getValue());
}
}
}
@@ -0,0 +1,43 @@
package org.diylc.swing.plugins.config;
import java.util.EnumSet;
import org.diylc.common.EventType;
import org.diylc.common.IPlugIn;
import org.diylc.common.IPlugInPort;
import org.diylc.swing.ActionFactory;
import org.diylc.swing.ISwingUI;
/**
* Controls configuration menu.
*
* @author Branislav Stojkovic
*/
public class ConfigPlugin implements IPlugIn {
private static final String CONFIG_MENU = "Config";
private ISwingUI swingUI;
public ConfigPlugin(ISwingUI swingUI) {
super();
this.swingUI = swingUI;
}
@Override
public void connect(IPlugInPort plugInPort) {
swingUI.injectMenuAction(ActionFactory.getInstance().createConfigAction(plugInPort,
"Anti-Aliasing", IPlugInPort.ANTI_ALIASING_KEY, true), CONFIG_MENU);
swingUI.injectMenuAction(ActionFactory.getInstance().createConfigAction(plugInPort,
"Hi-Quality Rendering", IPlugInPort.HI_QUALITY_RENDER_KEY, false), CONFIG_MENU);
}
@Override
public EnumSet<EventType> getSubscribedEventTypes() {
return EnumSet.noneOf(EventType.class);
}
@Override
public void processMessage(EventType eventType, Object... params) {
}
}
@@ -13,6 +13,7 @@ import org.diylc.common.EventType;
import org.diylc.common.IPlugIn;
import org.diylc.common.IPlugInPort;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IView;
import org.diylc.swing.ISwingUI;
public class LayersMenuPlugin implements IPlugIn {
@@ -36,7 +37,7 @@ public class LayersMenuPlugin implements IPlugIn {
(Boolean) getValue(Action.SELECTED_KEY));
}
};
action.putValue(IPlugInPort.CHECK_BOX_MENU_ITEM, true);
action.putValue(IView.CHECK_BOX_MENU_ITEM, true);
lockActionMap.put(layer, action);
swingUI.injectMenuAction(action, LOCK_LAYERS_TITLE);
}