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>
<entry>
<string>metric</string>
<boolean>true</boolean>
<string>lastPath</string>
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
</entry>
<entry>
<string>zoom</string>
<double>1.0</double>
</entry>
<entry>
<string>lastPath</string>
<string>C:\Documents and Settings\Branislav Stojkovic\workspace\DIYLC\templates</string>
<string>metric</string>
<boolean>true</boolean>
</entry>
<entry>
<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 DEFAULT_SIZE = new Size(1d, SizeUnit.in);
protected Size length;
protected Size width;
protected Size height;
protected Point[] points = new Point[] {
new Point((int) (-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() {
super();
try {
this.length = getDefaultLength().clone();
this.width = getDefaultWidth().clone();
this.height = getDefaultHeight().clone();
} catch (CloneNotSupportedException e) {
// This should never happen because Size supports cloning.
} 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
*/
protected abstract Size getDefaultHeight();
protected abstract Size getDefaultWidth();
/**
* @return shape that represents component body. Shape should not be
@@ -220,7 +220,16 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
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() {
return width;
}
@@ -229,15 +238,6 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
this.width = width;
}
@EditableProperty(defaultable = true)
public Size getHeight() {
return height;
}
public void setHeight(Size height) {
this.height = height;
}
@EditableProperty
public Display getDisplay() {
return display;
@@ -50,7 +50,7 @@ public class Presenter implements IPlugInPort {
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 METRIC_KEY = "metric";
@@ -260,8 +260,8 @@ public class ProjectFileManager {
} catch (Exception e) {
LOG.debug("Could not set value of " + nameAttr);
}
resistor.setWidth(new Size(6d, SizeUnit.mm));
resistor.setHeight(new Size(2d, SizeUnit.mm));
resistor.setLength(new Size(6d, SizeUnit.mm));
resistor.setWidth(new Size(2d, SizeUnit.mm));
resistor.setControlPoint(point1, 0);
resistor.setControlPoint(point2, 1);
component = resistor;
@@ -274,8 +274,8 @@ public class ProjectFileManager {
} catch (Exception e) {
LOG.debug("Could not set value of " + nameAttr);
}
capacitor.setWidth(new Size(6d, SizeUnit.mm));
capacitor.setHeight(new Size(2d, SizeUnit.mm));
capacitor.setLength(new Size(6d, SizeUnit.mm));
capacitor.setWidth(new Size(2d, SizeUnit.mm));
capacitor.setControlPoint(point1, 0);
capacitor.setControlPoint(point2, 1);
component = capacitor;
@@ -290,13 +290,13 @@ public class ProjectFileManager {
}
String sizeAttr = node.getAttributes().getNamedItem("Size").getNodeValue();
if (sizeAttr.equalsIgnoreCase("small")) {
capacitor.setWidth(new Size(3d, SizeUnit.mm));
capacitor.setLength(new Size(3d, SizeUnit.mm));
} else if (sizeAttr.equalsIgnoreCase("medium")) {
capacitor.setWidth(new Size(5d, SizeUnit.mm));
capacitor.setLength(new Size(5d, SizeUnit.mm));
} else if (sizeAttr.equalsIgnoreCase("large")) {
capacitor.setWidth(new Size(7d, SizeUnit.mm));
capacitor.setLength(new Size(7d, SizeUnit.mm));
} else {
capacitor.setWidth(new Size(4d, SizeUnit.mm));
capacitor.setLength(new Size(4d, SizeUnit.mm));
}
capacitor.setControlPoint(point1, 0);
capacitor.setControlPoint(point2, 1);
@@ -310,8 +310,8 @@ public class ProjectFileManager {
} catch (Exception e) {
LOG.debug("Could not set value of " + nameAttr);
}
capacitor.setWidth(new Size(6d, SizeUnit.mm));
capacitor.setHeight(new Size(2d, SizeUnit.mm));
capacitor.setLength(new Size(6d, SizeUnit.mm));
capacitor.setWidth(new Size(2d, SizeUnit.mm));
capacitor.setControlPoint(point1, 0);
capacitor.setControlPoint(point2, 1);
component = capacitor;
@@ -102,6 +102,10 @@
<changeType>NEW_FEATURE</changeType>
<description>Added TO-220 transistor</description>
</com.diyfever.gui.update.Change>
<com.diyfever.gui.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Added LED</description>
</com.diyfever.gui.update.Change>
</changes>
<url>http://code.google.com/p/diy-layout-creator/downloads/list
</url>
@@ -88,14 +88,14 @@ public class CopperTrace extends AbstractLeadedComponent<Void> {
@Deprecated
@Override
public Size getWidth() {
return super.getWidth();
public Size getLength() {
return super.getLength();
}
@Deprecated
@Override
public Size getHeight() {
return super.getHeight();
public Size getWidth() {
return super.getWidth();
}
@Deprecated
@@ -115,12 +115,12 @@ public class CopperTrace extends AbstractLeadedComponent<Void> {
}
@Override
protected Size getDefaultHeight() {
protected Size getDefaultWidth() {
return null;
}
@Override
protected Size getDefaultWidth() {
protected Size getDefaultLength() {
return null;
}
}
@@ -53,14 +53,14 @@ public class Jumper extends AbstractLeadedComponent<Void> {
@Deprecated
@Override
public Size getWidth() {
return super.getWidth();
public Size getLength() {
return super.getLength();
}
@Deprecated
@Override
public Size getHeight() {
return super.getHeight();
public Size getWidth() {
return super.getWidth();
}
@Deprecated
@@ -80,12 +80,12 @@ public class Jumper extends AbstractLeadedComponent<Void> {
}
@Override
protected Size getDefaultHeight() {
protected Size getDefaultWidth() {
return null;
}
@Override
protected Size getDefaultWidth() {
protected Size getDefaultLength() {
return null;
}
}
@@ -53,18 +53,18 @@ public class AxialFilmCapacitor extends AbstractLeadedComponent<Capacitance> {
}
@Override
protected Size getDefaultHeight() {
protected Size getDefaultWidth() {
return DEFAULT_HEIGHT;
}
@Override
protected Size getDefaultWidth() {
protected Size getDefaultLength() {
return DEFAULT_WIDTH;
}
@Override
protected Shape getBodyShape() {
return new Rectangle2D.Double(0f, 0f, getWidth().convertToPixels(),
getClosestOdd(getHeight().convertToPixels()));
return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(),
getClosestOdd(getWidth().convertToPixels()));
}
}
@@ -53,7 +53,7 @@ public class ElectrolyticRadial extends AbstractLeadedComponent<Capacitance> {
@Override
protected void decorateComponentBody(Graphics2D g2d) {
int totalDiameter = getClosestOdd(getWidth().convertToPixels());
int totalDiameter = getClosestOdd(getLength().convertToPixels());
int coverDiameter = getClosestOdd(totalDiameter * 3 / 4);
g2d.setColor(coverColor);
int position = (totalDiameter - coverDiameter) / 2;
@@ -66,26 +66,26 @@ public class ElectrolyticRadial extends AbstractLeadedComponent<Capacitance> {
}
@Override
protected Size getDefaultHeight() {
protected Size getDefaultWidth() {
return null;
}
@Deprecated
@Override
public Size getHeight() {
return super.getHeight();
public Size getWidth() {
return super.getWidth();
}
@Override
protected Size getDefaultWidth() {
protected Size getDefaultLength() {
// We'll reuse width property to set the diameter.
return DEFAULT_SIZE;
}
@EditableProperty(name = "Diameter")
@Override
public Size getWidth() {
return super.getWidth();
public Size getLength() {
return super.getLength();
}
@EditableProperty(name = "Cover")
@@ -99,7 +99,7 @@ public class ElectrolyticRadial extends AbstractLeadedComponent<Capacitance> {
@Override
protected Shape getBodyShape() {
return new Ellipse2D.Double(0f, 0f, getClosestOdd(getWidth().convertToPixels()),
getClosestOdd(getWidth().convertToPixels()));
return new Ellipse2D.Double(0f, 0f, getClosestOdd(getLength().convertToPixels()),
getClosestOdd(getLength().convertToPixels()));
}
}
@@ -53,18 +53,18 @@ public class RadialCeramicDiskCapacitor extends AbstractLeadedComponent<Capacita
}
@Override
protected Size getDefaultHeight() {
protected Size getDefaultWidth() {
return DEFAULT_HEIGHT;
}
@Override
protected Size getDefaultWidth() {
protected Size getDefaultLength() {
return DEFAULT_WIDTH;
}
@Override
protected Shape getBodyShape() {
return new Ellipse2D.Double(0f, 0f, getWidth().convertToPixels(), getClosestOdd(getHeight()
return new Ellipse2D.Double(0f, 0f, getLength().convertToPixels(), getClosestOdd(getWidth()
.convertToPixels()));
}
}
@@ -53,19 +53,19 @@ public class RadialFilmCapacitor extends AbstractLeadedComponent<Capacitance> {
}
@Override
protected Size getDefaultHeight() {
protected Size getDefaultWidth() {
return DEFAULT_HEIGHT;
}
@Override
protected Size getDefaultWidth() {
protected Size getDefaultLength() {
return DEFAULT_WIDTH;
}
@Override
protected Shape getBodyShape() {
double radius = getHeight().convertToPixels() * 0.7;
return new RoundRectangle2D.Double(0f, 0f, getWidth().convertToPixels(),
getClosestOdd(getHeight().convertToPixels()), radius, radius);
double radius = getWidth().convertToPixels() * 0.7;
return new RoundRectangle2D.Double(0f, 0f, getLength().convertToPixels(),
getClosestOdd(getWidth().convertToPixels()), radius, radius);
}
}
@@ -56,12 +56,12 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
}
@Override
protected Size getDefaultHeight() {
protected Size getDefaultWidth() {
return DEFAULT_HEIGHT;
}
@Override
protected Size getDefaultWidth() {
protected Size getDefaultLength() {
return DEFAULT_WIDTH;
}
@@ -76,8 +76,8 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
@Override
protected Shape getBodyShape() {
return new Rectangle2D.Double(0f, 0f, getWidth().convertToPixels(),
getClosestOdd(getHeight().convertToPixels()));
return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(),
getClosestOdd(getWidth().convertToPixels()));
}
@Override
@@ -86,7 +86,7 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
if (colorCode == ResistorColorCode.NONE) {
return;
}
int height = getClosestOdd(getHeight().convertToPixels());
int height = getClosestOdd(getWidth().convertToPixels());
Color[] bands = value.getColorCode(colorCode);
int x = 4;
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2));
@@ -59,27 +59,27 @@ public class DiodePlastic extends AbstractLeadedComponent<String> {
}
@Override
protected Size getDefaultHeight() {
protected Size getDefaultWidth() {
return DEFAULT_HEIGHT;
}
@Override
protected Size getDefaultWidth() {
protected Size getDefaultLength() {
return DEFAULT_WIDTH;
}
@Override
protected Shape getBodyShape() {
return new Rectangle2D.Double(0f, 0f, getWidth().convertToPixels(),
getClosestOdd(getHeight().convertToPixels()));
return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(),
getClosestOdd(getWidth().convertToPixels()));
}
@Override
protected void decorateComponentBody(Graphics2D g2d) {
g2d.setColor(markerColor);
int width = getWidth().convertToPixels();
int width = getLength().convertToPixels();
int markerWidth = MARKER_WIDTH.convertToPixels();
g2d.fillRect(width - markerWidth, 0, markerWidth, getClosestOdd(getHeight()
g2d.fillRect(width - markerWidth, 0, markerWidth, getClosestOdd(getWidth()
.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;
Area area = new Area(new Ellipse2D.Double(margin / 2, margin, width - 2 * margin, width - 2
* 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.fill(area);
g2d.setColor(BORDER_COLOR);