mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Loadline work
This commit is contained in:
Binary file not shown.
@@ -64,5 +64,9 @@ public enum DrawOption {
|
||||
/**
|
||||
* Whether components should be cached or not.
|
||||
*/
|
||||
ENABLE_CACHING;
|
||||
ENABLE_CACHING,
|
||||
/**
|
||||
* Whether locked components should be rendered as transparent or not.
|
||||
*/
|
||||
LOCKED_ALPHA;
|
||||
}
|
||||
|
||||
@@ -92,6 +92,8 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
|
||||
public static final String SNAP_TO_COMPONENTS = "Components";
|
||||
public static final String SNAP_TO_DEFAULT = SNAP_TO_GRID;
|
||||
|
||||
public static final String LOCKED_ALPHA = "lockedAlpha";
|
||||
|
||||
public static final String LANGUAGE = "language";
|
||||
public static final String LANGUAGE_DEFAULT = "English";
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.IConfigurationManager;
|
||||
import org.diylc.appframework.simplemq.MessageDispatcher;
|
||||
import org.diylc.common.DrawOption;
|
||||
import org.diylc.common.EventType;
|
||||
@@ -79,8 +79,7 @@ public class DrawingManager {
|
||||
public static Color CONTROL_POINT_COLOR = Color.blue;
|
||||
public static Color SELECTED_CONTROL_POINT_COLOR = Color.green;
|
||||
|
||||
private Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY,
|
||||
Constants.DEFAULT_THEME);
|
||||
private Theme theme;
|
||||
|
||||
// Maps keyed by object reference.
|
||||
// Keeps Area object of each drawn component.
|
||||
@@ -96,7 +95,7 @@ public class DrawingManager {
|
||||
private Composite lockedComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
|
||||
private List<IDIYComponent<?>> failedComponents = new ArrayList<IDIYComponent<?>>();
|
||||
|
||||
private double zoomLevel = 1d;// ConfigurationManager.getInstance().readDouble(ZOOM_KEY,
|
||||
private double zoomLevel = 1d;// configManager.readDouble(ZOOM_KEY,
|
||||
// 1d);
|
||||
|
||||
private MessageDispatcher<EventType> messageDispatcher;
|
||||
@@ -110,9 +109,16 @@ public class DrawingManager {
|
||||
private long statReportFrequencyMs = 1000 * 60;
|
||||
private Counter totalStats = new Counter();
|
||||
|
||||
public DrawingManager(MessageDispatcher<EventType> messageDispatcher) {
|
||||
private IConfigurationManager configManager;
|
||||
|
||||
public DrawingManager(MessageDispatcher<EventType> messageDispatcher, IConfigurationManager configManager) {
|
||||
super();
|
||||
this.messageDispatcher = messageDispatcher;
|
||||
this.configManager = configManager;
|
||||
|
||||
this.theme = (Theme) configManager.readObject(IPlugInPort.THEME_KEY,
|
||||
Constants.DEFAULT_THEME);
|
||||
|
||||
componentAreaMap = new HashMap<IDIYComponent<?>, ComponentArea>();
|
||||
lastDrawnStateMap = new HashMap<IDIYComponent<?>, ComponentState>();
|
||||
String debugComponentAreasStr = System.getProperty(DEBUG_COMPONENT_AREAS);
|
||||
@@ -169,7 +175,7 @@ public class DrawingManager {
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
|
||||
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
|
||||
}
|
||||
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.HI_QUALITY_RENDER_KEY, false)) {
|
||||
if (configManager.readBoolean(IPlugInPort.HI_QUALITY_RENDER_KEY, false)) {
|
||||
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);
|
||||
@@ -299,7 +305,7 @@ public class DrawingManager {
|
||||
}
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
// Draw locked components in a new composite.
|
||||
if (lockedComponents.contains(component)) {
|
||||
if (lockedComponents.contains(component) && drawOptions.contains(DrawOption.LOCKED_ALPHA)) {
|
||||
g2d.setComposite(lockedComposite);
|
||||
}
|
||||
// Draw the component through the g2dWrapper.
|
||||
@@ -456,7 +462,7 @@ public class DrawingManager {
|
||||
}
|
||||
|
||||
if (currentContinuityArea != null
|
||||
&& (ConfigurationManager.getInstance().readBoolean(IPlugInPort.HIGHLIGHT_CONTINUITY_AREA, false))) {
|
||||
&& (configManager.readBoolean(IPlugInPort.HIGHLIGHT_CONTINUITY_AREA, false))) {
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
|
||||
g2d.setColor(Color.green);
|
||||
@@ -503,7 +509,7 @@ public class DrawingManager {
|
||||
public void setZoomLevel(double zoomLevel) {
|
||||
this.zoomLevel = zoomLevel;
|
||||
fireZoomChanged();
|
||||
// ConfigurationManager.getInstance().writeValue(ZOOM_KEY, zoomLevel);
|
||||
// configManager.writeValue(ZOOM_KEY, zoomLevel);
|
||||
}
|
||||
|
||||
public void invalidateComponent(IDIYComponent<?> component) {
|
||||
@@ -570,7 +576,7 @@ public class DrawingManager {
|
||||
|
||||
public void setTheme(Theme theme) {
|
||||
this.theme = theme;
|
||||
ConfigurationManager.getInstance().writeValue(IPlugInPort.THEME_KEY, theme);
|
||||
configManager.writeValue(IPlugInPort.THEME_KEY, theme);
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ import javax.swing.JOptionPane;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.IConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.JarScanner;
|
||||
import org.diylc.appframework.miscutils.Utils;
|
||||
import org.diylc.appframework.simplemq.MessageDispatcher;
|
||||
@@ -191,6 +192,7 @@ public class Presenter implements IPlugInPort {
|
||||
private Rectangle selectionRect;
|
||||
|
||||
private final IView view;
|
||||
private IConfigurationManager configManager;
|
||||
|
||||
private MessageDispatcher<EventType> messageDispatcher;
|
||||
|
||||
@@ -208,16 +210,17 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
private DIYTest test = null;
|
||||
|
||||
public Presenter(IView view) {
|
||||
public Presenter(IView view, IConfigurationManager configManager) {
|
||||
super();
|
||||
this.view = view;
|
||||
this.configManager = configManager;
|
||||
plugIns = new ArrayList<IPlugIn>();
|
||||
messageDispatcher = new MessageDispatcher<EventType>(true);
|
||||
selectedComponents = new HashSet<IDIYComponent<?>>();
|
||||
lockedComponents = new HashSet<IDIYComponent<?>>();
|
||||
currentProject = new Project();
|
||||
// cloner = new Cloner();
|
||||
drawingManager = new DrawingManager(messageDispatcher);
|
||||
drawingManager = new DrawingManager(messageDispatcher, configManager);
|
||||
projectFileManager = new ProjectFileManager(messageDispatcher);
|
||||
instantiationManager = new InstantiationManager();
|
||||
|
||||
@@ -265,7 +268,7 @@ public class Presenter implements IPlugInPort {
|
||||
@Override
|
||||
public Cursor getCursorAt(Point point) {
|
||||
// Only change the cursor if we're not making a new component.
|
||||
if (ConfigurationManager.getInstance().readBoolean(HIGHLIGHT_CONTINUITY_AREA, false))
|
||||
if (configManager.readBoolean(HIGHLIGHT_CONTINUITY_AREA, false))
|
||||
return Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);
|
||||
if (instantiationManager.getComponentTypeSlot() == null) {
|
||||
// Scale point to remove zoom factor.
|
||||
@@ -275,7 +278,7 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
for (IDIYComponent<?> component : currentProject.getComponents()) {
|
||||
if (!isComponentLocked(component) && isComponentVisible(component)
|
||||
&& !ConfigurationManager.getInstance().readBoolean(HIGHLIGHT_CONTINUITY_AREA, false)) {
|
||||
&& !configManager.readBoolean(HIGHLIGHT_CONTINUITY_AREA, false)) {
|
||||
ComponentArea area = drawingManager.getComponentArea(component);
|
||||
if (area != null && area.getOutlineArea() != null && area.getOutlineArea().contains(scaledPoint)) {
|
||||
return Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
|
||||
@@ -361,14 +364,14 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void addToRecentFiles(String fileName) {
|
||||
List<String> recentFiles = (List<String>) ConfigurationManager.getInstance().readObject(RECENT_FILES_KEY, null);
|
||||
List<String> recentFiles = (List<String>) configManager.readObject(RECENT_FILES_KEY, null);
|
||||
if (recentFiles == null)
|
||||
recentFiles = new ArrayList<String>();
|
||||
recentFiles.remove(fileName);
|
||||
recentFiles.add(0, fileName);
|
||||
while (recentFiles.size() > MAX_RECENT_FILES)
|
||||
recentFiles.remove(recentFiles.size() - 1);
|
||||
ConfigurationManager.getInstance().writeValue(RECENT_FILES_KEY, recentFiles);
|
||||
configManager.writeValue(RECENT_FILES_KEY, recentFiles);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -640,10 +643,10 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
|
||||
if (componentTypeSlot.isAutoEdit()
|
||||
&& ConfigurationManager.getInstance().readBoolean(IPlugInPort.AUTO_EDIT_KEY, false)) {
|
||||
&& configManager.readBoolean(IPlugInPort.AUTO_EDIT_KEY, false)) {
|
||||
editSelection();
|
||||
}
|
||||
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.CONTINUOUS_CREATION_KEY, false)) {
|
||||
if (configManager.readBoolean(IPlugInPort.CONTINUOUS_CREATION_KEY, false)) {
|
||||
setNewComponentTypeSlot(componentTypeSlot, template, false);
|
||||
} else {
|
||||
setNewComponentTypeSlot(null, null, false);
|
||||
@@ -681,7 +684,7 @@ public class Presenter implements IPlugInPort {
|
||||
drawingManager.clearContinuityArea();
|
||||
projectFileManager.notifyFileChange();
|
||||
}
|
||||
} else if (ConfigurationManager.getInstance().readBoolean(HIGHLIGHT_CONTINUITY_AREA, false)) {
|
||||
} else if (configManager.readBoolean(HIGHLIGHT_CONTINUITY_AREA, false)) {
|
||||
drawingManager.findContinuityAreaAtPoint(currentProject, scaledPoint);
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
} else {
|
||||
@@ -742,10 +745,10 @@ public class Presenter implements IPlugInPort {
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
|
||||
if (componentTypeSlot.isAutoEdit()
|
||||
&& ConfigurationManager.getInstance().readBoolean(IPlugInPort.AUTO_EDIT_KEY, false)) {
|
||||
&& configManager.readBoolean(IPlugInPort.AUTO_EDIT_KEY, false)) {
|
||||
editSelection();
|
||||
}
|
||||
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.CONTINUOUS_CREATION_KEY, false)) {
|
||||
if (configManager.readBoolean(IPlugInPort.CONTINUOUS_CREATION_KEY, false)) {
|
||||
setNewComponentTypeSlot(componentTypeSlot, template, false);
|
||||
} else {
|
||||
setNewComponentTypeSlot(null, null, false);
|
||||
@@ -776,7 +779,7 @@ public class Presenter implements IPlugInPort {
|
||||
return false;
|
||||
}
|
||||
|
||||
String snapTo = ConfigurationManager.getInstance().readString(IPlugInPort.SNAP_TO_KEY, IPlugInPort.SNAP_TO_DEFAULT);
|
||||
String snapTo = configManager.readString(IPlugInPort.SNAP_TO_KEY, IPlugInPort.SNAP_TO_DEFAULT);
|
||||
if (shiftDown) {
|
||||
snapTo = IPlugInPort.SNAP_TO_NONE;
|
||||
}
|
||||
@@ -807,7 +810,7 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
|
||||
// Expand control points to include all stuck components.
|
||||
boolean sticky = ConfigurationManager.getInstance().readBoolean(IPlugInPort.STICKY_POINTS_KEY, true);
|
||||
boolean sticky = configManager.readBoolean(IPlugInPort.STICKY_POINTS_KEY, true);
|
||||
if (ctrlDown) {
|
||||
sticky = !sticky;
|
||||
}
|
||||
@@ -1010,7 +1013,7 @@ public class Presenter implements IPlugInPort {
|
||||
LOG.debug("Area is null for " + c.getName() + " of type " + c.getClass().getName());
|
||||
}
|
||||
|
||||
if (ConfigurationManager.getInstance().readBoolean(EXTRA_SPACE_KEY, true)) {
|
||||
if (configManager.readBoolean(EXTRA_SPACE_KEY, true)) {
|
||||
double extraSpace = drawingManager.getExtraSpace(currentProject);
|
||||
minX += extraSpace;
|
||||
maxX += extraSpace;
|
||||
@@ -1110,7 +1113,7 @@ public class Presenter implements IPlugInPort {
|
||||
dragAction == DnDConstants.ACTION_LINK, dragAction == DnDConstants.ACTION_MOVE, 1);
|
||||
return;
|
||||
}
|
||||
if (ConfigurationManager.getInstance().readBoolean(HIGHLIGHT_CONTINUITY_AREA, false)) {
|
||||
if (configManager.readBoolean(HIGHLIGHT_CONTINUITY_AREA, false)) {
|
||||
LOG.debug("Cannot start drag in hightlight continuity mode.");
|
||||
return;
|
||||
}
|
||||
@@ -1162,7 +1165,7 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
}
|
||||
// Expand control points to include all stuck components.
|
||||
boolean sticky = ConfigurationManager.getInstance().readBoolean(IPlugInPort.STICKY_POINTS_KEY, true);
|
||||
boolean sticky = configManager.readBoolean(IPlugInPort.STICKY_POINTS_KEY, true);
|
||||
if (this.dragAction == IPlugInPort.DND_TOGGLE_STICKY) {
|
||||
sticky = !sticky;
|
||||
}
|
||||
@@ -1247,14 +1250,14 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
|
||||
private boolean isSnapToGrid() {
|
||||
String snapTo = ConfigurationManager.getInstance().readString(IPlugInPort.SNAP_TO_KEY, IPlugInPort.SNAP_TO_DEFAULT);
|
||||
String snapTo = configManager.readString(IPlugInPort.SNAP_TO_KEY, IPlugInPort.SNAP_TO_DEFAULT);
|
||||
if (this.dragAction == IPlugInPort.DND_TOGGLE_SNAP)
|
||||
return false;
|
||||
return snapTo.equalsIgnoreCase(IPlugInPort.SNAP_TO_GRID);
|
||||
}
|
||||
|
||||
private boolean isSnapToObjects() {
|
||||
String snapTo = ConfigurationManager.getInstance().readString(IPlugInPort.SNAP_TO_KEY, IPlugInPort.SNAP_TO_DEFAULT);
|
||||
String snapTo = configManager.readString(IPlugInPort.SNAP_TO_KEY, IPlugInPort.SNAP_TO_DEFAULT);
|
||||
if (this.dragAction == IPlugInPort.DND_TOGGLE_SNAP)
|
||||
return false;
|
||||
return snapTo.equalsIgnoreCase(IPlugInPort.SNAP_TO_COMPONENTS);
|
||||
@@ -1269,7 +1272,7 @@ public class Presenter implements IPlugInPort {
|
||||
test.addStep(DIYTest.DRAG_OVER, params);
|
||||
}
|
||||
|
||||
if (point == null || ConfigurationManager.getInstance().readBoolean(HIGHLIGHT_CONTINUITY_AREA, false)) {
|
||||
if (point == null || configManager.readBoolean(HIGHLIGHT_CONTINUITY_AREA, false)) {
|
||||
return false;
|
||||
}
|
||||
Point scaledPoint = scalePoint(point);
|
||||
@@ -1310,7 +1313,7 @@ public class Presenter implements IPlugInPort {
|
||||
// For each component, do a simulation of the move to see if any of
|
||||
// them will overlap or go out of bounds.
|
||||
|
||||
boolean useExtraSpace = ConfigurationManager.getInstance().readBoolean(EXTRA_SPACE_KEY, true);
|
||||
boolean useExtraSpace = configManager.readBoolean(EXTRA_SPACE_KEY, true);
|
||||
Dimension d = drawingManager.getCanvasDimensions(currentProject, 1d, useExtraSpace);
|
||||
double extraSpace = useExtraSpace ? drawingManager.getExtraSpace(currentProject) : 0;
|
||||
|
||||
@@ -1620,7 +1623,7 @@ public class Presenter implements IPlugInPort {
|
||||
this.selectionRect = Utils.createRectangle(scaledPoint, previousDragPoint);
|
||||
}
|
||||
List<IDIYComponent<?>> newSelection = new ArrayList<IDIYComponent<?>>();
|
||||
if (!ConfigurationManager.getInstance().readBoolean(HIGHLIGHT_CONTINUITY_AREA, false))
|
||||
if (!configManager.readBoolean(HIGHLIGHT_CONTINUITY_AREA, false))
|
||||
for (IDIYComponent<?> component : currentProject.getComponents()) {
|
||||
if (!isComponentLocked(component) && isComponentVisible(component)) {
|
||||
ComponentArea area = drawingManager.getComponentArea(component);
|
||||
@@ -1731,7 +1734,7 @@ public class Presenter implements IPlugInPort {
|
||||
for (IDIYComponent<?> component : selectedComponents) {
|
||||
String className = component.getClass().getName();
|
||||
LOG.debug("Default property value set for " + className + ":" + propertyName);
|
||||
ConfigurationManager.getInstance().writeValue(DEFAULTS_KEY_PREFIX + className + ":" + propertyName, value);
|
||||
configManager.writeValue(DEFAULTS_KEY_PREFIX + className + ":" + propertyName, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1739,12 +1742,12 @@ public class Presenter implements IPlugInPort {
|
||||
public void setDefaultPropertyValue(Class<?> clazz, String propertyName, Object value) {
|
||||
LOG.info(String.format("setProjectDefaultPropertyValue(%s, %s, %s)", clazz.getName(), propertyName, value));
|
||||
LOG.debug("Default property value set for " + Project.class.getName() + ":" + propertyName);
|
||||
ConfigurationManager.getInstance().writeValue(DEFAULTS_KEY_PREFIX + clazz.getName() + ":" + propertyName, value);
|
||||
configManager.writeValue(DEFAULTS_KEY_PREFIX + clazz.getName() + ":" + propertyName, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMetric(boolean isMetric) {
|
||||
ConfigurationManager.getInstance().writeValue(Presenter.METRIC_KEY, isMetric);
|
||||
configManager.writeValue(Presenter.METRIC_KEY, isMetric);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2023,7 +2026,7 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
controlPointMap.put(component, indices);
|
||||
}
|
||||
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.STICKY_POINTS_KEY, true)) {
|
||||
if (configManager.readBoolean(IPlugInPort.STICKY_POINTS_KEY, true)) {
|
||||
includeStuckComponents(controlPointMap);
|
||||
}
|
||||
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents, controlPointMap.keySet());
|
||||
@@ -2472,7 +2475,7 @@ public class Presenter implements IPlugInPort {
|
||||
ComponentProcessor.getInstance().extractComponentTypeFrom(
|
||||
(Class<? extends IDIYComponent<?>>) component.getClass());
|
||||
Map<String, List<Template>> variantMap =
|
||||
(Map<String, List<Template>>) ConfigurationManager.getInstance().readObject(TEMPLATES_KEY, null);
|
||||
(Map<String, List<Template>>) configManager.readObject(TEMPLATES_KEY, null);
|
||||
if (variantMap == null) {
|
||||
variantMap = new HashMap<String, List<Template>>();
|
||||
}
|
||||
@@ -2550,20 +2553,20 @@ public class Presenter implements IPlugInPort {
|
||||
xStream.toXML(defaultVariantMap, out);
|
||||
out.close();
|
||||
// no more user variants
|
||||
ConfigurationManager.getInstance().writeValue(TEMPLATES_KEY, null);
|
||||
configManager.writeValue(TEMPLATES_KEY, null);
|
||||
LOG.info("Saved default variants");
|
||||
} catch (IOException e) {
|
||||
LOG.error("Could not save default variants", e);
|
||||
}
|
||||
} else {
|
||||
ConfigurationManager.getInstance().writeValue(TEMPLATES_KEY, variantMap);
|
||||
configManager.writeValue(TEMPLATES_KEY, variantMap);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void importDefaultVariants() {
|
||||
// import default templates from variants.xml file only if we didn't do it already
|
||||
if (!ConfigurationManager.getInstance().readBoolean(DEFAULT_TEMPLATES_IMPORTED_KEY, false)) {
|
||||
if (!configManager.readBoolean(DEFAULT_TEMPLATES_IMPORTED_KEY, false)) {
|
||||
try {
|
||||
URL resource = Presenter.class.getResource("variants.xml");
|
||||
if (resource != null) {
|
||||
@@ -2573,7 +2576,7 @@ public class Presenter implements IPlugInPort {
|
||||
in.close();
|
||||
|
||||
Map<String, List<Template>> variantMap =
|
||||
(Map<String, List<Template>>) ConfigurationManager.getInstance().readObject(TEMPLATES_KEY, null);
|
||||
(Map<String, List<Template>>) configManager.readObject(TEMPLATES_KEY, null);
|
||||
if (variantMap == null)
|
||||
variantMap = new HashMap<String, List<Template>>();
|
||||
|
||||
@@ -2588,8 +2591,8 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
|
||||
// update templates and a flag marking that we imported them
|
||||
ConfigurationManager.getInstance().writeValue(DEFAULT_TEMPLATES_IMPORTED_KEY, true);
|
||||
ConfigurationManager.getInstance().writeValue(TEMPLATES_KEY, variantMap);
|
||||
configManager.writeValue(DEFAULT_TEMPLATES_IMPORTED_KEY, true);
|
||||
configManager.writeValue(TEMPLATES_KEY, variantMap);
|
||||
LOG.info(String.format("Imported default variants for %d components",
|
||||
defaults == null ? 0 : defaults.size()));
|
||||
}
|
||||
@@ -2602,7 +2605,7 @@ public class Presenter implements IPlugInPort {
|
||||
@SuppressWarnings("unchecked")
|
||||
private void importDefaultBlocks() {
|
||||
// import default templates from variants.xml file only if we didn't do it already
|
||||
if (!ConfigurationManager.getInstance().readBoolean(DEFAULT_BLOCKS_IMPORTED_KEY, false)) {
|
||||
if (!configManager.readBoolean(DEFAULT_BLOCKS_IMPORTED_KEY, false)) {
|
||||
try {
|
||||
URL resource = Presenter.class.getResource("blocks.xml");
|
||||
if (resource != null) {
|
||||
@@ -2612,7 +2615,7 @@ public class Presenter implements IPlugInPort {
|
||||
in.close();
|
||||
|
||||
Map<String, List<IDIYComponent<?>>> blocksMap =
|
||||
(Map<String, List<IDIYComponent<?>>>) ConfigurationManager.getInstance().readObject(BLOCKS_KEY, null);
|
||||
(Map<String, List<IDIYComponent<?>>>) configManager.readObject(BLOCKS_KEY, null);
|
||||
if (blocksMap == null)
|
||||
blocksMap = new HashMap<String, List<IDIYComponent<?>>>();
|
||||
|
||||
@@ -2623,8 +2626,8 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
|
||||
// update templates and a flag marking that we imported them
|
||||
ConfigurationManager.getInstance().writeValue(DEFAULT_BLOCKS_IMPORTED_KEY, true);
|
||||
ConfigurationManager.getInstance().writeValue(BLOCKS_KEY, blocksMap);
|
||||
configManager.writeValue(DEFAULT_BLOCKS_IMPORTED_KEY, true);
|
||||
configManager.writeValue(BLOCKS_KEY, blocksMap);
|
||||
LOG.info(String.format("Imported %d default building blocks", defaults == null ? 0 : defaults.size()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -2639,7 +2642,7 @@ public class Presenter implements IPlugInPort {
|
||||
Map<String, List<Template>> lookupMap = new TreeMap<String, List<Template>>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
Map<String, List<Template>> variantMap =
|
||||
(Map<String, List<Template>>) ConfigurationManager.getInstance().readObject(TEMPLATES_KEY, null);
|
||||
(Map<String, List<Template>>) configManager.readObject(TEMPLATES_KEY, null);
|
||||
if (variantMap != null)
|
||||
lookupMap.putAll(variantMap);
|
||||
|
||||
@@ -2717,7 +2720,7 @@ public class Presenter implements IPlugInPort {
|
||||
public void deleteVariant(ComponentType type, String templateName) {
|
||||
LOG.debug(String.format("deleteTemplate(%s, %s)", type, templateName));
|
||||
Map<String, List<Template>> templateMap =
|
||||
(Map<String, List<Template>>) ConfigurationManager.getInstance().readObject(TEMPLATES_KEY, null);
|
||||
(Map<String, List<Template>>) configManager.readObject(TEMPLATES_KEY, null);
|
||||
if (templateMap != null) {
|
||||
// try by class name and then by old category.type format
|
||||
String key1 = type.getInstanceClass().getCanonicalName();
|
||||
@@ -2744,7 +2747,7 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
}
|
||||
}
|
||||
ConfigurationManager.getInstance().writeValue(TEMPLATES_KEY, templateMap);
|
||||
configManager.writeValue(TEMPLATES_KEY, templateMap);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -2752,7 +2755,7 @@ public class Presenter implements IPlugInPort {
|
||||
public void setDefaultVariant(ComponentType type, String templateName) {
|
||||
LOG.debug(String.format("setTemplateDefault(%s, %s)", type, templateName));
|
||||
Map<String, String> defaultTemplateMap =
|
||||
(Map<String, String>) ConfigurationManager.getInstance().readObject(DEFAULT_TEMPLATES_KEY, null);
|
||||
(Map<String, String>) configManager.readObject(DEFAULT_TEMPLATES_KEY, null);
|
||||
if (defaultTemplateMap == null)
|
||||
defaultTemplateMap = new HashMap<String, String>();
|
||||
|
||||
@@ -2768,14 +2771,14 @@ public class Presenter implements IPlugInPort {
|
||||
defaultTemplateMap.remove(key2);
|
||||
defaultTemplateMap.put(key1, templateName);
|
||||
}
|
||||
ConfigurationManager.getInstance().writeValue(DEFAULT_TEMPLATES_KEY, defaultTemplateMap);
|
||||
configManager.writeValue(DEFAULT_TEMPLATES_KEY, defaultTemplateMap);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public String getDefaultVariant(ComponentType type) {
|
||||
Map<String, String> defaultTemplateMap =
|
||||
(Map<String, String>) ConfigurationManager.getInstance().readObject(DEFAULT_TEMPLATES_KEY, null);
|
||||
(Map<String, String>) configManager.readObject(DEFAULT_TEMPLATES_KEY, null);
|
||||
if (defaultTemplateMap == null)
|
||||
return null;
|
||||
|
||||
@@ -2849,7 +2852,7 @@ public class Presenter implements IPlugInPort {
|
||||
point == null ? null : new Point((int) (point.x / drawingManager.getZoomLevel()),
|
||||
(int) (point.y / drawingManager.getZoomLevel()));
|
||||
|
||||
if (p != null && ConfigurationManager.getInstance().readBoolean(EXTRA_SPACE_KEY, true)) {
|
||||
if (p != null && configManager.readBoolean(EXTRA_SPACE_KEY, true)) {
|
||||
double extraSpace = drawingManager.getExtraSpace(currentProject);
|
||||
p.translate((int) (-extraSpace), (int) (-extraSpace));
|
||||
}
|
||||
@@ -2861,7 +2864,7 @@ public class Presenter implements IPlugInPort {
|
||||
public void saveSelectionAsBlock(String blockName) {
|
||||
LOG.debug(String.format("saveSelectionAsBlock(%s)", blockName));
|
||||
Map<String, List<IDIYComponent<?>>> blocks =
|
||||
(Map<String, List<IDIYComponent<?>>>) ConfigurationManager.getInstance().readObject(BLOCKS_KEY, null);
|
||||
(Map<String, List<IDIYComponent<?>>>) configManager.readObject(BLOCKS_KEY, null);
|
||||
if (blocks == null)
|
||||
blocks = new HashMap<String, List<IDIYComponent<?>>>();
|
||||
List<IDIYComponent<?>> blockComponents = new ArrayList<IDIYComponent<?>>(this.selectedComponents);
|
||||
@@ -2891,13 +2894,13 @@ public class Presenter implements IPlugInPort {
|
||||
xStream.toXML(defaultBlockMap, out);
|
||||
out.close();
|
||||
// no more user variants
|
||||
ConfigurationManager.getInstance().writeValue(BLOCKS_KEY, null);
|
||||
configManager.writeValue(BLOCKS_KEY, null);
|
||||
LOG.info("Saved default blocks");
|
||||
} catch (IOException e) {
|
||||
LOG.error("Could not save default blocks", e);
|
||||
}
|
||||
} else {
|
||||
ConfigurationManager.getInstance().writeValue(BLOCKS_KEY, blocks);
|
||||
configManager.writeValue(BLOCKS_KEY, blocks);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2906,7 +2909,7 @@ public class Presenter implements IPlugInPort {
|
||||
public void loadBlock(String blockName) throws InvalidBlockException {
|
||||
LOG.debug(String.format("loadBlock(%s)", blockName));
|
||||
Map<String, List<IDIYComponent<?>>> blocks =
|
||||
(Map<String, List<IDIYComponent<?>>>) ConfigurationManager.getInstance().readObject(BLOCKS_KEY, null);
|
||||
(Map<String, List<IDIYComponent<?>>>) configManager.readObject(BLOCKS_KEY, null);
|
||||
if (blocks != null) {
|
||||
Collection<IDIYComponent<?>> components = blocks.get(blockName);
|
||||
if (components == null)
|
||||
@@ -2937,20 +2940,20 @@ public class Presenter implements IPlugInPort {
|
||||
public void deleteBlock(String blockName) {
|
||||
LOG.debug(String.format("deleteBlock(%s)", blockName));
|
||||
Map<String, List<IDIYComponent<?>>> blocks =
|
||||
(Map<String, List<IDIYComponent<?>>>) ConfigurationManager.getInstance().readObject(BLOCKS_KEY, null);
|
||||
(Map<String, List<IDIYComponent<?>>>) configManager.readObject(BLOCKS_KEY, null);
|
||||
if (blocks != null) {
|
||||
blocks.remove(blockName);
|
||||
ConfigurationManager.getInstance().writeValue(BLOCKS_KEY, blocks);
|
||||
configManager.writeValue(BLOCKS_KEY, blocks);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getExtraSpace() {
|
||||
if (!ConfigurationManager.getInstance().readBoolean(EXTRA_SPACE_KEY, true))
|
||||
if (!configManager.readBoolean(EXTRA_SPACE_KEY, true))
|
||||
return 0;
|
||||
|
||||
double extraSpace = drawingManager.getExtraSpace(currentProject);
|
||||
boolean metric = ConfigurationManager.getInstance().readBoolean(Presenter.METRIC_KEY, true);
|
||||
boolean metric = configManager.readBoolean(Presenter.METRIC_KEY, true);
|
||||
|
||||
extraSpace /= Constants.PIXELS_PER_INCH;
|
||||
|
||||
@@ -2975,7 +2978,7 @@ public class Presenter implements IPlugInPort {
|
||||
return 0;
|
||||
|
||||
Map<String, List<Template>> variantMap =
|
||||
(Map<String, List<Template>>) ConfigurationManager.getInstance().readObject(TEMPLATES_KEY, null);
|
||||
(Map<String, List<Template>>) configManager.readObject(TEMPLATES_KEY, null);
|
||||
if (variantMap == null) {
|
||||
variantMap = new HashMap<String, List<Template>>();
|
||||
}
|
||||
@@ -2992,7 +2995,7 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
}
|
||||
|
||||
ConfigurationManager.getInstance().writeValue(TEMPLATES_KEY, variantMap);
|
||||
configManager.writeValue(TEMPLATES_KEY, variantMap);
|
||||
|
||||
LOG.info(String.format("Loaded variants for %d components", pkg.getVariants().size()));
|
||||
|
||||
@@ -3014,7 +3017,7 @@ public class Presenter implements IPlugInPort {
|
||||
return 0;
|
||||
|
||||
Map<String, List<IDIYComponent<?>>> blocks =
|
||||
(Map<String, List<IDIYComponent<?>>>) ConfigurationManager.getInstance().readObject(BLOCKS_KEY, null);
|
||||
(Map<String, List<IDIYComponent<?>>>) configManager.readObject(BLOCKS_KEY, null);
|
||||
if (blocks == null) {
|
||||
blocks = new HashMap<String, List<IDIYComponent<?>>>();
|
||||
}
|
||||
@@ -3023,7 +3026,7 @@ public class Presenter implements IPlugInPort {
|
||||
blocks.put(entry.getKey() + " [" + pkg.getOwner() + "]", entry.getValue());
|
||||
}
|
||||
|
||||
ConfigurationManager.getInstance().writeValue(BLOCKS_KEY, blocks);
|
||||
configManager.writeValue(BLOCKS_KEY, blocks);
|
||||
|
||||
LOG.info(String.format("Loaded building blocks for %d components", pkg.getBlocks().size()));
|
||||
|
||||
@@ -3042,7 +3045,7 @@ public class Presenter implements IPlugInPort {
|
||||
LOG.info("Checking if variants need to be updated");
|
||||
Map<String, List<Template>> lookupMap = new TreeMap<String, List<Template>>(String.CASE_INSENSITIVE_ORDER);
|
||||
Map<String, List<Template>> variantMap =
|
||||
(Map<String, List<Template>>) ConfigurationManager.getInstance().readObject(TEMPLATES_KEY, null);
|
||||
(Map<String, List<Template>>) configManager.readObject(TEMPLATES_KEY, null);
|
||||
|
||||
if (variantMap == null)
|
||||
return;
|
||||
@@ -3074,7 +3077,7 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
}
|
||||
|
||||
ConfigurationManager.getInstance().writeValue(TEMPLATES_KEY, newVariantMap);
|
||||
configManager.writeValue(TEMPLATES_KEY, newVariantMap);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
*
|
||||
* DIY Layout Creator (DIYLC). Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
*
|
||||
* This file is part of DIYLC.
|
||||
*
|
||||
* DIYLC is free software: you can redistribute it and/or modify it under the terms of the GNU
|
||||
* General Public License as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* DIYLC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with DIYLC. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package org.diylc.components.misc;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Composite;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Shape;
|
||||
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.SimpleComponentTransformer;
|
||||
import org.diylc.components.boards.AbstractBoard;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.annotations.BomPolicy;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
|
||||
@ComponentDescriptor(name = "Loadline", category = "Misc", author = "Branislav Stojkovic",
|
||||
zOrder = IDIYComponent.BOARD, instanceNamePrefix = "LL",
|
||||
description = "Loadline of a tube or transistor", bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME,
|
||||
autoEdit = false, transformer = SimpleComponentTransformer.class)
|
||||
public class Loadline extends AbstractBoard {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final Color COLOR = Color.white;
|
||||
private static final Color BORDER = Color.lightGray;
|
||||
|
||||
private LoadlineEntity data;
|
||||
|
||||
public Loadline() {
|
||||
boardColor = COLOR;
|
||||
borderColor = BORDER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
int factor = 32 / width;
|
||||
g2d.setColor(BOARD_COLOR);
|
||||
g2d.fillRect(2 / factor, 2 / factor, width - 4 / factor, height - 4 / factor);
|
||||
g2d.setColor(BORDER_COLOR);
|
||||
g2d.drawRect(2 / factor, 2 / factor, width - 4 / factor, height - 4 / factor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
|
||||
Project project, IDrawingObserver drawingObserver) {
|
||||
Point finalSecondPoint = getFinalSecondPoint();
|
||||
|
||||
Shape clip = g2d.getClip();
|
||||
if (checkPointsClipped(clip) && !clip.contains(firstPoint.x, finalSecondPoint.y)
|
||||
&& !clip.contains(finalSecondPoint.x, firstPoint.y)) {
|
||||
return;
|
||||
}
|
||||
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
if (componentState != ComponentState.DRAGGING) {
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
if (alpha < MAX_ALPHA) {
|
||||
g2d.setComposite(
|
||||
AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
|
||||
}
|
||||
g2d.setColor(boardColor);
|
||||
|
||||
g2d.fillRect(firstPoint.x, firstPoint.y, finalSecondPoint.x - firstPoint.x,
|
||||
finalSecondPoint.y - firstPoint.y);
|
||||
|
||||
g2d.setComposite(oldComposite);
|
||||
}
|
||||
// Do not track any changes that follow because the whole board has been
|
||||
// tracked so far.
|
||||
drawingObserver.stopTracking();
|
||||
g2d.setColor(
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
|
||||
? SELECTION_COLOR
|
||||
: borderColor);
|
||||
|
||||
g2d.drawRect(firstPoint.x, firstPoint.y, finalSecondPoint.x - firstPoint.x,
|
||||
finalSecondPoint.y - firstPoint.y);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CoordinateType getxType() {
|
||||
// Override to prevent editing.
|
||||
return super.getxType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CoordinateDisplay getCoordinateDisplay() {
|
||||
return CoordinateDisplay.None;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CoordinateType getyType() {
|
||||
// Override to prevent editing.
|
||||
return super.getyType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getCoordinateColor() {
|
||||
// Override to prevent editing.
|
||||
return super.getCoordinateColor();
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Model")
|
||||
public LoadlineEntity getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(LoadlineEntity data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getControlPointNodeName(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CoordinateOrigin getCoordinateOrigin() {
|
||||
// Override to prevent editing.
|
||||
return super.getCoordinateOrigin();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getBoardColor() {
|
||||
// Override to prevent editing.
|
||||
return super.getBoardColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getBorderColor() {
|
||||
// Override to prevent editing.
|
||||
return super.getBorderColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
// Override to prevent editing.
|
||||
return super.getValue();
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,6 @@ Deutsch
|
||||
E-B-C BJT
|
||||
English
|
||||
Español
|
||||
Fill
|
||||
Français
|
||||
G-D-S JFET
|
||||
G-D-S MOSFET
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -48,6 +48,7 @@ import javax.swing.KeyStroke;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.IConfigListener;
|
||||
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
|
||||
import org.diylc.common.BuildingBlockPackage;
|
||||
import org.diylc.common.ComponentType;
|
||||
import org.diylc.common.IComponentTransformer;
|
||||
@@ -421,7 +422,7 @@ public class ActionFactory {
|
||||
Set<PropertyWrapper> defaultedProperties) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}, InMemoryConfigurationManager.getInstance());
|
||||
putValue(AbstractAction.NAME, "Import");
|
||||
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_I,
|
||||
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
|
||||
|
||||
@@ -59,6 +59,8 @@ import javax.swing.event.MenuListener;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.IConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
|
||||
import org.diylc.common.BadPositionException;
|
||||
import org.diylc.common.EventType;
|
||||
import org.diylc.common.IPlugIn;
|
||||
@@ -117,11 +119,13 @@ public class MainFrame extends JFrame implements ISwingUI {
|
||||
buttonGroupMap = new HashMap<String, ButtonGroup>();
|
||||
setIconImages(Arrays.asList(IconLoader.IconSmall.getImage(), IconLoader.IconMedium.getImage(),
|
||||
IconLoader.IconLarge.getImage()));
|
||||
DialogFactory.getInstance().initialize(this);
|
||||
DialogFactory.getInstance().initialize(this);
|
||||
|
||||
IConfigurationManager configManager = ConfigurationManager.getInstance();
|
||||
|
||||
this.presenter = new Presenter(this);
|
||||
this.presenter = new Presenter(this, configManager);
|
||||
|
||||
canvasPlugin = new CanvasPlugin(this);
|
||||
canvasPlugin = new CanvasPlugin(this, configManager);
|
||||
|
||||
presenter.installPlugin(new ToolBox(this));
|
||||
presenter.installPlugin(new FileMenuPlugin(this));
|
||||
|
||||
@@ -54,7 +54,8 @@ import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
|
||||
import org.diylc.common.DrawOption;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
@@ -112,7 +113,7 @@ public class TemplateDialog extends JDialog {
|
||||
public boolean editProperties(List<PropertyWrapper> properties, Set<PropertyWrapper> defaultedProperties) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}, InMemoryConfigurationManager.getInstance());
|
||||
// this.presenter.installPlugin(new IPlugIn() {
|
||||
//
|
||||
// @Override
|
||||
|
||||
@@ -29,6 +29,7 @@ import javax.swing.JLabel;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.components.misc.LoadlineEntity;
|
||||
import org.diylc.core.annotations.DynamicList;
|
||||
import org.diylc.core.annotations.MultiLineText;
|
||||
import org.diylc.core.measures.AbstractMeasure;
|
||||
@@ -99,6 +100,10 @@ public class FieldEditorFactory {
|
||||
if (Integer.class.isAssignableFrom(property.getType()) || int.class.isAssignableFrom(property.getType())) {
|
||||
IntEditor editor = new IntEditor(property);
|
||||
return editor;
|
||||
}
|
||||
if (LoadlineEntity.class.isAssignableFrom(property.getType())) {
|
||||
LoadlineEditor editor = new LoadlineEditor(property);
|
||||
return editor;
|
||||
}
|
||||
LOG.error("Unrecognized parameter type: " + property.getType().getName());
|
||||
return new JLabel("Unrecognized");
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
|
||||
DIY Layout Creator (DIYLC).
|
||||
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
|
||||
This file is part of DIYLC.
|
||||
|
||||
DIYLC is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
DIYLC is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
package org.diylc.swing.gui.editor;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JColorChooser;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.components.misc.LoadlineEntity;
|
||||
import org.diylc.swingframework.ButtonDialog;
|
||||
|
||||
public class LoadlineEditor extends JButton {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final String title = "Click to edit";
|
||||
|
||||
private PropertyWrapper property;
|
||||
|
||||
public LoadlineEditor(final PropertyWrapper property) {
|
||||
super();
|
||||
this.property = property;
|
||||
|
||||
LoadlineEntity loadline = (LoadlineEntity) property.getValue();
|
||||
|
||||
String name = (loadline == null ? "<empty>" : loadline.getName()) + " ";
|
||||
|
||||
setText(property.isUnique() ? (name + title ): ("(multi value) " + title));
|
||||
setOpaque(true);
|
||||
setHorizontalAlignment(SwingConstants.CENTER);
|
||||
setBorder(BorderFactory.createEtchedBorder());
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
LoadlineEditorDialog dialog = new LoadlineEditorDialog(null, "Edit Loadline", loadline);
|
||||
dialog.setVisible(true);
|
||||
if (ButtonDialog.OK.equals(dialog.getSelectedButtonCaption()))
|
||||
{
|
||||
property.setChanged(true);
|
||||
// property.setValue(newColor);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (property.isReadOnly()) {
|
||||
setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,424 @@
|
||||
package org.diylc.swing.gui.editor;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.File;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import org.diylc.appframework.miscutils.IConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.Utils;
|
||||
import org.diylc.common.EventType;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.common.IPlugIn;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.common.VerticalAlignment;
|
||||
import org.diylc.components.AbstractCurvedComponent.PointCount;
|
||||
import org.diylc.components.connectivity.CurvedTrace;
|
||||
import org.diylc.components.connectivity.Dot;
|
||||
import org.diylc.components.connectivity.Line;
|
||||
import org.diylc.components.misc.Label;
|
||||
import org.diylc.components.misc.LoadlineEntity;
|
||||
import org.diylc.core.IView;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.measures.Current;
|
||||
import org.diylc.core.measures.CurrentUnit;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.core.measures.Voltage;
|
||||
import org.diylc.core.measures.VoltageUnit;
|
||||
import org.diylc.images.IconLoader;
|
||||
import org.diylc.presenter.Presenter;
|
||||
import org.diylc.swing.plugins.canvas.CanvasPanel;
|
||||
import org.diylc.swingframework.ButtonDialog;
|
||||
import org.diylc.swingframework.DoubleTextField;
|
||||
|
||||
public class LoadlineEditorDialog extends ButtonDialog implements IView {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final String AXIS_LABEL = "AXIS_LABEL";
|
||||
private LoadlineEntity loadline;
|
||||
private JPanel panel;
|
||||
private JPanel toolbar;
|
||||
private JPanel controlPanel;
|
||||
private CanvasPanel canvasPanel;
|
||||
private Presenter plugInPort;
|
||||
private IConfigurationManager configManager;
|
||||
|
||||
private static int[] INCREMENTS = new int[] {100, 50, 20, 10, 5, 1};
|
||||
private int xIncrement;
|
||||
private int yIncrement;
|
||||
|
||||
public LoadlineEditorDialog(JFrame owner, String title, LoadlineEntity loadline) {
|
||||
super(owner, title, new String[] {ButtonDialog.OK, ButtonDialog.CANCEL});
|
||||
|
||||
if (loadline == null) {
|
||||
loadline = new LoadlineEntity();
|
||||
loadline.setMaxVoltage(new Voltage(300d, VoltageUnit.V));
|
||||
loadline.setMaxCurrent(new Current(5d, CurrentUnit.mA));
|
||||
}
|
||||
|
||||
configManager = new InMemoryConfigurationManager(new HashMap<String, Object>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
{
|
||||
put(IPlugInPort.LOCKED_ALPHA, false);
|
||||
put(IPlugInPort.EXTRA_SPACE_KEY, false);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
this.loadline = loadline;
|
||||
this.plugInPort = new Presenter(this, configManager);
|
||||
this.plugInPort.installPlugin(new IPlugIn() {
|
||||
|
||||
@Override
|
||||
public void processMessage(EventType type, Object... params) {
|
||||
switch (type) {
|
||||
case REPAINT:
|
||||
getCanvasPanel().repaint();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<EventType> getSubscribedEventTypes() {
|
||||
return EnumSet.of(EventType.REPAINT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(IPlugInPort plugInPort) {}
|
||||
});
|
||||
initializeProject();
|
||||
updateAxis();
|
||||
|
||||
layoutGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JComponent getMainComponent() {
|
||||
if (panel == null) {
|
||||
panel = new JPanel();
|
||||
panel.setLayout(new BorderLayout());
|
||||
panel.add(getToolbar(), BorderLayout.NORTH);
|
||||
panel.add(getCanvasPanel(), BorderLayout.CENTER);
|
||||
panel.add(getControlPanel(), BorderLayout.SOUTH);
|
||||
}
|
||||
return panel;
|
||||
}
|
||||
|
||||
public JPanel getToolbar() {
|
||||
if (toolbar == null) {
|
||||
toolbar = new JPanel();
|
||||
toolbar.add(new JButton(new LoadAction()));
|
||||
toolbar.add(new JButton(new SaveAction()));
|
||||
toolbar.add(new JButton(new LoadImageAction()));
|
||||
toolbar.add(new JButton(new AddCurveAction()));
|
||||
}
|
||||
return toolbar;
|
||||
}
|
||||
|
||||
public CanvasPanel getCanvasPanel() {
|
||||
if (canvasPanel == null) {
|
||||
// create canvas panel that doesn't render locked components in lower alpha
|
||||
canvasPanel = new CanvasPanel(plugInPort, configManager);
|
||||
canvasPanel.setPreferredSize(plugInPort.getCanvasDimensions(true, false));
|
||||
|
||||
canvasPanel.addMouseMotionListener(new MouseAdapter() {
|
||||
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
canvasPanel.setCursor(plugInPort.getCursorAt(e.getPoint()));
|
||||
plugInPort.mouseMoved(e.getPoint(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(),
|
||||
e.isShiftDown(), e.isAltDown());
|
||||
}
|
||||
});
|
||||
}
|
||||
return canvasPanel;
|
||||
}
|
||||
|
||||
public JPanel getControlPanel() {
|
||||
if (controlPanel == null) {
|
||||
controlPanel = new JPanel();
|
||||
|
||||
|
||||
controlPanel.add(new JLabel("Max Voltage (V): "));
|
||||
JTextField vEditor = new DoubleTextField();
|
||||
vEditor.setColumns(8);
|
||||
controlPanel.add(vEditor);
|
||||
|
||||
controlPanel.add(new JLabel("Max Current (mA): "));
|
||||
JTextField iEditor = new DoubleTextField();
|
||||
iEditor.setColumns(8);
|
||||
controlPanel.add(iEditor);
|
||||
|
||||
controlPanel.add(new JLabel("Max Dissipation (W): "));
|
||||
JTextField dEditor = new DoubleTextField();
|
||||
dEditor.setColumns(8);
|
||||
controlPanel.add(dEditor);
|
||||
|
||||
JButton updateButton = new JButton("Update");
|
||||
controlPanel.add(updateButton);
|
||||
|
||||
}
|
||||
return controlPanel;
|
||||
}
|
||||
|
||||
|
||||
private void initializeProject() {
|
||||
Project project = new Project();
|
||||
project.setWidth(new Size(5d, SizeUnit.in));
|
||||
project.setHeight(new Size(3d, SizeUnit.in));
|
||||
project.setGridSpacing(new Size(0.05d, SizeUnit.in));
|
||||
|
||||
double spacing = project.getGridSpacing().convertToPixels();
|
||||
|
||||
int centerX = (int) (spacing * 3);
|
||||
int centerY = (int) (project.getHeight().convertToPixels() - spacing * 3);
|
||||
|
||||
// setup coordinate system
|
||||
Line y = new Line();
|
||||
y.setControlPoint(new Point(centerX, (int) (spacing * 2)), 0);
|
||||
y.setControlPoint(new Point(centerX, centerY), 1);
|
||||
y.setArrowStart(true);
|
||||
y.setThickness(new Size(2d, SizeUnit.px));
|
||||
project.getComponents().add(y);
|
||||
project.getLockedComponents().add(y);
|
||||
|
||||
Label yLabel = new Label();
|
||||
yLabel.setValue("I(ma)");
|
||||
yLabel.setControlPoint(new Point((int) (centerX + spacing), (int) (spacing * 5)), 0);
|
||||
yLabel.setHorizontalAlignment(HorizontalAlignment.LEFT);
|
||||
yLabel.setVerticalAlignment(VerticalAlignment.TOP);
|
||||
yLabel.setBold(true);
|
||||
project.getComponents().add(yLabel);
|
||||
project.getLockedComponents().add(yLabel);
|
||||
|
||||
Line x = new Line();
|
||||
x.setControlPoint(new Point(centerX, centerY), 0);
|
||||
x.setControlPoint(
|
||||
new Point((int) (project.getWidth().convertToPixels() - spacing * 2), centerY), 1);
|
||||
x.setArrowEnd(true);
|
||||
x.setThickness(new Size(2d, SizeUnit.px));
|
||||
project.getComponents().add(x);
|
||||
project.getLockedComponents().add(x);
|
||||
|
||||
Label xLabel = new Label();
|
||||
xLabel.setValue("U(V)");
|
||||
xLabel.setControlPoint(new Point((int) (project.getWidth().convertToPixels() - spacing * 4),
|
||||
(int) (centerY - spacing)), 0);
|
||||
xLabel.setHorizontalAlignment(HorizontalAlignment.RIGHT);
|
||||
xLabel.setVerticalAlignment(VerticalAlignment.TOP);
|
||||
xLabel.setBold(true);
|
||||
project.getComponents().add(xLabel);
|
||||
project.getLockedComponents().add(xLabel);
|
||||
|
||||
Dot dot = new Dot();
|
||||
dot.setControlPoint(new Point(centerX, centerY), 0);
|
||||
project.getComponents().add(dot);
|
||||
project.getLockedComponents().add(dot);
|
||||
|
||||
plugInPort.loadProject(project, true, "n/a");
|
||||
}
|
||||
|
||||
private void updateAxis() {
|
||||
int v = loadline.getMaxVoltage().getValue().intValue();
|
||||
int i = loadline.getMaxCurrent().getValue().intValue();
|
||||
|
||||
for (int j = 0; j < INCREMENTS.length; j++) {
|
||||
int increment = INCREMENTS[j];
|
||||
if (v % increment == 0 && v / increment >= 5) {
|
||||
xIncrement = increment;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < INCREMENTS.length; j++) {
|
||||
int increment = INCREMENTS[j];
|
||||
if (i % increment == 0 && i / increment >= 5) {
|
||||
yIncrement = increment;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// delete old axis components
|
||||
plugInPort.selectMatching(AXIS_LABEL);
|
||||
plugInPort.deleteSelectedComponents();
|
||||
|
||||
Project project = plugInPort.getCurrentProject();
|
||||
|
||||
double spacing = project.getGridSpacing().convertToPixels();
|
||||
int centerX = (int) (spacing * 3);
|
||||
int centerY = (int) (project.getHeight().convertToPixels() - spacing * 3);
|
||||
int maxX = (int) (project.getWidth().convertToPixels() - spacing * 4);
|
||||
int maxY = (int) (spacing * 5);
|
||||
|
||||
for (int j = xIncrement; j <= v; j += xIncrement) {
|
||||
Line tick = new Line();
|
||||
tick.setName(AXIS_LABEL);
|
||||
double offset = 1.0 * (maxX - centerX) * (1.0 * j / v);
|
||||
tick.setControlPoint(new Point((int) (centerX + offset), centerY), 0);
|
||||
tick.setControlPoint(new Point((int) (centerX + offset), (int) (centerY + spacing / 2)), 1);
|
||||
tick.setThickness(new Size(1d, SizeUnit.px));
|
||||
project.getComponents().add(tick);
|
||||
project.getLockedComponents().add(tick);
|
||||
|
||||
Label xLabel = new Label();
|
||||
xLabel.setValue(String.valueOf(j));
|
||||
xLabel.setControlPoint(new Point((int) (centerX + offset), (int) (centerY + spacing / 2 + 1)),
|
||||
0);
|
||||
xLabel.setHorizontalAlignment(HorizontalAlignment.CENTER);
|
||||
xLabel.setVerticalAlignment(VerticalAlignment.BOTTOM);
|
||||
// xLabel.setFontSize((int) (xLabel.getFontSize() * 0.8));
|
||||
project.getComponents().add(xLabel);
|
||||
project.getLockedComponents().add(xLabel);
|
||||
}
|
||||
|
||||
for (int j = yIncrement; j <= i; j += yIncrement) {
|
||||
Line tick = new Line();
|
||||
tick.setName(AXIS_LABEL);
|
||||
double offset = 1.0 * (maxY - centerY) * (1.0 * j / i);
|
||||
tick.setControlPoint(new Point(centerX, (int) (centerY + offset)), 0);
|
||||
tick.setControlPoint(new Point((int) (centerX - spacing / 2), (int) (centerY + offset)), 1);
|
||||
tick.setThickness(new Size(1d, SizeUnit.px));
|
||||
project.getComponents().add(tick);
|
||||
project.getLockedComponents().add(tick);
|
||||
|
||||
Label yLabel = new Label();
|
||||
yLabel.setValue(String.valueOf(j));
|
||||
yLabel.setControlPoint(new Point((int) (centerX - spacing / 2 - 1), (int) (centerY + offset)),
|
||||
0);
|
||||
yLabel.setHorizontalAlignment(HorizontalAlignment.RIGHT);
|
||||
yLabel.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
// yLabel.setFontSize((int) (yLabel.getFontSize() * 0.8));
|
||||
project.getComponents().add(yLabel);
|
||||
project.getLockedComponents().add(yLabel);
|
||||
}
|
||||
}
|
||||
|
||||
private void addCurve() {
|
||||
Project project = plugInPort.getCurrentProject();
|
||||
double spacing = project.getGridSpacing().convertToPixels();
|
||||
|
||||
int centerX = (int) (spacing * 3);
|
||||
int centerY = (int) (project.getHeight().convertToPixels() - spacing * 3);
|
||||
|
||||
CurvedTrace t = new CurvedTrace();
|
||||
t.setPointCount(PointCount.FOUR);
|
||||
t.setControlPoint(new Point(centerX, centerY), 0);
|
||||
t.setControlPoint(new Point((int) (centerX + 30 * spacing), (int) (centerY - 10 * spacing)), 1);
|
||||
t.setControlPoint(new Point((int) (centerX + 50 * spacing), (int) (centerY - 20 * spacing)), 2);
|
||||
t.setControlPoint(new Point((int) (centerX + 70 * spacing), (int) (centerY - 50 * spacing)), 3);
|
||||
t.setThickness(new Size(2d, SizeUnit.px));
|
||||
t.setLeadColor(Color.blue);
|
||||
project.getComponents().add(t);
|
||||
|
||||
plugInPort.loadProject(plugInPort.getCurrentProject(), false, "n/a");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMessage(String message, String title, int messageType) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int showConfirmDialog(String message, String title, int optionType, int messageType) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean editProperties(List<PropertyWrapper> properties,
|
||||
Set<PropertyWrapper> defaultedProperties) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String showInputDialog(String message, String title) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File promptFileSave() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
class SaveAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public SaveAction() {
|
||||
super();
|
||||
putValue(Action.NAME, "Save To File");
|
||||
putValue(Action.SMALL_ICON, IconLoader.DiskBlue.getIcon());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {}
|
||||
}
|
||||
|
||||
class LoadAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public LoadAction() {
|
||||
super();
|
||||
putValue(Action.NAME, "Load From File");
|
||||
putValue(Action.SMALL_ICON, IconLoader.FolderOut.getIcon());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {}
|
||||
}
|
||||
|
||||
class AddCurveAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public AddCurveAction() {
|
||||
super();
|
||||
putValue(Action.NAME, "Add a Curve");
|
||||
// putValue(Action.SMALL_ICON, IconLoader.DiskBlue.getIcon());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
addCurve();
|
||||
}
|
||||
}
|
||||
|
||||
class LoadImageAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public LoadImageAction() {
|
||||
super();
|
||||
putValue(Action.NAME, "Insert Image");
|
||||
putValue(Action.SMALL_ICON, IconLoader.Image.getIcon());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,23 @@
|
||||
/*
|
||||
*
|
||||
* DIY Layout Creator (DIYLC). Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
*
|
||||
* This file is part of DIYLC.
|
||||
*
|
||||
* DIYLC is free software: you can redistribute it and/or modify it under the terms of the GNU
|
||||
* General Public License as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* DIYLC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with DIYLC. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package org.diylc.swing.plugins.canvas;
|
||||
|
||||
DIY Layout Creator (DIYLC).
|
||||
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
|
||||
This file is part of DIYLC.
|
||||
|
||||
DIYLC is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
DIYLC is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
package org.diylc.swing.plugins.canvas;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
@@ -52,164 +49,175 @@ import javax.swing.KeyStroke;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.IConfigurationManager;
|
||||
import org.diylc.common.ComponentType;
|
||||
import org.diylc.common.DrawOption;
|
||||
import org.diylc.common.IBlockProcessor.InvalidBlockException;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.swing.plugins.tree.TreePanel;
|
||||
|
||||
/**
|
||||
* GUI class used to draw onto.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
public class CanvasPanel extends JComponent implements Autoscroll {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
/**
|
||||
* GUI class used to draw onto.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
public class CanvasPanel extends JComponent implements Autoscroll {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(CanvasPlugin.class);
|
||||
|
||||
public static boolean RENDER_VISIBLE_RECT_ONLY = true;
|
||||
|
||||
private IPlugInPort plugInPort;
|
||||
|
||||
private Image bufferImage;
|
||||
private GraphicsConfiguration screenGraphicsConfiguration;
|
||||
|
||||
public boolean useHardwareAcceleration = ConfigurationManager.getInstance().readBoolean(IPlugInPort.HARDWARE_ACCELERATION, 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);
|
||||
|
||||
private HashMap<String, ComponentType> componentTypeCache;
|
||||
|
||||
public CanvasPanel(IPlugInPort plugInPort) {
|
||||
super();
|
||||
this.plugInPort = plugInPort;
|
||||
setFocusable(true);
|
||||
initializeListeners();
|
||||
initializeDnD();
|
||||
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice[] devices = graphicsEnvironment.getScreenDevices();
|
||||
screenGraphicsConfiguration = devices[0].getDefaultConfiguration();
|
||||
|
||||
initializeActions();
|
||||
}
|
||||
|
||||
public void invalidateCache() {
|
||||
bufferImage = null;
|
||||
}
|
||||
|
||||
public HashMap<String, ComponentType> getComponentTypeCache() {
|
||||
if (componentTypeCache == null) {
|
||||
componentTypeCache = new HashMap<String, ComponentType>();
|
||||
for (Entry<String, List<ComponentType>> entry : this.plugInPort.getComponentTypes().entrySet()) {
|
||||
for (ComponentType type : entry.getValue())
|
||||
componentTypeCache.put(type.getInstanceClass().getCanonicalName(), type);
|
||||
}
|
||||
}
|
||||
return componentTypeCache;
|
||||
}
|
||||
|
||||
private void initializeDnD() {
|
||||
// Initialize drag source recognizer.
|
||||
DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(this,
|
||||
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);
|
||||
}
|
||||
|
||||
private void initializeActions() {
|
||||
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_QUOTE, 0), "repeatLast");
|
||||
|
||||
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "clearSlot");
|
||||
|
||||
for (int i = 1; i <= 12; i++) {
|
||||
final int x = i;
|
||||
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_F1 + i - 1, 0),
|
||||
"functionKey" + i);
|
||||
getActionMap().put("functionKey" + i, new AbstractAction() {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
functionKeyPressed(x);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getActionMap().put("clearSlot", new AbstractAction() {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
CanvasPanel.this.plugInPort.setNewComponentTypeSlot(null, null, false);
|
||||
}
|
||||
});
|
||||
|
||||
getActionMap().put("repeatLast", new AbstractAction() {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
List<String> recent =
|
||||
(List<String>) ConfigurationManager.getInstance().readObject(IPlugInPort.RECENT_COMPONENTS_KEY, null);
|
||||
if (recent != null && !recent.isEmpty()) {
|
||||
String clazz = recent.get(0);
|
||||
Map<String, List<ComponentType>> componentTypes = CanvasPanel.this.plugInPort.getComponentTypes();
|
||||
for (Map.Entry<String, List<ComponentType>> entry : componentTypes.entrySet()) {
|
||||
for (ComponentType type : entry.getValue()) {
|
||||
if (type.getInstanceClass().getCanonicalName().equals(clazz)) {
|
||||
CanvasPanel.this.plugInPort.setNewComponentTypeSlot(type, null, false);
|
||||
// hack: fake mouse movement to repaint
|
||||
CanvasPanel.this.plugInPort.mouseMoved(getMousePosition(), false, false, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void functionKeyPressed(int i) {
|
||||
HashMap<String, String> shortcutMap =
|
||||
(HashMap<String, String>) ConfigurationManager.getInstance().readObject(TreePanel.COMPONENT_SHORTCUT_KEY, null);
|
||||
if (shortcutMap == null)
|
||||
return;
|
||||
String typeName = shortcutMap.get("F" + i);
|
||||
if (typeName == null)
|
||||
return;
|
||||
if (typeName.startsWith("block:")) {
|
||||
String blockName = typeName.substring(6);
|
||||
try {
|
||||
plugInPort.loadBlock(blockName);
|
||||
} catch (InvalidBlockException e) {
|
||||
LOG.error("Could not find block assigned to shortcut: " + blockName);
|
||||
}
|
||||
} else {
|
||||
ComponentType type = getComponentTypeCache().get(typeName);
|
||||
if (type == null) {
|
||||
LOG.error("Could not find type: " + typeName);
|
||||
return;
|
||||
}
|
||||
this.plugInPort.setNewComponentTypeSlot(type, null, false);
|
||||
}
|
||||
|
||||
// hack: fake mouse movement to repaint
|
||||
this.plugInPort.mouseMoved(getMousePosition(), false, false, false);
|
||||
}
|
||||
|
||||
|
||||
public static boolean RENDER_VISIBLE_RECT_ONLY = true;
|
||||
|
||||
private IPlugInPort plugInPort;
|
||||
|
||||
private Image bufferImage;
|
||||
private GraphicsConfiguration screenGraphicsConfiguration;
|
||||
|
||||
public boolean useHardwareAcceleration;
|
||||
|
||||
// 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);
|
||||
|
||||
private HashMap<String, ComponentType> componentTypeCache;
|
||||
|
||||
private IConfigurationManager configManager;
|
||||
|
||||
public CanvasPanel(IPlugInPort plugInPort, IConfigurationManager configManager) {
|
||||
this.plugInPort = plugInPort;
|
||||
this.configManager = configManager;
|
||||
|
||||
this.useHardwareAcceleration =
|
||||
configManager.readBoolean(IPlugInPort.HARDWARE_ACCELERATION, false);
|
||||
setFocusable(true);
|
||||
initializeListeners();
|
||||
initializeDnD();
|
||||
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice[] devices = graphicsEnvironment.getScreenDevices();
|
||||
screenGraphicsConfiguration = devices[0].getDefaultConfiguration();
|
||||
|
||||
initializeActions();
|
||||
}
|
||||
|
||||
public void invalidateCache() {
|
||||
bufferImage = null;
|
||||
}
|
||||
|
||||
public HashMap<String, ComponentType> getComponentTypeCache() {
|
||||
if (componentTypeCache == null) {
|
||||
componentTypeCache = new HashMap<String, ComponentType>();
|
||||
for (Entry<String, List<ComponentType>> entry : this.plugInPort.getComponentTypes()
|
||||
.entrySet()) {
|
||||
for (ComponentType type : entry.getValue())
|
||||
componentTypeCache.put(type.getInstanceClass().getCanonicalName(), type);
|
||||
}
|
||||
}
|
||||
return componentTypeCache;
|
||||
}
|
||||
|
||||
private void initializeDnD() {
|
||||
// Initialize drag source recognizer.
|
||||
DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(this,
|
||||
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);
|
||||
}
|
||||
|
||||
private void initializeActions() {
|
||||
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
|
||||
.put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_QUOTE, 0), "repeatLast");
|
||||
|
||||
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
|
||||
.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "clearSlot");
|
||||
|
||||
for (int i = 1; i <= 12; i++) {
|
||||
final int x = i;
|
||||
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
|
||||
.put(KeyStroke.getKeyStroke(KeyEvent.VK_F1 + i - 1, 0), "functionKey" + i);
|
||||
getActionMap().put("functionKey" + i, new AbstractAction() {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
functionKeyPressed(x);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getActionMap().put("clearSlot", new AbstractAction() {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
CanvasPanel.this.plugInPort.setNewComponentTypeSlot(null, null, false);
|
||||
}
|
||||
});
|
||||
|
||||
getActionMap().put("repeatLast", new AbstractAction() {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
List<String> recent = (List<String>) configManager
|
||||
.readObject(IPlugInPort.RECENT_COMPONENTS_KEY, null);
|
||||
if (recent != null && !recent.isEmpty()) {
|
||||
String clazz = recent.get(0);
|
||||
Map<String, List<ComponentType>> componentTypes =
|
||||
CanvasPanel.this.plugInPort.getComponentTypes();
|
||||
for (Map.Entry<String, List<ComponentType>> entry : componentTypes.entrySet()) {
|
||||
for (ComponentType type : entry.getValue()) {
|
||||
if (type.getInstanceClass().getCanonicalName().equals(clazz)) {
|
||||
CanvasPanel.this.plugInPort.setNewComponentTypeSlot(type, null, false);
|
||||
// hack: fake mouse movement to repaint
|
||||
CanvasPanel.this.plugInPort.mouseMoved(getMousePosition(), false, false, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void functionKeyPressed(int i) {
|
||||
HashMap<String, String> shortcutMap = (HashMap<String, String>) configManager.readObject(TreePanel.COMPONENT_SHORTCUT_KEY, null);
|
||||
if (shortcutMap == null)
|
||||
return;
|
||||
String typeName = shortcutMap.get("F" + i);
|
||||
if (typeName == null)
|
||||
return;
|
||||
if (typeName.startsWith("block:")) {
|
||||
String blockName = typeName.substring(6);
|
||||
try {
|
||||
plugInPort.loadBlock(blockName);
|
||||
} catch (InvalidBlockException e) {
|
||||
LOG.error("Could not find block assigned to shortcut: " + blockName);
|
||||
}
|
||||
} else {
|
||||
ComponentType type = getComponentTypeCache().get(typeName);
|
||||
if (type == null) {
|
||||
LOG.error("Could not find type: " + typeName);
|
||||
return;
|
||||
}
|
||||
this.plugInPort.setNewComponentTypeSlot(type, null, false);
|
||||
}
|
||||
|
||||
// hack: fake mouse movement to repaint
|
||||
this.plugInPort.mouseMoved(getMousePosition(), false, false, false);
|
||||
}
|
||||
|
||||
protected void createBufferImage() {
|
||||
int imageWidth;
|
||||
int imageHeight;
|
||||
@@ -221,126 +229,135 @@ public class CanvasPanel extends JComponent implements Autoscroll {
|
||||
imageWidth = getWidth();
|
||||
imageHeight = getHeight();
|
||||
}
|
||||
|
||||
if (useHardwareAcceleration) {
|
||||
bufferImage = screenGraphicsConfiguration.createCompatibleVolatileImage(imageWidth, imageHeight);
|
||||
((VolatileImage) bufferImage).validate(screenGraphicsConfiguration);
|
||||
} else {
|
||||
bufferImage = createImage(imageWidth, imageHeight);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
if (plugInPort == null) {
|
||||
return;
|
||||
}
|
||||
if (bufferImage == null) {
|
||||
createBufferImage();
|
||||
}
|
||||
|
||||
if (useHardwareAcceleration) {
|
||||
bufferImage =
|
||||
screenGraphicsConfiguration.createCompatibleVolatileImage(imageWidth, imageHeight);
|
||||
((VolatileImage) bufferImage).validate(screenGraphicsConfiguration);
|
||||
} else {
|
||||
bufferImage = createImage(imageWidth, imageHeight);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
if (plugInPort == null) {
|
||||
return;
|
||||
}
|
||||
if (bufferImage == null) {
|
||||
createBufferImage();
|
||||
}
|
||||
Graphics2D g2d = (Graphics2D) bufferImage.getGraphics();
|
||||
|
||||
|
||||
Rectangle visibleRect = getVisibleRect();
|
||||
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
if (RENDER_VISIBLE_RECT_ONLY) {
|
||||
|
||||
if (RENDER_VISIBLE_RECT_ONLY) {
|
||||
x = visibleRect.x;
|
||||
y = visibleRect.y;
|
||||
g2d.translate(-x, -y);
|
||||
} else {
|
||||
} else {
|
||||
g2d.setClip(visibleRect);
|
||||
}
|
||||
|
||||
Set<DrawOption> drawOptions = EnumSet.of(DrawOption.SELECTION, DrawOption.ZOOM, DrawOption.CONTROL_POINTS);
|
||||
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.ANTI_ALIASING_KEY, true)) {
|
||||
drawOptions.add(DrawOption.ANTIALIASING);
|
||||
}
|
||||
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.OUTLINE_KEY, false)) {
|
||||
drawOptions.add(DrawOption.OUTLINE_MODE);
|
||||
}
|
||||
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.SHOW_GRID_KEY, true)) {
|
||||
drawOptions.add(DrawOption.GRID);
|
||||
|
||||
|
||||
Set<DrawOption> drawOptions = EnumSet.of(DrawOption.SELECTION, DrawOption.ZOOM,
|
||||
DrawOption.CONTROL_POINTS);
|
||||
|
||||
if (configManager.readBoolean(IPlugInPort.ANTI_ALIASING_KEY, true)) {
|
||||
drawOptions.add(DrawOption.ANTIALIASING);
|
||||
}
|
||||
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.EXTRA_SPACE_KEY, true)) {
|
||||
if (configManager.readBoolean(IPlugInPort.OUTLINE_KEY, false)) {
|
||||
drawOptions.add(DrawOption.OUTLINE_MODE);
|
||||
}
|
||||
if (configManager.readBoolean(IPlugInPort.SHOW_GRID_KEY, true)) {
|
||||
drawOptions.add(DrawOption.GRID);
|
||||
}
|
||||
if (configManager.readBoolean(IPlugInPort.EXTRA_SPACE_KEY, true)) {
|
||||
drawOptions.add(DrawOption.EXTRA_SPACE);
|
||||
}
|
||||
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.CACHING_ENABLED_KEY, true)) {
|
||||
if (configManager.readBoolean(IPlugInPort.CACHING_ENABLED_KEY, true)) {
|
||||
drawOptions.add(DrawOption.ENABLE_CACHING);
|
||||
}
|
||||
|
||||
}
|
||||
if (configManager.readBoolean(IPlugInPort.LOCKED_ALPHA, true)) {
|
||||
drawOptions.add(DrawOption.LOCKED_ALPHA);
|
||||
}
|
||||
|
||||
plugInPort.draw(g2d, drawOptions, null, null, visibleRect);
|
||||
|
||||
if (useHardwareAcceleration) {
|
||||
VolatileImage volatileImage = (VolatileImage) bufferImage;
|
||||
do {
|
||||
try {
|
||||
if (volatileImage.contentsLost()) {
|
||||
createBufferImage();
|
||||
}
|
||||
// int validation =
|
||||
// volatileImage.validate(screenGraphicsConfiguration);
|
||||
// if (validation == VolatileImage.IMAGE_INCOMPATIBLE) {
|
||||
// createBufferImage();
|
||||
// }
|
||||
g.drawImage(bufferImage, x, y, this);
|
||||
} catch (NullPointerException e) {
|
||||
createBufferImage();
|
||||
}
|
||||
} while (volatileImage == null || volatileImage.contentsLost());
|
||||
} else {
|
||||
g.drawImage(bufferImage, x, y, this);
|
||||
// bufferImage.flush();
|
||||
}
|
||||
g2d.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Graphics g) {
|
||||
paint(g);
|
||||
}
|
||||
|
||||
private void initializeListeners() {
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
invalidateCache();
|
||||
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());
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
// Autoscroll
|
||||
|
||||
private int autoScrollSize = 64;
|
||||
|
||||
@Override
|
||||
public void autoscroll(Point cursorLocn) {
|
||||
scrollRectToVisible(new Rectangle(cursorLocn.x - autoScrollSize, cursorLocn.y - autoScrollSize, autoScrollSize * 2, autoScrollSize * 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Insets getAutoscrollInsets() {
|
||||
Rectangle rect = getVisibleRect();
|
||||
return new Insets(rect.y - autoScrollSize, rect.x - autoScrollSize, rect.y + rect.height + autoScrollSize, rect.x + rect.width + autoScrollSize);
|
||||
|
||||
if (useHardwareAcceleration) {
|
||||
VolatileImage volatileImage = (VolatileImage) bufferImage;
|
||||
do {
|
||||
try {
|
||||
if (volatileImage.contentsLost()) {
|
||||
createBufferImage();
|
||||
}
|
||||
// int validation =
|
||||
// volatileImage.validate(screenGraphicsConfiguration);
|
||||
// if (validation == VolatileImage.IMAGE_INCOMPATIBLE) {
|
||||
// createBufferImage();
|
||||
// }
|
||||
g.drawImage(bufferImage, x, y, this);
|
||||
} catch (NullPointerException e) {
|
||||
createBufferImage();
|
||||
}
|
||||
} while (volatileImage == null || volatileImage.contentsLost());
|
||||
} else {
|
||||
g.drawImage(bufferImage, x, y, this);
|
||||
// bufferImage.flush();
|
||||
}
|
||||
g2d.dispose();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(Graphics g) {
|
||||
paint(g);
|
||||
}
|
||||
|
||||
private void initializeListeners() {
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
invalidateCache();
|
||||
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());
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
// Autoscroll
|
||||
|
||||
private int autoScrollSize = 64;
|
||||
|
||||
@Override
|
||||
public void autoscroll(Point cursorLocn) {
|
||||
scrollRectToVisible(new Rectangle(cursorLocn.x - autoScrollSize, cursorLocn.y - autoScrollSize,
|
||||
autoScrollSize * 2, autoScrollSize * 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Insets getAutoscrollInsets() {
|
||||
Rectangle rect = getVisibleRect();
|
||||
return new Insets(rect.y - autoScrollSize, rect.x - autoScrollSize,
|
||||
rect.y + rect.height + autoScrollSize, rect.x + rect.width + autoScrollSize);
|
||||
}
|
||||
|
||||
public void setUseHardwareAcceleration(boolean useHardwareAcceleration) {
|
||||
this.useHardwareAcceleration = useHardwareAcceleration;
|
||||
bufferImage = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ import javax.swing.SwingUtilities;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.IConfigListener;
|
||||
import org.diylc.appframework.miscutils.IConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.Utils;
|
||||
import org.diylc.common.BadPositionException;
|
||||
import org.diylc.common.EventType;
|
||||
@@ -115,8 +116,11 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
|
||||
private double zoomLevel = 1;
|
||||
|
||||
public CanvasPlugin(ISwingUI swingUI) {
|
||||
private IConfigurationManager configManager;
|
||||
|
||||
public CanvasPlugin(ISwingUI swingUI, IConfigurationManager configManager) {
|
||||
this.swingUI = swingUI;
|
||||
this.configManager = configManager;
|
||||
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
}
|
||||
|
||||
@@ -145,7 +149,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
}
|
||||
|
||||
getScrollPane().setRulerVisible(
|
||||
ConfigurationManager.getInstance().readBoolean(IPlugInPort.SHOW_RULERS_KEY, true));
|
||||
configManager.readBoolean(IPlugInPort.SHOW_RULERS_KEY, true));
|
||||
|
||||
// revalidate canvas on scrolling when we render visible rect only
|
||||
if (CanvasPanel.RENDER_VISIBLE_RECT_ONLY) {
|
||||
@@ -168,7 +172,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
});
|
||||
}
|
||||
|
||||
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.SHOW_RULERS_KEY,
|
||||
configManager.addConfigListener(IPlugInPort.SHOW_RULERS_KEY,
|
||||
new IConfigListener() {
|
||||
|
||||
@Override
|
||||
@@ -178,7 +182,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
}
|
||||
});
|
||||
|
||||
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.HARDWARE_ACCELERATION,
|
||||
configManager.addConfigListener(IPlugInPort.HARDWARE_ACCELERATION,
|
||||
new IConfigListener() {
|
||||
|
||||
@Override
|
||||
@@ -188,7 +192,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
}
|
||||
});
|
||||
|
||||
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.METRIC_KEY,
|
||||
configManager.addConfigListener(IPlugInPort.METRIC_KEY,
|
||||
new IConfigListener() {
|
||||
|
||||
@Override
|
||||
@@ -197,7 +201,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
}
|
||||
});
|
||||
|
||||
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.EXTRA_SPACE_KEY,
|
||||
configManager.addConfigListener(IPlugInPort.EXTRA_SPACE_KEY,
|
||||
new IConfigListener() {
|
||||
|
||||
@Override
|
||||
@@ -214,7 +218,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
}
|
||||
});
|
||||
|
||||
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.RULER_IN_SUBDIVISION_KEY,
|
||||
configManager.addConfigListener(IPlugInPort.RULER_IN_SUBDIVISION_KEY,
|
||||
new IConfigListener() {
|
||||
|
||||
@Override
|
||||
@@ -225,7 +229,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
}
|
||||
});
|
||||
|
||||
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.HIGHLIGHT_CONTINUITY_AREA,
|
||||
configManager.addConfigListener(IPlugInPort.HIGHLIGHT_CONTINUITY_AREA,
|
||||
new IConfigListener() {
|
||||
|
||||
@Override
|
||||
@@ -239,7 +243,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
|
||||
public CanvasPanel getCanvasPanel() {
|
||||
if (canvasPanel == null) {
|
||||
canvasPanel = new CanvasPanel(plugInPort);
|
||||
canvasPanel = new CanvasPanel(plugInPort, configManager);
|
||||
canvasPanel.addMouseListener(new MouseAdapter() {
|
||||
|
||||
private MouseEvent pressedEvent;
|
||||
@@ -336,7 +340,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
|
||||
private RulerScrollPane getScrollPane() {
|
||||
if (scrollPane == null) {
|
||||
String subdivision = ConfigurationManager.getInstance().readString(
|
||||
String subdivision = configManager.readString(
|
||||
IPlugInPort.RULER_IN_SUBDIVISION_KEY, IPlugInPort.RULER_IN_SUBDIVISION_DEFAULT);
|
||||
|
||||
scrollPane = new RulerScrollPane(getCanvasPanel(),
|
||||
@@ -345,10 +349,10 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
IPlugInPort.RULER_IN_SUBDIVISION_10.equalsIgnoreCase(subdivision)
|
||||
? InchSubdivision.BASE_10
|
||||
: InchSubdivision.BASE_2);
|
||||
boolean metric = ConfigurationManager.getInstance().readBoolean(IPlugInPort.METRIC_KEY, true);
|
||||
boolean metric = configManager.readBoolean(IPlugInPort.METRIC_KEY, true);
|
||||
|
||||
boolean useHardwareAcceleration =
|
||||
ConfigurationManager.getInstance().readBoolean(IPlugInPort.HARDWARE_ACCELERATION, false);
|
||||
configManager.readBoolean(IPlugInPort.HARDWARE_ACCELERATION, false);
|
||||
scrollPane.setUseHardwareAcceleration(useHardwareAcceleration);
|
||||
scrollPane.setMetric(metric);
|
||||
scrollPane.setWheelScrollingEnabled(true);
|
||||
@@ -374,7 +378,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
final JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();
|
||||
|
||||
boolean wheelZoom =
|
||||
ConfigurationManager.getInstance().readBoolean(IPlugInPort.WHEEL_ZOOM_KEY, false);
|
||||
configManager.readBoolean(IPlugInPort.WHEEL_ZOOM_KEY, false);
|
||||
|
||||
if (wheelZoom || (Utils.isMac() ? e.isMetaDown() : e.isControlDown())) {
|
||||
|
||||
@@ -817,7 +821,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.SHOW_RULERS_KEY, true))
|
||||
if (configManager.readBoolean(IPlugInPort.SHOW_RULERS_KEY, true))
|
||||
scrollPane.setSelectionRectangle(plugInPort.getSelectionBounds(true));
|
||||
}
|
||||
});
|
||||
@@ -838,7 +842,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
|
||||
private void refreshSize() {
|
||||
Dimension d = plugInPort.getCanvasDimensions(true,
|
||||
ConfigurationManager.getInstance().readBoolean(IPlugInPort.EXTRA_SPACE_KEY, true));
|
||||
configManager.readBoolean(IPlugInPort.EXTRA_SPACE_KEY, true));
|
||||
canvasPanel.setSize(d);
|
||||
canvasPanel.setPreferredSize(d);
|
||||
getScrollPane().setZoomLevel(plugInPort.getZoomLevel());
|
||||
|
||||
@@ -31,7 +31,8 @@ import java.util.ListIterator;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.AbstractAction;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
|
||||
import org.diylc.common.EventType;
|
||||
import org.diylc.common.IPlugIn;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
@@ -80,7 +81,7 @@ public class CloudPlugIn implements IPlugIn {
|
||||
super();
|
||||
|
||||
this.swingUI = swingUI;
|
||||
this.thumbnailPresenter = new Presenter(new DummyView());
|
||||
this.thumbnailPresenter = new Presenter(new DummyView(), InMemoryConfigurationManager.getInstance());
|
||||
|
||||
swingUI.injectMenuAction(getLibraryAction(), ONLINE_TITLE);
|
||||
swingUI.injectMenuAction(null, ONLINE_TITLE);
|
||||
|
||||
+3
-2
@@ -54,7 +54,8 @@ import javax.swing.SwingUtilities;
|
||||
import javax.swing.SwingWorker;
|
||||
import javax.swing.text.DefaultCaret;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ITask;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
@@ -402,7 +403,7 @@ public class ResultsScrollPanel extends JScrollPane {
|
||||
+ project.getName()
|
||||
+ "\" with a new file?\nThis opperation is irreversible. Once replaced, the old version of the project cannot be restored.",
|
||||
"Replace Project", IView.YES_NO_OPTION, IView.QUESTION_MESSAGE) == IView.YES_OPTION) {
|
||||
final Presenter thumbnailPresenter = new Presenter(new DummyView());
|
||||
final Presenter thumbnailPresenter = new Presenter(new DummyView(), InMemoryConfigurationManager.getInstance());
|
||||
final File file =
|
||||
DialogFactory.getInstance().showOpenDialog(FileFilterEnum.DIY.getFilter(), null,
|
||||
FileFilterEnum.DIY.getExtensions()[0], null, cloudUI.getOwnerFrame());
|
||||
|
||||
@@ -35,8 +35,9 @@ import java.util.EnumSet;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
|
||||
import org.diylc.common.DrawOption;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.core.Project;
|
||||
@@ -68,7 +69,7 @@ public class ProjectPreview extends JPanel implements PropertyChangeListener, IF
|
||||
super();
|
||||
|
||||
setPreferredSize(new Dimension(140, 128));
|
||||
presenter = new Presenter(new DummyView());
|
||||
presenter = new Presenter(new DummyView(), InMemoryConfigurationManager.getInstance());
|
||||
xStream = new XStream(new DomDriver());
|
||||
|
||||
emptyProject = new Project();
|
||||
|
||||
@@ -28,7 +28,8 @@ import java.util.Properties;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.PropertyConfigurator;
|
||||
import org.diylc.DIYLCStarter;
|
||||
import org.diylc.DIYLCStarter;
|
||||
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
|
||||
import org.diylc.presenter.Presenter;
|
||||
import org.diylc.swing.gui.DummyView;
|
||||
|
||||
@@ -52,7 +53,7 @@ public class BatchConverter {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
Presenter presenter = new Presenter(new DummyView());
|
||||
Presenter presenter = new Presenter(new DummyView(), InMemoryConfigurationManager.getInstance());
|
||||
for (File file : matchingFiles) {
|
||||
if (file.getName() != "" && file.getName() != "." && file.getName() != ".." && !file.isDirectory())
|
||||
presenter.loadProjectFromFile(file.getAbsolutePath());
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
|
||||
import org.diylc.common.ComponentType;
|
||||
import org.diylc.core.IView;
|
||||
import org.diylc.presenter.Presenter;
|
||||
@@ -18,7 +19,7 @@ public class TestBase {
|
||||
public TestBase() {
|
||||
ConfigurationManager.initialize("diylc-test");
|
||||
view = new MockView();
|
||||
presenter = new Presenter(view);
|
||||
presenter = new Presenter(view, InMemoryConfigurationManager.getInstance());
|
||||
}
|
||||
|
||||
protected void instantiateOneClick(String category, String name, Point point1) {
|
||||
|
||||
Reference in New Issue
Block a user