diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/config.xml b/ diy-layout-creator --username bancika@gmail.com/DIYLC/config.xml index 02f4b9f6..8d8197c4 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/config.xml +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/config.xml @@ -7,12 +7,12 @@ - lastPath - C:\Documents and Settings\Branislav Stojkovic\Desktop + metric + false - metric - true + lastPath + C:\Documents and Settings\Branislav Stojkovic\Desktop default.org.diylc.components.passive.AxialFilmCapacitor:Width diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/library/main.jar b/ diy-layout-creator --username bancika@gmail.com/DIYLC/library/main.jar index 5d599eb5..8072a14f 100644 Binary files a/ diy-layout-creator --username bancika@gmail.com/DIYLC/library/main.jar and b/ diy-layout-creator --username bancika@gmail.com/DIYLC/library/main.jar differ diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/components/AbstractLeadedComponent.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/components/AbstractLeadedComponent.java index 1477e467..6a2cb862 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/components/AbstractLeadedComponent.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/components/AbstractLeadedComponent.java @@ -52,6 +52,54 @@ public abstract class AbstractLeadedComponent extends AbstractTransparentComp } } + @Override + public void draw(Graphics2D g2d, ComponentState componentState, Project project) { + g2d.setStroke(new BasicStroke(getLeadThickness().convertToPixels())); + double distance = points[0].distance(points[1]); + Shape shape = getBodyShape(); + if (shape == null) { + g2d.drawLine(points[0].x, points[0].y, points[1].x, points[1].y); + return; + } + Rectangle shapeRect = shape.getBounds(); + double leadLenght = (distance - shapeRect.width) / 2; + Double theta = Math.atan2(points[1].y - points[0].y, points[1].x - points[0].x); + // Transform graphics to draw the body in the right place and at the + // right angle. + 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); + // Draw body. + if (componentState != ComponentState.DRAGGING) { + Composite oldComposite = g2d.getComposite(); + if (alpha < MAX_ALPHA) { + g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha + / MAX_ALPHA)); + } + g2d.setColor(bodyColor); + g2d.fill(shape); + g2d.setComposite(oldComposite); + } + // Draw leads. + g2d.setColor(getLeadColor()); + g2d.drawLine((int) (shapeRect.width - distance) / 2, (int) shapeRect.height / 2, + (int) ((shapeRect.width - distance) / 2 + leadLenght), (int) shapeRect.height / 2); + g2d.drawLine((int) (shapeRect.width + distance) / 2, (int) shapeRect.height / 2, + (int) ((shapeRect.width + distance) / 2 - leadLenght), (int) shapeRect.height / 2); + g2d.setStroke(new BasicStroke(1)); + g2d.setColor(borderColor); + g2d.draw(shape); + // Draw label. + g2d.setFont(Constants.LABEL_FONT); + g2d + .setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED + : LABEL_COLOR); + FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont()); + java.awt.geom.Rectangle2D textRect = fontMetrics.getStringBounds(getName(), g2d); + g2d.drawString(getName(), (int) (shapeRect.width - textRect.getWidth()) / 2, + (int) (shapeRect.height - textRect.getHeight()) / 2 + fontMetrics.getAscent()); + } + /** * @return default component width. */ @@ -109,54 +157,6 @@ public abstract class AbstractLeadedComponent extends AbstractTransparentComp points[index].setLocation(point); } - @Override - public void draw(Graphics2D g2d, ComponentState componentState, Project project) { - g2d.setColor(getLeadColor()); - g2d.setStroke(new BasicStroke(getLeadThickness().convertToPixels())); - double distance = points[0].distance(points[1]); - Shape shape = getBodyShape(); - if (shape == null) { - g2d.drawLine(points[0].x, points[0].y, points[1].x, points[1].y); - return; - } - Rectangle shapeRect = shape.getBounds(); - double leadLenght = (distance - shapeRect.width) / 2; - Double theta = Math.atan2(points[1].y - points[0].y, points[1].x - points[0].x); - // Draw leads. - g2d.drawLine(points[0].x, points[0].y, (int) (points[0].x + leadLenght * Math.cos(theta)), - (int) (points[0].y + leadLenght * Math.sin(theta))); - g2d.drawLine(points[1].x, points[1].y, (int) (points[1].x - leadLenght * Math.cos(theta)), - (int) (points[1].y - leadLenght * Math.sin(theta))); - // Transform graphics to draw the body in the right place and at the - // right angle. - 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); - // Draw body. - if (componentState != ComponentState.DRAGGING) { - Composite oldComposite = g2d.getComposite(); - if (alpha < MAX_ALPHA) { - g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha - / MAX_ALPHA)); - } - g2d.setColor(bodyColor); - g2d.fill(shape); - g2d.setComposite(oldComposite); - } - g2d.setStroke(new BasicStroke(1)); - g2d.setColor(borderColor); - g2d.draw(shape); - // Draw label. - g2d.setFont(Constants.LABEL_FONT); - g2d - .setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED - : LABEL_COLOR); - FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont()); - java.awt.geom.Rectangle2D textRect = fontMetrics.getStringBounds(getName(), g2d); - g2d.drawString(getName(), (int) (shapeRect.width - textRect.getWidth()) / 2, - (int) (shapeRect.height - textRect.getHeight()) / 2 + fontMetrics.getAscent()); - } - @EditableProperty(name = "Color") public Color getBodyColor() { return bodyColor; diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/Presenter.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/Presenter.java index 10e93e5e..cf2de98a 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/Presenter.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/Presenter.java @@ -59,7 +59,7 @@ public class Presenter implements IPlugInPort { public static final String DEFAULTS_KEY = "default."; public static final String METRIC_KEY = "metric"; - public static final int CONTROL_POINT_SENSITIVITY = 4; + public static final int CONTROL_POINT_SIZE = 5; public static final int ICON_SIZE = 32; public static boolean ENABLE_ANTIALIASING = true; public static boolean DEBUG_COMPONENT_AREAS = false; @@ -292,9 +292,11 @@ public class Presenter implements IPlugInPort { if (shouldShowControlPointsFor(component)) { g2d.setColor(Constants.CONTROL_POINT_COLOR); g2d.setStroke(new BasicStroke(2)); - g2d.drawOval(controlPoint.x - 2, controlPoint.y - 2, 4, 4); - // g2d.fillOval(point.getValue().x - 2, point - // .getValue().y - 2, 5, 5); + // g2d.drawOval(controlPoint.x - 2, + // controlPoint.y - 2, 4, 4); + g2d.fillOval(controlPoint.x - CONTROL_POINT_SIZE / 2, + controlPoint.y - CONTROL_POINT_SIZE / 2, + CONTROL_POINT_SIZE, CONTROL_POINT_SIZE); } } catch (Exception e) { LOG.error("Could not obtain control points for component of type " @@ -411,7 +413,7 @@ public class Presenter implements IPlugInPort { // Only consider selected components. if (selectedComponents.contains(component)) { try { - if (scaledPoint.distance(controlPoint) < CONTROL_POINT_SENSITIVITY) { + if (scaledPoint.distance(controlPoint) < CONTROL_POINT_SIZE) { Set indices = new HashSet(); ComponentType componentType = componentTypeMap .get(component.getClass()); diff --git a/ diy-layout-creator --username bancika@gmail.com/Library/lib/diylc.jar b/ diy-layout-creator --username bancika@gmail.com/Library/lib/diylc.jar deleted file mode 100644 index 8ccee306..00000000 Binary files a/ diy-layout-creator --username bancika@gmail.com/Library/lib/diylc.jar and /dev/null differ diff --git a/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/connectivity/HookupWire.java b/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/connectivity/HookupWire.java index 194ab1be..fe418e1b 100644 --- a/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/connectivity/HookupWire.java +++ b/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/connectivity/HookupWire.java @@ -20,16 +20,16 @@ public class HookupWire extends AbstractCurvedComponent { public static double INSULATION_THICKNESS_PCT = 0.3; protected AWG value = AWG._22; - + @Override protected Color getDefaultColor() { return COLOR; } - + @Override protected void drawCurve(CubicCurve2D curve, Graphics2D g2d) { int thickness = (int) (Math.pow(Math.E, -1.12436 - 0.11594 * value.getValue()) - * Constants.PIXELS_PER_INCH * (1 + 2 * INSULATION_THICKNESS_PCT)); + * Constants.GRID * Constants.GRIDS_PER_INCH * (1 + 2 * INSULATION_THICKNESS_PCT)); g2d.setColor(color.darker()); g2d.setStroke(new BasicStroke(thickness)); g2d.draw(curve);