auto-increment names

abstract leaded component
This commit is contained in:
bancika
2011-01-03 22:13:56 +00:00
parent 79a48a04e0
commit 60d5f1747b
7 changed files with 167 additions and 59 deletions
@@ -0,0 +1,94 @@
package com.diyfever.diylc.components;
import java.awt.Point;
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.ControlPoint;
import com.diyfever.diylc.model.annotations.EditableProperty;
import com.diyfever.diylc.model.measures.Size;
import com.diyfever.diylc.utils.Constants;
/**
* Base class for all leaded components such as resistors or capacitors. Has two
* control points for leads and one control point for the label.
*
* @author Branislav Stojkovic
*/
public abstract class AbstractLeadedComponentInstance implements IComponentInstance {
private static final long serialVersionUID = 1L;
protected Size width;
protected Size height;
protected Point point1 = new Point(0, 0);
protected Point point2 = new Point(0, (int) (Constants.GRID * 10));
protected Point labelPoint = new Point((int) Constants.GRID, (int) (Constants.GRID * 5));
protected String name = "New Component";
protected AbstractLeadedComponentInstance() {
super();
this.width = getDefaultWidth();
this.height = getDefaultHeight();
}
protected abstract Size getDefaultWidth();
protected abstract Size getDefaultHeight();
@BomName
@EditableProperty
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@ControlPoint(visibilityPolicy = VisibilityPolicy.WHEN_SELECTED)
public Point getPoint1() {
return point1;
}
public void setPoint1(Point point1) {
this.point1 = point1;
}
@ControlPoint(visibilityPolicy = VisibilityPolicy.WHEN_SELECTED)
public Point getPoint2() {
return point2;
}
public void setPoint2(Point point2) {
this.point2 = point2;
}
@ControlPoint(visibilityPolicy = VisibilityPolicy.WHEN_SELECTED)
public Point getLabelPoint() {
return labelPoint;
}
public void setLabelPoint(Point labelPoint) {
this.labelPoint = labelPoint;
}
@EditableProperty(defaultable = true)
public Size getWidth() {
return width;
}
public void setWidth(Size width) {
this.width = width;
}
@EditableProperty(defaultable = true)
public Size getHeight() {
return height;
}
public void setHeight(Size height) {
this.height = height;
}
}
@@ -13,6 +13,11 @@ public class MockComponentType implements IComponentType {
public Class<? extends IComponentInstance> getComponentInstanceClass() {
return MockComponentInstance.class;
}
@Override
public String getInstanceNamePrefix() {
return "ABC";
}
@Override
public ComponentLayer getComponentLayer() {
@@ -20,7 +20,7 @@ import com.diyfever.diylc.model.measures.Size;
import com.diyfever.diylc.model.measures.SizeUnit;
import com.diyfever.diylc.utils.Constants;
public class ResistorInstance implements IComponentInstance {
public class ResistorInstance extends AbstractLeadedComponentInstance {
private static final long serialVersionUID = 1L;
@@ -29,53 +29,11 @@ public class ResistorInstance implements IComponentInstance {
private Resistance r = new Resistance(123d, ResistanceUnit.K);
private Size s = new Size(1d, SizeUnit.cm);
private Color color = Color.green;
private Point leftTopCorner = new Point(0, 0);
private Point otherCorner = new Point((int) (Constants.GRID * 10), (int) (Constants.GRID * 10));
private String name = "something";
public ResistorInstance(String testField, Capacitance c, Resistance r, Size s, Color color,
Point leftTopCorner) {
super();
this.testField = testField;
this.c = c;
this.r = r;
this.s = s;
this.color = color;
this.leftTopCorner = leftTopCorner;
}
public ResistorInstance() {
super();
}
@BomName
@EditableProperty
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@ControlPoint(visibilityPolicy = VisibilityPolicy.ALWAYS)
public Point getLeftTopCorner() {
return leftTopCorner;
}
public void setLeftTopCorner(Point leftTopCorner) {
this.leftTopCorner = leftTopCorner;
}
@ControlPoint(visibilityPolicy = VisibilityPolicy.ALWAYS)
public Point getOtherCorner() {
return otherCorner;
}
public void setOtherCorner(Point otherCorner) {
this.otherCorner = otherCorner;
}
@EditableProperty(name = "Test Field")
public String getTestField() {
return testField;
@@ -126,21 +84,22 @@ public class ResistorInstance implements IComponentInstance {
@Override
public void draw(Graphics2D g2d, ComponentState componentState) {
g2d.setColor(componentState.equals(ComponentState.SELECTED) ? color : color.darker());
g2d.setStroke(new BasicStroke(2));
g2d.setStroke(new BasicStroke(1));
if (componentState == ComponentState.DRAGGING) {
g2d.setStroke(new BasicStroke(1));
}
g2d.drawLine(leftTopCorner.x, leftTopCorner.y, otherCorner.x, otherCorner.y);
g2d.rotate(Math.PI / 4, (leftTopCorner.x + otherCorner.x) / 2,
(leftTopCorner.y + otherCorner.y) / 2);
g2d.fillRect((leftTopCorner.x + otherCorner.x) / 2 - 10,
(leftTopCorner.y + otherCorner.y) / 2 - 10, 20, 20);
g2d.drawLine(point1.x, point1.y, point2.x, point2.y);
g2d.rotate(Math.PI / 4, (point1.x + point2.x) / 2, (point1.y + point2.y) / 2);
g2d.fillRect((point1.x + point2.x) / 2 - 10, (point1.y + point2.y) / 2 - 10, 20, 20);
}
@Override
public ResistorInstance clone() throws CloneNotSupportedException {
ResistorInstance newInstance = new ResistorInstance(testField, c.clone(), r.clone(), s
.clone(), color, (Point) leftTopCorner.clone());
return newInstance;
protected Size getDefaultHeight() {
return new Size(3d, SizeUnit.mm);
}
@Override
protected Size getDefaultWidth() {
return new Size(10d, SizeUnit.mm);
}
}
@@ -13,6 +13,11 @@ public class ResistorType implements IComponentType {
public Class<? extends IComponentInstance> getComponentInstanceClass() {
return ResistorInstance.class;
}
@Override
public String getInstanceNamePrefix() {
return "R";
}
@Override
public ComponentLayer getComponentLayer() {