inductor symbol

allow empty values
This commit is contained in:
bancika
2012-09-25 14:45:11 +00:00
parent 7ac43b5e1e
commit deae73f6be
6 changed files with 81 additions and 16 deletions
@@ -50,7 +50,7 @@ public abstract class AbstractLeadedComponent<T> extends
protected Color bodyColor = Color.white; protected Color bodyColor = Color.white;
protected Color borderColor = Color.black; protected Color borderColor = Color.black;
protected Color labelColor = LABEL_COLOR; protected Color labelColor = LABEL_COLOR;
protected Display display = Display.VALUE; protected Display display = Display.NAME;
protected AbstractLeadedComponent() { protected AbstractLeadedComponent() {
super(); super();
@@ -156,10 +156,20 @@ public abstract class AbstractLeadedComponent<T> extends
} }
// Transform graphics to draw the body in the right place and at the // Transform graphics to draw the body in the right place and at the
// right angle. // right angle.
AffineTransform oldTransform = g2d.getTransform(); AffineTransform oldTransform = null;
g2d.translate((points[0].x + points[1].x - shapeRect.width) / 2, double width;
(points[0].y + points[1].y - shapeRect.height) / 2); double length;
g2d.rotate(theta, shapeRect.width / 2, shapeRect.height / 2); if (useShapeRectAsPosition()) {
width = shapeRect.getHeight();
length = shapeRect.getWidth();
} else {
width = getWidth().convertToPixels();
length = getLength().convertToPixels();
}
oldTransform = g2d.getTransform();
g2d.translate((points[0].x + points[1].x - length) / 2,
(points[0].y + points[1].y - width) / 2);
g2d.rotate(theta, length / 2, width / 2);
// Draw body. // Draw body.
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
@@ -238,7 +248,9 @@ public abstract class AbstractLeadedComponent<T> extends
// Draw label. // Draw label.
g2d.setFont(LABEL_FONT); g2d.setFont(LABEL_FONT);
g2d.translate(shapeRect.x, shapeRect.y); if (useShapeRectAsPosition()) {
g2d.translate(shapeRect.x, shapeRect.y);
}
Color finalLabelColor; Color finalLabelColor;
if (outlineMode) { if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance() Theme theme = (Theme) ConfigurationManager.getInstance()
@@ -254,21 +266,21 @@ public abstract class AbstractLeadedComponent<T> extends
} }
g2d.setColor(finalLabelColor); g2d.setColor(finalLabelColor);
FontMetrics fontMetrics = g2d.getFontMetrics(); FontMetrics fontMetrics = g2d.getFontMetrics();
String label = display == Display.NAME ? getName() : getValue() String label = display == Display.NAME ? getName()
.toString(); : (getValue() == null ? "" : getValue().toString());
Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d); Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d);
// Don't offset in outline mode. // Don't offset in outline mode.
int offset = outlineMode ? 0 : getLabelOffset((int) shapeRect int offset = outlineMode ? 0 : getLabelOffset((int) length,
.getWidth(), (int) textRect.getWidth()); (int) width);
// Adjust label angle if needed to make sure that it's readable. // Adjust label angle if needed to make sure that it's readable.
if ((theta >= Math.PI / 2 && theta <= Math.PI) if ((theta >= Math.PI / 2 && theta <= Math.PI)
|| (theta < -Math.PI / 2 && theta > -Math.PI)) { || (theta < -Math.PI / 2 && theta > -Math.PI)) {
g2d.rotate(Math.PI, shapeRect.width / 2, shapeRect.height / 2); g2d.rotate(Math.PI, length / 2, width / 2);
offset = -offset; offset = -offset;
} }
g2d.drawString(label, (int) (shapeRect.width - textRect.getWidth()) g2d.drawString(label, (int) (length - textRect.getWidth()) / 2
/ 2 + offset, calculateLabelYCoordinate(shapeRect, + offset, calculateLabelYCoordinate(shapeRect, textRect,
textRect, fontMetrics)); fontMetrics));
g2d.setTransform(oldTransform); g2d.setTransform(oldTransform);
} }
} }
@@ -329,6 +341,19 @@ public abstract class AbstractLeadedComponent<T> extends
*/ */
protected abstract Shape getBodyShape(); protected abstract Shape getBodyShape();
/**
* Controls how component shape should be placed relative to start and end
* point.
*
* @return
* <code>true<code> if shape rect should be used to center the component or <code>false</code>
* to place the component relative to <code>length</code> and
* <code>width</code> values.
*/
protected boolean useShapeRectAsPosition() {
return true;
}
/** /**
* @return default lead thickness. Override this method to change it. * @return default lead thickness. Override this method to change it.
*/ */
@@ -0,0 +1,16 @@
package org.diylc.core.measures;
public class Current extends AbstractMeasure<CurrentUnit> {
private static final long serialVersionUID = 1L;
public Current(Double value, CurrentUnit unit) {
super(value, unit);
// TODO Auto-generated constructor stub
}
@Override
public Current clone() throws CloneNotSupportedException {
return new Current(value, unit);
}
}
@@ -0,0 +1,24 @@
package org.diylc.core.measures;
public enum CurrentUnit implements Unit {
uA(1e-6, "uA"), mA(1e-3, "mA"), A(1, "A");
double factor;
String display;
private CurrentUnit(double factor, String display) {
this.factor = factor;
this.display = display;
}
@Override
public double getFactor() {
return factor;
}
@Override
public String toString() {
return display;
}
}
@@ -2,7 +2,7 @@ package org.diylc.core.measures;
public enum InductanceUnit implements Unit { public enum InductanceUnit implements Unit {
pH(1, "pH"), nH(1e3, "nH"), uH(1e6, "\u03bcH"), mH(1e9, "mH"), H(1e12, "H"); pH(1, "pH"), nH(1e3, "nH"), uH(1e6, "uH"), mH(1e9, "mH"), H(1e12, "H");
double factor; double factor;
String display; String display;
@@ -2,7 +2,7 @@ package org.diylc.core.measures;
public enum VoltageUnit implements Unit { public enum VoltageUnit implements Unit {
MV(1e-1, "mV"), V(1, "V"), KV(1e3, "KV"); MV(1e-3, "mV"), V(1, "V"), KV(1e3, "KV");
double factor; double factor;
String display; String display;