mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
refactored component framework
This commit is contained in:
+4
-4
@@ -2,7 +2,7 @@ package org.diylc.components;
|
||||
|
||||
import java.awt.Point;
|
||||
|
||||
import org.diylc.core.IComponentInstance;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.VisibilityPolicy;
|
||||
import org.diylc.core.annotations.BomName;
|
||||
import org.diylc.core.annotations.ControlPoint;
|
||||
@@ -17,7 +17,7 @@ import org.diylc.utils.Constants;
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
public abstract class AbstractLeadedComponentInstance implements IComponentInstance {
|
||||
public abstract class AbstractLeadedDIYComponent implements IDIYComponent {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -28,7 +28,7 @@ public abstract class AbstractLeadedComponentInstance implements IComponentInsta
|
||||
protected Point labelPoint = new Point((int) (Constants.GRID * 5), -(int) Constants.GRID);
|
||||
protected String name = "New Component";
|
||||
|
||||
protected AbstractLeadedComponentInstance() {
|
||||
protected AbstractLeadedDIYComponent() {
|
||||
super();
|
||||
this.width = getDefaultWidth();
|
||||
this.height = getDefaultHeight();
|
||||
@@ -119,7 +119,7 @@ public abstract class AbstractLeadedComponentInstance implements IComponentInsta
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
AbstractLeadedComponentInstance other = (AbstractLeadedComponentInstance) obj;
|
||||
AbstractLeadedDIYComponent other = (AbstractLeadedDIYComponent) obj;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
package org.diylc.components;
|
||||
|
||||
import javax.swing.Icon;
|
||||
|
||||
import org.diylc.core.ComponentLayer;
|
||||
import org.diylc.core.IComponentInstance;
|
||||
import org.diylc.core.IComponentType;
|
||||
import org.diylc.images.IconLoader;
|
||||
|
||||
|
||||
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";
|
||||
}
|
||||
|
||||
}
|
||||
+8
-9
@@ -5,10 +5,11 @@ import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IComponentInstance;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.VisibilityPolicy;
|
||||
import org.diylc.core.annotations.BomName;
|
||||
import org.diylc.core.annotations.BomValue;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.ControlPoint;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.measures.Capacitance;
|
||||
@@ -18,8 +19,8 @@ import org.diylc.core.measures.ResistanceUnit;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
|
||||
|
||||
public class MockComponentInstance implements IComponentInstance {
|
||||
@ComponentDescriptor(name = "Mock", author = "bancika", category = "Sample", instanceNamePrefix = "M", desciption = "test")
|
||||
public class MockDIYComponent implements IDIYComponent {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -31,7 +32,7 @@ public class MockComponentInstance implements IComponentInstance {
|
||||
private Point leftTopCorner = new Point(0, 0);
|
||||
private String name = "something";
|
||||
|
||||
public MockComponentInstance(String testField, Capacitance c, Resistance r, Size s,
|
||||
public MockDIYComponent(String testField, Capacitance c, Resistance r, Size s,
|
||||
Color color, Point leftTopCorner) {
|
||||
super();
|
||||
this.testField = testField;
|
||||
@@ -42,7 +43,7 @@ public class MockComponentInstance implements IComponentInstance {
|
||||
this.leftTopCorner = leftTopCorner;
|
||||
}
|
||||
|
||||
public MockComponentInstance() {
|
||||
public MockDIYComponent() {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -119,9 +120,7 @@ public class MockComponentInstance implements IComponentInstance {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MockComponentInstance clone() throws CloneNotSupportedException {
|
||||
MockComponentInstance newInstance = new MockComponentInstance(testField, c.clone(), r
|
||||
.clone(), s.clone(), color, (Point) leftTopCorner.clone());
|
||||
return newInstance;
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
g2d.drawString("X", 10, 10);
|
||||
}
|
||||
}
|
||||
+9
-3
@@ -5,21 +5,22 @@ import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.measures.Resistance;
|
||||
import org.diylc.core.measures.ResistanceUnit;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
|
||||
|
||||
public class ResistorInstance extends AbstractLeadedComponentInstance {
|
||||
@ComponentDescriptor(name = "Resistor", author = "bancika", category = "Passive", instanceNamePrefix = "R", desciption = "test")
|
||||
public class Resistor extends AbstractLeadedDIYComponent {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Resistance r = new Resistance(123d, ResistanceUnit.K);
|
||||
private Color color = Color.green;
|
||||
|
||||
public ResistorInstance() {
|
||||
public Resistor() {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -40,6 +41,11 @@ public class ResistorInstance extends AbstractLeadedComponentInstance {
|
||||
g2d.fillRect((point1.x + point2.x) / 2 - 10, (point1.y + point2.y) / 2 - 10, 20, 20);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
g2d.drawString("R", 10, 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Size getDefaultHeight() {
|
||||
return new Size(3d, SizeUnit.mm);
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
package org.diylc.components;
|
||||
|
||||
import javax.swing.Icon;
|
||||
|
||||
import org.diylc.core.ComponentLayer;
|
||||
import org.diylc.core.IComponentInstance;
|
||||
import org.diylc.core.IComponentType;
|
||||
import org.diylc.images.IconLoader;
|
||||
|
||||
|
||||
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