diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/config.xml b/ diy-layout-creator --username bancika@gmail.com/DIYLC/config.xml index 5a1e99f0..daf4afdf 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/config.xml +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/config.xml @@ -20,12 +20,12 @@ - - lastPath - C:\Documents and Settings\Branislav Stojkovic\Desktop - metric true + + lastPath + C:\Documents and Settings\Branislav Stojkovic\Desktop + \ No newline at end of file diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src.library/com/diyfever/diylc/components/AbstractLeadedComponentInstance.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src.library/com/diyfever/diylc/components/AbstractLeadedComponentInstance.java index dcd92bc7..7ba323f8 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src.library/com/diyfever/diylc/components/AbstractLeadedComponentInstance.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src.library/com/diyfever/diylc/components/AbstractLeadedComponentInstance.java @@ -33,8 +33,18 @@ public abstract class AbstractLeadedComponentInstance implements IComponentInsta this.height = getDefaultHeight(); } + /** + * Returns the default component width. + * + * @return + */ protected abstract Size getDefaultWidth(); + /** + * Returns the default component height. + * + * @return + */ protected abstract Size getDefaultHeight(); @BomName @@ -91,4 +101,29 @@ public abstract class AbstractLeadedComponentInstance implements IComponentInsta public void setHeight(Size height) { this.height = height; } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + AbstractLeadedComponentInstance other = (AbstractLeadedComponentInstance) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src.library/com/diyfever/diylc/components/ResistorInstance.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src.library/com/diyfever/diylc/components/ResistorInstance.java index 556691a5..dac75a38 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src.library/com/diyfever/diylc/components/ResistorInstance.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src.library/com/diyfever/diylc/components/ResistorInstance.java @@ -3,84 +3,30 @@ package com.diyfever.diylc.components; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; -import java.awt.Point; import com.diyfever.diylc.model.ComponentState; -import com.diyfever.diylc.model.IComponentInstance; -import com.diyfever.diylc.model.VisibilityPolicy; -import com.diyfever.diylc.model.annotations.BomName; -import com.diyfever.diylc.model.annotations.BomValue; -import com.diyfever.diylc.model.annotations.ControlPoint; import com.diyfever.diylc.model.annotations.EditableProperty; -import com.diyfever.diylc.model.measures.Capacitance; -import com.diyfever.diylc.model.measures.CapacitanceUnit; import com.diyfever.diylc.model.measures.Resistance; import com.diyfever.diylc.model.measures.ResistanceUnit; import com.diyfever.diylc.model.measures.Size; import com.diyfever.diylc.model.measures.SizeUnit; -import com.diyfever.diylc.utils.Constants; public class ResistorInstance extends AbstractLeadedComponentInstance { private static final long serialVersionUID = 1L; - private String testField = "Hello World"; - private Capacitance c = new Capacitance(100d, CapacitanceUnit.uF); private Resistance r = new Resistance(123d, ResistanceUnit.K); - private Size s = new Size(1d, SizeUnit.cm); private Color color = Color.green; public ResistorInstance() { super(); } - @EditableProperty(name = "Test Field") - public String getTestField() { - return testField; - } - - public void setTestField(String testField) { - this.testField = testField; - } - - @BomValue - @EditableProperty(defaultable = true) - public Capacitance getC() { - return c; - } - - public void setC(Capacitance c) { - this.c = c; - } - - @EditableProperty(defaultable = true) - public Color getColor() { - return color; - } - - public void setColor(Color color) { - this.color = color; - } - @EditableProperty public Resistance getR() { return r; } - // Setter is commented out, ClassProcessor should ignore this property. - // public void setR(Resistance r) { - // this.r = r; - // } - - // No annotation, so this property should be ignored. - public Size getS() { - return s; - } - - public void setS(Size s) { - this.s = s; - } - @Override public void draw(Graphics2D g2d, ComponentState componentState) { g2d.setColor(componentState.equals(ComponentState.SELECTED) ? color : color.darker()); diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/presenter/ComponentProcessor.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/presenter/ComponentProcessor.java index cbbf10e2..2f04aabc 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/presenter/ComponentProcessor.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/presenter/ComponentProcessor.java @@ -18,6 +18,11 @@ import com.diyfever.diylc.model.annotations.ControlPoint; import com.diyfever.diylc.model.annotations.EditableProperty; import com.rits.cloning.Cloner; +/** + * Utility class with component processing methods. + * + * @author Branislav Stojkovic + */ public class ComponentProcessor { private static final Logger LOG = Logger.getLogger(ComponentProcessor.class); @@ -43,6 +48,12 @@ public class ComponentProcessor { this.controlPointCache = new HashMap, List>(); } + /** + * Extracts all editable properties from the component class. + * + * @param clazz + * @return + */ public List extractProperties(Class clazz) { if (propertyCache.containsKey(clazz)) { return cloner.deepClone(propertyCache.get(clazz)); @@ -118,6 +129,12 @@ public class ComponentProcessor { return cloner.deepClone(controlPoints); } + /** + * Returns properties mutual for all the selected components. + * + * @param selectedComponents + * @return + */ public List getMutualSelectionProperties( List selectedComponents) { if (selectedComponents.isEmpty()) { @@ -159,6 +176,13 @@ public class ComponentProcessor { return properties; } + /** + * Finds the method annotated with {@link BomName} annotations and calls it + * to retrieve component name. + * + * @param component + * @return + */ public String extractBomName(IComponentInstance component) { String name = null; for (Method method : component.getClass().getMethods()) { @@ -173,6 +197,13 @@ public class ComponentProcessor { return name; } + /** + * Finds the method annotated with {@link BomName} and it's matching setter + * and calls the setter to update the component name. + * + * @param component + * @param newBomName + */ public void writeBomName(IComponentInstance component, String newBomName) { for (Method method : component.getClass().getMethods()) { if (method.isAnnotationPresent(BomName.class)) { @@ -186,6 +217,13 @@ public class ComponentProcessor { } } + /** + * Finds the method annotated with {@link BomValue} annotations and calls it + * to retrieve component value. + * + * @param component + * @return + */ public String extractBomValue(IComponentInstance component) { String value = null; for (Method method : component.getClass().getMethods()) { diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/presenter/Presenter.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/presenter/Presenter.java index 35b16fac..0b052a88 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/presenter/Presenter.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/presenter/Presenter.java @@ -474,14 +474,17 @@ public class Presenter implements IPlugInPort { @Override public boolean dragOver(Point point) { + if (point == null) { + return false; + } Point scaledPoint = scalePoint(point); if (!componentControlPointMap.isEmpty()) { - // We're dragging control point(s). - // int dx = (int) ((point.x - dragStartPoint.x) / zoomLevel); - // int dy = (int) ((point.y - dragStartPoint.y) / zoomLevel); - // + // We're dragging control point(s). IComponentInstance firstComponent = componentControlPointMap.keySet().iterator().next(); ControlPointWrapper controlPoint = componentControlPointMap.get(firstComponent); + if (controlPoint == null) { + LOG.warn("Control point not found in the map!"); + } // Re-read the value just in case. try { controlPoint.readFrom(firstComponent); @@ -764,7 +767,8 @@ public class Presenter implements IPlugInPort { * @return */ private Point scalePoint(Point point) { - return new Point((int) (point.x / zoomLevel), (int) (point.y / zoomLevel)); + return point == null ? null : new Point((int) (point.x / zoomLevel), + (int) (point.y / zoomLevel)); } private boolean shouldShowControlPoint(ControlPointWrapper controlPoint,