added LED

This commit is contained in:
bancika
2011-01-29 13:47:00 +00:00
parent 1be52c1dfa
commit ac6aaf4e06
17 changed files with 186 additions and 76 deletions
@@ -1,15 +1,15 @@
<map> <map>
<entry> <entry>
<string>metric</string> <string>lastPath</string>
<boolean>true</boolean> <string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
</entry> </entry>
<entry> <entry>
<string>zoom</string> <string>zoom</string>
<double>1.0</double> <double>1.0</double>
</entry> </entry>
<entry> <entry>
<string>lastPath</string> <string>metric</string>
<string>C:\Documents and Settings\Branislav Stojkovic\workspace\DIYLC\templates</string> <boolean>true</boolean>
</entry> </entry>
<entry> <entry>
<string>default.org.diylc.components.misc.Label:Color</string> <string>default.org.diylc.components.misc.Label:Color</string>
@@ -35,8 +35,8 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
public static Size LEAD_THICKNESS = new Size(0.6d, SizeUnit.mm); public static Size LEAD_THICKNESS = new Size(0.6d, SizeUnit.mm);
public static Size DEFAULT_SIZE = new Size(1d, SizeUnit.in); public static Size DEFAULT_SIZE = new Size(1d, SizeUnit.in);
protected Size length;
protected Size width; protected Size width;
protected Size height;
protected Point[] points = new Point[] { protected Point[] points = new Point[] {
new Point((int) (-DEFAULT_SIZE.convertToPixels() / 2), 0), new Point((int) (-DEFAULT_SIZE.convertToPixels() / 2), 0),
new Point(DEFAULT_SIZE.convertToPixels() / 2, 0) }; new Point(DEFAULT_SIZE.convertToPixels() / 2, 0) };
@@ -48,8 +48,8 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
protected AbstractLeadedComponent() { protected AbstractLeadedComponent() {
super(); super();
try { try {
this.length = getDefaultLength().clone();
this.width = getDefaultWidth().clone(); this.width = getDefaultWidth().clone();
this.height = getDefaultHeight().clone();
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
// This should never happen because Size supports cloning. // This should never happen because Size supports cloning.
} catch (NullPointerException e) { } catch (NullPointerException e) {
@@ -145,16 +145,16 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
} }
/** /**
* @return default component width. * @return default component length.
*/ */
protected abstract Size getDefaultWidth(); protected abstract Size getDefaultLength();
/** /**
* Returns default component height. * Returns default component width.
* *
* @return * @return
*/ */
protected abstract Size getDefaultHeight(); protected abstract Size getDefaultWidth();
/** /**
* @return shape that represents component body. Shape should not be * @return shape that represents component body. Shape should not be
@@ -220,7 +220,16 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
this.borderColor = borderColor; this.borderColor = borderColor;
} }
@EditableProperty(defaultable = true) @EditableProperty(name = "Length", defaultable = true)
public Size getLength() {
return length;
}
public void setLength(Size length) {
this.length = length;
}
@EditableProperty(name = "Width", defaultable = true)
public Size getWidth() { public Size getWidth() {
return width; return width;
} }
@@ -229,15 +238,6 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
this.width = width; this.width = width;
} }
@EditableProperty(defaultable = true)
public Size getHeight() {
return height;
}
public void setHeight(Size height) {
this.height = height;
}
@EditableProperty @EditableProperty
public Display getDisplay() { public Display getDisplay() {
return display; return display;
@@ -50,7 +50,7 @@ public class Presenter implements IPlugInPort {
private static final Logger LOG = Logger.getLogger(Presenter.class); private static final Logger LOG = Logger.getLogger(Presenter.class);
public static final VersionNumber CURRENT_VERSION = new VersionNumber(3, 0, 4); public static final VersionNumber CURRENT_VERSION = new VersionNumber(3, 0, 5);
public static final String DEFAULTS_KEY_PREFIX = "default."; public static final String DEFAULTS_KEY_PREFIX = "default.";
public static final String METRIC_KEY = "metric"; public static final String METRIC_KEY = "metric";
@@ -260,8 +260,8 @@ public class ProjectFileManager {
} catch (Exception e) { } catch (Exception e) {
LOG.debug("Could not set value of " + nameAttr); LOG.debug("Could not set value of " + nameAttr);
} }
resistor.setWidth(new Size(6d, SizeUnit.mm)); resistor.setLength(new Size(6d, SizeUnit.mm));
resistor.setHeight(new Size(2d, SizeUnit.mm)); resistor.setWidth(new Size(2d, SizeUnit.mm));
resistor.setControlPoint(point1, 0); resistor.setControlPoint(point1, 0);
resistor.setControlPoint(point2, 1); resistor.setControlPoint(point2, 1);
component = resistor; component = resistor;
@@ -274,8 +274,8 @@ public class ProjectFileManager {
} catch (Exception e) { } catch (Exception e) {
LOG.debug("Could not set value of " + nameAttr); LOG.debug("Could not set value of " + nameAttr);
} }
capacitor.setWidth(new Size(6d, SizeUnit.mm)); capacitor.setLength(new Size(6d, SizeUnit.mm));
capacitor.setHeight(new Size(2d, SizeUnit.mm)); capacitor.setWidth(new Size(2d, SizeUnit.mm));
capacitor.setControlPoint(point1, 0); capacitor.setControlPoint(point1, 0);
capacitor.setControlPoint(point2, 1); capacitor.setControlPoint(point2, 1);
component = capacitor; component = capacitor;
@@ -290,13 +290,13 @@ public class ProjectFileManager {
} }
String sizeAttr = node.getAttributes().getNamedItem("Size").getNodeValue(); String sizeAttr = node.getAttributes().getNamedItem("Size").getNodeValue();
if (sizeAttr.equalsIgnoreCase("small")) { if (sizeAttr.equalsIgnoreCase("small")) {
capacitor.setWidth(new Size(3d, SizeUnit.mm)); capacitor.setLength(new Size(3d, SizeUnit.mm));
} else if (sizeAttr.equalsIgnoreCase("medium")) { } else if (sizeAttr.equalsIgnoreCase("medium")) {
capacitor.setWidth(new Size(5d, SizeUnit.mm)); capacitor.setLength(new Size(5d, SizeUnit.mm));
} else if (sizeAttr.equalsIgnoreCase("large")) { } else if (sizeAttr.equalsIgnoreCase("large")) {
capacitor.setWidth(new Size(7d, SizeUnit.mm)); capacitor.setLength(new Size(7d, SizeUnit.mm));
} else { } else {
capacitor.setWidth(new Size(4d, SizeUnit.mm)); capacitor.setLength(new Size(4d, SizeUnit.mm));
} }
capacitor.setControlPoint(point1, 0); capacitor.setControlPoint(point1, 0);
capacitor.setControlPoint(point2, 1); capacitor.setControlPoint(point2, 1);
@@ -310,8 +310,8 @@ public class ProjectFileManager {
} catch (Exception e) { } catch (Exception e) {
LOG.debug("Could not set value of " + nameAttr); LOG.debug("Could not set value of " + nameAttr);
} }
capacitor.setWidth(new Size(6d, SizeUnit.mm)); capacitor.setLength(new Size(6d, SizeUnit.mm));
capacitor.setHeight(new Size(2d, SizeUnit.mm)); capacitor.setWidth(new Size(2d, SizeUnit.mm));
capacitor.setControlPoint(point1, 0); capacitor.setControlPoint(point1, 0);
capacitor.setControlPoint(point2, 1); capacitor.setControlPoint(point2, 1);
component = capacitor; component = capacitor;
@@ -102,6 +102,10 @@
<changeType>NEW_FEATURE</changeType> <changeType>NEW_FEATURE</changeType>
<description>Added TO-220 transistor</description> <description>Added TO-220 transistor</description>
</com.diyfever.gui.update.Change> </com.diyfever.gui.update.Change>
<com.diyfever.gui.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Added LED</description>
</com.diyfever.gui.update.Change>
</changes> </changes>
<url>http://code.google.com/p/diy-layout-creator/downloads/list <url>http://code.google.com/p/diy-layout-creator/downloads/list
</url> </url>
@@ -88,14 +88,14 @@ public class CopperTrace extends AbstractLeadedComponent<Void> {
@Deprecated @Deprecated
@Override @Override
public Size getWidth() { public Size getLength() {
return super.getWidth(); return super.getLength();
} }
@Deprecated @Deprecated
@Override @Override
public Size getHeight() { public Size getWidth() {
return super.getHeight(); return super.getWidth();
} }
@Deprecated @Deprecated
@@ -115,12 +115,12 @@ public class CopperTrace extends AbstractLeadedComponent<Void> {
} }
@Override @Override
protected Size getDefaultHeight() { protected Size getDefaultWidth() {
return null; return null;
} }
@Override @Override
protected Size getDefaultWidth() { protected Size getDefaultLength() {
return null; return null;
} }
} }
@@ -53,14 +53,14 @@ public class Jumper extends AbstractLeadedComponent<Void> {
@Deprecated @Deprecated
@Override @Override
public Size getWidth() { public Size getLength() {
return super.getWidth(); return super.getLength();
} }
@Deprecated @Deprecated
@Override @Override
public Size getHeight() { public Size getWidth() {
return super.getHeight(); return super.getWidth();
} }
@Deprecated @Deprecated
@@ -80,12 +80,12 @@ public class Jumper extends AbstractLeadedComponent<Void> {
} }
@Override @Override
protected Size getDefaultHeight() { protected Size getDefaultWidth() {
return null; return null;
} }
@Override @Override
protected Size getDefaultWidth() { protected Size getDefaultLength() {
return null; return null;
} }
} }
@@ -53,18 +53,18 @@ public class AxialFilmCapacitor extends AbstractLeadedComponent<Capacitance> {
} }
@Override @Override
protected Size getDefaultHeight() { protected Size getDefaultWidth() {
return DEFAULT_HEIGHT; return DEFAULT_HEIGHT;
} }
@Override @Override
protected Size getDefaultWidth() { protected Size getDefaultLength() {
return DEFAULT_WIDTH; return DEFAULT_WIDTH;
} }
@Override @Override
protected Shape getBodyShape() { protected Shape getBodyShape() {
return new Rectangle2D.Double(0f, 0f, getWidth().convertToPixels(), return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(),
getClosestOdd(getHeight().convertToPixels())); getClosestOdd(getWidth().convertToPixels()));
} }
} }
@@ -53,7 +53,7 @@ public class ElectrolyticRadial extends AbstractLeadedComponent<Capacitance> {
@Override @Override
protected void decorateComponentBody(Graphics2D g2d) { protected void decorateComponentBody(Graphics2D g2d) {
int totalDiameter = getClosestOdd(getWidth().convertToPixels()); int totalDiameter = getClosestOdd(getLength().convertToPixels());
int coverDiameter = getClosestOdd(totalDiameter * 3 / 4); int coverDiameter = getClosestOdd(totalDiameter * 3 / 4);
g2d.setColor(coverColor); g2d.setColor(coverColor);
int position = (totalDiameter - coverDiameter) / 2; int position = (totalDiameter - coverDiameter) / 2;
@@ -66,26 +66,26 @@ public class ElectrolyticRadial extends AbstractLeadedComponent<Capacitance> {
} }
@Override @Override
protected Size getDefaultHeight() { protected Size getDefaultWidth() {
return null; return null;
} }
@Deprecated @Deprecated
@Override @Override
public Size getHeight() { public Size getWidth() {
return super.getHeight(); return super.getWidth();
} }
@Override @Override
protected Size getDefaultWidth() { protected Size getDefaultLength() {
// We'll reuse width property to set the diameter. // We'll reuse width property to set the diameter.
return DEFAULT_SIZE; return DEFAULT_SIZE;
} }
@EditableProperty(name = "Diameter") @EditableProperty(name = "Diameter")
@Override @Override
public Size getWidth() { public Size getLength() {
return super.getWidth(); return super.getLength();
} }
@EditableProperty(name = "Cover") @EditableProperty(name = "Cover")
@@ -99,7 +99,7 @@ public class ElectrolyticRadial extends AbstractLeadedComponent<Capacitance> {
@Override @Override
protected Shape getBodyShape() { protected Shape getBodyShape() {
return new Ellipse2D.Double(0f, 0f, getClosestOdd(getWidth().convertToPixels()), return new Ellipse2D.Double(0f, 0f, getClosestOdd(getLength().convertToPixels()),
getClosestOdd(getWidth().convertToPixels())); getClosestOdd(getLength().convertToPixels()));
} }
} }
@@ -53,18 +53,18 @@ public class RadialCeramicDiskCapacitor extends AbstractLeadedComponent<Capacita
} }
@Override @Override
protected Size getDefaultHeight() { protected Size getDefaultWidth() {
return DEFAULT_HEIGHT; return DEFAULT_HEIGHT;
} }
@Override @Override
protected Size getDefaultWidth() { protected Size getDefaultLength() {
return DEFAULT_WIDTH; return DEFAULT_WIDTH;
} }
@Override @Override
protected Shape getBodyShape() { protected Shape getBodyShape() {
return new Ellipse2D.Double(0f, 0f, getWidth().convertToPixels(), getClosestOdd(getHeight() return new Ellipse2D.Double(0f, 0f, getLength().convertToPixels(), getClosestOdd(getWidth()
.convertToPixels())); .convertToPixels()));
} }
} }
@@ -53,19 +53,19 @@ public class RadialFilmCapacitor extends AbstractLeadedComponent<Capacitance> {
} }
@Override @Override
protected Size getDefaultHeight() { protected Size getDefaultWidth() {
return DEFAULT_HEIGHT; return DEFAULT_HEIGHT;
} }
@Override @Override
protected Size getDefaultWidth() { protected Size getDefaultLength() {
return DEFAULT_WIDTH; return DEFAULT_WIDTH;
} }
@Override @Override
protected Shape getBodyShape() { protected Shape getBodyShape() {
double radius = getHeight().convertToPixels() * 0.7; double radius = getWidth().convertToPixels() * 0.7;
return new RoundRectangle2D.Double(0f, 0f, getWidth().convertToPixels(), return new RoundRectangle2D.Double(0f, 0f, getLength().convertToPixels(),
getClosestOdd(getHeight().convertToPixels()), radius, radius); getClosestOdd(getWidth().convertToPixels()), radius, radius);
} }
} }
@@ -56,12 +56,12 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
} }
@Override @Override
protected Size getDefaultHeight() { protected Size getDefaultWidth() {
return DEFAULT_HEIGHT; return DEFAULT_HEIGHT;
} }
@Override @Override
protected Size getDefaultWidth() { protected Size getDefaultLength() {
return DEFAULT_WIDTH; return DEFAULT_WIDTH;
} }
@@ -76,8 +76,8 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
@Override @Override
protected Shape getBodyShape() { protected Shape getBodyShape() {
return new Rectangle2D.Double(0f, 0f, getWidth().convertToPixels(), return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(),
getClosestOdd(getHeight().convertToPixels())); getClosestOdd(getWidth().convertToPixels()));
} }
@Override @Override
@@ -86,7 +86,7 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
if (colorCode == ResistorColorCode.NONE) { if (colorCode == ResistorColorCode.NONE) {
return; return;
} }
int height = getClosestOdd(getHeight().convertToPixels()); int height = getClosestOdd(getWidth().convertToPixels());
Color[] bands = value.getColorCode(colorCode); Color[] bands = value.getColorCode(colorCode);
int x = 4; int x = 4;
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2));
@@ -59,27 +59,27 @@ public class DiodePlastic extends AbstractLeadedComponent<String> {
} }
@Override @Override
protected Size getDefaultHeight() { protected Size getDefaultWidth() {
return DEFAULT_HEIGHT; return DEFAULT_HEIGHT;
} }
@Override @Override
protected Size getDefaultWidth() { protected Size getDefaultLength() {
return DEFAULT_WIDTH; return DEFAULT_WIDTH;
} }
@Override @Override
protected Shape getBodyShape() { protected Shape getBodyShape() {
return new Rectangle2D.Double(0f, 0f, getWidth().convertToPixels(), return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(),
getClosestOdd(getHeight().convertToPixels())); getClosestOdd(getWidth().convertToPixels()));
} }
@Override @Override
protected void decorateComponentBody(Graphics2D g2d) { protected void decorateComponentBody(Graphics2D g2d) {
g2d.setColor(markerColor); g2d.setColor(markerColor);
int width = getWidth().convertToPixels(); int width = getLength().convertToPixels();
int markerWidth = MARKER_WIDTH.convertToPixels(); int markerWidth = MARKER_WIDTH.convertToPixels();
g2d.fillRect(width - markerWidth, 0, markerWidth, getClosestOdd(getHeight() g2d.fillRect(width - markerWidth, 0, markerWidth, getClosestOdd(getWidth()
.convertToPixels())); .convertToPixels()));
} }
@@ -0,0 +1,104 @@
package org.diylc.components.semiconductors;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import org.diylc.common.ObjectCache;
import org.diylc.components.AbstractLeadedComponent;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "LED", author = "Branislav Stojkovic", category = "Semiconductors", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "D", description = "Light Emitting Diode", zOrder = IDIYComponent.COMPONENT)
public class LED extends AbstractLeadedComponent<String> {
private static final long serialVersionUID = 1L;
public static Size DEFAULT_SIZE = new Size(5d, SizeUnit.mm);
public static Color BODY_COLOR = Color.decode("#5DFC0A");
public static Color BORDER_COLOR = BODY_COLOR.darker();
private String value = "";
public LED() {
super();
this.bodyColor = BODY_COLOR;
this.borderColor = BORDER_COLOR;
}
@EditableProperty
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.rotate(-Math.PI / 4, width / 2, height / 2);
g2d.setColor(LEAD_COLOR);
g2d.drawLine(0, height / 2, width, height / 2);
int margin = 4 * width / 32;
Area area = new Area(new Ellipse2D.Double(margin, margin, width - 2 * margin, width - 2
* margin));
area.intersect(new Area(new Rectangle2D.Double(margin, margin, width - 5 * margin / 2,
width - 2 * margin)));
g2d.setColor(BODY_COLOR);
g2d.fill(area);
g2d.setColor(BORDER_COLOR);
g2d.draw(area);
g2d
.drawOval(margin * 2 - 1, margin * 2 - 1, width - 4 * margin + 2, width - 4
* margin + 2);
}
@Override
protected Size getDefaultWidth() {
return DEFAULT_SIZE;
}
@Override
protected Size getDefaultLength() {
return DEFAULT_SIZE;
}
@Override
protected Shape getBodyShape() {
int size = getClosestOdd((int) (getLength().convertToPixels() * 1.2));
Area area = new Area(new Ellipse2D.Double(0, 0, size, size));
area.intersect(new Area(new Rectangle2D.Double(0, 0, getLength().convertToPixels() * 1.15,
size)));
return area;
}
@Override
protected void decorateComponentBody(Graphics2D g2d) {
int size = getClosestOdd((int) (getLength().convertToPixels() * 1.2));
int innerSize = getClosestOdd(getLength().convertToPixels());
int x = (size - innerSize) / 2;
Shape s = new Ellipse2D.Double(x, x, innerSize, innerSize);
g2d.setColor(getBorderColor());
g2d.draw(s);
}
@EditableProperty(name = "Size")
@Override
public Size getLength() {
return super.getLength();
}
@Override
public Size getWidth() {
return super.getWidth();
}
}
@@ -207,7 +207,9 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
int margin = 3 * width / 32; int margin = 3 * width / 32;
Area area = new Area(new Ellipse2D.Double(margin / 2, margin, width - 2 * margin, width - 2 Area area = new Area(new Ellipse2D.Double(margin / 2, margin, width - 2 * margin, width - 2
* margin)); * margin));
area.subtract(new Area(new Rectangle2D.Double(0, 0, 2 * margin, height))); // area.subtract(new Area(new Rectangle2D.Double(0, 0, 2 * margin,
// height)));
area.intersect(new Area(new Rectangle2D.Double(2 * margin, 0, width, height)));
g2d.setColor(BODY_COLOR); g2d.setColor(BODY_COLOR);
g2d.fill(area); g2d.fill(area);
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);