From c08e52b994e508fbc7d857c22ca68a008bf0d663 Mon Sep 17 00:00:00 2001 From: bancika Date: Mon, 27 Aug 2012 14:34:59 +0000 Subject: [PATCH] Editable pin spacing for all radial components Folded elytics --- .../components/AbstractLeadedComponent.java | 102 ++++++++++++------ .../components/AbstractRadialComponent.java | 43 ++++++++ .../src/org/diylc/presenter/Presenter.java | 2 +- 3 files changed, 113 insertions(+), 34 deletions(-) create mode 100644 diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/components/AbstractRadialComponent.java 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 e67a87e4..4215cd25 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 @@ -108,6 +108,37 @@ public abstract class AbstractLeadedComponent extends AbstractTransparentComp // Normal mode with component body in the center and two lead parts. Rectangle shapeRect = shape.getBounds(); Double theta = Math.atan2(points[1].y - points[0].y, points[1].x - points[0].x); + // Go back to the original transformation to draw leads. + if (!outlineMode) { + AffineTransform textTransform = g2d.getTransform(); + if (length.convertToPixels() > points[0].distance(points[1])) { + g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); + } + int leadThickness = getClosestOdd(getLeadThickness()); + double leadLength = (distance - calculatePinSpacing(shapeRect)) / 2 - leadThickness / 2; + g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness)); + Color leadColor = shouldShadeLeads() ? getLeadColor(componentState).darker() + : getLeadColor(componentState); + g2d.setColor(leadColor); + int endX = (int) (points[0].x + Math.cos(theta) * leadLength); + int endY = (int) Math.round(points[0].y + Math.sin(theta) * leadLength); + g2d.drawLine(points[0].x, points[0].y, endX, endY); + endX = (int) (points[1].x + Math.cos(theta - Math.PI) * leadLength); + endY = (int) Math.round(points[1].y + Math.sin(theta - Math.PI) * leadLength); + g2d.drawLine(points[1].x, points[1].y, endX, endY); + if (shouldShadeLeads()) { + g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2)); + leadColor = getLeadColor(componentState); + g2d.setColor(leadColor); + g2d.drawLine(points[0].x, points[0].y, (int) (points[0].x + Math.cos(theta) + * leadLength), (int) (points[0].y + Math.sin(theta) * leadLength)); + g2d.drawLine(points[1].x, points[1].y, (int) (points[1].x + Math.cos(theta + - Math.PI) + * leadLength), (int) (points[1].y + Math.sin(theta - Math.PI) + * leadLength)); + } + g2d.setTransform(textTransform); + } // Transform graphics to draw the body in the right place and at the // right angle. AffineTransform oldTransform = g2d.getTransform(); @@ -144,42 +175,43 @@ public abstract class AbstractLeadedComponent extends AbstractTransparentComp g2d.setColor(finalBorderColor); g2d.draw(shape); - // Go back to the original transformation to draw leads. - if (!outlineMode) { - AffineTransform textTransform = g2d.getTransform(); - g2d.setTransform(oldTransform); - if (length.convertToPixels() > points[0].distance(points[1])) { - g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); - } - int leadThickness = getClosestOdd(getLeadThickness()); - double leadLength = (distance - shapeRect.width) / 2 - leadThickness / 2; - g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness)); - Color leadColor = shouldShadeLeads() ? getLeadColor(componentState).darker() - : getLeadColor(componentState); - g2d.setColor(leadColor); - int endX = (int) (points[0].x + Math.cos(theta) * leadLength); - int endY = (int) Math.round(points[0].y + Math.sin(theta) * leadLength); - g2d.drawLine(points[0].x, points[0].y, endX, endY); - endX = (int) (points[1].x + Math.cos(theta - Math.PI) * leadLength); - endY = (int) Math.round(points[1].y + Math.sin(theta - Math.PI) * leadLength); - g2d.drawLine(points[1].x, points[1].y, endX, endY); - if (shouldShadeLeads()) { - g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2)); - leadColor = getLeadColor(componentState); - g2d.setColor(leadColor); - g2d.drawLine(points[0].x, points[0].y, (int) (points[0].x + Math.cos(theta) - * leadLength), (int) (points[0].y + Math.sin(theta) * leadLength)); - g2d.drawLine(points[1].x, points[1].y, (int) (points[1].x + Math.cos(theta - - Math.PI) - * leadLength), (int) (points[1].y + Math.sin(theta - Math.PI) - * leadLength)); - } - g2d.setComposite(oldComposite); - g2d.setTransform(textTransform); - } +// // Go back to the original transformation to draw leads. +// if (!outlineMode) { +// AffineTransform textTransform = g2d.getTransform(); +// g2d.setTransform(oldTransform); +// if (length.convertToPixels() > points[0].distance(points[1])) { +// g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); +// } +// int leadThickness = getClosestOdd(getLeadThickness()); +// double leadLength = (distance - calculatePinSpacing(shapeRect)) / 2 - leadThickness / 2; +// g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness)); +// Color leadColor = shouldShadeLeads() ? getLeadColor(componentState).darker() +// : getLeadColor(componentState); +// g2d.setColor(leadColor); +// int endX = (int) (points[0].x + Math.cos(theta) * leadLength); +// int endY = (int) Math.round(points[0].y + Math.sin(theta) * leadLength); +// g2d.drawLine(points[0].x, points[0].y, endX, endY); +// endX = (int) (points[1].x + Math.cos(theta - Math.PI) * leadLength); +// endY = (int) Math.round(points[1].y + Math.sin(theta - Math.PI) * leadLength); +// g2d.drawLine(points[1].x, points[1].y, endX, endY); +// if (shouldShadeLeads()) { +// g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2)); +// leadColor = getLeadColor(componentState); +// g2d.setColor(leadColor); +// g2d.drawLine(points[0].x, points[0].y, (int) (points[0].x + Math.cos(theta) +// * leadLength), (int) (points[0].y + Math.sin(theta) * leadLength)); +// g2d.drawLine(points[1].x, points[1].y, (int) (points[1].x + Math.cos(theta +// - Math.PI) +// * leadLength), (int) (points[1].y + Math.sin(theta - Math.PI) +// * leadLength)); +// } +// g2d.setComposite(oldComposite); +// g2d.setTransform(textTransform); +// } // Draw label. g2d.setFont(LABEL_FONT); + g2d.translate(shapeRect.x, shapeRect.y); Color finalLabelColor; if (outlineMode) { Theme theme = (Theme) ConfigurationManager.getInstance().readObject( @@ -277,6 +309,10 @@ public abstract class AbstractLeadedComponent extends AbstractTransparentComp return componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR : LEAD_COLOR; } + + protected int calculatePinSpacing(Rectangle shapeRect) { + return shapeRect.width; + } @Override public int getControlPointCount() { diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/components/AbstractRadialComponent.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/components/AbstractRadialComponent.java new file mode 100644 index 00000000..c5bc9688 --- /dev/null +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/components/AbstractRadialComponent.java @@ -0,0 +1,43 @@ +package org.diylc.components; + +import java.awt.Rectangle; + +import org.diylc.core.annotations.EditableProperty; +import org.diylc.core.measures.Size; +import org.diylc.core.measures.SizeUnit; + +/** + * Base class for radial components. The same as {@link AbstractRadialComponent} + * but with added pin spacing. + * + * @author bancika + * + * @param + */ +public abstract class AbstractRadialComponent extends + AbstractLeadedComponent { + + private static final long serialVersionUID = 1L; + + public static Size PIN_SPACING = new Size(0.1d, SizeUnit.in); + + private Size pinSpacing = PIN_SPACING; + + @Override + protected int calculatePinSpacing(Rectangle shapeRect) { + return getClosestOdd(getPinSpacing().convertToPixels()); + } + + @EditableProperty(name = "Pin spacing") + public Size getPinSpacing() { + if (pinSpacing == null) { + pinSpacing = PIN_SPACING; + } + return pinSpacing; + } + + public void setPinSpacing(Size pinSpacing) { + this.pinSpacing = pinSpacing; + } + +} 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 4e450c78..9b990292 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 @@ -57,7 +57,7 @@ public class Presenter implements IPlugInPort { private static final Logger LOG = Logger.getLogger(Presenter.class); public static final VersionNumber CURRENT_VERSION = new VersionNumber(3, - 13, 0); + 14, 0); public static final String DEFAULTS_KEY_PREFIX = "default."; public static final List> EMPTY_SELECTION = Collections