diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-core/build.xml b/ diy-layout-creator --username bancika@gmail.com/diylc-core/build.xml index 8d056c3c..bcafc476 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-core/build.xml +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-core/build.xml @@ -62,6 +62,12 @@ + + + + + + diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/components/AbstractComponent.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/components/AbstractComponent.java index d632f39d..72204793 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/components/AbstractComponent.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/components/AbstractComponent.java @@ -31,7 +31,7 @@ public abstract class AbstractComponent implements IDIYComponent { public static Color SELECTION_COLOR = Color.red; public static Color LABEL_COLOR = Color.black; public static Color LABEL_COLOR_SELECTED = Color.red; - public static Font LABEL_FONT = new Font("Tahoma", Font.PLAIN, 13); + public static Font LABEL_FONT = new Font("Tahoma", Font.PLAIN, 14); @EditableProperty(defaultable = false) @Override 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 4bd6c150..e67a87e4 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 @@ -195,13 +195,16 @@ public abstract class AbstractLeadedComponent extends AbstractTransparentComp g2d.setColor(finalLabelColor); FontMetrics fontMetrics = g2d.getFontMetrics(); String label = display == Display.NAME ? getName() : 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()); // 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); - } - Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d); - g2d.drawString(label, (int) (shapeRect.width - textRect.getWidth()) / 2, + offset = -offset; + } + g2d.drawString(label, (int) (shapeRect.width - textRect.getWidth()) / 2 + offset, calculateLabelYCoordinate(shapeRect, textRect, fontMetrics)); g2d.setTransform(oldTransform); } @@ -237,6 +240,10 @@ public abstract class AbstractLeadedComponent extends AbstractTransparentComp protected boolean supportsStandingMode() { return false; } + + protected int getLabelOffset(int bodyWidth, int labelWidth) { + return 0; + } /** * @return default component length. diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/presenter/Presenter.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/presenter/Presenter.java index 6bb48992..c35599a1 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/presenter/Presenter.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/presenter/Presenter.java @@ -55,7 +55,7 @@ public class Presenter implements IPlugInPort { private static final Logger LOG = Logger.getLogger(Presenter.class); - public static final VersionNumber CURRENT_VERSION = new VersionNumber(3, 1, 0); + public static final VersionNumber CURRENT_VERSION = new VersionNumber(3, 2, 0); public static final String DEFAULTS_KEY_PREFIX = "default."; public static final List> EMPTY_SELECTION = Collections.emptyList(); diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-library/lib/diylc-core.jar b/ diy-layout-creator --username bancika@gmail.com/diylc-library/lib/diylc-core.jar index 689f2bdf..28a8fbf6 100644 Binary files a/ diy-layout-creator --username bancika@gmail.com/diylc-library/lib/diylc-core.jar and b/ diy-layout-creator --username bancika@gmail.com/diylc-library/lib/diylc-core.jar differ diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-library/src/org/diylc/components/passive/Resistor.java b/ diy-layout-creator --username bancika@gmail.com/diylc-library/src/org/diylc/components/passive/Resistor.java index 3f105d6b..67986e8b 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-library/src/org/diylc/components/passive/Resistor.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-library/src/org/diylc/components/passive/Resistor.java @@ -27,6 +27,8 @@ public class Resistor extends AbstractLeadedComponent { public static Size DEFAULT_HEIGHT = new Size(1d / 8, SizeUnit.in); public static Color BODY_COLOR = Color.decode("#82CFFD"); public static Color BORDER_COLOR = BODY_COLOR.darker(); + public static int BAND_SPACING = 5; + public static int FIRST_BAND = 4; private Resistance value = new Resistance(123d, ResistanceUnit.K); private Power power = Power.HALF; @@ -37,7 +39,7 @@ public class Resistor extends AbstractLeadedComponent { this.bodyColor = BODY_COLOR; this.borderColor = BORDER_COLOR; } - + @Override protected boolean supportsStandingMode() { return true; @@ -110,12 +112,22 @@ public class Resistor extends AbstractLeadedComponent { } int height = getClosestOdd(getWidth().convertToPixels()); Color[] bands = value.getColorCode(colorCode); - int x = 4; + int x = FIRST_BAND; g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2)); for (int i = 0; i < bands.length; i++) { g2d.setColor(bands[i]); g2d.drawLine(x, 1, x, height - 1); - x += 5; + x += BAND_SPACING; } } + + @Override + protected int getLabelOffset(int bodyWidth, int labelWidth) { + Color[] bands = value.getColorCode(colorCode); + int bandArea = FIRST_BAND + BAND_SPACING * (bands.length - 1); + // Only offset the label if overlaping with the band area. + if (labelWidth > bodyWidth - 2 * bandArea) + return bandArea / 2; + return 0; + } } diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/lib/diylc-core.jar b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/lib/diylc-core.jar index 03e86d69..340ac1e1 100644 Binary files a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/lib/diylc-core.jar and b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/lib/diylc-core.jar differ diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/library/main.jar b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/library/main.jar index 6053d799..d37a6651 100644 Binary files a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/library/main.jar and b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/library/main.jar differ diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/update.xml b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/update.xml index 30919a48..b0f96ae4 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/update.xml +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/update.xml @@ -426,6 +426,10 @@ NEW_FEATURE Perfboards can show hole coordinates + + IMPROVEMENT + Smarter resistor labels; try not to overlap label with bands + http://code.google.com/p/diy-layout-creator/downloads/list