mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
inductor symbol
allow empty values
This commit is contained in:
Binary file not shown.
+39
-14
@@ -50,7 +50,7 @@ public abstract class AbstractLeadedComponent<T> extends
|
||||
protected Color bodyColor = Color.white;
|
||||
protected Color borderColor = Color.black;
|
||||
protected Color labelColor = LABEL_COLOR;
|
||||
protected Display display = Display.VALUE;
|
||||
protected Display display = Display.NAME;
|
||||
|
||||
protected AbstractLeadedComponent() {
|
||||
super();
|
||||
@@ -156,10 +156,20 @@ public abstract class AbstractLeadedComponent<T> extends
|
||||
}
|
||||
// Transform graphics to draw the body in the right place and at the
|
||||
// right angle.
|
||||
AffineTransform oldTransform = g2d.getTransform();
|
||||
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);
|
||||
AffineTransform oldTransform = null;
|
||||
double width;
|
||||
double length;
|
||||
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.
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
if (alpha < MAX_ALPHA) {
|
||||
@@ -238,7 +248,9 @@ public abstract class AbstractLeadedComponent<T> extends
|
||||
|
||||
// Draw label.
|
||||
g2d.setFont(LABEL_FONT);
|
||||
g2d.translate(shapeRect.x, shapeRect.y);
|
||||
if (useShapeRectAsPosition()) {
|
||||
g2d.translate(shapeRect.x, shapeRect.y);
|
||||
}
|
||||
Color finalLabelColor;
|
||||
if (outlineMode) {
|
||||
Theme theme = (Theme) ConfigurationManager.getInstance()
|
||||
@@ -254,21 +266,21 @@ public abstract class AbstractLeadedComponent<T> extends
|
||||
}
|
||||
g2d.setColor(finalLabelColor);
|
||||
FontMetrics fontMetrics = g2d.getFontMetrics();
|
||||
String label = display == Display.NAME ? getName() : getValue()
|
||||
.toString();
|
||||
String label = display == Display.NAME ? getName()
|
||||
: (getValue() == null ? "" : getValue().toString());
|
||||
Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d);
|
||||
// Don't offset in outline mode.
|
||||
int offset = outlineMode ? 0 : getLabelOffset((int) shapeRect
|
||||
.getWidth(), (int) textRect.getWidth());
|
||||
int offset = outlineMode ? 0 : getLabelOffset((int) length,
|
||||
(int) width);
|
||||
// Adjust label angle if needed to make sure that it's readable.
|
||||
if ((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;
|
||||
}
|
||||
g2d.drawString(label, (int) (shapeRect.width - textRect.getWidth())
|
||||
/ 2 + offset, calculateLabelYCoordinate(shapeRect,
|
||||
textRect, fontMetrics));
|
||||
g2d.drawString(label, (int) (length - textRect.getWidth()) / 2
|
||||
+ offset, calculateLabelYCoordinate(shapeRect, textRect,
|
||||
fontMetrics));
|
||||
g2d.setTransform(oldTransform);
|
||||
}
|
||||
}
|
||||
@@ -329,6 +341,19 @@ public abstract class AbstractLeadedComponent<T> extends
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
|
||||
+16
@@ -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);
|
||||
}
|
||||
}
|
||||
+24
@@ -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;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@ package org.diylc.core.measures;
|
||||
|
||||
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;
|
||||
String display;
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ package org.diylc.core.measures;
|
||||
|
||||
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;
|
||||
String display;
|
||||
|
||||
Reference in New Issue
Block a user