mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
package renamed
This commit is contained in:
+130
@@ -0,0 +1,130 @@
|
||||
package org.diylc.components;
|
||||
|
||||
import java.awt.Point;
|
||||
|
||||
import org.diylc.model.IComponentInstance;
|
||||
import org.diylc.model.VisibilityPolicy;
|
||||
import org.diylc.model.annotations.BomName;
|
||||
import org.diylc.model.annotations.ControlPoint;
|
||||
import org.diylc.model.annotations.EditableProperty;
|
||||
import org.diylc.model.measures.Size;
|
||||
import org.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((int) (Constants.GRID * 10), 0);
|
||||
protected Point labelPoint = new Point((int) (Constants.GRID * 5), -(int) Constants.GRID);
|
||||
protected String name = "New Component";
|
||||
|
||||
protected AbstractLeadedComponentInstance() {
|
||||
super();
|
||||
this.width = getDefaultWidth();
|
||||
this.height = getDefaultHeight();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default component width.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract Size getDefaultWidth();
|
||||
|
||||
/**
|
||||
* Returns the default component height.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
package org.diylc.components;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
|
||||
import org.diylc.model.ComponentState;
|
||||
import org.diylc.model.IComponentInstance;
|
||||
import org.diylc.model.VisibilityPolicy;
|
||||
import org.diylc.model.annotations.BomName;
|
||||
import org.diylc.model.annotations.BomValue;
|
||||
import org.diylc.model.annotations.ControlPoint;
|
||||
import org.diylc.model.annotations.EditableProperty;
|
||||
import org.diylc.model.measures.Capacitance;
|
||||
import org.diylc.model.measures.CapacitanceUnit;
|
||||
import org.diylc.model.measures.Resistance;
|
||||
import org.diylc.model.measures.ResistanceUnit;
|
||||
import org.diylc.model.measures.Size;
|
||||
import org.diylc.model.measures.SizeUnit;
|
||||
|
||||
|
||||
public class MockComponentInstance implements IComponentInstance {
|
||||
|
||||
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;
|
||||
private Point leftTopCorner = new Point(0, 0);
|
||||
private String name = "something";
|
||||
|
||||
public MockComponentInstance(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 MockComponentInstance() {
|
||||
super();
|
||||
}
|
||||
|
||||
@BomName
|
||||
@EditableProperty
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@ControlPoint(visibilityPolicy = VisibilityPolicy.WHEN_SELECTED)
|
||||
public Point getLeftTopCorner() {
|
||||
return leftTopCorner;
|
||||
}
|
||||
|
||||
public void setLeftTopCorner(Point leftTopCorner) {
|
||||
this.leftTopCorner = leftTopCorner;
|
||||
}
|
||||
|
||||
@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());
|
||||
g2d.fillRect(leftTopCorner.x, leftTopCorner.y, 200, 50);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MockComponentInstance clone() throws CloneNotSupportedException {
|
||||
MockComponentInstance newInstance = new MockComponentInstance(testField, c.clone(), r
|
||||
.clone(), s.clone(), color, (Point) leftTopCorner.clone());
|
||||
return newInstance;
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package org.diylc.components;
|
||||
|
||||
import javax.swing.Icon;
|
||||
|
||||
import org.diylc.images.IconLoader;
|
||||
import org.diylc.model.ComponentLayer;
|
||||
import org.diylc.model.IComponentInstance;
|
||||
import org.diylc.model.IComponentType;
|
||||
|
||||
|
||||
public class MockComponentType implements IComponentType {
|
||||
|
||||
@Override
|
||||
public Class<? extends IComponentInstance> getComponentInstanceClass() {
|
||||
return MockComponentInstance.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInstanceNamePrefix() {
|
||||
return "ABC";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComponentLayer getComponentLayer() {
|
||||
return ComponentLayer.BOARD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Some description";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return IconLoader.Gears.getIcon();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Mock Component";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCategory() {
|
||||
return "Samples";
|
||||
}
|
||||
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package org.diylc.components;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
import org.diylc.model.ComponentState;
|
||||
import org.diylc.model.annotations.EditableProperty;
|
||||
import org.diylc.model.measures.Resistance;
|
||||
import org.diylc.model.measures.ResistanceUnit;
|
||||
import org.diylc.model.measures.Size;
|
||||
import org.diylc.model.measures.SizeUnit;
|
||||
|
||||
|
||||
public class ResistorInstance extends AbstractLeadedComponentInstance {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Resistance r = new Resistance(123d, ResistanceUnit.K);
|
||||
private Color color = Color.green;
|
||||
|
||||
public ResistorInstance() {
|
||||
super();
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Resistance getR() {
|
||||
return r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState) {
|
||||
g2d.setColor(componentState.equals(ComponentState.SELECTED) ? color : color.darker());
|
||||
g2d.setStroke(new BasicStroke(1));
|
||||
if (componentState == ComponentState.DRAGGING) {
|
||||
g2d.setStroke(new BasicStroke(1));
|
||||
}
|
||||
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
|
||||
protected Size getDefaultHeight() {
|
||||
return new Size(3d, SizeUnit.mm);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Size getDefaultWidth() {
|
||||
return new Size(10d, SizeUnit.mm);
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package org.diylc.components;
|
||||
|
||||
import javax.swing.Icon;
|
||||
|
||||
import org.diylc.images.IconLoader;
|
||||
import org.diylc.model.ComponentLayer;
|
||||
import org.diylc.model.IComponentInstance;
|
||||
import org.diylc.model.IComponentType;
|
||||
|
||||
|
||||
public class ResistorType implements IComponentType {
|
||||
|
||||
@Override
|
||||
public Class<? extends IComponentInstance> getComponentInstanceClass() {
|
||||
return ResistorInstance.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInstanceNamePrefix() {
|
||||
return "R";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComponentLayer getComponentLayer() {
|
||||
return ComponentLayer.COMPONENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Some description";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return IconLoader.Gears.getIcon();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Resistor";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCategory() {
|
||||
return "Samples";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user