Loadline work

This commit is contained in:
Branislav Stojkovic
2020-04-29 20:55:18 +02:00
parent 2dfd925462
commit 5cf4f5a27a
25 changed files with 1098 additions and 378 deletions
Binary file not shown.
@@ -64,5 +64,9 @@ public enum DrawOption {
/** /**
* Whether components should be cached or not. * 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_COMPONENTS = "Components";
public static final String SNAP_TO_DEFAULT = SNAP_TO_GRID; 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 = "language";
public static final String LANGUAGE_DEFAULT = "English"; public static final String LANGUAGE_DEFAULT = "English";
@@ -40,7 +40,7 @@ import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.log4j.Logger; 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.appframework.simplemq.MessageDispatcher;
import org.diylc.common.DrawOption; import org.diylc.common.DrawOption;
import org.diylc.common.EventType; import org.diylc.common.EventType;
@@ -79,8 +79,7 @@ public class DrawingManager {
public static Color CONTROL_POINT_COLOR = Color.blue; public static Color CONTROL_POINT_COLOR = Color.blue;
public static Color SELECTED_CONTROL_POINT_COLOR = Color.green; public static Color SELECTED_CONTROL_POINT_COLOR = Color.green;
private Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, private Theme theme;
Constants.DEFAULT_THEME);
// Maps keyed by object reference. // Maps keyed by object reference.
// Keeps Area object of each drawn component. // 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 Composite lockedComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
private List<IDIYComponent<?>> failedComponents = new ArrayList<IDIYComponent<?>>(); 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); // 1d);
private MessageDispatcher<EventType> messageDispatcher; private MessageDispatcher<EventType> messageDispatcher;
@@ -110,9 +109,16 @@ public class DrawingManager {
private long statReportFrequencyMs = 1000 * 60; private long statReportFrequencyMs = 1000 * 60;
private Counter totalStats = new Counter(); private Counter totalStats = new Counter();
public DrawingManager(MessageDispatcher<EventType> messageDispatcher) { private IConfigurationManager configManager;
public DrawingManager(MessageDispatcher<EventType> messageDispatcher, IConfigurationManager configManager) {
super(); super();
this.messageDispatcher = messageDispatcher; this.messageDispatcher = messageDispatcher;
this.configManager = configManager;
this.theme = (Theme) configManager.readObject(IPlugInPort.THEME_KEY,
Constants.DEFAULT_THEME);
componentAreaMap = new HashMap<IDIYComponent<?>, ComponentArea>(); componentAreaMap = new HashMap<IDIYComponent<?>, ComponentArea>();
lastDrawnStateMap = new HashMap<IDIYComponent<?>, ComponentState>(); lastDrawnStateMap = new HashMap<IDIYComponent<?>, ComponentState>();
String debugComponentAreasStr = System.getProperty(DEBUG_COMPONENT_AREAS); 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_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_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_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
@@ -299,7 +305,7 @@ public class DrawingManager {
} }
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
// Draw locked components in a new composite. // Draw locked components in a new composite.
if (lockedComponents.contains(component)) { if (lockedComponents.contains(component) && drawOptions.contains(DrawOption.LOCKED_ALPHA)) {
g2d.setComposite(lockedComposite); g2d.setComposite(lockedComposite);
} }
// Draw the component through the g2dWrapper. // Draw the component through the g2dWrapper.
@@ -456,7 +462,7 @@ public class DrawingManager {
} }
if (currentContinuityArea != null if (currentContinuityArea != null
&& (ConfigurationManager.getInstance().readBoolean(IPlugInPort.HIGHLIGHT_CONTINUITY_AREA, false))) { && (configManager.readBoolean(IPlugInPort.HIGHLIGHT_CONTINUITY_AREA, false))) {
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
g2d.setColor(Color.green); g2d.setColor(Color.green);
@@ -503,7 +509,7 @@ public class DrawingManager {
public void setZoomLevel(double zoomLevel) { public void setZoomLevel(double zoomLevel) {
this.zoomLevel = zoomLevel; this.zoomLevel = zoomLevel;
fireZoomChanged(); fireZoomChanged();
// ConfigurationManager.getInstance().writeValue(ZOOM_KEY, zoomLevel); // configManager.writeValue(ZOOM_KEY, zoomLevel);
} }
public void invalidateComponent(IDIYComponent<?> component) { public void invalidateComponent(IDIYComponent<?> component) {
@@ -570,7 +576,7 @@ public class DrawingManager {
public void setTheme(Theme theme) { public void setTheme(Theme theme) {
this.theme = theme; this.theme = theme;
ConfigurationManager.getInstance().writeValue(IPlugInPort.THEME_KEY, theme); configManager.writeValue(IPlugInPort.THEME_KEY, theme);
messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.REPAINT);
} }
@@ -51,6 +51,7 @@ import javax.swing.JOptionPane;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.appframework.miscutils.IConfigurationManager;
import org.diylc.appframework.miscutils.JarScanner; import org.diylc.appframework.miscutils.JarScanner;
import org.diylc.appframework.miscutils.Utils; import org.diylc.appframework.miscutils.Utils;
import org.diylc.appframework.simplemq.MessageDispatcher; import org.diylc.appframework.simplemq.MessageDispatcher;
@@ -191,6 +192,7 @@ public class Presenter implements IPlugInPort {
private Rectangle selectionRect; private Rectangle selectionRect;
private final IView view; private final IView view;
private IConfigurationManager configManager;
private MessageDispatcher<EventType> messageDispatcher; private MessageDispatcher<EventType> messageDispatcher;
@@ -208,16 +210,17 @@ public class Presenter implements IPlugInPort {
private DIYTest test = null; private DIYTest test = null;
public Presenter(IView view) { public Presenter(IView view, IConfigurationManager configManager) {
super(); super();
this.view = view; this.view = view;
this.configManager = configManager;
plugIns = new ArrayList<IPlugIn>(); plugIns = new ArrayList<IPlugIn>();
messageDispatcher = new MessageDispatcher<EventType>(true); messageDispatcher = new MessageDispatcher<EventType>(true);
selectedComponents = new HashSet<IDIYComponent<?>>(); selectedComponents = new HashSet<IDIYComponent<?>>();
lockedComponents = new HashSet<IDIYComponent<?>>(); lockedComponents = new HashSet<IDIYComponent<?>>();
currentProject = new Project(); currentProject = new Project();
// cloner = new Cloner(); // cloner = new Cloner();
drawingManager = new DrawingManager(messageDispatcher); drawingManager = new DrawingManager(messageDispatcher, configManager);
projectFileManager = new ProjectFileManager(messageDispatcher); projectFileManager = new ProjectFileManager(messageDispatcher);
instantiationManager = new InstantiationManager(); instantiationManager = new InstantiationManager();
@@ -265,7 +268,7 @@ public class Presenter implements IPlugInPort {
@Override @Override
public Cursor getCursorAt(Point point) { public Cursor getCursorAt(Point point) {
// Only change the cursor if we're not making a new component. // 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); return Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);
if (instantiationManager.getComponentTypeSlot() == null) { if (instantiationManager.getComponentTypeSlot() == null) {
// Scale point to remove zoom factor. // Scale point to remove zoom factor.
@@ -275,7 +278,7 @@ public class Presenter implements IPlugInPort {
} }
for (IDIYComponent<?> component : currentProject.getComponents()) { for (IDIYComponent<?> component : currentProject.getComponents()) {
if (!isComponentLocked(component) && isComponentVisible(component) if (!isComponentLocked(component) && isComponentVisible(component)
&& !ConfigurationManager.getInstance().readBoolean(HIGHLIGHT_CONTINUITY_AREA, false)) { && !configManager.readBoolean(HIGHLIGHT_CONTINUITY_AREA, false)) {
ComponentArea area = drawingManager.getComponentArea(component); ComponentArea area = drawingManager.getComponentArea(component);
if (area != null && area.getOutlineArea() != null && area.getOutlineArea().contains(scaledPoint)) { if (area != null && area.getOutlineArea() != null && area.getOutlineArea().contains(scaledPoint)) {
return Cursor.getPredefinedCursor(Cursor.HAND_CURSOR); return Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
@@ -361,14 +364,14 @@ public class Presenter implements IPlugInPort {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void addToRecentFiles(String fileName) { 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) if (recentFiles == null)
recentFiles = new ArrayList<String>(); recentFiles = new ArrayList<String>();
recentFiles.remove(fileName); recentFiles.remove(fileName);
recentFiles.add(0, fileName); recentFiles.add(0, fileName);
while (recentFiles.size() > MAX_RECENT_FILES) while (recentFiles.size() > MAX_RECENT_FILES)
recentFiles.remove(recentFiles.size() - 1); recentFiles.remove(recentFiles.size() - 1);
ConfigurationManager.getInstance().writeValue(RECENT_FILES_KEY, recentFiles); configManager.writeValue(RECENT_FILES_KEY, recentFiles);
} }
@Override @Override
@@ -640,10 +643,10 @@ public class Presenter implements IPlugInPort {
} }
if (componentTypeSlot.isAutoEdit() if (componentTypeSlot.isAutoEdit()
&& ConfigurationManager.getInstance().readBoolean(IPlugInPort.AUTO_EDIT_KEY, false)) { && configManager.readBoolean(IPlugInPort.AUTO_EDIT_KEY, false)) {
editSelection(); editSelection();
} }
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.CONTINUOUS_CREATION_KEY, false)) { if (configManager.readBoolean(IPlugInPort.CONTINUOUS_CREATION_KEY, false)) {
setNewComponentTypeSlot(componentTypeSlot, template, false); setNewComponentTypeSlot(componentTypeSlot, template, false);
} else { } else {
setNewComponentTypeSlot(null, null, false); setNewComponentTypeSlot(null, null, false);
@@ -681,7 +684,7 @@ public class Presenter implements IPlugInPort {
drawingManager.clearContinuityArea(); drawingManager.clearContinuityArea();
projectFileManager.notifyFileChange(); projectFileManager.notifyFileChange();
} }
} else if (ConfigurationManager.getInstance().readBoolean(HIGHLIGHT_CONTINUITY_AREA, false)) { } else if (configManager.readBoolean(HIGHLIGHT_CONTINUITY_AREA, false)) {
drawingManager.findContinuityAreaAtPoint(currentProject, scaledPoint); drawingManager.findContinuityAreaAtPoint(currentProject, scaledPoint);
messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.REPAINT);
} else { } else {
@@ -742,10 +745,10 @@ public class Presenter implements IPlugInPort {
messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.REPAINT);
if (componentTypeSlot.isAutoEdit() if (componentTypeSlot.isAutoEdit()
&& ConfigurationManager.getInstance().readBoolean(IPlugInPort.AUTO_EDIT_KEY, false)) { && configManager.readBoolean(IPlugInPort.AUTO_EDIT_KEY, false)) {
editSelection(); editSelection();
} }
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.CONTINUOUS_CREATION_KEY, false)) { if (configManager.readBoolean(IPlugInPort.CONTINUOUS_CREATION_KEY, false)) {
setNewComponentTypeSlot(componentTypeSlot, template, false); setNewComponentTypeSlot(componentTypeSlot, template, false);
} else { } else {
setNewComponentTypeSlot(null, null, false); setNewComponentTypeSlot(null, null, false);
@@ -776,7 +779,7 @@ public class Presenter implements IPlugInPort {
return false; 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) { if (shiftDown) {
snapTo = IPlugInPort.SNAP_TO_NONE; snapTo = IPlugInPort.SNAP_TO_NONE;
} }
@@ -807,7 +810,7 @@ public class Presenter implements IPlugInPort {
} }
// Expand control points to include all stuck components. // 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) { if (ctrlDown) {
sticky = !sticky; sticky = !sticky;
} }
@@ -1010,7 +1013,7 @@ public class Presenter implements IPlugInPort {
LOG.debug("Area is null for " + c.getName() + " of type " + c.getClass().getName()); 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); double extraSpace = drawingManager.getExtraSpace(currentProject);
minX += extraSpace; minX += extraSpace;
maxX += extraSpace; maxX += extraSpace;
@@ -1110,7 +1113,7 @@ public class Presenter implements IPlugInPort {
dragAction == DnDConstants.ACTION_LINK, dragAction == DnDConstants.ACTION_MOVE, 1); dragAction == DnDConstants.ACTION_LINK, dragAction == DnDConstants.ACTION_MOVE, 1);
return; 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."); LOG.debug("Cannot start drag in hightlight continuity mode.");
return; return;
} }
@@ -1162,7 +1165,7 @@ public class Presenter implements IPlugInPort {
} }
} }
// Expand control points to include all stuck components. // 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) { if (this.dragAction == IPlugInPort.DND_TOGGLE_STICKY) {
sticky = !sticky; sticky = !sticky;
} }
@@ -1247,14 +1250,14 @@ public class Presenter implements IPlugInPort {
} }
private boolean isSnapToGrid() { 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) if (this.dragAction == IPlugInPort.DND_TOGGLE_SNAP)
return false; return false;
return snapTo.equalsIgnoreCase(IPlugInPort.SNAP_TO_GRID); return snapTo.equalsIgnoreCase(IPlugInPort.SNAP_TO_GRID);
} }
private boolean isSnapToObjects() { 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) if (this.dragAction == IPlugInPort.DND_TOGGLE_SNAP)
return false; return false;
return snapTo.equalsIgnoreCase(IPlugInPort.SNAP_TO_COMPONENTS); return snapTo.equalsIgnoreCase(IPlugInPort.SNAP_TO_COMPONENTS);
@@ -1269,7 +1272,7 @@ public class Presenter implements IPlugInPort {
test.addStep(DIYTest.DRAG_OVER, params); 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; return false;
} }
Point scaledPoint = scalePoint(point); 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 // For each component, do a simulation of the move to see if any of
// them will overlap or go out of bounds. // 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); Dimension d = drawingManager.getCanvasDimensions(currentProject, 1d, useExtraSpace);
double extraSpace = useExtraSpace ? drawingManager.getExtraSpace(currentProject) : 0; double extraSpace = useExtraSpace ? drawingManager.getExtraSpace(currentProject) : 0;
@@ -1620,7 +1623,7 @@ public class Presenter implements IPlugInPort {
this.selectionRect = Utils.createRectangle(scaledPoint, previousDragPoint); this.selectionRect = Utils.createRectangle(scaledPoint, previousDragPoint);
} }
List<IDIYComponent<?>> newSelection = new ArrayList<IDIYComponent<?>>(); 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()) { for (IDIYComponent<?> component : currentProject.getComponents()) {
if (!isComponentLocked(component) && isComponentVisible(component)) { if (!isComponentLocked(component) && isComponentVisible(component)) {
ComponentArea area = drawingManager.getComponentArea(component); ComponentArea area = drawingManager.getComponentArea(component);
@@ -1731,7 +1734,7 @@ public class Presenter implements IPlugInPort {
for (IDIYComponent<?> component : selectedComponents) { for (IDIYComponent<?> component : selectedComponents) {
String className = component.getClass().getName(); String className = component.getClass().getName();
LOG.debug("Default property value set for " + className + ":" + propertyName); 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) { public void setDefaultPropertyValue(Class<?> clazz, String propertyName, Object value) {
LOG.info(String.format("setProjectDefaultPropertyValue(%s, %s, %s)", clazz.getName(), propertyName, value)); LOG.info(String.format("setProjectDefaultPropertyValue(%s, %s, %s)", clazz.getName(), propertyName, value));
LOG.debug("Default property value set for " + Project.class.getName() + ":" + propertyName); 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 @Override
public void setMetric(boolean isMetric) { public void setMetric(boolean isMetric) {
ConfigurationManager.getInstance().writeValue(Presenter.METRIC_KEY, isMetric); configManager.writeValue(Presenter.METRIC_KEY, isMetric);
} }
@Override @Override
@@ -2023,7 +2026,7 @@ public class Presenter implements IPlugInPort {
} }
controlPointMap.put(component, indices); controlPointMap.put(component, indices);
} }
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.STICKY_POINTS_KEY, true)) { if (configManager.readBoolean(IPlugInPort.STICKY_POINTS_KEY, true)) {
includeStuckComponents(controlPointMap); includeStuckComponents(controlPointMap);
} }
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents, controlPointMap.keySet()); messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents, controlPointMap.keySet());
@@ -2472,7 +2475,7 @@ public class Presenter implements IPlugInPort {
ComponentProcessor.getInstance().extractComponentTypeFrom( ComponentProcessor.getInstance().extractComponentTypeFrom(
(Class<? extends IDIYComponent<?>>) component.getClass()); (Class<? extends IDIYComponent<?>>) component.getClass());
Map<String, List<Template>> variantMap = 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) { if (variantMap == null) {
variantMap = new HashMap<String, List<Template>>(); variantMap = new HashMap<String, List<Template>>();
} }
@@ -2550,20 +2553,20 @@ public class Presenter implements IPlugInPort {
xStream.toXML(defaultVariantMap, out); xStream.toXML(defaultVariantMap, out);
out.close(); out.close();
// no more user variants // no more user variants
ConfigurationManager.getInstance().writeValue(TEMPLATES_KEY, null); configManager.writeValue(TEMPLATES_KEY, null);
LOG.info("Saved default variants"); LOG.info("Saved default variants");
} catch (IOException e) { } catch (IOException e) {
LOG.error("Could not save default variants", e); LOG.error("Could not save default variants", e);
} }
} else { } else {
ConfigurationManager.getInstance().writeValue(TEMPLATES_KEY, variantMap); configManager.writeValue(TEMPLATES_KEY, variantMap);
} }
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void importDefaultVariants() { private void importDefaultVariants() {
// import default templates from variants.xml file only if we didn't do it already // 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 { try {
URL resource = Presenter.class.getResource("variants.xml"); URL resource = Presenter.class.getResource("variants.xml");
if (resource != null) { if (resource != null) {
@@ -2573,7 +2576,7 @@ public class Presenter implements IPlugInPort {
in.close(); in.close();
Map<String, List<Template>> variantMap = 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) if (variantMap == null)
variantMap = new HashMap<String, List<Template>>(); 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 // update templates and a flag marking that we imported them
ConfigurationManager.getInstance().writeValue(DEFAULT_TEMPLATES_IMPORTED_KEY, true); configManager.writeValue(DEFAULT_TEMPLATES_IMPORTED_KEY, true);
ConfigurationManager.getInstance().writeValue(TEMPLATES_KEY, variantMap); configManager.writeValue(TEMPLATES_KEY, variantMap);
LOG.info(String.format("Imported default variants for %d components", LOG.info(String.format("Imported default variants for %d components",
defaults == null ? 0 : defaults.size())); defaults == null ? 0 : defaults.size()));
} }
@@ -2602,7 +2605,7 @@ public class Presenter implements IPlugInPort {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void importDefaultBlocks() { private void importDefaultBlocks() {
// import default templates from variants.xml file only if we didn't do it already // 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 { try {
URL resource = Presenter.class.getResource("blocks.xml"); URL resource = Presenter.class.getResource("blocks.xml");
if (resource != null) { if (resource != null) {
@@ -2612,7 +2615,7 @@ public class Presenter implements IPlugInPort {
in.close(); in.close();
Map<String, List<IDIYComponent<?>>> blocksMap = 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) if (blocksMap == null)
blocksMap = new HashMap<String, List<IDIYComponent<?>>>(); 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 // update templates and a flag marking that we imported them
ConfigurationManager.getInstance().writeValue(DEFAULT_BLOCKS_IMPORTED_KEY, true); configManager.writeValue(DEFAULT_BLOCKS_IMPORTED_KEY, true);
ConfigurationManager.getInstance().writeValue(BLOCKS_KEY, blocksMap); configManager.writeValue(BLOCKS_KEY, blocksMap);
LOG.info(String.format("Imported %d default building blocks", defaults == null ? 0 : defaults.size())); LOG.info(String.format("Imported %d default building blocks", defaults == null ? 0 : defaults.size()));
} }
} catch (Exception e) { } 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>> lookupMap = new TreeMap<String, List<Template>>(String.CASE_INSENSITIVE_ORDER);
Map<String, List<Template>> variantMap = 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) if (variantMap != null)
lookupMap.putAll(variantMap); lookupMap.putAll(variantMap);
@@ -2717,7 +2720,7 @@ public class Presenter implements IPlugInPort {
public void deleteVariant(ComponentType type, String templateName) { public void deleteVariant(ComponentType type, String templateName) {
LOG.debug(String.format("deleteTemplate(%s, %s)", type, templateName)); LOG.debug(String.format("deleteTemplate(%s, %s)", type, templateName));
Map<String, List<Template>> templateMap = 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) { if (templateMap != null) {
// try by class name and then by old category.type format // try by class name and then by old category.type format
String key1 = type.getInstanceClass().getCanonicalName(); 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") @SuppressWarnings("unchecked")
@@ -2752,7 +2755,7 @@ public class Presenter implements IPlugInPort {
public void setDefaultVariant(ComponentType type, String templateName) { public void setDefaultVariant(ComponentType type, String templateName) {
LOG.debug(String.format("setTemplateDefault(%s, %s)", type, templateName)); LOG.debug(String.format("setTemplateDefault(%s, %s)", type, templateName));
Map<String, String> defaultTemplateMap = 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) if (defaultTemplateMap == null)
defaultTemplateMap = new HashMap<String, String>(); defaultTemplateMap = new HashMap<String, String>();
@@ -2768,14 +2771,14 @@ public class Presenter implements IPlugInPort {
defaultTemplateMap.remove(key2); defaultTemplateMap.remove(key2);
defaultTemplateMap.put(key1, templateName); defaultTemplateMap.put(key1, templateName);
} }
ConfigurationManager.getInstance().writeValue(DEFAULT_TEMPLATES_KEY, defaultTemplateMap); configManager.writeValue(DEFAULT_TEMPLATES_KEY, defaultTemplateMap);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public String getDefaultVariant(ComponentType type) { public String getDefaultVariant(ComponentType type) {
Map<String, String> defaultTemplateMap = 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) if (defaultTemplateMap == null)
return null; return null;
@@ -2849,7 +2852,7 @@ public class Presenter implements IPlugInPort {
point == null ? null : new Point((int) (point.x / drawingManager.getZoomLevel()), point == null ? null : new Point((int) (point.x / drawingManager.getZoomLevel()),
(int) (point.y / 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); double extraSpace = drawingManager.getExtraSpace(currentProject);
p.translate((int) (-extraSpace), (int) (-extraSpace)); p.translate((int) (-extraSpace), (int) (-extraSpace));
} }
@@ -2861,7 +2864,7 @@ public class Presenter implements IPlugInPort {
public void saveSelectionAsBlock(String blockName) { public void saveSelectionAsBlock(String blockName) {
LOG.debug(String.format("saveSelectionAsBlock(%s)", blockName)); LOG.debug(String.format("saveSelectionAsBlock(%s)", blockName));
Map<String, List<IDIYComponent<?>>> blocks = 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) if (blocks == null)
blocks = new HashMap<String, List<IDIYComponent<?>>>(); blocks = new HashMap<String, List<IDIYComponent<?>>>();
List<IDIYComponent<?>> blockComponents = new ArrayList<IDIYComponent<?>>(this.selectedComponents); List<IDIYComponent<?>> blockComponents = new ArrayList<IDIYComponent<?>>(this.selectedComponents);
@@ -2891,13 +2894,13 @@ public class Presenter implements IPlugInPort {
xStream.toXML(defaultBlockMap, out); xStream.toXML(defaultBlockMap, out);
out.close(); out.close();
// no more user variants // no more user variants
ConfigurationManager.getInstance().writeValue(BLOCKS_KEY, null); configManager.writeValue(BLOCKS_KEY, null);
LOG.info("Saved default blocks"); LOG.info("Saved default blocks");
} catch (IOException e) { } catch (IOException e) {
LOG.error("Could not save default blocks", e); LOG.error("Could not save default blocks", e);
} }
} else { } 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 { public void loadBlock(String blockName) throws InvalidBlockException {
LOG.debug(String.format("loadBlock(%s)", blockName)); LOG.debug(String.format("loadBlock(%s)", blockName));
Map<String, List<IDIYComponent<?>>> blocks = 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) { if (blocks != null) {
Collection<IDIYComponent<?>> components = blocks.get(blockName); Collection<IDIYComponent<?>> components = blocks.get(blockName);
if (components == null) if (components == null)
@@ -2937,20 +2940,20 @@ public class Presenter implements IPlugInPort {
public void deleteBlock(String blockName) { public void deleteBlock(String blockName) {
LOG.debug(String.format("deleteBlock(%s)", blockName)); LOG.debug(String.format("deleteBlock(%s)", blockName));
Map<String, List<IDIYComponent<?>>> blocks = 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) { if (blocks != null) {
blocks.remove(blockName); blocks.remove(blockName);
ConfigurationManager.getInstance().writeValue(BLOCKS_KEY, blocks); configManager.writeValue(BLOCKS_KEY, blocks);
} }
} }
@Override @Override
public double getExtraSpace() { public double getExtraSpace() {
if (!ConfigurationManager.getInstance().readBoolean(EXTRA_SPACE_KEY, true)) if (!configManager.readBoolean(EXTRA_SPACE_KEY, true))
return 0; return 0;
double extraSpace = drawingManager.getExtraSpace(currentProject); 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; extraSpace /= Constants.PIXELS_PER_INCH;
@@ -2975,7 +2978,7 @@ public class Presenter implements IPlugInPort {
return 0; return 0;
Map<String, List<Template>> variantMap = 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) { if (variantMap == null) {
variantMap = new HashMap<String, List<Template>>(); 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())); LOG.info(String.format("Loaded variants for %d components", pkg.getVariants().size()));
@@ -3014,7 +3017,7 @@ public class Presenter implements IPlugInPort {
return 0; return 0;
Map<String, List<IDIYComponent<?>>> blocks = 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) { if (blocks == null) {
blocks = new HashMap<String, List<IDIYComponent<?>>>(); blocks = new HashMap<String, List<IDIYComponent<?>>>();
} }
@@ -3023,7 +3026,7 @@ public class Presenter implements IPlugInPort {
blocks.put(entry.getKey() + " [" + pkg.getOwner() + "]", entry.getValue()); 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())); 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"); 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>> lookupMap = new TreeMap<String, List<Template>>(String.CASE_INSENSITIVE_ORDER);
Map<String, List<Template>> variantMap = 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) if (variantMap == null)
return; return;
@@ -3074,7 +3077,7 @@ public class Presenter implements IPlugInPort {
} }
} }
ConfigurationManager.getInstance().writeValue(TEMPLATES_KEY, newVariantMap); configManager.writeValue(TEMPLATES_KEY, newVariantMap);
} }
@SuppressWarnings("unchecked") @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();
}
}
-1
View File
@@ -40,7 +40,6 @@ Deutsch
E-B-C BJT E-B-C BJT
English English
Español Español
Fill
Français Français
G-D-S JFET G-D-S JFET
G-D-S MOSFET 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.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.appframework.miscutils.IConfigListener; import org.diylc.appframework.miscutils.IConfigListener;
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
import org.diylc.common.BuildingBlockPackage; import org.diylc.common.BuildingBlockPackage;
import org.diylc.common.ComponentType; import org.diylc.common.ComponentType;
import org.diylc.common.IComponentTransformer; import org.diylc.common.IComponentTransformer;
@@ -421,7 +422,7 @@ public class ActionFactory {
Set<PropertyWrapper> defaultedProperties) { Set<PropertyWrapper> defaultedProperties) {
return false; return false;
} }
}); }, InMemoryConfigurationManager.getInstance());
putValue(AbstractAction.NAME, "Import"); putValue(AbstractAction.NAME, "Import");
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_I, putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_I,
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
@@ -59,6 +59,8 @@ import javax.swing.event.MenuListener;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager; 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.BadPositionException;
import org.diylc.common.EventType; import org.diylc.common.EventType;
import org.diylc.common.IPlugIn; import org.diylc.common.IPlugIn;
@@ -119,9 +121,11 @@ public class MainFrame extends JFrame implements ISwingUI {
IconLoader.IconLarge.getImage())); IconLoader.IconLarge.getImage()));
DialogFactory.getInstance().initialize(this); DialogFactory.getInstance().initialize(this);
this.presenter = new Presenter(this); IConfigurationManager configManager = ConfigurationManager.getInstance();
canvasPlugin = new CanvasPlugin(this); this.presenter = new Presenter(this, configManager);
canvasPlugin = new CanvasPlugin(this, configManager);
presenter.installPlugin(new ToolBox(this)); presenter.installPlugin(new ToolBox(this));
presenter.installPlugin(new FileMenuPlugin(this)); presenter.installPlugin(new FileMenuPlugin(this));
@@ -55,6 +55,7 @@ import javax.swing.event.ListSelectionListener;
import org.apache.log4j.Logger; 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.DrawOption;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
import org.diylc.common.PropertyWrapper; import org.diylc.common.PropertyWrapper;
@@ -112,7 +113,7 @@ public class TemplateDialog extends JDialog {
public boolean editProperties(List<PropertyWrapper> properties, Set<PropertyWrapper> defaultedProperties) { public boolean editProperties(List<PropertyWrapper> properties, Set<PropertyWrapper> defaultedProperties) {
return false; return false;
} }
}); }, InMemoryConfigurationManager.getInstance());
// this.presenter.installPlugin(new IPlugIn() { // this.presenter.installPlugin(new IPlugIn() {
// //
// @Override // @Override
@@ -29,6 +29,7 @@ import javax.swing.JLabel;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.diylc.common.PropertyWrapper; import org.diylc.common.PropertyWrapper;
import org.diylc.components.misc.LoadlineEntity;
import org.diylc.core.annotations.DynamicList; import org.diylc.core.annotations.DynamicList;
import org.diylc.core.annotations.MultiLineText; import org.diylc.core.annotations.MultiLineText;
import org.diylc.core.measures.AbstractMeasure; import org.diylc.core.measures.AbstractMeasure;
@@ -100,6 +101,10 @@ public class FieldEditorFactory {
IntEditor editor = new IntEditor(property); IntEditor editor = new IntEditor(property);
return editor; return editor;
} }
if (LoadlineEntity.class.isAssignableFrom(property.getType())) {
LoadlineEditor editor = new LoadlineEditor(property);
return editor;
}
LOG.error("Unrecognized parameter type: " + property.getType().getName()); LOG.error("Unrecognized parameter type: " + property.getType().getName());
return new JLabel("Unrecognized"); 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,23 +1,20 @@
/* /*
*
DIY Layout Creator (DIYLC). * DIY Layout Creator (DIYLC). Copyright (c) 2009-2018 held jointly by the individual authors.
Copyright (c) 2009-2018 held jointly by the individual authors. *
* This file is part of DIYLC.
This file is part of DIYLC. *
* DIYLC is free software: you can redistribute it and/or modify it under the terms of the GNU
DIYLC is free software: you can redistribute it and/or modify * General Public License as published by the Free Software Foundation, either version 3 of the
it under the terms of the GNU General Public License as published by * License, or (at your option) any later version.
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
DIYLC is distributed in the hope that it will be useful, * Public License for more details.
but WITHOUT ANY WARRANTY; without even the implied warranty of *
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * You should have received a copy of the GNU General Public License along with DIYLC. If not, see
GNU General Public License for more details. * <http://www.gnu.org/licenses/>.
*
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; package org.diylc.swing.plugins.canvas;
@@ -52,6 +49,7 @@ import javax.swing.KeyStroke;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.appframework.miscutils.IConfigurationManager;
import org.diylc.common.ComponentType; import org.diylc.common.ComponentType;
import org.diylc.common.DrawOption; import org.diylc.common.DrawOption;
import org.diylc.common.IBlockProcessor.InvalidBlockException; import org.diylc.common.IBlockProcessor.InvalidBlockException;
@@ -76,7 +74,7 @@ public class CanvasPanel extends JComponent implements Autoscroll {
private Image bufferImage; private Image bufferImage;
private GraphicsConfiguration screenGraphicsConfiguration; private GraphicsConfiguration screenGraphicsConfiguration;
public boolean useHardwareAcceleration = ConfigurationManager.getInstance().readBoolean(IPlugInPort.HARDWARE_ACCELERATION, false); public boolean useHardwareAcceleration;
// static final EnumSet<DrawOption> DRAW_OPTIONS = // static final EnumSet<DrawOption> DRAW_OPTIONS =
// EnumSet.of(DrawOption.GRID, // EnumSet.of(DrawOption.GRID,
@@ -88,9 +86,14 @@ public class CanvasPanel extends JComponent implements Autoscroll {
private HashMap<String, ComponentType> componentTypeCache; private HashMap<String, ComponentType> componentTypeCache;
public CanvasPanel(IPlugInPort plugInPort) { private IConfigurationManager configManager;
super();
public CanvasPanel(IPlugInPort plugInPort, IConfigurationManager configManager) {
this.plugInPort = plugInPort; this.plugInPort = plugInPort;
this.configManager = configManager;
this.useHardwareAcceleration =
configManager.readBoolean(IPlugInPort.HARDWARE_ACCELERATION, false);
setFocusable(true); setFocusable(true);
initializeListeners(); initializeListeners();
initializeDnD(); initializeDnD();
@@ -108,7 +111,8 @@ public class CanvasPanel extends JComponent implements Autoscroll {
public HashMap<String, ComponentType> getComponentTypeCache() { public HashMap<String, ComponentType> getComponentTypeCache() {
if (componentTypeCache == null) { if (componentTypeCache == null) {
componentTypeCache = new HashMap<String, ComponentType>(); componentTypeCache = new HashMap<String, ComponentType>();
for (Entry<String, List<ComponentType>> entry : this.plugInPort.getComponentTypes().entrySet()) { for (Entry<String, List<ComponentType>> entry : this.plugInPort.getComponentTypes()
.entrySet()) {
for (ComponentType type : entry.getValue()) for (ComponentType type : entry.getValue())
componentTypeCache.put(type.getInstanceClass().getCanonicalName(), type); componentTypeCache.put(type.getInstanceClass().getCanonicalName(), type);
} }
@@ -119,20 +123,24 @@ public class CanvasPanel extends JComponent implements Autoscroll {
private void initializeDnD() { private void initializeDnD() {
// Initialize drag source recognizer. // Initialize drag source recognizer.
DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(this, DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(this,
DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK, new CanvasGestureListener(plugInPort)); DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK,
new CanvasGestureListener(plugInPort));
// Initialize drop target. // Initialize drop target.
new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, new CanvasTargetListener(plugInPort), true); new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, new CanvasTargetListener(plugInPort),
true);
} }
private void initializeActions() { 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_BACK_QUOTE, 0), "repeatLast");
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "clearSlot"); getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "clearSlot");
for (int i = 1; i <= 12; i++) { for (int i = 1; i <= 12; i++) {
final int x = i; final int x = i;
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_F1 + i - 1, 0), getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
"functionKey" + i); .put(KeyStroke.getKeyStroke(KeyEvent.VK_F1 + i - 1, 0), "functionKey" + i);
getActionMap().put("functionKey" + i, new AbstractAction() { getActionMap().put("functionKey" + i, new AbstractAction() {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -161,11 +169,12 @@ public class CanvasPanel extends JComponent implements Autoscroll {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
List<String> recent = List<String> recent = (List<String>) configManager
(List<String>) ConfigurationManager.getInstance().readObject(IPlugInPort.RECENT_COMPONENTS_KEY, null); .readObject(IPlugInPort.RECENT_COMPONENTS_KEY, null);
if (recent != null && !recent.isEmpty()) { if (recent != null && !recent.isEmpty()) {
String clazz = recent.get(0); String clazz = recent.get(0);
Map<String, List<ComponentType>> componentTypes = CanvasPanel.this.plugInPort.getComponentTypes(); Map<String, List<ComponentType>> componentTypes =
CanvasPanel.this.plugInPort.getComponentTypes();
for (Map.Entry<String, List<ComponentType>> entry : componentTypes.entrySet()) { for (Map.Entry<String, List<ComponentType>> entry : componentTypes.entrySet()) {
for (ComponentType type : entry.getValue()) { for (ComponentType type : entry.getValue()) {
if (type.getInstanceClass().getCanonicalName().equals(clazz)) { if (type.getInstanceClass().getCanonicalName().equals(clazz)) {
@@ -183,8 +192,7 @@ public class CanvasPanel extends JComponent implements Autoscroll {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected void functionKeyPressed(int i) { protected void functionKeyPressed(int i) {
HashMap<String, String> shortcutMap = HashMap<String, String> shortcutMap = (HashMap<String, String>) configManager.readObject(TreePanel.COMPONENT_SHORTCUT_KEY, null);
(HashMap<String, String>) ConfigurationManager.getInstance().readObject(TreePanel.COMPONENT_SHORTCUT_KEY, null);
if (shortcutMap == null) if (shortcutMap == null)
return; return;
String typeName = shortcutMap.get("F" + i); String typeName = shortcutMap.get("F" + i);
@@ -223,7 +231,8 @@ public class CanvasPanel extends JComponent implements Autoscroll {
} }
if (useHardwareAcceleration) { if (useHardwareAcceleration) {
bufferImage = screenGraphicsConfiguration.createCompatibleVolatileImage(imageWidth, imageHeight); bufferImage =
screenGraphicsConfiguration.createCompatibleVolatileImage(imageWidth, imageHeight);
((VolatileImage) bufferImage).validate(screenGraphicsConfiguration); ((VolatileImage) bufferImage).validate(screenGraphicsConfiguration);
} else { } else {
bufferImage = createImage(imageWidth, imageHeight); bufferImage = createImage(imageWidth, imageHeight);
@@ -253,22 +262,28 @@ public class CanvasPanel extends JComponent implements Autoscroll {
g2d.setClip(visibleRect); g2d.setClip(visibleRect);
} }
Set<DrawOption> drawOptions = EnumSet.of(DrawOption.SELECTION, DrawOption.ZOOM, DrawOption.CONTROL_POINTS);
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.ANTI_ALIASING_KEY, true)) { Set<DrawOption> drawOptions = EnumSet.of(DrawOption.SELECTION, DrawOption.ZOOM,
DrawOption.CONTROL_POINTS);
if (configManager.readBoolean(IPlugInPort.ANTI_ALIASING_KEY, true)) {
drawOptions.add(DrawOption.ANTIALIASING); drawOptions.add(DrawOption.ANTIALIASING);
} }
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.OUTLINE_KEY, false)) { if (configManager.readBoolean(IPlugInPort.OUTLINE_KEY, false)) {
drawOptions.add(DrawOption.OUTLINE_MODE); drawOptions.add(DrawOption.OUTLINE_MODE);
} }
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.SHOW_GRID_KEY, true)) { if (configManager.readBoolean(IPlugInPort.SHOW_GRID_KEY, true)) {
drawOptions.add(DrawOption.GRID); drawOptions.add(DrawOption.GRID);
} }
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.EXTRA_SPACE_KEY, true)) { if (configManager.readBoolean(IPlugInPort.EXTRA_SPACE_KEY, true)) {
drawOptions.add(DrawOption.EXTRA_SPACE); 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); drawOptions.add(DrawOption.ENABLE_CACHING);
} }
if (configManager.readBoolean(IPlugInPort.LOCKED_ALPHA, true)) {
drawOptions.add(DrawOption.LOCKED_ALPHA);
}
plugInPort.draw(g2d, drawOptions, null, null, visibleRect); plugInPort.draw(g2d, drawOptions, null, null, visibleRect);
@@ -330,13 +345,15 @@ public class CanvasPanel extends JComponent implements Autoscroll {
@Override @Override
public void autoscroll(Point cursorLocn) { public void autoscroll(Point cursorLocn) {
scrollRectToVisible(new Rectangle(cursorLocn.x - autoScrollSize, cursorLocn.y - autoScrollSize, autoScrollSize * 2, autoScrollSize * 2)); scrollRectToVisible(new Rectangle(cursorLocn.x - autoScrollSize, cursorLocn.y - autoScrollSize,
autoScrollSize * 2, autoScrollSize * 2));
} }
@Override @Override
public Insets getAutoscrollInsets() { public Insets getAutoscrollInsets() {
Rectangle rect = getVisibleRect(); Rectangle rect = getVisibleRect();
return new Insets(rect.y - autoScrollSize, rect.x - autoScrollSize, rect.y + rect.height + autoScrollSize, rect.x + rect.width + autoScrollSize); return new Insets(rect.y - autoScrollSize, rect.x - autoScrollSize,
rect.y + rect.height + autoScrollSize, rect.x + rect.width + autoScrollSize);
} }
public void setUseHardwareAcceleration(boolean useHardwareAcceleration) { public void setUseHardwareAcceleration(boolean useHardwareAcceleration) {
@@ -52,6 +52,7 @@ import javax.swing.SwingUtilities;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.appframework.miscutils.IConfigListener; import org.diylc.appframework.miscutils.IConfigListener;
import org.diylc.appframework.miscutils.IConfigurationManager;
import org.diylc.appframework.miscutils.Utils; import org.diylc.appframework.miscutils.Utils;
import org.diylc.common.BadPositionException; import org.diylc.common.BadPositionException;
import org.diylc.common.EventType; import org.diylc.common.EventType;
@@ -115,8 +116,11 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
private double zoomLevel = 1; private double zoomLevel = 1;
public CanvasPlugin(ISwingUI swingUI) { private IConfigurationManager configManager;
public CanvasPlugin(ISwingUI swingUI, IConfigurationManager configManager) {
this.swingUI = swingUI; this.swingUI = swingUI;
this.configManager = configManager;
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
} }
@@ -145,7 +149,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
} }
getScrollPane().setRulerVisible( 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 // revalidate canvas on scrolling when we render visible rect only
if (CanvasPanel.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() { new IConfigListener() {
@Override @Override
@@ -178,7 +182,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
} }
}); });
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.HARDWARE_ACCELERATION, configManager.addConfigListener(IPlugInPort.HARDWARE_ACCELERATION,
new IConfigListener() { new IConfigListener() {
@Override @Override
@@ -188,7 +192,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
} }
}); });
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.METRIC_KEY, configManager.addConfigListener(IPlugInPort.METRIC_KEY,
new IConfigListener() { new IConfigListener() {
@Override @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() { new IConfigListener() {
@Override @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() { new IConfigListener() {
@Override @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() { new IConfigListener() {
@Override @Override
@@ -239,7 +243,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
public CanvasPanel getCanvasPanel() { public CanvasPanel getCanvasPanel() {
if (canvasPanel == null) { if (canvasPanel == null) {
canvasPanel = new CanvasPanel(plugInPort); canvasPanel = new CanvasPanel(plugInPort, configManager);
canvasPanel.addMouseListener(new MouseAdapter() { canvasPanel.addMouseListener(new MouseAdapter() {
private MouseEvent pressedEvent; private MouseEvent pressedEvent;
@@ -336,7 +340,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
private RulerScrollPane getScrollPane() { private RulerScrollPane getScrollPane() {
if (scrollPane == null) { if (scrollPane == null) {
String subdivision = ConfigurationManager.getInstance().readString( String subdivision = configManager.readString(
IPlugInPort.RULER_IN_SUBDIVISION_KEY, IPlugInPort.RULER_IN_SUBDIVISION_DEFAULT); IPlugInPort.RULER_IN_SUBDIVISION_KEY, IPlugInPort.RULER_IN_SUBDIVISION_DEFAULT);
scrollPane = new RulerScrollPane(getCanvasPanel(), scrollPane = new RulerScrollPane(getCanvasPanel(),
@@ -345,10 +349,10 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
IPlugInPort.RULER_IN_SUBDIVISION_10.equalsIgnoreCase(subdivision) IPlugInPort.RULER_IN_SUBDIVISION_10.equalsIgnoreCase(subdivision)
? InchSubdivision.BASE_10 ? InchSubdivision.BASE_10
: InchSubdivision.BASE_2); : InchSubdivision.BASE_2);
boolean metric = ConfigurationManager.getInstance().readBoolean(IPlugInPort.METRIC_KEY, true); boolean metric = configManager.readBoolean(IPlugInPort.METRIC_KEY, true);
boolean useHardwareAcceleration = boolean useHardwareAcceleration =
ConfigurationManager.getInstance().readBoolean(IPlugInPort.HARDWARE_ACCELERATION, false); configManager.readBoolean(IPlugInPort.HARDWARE_ACCELERATION, false);
scrollPane.setUseHardwareAcceleration(useHardwareAcceleration); scrollPane.setUseHardwareAcceleration(useHardwareAcceleration);
scrollPane.setMetric(metric); scrollPane.setMetric(metric);
scrollPane.setWheelScrollingEnabled(true); scrollPane.setWheelScrollingEnabled(true);
@@ -374,7 +378,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
final JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar(); final JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();
boolean wheelZoom = 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())) { if (wheelZoom || (Utils.isMac() ? e.isMetaDown() : e.isControlDown())) {
@@ -817,7 +821,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
@Override @Override
public void run() { 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)); scrollPane.setSelectionRectangle(plugInPort.getSelectionBounds(true));
} }
}); });
@@ -838,7 +842,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
private void refreshSize() { private void refreshSize() {
Dimension d = plugInPort.getCanvasDimensions(true, Dimension d = plugInPort.getCanvasDimensions(true,
ConfigurationManager.getInstance().readBoolean(IPlugInPort.EXTRA_SPACE_KEY, true)); configManager.readBoolean(IPlugInPort.EXTRA_SPACE_KEY, true));
canvasPanel.setSize(d); canvasPanel.setSize(d);
canvasPanel.setPreferredSize(d); canvasPanel.setPreferredSize(d);
getScrollPane().setZoomLevel(plugInPort.getZoomLevel()); getScrollPane().setZoomLevel(plugInPort.getZoomLevel());
@@ -32,6 +32,7 @@ import javax.imageio.ImageIO;
import javax.swing.AbstractAction; 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.EventType;
import org.diylc.common.IPlugIn; import org.diylc.common.IPlugIn;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
@@ -80,7 +81,7 @@ public class CloudPlugIn implements IPlugIn {
super(); super();
this.swingUI = swingUI; this.swingUI = swingUI;
this.thumbnailPresenter = new Presenter(new DummyView()); this.thumbnailPresenter = new Presenter(new DummyView(), InMemoryConfigurationManager.getInstance());
swingUI.injectMenuAction(getLibraryAction(), ONLINE_TITLE); swingUI.injectMenuAction(getLibraryAction(), ONLINE_TITLE);
swingUI.injectMenuAction(null, ONLINE_TITLE); swingUI.injectMenuAction(null, ONLINE_TITLE);
@@ -55,6 +55,7 @@ import javax.swing.SwingWorker;
import javax.swing.text.DefaultCaret; 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.IPlugInPort;
import org.diylc.common.ITask; import org.diylc.common.ITask;
import org.diylc.common.PropertyWrapper; import org.diylc.common.PropertyWrapper;
@@ -402,7 +403,7 @@ public class ResultsScrollPanel extends JScrollPane {
+ project.getName() + project.getName()
+ "\" with a new file?\nThis opperation is irreversible. Once replaced, the old version of the project cannot be restored.", + "\" 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) { "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 = final File file =
DialogFactory.getInstance().showOpenDialog(FileFilterEnum.DIY.getFilter(), null, DialogFactory.getInstance().showOpenDialog(FileFilterEnum.DIY.getFilter(), null,
FileFilterEnum.DIY.getExtensions()[0], null, cloudUI.getOwnerFrame()); FileFilterEnum.DIY.getExtensions()[0], null, cloudUI.getOwnerFrame());
@@ -37,6 +37,7 @@ import javax.swing.JFileChooser;
import javax.swing.JLabel; 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.DrawOption;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
import org.diylc.core.Project; import org.diylc.core.Project;
@@ -68,7 +69,7 @@ public class ProjectPreview extends JPanel implements PropertyChangeListener, IF
super(); super();
setPreferredSize(new Dimension(140, 128)); setPreferredSize(new Dimension(140, 128));
presenter = new Presenter(new DummyView()); presenter = new Presenter(new DummyView(), InMemoryConfigurationManager.getInstance());
xStream = new XStream(new DomDriver()); xStream = new XStream(new DomDriver());
emptyProject = new Project(); emptyProject = new Project();
@@ -29,6 +29,7 @@ import java.util.Properties;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator; 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.presenter.Presenter;
import org.diylc.swing.gui.DummyView; import org.diylc.swing.gui.DummyView;
@@ -52,7 +53,7 @@ public class BatchConverter {
return true; return true;
} }
}); });
Presenter presenter = new Presenter(new DummyView()); Presenter presenter = new Presenter(new DummyView(), InMemoryConfigurationManager.getInstance());
for (File file : matchingFiles) { for (File file : matchingFiles) {
if (file.getName() != "" && file.getName() != "." && file.getName() != ".." && !file.isDirectory()) if (file.getName() != "" && file.getName() != "." && file.getName() != ".." && !file.isDirectory())
presenter.loadProjectFromFile(file.getAbsolutePath()); presenter.loadProjectFromFile(file.getAbsolutePath());
@@ -6,6 +6,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
import org.diylc.common.ComponentType; import org.diylc.common.ComponentType;
import org.diylc.core.IView; import org.diylc.core.IView;
import org.diylc.presenter.Presenter; import org.diylc.presenter.Presenter;
@@ -18,7 +19,7 @@ public class TestBase {
public TestBase() { public TestBase() {
ConfigurationManager.initialize("diylc-test"); ConfigurationManager.initialize("diylc-test");
view = new MockView(); view = new MockView();
presenter = new Presenter(view); presenter = new Presenter(view, InMemoryConfigurationManager.getInstance());
} }
protected void instantiateOneClick(String category, String name, Point point1) { protected void instantiateOneClick(String category, String name, Point point1) {