This commit is contained in:
bancika
2011-01-03 22:41:30 +00:00
parent 60d5f1747b
commit d248e7b211
5 changed files with 86 additions and 63 deletions
@@ -20,12 +20,12 @@
</entry>
</map>
</entry>
<entry>
<string>lastPath</string>
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
</entry>
<entry>
<string>metric</string>
<boolean>true</boolean>
</entry>
<entry>
<string>lastPath</string>
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
</entry>
</map>
@@ -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;
}
}
@@ -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());
@@ -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<Class<?>, List<ControlPointWrapper>>();
}
/**
* Extracts all editable properties from the component class.
*
* @param clazz
* @return
*/
public List<PropertyWrapper> extractProperties(Class<? extends IComponentInstance> 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<PropertyWrapper> getMutualSelectionProperties(
List<IComponentInstance> 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()) {
@@ -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);
//
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,