From 7f2b973638ca0527f94c467677e198cbc1265b01 Mon Sep 17 00:00:00 2001 From: bancika Date: Sat, 3 Sep 2011 19:47:35 +0000 Subject: [PATCH] Better lead and label rendering when lead spacing is smaller than component body --- .../components/AbstractLeadedComponent.java | 64 +++++++++++-------- .../diylc-swing/update.xml | 4 ++ 2 files changed, 40 insertions(+), 28 deletions(-) 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 86e605b0..4bd6c150 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 @@ -143,6 +143,41 @@ 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); + } + // Draw label. g2d.setFont(LABEL_FONT); Color finalLabelColor; @@ -168,34 +203,7 @@ public abstract class AbstractLeadedComponent extends AbstractTransparentComp Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d); g2d.drawString(label, (int) (shapeRect.width - textRect.getWidth()) / 2, calculateLabelYCoordinate(shapeRect, textRect, fontMetrics)); - - // Go back to the original transformation to draw leads. - if (!outlineMode) { - g2d.setTransform(oldTransform); - 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.setTransform(oldTransform); } } 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 7a8dcd68..3fdef9d7 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 @@ -390,6 +390,10 @@ IMPROVEMENT Select All should not include locked components + + IMPROVEMENT + Better lead and label rendering when lead spacing is smaller than component body + http://code.google.com/p/diy-layout-creator/downloads/list