mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
doc
This commit is contained in:
@@ -20,12 +20,12 @@
|
|||||||
</entry>
|
</entry>
|
||||||
</map>
|
</map>
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
|
||||||
<string>lastPath</string>
|
|
||||||
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
|
|
||||||
</entry>
|
|
||||||
<entry>
|
<entry>
|
||||||
<string>metric</string>
|
<string>metric</string>
|
||||||
<boolean>true</boolean>
|
<boolean>true</boolean>
|
||||||
</entry>
|
</entry>
|
||||||
|
<entry>
|
||||||
|
<string>lastPath</string>
|
||||||
|
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
|
||||||
|
</entry>
|
||||||
</map>
|
</map>
|
||||||
+35
@@ -33,8 +33,18 @@ public abstract class AbstractLeadedComponentInstance implements IComponentInsta
|
|||||||
this.height = getDefaultHeight();
|
this.height = getDefaultHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the default component width.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
protected abstract Size getDefaultWidth();
|
protected abstract Size getDefaultWidth();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the default component height.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
protected abstract Size getDefaultHeight();
|
protected abstract Size getDefaultHeight();
|
||||||
|
|
||||||
@BomName
|
@BomName
|
||||||
@@ -91,4 +101,29 @@ public abstract class AbstractLeadedComponentInstance implements IComponentInsta
|
|||||||
public void setHeight(Size height) {
|
public void setHeight(Size height) {
|
||||||
this.height = 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-54
@@ -3,84 +3,30 @@ package com.diyfever.diylc.components;
|
|||||||
import java.awt.BasicStroke;
|
import java.awt.BasicStroke;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Point;
|
|
||||||
|
|
||||||
import com.diyfever.diylc.model.ComponentState;
|
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.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.Resistance;
|
||||||
import com.diyfever.diylc.model.measures.ResistanceUnit;
|
import com.diyfever.diylc.model.measures.ResistanceUnit;
|
||||||
import com.diyfever.diylc.model.measures.Size;
|
import com.diyfever.diylc.model.measures.Size;
|
||||||
import com.diyfever.diylc.model.measures.SizeUnit;
|
import com.diyfever.diylc.model.measures.SizeUnit;
|
||||||
import com.diyfever.diylc.utils.Constants;
|
|
||||||
|
|
||||||
public class ResistorInstance extends AbstractLeadedComponentInstance {
|
public class ResistorInstance extends AbstractLeadedComponentInstance {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
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 Resistance r = new Resistance(123d, ResistanceUnit.K);
|
||||||
private Size s = new Size(1d, SizeUnit.cm);
|
|
||||||
private Color color = Color.green;
|
private Color color = Color.green;
|
||||||
|
|
||||||
public ResistorInstance() {
|
public ResistorInstance() {
|
||||||
super();
|
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
|
@EditableProperty
|
||||||
public Resistance getR() {
|
public Resistance getR() {
|
||||||
return r;
|
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
|
@Override
|
||||||
public void draw(Graphics2D g2d, ComponentState componentState) {
|
public void draw(Graphics2D g2d, ComponentState componentState) {
|
||||||
g2d.setColor(componentState.equals(ComponentState.SELECTED) ? color : color.darker());
|
g2d.setColor(componentState.equals(ComponentState.SELECTED) ? color : color.darker());
|
||||||
|
|||||||
+38
@@ -18,6 +18,11 @@ import com.diyfever.diylc.model.annotations.ControlPoint;
|
|||||||
import com.diyfever.diylc.model.annotations.EditableProperty;
|
import com.diyfever.diylc.model.annotations.EditableProperty;
|
||||||
import com.rits.cloning.Cloner;
|
import com.rits.cloning.Cloner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility class with component processing methods.
|
||||||
|
*
|
||||||
|
* @author Branislav Stojkovic
|
||||||
|
*/
|
||||||
public class ComponentProcessor {
|
public class ComponentProcessor {
|
||||||
|
|
||||||
private static final Logger LOG = Logger.getLogger(ComponentProcessor.class);
|
private static final Logger LOG = Logger.getLogger(ComponentProcessor.class);
|
||||||
@@ -43,6 +48,12 @@ public class ComponentProcessor {
|
|||||||
this.controlPointCache = new HashMap<Class<?>, List<ControlPointWrapper>>();
|
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) {
|
public List<PropertyWrapper> extractProperties(Class<? extends IComponentInstance> clazz) {
|
||||||
if (propertyCache.containsKey(clazz)) {
|
if (propertyCache.containsKey(clazz)) {
|
||||||
return cloner.deepClone(propertyCache.get(clazz));
|
return cloner.deepClone(propertyCache.get(clazz));
|
||||||
@@ -118,6 +129,12 @@ public class ComponentProcessor {
|
|||||||
return cloner.deepClone(controlPoints);
|
return cloner.deepClone(controlPoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns properties mutual for all the selected components.
|
||||||
|
*
|
||||||
|
* @param selectedComponents
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public List<PropertyWrapper> getMutualSelectionProperties(
|
public List<PropertyWrapper> getMutualSelectionProperties(
|
||||||
List<IComponentInstance> selectedComponents) {
|
List<IComponentInstance> selectedComponents) {
|
||||||
if (selectedComponents.isEmpty()) {
|
if (selectedComponents.isEmpty()) {
|
||||||
@@ -159,6 +176,13 @@ public class ComponentProcessor {
|
|||||||
return properties;
|
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) {
|
public String extractBomName(IComponentInstance component) {
|
||||||
String name = null;
|
String name = null;
|
||||||
for (Method method : component.getClass().getMethods()) {
|
for (Method method : component.getClass().getMethods()) {
|
||||||
@@ -173,6 +197,13 @@ public class ComponentProcessor {
|
|||||||
return name;
|
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) {
|
public void writeBomName(IComponentInstance component, String newBomName) {
|
||||||
for (Method method : component.getClass().getMethods()) {
|
for (Method method : component.getClass().getMethods()) {
|
||||||
if (method.isAnnotationPresent(BomName.class)) {
|
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) {
|
public String extractBomValue(IComponentInstance component) {
|
||||||
String value = null;
|
String value = null;
|
||||||
for (Method method : component.getClass().getMethods()) {
|
for (Method method : component.getClass().getMethods()) {
|
||||||
|
|||||||
+8
-4
@@ -474,14 +474,17 @@ public class Presenter implements IPlugInPort {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dragOver(Point point) {
|
public boolean dragOver(Point point) {
|
||||||
|
if (point == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Point scaledPoint = scalePoint(point);
|
Point scaledPoint = scalePoint(point);
|
||||||
if (!componentControlPointMap.isEmpty()) {
|
if (!componentControlPointMap.isEmpty()) {
|
||||||
// We're dragging control point(s).
|
// 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();
|
IComponentInstance firstComponent = componentControlPointMap.keySet().iterator().next();
|
||||||
ControlPointWrapper controlPoint = componentControlPointMap.get(firstComponent);
|
ControlPointWrapper controlPoint = componentControlPointMap.get(firstComponent);
|
||||||
|
if (controlPoint == null) {
|
||||||
|
LOG.warn("Control point not found in the map!");
|
||||||
|
}
|
||||||
// Re-read the value just in case.
|
// Re-read the value just in case.
|
||||||
try {
|
try {
|
||||||
controlPoint.readFrom(firstComponent);
|
controlPoint.readFrom(firstComponent);
|
||||||
@@ -764,7 +767,8 @@ public class Presenter implements IPlugInPort {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private Point scalePoint(Point point) {
|
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,
|
private boolean shouldShowControlPoint(ControlPointWrapper controlPoint,
|
||||||
|
|||||||
Reference in New Issue
Block a user