diff --git a/diylc/diylc-core/src/org/diylc/common/IGraphProcessor.java b/diylc/diylc-core/src/org/diylc/common/IGraphProcessor.java index c38dfd8b..293b79a3 100644 --- a/diylc/diylc-core/src/org/diylc/common/IGraphProcessor.java +++ b/diylc/diylc-core/src/org/diylc/common/IGraphProcessor.java @@ -21,6 +21,7 @@ */ package org.diylc.common; +import java.util.List; import java.util.Map; import org.diylc.graph.Graph; @@ -28,5 +29,5 @@ import org.diylc.graph.GraphKey; public interface IGraphProcessor { - Map extractGraphs(); + Map> extractGraphs(); } diff --git a/diylc/diylc-core/src/org/diylc/components/AbstractComponent.java b/diylc/diylc-core/src/org/diylc/components/AbstractComponent.java index 0e8af038..4229464a 100644 --- a/diylc/diylc-core/src/org/diylc/components/AbstractComponent.java +++ b/diylc/diylc-core/src/org/diylc/components/AbstractComponent.java @@ -283,6 +283,6 @@ public abstract class AbstractComponent implements IDIYComponent { @Override public String getControlPointNodeName(int index) { - return getName() + "." + index; + return Integer.toString(index); } } diff --git a/diylc/diylc-core/src/org/diylc/graph/Graph.java b/diylc/diylc-core/src/org/diylc/graph/Graph.java index 9e3ae1c0..6d5d8790 100644 --- a/diylc/diylc-core/src/org/diylc/graph/Graph.java +++ b/diylc/diylc-core/src/org/diylc/graph/Graph.java @@ -18,11 +18,36 @@ public class Graph { return this.vertices.equals(other.vertices); } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((vertices == null) ? 0 : vertices.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Graph other = (Graph) obj; + if (vertices == null) { + if (other.vertices != null) + return false; + } else if (!vertices.equals(other.vertices)) + return false; + return true; + } + @Override public String toString() { StringBuilder sb = new StringBuilder(); for (Vertex v : vertices) { - sb.append("\t").append(v.getNode1()).append(" - ").append(v.getNode2()).append("\n"); + sb.append("\t").append(v).append("\n"); } return sb.toString(); } diff --git a/diylc/diylc-core/src/org/diylc/graph/Node.java b/diylc/diylc-core/src/org/diylc/graph/Node.java index 93fb905e..01c2a2e6 100644 --- a/diylc/diylc-core/src/org/diylc/graph/Node.java +++ b/diylc/diylc-core/src/org/diylc/graph/Node.java @@ -52,6 +52,6 @@ public class Node { @Override public String toString() { - return component.getName() + "." + pointIndex + " @ (" + component.getControlPoint(pointIndex).getX() + ":" + component.getControlPoint(pointIndex).getY() + ")"; + return component.getName() + "." + component.getControlPointNodeName(pointIndex) /*+ " @ (" + component.getControlPoint(pointIndex).getX() + ":" + component.getControlPoint(pointIndex).getY() + ")"*/; } } diff --git a/diylc/diylc-core/src/org/diylc/graph/Vertex.java b/diylc/diylc-core/src/org/diylc/graph/Vertex.java index 6c646e9a..d019861d 100644 --- a/diylc/diylc-core/src/org/diylc/graph/Vertex.java +++ b/diylc/diylc-core/src/org/diylc/graph/Vertex.java @@ -1,29 +1,34 @@ package org.diylc.graph; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + public class Vertex { - private Node node1; - private Node node2; + private Set nodes = new HashSet(); public Vertex(Node node1, Node node2) { - this.node1 = node1; - this.node2 = node2; + nodes.add(node1); + nodes.add(node2); } public Node getNode1() { - return node1; + Iterator i = nodes.iterator(); + return i.next(); } public Node getNode2() { - return node2; - } - + Iterator i = nodes.iterator(); + i.next(); + return i.next(); + } + @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((node1 == null) ? 0 : node1.hashCode()); - result = prime * result + ((node2 == null) ? 0 : node2.hashCode()); + result = prime * result + ((nodes == null) ? 0 : nodes.hashCode()); return result; } @@ -36,21 +41,16 @@ public class Vertex { if (getClass() != obj.getClass()) return false; Vertex other = (Vertex) obj; - if (node1 == null) { - if (other.node1 != null) + if (nodes == null) { + if (other.nodes != null) return false; - } else if (!node1.equals(other.node1)) - return false; - if (node2 == null) { - if (other.node2 != null) - return false; - } else if (!node2.equals(other.node2)) + } else if (!nodes.equals(other.nodes)) return false; return true; } @Override public String toString() { - return node1.toString() + " -> " + node2.toString(); + return getNode1().toString() + " <-> " + getNode2().toString(); } } diff --git a/diylc/diylc-core/src/org/diylc/presenter/Presenter.java b/diylc/diylc-core/src/org/diylc/presenter/Presenter.java index e2370acc..ea7d4655 100644 --- a/diylc/diylc-core/src/org/diylc/presenter/Presenter.java +++ b/diylc/diylc-core/src/org/diylc/presenter/Presenter.java @@ -301,7 +301,7 @@ public class Presenter implements IPlugInPort { LOG.info(String.format("loadProjectFromFile(%s)", fileName)); try { List warnings = new ArrayList(); - Project project = (Project) projectFileManager.deserializeProjectFromFile(fileName, warnings); + Project project = (Project) projectFileManager.deserializeProjectFromFile(fileName, warnings); loadProject(project, true); projectFileManager.fireFileStatusChanged(); if (!warnings.isEmpty()) { @@ -2687,8 +2687,8 @@ public class Presenter implements IPlugInPort { @SuppressWarnings("unchecked") @Override - public Map extractGraphs() { - Map result = new HashMap(); + public Map> extractGraphs() { + Map> result = new HashMap>(); List nodes = new ArrayList(); List switches = new ArrayList(); @@ -2753,7 +2753,15 @@ public class Presenter implements IPlugInPort { } List connections = getConnections(switchPositions); Graph graph = constructGraph(nodes, connections, continuity); - result.put(new GraphKey(posList), graph); + + // merge graphs that are effectivelly the same + if (result.containsKey(graph)) { + result.get(graph).add(new GraphKey(posList)); + } else { + List list = new ArrayList(); + list.add(new GraphKey(posList)); + result.put(graph, list); + } // find the next combination if possible if (positions[i] < switches.get(i).getPositionCount() - 1) { diff --git a/diylc/diylc-library/lib/diylc-core.jar b/diylc/diylc-library/lib/diylc-core.jar index e91b03aa..afba58ac 100644 Binary files a/diylc/diylc-library/lib/diylc-core.jar and b/diylc/diylc-library/lib/diylc-core.jar differ diff --git a/diylc/diylc-library/src/org/diylc/components/guitar/HumbuckerPickup.java b/diylc/diylc-library/src/org/diylc/components/guitar/HumbuckerPickup.java index 273f921e..c0b6df1c 100644 --- a/diylc/diylc-library/src/org/diylc/components/guitar/HumbuckerPickup.java +++ b/diylc/diylc-library/src/org/diylc/components/guitar/HumbuckerPickup.java @@ -1,612 +1,676 @@ /* + * + * DIY Layout Creator (DIYLC). Copyright (c) 2009-2018 held jointly by the individual authors. + * + * This file is part of DIYLC. + * + * DIYLC is free software: you can redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * DIYLC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with DIYLC. If not, see + * . + */ +package org.diylc.components.guitar; - DIY Layout Creator (DIYLC). - Copyright (c) 2009-2018 held jointly by the individual authors. - - This file is part of DIYLC. - - DIYLC is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - DIYLC is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with DIYLC. If not, see . - -*/ -package org.diylc.components.guitar; - -import java.awt.AlphaComposite; -import java.awt.Color; -import java.awt.Composite; -import java.awt.Graphics2D; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.Shape; +import java.awt.AlphaComposite; +import java.awt.Color; +import java.awt.Composite; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Shape; import java.awt.Stroke; -import java.awt.geom.AffineTransform; -import java.awt.geom.Area; -import java.awt.geom.Ellipse2D; +import java.awt.geom.AffineTransform; +import java.awt.geom.Area; +import java.awt.geom.Ellipse2D; import java.awt.geom.Path2D; import java.awt.geom.Rectangle2D; -import java.awt.geom.RoundRectangle2D; +import java.awt.geom.RoundRectangle2D; -import org.diylc.appframework.miscutils.ConfigurationManager; -import org.diylc.common.HorizontalAlignment; -import org.diylc.common.IPlugInPort; -import org.diylc.common.ObjectCache; -import org.diylc.common.Orientation; -import org.diylc.common.VerticalAlignment; -import org.diylc.components.AbstractTransparentComponent; -import org.diylc.core.ComponentState; -import org.diylc.core.IDIYComponent; -import org.diylc.core.IDrawingObserver; -import org.diylc.core.Project; -import org.diylc.core.Theme; -import org.diylc.core.VisibilityPolicy; -import org.diylc.core.annotations.ComponentDescriptor; -import org.diylc.core.annotations.EditableProperty; -import org.diylc.core.annotations.KeywordPolicy; -import org.diylc.core.measures.Size; -import org.diylc.core.measures.SizeUnit; -import org.diylc.utils.Constants; - -@ComponentDescriptor(name = "Humbucker Pickup", category = "Guitar", author = "Branislav Stojkovic", - description = "Double-coil humbucker guitar pickup (PAF, Mini Humbuckers, Filtertrons)", stretchable = false, zOrder = IDIYComponent.COMPONENT, - instanceNamePrefix = "PKP", autoEdit = false, keywordPolicy = KeywordPolicy.SHOW_TAG, - keywordTag = "Guitar Wiring Diagram") -public class HumbuckerPickup extends AbstractTransparentComponent { - - private static final long serialVersionUID = 1L; - - private static Color BASE_COLOR = Color.lightGray; - private static Color BOBIN_COLOR1 = Color.decode("#EAE3C6"); - private static Color BOBIN_COLOR2 = Color.black; - private static Color POINT_COLOR = Color.darkGray; - private static Size WIDTH = new Size(36.5d, SizeUnit.mm); - private static Size LENGTH = new Size(68.58d, SizeUnit.mm); - private static Size WIDTH_MINI = new Size(29.3d, SizeUnit.mm); +import org.diylc.appframework.miscutils.ConfigurationManager; +import org.diylc.common.HorizontalAlignment; +import org.diylc.common.IPlugInPort; +import org.diylc.common.ObjectCache; +import org.diylc.common.Orientation; +import org.diylc.common.VerticalAlignment; +import org.diylc.components.AbstractTransparentComponent; +import org.diylc.core.ComponentState; +import org.diylc.core.IDIYComponent; +import org.diylc.core.IDrawingObserver; +import org.diylc.core.Project; +import org.diylc.core.Theme; +import org.diylc.core.VisibilityPolicy; +import org.diylc.core.annotations.ComponentDescriptor; +import org.diylc.core.annotations.EditableProperty; +import org.diylc.core.annotations.KeywordPolicy; +import org.diylc.core.measures.Size; +import org.diylc.core.measures.SizeUnit; +import org.diylc.utils.Constants; + +@ComponentDescriptor(name = "Humbucker Pickup", category = "Guitar", author = "Branislav Stojkovic", + description = "Double-coil humbucker guitar pickup (PAF, Mini Humbuckers, Filtertrons)", stretchable = false, + zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "PKP", autoEdit = false, + keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "Guitar Wiring Diagram") +public class HumbuckerPickup extends AbstractTransparentComponent { + + private static final long serialVersionUID = 1L; + + private static Color BASE_COLOR = Color.lightGray; + private static Color BOBIN_COLOR1 = Color.decode("#EAE3C6"); + private static Color BOBIN_COLOR2 = Color.black; +// private static Color POINT_COLOR = Color.darkGray; + private static Size WIDTH = new Size(36.5d, SizeUnit.mm); + private static Size LENGTH = new Size(68.58d, SizeUnit.mm); + private static Size WIDTH_MINI = new Size(29.3d, SizeUnit.mm); private static Size LENGTH_MINI = new Size(67.4d, SizeUnit.mm); private static Size WIDTH_FILTERTRON = new Size(34.9d, SizeUnit.mm); private static Size LENGTH_FILTERTRON = new Size(71.4d, SizeUnit.mm); - private static Size FILTETRON_CUTOUT_MARGIN = new Size(1d, SizeUnit.mm); - private static Size LIP_WIDTH = new Size(12.7d, SizeUnit.mm); - private static Size LIP_LENGTH = new Size(7.9d, SizeUnit.mm); - private static Size EDGE_RADIUS = new Size(4d, SizeUnit.mm); + private static Size FILTETRON_CUTOUT_MARGIN = new Size(1d, SizeUnit.mm); + private static Size LIP_WIDTH = new Size(12.7d, SizeUnit.mm); + private static Size LIP_LENGTH = new Size(7.9d, SizeUnit.mm); + private static Size EDGE_RADIUS = new Size(4d, SizeUnit.mm); private static Size POINT_MARGIN = new Size(1.5d, SizeUnit.mm); - private static Size SCREW_LINE = new Size(1d, SizeUnit.mm); - private static Size POINT_SIZE = new Size(2d, SizeUnit.mm); - private static Size LIP_HOLE_SIZE = new Size(2d, SizeUnit.mm); + private static Size POINT_SPACING = new Size(0.1d, SizeUnit.in); + private static Size SCREW_LINE = new Size(1d, SizeUnit.mm); + private static Size POINT_SIZE = new Size(2d, SizeUnit.mm); + private static Size LIP_HOLE_SIZE = new Size(2d, SizeUnit.mm); private static Size POLE_SIZE = new Size(4d, SizeUnit.mm); - private static Size POLE_SIZE_FILTERTRON = new Size(5d, SizeUnit.mm); - private static Size POLE_SPACING = new Size(10.1d, SizeUnit.mm); - - private String value = ""; - private Point controlPoint = new Point(0, 0); - transient Shape[] body; - private Orientation orientation = Orientation.DEFAULT; - private Color color = BASE_COLOR; - private Color poleColor = METAL_COLOR; - private HumbuckerType type; - private boolean cover; - private Boolean legs = true; - private Color bobinColor1 = BOBIN_COLOR1; - private Color bobinColor2 = BOBIN_COLOR2; - private PolePieceType coilType1; - private PolePieceType coilType2; - - @Override - public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project, - IDrawingObserver drawingObserver) { - Shape[] body = getBody(); - - g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); - - Composite oldComposite = g2d.getComposite(); - if (alpha < MAX_ALPHA) { - g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA)); - } - g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : color); - if (getType() != HumbuckerType.Filtertron) - g2d.fill(body[0]); - if (body[1] != null) - g2d.fill(body[1]); + private static Size POLE_SIZE_FILTERTRON = new Size(5d, SizeUnit.mm); + private static Size POLE_SPACING = new Size(10.1d, SizeUnit.mm); - if (!outlineMode) { - if (body[4] != null) { - g2d.setColor(getBobinColor1()); - g2d.fill(body[4]); - } - if (body[5] != null) { - g2d.setColor(getBobinColor2()); - g2d.fill(body[5]); + private String value = ""; + private Point controlPoint = new Point(0, 0); + transient Shape[] body; + private Orientation orientation = Orientation.DEFAULT; + private Color color = BASE_COLOR; + private Color poleColor = METAL_COLOR; + private HumbuckerType type; + private boolean cover; + private Boolean legs = true; + private Color bobinColor1 = BOBIN_COLOR1; + private Color bobinColor2 = BOBIN_COLOR2; + private PolePieceType coilType1; + private PolePieceType coilType2; + + private Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0), new Point(0, 0)}; + + public HumbuckerPickup() { + updateControlPoints(); + } + + @Override + public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project, + IDrawingObserver drawingObserver) { + Shape[] body = getBody(); + + g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); + + Composite oldComposite = g2d.getComposite(); + if (alpha < MAX_ALPHA) { + g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA)); + } + g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : color); + if (getType() != HumbuckerType.Filtertron) + g2d.fill(body[0]); + if (body[1] != null) + g2d.fill(body[1]); + + if (!outlineMode) { + if (body[4] != null) { + g2d.setColor(getBobinColor1()); + g2d.fill(body[4]); + } + if (body[5] != null) { + g2d.setColor(getBobinColor2()); + g2d.fill(body[5]); } } - + if (getType() == HumbuckerType.Filtertron) { g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : color); g2d.fill(body[0]); - } - - g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : POINT_COLOR); - g2d.fill(body[2]); - - g2d.setComposite(oldComposite); - - - Color finalBorderColor; - if (outlineMode) { - Theme theme = - (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); - finalBorderColor = - componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR - : theme.getOutlineColor(); - } else { - finalBorderColor = - componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR - : color.darker(); - } - - g2d.setColor(finalBorderColor); - if (getType() != HumbuckerType.Filtertron) - g2d.draw(body[0]); - if (body[1] != null) - g2d.draw(body[1]); + } - if (!outlineMode) { - g2d.setColor(getPoleColor()); - g2d.fill(body[3]); - g2d.setColor(darkerOrLighter(getPoleColor())); + // g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : POINT_COLOR); + // g2d.fill(body[2]); + + g2d.setComposite(oldComposite); + + + Color finalBorderColor; + if (outlineMode) { + Theme theme = + (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); + finalBorderColor = + componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR + : theme.getOutlineColor(); + } else { + finalBorderColor = + componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR + : color.darker(); + } + + g2d.setColor(finalBorderColor); + if (getType() != HumbuckerType.Filtertron) + g2d.draw(body[0]); + if (body[1] != null) + g2d.draw(body[1]); + + if (!outlineMode) { + g2d.setColor(getPoleColor()); + g2d.fill(body[3]); + g2d.setColor(darkerOrLighter(getPoleColor())); g2d.draw(body[3]); if (body[6] != null) - g2d.draw(body[6]); - - if (getType() != HumbuckerType.Filtertron) { - if (body[4] != null) { - g2d.setColor(getBobinColor1().darker()); - g2d.draw(body[4]); - } - if (body[5] != null) { - g2d.setColor(getBobinColor2().darker()); - g2d.draw(body[5]); + g2d.draw(body[6]); + + if (getType() != HumbuckerType.Filtertron) { + if (body[4] != null) { + g2d.setColor(getBobinColor1().darker()); + g2d.draw(body[4]); + } + if (body[5] != null) { + g2d.setColor(getBobinColor2().darker()); + g2d.draw(body[5]); } } - } - + } + if (getType() == HumbuckerType.Filtertron) { g2d.setColor(finalBorderColor); g2d.draw(body[0]); - } - - Color finalLabelColor; - if (outlineMode) { - Theme theme = - (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); - finalLabelColor = - componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED - : theme.getOutlineColor(); - } else { - finalLabelColor = - componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED - : LABEL_COLOR; - } - g2d.setColor(finalLabelColor); - g2d.setFont(project.getFont()); - Rectangle bounds = body[0].getBounds(); - drawCenteredText(g2d, value, bounds.x + bounds.width / 2, bounds.y + bounds.height / 2, HorizontalAlignment.CENTER, - VerticalAlignment.CENTER); - } - - @SuppressWarnings("incomplete-switch") - public Shape[] getBody() { - if (body == null) { - body = new Shape[7]; - - int x = controlPoint.x; - int y = controlPoint.y; - int width = (int) getType().getWidth().convertToPixels(); - int length = (int) getType().getLength().convertToPixels(); - int lipWidth = (int) LIP_WIDTH.convertToPixels(); - int lipLength = (int) LIP_LENGTH.convertToPixels(); - int edgeRadius = (int) EDGE_RADIUS.convertToPixels(); - int pointMargin = (int) POINT_MARGIN.convertToPixels(); - int pointSize = getClosestOdd(POINT_SIZE.convertToPixels()); + } + + Color finalLabelColor; + if (outlineMode) { + Theme theme = + (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); + finalLabelColor = + componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED + : theme.getOutlineColor(); + } else { + finalLabelColor = + componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED + : LABEL_COLOR; + } + g2d.setColor(finalLabelColor); + g2d.setFont(project.getFont()); + Rectangle bounds = body[0].getBounds(); + drawCenteredText(g2d, value, bounds.x + bounds.width / 2, bounds.y + bounds.height / 2, HorizontalAlignment.CENTER, + VerticalAlignment.CENTER); + } + + private Point[] getControlPoints() { + if (controlPoints == null) { + controlPoints = + new Point[] {controlPoint, new Point(controlPoint.x, controlPoint.y), + new Point(controlPoint.x, controlPoint.y), new Point(controlPoint.x, controlPoint.y)}; + updateControlPoints(); + } + return controlPoints; + } + + @SuppressWarnings("incomplete-switch") + private void updateControlPoints() { + Point[] points = getControlPoints(); + int pointSpacing = (int) POINT_SPACING.convertToPixels(); + int dx = 0; + int dy = 1; + if (orientation != Orientation.DEFAULT) { + switch (orientation) { + case _90: + dx = -1; + dy = 0; + break; + case _180: + dx = 0; + dy = -1; + break; + case _270: + dx = 1; + dy = 0; + break; + } + } + points[1].setLocation(points[0].x + dx * pointSpacing, points[0].y + dy * pointSpacing); + points[2] + .setLocation(points[0].x + 2 * dx * pointSpacing, points[0].y + 2 * dy * pointSpacing); + points[3] + .setLocation(points[0].x + 3 * dx * pointSpacing, points[0].y + 3 * dy * pointSpacing); + } + + @SuppressWarnings("incomplete-switch") + public Shape[] getBody() { + if (body == null) { + body = new Shape[7]; + + Point[] points = getControlPoints(); + int x = points[0].x; + int y = points[0].y; + int width = (int) getType().getWidth().convertToPixels(); + int length = (int) getType().getLength().convertToPixels(); + int lipWidth = (int) LIP_WIDTH.convertToPixels(); + int lipLength = (int) LIP_LENGTH.convertToPixels(); + int edgeRadius = (int) EDGE_RADIUS.convertToPixels(); + int pointMargin = (int) POINT_MARGIN.convertToPixels(); + int pointSize = getClosestOdd(POINT_SIZE.convertToPixels()); int lipHoleSize = getClosestOdd(LIP_HOLE_SIZE.convertToPixels()); int poleSize = (int) getType().getPoleSize().convertToPixels(); int poleSpacing = (int) POLE_SPACING.convertToPixels(); int coilSpacing = width / 2; int coilMargin = (width - coilSpacing) / 2; int poleMargin = (length - poleSpacing * 5) / 2; - - Area base = new Area(new RoundRectangle2D.Double(x + pointMargin - length, y - pointMargin, length, width, edgeRadius, - edgeRadius)); - // base or cover + Area base = + new Area(new RoundRectangle2D.Double(x /* + pointMargin */- length, y - pointMargin, length, width, + edgeRadius, edgeRadius)); + + // base or cover body[0] = new Area(base); if (getType() == HumbuckerType.Filtertron) { int cutoutMargin = (int) FILTETRON_CUTOUT_MARGIN.convertToPixels(); int cutoutHeight = poleSize + 2 * cutoutMargin; int cutoutWidth = 5 * poleSpacing + poleSize + 2 * cutoutMargin; - Area cutout = new Area(new RoundRectangle2D.Double(x + pointMargin - length + poleMargin - poleSize / 2 - cutoutMargin, y - - pointMargin + coilMargin - poleSize / 2 - cutoutMargin, cutoutWidth, cutoutHeight, cutoutHeight, cutoutHeight)); - ((Area)body[0]).subtract(cutout); - cutout = new Area(new RoundRectangle2D.Double(x + pointMargin - length + poleMargin - poleSize / 2 - cutoutMargin, y - - pointMargin + width - coilMargin - poleSize / 2 - cutoutMargin, cutoutWidth, cutoutHeight, cutoutHeight, cutoutHeight)); - ((Area)body[0]).subtract(cutout); + Area cutout = + new Area(new RoundRectangle2D.Double(x /* + pointMargin */- length + poleMargin - poleSize / 2 + - cutoutMargin, y - pointMargin + coilMargin - poleSize / 2 - cutoutMargin, cutoutWidth, cutoutHeight, + cutoutHeight, cutoutHeight)); + ((Area) body[0]).subtract(cutout); + cutout = + new Area(new RoundRectangle2D.Double(x /* + pointMargin */- length + poleMargin - poleSize / 2 + - cutoutMargin, y - pointMargin + width - coilMargin - poleSize / 2 - cutoutMargin, cutoutWidth, + cutoutHeight, cutoutHeight, cutoutHeight)); + ((Area) body[0]).subtract(cutout); int middleCutoutWidth = poleSpacing / 5; - cutout = new Area(new Rectangle2D.Double(x + pointMargin - length / 2 - middleCutoutWidth / 2, y - - pointMargin + width / 4, middleCutoutWidth, width / 2)); - ((Area)body[0]).subtract(cutout); + cutout = + new Area(new Rectangle2D.Double(x /* + pointMargin */- length / 2 - middleCutoutWidth / 2, y - pointMargin + + width / 4, middleCutoutWidth, width / 2)); + ((Area) body[0]).subtract(cutout); if (!getLegs()) { - cutout = new Area(new Ellipse2D.Double(x + pointMargin - length + lipHoleSize * 2, y - - pointMargin + width / 2 - lipHoleSize * 0.75, lipHoleSize * 1.5, lipHoleSize * 1.5)); - ((Area)body[0]).subtract(cutout); - cutout = new Area(new Ellipse2D.Double(x + pointMargin - lipHoleSize * 3, y - - pointMargin + width / 2 - lipHoleSize * 0.75, lipHoleSize* 1.5, lipHoleSize* 1.5)); - ((Area)body[0]).subtract(cutout); + cutout = + new Area(new Ellipse2D.Double(x /* + pointMargin */- length + lipHoleSize * 2, y - pointMargin + width + / 2 - lipHoleSize * 0.75, lipHoleSize * 1.5, lipHoleSize * 1.5)); + ((Area) body[0]).subtract(cutout); + cutout = + new Area(new Ellipse2D.Double(x /* + pointMargin */- lipHoleSize * 3, y - pointMargin + width / 2 + - lipHoleSize * 0.75, lipHoleSize * 1.5, lipHoleSize * 1.5)); + ((Area) body[0]).subtract(cutout); } } - - // bobins - if (!getCover() || getType() == HumbuckerType.Filtertron) { + + // bobins + if (!getCover() || getType() == HumbuckerType.Filtertron) { int bobinWidth = width / 2; - int bobinRadius = (int) (getType() == HumbuckerType.Filtertron ? edgeRadius * 1.1f : bobinWidth); - body[4] = - new Area(new RoundRectangle2D.Double(x + pointMargin - length, y - pointMargin, length, bobinWidth, - bobinRadius, bobinRadius)); - body[5] = - new Area(new RoundRectangle2D.Double(x + pointMargin - length, y - pointMargin + bobinWidth, length, - bobinWidth, bobinRadius, bobinRadius)); - } + int bobinRadius = (int) (getType() == HumbuckerType.Filtertron ? edgeRadius * 1.1f : bobinWidth); + body[4] = + new Area(new RoundRectangle2D.Double(x /* + pointMargin */- length, y - pointMargin, length, bobinWidth, + bobinRadius, bobinRadius)); + body[5] = + new Area(new RoundRectangle2D.Double(x /* + pointMargin */- length, y - pointMargin + bobinWidth, length, + bobinWidth, bobinRadius, bobinRadius)); + } // legs - if (getLegs()) { - Area legArea = new Area(new RoundRectangle2D.Double(x + pointMargin - length - lipLength, y - pointMargin + width / 2 - - lipWidth / 2, length + 2 * lipLength, lipWidth, edgeRadius / 2, edgeRadius / 2)); - legArea.subtract((Area) (body[0])); - legArea.subtract(new Area(new Ellipse2D.Double(x + pointMargin - length - lipLength / 2, y - pointMargin + width - / 2 - lipHoleSize / 2, lipHoleSize, lipHoleSize))); - legArea.subtract(new Area(new Ellipse2D.Double(x + pointMargin + lipLength / 2, y - pointMargin + width / 2 - - lipHoleSize / 2, lipHoleSize, lipHoleSize))); - legArea.subtract(base); + if (getLegs()) { + Area legArea = + new Area(new RoundRectangle2D.Double(x /* + pointMargin */- length - lipLength, y - pointMargin + width / 2 + - lipWidth / 2, length + 2 * lipLength, lipWidth, edgeRadius / 2, edgeRadius / 2)); + legArea.subtract((Area) (body[0])); + legArea.subtract(new Area(new Ellipse2D.Double(x /* + pointMargin */- length - lipLength / 2, y - pointMargin + + width / 2 - lipHoleSize / 2, lipHoleSize, lipHoleSize))); + legArea.subtract(new Area(new Ellipse2D.Double(x /* + pointMargin */+ lipLength / 2, y - pointMargin + width + / 2 - lipHoleSize / 2, lipHoleSize, lipHoleSize))); + legArea.subtract(base); body[1] = legArea; } - - // contact point - body[2] = new Area(new Ellipse2D.Double(x - pointSize / 2, y - pointSize / 2, pointSize, pointSize)); - + + // contact point + body[2] = new Area(new Ellipse2D.Double(x - pointSize / 2, y - pointSize / 2, pointSize, pointSize)); + Area poleArea = new Area(); - Area poleDecorationArea = new Area(); - - if (getCoilType1() == PolePieceType.Rail) { - poleArea.add(new Area( - new RoundRectangle2D.Double(x + pointMargin - length + poleMargin - poleSize / 2, y - pointMargin - + coilMargin - poleSize / 2, poleSpacing * 5 + poleSize, poleSize, poleSize / 2, poleSize / 2))); + Area poleDecorationArea = new Area(); + + if (getCoilType1() == PolePieceType.Rail) { + poleArea.add(new Area( + new RoundRectangle2D.Double(x /* + pointMargin */- length + poleMargin - poleSize / 2, y - pointMargin + + coilMargin - poleSize / 2, poleSpacing * 5 + poleSize, poleSize, poleSize / 2, poleSize / 2))); } else if (getCoilType1() == PolePieceType.Rods || getCoilType1() == PolePieceType.Screws) { - Path2D screwPath = new Path2D.Double(); - for (int i = 0; i < 6; i++) { - Ellipse2D pole = - new Ellipse2D.Double(x + pointMargin - length + poleMargin + i * poleSpacing - poleSize / 2, y - - pointMargin + coilMargin - poleSize / 2, poleSize, poleSize); + Path2D screwPath = new Path2D.Double(); + for (int i = 0; i < 6; i++) { + Ellipse2D pole = + new Ellipse2D.Double(x /* + pointMargin */- length + poleMargin + i * poleSpacing - poleSize / 2, y + - pointMargin + coilMargin - poleSize / 2, poleSize, poleSize); poleArea.add(new Area(pole)); if (getCoilType1() == PolePieceType.Screws) { if (i % 2 == 0) { - screwPath.moveTo(x + pointMargin - length + poleMargin + i * poleSpacing - poleSize / 2, y + screwPath.moveTo(x /* + pointMargin */- length + poleMargin + i * poleSpacing - poleSize / 2, y - pointMargin + coilMargin - poleSize / 2); - screwPath.lineTo(x + pointMargin - length + poleMargin + i * poleSpacing - poleSize / 2 + poleSize, y - - pointMargin + coilMargin - poleSize / 2 + poleSize); + screwPath.lineTo(x /* + pointMargin */- length + poleMargin + i * poleSpacing - poleSize / 2 + poleSize, + y - pointMargin + coilMargin - poleSize / 2 + poleSize); } else { - screwPath.moveTo(x + pointMargin - length + poleMargin + i * poleSpacing - poleSize / 2, y + screwPath.moveTo(x /* + pointMargin */- length + poleMargin + i * poleSpacing - poleSize / 2, y - pointMargin + coilMargin - poleSize / 2 + poleSize); - screwPath.lineTo(x + pointMargin - length + poleMargin + i * poleSpacing - poleSize / 2 + poleSize, y - - pointMargin + coilMargin - poleSize / 2); + screwPath.lineTo(x /* + pointMargin */- length + poleMargin + i * poleSpacing - poleSize / 2 + poleSize, + y - pointMargin + coilMargin - poleSize / 2); } - } + } } if (getCoilType1() == PolePieceType.Screws) { Stroke pathStroke = ObjectCache.getInstance().fetchBasicStroke((float) SCREW_LINE.convertToPixels()); Area screwArea = new Area(pathStroke.createStrokedShape(screwPath)); screwArea.intersect(poleArea); poleDecorationArea.add(screwArea); - } - } - - if (getCoilType2() == PolePieceType.Rail) { - poleArea.add(new Area(new RoundRectangle2D.Double(x + pointMargin - length + poleMargin - poleSize / 2, y - - pointMargin + width - coilMargin - poleSize / 2, poleSpacing * 5 + poleSize, poleSize, poleSize / 2, - poleSize / 2))); - } else if (getCoilType2() == PolePieceType.Rods|| getCoilType2() == PolePieceType.Screws) { - Path2D screwPath = new Path2D.Double(); - for (int i = 0; i < 6; i++) { - Ellipse2D pole = - new Ellipse2D.Double(x + pointMargin - length + poleMargin + i * poleSpacing - poleSize / 2, y - - pointMargin + width - coilMargin - poleSize / 2, poleSize, poleSize); + } + } + + if (getCoilType2() == PolePieceType.Rail) { + poleArea.add(new Area(new RoundRectangle2D.Double(x /* + pointMargin */- length + poleMargin - poleSize / 2, y + - pointMargin + width - coilMargin - poleSize / 2, poleSpacing * 5 + poleSize, poleSize, poleSize / 2, + poleSize / 2))); + } else if (getCoilType2() == PolePieceType.Rods || getCoilType2() == PolePieceType.Screws) { + Path2D screwPath = new Path2D.Double(); + for (int i = 0; i < 6; i++) { + Ellipse2D pole = + new Ellipse2D.Double(x /* + pointMargin */- length + poleMargin + i * poleSpacing - poleSize / 2, y + - pointMargin + width - coilMargin - poleSize / 2, poleSize, poleSize); poleArea.add(new Area(pole)); if (getCoilType1() == PolePieceType.Screws) { if (i % 2 == 1) { - screwPath.moveTo(x + pointMargin - length + poleMargin + i * poleSpacing - poleSize / 2, y + screwPath.moveTo(x /* + pointMargin */- length + poleMargin + i * poleSpacing - poleSize / 2, y - pointMargin + width - coilMargin - poleSize / 2); - screwPath.lineTo(x + pointMargin - length + poleMargin + i * poleSpacing - poleSize / 2 + poleSize, y - - pointMargin + width - coilMargin - poleSize / 2 + poleSize); + screwPath.lineTo(x /* + pointMargin */- length + poleMargin + i * poleSpacing - poleSize / 2 + poleSize, + y - pointMargin + width - coilMargin - poleSize / 2 + poleSize); } else { - screwPath.moveTo(x + pointMargin - length + poleMargin + i * poleSpacing - poleSize / 2, y + screwPath.moveTo(x /* + pointMargin */- length + poleMargin + i * poleSpacing - poleSize / 2, y - pointMargin + width - coilMargin - poleSize / 2 + poleSize); - screwPath.lineTo(x + pointMargin - length + poleMargin + i * poleSpacing - poleSize / 2 + poleSize, y - - pointMargin + width - coilMargin - poleSize / 2); + screwPath.lineTo(x /* + pointMargin */- length + poleMargin + i * poleSpacing - poleSize / 2 + poleSize, + y - pointMargin + width - coilMargin - poleSize / 2); } - } + } } if (getCoilType2() == PolePieceType.Screws) { Stroke pathStroke = ObjectCache.getInstance().fetchBasicStroke((float) SCREW_LINE.convertToPixels()); Area screwArea = new Area(pathStroke.createStrokedShape(screwPath)); screwArea.intersect(poleArea); poleDecorationArea.add(screwArea); - } - } - + } + } + body[3] = poleArea; - body[6] = poleDecorationArea; - - // Rotate if needed - if (orientation != Orientation.DEFAULT) { - double theta = 0; - switch (orientation) { - case _90: - theta = Math.PI / 2; - break; - case _180: - theta = Math.PI; - break; - case _270: - theta = Math.PI * 3 / 2; - break; - } - AffineTransform rotation = AffineTransform.getRotateInstance(theta, x, y); - for (Shape shape : body) { + body[6] = poleDecorationArea; + + // Rotate if needed + if (orientation != Orientation.DEFAULT) { + double theta = 0; + switch (orientation) { + case _90: + theta = Math.PI / 2; + break; + case _180: + theta = Math.PI; + break; + case _270: + theta = Math.PI * 3 / 2; + break; + } + AffineTransform rotation = AffineTransform.getRotateInstance(theta, x, y); + for (Shape shape : body) { Area area = (Area) shape; - if (area != null) - area.transform(rotation); - } - } - } - return body; - } - - @Override - public void drawIcon(Graphics2D g2d, int width, int height) { - g2d.rotate(Math.PI / 4, width / 2, height / 2); - - int baseWidth = 16 * width / 32; - int baseLength = 27 * width / 32; - - g2d.setColor(BASE_COLOR); - g2d.fillRoundRect((width - baseWidth / 4) / 2, 0, baseWidth / 4, height - 1, 2 * width / 32, 2 * width / 32); - g2d.setColor(BASE_COLOR.darker()); - g2d.drawRoundRect((width - baseWidth / 4) / 2, 0, baseWidth / 4, height - 1, 2 * width / 32, 2 * width / 32); - - g2d.setColor(BASE_COLOR); - g2d.fillRoundRect((width - baseWidth) / 2, (height - baseLength) / 2, baseWidth, baseLength, 4 * width / 32, - 4 * width / 32); - g2d.setColor(BASE_COLOR.darker()); - g2d.drawRoundRect((width - baseWidth) / 2, (height - baseLength) / 2, baseWidth, baseLength, 4 * width / 32, - 4 * width / 32); - - g2d.setColor(BOBIN_COLOR1); - g2d.fillRoundRect((width - baseWidth) / 2, (height - baseLength) / 2, baseWidth / 2, baseLength, baseWidth / 2, - baseWidth / 2); - g2d.setColor(BOBIN_COLOR2); - g2d.fillRoundRect(width / 2, (height - baseLength) / 2, baseWidth / 2, baseLength, baseWidth / 2, baseWidth / 2); - - g2d.setColor(METAL_COLOR); - int poleSize = 2; - int poleSpacing = 17 * width / 32; - for (int i = 0; i < 6; i++) { - g2d.fillOval((width - poleSize - baseWidth / 2) / 2, (height - poleSpacing) / 2 + (i * poleSpacing / 5), - poleSize, poleSize); - g2d.fillOval((width - poleSize + baseWidth / 2) / 2, (height - poleSpacing) / 2 + (i * poleSpacing / 5), - poleSize, poleSize); - } - } - - @EditableProperty - public HumbuckerType getType() { - if (type == null) - type = HumbuckerType.PAF; - return type; - } - - public void setType(HumbuckerType type) { - this.type = type; - // Invalidate the body - body = null; - } - - @EditableProperty(name = "Bobin 1") - public Color getBobinColor1() { - if (bobinColor1 == null) - bobinColor1 = BOBIN_COLOR1; - return bobinColor1; - } - - public void setBobinColor1(Color bobinColor1) { - this.bobinColor1 = bobinColor1; - } - - @EditableProperty(name = "Bobin 2") - public Color getBobinColor2() { - if (bobinColor2 == null) - bobinColor2 = BOBIN_COLOR2; - return bobinColor2; - } - - public void setBobinColor2(Color bobinColor2) { - this.bobinColor2 = bobinColor2; - } - - @EditableProperty - public boolean getCover() { - return cover; - } - - public void setCover(boolean cover) { - this.cover = cover; - // Invalidate the body - body = null; + if (area != null) + area.transform(rotation); + } + } + } + return body; } - + + @Override + public void drawIcon(Graphics2D g2d, int width, int height) { + g2d.rotate(Math.PI / 4, width / 2, height / 2); + + int baseWidth = 16 * width / 32; + int baseLength = 27 * width / 32; + + g2d.setColor(BASE_COLOR); + g2d.fillRoundRect((width - baseWidth / 4) / 2, 0, baseWidth / 4, height - 1, 2 * width / 32, 2 * width / 32); + g2d.setColor(BASE_COLOR.darker()); + g2d.drawRoundRect((width - baseWidth / 4) / 2, 0, baseWidth / 4, height - 1, 2 * width / 32, 2 * width / 32); + + g2d.setColor(BASE_COLOR); + g2d.fillRoundRect((width - baseWidth) / 2, (height - baseLength) / 2, baseWidth, baseLength, 4 * width / 32, + 4 * width / 32); + g2d.setColor(BASE_COLOR.darker()); + g2d.drawRoundRect((width - baseWidth) / 2, (height - baseLength) / 2, baseWidth, baseLength, 4 * width / 32, + 4 * width / 32); + + g2d.setColor(BOBIN_COLOR1); + g2d.fillRoundRect((width - baseWidth) / 2, (height - baseLength) / 2, baseWidth / 2, baseLength, baseWidth / 2, + baseWidth / 2); + g2d.setColor(BOBIN_COLOR2); + g2d.fillRoundRect(width / 2, (height - baseLength) / 2, baseWidth / 2, baseLength, baseWidth / 2, baseWidth / 2); + + g2d.setColor(METAL_COLOR); + int poleSize = 2; + int poleSpacing = 17 * width / 32; + for (int i = 0; i < 6; i++) { + g2d.fillOval((width - poleSize - baseWidth / 2) / 2, (height - poleSpacing) / 2 + (i * poleSpacing / 5), + poleSize, poleSize); + g2d.fillOval((width - poleSize + baseWidth / 2) / 2, (height - poleSpacing) / 2 + (i * poleSpacing / 5), + poleSize, poleSize); + } + } + + @EditableProperty + public HumbuckerType getType() { + if (type == null) + type = HumbuckerType.PAF; + return type; + } + + public void setType(HumbuckerType type) { + this.type = type; + // Invalidate the body + body = null; + } + + @EditableProperty(name = "Bobin 1") + public Color getBobinColor1() { + if (bobinColor1 == null) + bobinColor1 = BOBIN_COLOR1; + return bobinColor1; + } + + public void setBobinColor1(Color bobinColor1) { + this.bobinColor1 = bobinColor1; + } + + @EditableProperty(name = "Bobin 2") + public Color getBobinColor2() { + if (bobinColor2 == null) + bobinColor2 = BOBIN_COLOR2; + return bobinColor2; + } + + public void setBobinColor2(Color bobinColor2) { + this.bobinColor2 = bobinColor2; + } + + @EditableProperty + public boolean getCover() { + return cover; + } + + public void setCover(boolean cover) { + this.cover = cover; + // Invalidate the body + body = null; + } + @EditableProperty public Boolean getLegs() { if (legs == null) legs = true; return legs; } - + public void setLegs(Boolean legs) { this.legs = legs; // Invalidate the body body = null; - } - - @Override - public int getControlPointCount() { - return 1; - } - - @Override - public VisibilityPolicy getControlPointVisibilityPolicy(int index) { - return VisibilityPolicy.WHEN_SELECTED; - } - - @Override - public boolean isControlPointSticky(int index) { - return true; - } - - @Override - public Point getControlPoint(int index) { - return controlPoint; - } - - @Override - public void setControlPoint(Point point, int index) { - this.controlPoint.setLocation(point); - // Invalidate the body - body = null; - } - - @EditableProperty(name = "Model") - @Override - public String getValue() { - return value; - } - - @Override - public void setValue(String value) { - this.value = value; - } - - @EditableProperty - public Orientation getOrientation() { - return orientation; - } - - public void setOrientation(Orientation orientation) { - this.orientation = orientation; - // Invalidate the body - body = null; - } - - @EditableProperty - public Color getColor() { - return color; - } - - public void setColor(Color color) { - this.color = color; - } - - @EditableProperty(name = "Pole Color") - public Color getPoleColor() { - if (poleColor == null) - poleColor = METAL_COLOR; - return poleColor; - } - - public void setPoleColor(Color poleColor) { - this.poleColor = poleColor; - } - - @EditableProperty(name = "Pole Pieces 1") - public PolePieceType getCoilType1() { - if (coilType1 == null) { - return PolePieceType.Screws; - } - return coilType1; - } - - public void setCoilType1(PolePieceType coilType1) { - this.coilType1 = coilType1; - // Invalidate the body - body = null; - } - - @EditableProperty(name = "Pole Pieces 2") - public PolePieceType getCoilType2() { - if (coilType2 == null) { - return PolePieceType.Rods; - } - return coilType2; - } - - public void setCoilType2(PolePieceType coilType2) { - this.coilType2 = coilType2; - // Invalidate the body - body = null; } - + + @Override + public int getControlPointCount() { + return 4; + } + + @Override + public VisibilityPolicy getControlPointVisibilityPolicy(int index) { + return VisibilityPolicy.ALWAYS; + } + + @Override + public boolean isControlPointSticky(int index) { + return true; + } + + @Override + public Point getControlPoint(int index) { + return getControlPoints()[index]; + } + + @Override + public void setControlPoint(Point point, int index) { + getControlPoints()[index].setLocation(point); + // Invalidate the body + body = null; + } + + @EditableProperty(name = "Model") + @Override + public String getValue() { + return value; + } + + @Override + public void setValue(String value) { + this.value = value; + } + + @EditableProperty + public Orientation getOrientation() { + return orientation; + } + + public void setOrientation(Orientation orientation) { + this.orientation = orientation; + // Invalidate the body + body = null; + updateControlPoints(); + } + + @EditableProperty + public Color getColor() { + return color; + } + + public void setColor(Color color) { + this.color = color; + } + + @EditableProperty(name = "Pole Color") + public Color getPoleColor() { + if (poleColor == null) + poleColor = METAL_COLOR; + return poleColor; + } + + public void setPoleColor(Color poleColor) { + this.poleColor = poleColor; + } + + @EditableProperty(name = "Pole Pieces 1") + public PolePieceType getCoilType1() { + if (coilType1 == null) { + return PolePieceType.Screws; + } + return coilType1; + } + + public void setCoilType1(PolePieceType coilType1) { + this.coilType1 = coilType1; + // Invalidate the body + body = null; + } + + @EditableProperty(name = "Pole Pieces 2") + public PolePieceType getCoilType2() { + if (coilType2 == null) { + return PolePieceType.Rods; + } + return coilType2; + } + + public void setCoilType2(PolePieceType coilType2) { + this.coilType2 = coilType2; + // Invalidate the body + body = null; + } + @Override public String getControlPointNodeName(int index) { - return "PickupTerminal"; - } - - public static enum HumbuckerType { - - PAF(WIDTH, LENGTH, POLE_SIZE), Mini(WIDTH_MINI, LENGTH_MINI, POLE_SIZE), Filtertron(WIDTH_FILTERTRON, LENGTH_FILTERTRON, POLE_SIZE_FILTERTRON); - - private Size width; - private Size length; - private Size poleSize; - - private HumbuckerType(Size width, Size length, Size poleSize) { - this.width = width; - this.length = length; - this.poleSize = poleSize; - } - - public Size getWidth() { - return width; - } - - public Size getLength() { - return length; + switch (index) { + case 0: + return"North Start"; + case 1: + return "North End"; + case 2: + return "South Start"; + case 3: + return "South End"; } - + return null; + } + + public static enum HumbuckerType { + + PAF(WIDTH, LENGTH, POLE_SIZE), Mini(WIDTH_MINI, LENGTH_MINI, POLE_SIZE), Filtertron(WIDTH_FILTERTRON, + LENGTH_FILTERTRON, POLE_SIZE_FILTERTRON); + + private Size width; + private Size length; + private Size poleSize; + + private HumbuckerType(Size width, Size length, Size poleSize) { + this.width = width; + this.length = length; + this.poleSize = poleSize; + } + + public Size getWidth() { + return width; + } + + public Size getLength() { + return length; + } + public Size getPoleSize() { return poleSize; - } - - @Override - public String toString() { - return name(); - } - } - - public enum PolePieceType { - Rods, Rail, Screws, None; - } -} + } + + @Override + public String toString() { + return name(); + } + } + + public enum PolePieceType { + Rods, Rail, Screws, None; + } +} diff --git a/diylc/diylc-library/src/org/diylc/components/guitar/SingleCoilPickup.java b/diylc/diylc-library/src/org/diylc/components/guitar/SingleCoilPickup.java index f404399a..2a9a9b2a 100644 --- a/diylc/diylc-library/src/org/diylc/components/guitar/SingleCoilPickup.java +++ b/diylc/diylc-library/src/org/diylc/components/guitar/SingleCoilPickup.java @@ -65,10 +65,11 @@ public class SingleCoilPickup extends AbstractTransparentComponent { private static Color BODY_COLOR = Color.white; private static Color BASE_COLOR = Color.gray; - private static Color POINT_COLOR = Color.lightGray; +// private static Color POINT_COLOR = Color.lightGray; private static Size WIDTH = new Size(15.5d, SizeUnit.mm); private static Size LENGTH = new Size(83d, SizeUnit.mm); - private static Size BASE_RADIUS = new Size(0.15d, SizeUnit.in); + private static Size BASE_RADIUS = new Size(0.15d, SizeUnit.in); + private static Size POINT_SPACING = new Size(0.1d, SizeUnit.in); // strat-specific private static Size STRAT_LIP_WIDTH = new Size(5d, SizeUnit.mm); @@ -99,7 +100,52 @@ public class SingleCoilPickup extends AbstractTransparentComponent { private Color poleColor = METAL_COLOR; private Color baseColor = BASE_COLOR; private SingleCoilType type = SingleCoilType.Stratocaster; - private PolePieceType polePieceType = PolePieceType.Rods; + private PolePieceType polePieceType = PolePieceType.Rods; + + private Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0), new Point(0, 0)}; + + public SingleCoilPickup() { + updateControlPoints(); + } + + private Point[] getControlPoints() { + if (controlPoints == null) { + controlPoints = + new Point[] {controlPoint, new Point(controlPoint.x, controlPoint.y), + new Point(controlPoint.x, controlPoint.y), new Point(controlPoint.x, controlPoint.y)}; + updateControlPoints(); + } + return controlPoints; + } + + @SuppressWarnings("incomplete-switch") + private void updateControlPoints() { + Point[] points = getControlPoints(); + int pointSpacing = (int) POINT_SPACING.convertToPixels(); + int dx = 1; + int dy = 0; + if (orientation != Orientation.DEFAULT) { + switch (orientation) { + case _90: + dx = 0; + dy = -1; + break; + case _180: + dx = -1; + dy = 0; + break; + case _270: + dx = 0; + dy = 1; + break; + } + } + points[1].setLocation(points[0].x + dx * pointSpacing, points[0].y + dy * pointSpacing); + points[2] + .setLocation(points[0].x + 2 * dx * pointSpacing, points[0].y + 2 * dy * pointSpacing); + points[3] + .setLocation(points[0].x + 3 * dx * pointSpacing, points[0].y + 3 * dy * pointSpacing); + } @Override public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project, @@ -120,8 +166,8 @@ public class SingleCoilPickup extends AbstractTransparentComponent { g2d.fill(body[3]); else g2d.fill(body[0]); - g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : POINT_COLOR); - g2d.fill(body[1]); +// g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : POINT_COLOR); +// g2d.fill(body[1]); // g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : color); // g2d.fill(body[3]); @@ -190,9 +236,10 @@ public class SingleCoilPickup extends AbstractTransparentComponent { public Shape[] getBody() { if (body == null) { body = new Shape[5]; - - int x = controlPoint.x; - int y = controlPoint.y; + + Point[] points = getControlPoints(); + int x = (points[0].x + points[3].x) / 2; + int y = (points[0].y + points[3].y) / 2;; int width = (int) WIDTH.convertToPixels(); int length = (int) LENGTH.convertToPixels(); int stratInnerLength = (int) STRAT_INNER_LENGTH.convertToPixels(); @@ -388,7 +435,7 @@ public class SingleCoilPickup extends AbstractTransparentComponent { @Override public int getControlPointCount() { - return 1; + return 4; } @Override @@ -403,12 +450,12 @@ public class SingleCoilPickup extends AbstractTransparentComponent { @Override public Point getControlPoint(int index) { - return controlPoint; + return getControlPoints()[index]; } @Override public void setControlPoint(Point point, int index) { - this.controlPoint.setLocation(point); + getControlPoints()[index].setLocation(point); // Invalidate the body body = null; } @@ -432,7 +479,8 @@ public class SingleCoilPickup extends AbstractTransparentComponent { public void setOrientation(Orientation orientation) { this.orientation = orientation; // Invalidate the body - body = null; + body = null; + updateControlPoints(); } @EditableProperty @@ -468,7 +516,17 @@ public class SingleCoilPickup extends AbstractTransparentComponent { @Override public String getControlPointNodeName(int index) { - return getName() + ".PickupTerminal"; + switch (index) { + case 0: + return"North Start"; + case 1: + return "North End"; + case 2: + return "South Start"; + case 3: + return "South End"; + } + return null; } public enum SingleCoilType { diff --git a/diylc/diylc-swing/lib/diylc-core.jar b/diylc/diylc-swing/lib/diylc-core.jar index e91b03aa..afba58ac 100644 Binary files a/diylc/diylc-swing/lib/diylc-core.jar and b/diylc/diylc-swing/lib/diylc-core.jar differ diff --git a/diylc/diylc-swing/library/main.jar b/diylc/diylc-swing/library/main.jar index 4daadae3..2e05cd03 100644 Binary files a/diylc/diylc-swing/library/main.jar and b/diylc/diylc-swing/library/main.jar differ