moving library to new project

This commit is contained in:
bancika
2011-01-07 16:37:37 +00:00
parent a6b378c173
commit a5c5296365
9 changed files with 0 additions and 793 deletions
@@ -2,7 +2,6 @@
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/> <classpathentry kind="src" path="test"/>
<classpathentry kind="src" path="src.library"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/log4j-1.2.15.jar"/> <classpathentry kind="lib" path="lib/log4j-1.2.15.jar"/>
<classpathentry kind="lib" path="lib/xstream-1.3.1.jar"/> <classpathentry kind="lib" path="lib/xstream-1.3.1.jar"/>
@@ -1,182 +0,0 @@
package org.diylc.components;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Shape;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.Project;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.utils.Constants;
/**
* Base class for all leaded components such as resistors or capacitors. Has two
* control points and draws leads between them. Also, it positions and draws the
* shape of the component as specified by a child class.
*
* @author Branislav Stojkovic
*/
public abstract class AbstractLeadedDIYComponent<T> implements IDIYComponent<T> {
private static final long serialVersionUID = 1L;
public static Color LEAD_COLOR = Color.black;
public static Color LABEL_COLOR = Color.black;
public static Color LABEL_COLOR_SELECTED = Color.red;
protected Size width;
protected Size height;
protected Point[] points = new Point[] { new Point(0, 0),
new Point((int) (Constants.GRID * 10), 0) };
protected String name = "New Component";
protected AbstractLeadedDIYComponent() {
super();
try {
this.width = getDefaultWidth().clone();
this.height = getDefaultHeight().clone();
} catch (CloneNotSupportedException e) {
// This should never happen because Size supports cloning.
}
}
/**
* @return default component width.
*/
protected abstract Size getDefaultWidth();
/**
* Returns default component height.
*
* @return
*/
protected abstract Size getDefaultHeight();
/**
* @return shape that represents component body. Shape should not be
* transformed and should be referenced to (0, 0).
*/
protected abstract Shape getComponentShape();
/**
* @return component body color.
*/
protected abstract Color getBodyColor();
/**
* @return component border color.
*/
protected abstract Color getBorderColor();
@Override
public int getControlPointCount() {
return points.length;
}
@Override
public Point getControlPoint(int index) {
return (Point) points[index].clone();
}
@Override
public void setControlPoint(Point point, int index) {
points[index].setLocation(point);
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project) {
g2d.setColor(LEAD_COLOR);
g2d.setStroke(new BasicStroke(1));
double distance = points[0].distance(points[1]);
Shape shape = getComponentShape();
Rectangle shapeRect = shape.getBounds();
double leadLenght = (distance - shapeRect.width) / 2;
Double theta;
theta = Math.atan2(points[1].y - points[0].y, points[1].x - points[0].x);
// Draw leads.
g2d.drawLine(points[0].x, points[0].y, (int) (points[0].x + leadLenght * Math.cos(theta)),
(int) (points[0].y + leadLenght * Math.sin(theta)));
g2d.drawLine(points[1].x, points[1].y, (int) (points[1].x - leadLenght * Math.cos(theta)),
(int) (points[1].y - leadLenght * Math.sin(theta)));
// Transform graphics to draw the body in the right place and at the
// right angle.
g2d.translate((points[0].x + points[1].x - shapeRect.width) / 2,
(points[0].y + points[1].y - shapeRect.height) / 2);
g2d.rotate(theta, shapeRect.width / 2, shapeRect.height / 2);
// Draw body.
if (componentState != ComponentState.DRAGGING) {
g2d.setColor(getBodyColor());
g2d.fill(shape);
}
g2d.setColor(getBorderColor());
g2d.draw(shape);
// Draw label.
g2d.setFont(Constants.LABEL_FONT);
g2d
.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED
: LABEL_COLOR);
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
java.awt.geom.Rectangle2D textRect = fontMetrics.getStringBounds(getName(), g2d);
g2d.drawString(getName(), (int) (shapeRect.width - textRect.getWidth()) / 2,
(int) (shapeRect.height - textRect.getHeight()) / 2 + fontMetrics.getAscent());
}
@EditableProperty(defaultable = false)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@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;
}
@SuppressWarnings("unchecked")
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
AbstractLeadedDIYComponent other = (AbstractLeadedDIYComponent) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
}
@@ -1,69 +0,0 @@
package org.diylc.components;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Capacitance;
import org.diylc.core.measures.CapacitanceUnit;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Axial Film Capacitor", author = "bancika", category = "Passive", instanceNamePrefix = "C", desciption = "test")
public class AxialFilmCapacitor extends AbstractLeadedDIYComponent<Capacitance> {
private static final long serialVersionUID = 1L;
public static Size DEFAULT_WIDTH = new Size(1d / 2, SizeUnit.in);
public static Size DEFAULT_HEIGHT = new Size(1d / 8, SizeUnit.in);
public static Color BODY_COLOR = Color.decode("#FFE303");
public static Color BORDER_COLOR = BODY_COLOR.darker();
private Capacitance value = new Capacitance(123d, CapacitanceUnit.nF);
public AxialFilmCapacitor() {
super();
}
@EditableProperty
public Capacitance getValue() {
return value;
}
public void setValue(Capacitance value) {
this.value = value;
}
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.drawString("C", 10, 10);
}
@Override
protected Size getDefaultHeight() {
return DEFAULT_HEIGHT;
}
@Override
protected Size getDefaultWidth() {
return DEFAULT_WIDTH;
}
@Override
protected Color getBodyColor() {
return BODY_COLOR;
}
@Override
protected Color getBorderColor() {
return BORDER_COLOR;
}
@Override
protected Shape getComponentShape() {
return new Rectangle2D.Double(0f, 0f, getWidth().convertToPixels(), getHeight()
.convertToPixels());
}
}
@@ -1,206 +0,0 @@
package org.diylc.components;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.Rectangle2D;
import org.diylc.common.Orientation;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.Project;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
@ComponentDescriptor(name = "DIL IC", author = "bancika", category = "Semiconductors", instanceNamePrefix = "IC", desciption = "test", stretchable = false)
public class DIL_IC implements IDIYComponent<String> {
private static final long serialVersionUID = 1L;
public static Color BODY_COLOR = Color.gray;
public static Color BORDER_COLOR = Color.black;
public static Color LABEL_COLOR = Color.white;
public static int EDGE_RADIUS = 6;
private String name = "New Component";
private String value = "";
private Orientation orientation = Orientation.DEFAULT;
private PinCount pinCount = PinCount._8;
private Size rowSpacing = new Size(0.3d, SizeUnit.in);
private Point[] controlPoints = new Point[] { new Point(0, 0),
new Point(0, (int) Constants.GRID), new Point(0, (int) (2 * Constants.GRID)),
new Point(0, (int) (3 * Constants.GRID)), new Point((int) (3 * Constants.GRID), 0),
new Point((int) (3 * Constants.GRID), (int) Constants.GRID),
new Point((int) (3 * Constants.GRID), (int) (2 * Constants.GRID)),
new Point((int) (3 * Constants.GRID), (int) (3 * Constants.GRID)) };
@EditableProperty(defaultable = false)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@EditableProperty
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@EditableProperty
public Orientation getOrientation() {
return orientation;
}
public void setOrientation(Orientation orientation) {
this.orientation = orientation;
}
@EditableProperty(name = "Pins")
public PinCount getPinCount() {
return pinCount;
}
public void setPinCount(PinCount pinCount) {
this.pinCount = pinCount;
updateControlPoints();
}
@EditableProperty(name = "Row spacing")
public Size getRowSpacing() {
return rowSpacing;
}
public void setRowSpacing(Size rowSpacing) {
this.rowSpacing = rowSpacing;
updateControlPoints();
}
@Override
public int getControlPointCount() {
return controlPoints.length;
}
@Override
public Point getControlPoint(int index) {
return controlPoints[index];
}
@Override
public void setControlPoint(Point point, int index) {
controlPoints[index].setLocation(point);
}
private void updateControlPoints() {
Point firstPoint = controlPoints[0];
controlPoints = new Point[pinCount.getValue()];
controlPoints[0] = firstPoint;
int dx1;
int dy1;
int dx2;
int dy2;
for (int i = 0; i < pinCount.getValue() / 2; i++) {
switch (orientation) {
case DEFAULT:
dx1 = 0;
dy1 = (int) (i * Constants.GRID);
dx2 = rowSpacing.convertToPixels();
dy2 = (int) (i * Constants.GRID);
break;
case _90:
dx1 = (int) (-i * Constants.GRID);
dy1 = 0;
dx2 = (int) (-i * Constants.GRID);
dy2 = rowSpacing.convertToPixels();
break;
case _180:
dx1 = 0;
dy1 = (int) (-i * Constants.GRID);
dx2 = -rowSpacing.convertToPixels();
dy2 = (int) (-i * Constants.GRID);
break;
case _270:
dx1 = (int) (i * Constants.GRID);
dy1 = 0;
dx2 = (int) (i * Constants.GRID);
dy2 = rowSpacing.convertToPixels();
break;
default:
throw new RuntimeException("Unexpected orientation: " + orientation);
}
controlPoints[i] = new Point(firstPoint.x + dx1, firstPoint.y + dy1);
controlPoints[i + pinCount.getValue() / 2] = new Point(firstPoint.x + dx2, firstPoint.y
+ dy2);
}
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project) {
int x = controlPoints[0].x;
int y = controlPoints[0].y;
int width;
int height;
if (orientation == Orientation.DEFAULT || orientation == Orientation._180) {
width = rowSpacing.convertToPixels();
height = (int) ((pinCount.getValue() / 2) * Constants.GRID);
y -= (int) (Constants.GRID / 2);
} else {
width = (int) ((pinCount.getValue() / 2) * Constants.GRID);
height = rowSpacing.convertToPixels();
x -= (int) (Constants.GRID / 2);
}
if (orientation == Orientation._90) {
x -= width - Constants.GRID;
} else if (orientation == Orientation._180) {
x -= rowSpacing.convertToPixels();
y -= height - Constants.GRID;
}
if (componentState != ComponentState.DRAGGING) {
g2d.setColor(BODY_COLOR);
g2d.fillRoundRect(x, y, width, height, EDGE_RADIUS, EDGE_RADIUS);
}
g2d.setColor(BORDER_COLOR);
g2d.setStroke(new BasicStroke());
g2d.drawRoundRect(x, y, width, height, EDGE_RADIUS, EDGE_RADIUS);
// Draw label.
g2d.setFont(Constants.LABEL_FONT);
g2d.setColor(componentState == ComponentState.DRAGGING ? BORDER_COLOR : LABEL_COLOR);
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
Rectangle2D rect = fontMetrics.getStringBounds(getName(), g2d);
int textHeight = (int) (rect.getHeight());
int textWidth = (int) (rect.getWidth());
// Center text horizontally and vertically
x += (width - textWidth) / 2;
y += (height - textHeight) / 2 + fontMetrics.getAscent();
g2d.drawString(getName(), x, y);
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.drawString("IC", 10, 10);
}
static enum PinCount {
_4, _8, _10, _12, _14, _16, _24, _32;
@Override
public String toString() {
return name().replace("_", "");
}
public int getValue() {
return Integer.parseInt(toString());
}
}
}
@@ -1,69 +0,0 @@
package org.diylc.components;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Capacitance;
import org.diylc.core.measures.CapacitanceUnit;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Ceramic Capacitor", author = "bancika", category = "Passive", instanceNamePrefix = "C", desciption = "test")
public class RadialCeramicDiskCapacitor extends AbstractLeadedDIYComponent<Capacitance> {
private static final long serialVersionUID = 1L;
public static Size DEFAULT_WIDTH = new Size(1d / 2, SizeUnit.in);
public static Size DEFAULT_HEIGHT = new Size(1d / 8, SizeUnit.in);
public static Color BODY_COLOR = Color.decode("#F0E68C");
public static Color BORDER_COLOR = BODY_COLOR.darker();
private Capacitance value = new Capacitance(123d, CapacitanceUnit.nF);
public RadialCeramicDiskCapacitor() {
super();
}
@EditableProperty
public Capacitance getValue() {
return value;
}
public void setValue(Capacitance value) {
this.value = value;
}
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.drawString("C", 10, 10);
}
@Override
protected Size getDefaultHeight() {
return DEFAULT_HEIGHT;
}
@Override
protected Size getDefaultWidth() {
return DEFAULT_WIDTH;
}
@Override
protected Color getBodyColor() {
return BODY_COLOR;
}
@Override
protected Color getBorderColor() {
return BORDER_COLOR;
}
@Override
protected Shape getComponentShape() {
return new Ellipse2D.Double(0f, 0f, getWidth().convertToPixels(), getHeight()
.convertToPixels());
}
}
@@ -1,70 +0,0 @@
package org.diylc.components;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.RoundRectangle2D;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Capacitance;
import org.diylc.core.measures.CapacitanceUnit;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Radial Film Capacitor", author = "bancika", category = "Passive", instanceNamePrefix = "C", desciption = "test")
public class RadialFilmCapacitor extends AbstractLeadedDIYComponent<Capacitance> {
private static final long serialVersionUID = 1L;
public static Size DEFAULT_WIDTH = new Size(1d, SizeUnit.in);
public static Size DEFAULT_HEIGHT = new Size(1d / 4, SizeUnit.in);
public static Color BODY_COLOR = Color.decode("#FF8000");
public static Color BORDER_COLOR = BODY_COLOR.darker();
private Capacitance value = new Capacitance(123d, CapacitanceUnit.nF);
public RadialFilmCapacitor() {
super();
}
@EditableProperty
public Capacitance getValue() {
return value;
}
public void setValue(Capacitance value) {
this.value = value;
}
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.drawString("C", 10, 10);
}
@Override
protected Size getDefaultHeight() {
return DEFAULT_HEIGHT;
}
@Override
protected Size getDefaultWidth() {
return DEFAULT_WIDTH;
}
@Override
protected Color getBodyColor() {
return BODY_COLOR;
}
@Override
protected Color getBorderColor() {
return BORDER_COLOR;
}
@Override
protected Shape getComponentShape() {
double radius = getHeight().convertToPixels() * 0.7;
return new RoundRectangle2D.Double(0f, 0f, getWidth().convertToPixels(), getHeight()
.convertToPixels(), radius, radius);
}
}
@@ -1,69 +0,0 @@
package org.diylc.components;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;
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;
@ComponentDescriptor(name = "Resistor", author = "bancika", category = "Passive", instanceNamePrefix = "R", desciption = "test")
public class Resistor extends AbstractLeadedDIYComponent<Resistance> {
private static final long serialVersionUID = 1L;
public static Size DEFAULT_WIDTH = new Size(1d / 2, SizeUnit.in);
public static Size DEFAULT_HEIGHT = new Size(1d / 8, SizeUnit.in);
public static Color BODY_COLOR = Color.decode("#82CFFD");
public static Color BORDER_COLOR = BODY_COLOR.darker();
private Resistance value = new Resistance(123d, ResistanceUnit.K);
public Resistor() {
super();
}
@EditableProperty
public Resistance getValue() {
return value;
}
public void setValue(Resistance value) {
this.value = value;
}
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.drawString("R", 10, 10);
}
@Override
protected Size getDefaultHeight() {
return DEFAULT_HEIGHT;
}
@Override
protected Size getDefaultWidth() {
return DEFAULT_WIDTH;
}
@Override
protected Color getBodyColor() {
return BODY_COLOR;
}
@Override
protected Color getBorderColor() {
return BORDER_COLOR;
}
@Override
protected Shape getComponentShape() {
return new Rectangle2D.Double(0f, 0f, getWidth().convertToPixels(), getHeight()
.convertToPixels());
}
}
@@ -1,127 +0,0 @@
package org.diylc.components;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.Project;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Capacitance;
import org.diylc.core.measures.CapacitanceUnit;
import org.diylc.core.measures.Resistance;
import org.diylc.core.measures.ResistanceUnit;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Mock", author = "bancika", category = "Sample", instanceNamePrefix = "M", desciption = "test")
public class MockDIYComponent implements IDIYComponent<Capacitance> {
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 MockDIYComponent(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 MockDIYComponent() {
super();
}
@EditableProperty
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public int getControlPointCount() {
return 1;
}
@Override
public Point getControlPoint(int index) {
return leftTopCorner;
}
@Override
public void setControlPoint(Point point, int index) {
leftTopCorner.setLocation(point);
}
@EditableProperty(name = "Test Field")
public String getTestField() {
return testField;
}
public void setTestField(String testField) {
this.testField = testField;
}
@EditableProperty(defaultable = true)
public Capacitance getValue() {
return c;
}
public void setValue(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, Project project) {
g2d.setColor(componentState.equals(ComponentState.SELECTED) ? color : color.darker());
g2d.fillRect(leftTopCorner.x, leftTopCorner.y, 200, 50);
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.drawString("X", 10, 10);
}
}