added layer locking

added eyelet board
This commit is contained in:
bancika
2011-01-22 13:17:43 +00:00
parent 99d85a2d1f
commit 664bf91852
15 changed files with 372 additions and 67 deletions
@@ -1,14 +1,14 @@
<map> <map>
<entry> <entry>
<string>metric</string> <string>lastPath</string>
<boolean>false</boolean> <string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
</entry> </entry>
<entry> <entry>
<string>zoom</string> <string>zoom</string>
<double>1.0</double> <double>1.0</double>
</entry> </entry>
<entry> <entry>
<string>lastPath</string> <string>metric</string>
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string> <boolean>true</boolean>
</entry> </entry>
</map> </map>
@@ -75,5 +75,7 @@ public enum EventType {
* Called when mouse cursor is moved. Point object is passed, containing the * Called when mouse cursor is moved. Point object is passed, containing the
* current cursor location (not taking zoom into account). * current cursor location (not taking zoom into account).
*/ */
MOUSE_MOVED; MOUSE_MOVED,
LAYER_STATE_CHANGED;
;
} }
@@ -35,6 +35,8 @@ import com.diyfever.gui.update.VersionNumber;
*/ */
public interface IPlugInPort { public interface IPlugInPort {
public static final String CHECK_BOX_MENU_ITEM = "org.diylc.checkBoxMenuItem";
/** /**
* Returns size of the canvas that takes project dimensions into account as * Returns size of the canvas that takes project dimensions into account as
* well as zoom level. Each dimension is calculated as the product of the * well as zoom level. Each dimension is calculated as the product of the
@@ -349,4 +351,6 @@ public interface IPlugInPort {
* Ungroups all selected components. * Ungroups all selected components.
*/ */
void ungroupSelectedComponents(); void ungroupSelectedComponents();
void setLayerLocked(int layerZOrder, boolean locked);
} }
@@ -1,10 +1,17 @@
package org.diylc.common; package org.diylc.common;
import java.awt.AlphaComposite;
import java.awt.BasicStroke; import java.awt.BasicStroke;
import java.awt.Stroke; import java.awt.Stroke;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
/**
* Repository for object that may be reused, such as {@link Stroke} or
* {@link AlphaComposite}.
*
* @author Branislav Stojkovic
*/
public class ObjectCache { public class ObjectCache {
private static ObjectCache instance; private static ObjectCache instance;
@@ -34,10 +34,12 @@ public class Project implements Serializable {
private Size gridSpacing; private Size gridSpacing;
private List<IDIYComponent<?>> components; private List<IDIYComponent<?>> components;
private Set<Set<IDIYComponent<?>>> groups; private Set<Set<IDIYComponent<?>>> groups;
private Set<Integer> lockedLayers;
public Project() { public Project() {
components = new ArrayList<IDIYComponent<?>>(); components = new ArrayList<IDIYComponent<?>>();
groups = new HashSet<Set<IDIYComponent<?>>>(); groups = new HashSet<Set<IDIYComponent<?>>>();
lockedLayers = new HashSet<Integer>();
title = DEFAULT_TITLE; title = DEFAULT_TITLE;
author = System.getProperty("user.name"); author = System.getProperty("user.name");
width = DEFAULT_WIDTH; width = DEFAULT_WIDTH;
@@ -45,19 +47,6 @@ public class Project implements Serializable {
gridSpacing = DEFAULT_GRID_SPACING; gridSpacing = DEFAULT_GRID_SPACING;
} }
public Project(String title, String author, String description, Size width, Size height,
Size gridSpacing, List<IDIYComponent<?>> components, Set<Set<IDIYComponent<?>>> groups) {
super();
this.title = title;
this.author = author;
this.description = description;
this.width = width;
this.height = height;
this.gridSpacing = gridSpacing;
this.components = components;
this.groups = groups;
}
@EditableProperty(defaultable = false) @EditableProperty(defaultable = false)
public String getTitle() { public String getTitle() {
return title; return title;
@@ -130,6 +119,10 @@ public class Project implements Serializable {
return groups; return groups;
} }
public Set<Integer> getLockedLayers() {
return lockedLayers;
}
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
@@ -185,6 +178,11 @@ public class Project implements Serializable {
return true; return true;
} }
@Override
public String toString() {
return title;
}
// @Override // @Override
// public Project clone() throws CloneNotSupportedException { // public Project clone() throws CloneNotSupportedException {
// List<IDIYComponent> clonedComponents = new // List<IDIYComponent> clonedComponents = new
@@ -15,6 +15,7 @@ import java.util.Map;
import javax.swing.Action; import javax.swing.Action;
import javax.swing.BoxLayout; import javax.swing.BoxLayout;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JMenu; import javax.swing.JMenu;
@@ -33,6 +34,7 @@ import org.diylc.plugins.canvas.CanvasPlugin;
import org.diylc.plugins.clipboard.EditMenuPlugin; import org.diylc.plugins.clipboard.EditMenuPlugin;
import org.diylc.plugins.file.FileMenuPlugin; import org.diylc.plugins.file.FileMenuPlugin;
import org.diylc.plugins.help.HelpMenuPlugin; import org.diylc.plugins.help.HelpMenuPlugin;
import org.diylc.plugins.layers.LayersMenuPlugin;
import org.diylc.plugins.statusbar.StatusBar; import org.diylc.plugins.statusbar.StatusBar;
import org.diylc.plugins.toolbox.ToolBox; import org.diylc.plugins.toolbox.ToolBox;
import org.diylc.presenter.Presenter; import org.diylc.presenter.Presenter;
@@ -69,6 +71,7 @@ public class MainFrame extends JFrame implements IView {
presenter.installPlugin(new ToolBox()); presenter.installPlugin(new ToolBox());
presenter.installPlugin(new FileMenuPlugin()); presenter.installPlugin(new FileMenuPlugin());
presenter.installPlugin(new EditMenuPlugin()); presenter.installPlugin(new EditMenuPlugin());
presenter.installPlugin(new LayersMenuPlugin());
// presenter.installPlugin(new OnlineManager()); // presenter.installPlugin(new OnlineManager());
presenter.installPlugin(new HelpMenuPlugin()); presenter.installPlugin(new HelpMenuPlugin());
@@ -194,10 +197,15 @@ public class MainFrame extends JFrame implements IView {
JMenu menu = findOrCreateMenu(menuName); JMenu menu = findOrCreateMenu(menuName);
if (action == null) { if (action == null) {
menu.addSeparator(); menu.addSeparator();
} else {
Boolean isCheckBox = (Boolean) action.getValue(IPlugInPort.CHECK_BOX_MENU_ITEM);
if (isCheckBox != null && isCheckBox) {
menu.add(new JCheckBoxMenuItem(action));
} else { } else {
menu.add(action); menu.add(action);
} }
} }
}
@Override @Override
public void addSubmenu(String name, Icon icon, String parentMenuName) { public void addSubmenu(String name, Icon icon, String parentMenuName) {
@@ -0,0 +1,51 @@
package org.diylc.gui.editor;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.BorderFactory;
import javax.swing.JColorChooser;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import org.diylc.common.PropertyWrapper;
public class FontEditor extends JLabel {
private static final long serialVersionUID = 1L;
public FontEditor(final PropertyWrapper property) {
super("Click to edit");
setOpaque(true);
setHorizontalAlignment(SwingConstants.CENTER);
setBorder(BorderFactory.createEtchedBorder());
setBackground((Color) property.getValue());
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// JFo
Color newColor = JColorChooser.showDialog(FontEditor.this, "Choose Color",
getBackground());
if (newColor != null) {
property.setValue(newColor);
setBackground(newColor);
}
}
});
}
@Override
public void setBackground(Color bg) {
if (bg.getRed() < 127 || bg.getBlue() < 127 || bg.getGreen() < 127) {
setForeground(Color.white);
} else {
setForeground(Color.black);
}
super.setBackground(bg);
}
}
@@ -0,0 +1,89 @@
package org.diylc.plugins.layers;
import java.awt.event.ActionEvent;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import javax.swing.AbstractAction;
import javax.swing.Action;
import org.diylc.common.EventType;
import org.diylc.common.IPlugIn;
import org.diylc.common.IPlugInPort;
import org.diylc.core.IDIYComponent;
public class LayersMenuPlugin implements IPlugIn {
private static final String LOCK_LAYERS_TITLE = "Lock Layers";
private IPlugInPort plugInPort;
private Map<Layer, Action> lockActionMap;
public LayersMenuPlugin() {
}
@Override
public void connect(IPlugInPort plugInPort) {
this.plugInPort = plugInPort;
lockActionMap = new HashMap<Layer, Action>();
for (Layer layer : Layer.values()) {
final int zOrder = layer.getZOrder();
AbstractAction action = new AbstractAction(layer.getTitle()) {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent e) {
LayersMenuPlugin.this.plugInPort.setLayerLocked(zOrder, true);
}
};
action.putValue(IPlugInPort.CHECK_BOX_MENU_ITEM, true);
lockActionMap.put(layer, action);
plugInPort.injectMenuAction(action, LOCK_LAYERS_TITLE);
}
}
@Override
public EnumSet<EventType> getSubscribedEventTypes() {
return EnumSet.of(EventType.LAYER_STATE_CHANGED);
}
@Override
public void processMessage(EventType eventType, Object... params) {
if (eventType == EventType.LAYER_STATE_CHANGED) {
Set<Integer> lockedLayers = (Set<Integer>) params[0];
for (Layer layer : Layer.values()) {
lockActionMap.get(layer).putValue(Action.SELECTED_KEY,
lockedLayers.contains(layer.getZOrder()));
}
}
}
static enum Layer {
BELOW_CHASSIS("Below Chassis", IDIYComponent.BELOW_CHASSIS), CHASSIS("Chassis",
IDIYComponent.CHASSIS), ABOVE_CHASSIS("Above Chassis", IDIYComponent.ABOVE_CHASSIS), BELOW_BOARD(
"Below Board", IDIYComponent.BELOW_BOARD), BOARD("Board", IDIYComponent.BOARD), ABOVE_BOARD(
"Above Board", IDIYComponent.ABOVE_BOARD), COMPONENT("Component",
IDIYComponent.COMPONENT), ABOVE_COMPONENT("Above Component",
IDIYComponent.ABOVE_COMPONENT);
String title;
int zOrder;
private Layer(String title, int order) {
this.title = title;
zOrder = order;
}
public String getTitle() {
return title;
}
public int getZOrder() {
return zOrder;
}
}
}
@@ -10,7 +10,6 @@ import java.awt.Point;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.RenderingHints; import java.awt.RenderingHints;
import java.awt.geom.Area; import java.awt.geom.Area;
import java.awt.geom.Point2D;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@@ -58,6 +57,7 @@ public class DrawingManager {
private Map<IDIYComponent<?>, ComponentState> lastDrawnStateMap; private Map<IDIYComponent<?>, ComponentState> lastDrawnStateMap;
private Composite slotComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f); private Composite slotComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
private Composite lockedComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
private double zoomLevel = 1d;// ConfigurationManager.getInstance().readDouble(ZOOM_KEY, private double zoomLevel = 1d;// ConfigurationManager.getInstance().readDouble(ZOOM_KEY,
// 1d); // 1d);
@@ -73,8 +73,8 @@ public class DrawingManager {
public void drawProject(Graphics2D g2d, Project project, Set<DrawOption> drawOptions, public void drawProject(Graphics2D g2d, Project project, Set<DrawOption> drawOptions,
IComponentFiler filter, Rectangle selectionRect, ComponentSelection selectedComponents, IComponentFiler filter, Rectangle selectionRect, ComponentSelection selectedComponents,
Set<IDIYComponent<?>> groupedComponents, List<Point> controlPointSlot, Set<IDIYComponent<?>> lockedComponents, Set<IDIYComponent<?>> groupedComponents,
IDIYComponent<?> componentSlot, boolean dragInProgress) { List<Point> controlPointSlot, IDIYComponent<?> componentSlot, boolean dragInProgress) {
if (project == null) { if (project == null) {
return; return;
} }
@@ -155,6 +155,10 @@ public class DrawingManager {
if (!trackArea) { if (!trackArea) {
g2dWrapper.stopTracking(); g2dWrapper.stopTracking();
} }
// Draw locked components in a new composite.
if (lockedComponents.contains(component)) {
g2d.setComposite(lockedComposite);
}
// Draw the component through the g2dWrapper. // Draw the component through the g2dWrapper.
component.draw(g2dWrapper, state, project, g2dWrapper); component.draw(g2dWrapper, state, project, g2dWrapper);
Area area = g2dWrapper.finishedDrawingComponent(); Area area = g2dWrapper.finishedDrawingComponent();
@@ -277,15 +281,6 @@ public class DrawingManager {
return componentAreaMap.get(component); return componentAreaMap.get(component);
} }
public boolean isCursorOverArea(Point2D cursorPosition) {
for (Map.Entry<IDIYComponent<?>, Area> entry : componentAreaMap.entrySet()) {
if (entry.getValue().contains(cursorPosition)) {
return true;
}
}
return false;
}
public List<IDIYComponent<?>> findComponentsAt(Point point, Project project) { public List<IDIYComponent<?>> findComponentsAt(Point point, Project project) {
List<IDIYComponent<?>> components = new ArrayList<IDIYComponent<?>>(); List<IDIYComponent<?>> components = new ArrayList<IDIYComponent<?>>();
for (Map.Entry<IDIYComponent<?>, Area> entry : componentAreaMap.entrySet()) { for (Map.Entry<IDIYComponent<?>, Area> entry : componentAreaMap.entrySet()) {
@@ -56,7 +56,7 @@ public class Presenter implements IPlugInPort {
private static final Logger LOG = Logger.getLogger(Presenter.class); private static final Logger LOG = Logger.getLogger(Presenter.class);
public static final VersionNumber CURRENT_VERSION = new VersionNumber(3, 0, 1); public static final VersionNumber CURRENT_VERSION = new VersionNumber(3, 0, 3);
public static final String DEFAULTS_KEY_PREFIX = "default."; public static final String DEFAULTS_KEY_PREFIX = "default.";
public static final String METRIC_KEY = "metric"; public static final String METRIC_KEY = "metric";
@@ -72,6 +72,7 @@ public class Presenter implements IPlugInPort {
// Maps components that have at least one dragged point to set of indices // Maps components that have at least one dragged point to set of indices
// that designate which of their control points are being dragged. // that designate which of their control points are being dragged.
private Map<IDIYComponent<?>, Set<Integer>> controlPointMap; private Map<IDIYComponent<?>, Set<Integer>> controlPointMap;
private Set<IDIYComponent<?>> lockedComponents;
// Utilities // Utilities
private Cloner cloner; private Cloner cloner;
@@ -103,6 +104,7 @@ public class Presenter implements IPlugInPort {
plugIns = new ArrayList<IPlugIn>(); plugIns = new ArrayList<IPlugIn>();
messageDispatcher = new MessageDispatcher<EventType>(); messageDispatcher = new MessageDispatcher<EventType>();
selectedComponents = new ComponentSelection(); selectedComponents = new ComponentSelection();
lockedComponents = new HashSet<IDIYComponent<?>>();
currentProject = new Project(); currentProject = new Project();
cloner = new Cloner(); cloner = new Cloner();
drawingManager = new DrawingManager(messageDispatcher); drawingManager = new DrawingManager(messageDispatcher);
@@ -153,12 +155,17 @@ public class Presenter implements IPlugInPort {
if (instantiationManager.getComponentTypeSlot() == null) { if (instantiationManager.getComponentTypeSlot() == null) {
// Scale point to remove zoom factor. // Scale point to remove zoom factor.
Point2D scaledPoint = scalePoint(point); Point2D scaledPoint = scalePoint(point);
if (drawingManager.isCursorOverArea(scaledPoint)) {
return Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
}
if (controlPointMap != null && !controlPointMap.isEmpty()) { if (controlPointMap != null && !controlPointMap.isEmpty()) {
return Cursor.getPredefinedCursor(Cursor.HAND_CURSOR); return Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
} }
for (IDIYComponent<?> component : currentProject.getComponents()) {
if (!isComponentLocked(component)) {
Area area = drawingManager.getComponentArea(component);
if (area != null && area.contains(scaledPoint)) {
return Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
}
}
}
} }
return Cursor.getDefaultCursor(); return Cursor.getDefaultCursor();
} }
@@ -181,6 +188,8 @@ public class Presenter implements IPlugInPort {
updateSelection(ComponentSelection.EMPTY_SELECTION); updateSelection(ComponentSelection.EMPTY_SELECTION);
messageDispatcher.dispatchMessage(EventType.PROJECT_LOADED, project, freshStart); messageDispatcher.dispatchMessage(EventType.PROJECT_LOADED, project, freshStart);
messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.REPAINT);
messageDispatcher.dispatchMessage(EventType.LAYER_STATE_CHANGED, currentProject
.getLockedLayers());
} }
@Override @Override
@@ -296,9 +305,9 @@ public class Presenter implements IPlugInPort {
componentSlotToDraw = instantiationManager.getComponentSlot(); componentSlotToDraw = instantiationManager.getComponentSlot();
} }
drawingManager.drawProject(g2d, currentProject, drawOptions, filter, selectionRect, drawingManager.drawProject(g2d, currentProject, drawOptions, filter, selectionRect,
selectedComponents, groupedComponents, Arrays.asList(instantiationManager selectedComponents, getLockedComponents(), groupedComponents, Arrays.asList(
.getFirstControlPoint(), instantiationManager.getPotentialControlPoint()), instantiationManager.getFirstControlPoint(), instantiationManager
componentSlotToDraw, dragInProgress); .getPotentialControlPoint()), componentSlotToDraw, dragInProgress);
} }
@Override @Override
@@ -323,12 +332,20 @@ public class Presenter implements IPlugInPort {
/** /**
* Finds all components whose areas include the specified {@link Point}. * Finds all components whose areas include the specified {@link Point}.
* Point is <b>not</b> scaled by the zoom factor. * Point is <b>not</b> scaled by the zoom factor. Components that belong to
* locked layers are ignored.
* *
* @return * @return
*/ */
private List<IDIYComponent<?>> findComponentsAt(Point point) { private List<IDIYComponent<?>> findComponentsAt(Point point) {
return drawingManager.findComponentsAt(point, currentProject); List<IDIYComponent<?>> components = drawingManager.findComponentsAt(point, currentProject);
Iterator<IDIYComponent<?>> iterator = components.iterator();
while (iterator.hasNext()) {
if (isComponentLocked(iterator.next())) {
iterator.remove();
}
}
return components;
} }
@Override @Override
@@ -350,12 +367,12 @@ public class Presenter implements IPlugInPort {
componentTypeSlot, scaledPoint, currentProject); componentTypeSlot, scaledPoint, currentProject);
addComponent(component, componentTypeSlot); addComponent(component, componentTypeSlot);
// Select the new component // Select the new component
updateSelection(ComponentSelection.of(component));
// messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
// selectedComponents); // selectedComponents);
// messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED, // messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED,
// calculateSelectionDimension()); // calculateSelectionDimension());
messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.REPAINT);
updateSelection(ComponentSelection.of(component));
} catch (Exception e) { } catch (Exception e) {
LOG.error("Error instatiating component of type: " LOG.error("Error instatiating component of type: "
+ componentTypeSlot.getInstanceClass().getName(), e); + componentTypeSlot.getInstanceClass().getName(), e);
@@ -384,8 +401,9 @@ public class Presenter implements IPlugInPort {
IDIYComponent<?> componentSlot = instantiationManager.getComponentSlot(); IDIYComponent<?> componentSlot = instantiationManager.getComponentSlot();
componentSlot.setControlPoint(scaledPoint, 1); componentSlot.setControlPoint(scaledPoint, 1);
addComponent(componentSlot, componentTypeSlot); addComponent(componentSlot, componentTypeSlot);
// Select the new component // Select the new component if it's not locked.
updateSelection(ComponentSelection.of(componentSlot)); updateSelection(isComponentLocked(componentSlot) ? ComponentSelection.EMPTY_SELECTION
: ComponentSelection.of(componentSlot));
messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.REPAINT);
setNewComponentTypeSlot(null); setNewComponentTypeSlot(null);
} }
@@ -685,7 +703,7 @@ public class Presenter implements IPlugInPort {
// Update all points. // Update all points.
for (Map.Entry<IDIYComponent<?>, Set<Integer>> entry : controlPointMap.entrySet()) { for (Map.Entry<IDIYComponent<?>, Set<Integer>> entry : controlPointMap.entrySet()) {
IDIYComponent<?> c = entry.getKey(); IDIYComponent<?> c = entry.getKey();
drawingManager.invalidateComponent(c); // drawingManager.invalidateComponent(c);
for (Integer index : entry.getValue()) { for (Integer index : entry.getValue()) {
Point p = new Point(c.getControlPoint(index)); Point p = new Point(c.getControlPoint(index));
p.translate(dx, dy); p.translate(dx, dy);
@@ -739,11 +757,13 @@ public class Presenter implements IPlugInPort {
} }
ComponentSelection newSelection = new ComponentSelection(); ComponentSelection newSelection = new ComponentSelection();
for (IDIYComponent<?> component : currentProject.getComponents()) { for (IDIYComponent<?> component : currentProject.getComponents()) {
if (!isComponentLocked(component)) {
Area area = drawingManager.getComponentArea(component); Area area = drawingManager.getComponentArea(component);
if ((area != null) && (selectionRect != null) && area.intersects(selectionRect)) { if ((area != null) && (selectionRect != null) && area.intersects(selectionRect)) {
newSelection.addAll(findAllGroupedComponents(component)); newSelection.addAll(findAllGroupedComponents(component));
} }
} }
}
selectionRect = null; selectionRect = null;
updateSelection(newSelection); updateSelection(newSelection);
// messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, // messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
@@ -864,6 +884,19 @@ public class Presenter implements IPlugInPort {
} }
} }
@Override
public void setLayerLocked(int layerZOrder, boolean locked) {
if (locked) {
currentProject.getLockedLayers().add(layerZOrder);
} else {
currentProject.getLockedLayers().remove(layerZOrder);
}
updateSelection(ComponentSelection.EMPTY_SELECTION);
messageDispatcher.dispatchMessage(EventType.REPAINT);
messageDispatcher.dispatchMessage(EventType.LAYER_STATE_CHANGED, currentProject
.getLockedLayers());
}
/** /**
* Updates the selection with the specified {@link ComponentSelection}. * Updates the selection with the specified {@link ComponentSelection}.
* Also, updates control point map with all components that are stuck to the * Also, updates control point map with all components that are stuck to the
@@ -945,6 +978,8 @@ public class Presenter implements IPlugInPort {
Area componentArea = drawingManager.getComponentArea(component); Area componentArea = drawingManager.getComponentArea(component);
if (componentArea != null) { if (componentArea != null) {
area.add(componentArea); area.add(componentArea);
} else {
LOG.warn("No area found for: " + component.getName());
} }
} }
double width = area.getBounds2D().getWidth(); double width = area.getBounds2D().getWidth();
@@ -1081,6 +1116,22 @@ public class Presenter implements IPlugInPort {
} }
} }
private Set<IDIYComponent<?>> getLockedComponents() {
lockedComponents.clear();
for (IDIYComponent<?> component : currentProject.getComponents()) {
if (isComponentLocked(component)) {
lockedComponents.add(component);
}
}
return lockedComponents;
}
private boolean isComponentLocked(IDIYComponent<?> component) {
ComponentType componentType = componentTypeMap.get(component.getClass().getName());
return currentProject.getLockedLayers().contains(
(int) Math.round(componentType.getZOrder()));
}
/** /**
* Scales point from display base to actual base. * Scales point from display base to actual base.
* *
@@ -23,7 +23,7 @@ public abstract class AbstractBoard extends AbstractTransparentComponent<String>
public static Color BOARD_COLOR = Color.decode("#F8EBB3"); public static Color BOARD_COLOR = Color.decode("#F8EBB3");
public static Color BORDER_COLOR = BOARD_COLOR.darker(); public static Color BORDER_COLOR = BOARD_COLOR.darker();
public static Size DEFAULT_WIDTH = new Size(1.5d, SizeUnit.in); public static Size DEFAULT_WIDTH = new Size(1.5d, SizeUnit.in);
public static Size DEFAULT_HEIGHT = new Size(1d, SizeUnit.in); public static Size DEFAULT_HEIGHT = new Size(1.2d, SizeUnit.in);
protected String value = ""; protected String value = "";
protected Point[] controlPoints = new Point[] { new Point(0, 0), protected Point[] controlPoints = new Point[] { new Point(0, 0),
@@ -0,0 +1,100 @@
package org.diylc.components.boards;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
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.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Eyelet Board", category = "Boards", author = "Branislav Stojkovic", zOrder = IDIYComponent.BOARD, instanceNamePrefix = "Board", description = "Perforated board with eyelets")
public class EyeletBoard extends AbstractBoard {
private static final long serialVersionUID = 1L;
public static Color EYELET_COLOR = Color.decode("#C3E4ED");
public static Size SPACING = new Size(0.3d, SizeUnit.in);
public static Size EYELET_SIZE = new Size(1/8d, SizeUnit.in);
public static Size HOLE_SIZE = new Size(2d, SizeUnit.mm);
// private Area copperArea;
protected Size spacing = SPACING;
protected Color eyeletColor = EYELET_COLOR;
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
super.draw(g2d, componentState, project, drawingObserver);
if (componentState != ComponentState.DRAGGING) {
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
/ MAX_ALPHA));
}
Point p = new Point(firstPoint);
int diameter = getClosestOdd(EYELET_SIZE.convertToPixels());
int holeDiameter = getClosestOdd(HOLE_SIZE.convertToPixels());
int spacing = this.spacing.convertToPixels();
while (p.y < secondPoint.y - spacing) {
p.x = firstPoint.x;
p.y += spacing;
while (p.x < secondPoint.x - spacing) {
p.x += spacing;
g2d.setColor(eyeletColor);
g2d.fillOval(p.x - diameter / 2, p.y - diameter / 2, diameter, diameter);
g2d.setColor(eyeletColor.darker());
g2d.drawOval(p.x - diameter / 2, p.y - diameter / 2, diameter, diameter);
g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(p.x - holeDiameter / 2, p.y - holeDiameter / 2, holeDiameter,
holeDiameter);
g2d.setColor(eyeletColor.darker());
g2d.drawOval(p.x - holeDiameter / 2, p.y - holeDiameter / 2, holeDiameter,
holeDiameter);
}
}
}
}
@EditableProperty(name = "Eyelet color")
public Color getEyeletColor() {
return eyeletColor;
}
public void setEyeletColor(Color padColor) {
this.eyeletColor = padColor;
}
@EditableProperty
public Size getSpacing() {
return spacing;
}
public void setSpacing(Size spacing) {
this.spacing = spacing;
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.setColor(BOARD_COLOR);
g2d.fillRect(2, 2, width - 4, height - 4);
g2d.setColor(BORDER_COLOR);
g2d.drawRect(2, 2, width - 4, height - 4);
g2d.setColor(EYELET_COLOR);
g2d.fillOval(width / 4, width / 4, width / 2, width / 2);
g2d.setColor(EYELET_COLOR.darker());
g2d.drawOval(width / 4, width / 4, width / 2, width / 2);
g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(width / 2 - 2, width / 2 - 2, 5, 5);
g2d.setColor(EYELET_COLOR.darker());
g2d.drawOval(width / 2 - 2, width / 2 - 2, 5, 5);
}
}
@@ -64,7 +64,7 @@ public class PerfBoard extends AbstractBoard {
} }
} }
@EditableProperty(name = "Pad") @EditableProperty(name = "Pad color")
public Color getPadColor() { public Color getPadColor() {
return padColor; return padColor;
} }
@@ -21,7 +21,7 @@ public class VeroBoard extends AbstractBoard {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public static Color COPPER_COLOR = Color.decode("#DA8A67"); public static Color STRIP_COLOR = Color.decode("#DA8A67");
public static Color BORDER_COLOR = BOARD_COLOR.darker(); public static Color BORDER_COLOR = BOARD_COLOR.darker();
public static Size SPACING = new Size(0.1d, SizeUnit.in); public static Size SPACING = new Size(0.1d, SizeUnit.in);
@@ -29,7 +29,7 @@ public class VeroBoard extends AbstractBoard {
public static Size HOLE_SIZE = new Size(0.7d, SizeUnit.mm); public static Size HOLE_SIZE = new Size(0.7d, SizeUnit.mm);
protected Size spacing = SPACING; protected Size spacing = SPACING;
protected Color padColor = COPPER_COLOR; protected Color stripColor = STRIP_COLOR;
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project, public void draw(Graphics2D g2d, ComponentState componentState, Project project,
@@ -50,17 +50,17 @@ public class VeroBoard extends AbstractBoard {
while (p.y < secondPoint.y - spacing) { while (p.y < secondPoint.y - spacing) {
p.x = firstPoint.x; p.x = firstPoint.x;
p.y += spacing; p.y += spacing;
g2d.setColor(padColor); g2d.setColor(stripColor);
g2d.fillRect(p.x + SPACING.convertToPixels() / 2, p.y - stripSize / 2, g2d.fillRect(p.x + SPACING.convertToPixels() / 2, p.y - stripSize / 2,
secondPoint.x - spacing - p.x, stripSize); secondPoint.x - spacing - p.x, stripSize);
g2d.setColor(padColor.darker()); g2d.setColor(stripColor.darker());
g2d.drawRect(p.x + SPACING.convertToPixels() / 2, p.y - stripSize / 2, g2d.drawRect(p.x + SPACING.convertToPixels() / 2, p.y - stripSize / 2,
secondPoint.x - spacing - p.x, stripSize); secondPoint.x - spacing - p.x, stripSize);
while (p.x < secondPoint.x - spacing) { while (p.x < secondPoint.x - spacing) {
p.x += spacing; p.x += spacing;
g2d.setColor(Constants.CANVAS_COLOR); g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(p.x - holeSize / 2, p.y - holeSize / 2, holeSize, holeSize); g2d.fillOval(p.x - holeSize / 2, p.y - holeSize / 2, holeSize, holeSize);
g2d.setColor(padColor.darker()); g2d.setColor(stripColor.darker());
g2d.drawOval(p.x - holeSize / 2, p.y - holeSize / 2, holeSize, holeSize); g2d.drawOval(p.x - holeSize / 2, p.y - holeSize / 2, holeSize, holeSize);
} }
} }
@@ -68,13 +68,13 @@ public class VeroBoard extends AbstractBoard {
} }
} }
@EditableProperty(name = "Pad") @EditableProperty(name = "Strip color")
public Color getPadColor() { public Color getStripColor() {
return padColor; return stripColor;
} }
public void setPadColor(Color padColor) { public void setStripColor(Color padColor) {
this.padColor = padColor; this.stripColor = padColor;
} }
@EditableProperty @EditableProperty
@@ -92,14 +92,14 @@ public class VeroBoard extends AbstractBoard {
g2d.fillRect(2, 2, width - 4, height - 4); g2d.fillRect(2, 2, width - 4, height - 4);
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.drawRect(2, 2, width - 4, height - 4); g2d.drawRect(2, 2, width - 4, height - 4);
g2d.setColor(COPPER_COLOR); g2d.setColor(STRIP_COLOR);
g2d.fillRect(4, width / 4, width - 8, width / 2); g2d.fillRect(4, width / 4, width - 8, width / 2);
g2d.setColor(COPPER_COLOR.darker()); g2d.setColor(STRIP_COLOR.darker());
g2d.drawRect(4, width / 4, width - 8, width / 2); g2d.drawRect(4, width / 4, width - 8, width / 2);
g2d.setColor(Constants.CANVAS_COLOR); g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(width / 3 - 2, width / 2 - 2, 5, 5); g2d.fillOval(width / 3 - 2, width / 2 - 2, 5, 5);
g2d.fillOval(2 * width / 3 - 2, width / 2 - 2, 5, 5); g2d.fillOval(2 * width / 3 - 2, width / 2 - 2, 5, 5);
g2d.setColor(COPPER_COLOR.darker()); g2d.setColor(STRIP_COLOR.darker());
g2d.drawOval(width / 3 - 2, width / 2 - 2, 5, 5); g2d.drawOval(width / 3 - 2, width / 2 - 2, 5, 5);
g2d.drawOval(2 * width / 3 - 2, width / 2 - 2, 5, 5); g2d.drawOval(2 * width / 3 - 2, width / 2 - 2, 5, 5);
} }