diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-core/library/main.jar b/ diy-layout-creator --username bancika@gmail.com/diylc-core/library/main.jar index cf6523d8..e2a8b6d9 100644 Binary files a/ diy-layout-creator --username bancika@gmail.com/diylc-core/library/main.jar and b/ diy-layout-creator --username bancika@gmail.com/diylc-core/library/main.jar differ diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/components/AbstractLeadedComponent.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/components/AbstractLeadedComponent.java index 5c871b5f..45b970c5 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/components/AbstractLeadedComponent.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/components/AbstractLeadedComponent.java @@ -50,7 +50,7 @@ public abstract class AbstractLeadedComponent 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 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 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 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 extends */ protected abstract Shape getBodyShape(); + /** + * Controls how component shape should be placed relative to start and end + * point. + * + * @return + * true if shape rect should be used to center the component or false + * to place the component relative to length and + * width values. + */ + protected boolean useShapeRectAsPosition() { + return true; + } + /** * @return default lead thickness. Override this method to change it. */ diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/core/measures/Current.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/core/measures/Current.java new file mode 100644 index 00000000..0ea01291 --- /dev/null +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/core/measures/Current.java @@ -0,0 +1,16 @@ +package org.diylc.core.measures; + +public class Current extends AbstractMeasure { + + 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); + } +} diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/core/measures/CurrentUnit.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/core/measures/CurrentUnit.java new file mode 100644 index 00000000..c5c18ac4 --- /dev/null +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/core/measures/CurrentUnit.java @@ -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; + } +} diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/core/measures/InductanceUnit.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/core/measures/InductanceUnit.java index e00facd8..6c838315 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/core/measures/InductanceUnit.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/core/measures/InductanceUnit.java @@ -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; diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/core/measures/VoltageUnit.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/core/measures/VoltageUnit.java index feb9d6ce..f20071b1 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/core/measures/VoltageUnit.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/core/measures/VoltageUnit.java @@ -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;