diff --git a/diylc/diylc-library/src/org/diylc/components/passive/Resistor.java b/diylc/diylc-library/src/org/diylc/components/passive/Resistor.java index 7a24916a..3879e1e8 100644 --- a/diylc/diylc-library/src/org/diylc/components/passive/Resistor.java +++ b/diylc/diylc-library/src/org/diylc/components/passive/Resistor.java @@ -39,6 +39,7 @@ public class Resistor extends AbstractLeadedComponent { private Power power = Power.HALF; private org.diylc.core.measures.Power powerNew = null; private ResistorColorCode colorCode = ResistorColorCode._5_BAND; + private ResistorShape shape = ResistorShape.Standard; public Resistor() { super(); @@ -122,15 +123,29 @@ public class Resistor extends AbstractLeadedComponent { this.colorCode = colorCode; } + @EditableProperty + public ResistorShape getShape() { + if (shape == null) + shape = ResistorShape.Standard; + return shape; + } + + public void setShape(ResistorShape shape) { + this.shape = shape; + } + @Override protected Shape getBodyShape() { - double length = getLength().convertToPixels(); - double width = getClosestOdd(getWidth().convertToPixels()); - Rectangle2D rect = new Rectangle2D.Double(width / 2, width / 10, length - width, width * 8 / 10); - Area a = new Area(rect); - a.add(new Area(new Ellipse2D.Double(0, 0, width, width))); - a.add(new Area(new Ellipse2D.Double(length - width, 0, width, width))); - return a; + if (shape == ResistorShape.Standard) { + double length = getLength().convertToPixels(); + double width = getClosestOdd(getWidth().convertToPixels()); + Rectangle2D rect = new Rectangle2D.Double(width / 2, width / 10, length - width, width * 8 / 10); + Area a = new Area(rect); + a.add(new Area(new Ellipse2D.Double(0, 0, width, width))); + a.add(new Area(new Ellipse2D.Double(length - width, 0, width, width))); + return a; + } + return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(), getClosestOdd(getWidth().convertToPixels())); } @Override @@ -139,14 +154,26 @@ public class Resistor extends AbstractLeadedComponent { if (colorCode == ResistorColorCode.NONE || outlineMode || value == null) { return; } - int width = getClosestOdd(getWidth().convertToPixels()); - Color[] bands = value.getColorCode(colorCode); - int x = width + FIRST_BAND; - g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2)); - for (int i = 0; i < bands.length; i++) { - g2d.setColor(bands[i]); - g2d.drawLine(x, width / 10 + 2, x, width * 8 / 10 + 1); - x += BAND_SPACING; + if (shape == ResistorShape.Standard) { + int width = getClosestOdd(getWidth().convertToPixels()); + Color[] bands = value.getColorCode(colorCode); + int x = width + FIRST_BAND; + g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2)); + for (int i = 0; i < bands.length; i++) { + g2d.setColor(bands[i]); + g2d.drawLine(x, width / 10 + 2, x, width * 8 / 10 + 1); + x += BAND_SPACING; + } + } else { + int height = getClosestOdd(getWidth().convertToPixels()); + Color[] bands = value.getColorCode(colorCode); + 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 += BAND_SPACING; + } } } @@ -167,4 +194,8 @@ public class Resistor extends AbstractLeadedComponent { public boolean getFlipStanding() { return super.getFlipStanding(); } + + public enum ResistorShape { + Tubular, Standard + } } diff --git a/diylc/diylc-swing/library/main.jar b/diylc/diylc-swing/library/main.jar index 315be3c5..14a76785 100644 Binary files a/diylc/diylc-swing/library/main.jar and b/diylc/diylc-swing/library/main.jar differ diff --git a/diylc/diylc-swing/update.xml b/diylc/diylc-swing/update.xml index d374ab01..0d60740d 100644 --- a/diylc/diylc-swing/update.xml +++ b/diylc/diylc-swing/update.xml @@ -1551,7 +1551,7 @@ 36 0 - 2017-01-05 20:00:00.000 CET + 2017-01-26 20:00:00.000 CET @@ -1612,6 +1612,22 @@ https://github.com/bancika/diy-layout-creator/releases + + + + 3 + 37 + 0 + + 2017-01-26 20:00:00.000 CET + + + + IMPROVEMENT + Ability to change resistor shape (tubular or standard "dog bone") + + + https://github.com/bancika/diy-layout-creator/releases \ No newline at end of file