Compare commits

..

37 Commits

Author SHA1 Message Date
Branislav Stojkovic bb3b37f23b patched osx component loading issue, investigate further 2019-03-25 08:21:20 +01:00
Branislav Stojkovic fcea5975a8 change backup folder name 2019-03-24 21:38:27 +01:00
Branislav Stojkovic 2294ac45a2 copy loaded file as-is to backup folder 2019-03-24 21:37:37 +01:00
Branislav Stojkovic 5598f22b2f Added "Auto-Wrap Label" component
extracted string rendering function into a separate class
2019-03-24 08:34:28 +01:00
Branislav Stojkovic 812b7adb28 remove newPoints and reuse points for backward compatibility 2019-03-23 22:44:09 +01:00
Branislav Stojkovic 9fd5a8fe96 redo relaxed validation 2019-03-23 19:11:06 +01:00
Branislav Stojkovic 0b8952e354 relax validation of control point collision while dragging 2019-03-23 18:54:44 +01:00
Branislav Stojkovic 5c47ff1ef0 added ability to include or exclude switches from netlist analyzer 2019-03-23 18:05:28 +01:00
Branislav Stojkovic b85b93404b Added mini toolbar in the top-right corner of the screen with transform
actions exposed for quick access
2019-03-22 23:37:59 +01:00
Branislav Stojkovic b46f46aa99 When pasting a group of components that contain at least one "PCB Text"
instance, some of the other components get rendered mirrored while
position the pasted components
2019-03-22 22:29:05 +01:00
Branislav Stojkovic 48266d3b27 fix the 3rd control point when copy-pasting 2019-03-22 21:04:54 +01:00
Branislav Stojkovic eb6cc76f02 make autosave params configurable 2019-03-22 20:58:27 +01:00
Branislav Stojkovic a5d512ca37 Merge branch 'master' of https://github.com/bancika/diy-layout-creator.git 2019-03-22 16:39:23 +01:00
Branislav Stojkovic 1d038b5f8c better log 2019-03-22 16:39:08 +01:00
Branislav Stojkovic 9366f9c602 Auto-save plugin now works by periodically creating project backups in
user\.diylc\autoSave directory and maintains file history, keeping the
last X versions of the file. Maximum size for all backups is
configurable and pre-set to 64MB
2019-03-22 16:38:01 +01:00
bancika 23b4fcae02 Update README.md 2019-03-22 10:34:55 +01:00
Branislav Stojkovic 14a994e68f Improve "Expand Selection" feature to use the same algorithm as netlists
for better precision<
2019-03-22 00:47:28 +01:00
Branislav Stojkovic 894ff1a2cb Assign new name for pasted component if the project already contains
components under that name
2019-03-20 22:35:28 +01:00
Branislav Stojkovic 78dcd27e1d Some schematic symbols (transistors, potentiometer...) get into bad
state when rotated and flipped at the same time
2019-03-20 20:06:38 +01:00
Branislav Stojkovic 714db98afa deleted old file
fixed pin rendering on some components
2019-03-20 19:27:46 +01:00
Branislav Stojkovic 2faa2c6d61 reorganized "stretchable" property into more granular control at the
point level

added controlable label to pot symbol and transistor symbols
2019-03-20 19:21:31 +01:00
Branislav Stojkovic 3c45336afe rename a function 2019-03-19 21:26:03 +01:00
Branislav Stojkovic a0601cc83d better default label position on schematic symbols 2019-03-19 19:03:21 +01:00
Branislav Stojkovic 9925d58347 keep label oriantation the same between the two modes 2019-03-18 22:57:30 +01:00
Branislav Stojkovic 6c241b3180 added third control point to leaded components to set label position 2019-03-18 22:49:27 +01:00
Branislav Stojkovic 838adc9a51 reorganize netlist code, comment out unused functions 2019-03-14 22:36:43 +01:00
Branislav Stojkovic 41d2b73cca Merge switch configurations that yield with the same effective wiring
for "Analyze Guitar Wirings" module, for more compact report
2019-03-14 22:26:49 +01:00
Branislav Stojkovic 8d3789a0b0 update file 2019-03-14 11:19:15 +01:00
Branislav Stojkovic 95f65dcdf1 scan library folder for more jars 2019-03-14 11:14:32 +01:00
Branislav Stojkovic 3d0f9554b0 Honor all possible combinations of "DIP Switch" positions when creating
a netlist
2019-03-14 10:32:51 +01:00
Branislav Stojkovic 0c21e013b4 improve node display for single point componenets 2019-03-14 10:03:04 +01:00
Branislav Stojkovic f8e24b0937 Improve performance of netlist calculations 2019-03-14 00:08:39 +01:00
Branislav Stojkovic 37d5ce18fc Z-order of components sometimes gets wrong when importing a DIY file
into another file
2019-03-13 21:24:55 +01:00
Branislav Stojkovic e9a2785344 Honor "Terminal Strip" connectivity when creating a netlist 2019-03-13 20:54:24 +01:00
Branislav Stojkovic 4de3b6d97c Output SPICE node names in the "Nxxx" format
join all nodes connected to GND together
2019-03-13 19:23:35 +01:00
Branislav Stojkovic 92a2bb9809 fix "Ground Symbol" jumping 2019-03-10 22:58:36 +01:00
Branislav Stojkovic 440b953531 fix orientation parsing 2019-03-10 22:53:01 +01:00
106 changed files with 2336 additions and 1551 deletions
+1
View File
@@ -19,6 +19,7 @@
<li>group components together and treat them as one, e.g. move, edit or delete </li> <li>group components together and treat them as one, e.g. move, edit or delete </li>
<li>export the output to image, PDF or printer </li> <li>export the output to image, PDF or printer </li>
<li>export PCB trace mask suitable for toner transfer </li> <li>export PCB trace mask suitable for toner transfer </li>
<li>export the circuit to a SPICE compatible netlist (beta) </li>
<li>create a Bill of Materials as a part of the project or export it to few different file formats </li> <li>create a Bill of Materials as a part of the project or export it to few different file formats </li>
<li>analyze guitar wirings and show detailed pickup configuration in each switch configuration</li> <li>analyze guitar wirings and show detailed pickup configuration in each switch configuration</li>
<li>zoom in/out feature </li> <li>zoom in/out feature </li>
@@ -43,18 +43,16 @@ public class ComponentType {
private Class<? extends IDIYComponent<?>> instanceClass; private Class<? extends IDIYComponent<?>> instanceClass;
private double zOrder; private double zOrder;
private boolean flexibleZOrder; private boolean flexibleZOrder;
private boolean stretchable;
private BomPolicy bomPolicy; private BomPolicy bomPolicy;
private boolean autoEdit; private boolean autoEdit;
private IComponentTransformer transformer; private IComponentTransformer transformer;
private KeywordPolicy keywordPolicy; private KeywordPolicy keywordPolicy;
private String keywordTag; private String keywordTag;
private boolean continuity;
public ComponentType(String name, String description, CreationMethod creationMethod, String category, public ComponentType(String name, String description, CreationMethod creationMethod, String category,
String namePrefix, String author, Icon icon, Class<? extends IDIYComponent<?>> instanceClass, double zOrder, String namePrefix, String author, Icon icon, Class<? extends IDIYComponent<?>> instanceClass, double zOrder,
boolean flexibleZOrder, boolean stretchable, BomPolicy bomPolicy, boolean autoEdit, boolean flexibleZOrder, BomPolicy bomPolicy, boolean autoEdit, IComponentTransformer transformer,
IComponentTransformer transformer, KeywordPolicy keywordPolicy, String keywordTag, boolean continuity) { KeywordPolicy keywordPolicy, String keywordTag) {
super(); super();
this.name = name; this.name = name;
this.description = description; this.description = description;
@@ -66,13 +64,11 @@ public class ComponentType {
this.instanceClass = instanceClass; this.instanceClass = instanceClass;
this.zOrder = zOrder; this.zOrder = zOrder;
this.flexibleZOrder = flexibleZOrder; this.flexibleZOrder = flexibleZOrder;
this.stretchable = stretchable;
this.bomPolicy = bomPolicy; this.bomPolicy = bomPolicy;
this.autoEdit = autoEdit; this.autoEdit = autoEdit;
this.transformer = transformer; this.transformer = transformer;
this.keywordPolicy = keywordPolicy; this.keywordPolicy = keywordPolicy;
this.keywordTag = keywordTag; this.keywordTag = keywordTag;
this.continuity = continuity;
} }
public String getName() { public String getName() {
@@ -115,10 +111,6 @@ public class ComponentType {
return flexibleZOrder; return flexibleZOrder;
} }
public boolean isStretchable() {
return stretchable;
}
public BomPolicy getBomPolicy() { public BomPolicy getBomPolicy() {
return bomPolicy; return bomPolicy;
} }
@@ -139,10 +131,6 @@ public class ComponentType {
return keywordTag; return keywordTag;
} }
public boolean isContinuity() {
return continuity;
}
@Override @Override
public String toString() { public String toString() {
return name; return name;
@@ -35,9 +35,10 @@ public interface INetlistProcessor {
/** /**
* Finds all {@link Netlist}s for each switch position combination. * Finds all {@link Netlist}s for each switch position combination.
* *
* @param includeSwitches
* @return * @return
*/ */
List<Netlist> extractNetlists(); List<Netlist> extractNetlists(boolean includeSwitches);
/** /**
* Finds all available {@link INetlistAnalyzer} implementations. * Finds all available {@link INetlistAnalyzer} implementations.
@@ -121,9 +121,10 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
* Loads specified {@link Project}. * Loads specified {@link Project}.
* *
* @param project * @param project
* @param freshStart * @param freshStart
* @param optional file name when loading from a file
*/ */
void loadProject(Project project, boolean freshStart); void loadProject(Project project, boolean freshStart, String filename);
/** /**
* Creates a new project. * Creates a new project.
@@ -21,25 +21,18 @@
*/ */
package org.diylc.components; package org.diylc.components;
import java.awt.Color; import java.awt.Color;
import java.awt.Font; import java.awt.Font;
import java.awt.FontMetrics; import java.awt.Point;
import java.awt.Graphics2D; import java.awt.Shape;
import java.awt.Point; import java.awt.geom.Rectangle2D;
import java.awt.Rectangle; import java.lang.reflect.Array;
import java.awt.Shape; import java.lang.reflect.Field;
import java.awt.font.FontRenderContext; import java.lang.reflect.Modifier;
import java.awt.font.GlyphVector; import java.util.Arrays;
import java.awt.geom.Rectangle2D;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import org.diylc.common.HorizontalAlignment; import org.diylc.core.IDIYComponent;
import org.diylc.common.VerticalAlignment; import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.EditableProperty;
/** /**
* Abstract implementation of {@link IDIYComponent} that contains component name and toString. * Abstract implementation of {@link IDIYComponent} that contains component name and toString.
@@ -147,54 +140,6 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
return !clip.intersects(rect); return !clip.intersects(rect);
} }
protected void drawCenteredText(Graphics2D g2d, String text, int x, int y, HorizontalAlignment horizontalAlignment,
VerticalAlignment verticalAlignment) {
String[] parts = text.split("\n");
if (parts.length > 1) {
FontMetrics fontMetrics = g2d.getFontMetrics();
Rectangle stringBounds = fontMetrics.getStringBounds(parts[0], g2d).getBounds();
for (int i = 0; i < parts.length; i++)
drawCenteredText(g2d, parts[i], x, (int)(y - stringBounds.height * (parts.length - 1) / 2d + i * stringBounds.height), horizontalAlignment, verticalAlignment);
return;
}
FontMetrics fontMetrics = g2d.getFontMetrics();
Rectangle stringBounds = fontMetrics.getStringBounds(text, g2d).getBounds();
Font font = g2d.getFont();
FontRenderContext renderContext = g2d.getFontRenderContext();
GlyphVector glyphVector = font.createGlyphVector(renderContext, text);
Rectangle visualBounds = glyphVector.getVisualBounds().getBounds();
int textX = 0;
switch (horizontalAlignment) {
case CENTER:
textX = x - stringBounds.width / 2;
break;
case LEFT:
textX = x;
break;
case RIGHT:
textX = x - stringBounds.width;
break;
}
int textY = 0;
switch (verticalAlignment) {
case TOP:
textY = y + stringBounds.height;
break;
case CENTER:
textY = y - visualBounds.height / 2 - visualBounds.y;
break;
case BOTTOM:
textY = y - visualBounds.y;
break;
}
g2d.drawString(text, textX, textY);
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public IDIYComponent<T> clone() throws CloneNotSupportedException { public IDIYComponent<T> clone() throws CloneNotSupportedException {
try { try {
@@ -297,5 +242,14 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
public String[] getSectionNames(int pointIndex) { public String[] getSectionNames(int pointIndex) {
return null; return null;
} }
@Override
public String getCommonPointName(int pointIndex) {
return null;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return true;
}
} }
@@ -0,0 +1,34 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
package org.diylc.core;
public interface IContinuity {
/**
* Tests control point connectivity.
*
* @param index1
* @param index2
* @return true if the two points are connected, false otherwise.
*/
boolean arePointsConnected(int index1, int index2);
}
@@ -131,11 +131,23 @@ public interface IDIYComponent<T> extends Serializable {
String getInternalLinkName(int index1, int index2); String getInternalLinkName(int index1, int index2);
/** /**
* @param pointIndex name of the internal section containing the specified point, or null if the component does not have internal sections. * @param pointIndex
* One point can be shared between multiple sections, in which case, the result may contain more than one element. * @return name of the internal section containing the specified point, or null if the component does not have internal sections.
* @return * One point can be shared between multiple sections, in which case, the result may contain more than one element.
*/ */
String[] getSectionNames(int pointIndex); String[] getSectionNames(int pointIndex);
/**
* @param pointIndex
* @return name of the common point that joins all the other points with the same name together, e.g. GND
*/
String getCommonPointName(int pointIndex);
/**
* @param pointIndex
* @return true if the control point can move without affecting other points' position, false otherwise
*/
boolean canPointMoveFreely(int pointIndex);
/** /**
* Draws the component onto the {@link Graphics2D}. * Draws the component onto the {@link Graphics2D}.
@@ -82,12 +82,6 @@ public @interface ComponentDescriptor {
*/ */
boolean flexibleZOrder() default false; boolean flexibleZOrder() default false;
/**
* @return when false, moving one control point will cause all the others to move together with
* it.
*/
boolean stretchable() default true;
/** /**
* @return controls what should be shown the BOM * @return controls what should be shown the BOM
*/ */
@@ -116,13 +110,5 @@ public @interface ComponentDescriptor {
* *
* @return * @return
*/ */
String keywordTag() default ""; String keywordTag() default "";
/**
* For components that show continuity between the two ending points, e.d. wires, jumpers, etc.
*
* @return
*/
boolean continuity() default false;
} }
@@ -18,7 +18,6 @@
package org.diylc.netlist; package org.diylc.netlist;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@@ -28,9 +27,26 @@ import java.util.Set;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
public class NetlistAnalyzer { public abstract class NetlistAnalyzer {
public NetlistAnalyzer() {} public NetlistAnalyzer() {}
public List<Summary> summarize(List<Netlist> netlists, Node preferredOutput) throws TreeException {
Map<String, Summary> summaries = new HashMap<String, Summary>();
for (Netlist n : netlists) {
Summary s = summarize(n, preferredOutput);
if (summaries.containsKey(s.getSummary()))
summaries.get(s.getSummary()).append(n);
else
summaries.put(s.getSummary(), s);
}
List<Summary> res = new ArrayList<Summary>(summaries.values());
Collections.sort(res);
return res;
}
protected abstract Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException;
public Tree constructTreeBetween(Netlist netlist, Node nodeA, Node nodeB) { public Tree constructTreeBetween(Netlist netlist, Node nodeA, Node nodeB) {
Tree tree = new Tree(TreeConnectionType.Parallel); Tree tree = new Tree(TreeConnectionType.Parallel);
@@ -199,45 +215,45 @@ public class NetlistAnalyzer {
paths.addAll(unmerged); paths.addAll(unmerged);
} }
} }
//
protected void findAllPaths(Netlist netlist, Node nodeA, Node nodeB, List<TreeLeaf> currentPath, // protected void findAllPaths(Netlist netlist, Node nodeA, Node nodeB, List<TreeLeaf> currentPath,
List<List<TreeLeaf>> allPaths, Set<Node> visited) { // List<List<TreeLeaf>> allPaths, Set<Node> visited) {
if (nodeA == nodeB) { // if (nodeA == nodeB) {
allPaths.add(currentPath); // allPaths.add(currentPath);
return; // return;
} // }
//
// System.out.println("Finding path between " + nodeA + " and " + nodeB); // // System.out.println("Finding path between " + nodeA + " and " + nodeB);
//
Group groupA = findGroup(netlist, nodeA); // Group groupA = findGroup(netlist, nodeA);
//
if (groupA == null) // if (groupA == null)
return; // return;
//
if (groupA.getNodes().contains(nodeB)) { // if (groupA.getNodes().contains(nodeB)) {
allPaths.add(currentPath); // allPaths.add(currentPath);
return; // return;
} // }
//
for (Node n : groupA.getNodes()) { // for (Node n : groupA.getNodes()) {
IDIYComponent<?> c = n.getComponent(); // IDIYComponent<?> c = n.getComponent();
for (int i = 0; i < c.getControlPointCount(); i++) { // for (int i = 0; i < c.getControlPointCount(); i++) {
if (i != n.getPointIndex() && c.getInternalLinkName(i, n.getPointIndex()) != null) { // if (i != n.getPointIndex() && c.getInternalLinkName(i, n.getPointIndex()) != null) {
TreeLeaf l = new TreeLeaf(c, i, n.getPointIndex()); // TreeLeaf l = new TreeLeaf(c, i, n.getPointIndex());
Node newNodeA = new Node(c, i); // Node newNodeA = new Node(c, i);
if (!visited.contains(newNodeA)) { // if (!visited.contains(newNodeA)) {
List<TreeLeaf> newCurrentPath = new ArrayList<TreeLeaf>(currentPath); // List<TreeLeaf> newCurrentPath = new ArrayList<TreeLeaf>(currentPath);
if (!currentPath.contains(l)) // if (!currentPath.contains(l))
newCurrentPath.add(l); // newCurrentPath.add(l);
Set<Node> newVisited = new HashSet<Node>(visited); // Set<Node> newVisited = new HashSet<Node>(visited);
newVisited.add(nodeA); // newVisited.add(nodeA);
newVisited.add(newNodeA); // newVisited.add(newNodeA);
findAllPaths(netlist, newNodeA, nodeB, newCurrentPath, allPaths, newVisited); // findAllPaths(netlist, newNodeA, nodeB, newCurrentPath, allPaths, newVisited);
} // }
} // }
} // }
} // }
} // }
protected Group findGroup(Netlist netlist, Node node) { protected Group findGroup(Netlist netlist, Node node) {
for (Group g : netlist.getGroups()) for (Group g : netlist.getGroups())
@@ -246,62 +262,62 @@ public class NetlistAnalyzer {
return null; return null;
} }
protected List<Group> trace(Set<String> typeNames, String nodeName, Netlist netlist) { // protected List<Group> trace(Set<String> typeNames, String nodeName, Netlist netlist) {
List<Group> res = new ArrayList<Group>(); // List<Group> res = new ArrayList<Group>();
for (Group g : netlist.getGroups()) { // for (Group g : netlist.getGroups()) {
for (Node n : g.getNodes()) { // for (Node n : g.getNodes()) {
if (typeNames.contains(n.getComponent().getClass().getCanonicalName()) // if (typeNames.contains(n.getComponent().getClass().getCanonicalName())
&& (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) { // && (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
res.add(g); // res.add(g);
break; // break;
} // }
} // }
} // }
return res; // return res;
} // }
protected List<Node> find(Set<String> typeNames, String nodeName, Group group) { // protected List<Node> find(Set<String> typeNames, String nodeName, Group group) {
List<Node> res = new ArrayList<Node>(); // List<Node> res = new ArrayList<Node>();
//
// for (Node n : group.getNodes()) {
// if (typeNames.contains(n.getComponent().getClass().getCanonicalName())
// && (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
// res.add(n);
// }
// }
//
// return res;
// }
for (Node n : group.getNodes()) { // protected List<Group> findGroups(Set<String> typeNames, String nodeName, Netlist netlist) {
if (typeNames.contains(n.getComponent().getClass().getCanonicalName()) // List<Group> res = new ArrayList<Group>();
&& (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) { // for (Group g : netlist.getGroups()) {
res.add(n); // for (Node n : g.getNodes()) {
} // if (typeNames.contains(n.getComponent().getClass().getCanonicalName())
} // && (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
// res.add(g);
// break;
// }
// }
// }
// return res;
// }
return res; // protected List<Group> findGroups(Set<String> typeNames, String nodeName, Netlist netlist,
} // Collection<IDIYComponent<?>> belongTo) {
// List<Group> res = new ArrayList<Group>();
protected List<Group> findGroups(Set<String> typeNames, String nodeName, Netlist netlist) { // for (Group g : netlist.getGroups()) {
List<Group> res = new ArrayList<Group>(); // for (Node n : g.getNodes()) {
for (Group g : netlist.getGroups()) { // if ((belongTo == null || belongTo.contains(n.getComponent()))
for (Node n : g.getNodes()) { // && (typeNames.contains(n.getComponent().getClass().getCanonicalName()))
if (typeNames.contains(n.getComponent().getClass().getCanonicalName()) // && (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
&& (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) { // res.add(g);
res.add(g); // break;
break; // }
} // }
} // }
} // return res;
return res; // }
}
protected List<Group> findGroups(Set<String> typeNames, String nodeName, Netlist netlist,
Collection<IDIYComponent<?>> belongTo) {
List<Group> res = new ArrayList<Group>();
for (Group g : netlist.getGroups()) {
for (Node n : g.getNodes()) {
if ((belongTo == null || belongTo.contains(n.getComponent()))
&& (typeNames.contains(n.getComponent().getClass().getCanonicalName()))
&& (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
res.add(g);
break;
}
}
}
return res;
}
protected List<Node> find(Set<String> typeNames, String nodeName, Netlist netlist) { protected List<Node> find(Set<String> typeNames, String nodeName, Netlist netlist) {
List<Node> res = new ArrayList<Node>(); List<Node> res = new ArrayList<Node>();
@@ -316,73 +332,92 @@ public class NetlistAnalyzer {
return res; return res;
} }
protected List<Node> find(Set<String> typeNames, String nodeName, Netlist netlist, List<Node> inGroupWith) { // protected List<Node> find(Set<String> typeNames, String nodeName, Netlist netlist, List<Node> inGroupWith) {
List<Node> res = new ArrayList<Node>(); // List<Node> res = new ArrayList<Node>();
for (Group g : netlist.getGroups()) { // for (Group g : netlist.getGroups()) {
//
// boolean inGroup;
// if (inGroupWith == null) {
// inGroup = true;
// } else {
// inGroup = true;
// for (Node n1 : inGroupWith)
// if (!g.getNodes().contains(n1)) {
// inGroup = false;
// break;
// }
// }
//
// for (Node n : g.getNodes()) {
// if (inGroup && typeNames.contains(n.getComponent().getClass().getCanonicalName())
// && (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
// res.add(n);
// }
// }
// }
// return res;
// }
boolean inGroup; // protected List<Node> find(Set<String> typeNames, String nodeName, Netlist netlist,
if (inGroupWith == null) { // Collection<IDIYComponent<?>> belongTo) {
inGroup = true; // List<Node> res = new ArrayList<Node>();
} else { // for (Group g : netlist.getGroups()) {
inGroup = true; //
for (Node n1 : inGroupWith) // for (Node n : g.getNodes()) {
if (!g.getNodes().contains(n1)) { // if ((belongTo == null || belongTo.contains(n.getComponent()))
inGroup = false; // && typeNames.contains(n.getComponent().getClass().getCanonicalName())
break; // && (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
} // res.add(n);
} // }
// }
// }
// return res;
// }
for (Node n : g.getNodes()) { // protected boolean allMatch(Collection<Node> nodes, String name) {
if (inGroup && typeNames.contains(n.getComponent().getClass().getCanonicalName()) // for (Node n : nodes)
&& (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) { // if (!n.getDisplayName().equalsIgnoreCase(name))
res.add(n); // return false;
} //
} // return true;
} // }
return res;
}
protected List<Node> find(Set<String> typeNames, String nodeName, Netlist netlist, // protected boolean allComponentsMatch(Collection<Node> nodes, Set<IDIYComponent<?>> components) {
Collection<IDIYComponent<?>> belongTo) { // Set<IDIYComponent<?>> extracted = extractComponents(nodes);
List<Node> res = new ArrayList<Node>(); // return extracted.containsAll(components);
for (Group g : netlist.getGroups()) { // }
//
for (Node n : g.getNodes()) { // protected Set<IDIYComponent<?>> extractComponents(Collection<Node> nodes) {
if ((belongTo == null || belongTo.contains(n.getComponent())) // Set<IDIYComponent<?>> components = new HashSet<IDIYComponent<?>>();
&& typeNames.contains(n.getComponent().getClass().getCanonicalName()) // for (Node n : nodes)
&& (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) { // components.add(n.getComponent());
res.add(n); // return components;
} // }
}
}
return res;
}
protected boolean allMatch(Collection<Node> nodes, String name) {
for (Node n : nodes)
if (!n.getDisplayName().equalsIgnoreCase(name))
return false;
return true;
}
protected boolean allComponentsMatch(Collection<Node> nodes, Set<IDIYComponent<?>> components) {
Set<IDIYComponent<?>> extracted = extractComponents(nodes);
return extracted.containsAll(components);
}
protected Set<IDIYComponent<?>> extractComponents(Collection<Node> nodes) {
Set<IDIYComponent<?>> components = new HashSet<IDIYComponent<?>>();
for (Node n : nodes)
components.add(n.getComponent());
return components;
}
protected String extractName(IDIYComponent<?> c) { protected String extractName(IDIYComponent<?> c) {
return c.getName() + " " + c.getValueForDisplay(); return c.getName() + " " + c.getValueForDisplay();
} }
protected Set<IDIYComponent<?>> extractComponents(Netlist netlist) { public static List<Set<IDIYComponent<?>>> extractComponentGroups(List<Netlist> netlists) {
List<Set<IDIYComponent<?>>> res = new ArrayList<Set<IDIYComponent<?>>>();
for (Netlist n : netlists) {
res.addAll(extractComponentGroups(n));
}
return res;
}
public static List<Set<IDIYComponent<?>>> extractComponentGroups(Netlist netlist) {
List<Set<IDIYComponent<?>>> res = new ArrayList<Set<IDIYComponent<?>>>();
for (Group g : netlist.getGroups()) {
Set<IDIYComponent<?>> components = new HashSet<IDIYComponent<?>>();
for (Node n : g.getNodes())
components.add(n.getComponent());
res.add(components);
}
return res;
}
public static Set<IDIYComponent<?>> extractComponents(Netlist netlist) {
Set<IDIYComponent<?>> res = new HashSet<IDIYComponent<?>>(); Set<IDIYComponent<?>> res = new HashSet<IDIYComponent<?>>();
for (Group g : netlist.getGroups()) for (Group g : netlist.getGroups())
for (Node n : g.getNodes()) for (Node n : g.getNodes())
@@ -397,53 +432,53 @@ public class NetlistAnalyzer {
return -1; return -1;
} }
protected List<String> extractNames(Collection<IDIYComponent<?>> components) { // protected List<String> extractNames(Collection<IDIYComponent<?>> components) {
List<String> names = new ArrayList<String>(); // List<String> names = new ArrayList<String>();
for (IDIYComponent<?> c : components) // for (IDIYComponent<?> c : components)
names.add(c.getName() + " " + c.getValueForDisplay()); // names.add(c.getName() + " " + c.getValueForDisplay());
Collections.sort(names); // Collections.sort(names);
return names; // return names;
} // }
//
protected Netlist simplify(Netlist netlist, Set<Node> nodesToMerge, Collection<Node> nodesToPurge) { // protected Netlist simplify(Netlist netlist, Set<Node> nodesToMerge, Collection<Node> nodesToPurge) {
Netlist res = new Netlist(); // Netlist res = new Netlist();
res.getSwitchSetup().addAll(netlist.getSwitchSetup()); // res.getSwitchSetup().addAll(netlist.getSwitchSetup());
//
Group merged = new Group(); // Group merged = new Group();
//
// merge // // merge
for (Group g : netlist.getGroups()) { // for (Group g : netlist.getGroups()) {
boolean needsMerging = false; // boolean needsMerging = false;
for (Node n : nodesToMerge) { // for (Node n : nodesToMerge) {
if (g.getNodes().contains(n)) { // if (g.getNodes().contains(n)) {
needsMerging = true; // needsMerging = true;
break; // break;
} // }
} // }
if (needsMerging) { // if (needsMerging) {
for (Node n : g.getNodes()) { // for (Node n : g.getNodes()) {
if (!nodesToMerge.contains(n)) // if (!nodesToMerge.contains(n))
merged.getNodes().add(n); // merged.getNodes().add(n);
} // }
} else { // } else {
res.getGroups().add(g.clone()); // res.getGroups().add(g.clone());
} // }
} // }
//
if (!merged.getNodes().isEmpty()) // if (!merged.getNodes().isEmpty())
res.getGroups().add(merged); // res.getGroups().add(merged);
//
// purge // // purge
for (Group g : res.getGroups()) { // for (Group g : res.getGroups()) {
g.getNodes().removeAll(nodesToPurge); // g.getNodes().removeAll(nodesToPurge);
} // }
//
System.out.println("Before:\n" + netlist); // System.out.println("Before:\n" + netlist);
System.out.println("After:\n" + res); // System.out.println("After:\n" + res);
//
return res; // return res;
} // }
//
protected boolean intersect(List<Group> groups, Node node) { protected boolean intersect(List<Group> groups, Node node) {
for (Group g : groups) for (Group g : groups)
if (g.getNodes().contains(node)) if (g.getNodes().contains(node))
@@ -82,6 +82,8 @@ public class Node implements Comparable<Node> {
@Override @Override
public String toString() { public String toString() {
if (component.getControlPointCount() == 1)
return component.getName();
return component.getName() + "." + getDisplayName() /*+ " @ (" + component.getControlPoint(pointIndex).getX() + ":" + component.getControlPoint(pointIndex).getY() + ")"*/; return component.getName() + "." + getDisplayName() /*+ " @ (" + component.getControlPoint(pointIndex).getX() + ":" + component.getControlPoint(pointIndex).getY() + ")"*/;
} }
@@ -21,8 +21,7 @@
*/ */
package org.diylc.netlist; package org.diylc.netlist;
public class Summary implements Comparable<Summary> {
public class Summary {
private Netlist netlist; private Netlist netlist;
private String summary; private String summary;
@@ -36,6 +35,10 @@ public class Summary {
public Netlist getNetlist() { public Netlist getNetlist() {
return netlist; return netlist;
} }
public void append(Netlist netlist) {
this.netlist.getSwitchSetup().addAll(netlist.getSwitchSetup());
}
public String getSummary() { public String getSummary() {
return summary; return summary;
@@ -76,4 +79,9 @@ public class Summary {
public String toString() { public String toString() {
return summary.toString(); return summary.toString();
} }
@Override
public int compareTo(Summary o) {
return netlist.compareTo(o.netlist);
}
} }
@@ -72,9 +72,9 @@ public class SwitchSetup implements Comparable<SwitchSetup> {
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (Position s : positions) for (Position s : positions)
{ {
if (sb.length() > 0) if (sb.length() > 0)
sb.append(":"); sb.append(":");
sb.append(s.toString()); sb.append(s.toString());
} }
return sb.toString(); return sb.toString();
@@ -92,13 +92,11 @@ public class ComponentProcessor {
Icon icon; Icon icon;
double zOrder; double zOrder;
boolean flexibleZOrder; boolean flexibleZOrder;
boolean stretchable;
BomPolicy bomPolicy; BomPolicy bomPolicy;
boolean autoEdit; boolean autoEdit;
IComponentTransformer transformer; IComponentTransformer transformer;
KeywordPolicy keywordPolicy; KeywordPolicy keywordPolicy;
String keywordTag; String keywordTag;
boolean continuity;
if (clazz.isAnnotationPresent(ComponentDescriptor.class)) { if (clazz.isAnnotationPresent(ComponentDescriptor.class)) {
ComponentDescriptor annotation = clazz.getAnnotation(ComponentDescriptor.class); ComponentDescriptor annotation = clazz.getAnnotation(ComponentDescriptor.class);
name = annotation.name(); name = annotation.name();
@@ -109,13 +107,11 @@ public class ComponentProcessor {
author = annotation.author(); author = annotation.author();
zOrder = annotation.zOrder(); zOrder = annotation.zOrder();
flexibleZOrder = annotation.flexibleZOrder(); flexibleZOrder = annotation.flexibleZOrder();
stretchable = annotation.stretchable();
bomPolicy = annotation.bomPolicy(); bomPolicy = annotation.bomPolicy();
autoEdit = annotation.autoEdit(); autoEdit = annotation.autoEdit();
transformer = getComponentTransformer(annotation.transformer()); transformer = getComponentTransformer(annotation.transformer());
keywordPolicy = annotation.keywordPolicy(); keywordPolicy = annotation.keywordPolicy();
keywordTag = annotation.keywordTag(); keywordTag = annotation.keywordTag();
continuity = annotation.continuity();
} else { // default } else { // default
return null; return null;
} }
@@ -137,7 +133,7 @@ public class ComponentProcessor {
} }
ComponentType componentType = ComponentType componentType =
new ComponentType(name, description, creationMethod, category, namePrefix, author, icon, clazz, zOrder, new ComponentType(name, description, creationMethod, category, namePrefix, author, icon, clazz, zOrder,
flexibleZOrder, stretchable, bomPolicy, autoEdit, transformer, keywordPolicy, keywordTag, continuity); flexibleZOrder, bomPolicy, autoEdit, transformer, keywordPolicy, keywordTag);
componentTypeMap.put(clazz.getName(), componentType); componentTypeMap.put(clazz.getName(), componentType);
return componentType; return componentType;
} }
@@ -43,7 +43,6 @@ import java.util.Set;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.appframework.simplemq.MessageDispatcher; import org.diylc.appframework.simplemq.MessageDispatcher;
import org.diylc.common.ComponentType;
import org.diylc.common.DrawOption; import org.diylc.common.DrawOption;
import org.diylc.common.EventType; import org.diylc.common.EventType;
import org.diylc.common.GridType; import org.diylc.common.GridType;
@@ -51,6 +50,7 @@ import org.diylc.common.IComponentFiler;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache; import org.diylc.common.ObjectCache;
import org.diylc.core.ComponentState; import org.diylc.core.ComponentState;
import org.diylc.core.IContinuity;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.Project; import org.diylc.core.Project;
import org.diylc.core.Theme; import org.diylc.core.Theme;
@@ -505,7 +505,6 @@ public class DrawingManager {
continuityArea = null; continuityArea = null;
} }
@SuppressWarnings("unchecked")
public List<Area> getContinuityAreas(Project project) { public List<Area> getContinuityAreas(Project project) {
// Find all individual continuity areas for all components // Find all individual continuity areas for all components
List<Area> preliminaryAreas = new ArrayList<Area>(); List<Area> preliminaryAreas = new ArrayList<Area>();
@@ -513,11 +512,12 @@ public class DrawingManager {
Set<Connection> connections = new HashSet<Connection>(); Set<Connection> connections = new HashSet<Connection>();
for (IDIYComponent<?> c : project.getComponents()) { for (IDIYComponent<?> c : project.getComponents()) {
ComponentArea a = getComponentArea(c); ComponentArea a = getComponentArea(c);
ComponentType type = if (c instanceof IContinuity) {
ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) c.getClass()); for (int i = 0; i < c.getControlPointCount() - 1; i++)
if (type.isContinuity()) { for (int j = i + 1; j < c.getControlPointCount(); j++)
connections.add(new Connection(c.getControlPoint(0), c.getControlPoint(c.getControlPointCount() - 1))); if (((IContinuity)c).arePointsConnected(i, j))
connections.add(new Connection(c.getControlPoint(i), c.getControlPoint(j)));
} }
if (a == null || a.getOutlineArea() == null) if (a == null || a.getOutlineArea() == null)
@@ -556,7 +556,7 @@ public class DrawingManager {
return areas; return areas;
} }
private void expandConnections(Set<Connection> connections) { public void expandConnections(Set<Connection> connections) {
Set<Connection> toAdd = new HashSet<Connection>(); Set<Connection> toAdd = new HashSet<Connection>();
for (Connection c1 : connections) for (Connection c1 : connections)
for (Connection c2 : connections) { for (Connection c2 : connections) {
@@ -596,15 +596,19 @@ public class DrawingManager {
continue; continue;
Area a1 = areas.get(i); Area a1 = areas.get(i);
Area a2 = areas.get(j); Area a2 = areas.get(j);
Area intersection = new Area(a1); Area intersection = null;
intersection.intersect(a2); if (a1.getBounds2D().intersects(a2.getBounds())) {
intersection = new Area(a1);
intersection.intersect(a2);
}
// if the two areas intersect, make a union and consume the second area // if the two areas intersect, make a union and consume the second area
if (!intersection.isEmpty()) { if (intersection != null && !intersection.isEmpty()) {
a1.add(a2); a1.add(a2);
consumed.set(j, true); consumed.set(j, true);
} else { // maybe there's a connection between them } else { // maybe there's a connection between them
for (Connection p : connections) { for (Connection p : connections) { // use getBounds to optimize the computation, don't get into complex math if not needed
if ((a1.contains(p.getP1()) && a2.contains(p.getP2())) || (a1.contains(p.getP2()) && a2.contains(p.getP1()))) { if ((a1.getBounds().contains(p.getP1()) && a2.getBounds().contains(p.getP2()) && a1.contains(p.getP1()) && a2.contains(p.getP2())) ||
(a1.getBounds().contains(p.getP2()) && a2.getBounds().contains(p.getP1())) && a1.contains(p.getP2()) && a2.contains(p.getP1())) {
a1.add(a2); a1.add(a2);
consumed.set(j, true); consumed.set(j, true);
break; break;
@@ -27,8 +27,10 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
@@ -62,11 +64,11 @@ public class InstantiationManager {
private Point potentialControlPoint; private Point potentialControlPoint;
public static final ComponentType clipboardType = new ComponentType("Clipboard contents", public static final ComponentType clipboardType = new ComponentType("Clipboard contents",
"Components from the clipboard", CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, false, null, "Components from the clipboard", CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, null,
false, null, KeywordPolicy.NEVER_SHOW, null, false); false, null, KeywordPolicy.NEVER_SHOW, null);
public static final ComponentType blockType = new ComponentType("Building block", public static final ComponentType blockType = new ComponentType("Building block",
"Components from the building block", CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, false, null, "Components from the building block", CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, null,
false, null, KeywordPolicy.NEVER_SHOW, null, false); false, null, KeywordPolicy.NEVER_SHOW, null);
public InstantiationManager() {} public InstantiationManager() {}
@@ -139,16 +141,34 @@ public class InstantiationManager {
return changeMade; return changeMade;
} }
@SuppressWarnings("unchecked")
public void pasteComponents(Collection<IDIYComponent<?>> components, Point scaledPoint, boolean snapToGrid, public void pasteComponents(Collection<IDIYComponent<?>> components, Point scaledPoint, boolean snapToGrid,
Size gridSpacing, boolean autoGroup) { Size gridSpacing, boolean autoGroup, Project currentProject) {
// Adjust location of components so they are centered under the mouse // Adjust location of components so they are centered under the mouse
// cursor // cursor
int minX = Integer.MAX_VALUE; int minX = Integer.MAX_VALUE;
int maxX = Integer.MIN_VALUE; int maxX = Integer.MIN_VALUE;
int minY = Integer.MAX_VALUE; int minY = Integer.MAX_VALUE;
int maxY = Integer.MIN_VALUE; int maxY = Integer.MIN_VALUE;
for (IDIYComponent<?> component : components) {
for (int i = 0; i < component.getControlPointCount(); i++) { Set<String> existingNames = new HashSet<String>();
for (IDIYComponent<?> c : currentProject.getComponents())
existingNames.add(c.getName());
List<IDIYComponent<?>> allComponents = new ArrayList<IDIYComponent<?>>(currentProject.getComponents());
for (IDIYComponent<?> component : components) {
// assign a new name if it already exists in the project
if (existingNames.contains(component.getName())) {
ComponentType componentType =
ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) component.getClass());
String newName = createUniqueName(componentType, allComponents);
existingNames.add(newName);
component.setName(newName);
allComponents.add(component);
}
for (int i = 0; i < component.getControlPointCount(); i++) {
Point p = component.getControlPoint(i); Point p = component.getControlPoint(i);
if (p.x > maxX) { if (p.x > maxX) {
maxX = p.x; maxX = p.x;
File diff suppressed because it is too large Load Diff
Binary file not shown.
@@ -0,0 +1,245 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
package org.diylc.awt;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.diylc.common.HorizontalAlignment;
import org.diylc.common.VerticalAlignment;
/**
* Globally available utility classes, mostly for string manipulation.
*
* @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
*/
public class StringUtils {
public static void drawWrappedText(String text, Graphics2D g2d, int x, int y, int maxWidth, HorizontalAlignment horizontalAlignment) {
FontMetrics textMetrics = g2d.getFontMetrics();
List<String> lines = wrap(text, textMetrics, maxWidth);
int lineHeight = textMetrics.getHeight();
if (horizontalAlignment == HorizontalAlignment.CENTER)
x += maxWidth / 2;
else if (horizontalAlignment == HorizontalAlignment.RIGHT)
x += maxWidth;
for (String line : lines) {
drawCenteredText(g2d, line, x, y, horizontalAlignment, VerticalAlignment.BOTTOM);
y += lineHeight;
}
}
/**
* Returns an array of strings, one for each line in the string after it has been wrapped to fit
* lines of <var>maxWidth</var>. Lines end with any of cr, lf, or cr lf. A line ending at the end
* of the string will not output a further, empty string.
* <p>
* This code assumes <var>str</var> is not <code>null</code>.
*
* @param str the string to split
* @param fm needed for string width calculations
* @param maxWidth the max line width, in points
* @return a non-empty list of strings
*/
public static List<String> wrap(String str, FontMetrics fm, int maxWidth) {
List<String> lines = splitIntoLines(str);
if (lines.size() == 0)
return lines;
ArrayList<String> strings = new ArrayList<String>();
for (Iterator<String> iter = lines.iterator(); iter.hasNext();)
wrapLineInto((String) iter.next(), strings, fm, maxWidth);
return strings;
}
/**
* Given a line of text and font metrics information, wrap the line and add the new line(s) to
* <var>list</var>.
*
* @param line a line of text
* @param list an output list of strings
* @param fm font metrics
* @param maxWidth maximum width of the line(s)
*/
public static void wrapLineInto(String line, List<String> list, FontMetrics fm, int maxWidth) {
int len = line.length();
int width;
while (len > 0 && (width = fm.stringWidth(line)) > maxWidth) {
// Guess where to split the line. Look for the next space before
// or after the guess.
int guess = len * maxWidth / width;
String before = line.substring(0, guess).trim();
width = fm.stringWidth(before);
int pos;
if (width > maxWidth) // Too long
pos = findBreakBefore(line, guess);
else { // Too short or possibly just right
pos = findBreakAfter(line, guess);
if (pos != -1) { // Make sure this doesn't make us too long
before = line.substring(0, pos).trim();
if (fm.stringWidth(before) > maxWidth)
pos = findBreakBefore(line, guess);
}
}
if (pos == -1)
pos = guess; // Split in the middle of the word
list.add(line.substring(0, pos).trim());
line = line.substring(pos).trim();
len = line.length();
}
if (len > 0)
list.add(line);
}
/**
* Returns the index of the first whitespace character or '-' in <var>line</var> that is at or
* before <var>start</var>. Returns -1 if no such character is found.
*
* @param line a string
* @param start where to star looking
*/
public static int findBreakBefore(String line, int start) {
for (int i = start; i >= 0; --i) {
char c = line.charAt(i);
if (Character.isWhitespace(c) || c == '-')
return i;
}
return -1;
}
/**
* Returns the index of the first whitespace character or '-' in <var>line</var> that is at or
* after <var>start</var>. Returns -1 if no such character is found.
*
* @param line a string
* @param start where to star looking
*/
public static int findBreakAfter(String line, int start) {
int len = line.length();
for (int i = start; i < len; ++i) {
char c = line.charAt(i);
if (Character.isWhitespace(c) || c == '-')
return i;
}
return -1;
}
/**
* Returns an array of strings, one for each line in the string. Lines end with any of cr, lf, or
* cr lf. A line ending at the end of the string will not output a further, empty string.
* <p>
* This code assumes <var>str</var> is not <code>null</code>.
*
* @param str the string to split
* @return a non-empty list of strings
*/
public static List<String> splitIntoLines(String str) {
List<String> strings = new ArrayList<String>();
int len = str.length();
if (len == 0) {
strings.add("");
return strings;
}
int lineStart = 0;
for (int i = 0; i < len; ++i) {
char c = str.charAt(i);
if (c == '\r') {
int newlineLength = 1;
if ((i + 1) < len && str.charAt(i + 1) == '\n')
newlineLength = 2;
strings.add(str.substring(lineStart, i));
lineStart = i + newlineLength;
if (newlineLength == 2) // skip \n next time through loop
++i;
} else if (c == '\n') {
strings.add(str.substring(lineStart, i));
lineStart = i + 1;
}
}
if (lineStart < len)
strings.add(str.substring(lineStart));
return strings;
}
public static void drawCenteredText(Graphics2D g2d, String text, int x, int y, HorizontalAlignment horizontalAlignment,
VerticalAlignment verticalAlignment) {
String[] parts = text.split("\n");
if (parts.length > 1) {
FontMetrics fontMetrics = g2d.getFontMetrics();
Rectangle stringBounds = fontMetrics.getStringBounds(parts[0], g2d).getBounds();
for (int i = 0; i < parts.length; i++)
drawCenteredText(g2d, parts[i], x, (int)(y - stringBounds.height * (parts.length - 1) / 2d + i * stringBounds.height), horizontalAlignment, verticalAlignment);
return;
}
FontMetrics fontMetrics = g2d.getFontMetrics();
Rectangle stringBounds = fontMetrics.getStringBounds(text, g2d).getBounds();
Font font = g2d.getFont();
FontRenderContext renderContext = g2d.getFontRenderContext();
GlyphVector glyphVector = font.createGlyphVector(renderContext, text);
Rectangle visualBounds = glyphVector.getVisualBounds().getBounds();
int textX = 0;
switch (horizontalAlignment) {
case CENTER:
textX = x - stringBounds.width / 2;
break;
case LEFT:
textX = x;
break;
case RIGHT:
textX = x - stringBounds.width;
break;
}
int textY = 0;
switch (verticalAlignment) {
case TOP:
textY = y + stringBounds.height;
break;
case CENTER:
textY = y - visualBounds.height / 2 - visualBounds.y;
break;
case BOTTOM:
textY = y - visualBounds.y;
break;
}
g2d.drawString(text, textX, textY);
}
}
@@ -21,33 +21,33 @@
*/ */
package org.diylc.components; package org.diylc.components;
import java.awt.Color; import java.awt.Color;
import java.awt.FontMetrics; import java.awt.FontMetrics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Point; import java.awt.Point;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.Shape; import java.awt.Shape;
import java.awt.geom.AffineTransform; import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.common.Display; import org.diylc.awt.StringUtils;
import org.diylc.common.HorizontalAlignment; import org.diylc.common.Display;
import org.diylc.common.IPlugInPort; import org.diylc.common.HorizontalAlignment;
import org.diylc.common.ObjectCache; import org.diylc.common.IPlugInPort;
import org.diylc.common.Orientation; import org.diylc.common.ObjectCache;
import org.diylc.common.VerticalAlignment; import org.diylc.common.Orientation;
import org.diylc.components.AbstractComponent; import org.diylc.common.VerticalAlignment;
import org.diylc.components.semiconductors.SymbolFlipping; import org.diylc.components.semiconductors.SymbolFlipping;
import org.diylc.core.ComponentState; import org.diylc.core.ComponentState;
import org.diylc.core.IDrawingObserver; import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project; import org.diylc.core.Project;
import org.diylc.core.Theme; import org.diylc.core.Theme;
import org.diylc.core.VisibilityPolicy; import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size; import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
public abstract class Abstract3LegSymbol extends AbstractComponent<String> { public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
@@ -57,16 +57,31 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
public static Color COLOR = Color.black; public static Color COLOR = Color.black;
protected String value = ""; protected String value = "";
protected Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0)}; protected Point[] controlPoints = new Point[] { new Point(0, 0), new Point(0, 0), new Point(0, 0), new Point(0, 0) };
protected Color color = COLOR; protected Color color = COLOR;
protected SymbolFlipping flip = SymbolFlipping.NONE; protected SymbolFlipping flip = SymbolFlipping.NONE;
protected Display display = Display.NAME; protected Display display = Display.NAME;
transient protected Shape[] body; transient protected Shape[] body;
protected Orientation orientation = Orientation.DEFAULT; protected Orientation orientation = Orientation.DEFAULT;
protected boolean moveLabel = false;
public Abstract3LegSymbol() { public Abstract3LegSymbol() {
super(); super();
updateControlPoints(); updateControlPoints();
controlPoints[3] = getDefaultLabelPosition(controlPoints);
}
public Point[] getControlPoints() {
if (controlPoints.length == 3) {
controlPoints = new Point[] { controlPoints[0], controlPoints[1], controlPoints[2], getDefaultLabelPosition(controlPoints) };
}
return controlPoints;
}
protected Point getDefaultLabelPosition(Point[] oldControlPoints) {
int f = flip == SymbolFlipping.X ? -1 : 1;
int d = flip == SymbolFlipping.X ? (int) PIN_SPACING.convertToPixels() / 2 : 0;
return new Point(oldControlPoints[0].x + f * (int) (PIN_SPACING.convertToPixels() * 1.5 + d), oldControlPoints[0].y);
} }
@Override @Override
@@ -88,14 +103,14 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
} }
g2d.setColor(finalColor); g2d.setColor(finalColor);
// Draw transistor
if (this.body == null) { if (this.body == null) {
this.body = getBody(); this.body = getBody();
applyOrientation(this.body); applyOrientation(this.body);
} }
AffineTransform old = g2d.getTransform(); AffineTransform old = g2d.getTransform();
Point[] controlPoints = getControlPoints();
if (this.flip == SymbolFlipping.Y) { if (this.flip == SymbolFlipping.Y) {
g2d.translate(0, controlPoints[0].y); g2d.translate(0, controlPoints[0].y);
@@ -142,61 +157,82 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
FontMetrics fontMetrics = g2d.getFontMetrics(); FontMetrics fontMetrics = g2d.getFontMetrics();
Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d); Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d);
Rectangle shapeRect = body[0].getBounds().union(body[1].getBounds()).union(body[2].getBounds()); Rectangle shapeRect = body[0].getBounds().union(body[1].getBounds()).union(body[2].getBounds());
drawCenteredText(g2d, label, getLabelX(shapeRect, textRect, fontMetrics, outlineMode), if (getMoveLabel()) {
getLabelY(shapeRect, textRect, fontMetrics, outlineMode), flip == SymbolFlipping.X ? HorizontalAlignment.RIGHT StringUtils.drawCenteredText(g2d, label, controlPoints[3].x, controlPoints[3].y, flip == SymbolFlipping.X ? HorizontalAlignment.RIGHT
: HorizontalAlignment.LEFT, VerticalAlignment.CENTER); : HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
} else {
StringUtils.drawCenteredText(g2d, label, getLabelX(shapeRect, textRect, fontMetrics, outlineMode),
getLabelY(shapeRect, textRect, fontMetrics, outlineMode), flip == SymbolFlipping.X ? HorizontalAlignment.RIGHT
: HorizontalAlignment.LEFT, VerticalAlignment.CENTER);
}
} }
@Override @Override
public Point getControlPoint(int index) { public Point getControlPoint(int index) {
return controlPoints[index]; return getControlPoints()[index];
} }
@Override @Override
public int getControlPointCount() { public int getControlPointCount() {
return controlPoints.length; return getControlPoints().length;
} }
protected int getLabelX(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics, boolean outlineMode) { protected int getLabelX(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics, boolean outlineMode) {
int f = flip == SymbolFlipping.X ? -1 : 1; int f = flip == SymbolFlipping.X ? -1 : 1;
int d = flip == SymbolFlipping.X ? (int) PIN_SPACING.convertToPixels() / 2 : 0; int d = flip == SymbolFlipping.X ? (int) PIN_SPACING.convertToPixels() / 2 : 0;
return controlPoints[0].x + f * (int) (PIN_SPACING.convertToPixels() * 1.5 + d); return getControlPoints()[0].x + f * (int) (PIN_SPACING.convertToPixels() * 1.5 + d);
} }
protected int getLabelY(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics, boolean outlineMode) { protected int getLabelY(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics, boolean outlineMode) {
return controlPoints[0].y; return getControlPoints()[0].y;
} }
protected void updateControlPoints() { protected void updateControlPoints() {
int pinSpacing = (int) PIN_SPACING.convertToPixels(); int pinSpacing = (int) PIN_SPACING.convertToPixels();
// Update control points. Point[] controlPoints = getControlPoints();
int x = controlPoints[0].x; int x = controlPoints[0].x;
int y = controlPoints[0].y; int y = controlPoints[0].y;
int f = flip == SymbolFlipping.X ? -1 : 1; // set default point positions
controlPoints[1].x = x + pinSpacing * 2;
controlPoints[1].x = x + f * pinSpacing * 2;
controlPoints[1].y = y - pinSpacing * 2; controlPoints[1].y = y - pinSpacing * 2;
controlPoints[2].x = x + f * pinSpacing * 2; controlPoints[2].x = x + pinSpacing * 2;
controlPoints[2].y = y + pinSpacing * 2; controlPoints[2].y = y + pinSpacing * 2;
controlPoints[3].x = x + (int) (PIN_SPACING.convertToPixels() * 2);
controlPoints[3].y = y;
// apply rotation if needed
if (getOrientation() != Orientation.DEFAULT) if (getOrientation() != Orientation.DEFAULT)
{ {
Point first = this.controlPoints[0]; Point first = controlPoints[0];
double angle = Double.parseDouble(getOrientation().name().replace("_", "")); double angle = Double.parseDouble(getOrientation().name().replace("_", ""));
AffineTransform rotate = AffineTransform.getRotateInstance(Math.toRadians(angle), first.x, first.y); AffineTransform rotate = AffineTransform.getRotateInstance(Math.toRadians(angle), first.x, first.y);
for (int i = 1; i < this.controlPoints.length; i++) { for (int i = 1; i < controlPoints.length; i++) {
rotate.transform(this.controlPoints[i], this.controlPoints[i]); rotate.transform(controlPoints[i], controlPoints[i]);
} }
}
// flip at the end
if (flip == SymbolFlipping.X) {
controlPoints[1].x = controlPoints[0].x - (controlPoints[1].x - controlPoints[0].x);
controlPoints[2].x = controlPoints[0].x - (controlPoints[2].x - controlPoints[0].x);
controlPoints[3].x = controlPoints[0].x - (controlPoints[3].x - controlPoints[0].x);
}
if (flip == SymbolFlipping.Y) {
controlPoints[1].y = controlPoints[0].y - (controlPoints[1].y - controlPoints[0].y);
controlPoints[2].y = controlPoints[0].y - (controlPoints[2].y - controlPoints[0].y);
controlPoints[3].y = controlPoints[0].y - (controlPoints[3].y - controlPoints[0].y);
} }
} }
@Override @Override
public VisibilityPolicy getControlPointVisibilityPolicy(int index) { public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
return VisibilityPolicy.WHEN_SELECTED; return index < 3 || getMoveLabel() ? VisibilityPolicy.WHEN_SELECTED : VisibilityPolicy.NEVER;
} }
@EditableProperty @EditableProperty
@@ -212,15 +248,25 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
@Override @Override
public boolean isControlPointSticky(int index) { public boolean isControlPointSticky(int index) {
return true; return index < 3;
} }
@Override @Override
public void setControlPoint(Point point, int index) { public void setControlPoint(Point point, int index) {
controlPoints[index].setLocation(point); getControlPoints()[index].setLocation(point);
// make sure we have a new drawing // make sure we have a new drawing
body = null; body = null;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return pointIndex == 3;
}
@Override
public boolean canControlPointOverlap(int index) {
return index >= 3;
} }
@EditableProperty @EditableProperty
@@ -243,6 +289,15 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
public void setColor(Color color) { public void setColor(Color color) {
this.color = color; this.color = color;
}
@EditableProperty(name = "Moveable Label")
public boolean getMoveLabel() {
return moveLabel;
}
public void setMoveLabel(boolean moveLabel) {
this.moveLabel = moveLabel;
} }
@EditableProperty @EditableProperty
@@ -274,7 +329,7 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
if (getOrientation() == Orientation.DEFAULT) if (getOrientation() == Orientation.DEFAULT)
return; return;
Point first = this.controlPoints[0]; Point first = getControlPoints()[0];
double angle = Double.parseDouble(getOrientation().name().replace("_", "")); double angle = Double.parseDouble(getOrientation().name().replace("_", ""));
AffineTransform rotate = AffineTransform.getRotateInstance(Math.toRadians(angle), first.x, first.y); AffineTransform rotate = AffineTransform.getRotateInstance(Math.toRadians(angle), first.x, first.y);
@@ -283,6 +338,13 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
body[i] = rotate.createTransformedShape(body[i]); body[i] = rotate.createTransformedShape(body[i]);
} }
} }
}
@Override
public String getControlPointNodeName(int index) {
if (index >= 3)
return null;
return Integer.toString(index + 1);
} }
/** /**
@@ -36,10 +36,13 @@ import java.awt.geom.Rectangle2D;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.awt.ShadedPaint; import org.diylc.awt.ShadedPaint;
import org.diylc.awt.StringUtils;
import org.diylc.common.Display; import org.diylc.common.Display;
import org.diylc.common.HorizontalAlignment;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
import org.diylc.common.LineStyle; import org.diylc.common.LineStyle;
import org.diylc.common.ObjectCache; import org.diylc.common.ObjectCache;
import org.diylc.common.VerticalAlignment;
import org.diylc.core.ComponentState; import org.diylc.core.ComponentState;
import org.diylc.core.IDrawingObserver; import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project; import org.diylc.core.Project;
@@ -70,7 +73,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
protected Size length; protected Size length;
protected Size width; protected Size width;
protected Point[] points = new Point[] {new Point((int) (-DEFAULT_SIZE.convertToPixels() / 2), 0), protected Point[] points = new Point[] {new Point((int) (-DEFAULT_SIZE.convertToPixels() / 2), 0),
new Point((int) (DEFAULT_SIZE.convertToPixels() / 2), 0)}; new Point((int) (DEFAULT_SIZE.convertToPixels() / 2), 0), new Point(0, 0)};
protected Color bodyColor = Color.white; protected Color bodyColor = Color.white;
protected Color borderColor = Color.black; protected Color borderColor = Color.black;
protected Color labelColor = LABEL_COLOR; protected Color labelColor = LABEL_COLOR;
@@ -78,6 +81,11 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
protected Display display = Display.NAME; protected Display display = Display.NAME;
private boolean flipStanding = false; private boolean flipStanding = false;
private LabelOriantation labelOriantation = LabelOriantation.Directional; private LabelOriantation labelOriantation = LabelOriantation.Directional;
protected boolean moveLabel = false;
// parameters for adjusting the label control point
protected Double gamma = null;
protected Double r = null;
protected AbstractLeadedComponent() { protected AbstractLeadedComponent() {
super(); super();
@@ -88,28 +96,67 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
// This should never happen because Size supports cloning. // This should never happen because Size supports cloning.
} catch (NullPointerException e) { } catch (NullPointerException e) {
// This will happen if components do not have any shape. // This will happen if components do not have any shape.
} }
points[2] = calculateLabelPosition(points[0], points[1]);
} }
protected boolean IsCopperArea() { protected boolean IsCopperArea() {
return false; return false;
} }
protected Point[] getPoints() {
// convert old points to new
if (points.length == 2) {
points = new Point[] { points[0], points[1], calculateLabelPosition(points[0], points[1]) };
// to make standing components backward compatible and not show a label until the user switches the display to something else
if (isStanding())
display = Display.NONE;
}
return points;
}
protected Point calculateLabelPosition(Point point1, Point point2) {
double x = (point1.x + point2.x) / 2.0;
double y = (point1.y + point2.y) / 2.0;
return new Point((int) x, (int) y);
}
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
double distance = points[0].distance(points[1]); if (gamma != null) {
// recalculate center position and theta, then adjust label point accordingly, while preserving alpha and p
double x = (getPoints()[1].x + getPoints()[0].x) / 2.0;
double y = (getPoints()[1].y + getPoints()[0].y) / 2.0;
double theta = Math.atan2(getPoints()[1].y - getPoints()[0].y, getPoints()[1].x - getPoints()[0].x);
double beta = gamma - (Math.PI / 2 - theta);
getPoints()[2].setLocation(x + Math.cos(beta) * r, y + Math.sin(beta) * r);
gamma = null;
r = null;
}
double distance = getPoints()[0].distance(getPoints()[1]);
Shape shape = getBodyShape(); Shape shape = getBodyShape();
// If there's no body, just draw the line connecting the ending points. // If there's no body, just draw the line connecting the ending points.
if (shape == null) { if (shape == null) {
drawLead(g2d, componentState, drawingObserver, IsCopperArea()); drawLead(g2d, componentState, drawingObserver, IsCopperArea());
} else if (supportsStandingMode() && length.convertToPixels() > points[0].distance(points[1])) { return;
}
AffineTransform oldTransform = g2d.getTransform();
double width;
double length;
Rectangle shapeRect;
double theta = Math.atan2(getPoints()[1].y - getPoints()[0].y, getPoints()[1].x - getPoints()[0].x);
if (isStanding()) {
// When ending points are too close draw the component in standing // When ending points are too close draw the component in standing
// mode. // mode.
int width = getClosestOdd(this.width.convertToPixels()); width = length = getClosestOdd(this.width.convertToPixels());
Shape body = Shape body =
new Ellipse2D.Double((getFlipStanding() ? points[1] : points[0]).x - width / 2, new Ellipse2D.Double((getFlipStanding() ? getPoints()[1] : getPoints()[0]).x - width / 2,
(getFlipStanding() ? points[1] : points[0]).y - width / 2, width, width); (getFlipStanding() ? getPoints()[1] : getPoints()[0]).y - width / 2, width, width);
shapeRect = body.getBounds();
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA)); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
@@ -138,11 +185,10 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
} }
} else { } else {
// Normal mode with component body in the center and two lead parts. // Normal mode with component body in the center and two lead parts.
Rectangle shapeRect = shape.getBounds(); 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. // Go back to the original transformation to draw leads.
if (!outlineMode) { if (!outlineMode) {
AffineTransform textTransform = g2d.getTransform(); // AffineTransform textTransform = g2d.getTransform();
// if (length.convertToPixels() > points[0].distance(points[1])) // if (length.convertToPixels() > points[0].distance(points[1]))
// { // {
// g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, // g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
@@ -157,14 +203,14 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
Area leadArea = new Area(); Area leadArea = new Area();
int endX = (int) (points[0].x + Math.cos(theta) * leadLength); int endX = (int) (getPoints()[0].x + Math.cos(theta) * leadLength);
int endY = (int) (points[0].y + Math.sin(theta) * leadLength); int endY = (int) (getPoints()[0].y + Math.sin(theta) * leadLength);
Line2D line = new Line2D.Double(points[0].x, points[0].y, endX, endY); Line2D line = new Line2D.Double(getPoints()[0].x, getPoints()[0].y, endX, endY);
leadArea.add(new Area(leadStroke.createStrokedShape(line))); leadArea.add(new Area(leadStroke.createStrokedShape(line)));
endX = (int) (points[1].x + Math.cos(theta - Math.PI) * leadLength); endX = (int) (getPoints()[1].x + Math.cos(theta - Math.PI) * leadLength);
endY = (int) (points[1].y + Math.sin(theta - Math.PI) * leadLength); endY = (int) (getPoints()[1].y + Math.sin(theta - Math.PI) * leadLength);
line = new Line2D.Double(points[1].x, points[1].y, endX, endY); line = new Line2D.Double(getPoints()[1].x, getPoints()[1].y, endX, endY);
leadArea.add(new Area(leadStroke.createStrokedShape(line))); leadArea.add(new Area(leadStroke.createStrokedShape(line)));
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1f)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1f));
@@ -178,13 +224,10 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
g2d.setColor(leadColor); g2d.setColor(leadColor);
drawLeads(g2d, theta, leadLength); drawLeads(g2d, theta, leadLength);
} }
g2d.setTransform(textTransform); // g2d.setTransform(textTransform);
} }
// Transform graphics to draw the body in the right place and at the // Transform graphics to draw the body in the right place and at the
// right angle. // right angle.
AffineTransform oldTransform = null;
double width;
double length;
if (useShapeRectAsPosition()) { if (useShapeRectAsPosition()) {
width = shapeRect.getHeight(); width = shapeRect.getHeight();
length = shapeRect.getWidth(); length = shapeRect.getWidth();
@@ -192,8 +235,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
width = getWidth().convertToPixels(); width = getWidth().convertToPixels();
length = getLength().convertToPixels(); length = getLength().convertToPixels();
} }
oldTransform = g2d.getTransform(); g2d.translate((getPoints()[0].x + getPoints()[1].x - length) / 2, (getPoints()[0].y + getPoints()[1].y - width) / 2);
g2d.translate((points[0].x + points[1].x - length) / 2, (points[0].y + points[1].y - width) / 2);
g2d.rotate(theta, length / 2, width / 2); g2d.rotate(theta, length / 2, width / 2);
// Draw body. // Draw body.
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
@@ -244,64 +286,91 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
decorateComponentBody(g2d, outlineMode); decorateComponentBody(g2d, outlineMode);
g2d.setComposite(oldComposite); g2d.setComposite(oldComposite);
} }
}
// Draw label. // Draw label.
g2d.setFont(project.getFont()); g2d.setFont(project.getFont());
if (useShapeRectAsPosition()) { if (useShapeRectAsPosition()) {
g2d.translate(shapeRect.x, shapeRect.y); g2d.translate(shapeRect.x, shapeRect.y);
}
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
: labelColor;
}
g2d.setColor(finalLabelColor);
FontMetrics fontMetrics = g2d.getFontMetrics();
String label = "";
label = display == Display.NAME ? getName() : (getValue() == null ? "" : getValue().toString());
if (display == Display.NONE) {
label = "";
}
if (display == Display.BOTH) {
label = getName() + " " + (getValue() == null ? "" : getValue().toString());
}
Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d);
// Don't offset in outline mode.
int offset = outlineMode ? 0 : getLabelOffset((int) length, (int) width, (int) textRect.getWidth());
// Adjust label angle if needed to make sure that it's readable.
if ((theta >= Math.PI / 2 && theta <= Math.PI) || (theta < -Math.PI / 2 && theta > -Math.PI)) {
g2d.rotate(Math.PI, length / 2, width / 2);
theta += Math.PI;
offset = -offset;
}
if (getMoveLabel()) {
g2d.setTransform(oldTransform);
g2d.translate(getPoints()[2].x, getPoints()[2].y);
if (getLabelOriantation() != LabelOriantation.Horizontal) {
g2d.rotate(theta);
} }
Color finalLabelColor; StringUtils.drawCenteredText(g2d, label, offset, 0, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
if (outlineMode) { g2d.setTransform(oldTransform);
Theme theme = } else {
(Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); if (isStanding() || getLabelOriantation() == LabelOriantation.Horizontal) {
finalLabelColor =
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: theme.getOutlineColor();
} else {
finalLabelColor =
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: labelColor;
}
g2d.setColor(finalLabelColor);
FontMetrics fontMetrics = g2d.getFontMetrics();
String label = "";
label = display == Display.NAME ? getName() : (getValue() == null ? "" : getValue().toString());
if (display == Display.NONE) {
label = "";
}
if (display == Display.BOTH) {
label = getName() + " " + (getValue() == null ? "" : getValue().toString());
}
Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d);
// Don't offset in outline mode.
int offset = outlineMode ? 0 : getLabelOffset((int) length, (int) width, (int) textRect.getWidth());
// Adjust label angle if needed to make sure that it's readable.
if ((theta >= Math.PI / 2 && theta <= Math.PI) || (theta < -Math.PI / 2 && theta > -Math.PI)) {
g2d.rotate(Math.PI, length / 2, width / 2);
offset = -offset;
}
if (getLabelOriantation() == LabelOriantation.Horizontal) {
g2d.setTransform(oldTransform); g2d.setTransform(oldTransform);
double x = (points[0].x + points[1].x - length) / 2.0; double x = (getPoints()[0].x + getPoints()[1].x - length) / 2.0;
double y = (points[0].y + points[1].y - width) / 2.0; double y = (getPoints()[0].y + getPoints()[1].y - width) / 2.0;
g2d.drawString(label, (int) (x + (length - textRect.getWidth()) / 2 + offset), g2d.drawString(label, (int) (x + (length - textRect.getWidth()) / 2 + offset),
(int)(y + calculateLabelYCoordinate(shapeRect, textRect, fontMetrics))); (int)(y + calculateLabelYOffset(shapeRect, textRect, fontMetrics)));
} else { } else {
g2d.drawString(label, (int) (length - textRect.getWidth()) / 2 + offset, g2d.drawString(label, (int) (length - textRect.getWidth()) / 2 + offset,
calculateLabelYCoordinate(shapeRect, textRect, fontMetrics)); calculateLabelYOffset(shapeRect, textRect, fontMetrics));
g2d.setTransform(oldTransform); g2d.setTransform(oldTransform);
} }
} }
// if (getLabelOriantation() == LabelOriantation.Horizontal) {
//
// drawCenteredText(g2d, label, getNewPoints()[2].x, getNewPoints()[2].x, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
// g2d.drawString(label, (int) (x + (length - textRect.getWidth()) / 2 + offset),
// (int)(y + calculateLabelYCoordinate(shapeRect, textRect, fontMetrics)));
// } else {
// g2d.drawString(label, (int) (length - textRect.getWidth()) / 2 + offset,
// calculateLabelYCoordinate(shapeRect, textRect, fontMetrics));
// g2d.setTransform(oldTransform);
// }
}
protected boolean isStanding() {
return supportsStandingMode() && this.length.convertToPixels() > getPoints()[0].distance(getPoints()[1]);
} }
private void drawLeads(Graphics2D g2d, double theta, double leadLength) { private void drawLeads(Graphics2D g2d, double theta, double leadLength) {
double endX = points[0].x + Math.cos(theta) * leadLength; double endX = getPoints()[0].x + Math.cos(theta) * leadLength;
double endY = points[0].y + Math.sin(theta) * leadLength; double endY = getPoints()[0].y + Math.sin(theta) * leadLength;
g2d.draw(new Line2D.Double(points[0].x, points[0].y, endX, endY)); g2d.draw(new Line2D.Double(getPoints()[0].x, getPoints()[0].y, endX, endY));
endX = points[1].x + Math.cos(theta - Math.PI) * leadLength; endX = getPoints()[1].x + Math.cos(theta - Math.PI) * leadLength;
endY = points[1].y + Math.sin(theta - Math.PI) * leadLength; endY = getPoints()[1].y + Math.sin(theta - Math.PI) * leadLength;
g2d.draw(new Line2D.Double(points[1].x, points[1].y, endX, endY)); g2d.draw(new Line2D.Double(getPoints()[1].x, getPoints()[1].y, endX, endY));
} }
private void drawLead(Graphics2D g2d, ComponentState componentState, IDrawingObserver observer, boolean isCopperArea) { private void drawLead(Graphics2D g2d, ComponentState componentState, IDrawingObserver observer, boolean isCopperArea) {
@@ -310,7 +379,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
float thickness = getLeadThickness(); float thickness = getLeadThickness();
Line2D line = new Line2D.Double(points[0].x, points[0].y, points[1].x, points[1].y); Line2D line = new Line2D.Double(getPoints()[0].x, getPoints()[0].y, getPoints()[1].x, getPoints()[1].y);
if (shouldShadeLeads()) { if (shouldShadeLeads()) {
// for some reason the stroked line gets approx 1px thicker when converted to shape // for some reason the stroked line gets approx 1px thicker when converted to shape
@@ -366,7 +435,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
return false; return false;
} }
protected int calculateLabelYCoordinate(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics) { protected int calculateLabelYOffset(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics) {
return (int) (shapeRect.getHeight() - textRect.getHeight()) / 2 + fontMetrics.getAscent(); return (int) (shapeRect.getHeight() - textRect.getHeight()) / 2 + fontMetrics.getAscent();
} }
@@ -447,27 +516,48 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
@Override @Override
public int getControlPointCount() { public int getControlPointCount() {
return points.length; return getPoints().length;
} }
@Override @Override
public Point getControlPoint(int index) { public Point getControlPoint(int index) {
return (Point) points[index]; return (Point) getPoints()[index];
} }
@Override @Override
public boolean isControlPointSticky(int index) { public boolean isControlPointSticky(int index) {
return true; return index < 2;
} }
@Override @Override
public VisibilityPolicy getControlPointVisibilityPolicy(int index) { public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
return VisibilityPolicy.ALWAYS; return getMoveLabel() || index < 2 ? VisibilityPolicy.ALWAYS : VisibilityPolicy.NEVER;
}
@Override
public boolean canControlPointOverlap(int index) {
return index >= 2;
} }
@Override @Override
public void setControlPoint(Point point, int index) { public void setControlPoint(Point point, int index) {
points[index].setLocation(point); // when moving one of the ending points, try to retain the angle and distance from the center point to label point
if (index < 2) {
if (gamma == null) {
double x = (getPoints()[1].x + getPoints()[0].x) / 2.0;
double y = (getPoints()[1].y + getPoints()[0].y) / 2.0;
double theta = Math.atan2(getPoints()[1].y - getPoints()[0].y, getPoints()[1].x - getPoints()[0].x);
double beta = Math.atan2(getPoints()[2].y - y, getPoints()[2].x - x);
gamma = beta + (Math.PI / 2 - theta);
r = getPoints()[2].distance(x, y);
} else { // in case when we are copy pasting we don't want to recalculate 3rd point position as they will all move in unison
// when we moved the first point, gamma and r were initialized, so now we are canceling
gamma = null;
r = null;
}
}
getPoints()[index].setLocation(point);
} }
@EditableProperty(name = "Color") @EditableProperty(name = "Color")
@@ -541,7 +631,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
@Override @Override
public String getInternalLinkName(int index1, int index2) { public String getInternalLinkName(int index1, int index2) {
if ((index1 == 0 && index2 == getControlPointCount() - 1) || (index2 == 0 && index1 == getControlPointCount() - 1)) if ((index1 == 0 && index2 == 1) || (index2 == 0 && index1 == 1))
return getName(); return getName();
return null; return null;
} }
@@ -559,7 +649,23 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
public void setFlipStanding(boolean flipStanding) { public void setFlipStanding(boolean flipStanding) {
this.flipStanding = flipStanding; this.flipStanding = flipStanding;
} }
@EditableProperty(name = "Moveable Label")
public boolean getMoveLabel() {
return moveLabel;
}
public void setMoveLabel(boolean moveLabel) {
this.moveLabel = moveLabel;
}
@Override
public String getControlPointNodeName(int index) {
if (index >= 2)
return null;
return Integer.toString(index + 1);
}
public enum LabelOriantation { public enum LabelOriantation {
Directional, Horizontal Directional, Horizontal
} }
@@ -21,13 +21,14 @@
*/ */
package org.diylc.components; package org.diylc.components;
import java.awt.Color; import java.awt.Color;
import java.awt.FontMetrics; import java.awt.FontMetrics;
import java.awt.geom.Rectangle2D; import java.awt.Point;
import java.awt.geom.Rectangle2D;
import org.diylc.common.LabelPosition; import org.diylc.common.LabelPosition;
import org.diylc.core.ComponentState; import org.diylc.core.ComponentState;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
public abstract class AbstractSchematicLeadedSymbol<T> extends AbstractLeadedComponent<T> { public abstract class AbstractSchematicLeadedSymbol<T> extends AbstractLeadedComponent<T> {
@@ -62,12 +63,21 @@ public abstract class AbstractSchematicLeadedSymbol<T> extends AbstractLeadedCom
} }
@Override @Override
protected int calculateLabelYCoordinate(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics) { protected int calculateLabelYOffset(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics) {
if (labelPosition == LabelPosition.ABOVE) { if (labelPosition == LabelPosition.ABOVE) {
return -5; return -5;
} else { } else {
return (int) (shapeRect.getHeight() + textRect.getHeight()); return (int) (shapeRect.getHeight() + textRect.getHeight());
} }
}
@Override
protected Point calculateLabelPosition(Point point1, Point point2) {
double x = (point1.x + point2.x) / 2.0;
double y = (point1.y + point2.y) / 2.0;
double theta = Math.atan2(point2.y - point1.y, point2.x - point2.x) - Math.PI / 2;
double r = width.convertToPixels() / 2 + LABEL_FONT.getSize() / 2;
return new Point((int) (x + Math.cos(theta) * r), (int) (y + Math.sin(theta) * r));
} }
@EditableProperty(name = "Label Position") @EditableProperty(name = "Label Position")
@@ -27,6 +27,7 @@ import java.awt.Composite;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Point; import java.awt.Point;
import org.diylc.awt.StringUtils;
import org.diylc.common.HorizontalAlignment; import org.diylc.common.HorizontalAlignment;
import org.diylc.common.ObjectCache; import org.diylc.common.ObjectCache;
import org.diylc.common.VerticalAlignment; import org.diylc.common.VerticalAlignment;
@@ -116,11 +117,11 @@ public abstract class AbstractBoard extends AbstractTransparentComponent<String>
String label = yType == CoordinateType.Letters ? getCoordinateLabel(c) : Integer.toString(c); String label = yType == CoordinateType.Letters ? getCoordinateLabel(c) : Integer.toString(c);
drawPoint.y += yOffset; drawPoint.y += yOffset;
drawCenteredText(g2d, label, StringUtils.drawCenteredText(g2d, label,
firstPoint.x + xOffset, drawPoint.y, firstPoint.x + xOffset, drawPoint.y,
HorizontalAlignment.LEFT, VerticalAlignment.CENTER); HorizontalAlignment.LEFT, VerticalAlignment.CENTER);
if (getCoordinateDisplay() == CoordinateDisplay.Both_Sides) { if (getCoordinateDisplay() == CoordinateDisplay.Both_Sides) {
drawCenteredText(g2d, label, StringUtils.drawCenteredText(g2d, label,
secondPoint.x - xOffset, drawPoint.y, secondPoint.x - xOffset, drawPoint.y,
HorizontalAlignment.RIGHT, VerticalAlignment.CENTER); HorizontalAlignment.RIGHT, VerticalAlignment.CENTER);
} }
@@ -146,11 +147,11 @@ public abstract class AbstractBoard extends AbstractTransparentComponent<String>
String label = xType == CoordinateType.Letters ? getCoordinateLabel(c) : Integer.toString(c); String label = xType == CoordinateType.Letters ? getCoordinateLabel(c) : Integer.toString(c);
drawPoint.x += xOffset; drawPoint.x += xOffset;
drawCenteredText(g2d, label, StringUtils.drawCenteredText(g2d, label,
drawPoint.x, firstPoint.y - 2, drawPoint.x, firstPoint.y - 2,
HorizontalAlignment.CENTER, VerticalAlignment.TOP); HorizontalAlignment.CENTER, VerticalAlignment.TOP);
if (getCoordinateDisplay() == CoordinateDisplay.Both_Sides) { if (getCoordinateDisplay() == CoordinateDisplay.Both_Sides) {
drawCenteredText(g2d, label, StringUtils.drawCenteredText(g2d, label,
drawPoint.x, (int) (secondPoint.y - COORDINATE_FONT_SIZE), drawPoint.x, (int) (secondPoint.y - COORDINATE_FONT_SIZE),
HorizontalAlignment.CENTER, VerticalAlignment.BOTTOM); HorizontalAlignment.CENTER, VerticalAlignment.BOTTOM);
} }
@@ -28,6 +28,7 @@ import java.awt.Graphics2D;
import java.awt.Point; import java.awt.Point;
import java.awt.geom.AffineTransform; import java.awt.geom.AffineTransform;
import org.diylc.awt.StringUtils;
import org.diylc.common.HorizontalAlignment; import org.diylc.common.HorizontalAlignment;
import org.diylc.common.ObjectCache; import org.diylc.common.ObjectCache;
import org.diylc.common.Orientation; import org.diylc.common.Orientation;
@@ -46,7 +47,7 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Breadboard", category = "Boards", author = "Branislav Stojkovic", @ComponentDescriptor(name = "Breadboard", category = "Boards", author = "Branislav Stojkovic",
description = "Prototyping solderless breadboard", instanceNamePrefix = "BB", stretchable = false, description = "Prototyping solderless breadboard", instanceNamePrefix = "BB",
zOrder = IDIYComponent.BOARD, bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false, zOrder = IDIYComponent.BOARD, bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false,
keywordPolicy = KeywordPolicy.SHOW_TYPE_NAME) keywordPolicy = KeywordPolicy.SHOW_TYPE_NAME)
public class Breadboard extends AbstractComponent<Void> { public class Breadboard extends AbstractComponent<Void> {
@@ -146,7 +147,7 @@ public class Breadboard extends AbstractComponent<Void> {
} else { } else {
coordinateX = (int) (point.x + offset + 10.5 * spacing); coordinateX = (int) (point.x + offset + 10.5 * spacing);
} }
drawCenteredText(g2d, new Integer(y + 1).toString(), coordinateX, (int) (point.y + (y + 1) * spacing), StringUtils.drawCenteredText(g2d, new Integer(y + 1).toString(), coordinateX, (int) (point.y + (y + 1) * spacing),
section == 0 ? HorizontalAlignment.RIGHT : HorizontalAlignment.LEFT, VerticalAlignment.CENTER); section == 0 ? HorizontalAlignment.RIGHT : HorizontalAlignment.LEFT, VerticalAlignment.CENTER);
for (int x = 0; x < 5; x++) { for (int x = 0; x < 5; x++) {
int holeX = (int) (point.x + offset + (x + 6) * spacing); int holeX = (int) (point.x + offset + (x + 6) * spacing);
@@ -159,9 +160,9 @@ public class Breadboard extends AbstractComponent<Void> {
// Draw horizontal labels // Draw horizontal labels
if (y == 0) { if (y == 0) {
g2d.setColor(COORDINATE_COLOR); g2d.setColor(COORDINATE_COLOR);
drawCenteredText(g2d, new String(new byte[] {(byte) (a + x + 5 * section)}), holeX, (int) (point.y), StringUtils.drawCenteredText(g2d, new String(new byte[] {(byte) (a + x + 5 * section)}), holeX, (int) (point.y),
HorizontalAlignment.CENTER, VerticalAlignment.TOP); HorizontalAlignment.CENTER, VerticalAlignment.TOP);
drawCenteredText(g2d, new String(new byte[] {(byte) (a + x + 5 * section)}), holeX, (int) (point.y StringUtils.drawCenteredText(g2d, new String(new byte[] {(byte) (a + x + 5 * section)}), holeX, (int) (point.y
+ spacing * 30 + COORDINATE_FONT_SIZE / 2), HorizontalAlignment.CENTER, VerticalAlignment.TOP); + spacing * 30 + COORDINATE_FONT_SIZE / 2), HorizontalAlignment.CENTER, VerticalAlignment.TOP);
} }
} }
@@ -218,7 +219,7 @@ public class Breadboard extends AbstractComponent<Void> {
} else { } else {
coordinateX = (int) (point.x + offset + 10.5 * spacing); coordinateX = (int) (point.x + offset + 10.5 * spacing);
} }
drawCenteredText(g2d, new Integer(y + 1).toString(), coordinateX, (int) (point.y + (y + 1) * spacing), StringUtils.drawCenteredText(g2d, new Integer(y + 1).toString(), coordinateX, (int) (point.y + (y + 1) * spacing),
section == 0 ? HorizontalAlignment.RIGHT : HorizontalAlignment.LEFT, VerticalAlignment.CENTER); section == 0 ? HorizontalAlignment.RIGHT : HorizontalAlignment.LEFT, VerticalAlignment.CENTER);
// for (int x = 0; x < 5; x++) { // for (int x = 0; x < 5; x++) {
int holeX1 = (int) (point.x + offset + 6 * spacing); int holeX1 = (int) (point.x + offset + 6 * spacing);
@@ -312,6 +313,11 @@ public class Breadboard extends AbstractComponent<Void> {
@Override @Override
public int getControlPointCount() { public int getControlPointCount() {
return 2; return 2;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
} }
@SuppressWarnings("incomplete-switch") @SuppressWarnings("incomplete-switch")
@@ -37,6 +37,7 @@ import org.diylc.common.Orientation;
import org.diylc.components.AbstractTransparentComponent; import org.diylc.components.AbstractTransparentComponent;
import org.diylc.components.transform.TerminalStripTransformer; import org.diylc.components.transform.TerminalStripTransformer;
import org.diylc.core.ComponentState; import org.diylc.core.ComponentState;
import org.diylc.core.IContinuity;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver; import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project; import org.diylc.core.Project;
@@ -51,9 +52,9 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Terminal Strip", author = "Branislav Stojkovic", category = "Boards", @ComponentDescriptor(name = "Terminal Strip", author = "Branislav Stojkovic", category = "Boards",
instanceNamePrefix = "TS", description = "Row of terminals for point-to-point construction", stretchable = false, instanceNamePrefix = "TS", description = "Row of terminals for point-to-point construction",
zOrder = IDIYComponent.BOARD, keywordPolicy = KeywordPolicy.SHOW_TYPE_NAME, transformer = TerminalStripTransformer.class) zOrder = IDIYComponent.BOARD, keywordPolicy = KeywordPolicy.SHOW_TYPE_NAME, transformer = TerminalStripTransformer.class)
public class TerminalStrip extends AbstractTransparentComponent<String> { public class TerminalStrip extends AbstractTransparentComponent<String> implements IContinuity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -454,5 +455,15 @@ public class TerminalStrip extends AbstractTransparentComponent<String> {
@Override @Override
public String getControlPointNodeName(int index) { public String getControlPointNodeName(int index) {
return "TerminalStrip" + index; return "TerminalStrip" + index;
}
@Override
public boolean arePointsConnected(int index1, int index2) {
return Math.abs(index1 - index2) == getTerminalCount();
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
} }
} }
@@ -167,4 +167,9 @@ public class CopperTrace extends AbstractLeadedComponent<Void> {
public String getControlPointNodeName(int index) { public String getControlPointNodeName(int index) {
return null; return null;
} }
public boolean getMoveLabel() {
// override to disable edit
return false;
}
} }
@@ -39,7 +39,7 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Cut Line", category = "Connectivity", author = "Branislav Stojkovic", @ComponentDescriptor(name = "Cut Line", category = "Connectivity", author = "Branislav Stojkovic",
description = "Cut line", instanceNamePrefix = "CL", stretchable = false, zOrder = IDIYComponent.COMPONENT, description = "Cut line", instanceNamePrefix = "CL", zOrder = IDIYComponent.COMPONENT,
bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false, transformer = SimpleComponentTransformer.class) bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false, transformer = SimpleComponentTransformer.class)
public class CutLine extends AbstractTransparentComponent<Void> { public class CutLine extends AbstractTransparentComponent<Void> {
@@ -40,7 +40,7 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Dot", category = "Connectivity", author = "Branislav Stojkovic", @ComponentDescriptor(name = "Dot", category = "Connectivity", author = "Branislav Stojkovic",
description = "Connector dot", instanceNamePrefix = "Dot", stretchable = false, zOrder = IDIYComponent.COMPONENT, description = "Connector dot", instanceNamePrefix = "Dot", zOrder = IDIYComponent.COMPONENT,
bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false, transformer = SimpleComponentTransformer.class) bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false, transformer = SimpleComponentTransformer.class)
public class Dot extends AbstractComponent<Void> { public class Dot extends AbstractComponent<Void> {
@@ -44,7 +44,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Eyelet", category = "Connectivity", author = "Branislav Stojkovic", @ComponentDescriptor(name = "Eyelet", category = "Connectivity", author = "Branislav Stojkovic",
description = "Eyelet or turret terminal", instanceNamePrefix = "Eyelet", stretchable = false, description = "Eyelet or turret terminal", instanceNamePrefix = "Eyelet",
zOrder = IDIYComponent.TRACE + 0.1, bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false, zOrder = IDIYComponent.TRACE + 0.1, bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false,
keywordPolicy = KeywordPolicy.SHOW_TYPE_NAME, transformer = SimpleComponentTransformer.class) keywordPolicy = KeywordPolicy.SHOW_TYPE_NAME, transformer = SimpleComponentTransformer.class)
public class Eyelet extends AbstractComponent<String> { public class Eyelet extends AbstractComponent<String> {
@@ -28,6 +28,7 @@ import org.diylc.common.ObjectCache;
import org.diylc.common.SimpleComponentTransformer; import org.diylc.common.SimpleComponentTransformer;
import org.diylc.components.AbstractCurvedComponent; import org.diylc.components.AbstractCurvedComponent;
import org.diylc.core.ComponentState; import org.diylc.core.ComponentState;
import org.diylc.core.IContinuity;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver; import org.diylc.core.IDrawingObserver;
import org.diylc.core.annotations.BomPolicy; import org.diylc.core.annotations.BomPolicy;
@@ -38,8 +39,8 @@ import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Hookup Wire", author = "Branislav Stojkovic", category = "Connectivity", @ComponentDescriptor(name = "Hookup Wire", author = "Branislav Stojkovic", category = "Connectivity",
instanceNamePrefix = "W", description = "Flexible wire with two control points", zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "W", description = "Flexible wire with two control points", zOrder = IDIYComponent.COMPONENT,
flexibleZOrder = true, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false, flexibleZOrder = true, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false,
transformer = SimpleComponentTransformer.class, continuity = true) transformer = SimpleComponentTransformer.class)
public class HookupWire extends AbstractCurvedComponent<Void> { public class HookupWire extends AbstractCurvedComponent<Void> implements IContinuity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -131,5 +132,10 @@ public class HookupWire extends AbstractCurvedComponent<Void> {
public void setStripeColor(Color stripeColor) { public void setStripeColor(Color stripeColor) {
this.stripeColor = stripeColor; this.stripeColor = stripeColor;
}
@Override
public boolean arePointsConnected(int index1, int index2) {
return Math.abs(index1 - index2) == getControlPointCount() - 1;
} }
} }
@@ -32,6 +32,7 @@ import org.diylc.common.SimpleComponentTransformer;
import org.diylc.components.AbstractLeadedComponent; import org.diylc.components.AbstractLeadedComponent;
import org.diylc.core.ComponentState; import org.diylc.core.ComponentState;
import org.diylc.core.CreationMethod; import org.diylc.core.CreationMethod;
import org.diylc.core.IContinuity;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.BomPolicy; import org.diylc.core.annotations.BomPolicy;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
@@ -41,8 +42,8 @@ import org.diylc.core.measures.Size;
@ComponentDescriptor(name = "Jumper", author = "Branislav Stojkovic", category = "Connectivity", @ComponentDescriptor(name = "Jumper", author = "Branislav Stojkovic", category = "Connectivity",
creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "J", description = "", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "J", description = "",
zOrder = IDIYComponent.COMPONENT, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false, zOrder = IDIYComponent.COMPONENT, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false,
transformer = SimpleComponentTransformer.class, continuity = true) transformer = SimpleComponentTransformer.class)
public class Jumper extends AbstractLeadedComponent<Void> { public class Jumper extends AbstractLeadedComponent<Void> implements IContinuity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -156,5 +157,15 @@ public class Jumper extends AbstractLeadedComponent<Void> {
@Override @Override
public Display getDisplay() { public Display getDisplay() {
return super.getDisplay(); return super.getDisplay();
}
@Override
public boolean arePointsConnected(int index1, int index2) {
return true;
}
public boolean getMoveLabel() {
// override to disable edit
return false;
} }
} }
@@ -42,7 +42,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Solder Pad", category = "Connectivity", author = "Branislav Stojkovic", @ComponentDescriptor(name = "Solder Pad", category = "Connectivity", author = "Branislav Stojkovic",
description = "Copper solder pad, round or square", instanceNamePrefix = "Pad", stretchable = false, description = "Copper solder pad, round or square", instanceNamePrefix = "Pad",
zOrder = IDIYComponent.TRACE + 0.1, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false, zOrder = IDIYComponent.TRACE + 0.1, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false,
keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "PCB", transformer = SimpleComponentTransformer.class) keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "PCB", transformer = SimpleComponentTransformer.class)
public class SolderPad extends AbstractComponent<Void> { public class SolderPad extends AbstractComponent<Void> {
@@ -44,7 +44,7 @@ import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Trace Cut", category = "Connectivity", author = "Branislav Stojkovic", @ComponentDescriptor(name = "Trace Cut", category = "Connectivity", author = "Branislav Stojkovic",
description = "Designates the place where a trace on the vero board needs to be cut", instanceNamePrefix = "Cut", description = "Designates the place where a trace on the vero board needs to be cut", instanceNamePrefix = "Cut",
stretchable = false, zOrder = IDIYComponent.BOARD + 1, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false, zOrder = IDIYComponent.BOARD + 1, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false,
transformer = SimpleComponentTransformer.class) transformer = SimpleComponentTransformer.class)
public class TraceCut extends AbstractComponent<Void> { public class TraceCut extends AbstractComponent<Void> {
@@ -42,7 +42,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Turret Lug", category = "Connectivity", author = "Branislav Stojkovic", @ComponentDescriptor(name = "Turret Lug", category = "Connectivity", author = "Branislav Stojkovic",
description = "Turret terminal lug", instanceNamePrefix = "Turret", stretchable = false, description = "Turret terminal lug", instanceNamePrefix = "Turret",
zOrder = IDIYComponent.TRACE + 0.1, bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false, zOrder = IDIYComponent.TRACE + 0.1, bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false,
keywordPolicy = KeywordPolicy.SHOW_TYPE_NAME, transformer = SimpleComponentTransformer.class) keywordPolicy = KeywordPolicy.SHOW_TYPE_NAME, transformer = SimpleComponentTransformer.class)
public class Turret extends AbstractComponent<String> { public class Turret extends AbstractComponent<String> {
@@ -37,6 +37,7 @@ import org.diylc.common.ObjectCache;
import org.diylc.common.SimpleComponentTransformer; import org.diylc.common.SimpleComponentTransformer;
import org.diylc.components.AbstractCurvedComponent; import org.diylc.components.AbstractCurvedComponent;
import org.diylc.core.ComponentState; import org.diylc.core.ComponentState;
import org.diylc.core.IContinuity;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver; import org.diylc.core.IDrawingObserver;
import org.diylc.core.annotations.BomPolicy; import org.diylc.core.annotations.BomPolicy;
@@ -47,8 +48,8 @@ import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Twisted Leads", author = "Branislav Stojkovic", category = "Connectivity", @ComponentDescriptor(name = "Twisted Leads", author = "Branislav Stojkovic", category = "Connectivity",
instanceNamePrefix = "W", description = "A pair of flexible leads twisted tighly together", zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "W", description = "A pair of flexible leads twisted tighly together", zOrder = IDIYComponent.COMPONENT,
flexibleZOrder = true, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false, flexibleZOrder = true, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false,
transformer = SimpleComponentTransformer.class, continuity = true) transformer = SimpleComponentTransformer.class)
public class TwistedWire extends AbstractCurvedComponent<Void> { public class TwistedWire extends AbstractCurvedComponent<Void> implements IContinuity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -432,4 +433,9 @@ public class TwistedWire extends AbstractCurvedComponent<Void> {
return calculateLength(left, precision) + calculateLength(right, precision); return calculateLength(left, precision) + calculateLength(right, precision);
} }
@Override
public boolean arePointsConnected(int index1, int index2) {
return Math.abs(index1 - index2) == getControlPointCount() - 1;
}
} }
@@ -52,7 +52,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "9V Battery Snap", category = "Electro-Mechanical", author = "Branislav Stojkovic", @ComponentDescriptor(name = "9V Battery Snap", category = "Electro-Mechanical", author = "Branislav Stojkovic",
description = "", stretchable = false, zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "BTR", description = "", zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "BTR",
autoEdit = false, transformer = BatterySnapTransformer.class) autoEdit = false, transformer = BatterySnapTransformer.class)
public class BatterySnap9V extends AbstractTransparentComponent<String> { public class BatterySnap9V extends AbstractTransparentComponent<String> {
@@ -34,6 +34,7 @@ import java.awt.geom.Ellipse2D;
import java.awt.geom.RoundRectangle2D; import java.awt.geom.RoundRectangle2D;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.awt.StringUtils;
import org.diylc.common.HorizontalAlignment; import org.diylc.common.HorizontalAlignment;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache; import org.diylc.common.ObjectCache;
@@ -54,7 +55,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Cliff 1/4\" Jack", category = "Electro-Mechanical", author = "Branislav Stojkovic", @ComponentDescriptor(name = "Cliff 1/4\" Jack", category = "Electro-Mechanical", author = "Branislav Stojkovic",
description = "Cliff-style closed panel mount 1/4\" phono jack", stretchable = false, description = "Cliff-style closed panel mount 1/4\" phono jack",
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "J", autoEdit = false, transformer = CliffJackTransformer.class) zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "J", autoEdit = false, transformer = CliffJackTransformer.class)
public class CliffJack1_4 extends AbstractMultiPartComponent<String> { public class CliffJack1_4 extends AbstractMultiPartComponent<String> {
@@ -246,7 +247,7 @@ public class CliffJack1_4 extends AbstractMultiPartComponent<String> {
g2d.setFont(project.getFont()); g2d.setFont(project.getFont());
int centerX = (controlPoints[0].x + controlPoints[3].x) / 2; int centerX = (controlPoints[0].x + controlPoints[3].x) / 2;
int centerY = (controlPoints[0].y + controlPoints[3].y) / 2; int centerY = (controlPoints[0].y + controlPoints[3].y) / 2;
drawCenteredText(g2d, name, centerX, centerY, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); StringUtils.drawCenteredText(g2d, name, centerX, centerY, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
drawSelectionOutline(g2d, componentState, outlineMode, project, drawingObserver); drawSelectionOutline(g2d, componentState, outlineMode, project, drawingObserver);
} }
@@ -337,5 +338,10 @@ public class CliffJack1_4 extends AbstractMultiPartComponent<String> {
public void setOrientation(Orientation orientation) { public void setOrientation(Orientation orientation) {
this.orientation = orientation; this.orientation = orientation;
updateControlPoints(); updateControlPoints();
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
} }
} }
@@ -34,6 +34,7 @@ import java.awt.geom.Ellipse2D;
import java.awt.geom.GeneralPath; import java.awt.geom.GeneralPath;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.awt.StringUtils;
import org.diylc.common.HorizontalAlignment; import org.diylc.common.HorizontalAlignment;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache; import org.diylc.common.ObjectCache;
@@ -54,7 +55,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Closed 1/4\" Jack", category = "Electro-Mechanical", author = "Branislav Stojkovic", @ComponentDescriptor(name = "Closed 1/4\" Jack", category = "Electro-Mechanical", author = "Branislav Stojkovic",
description = "Enclosed panel mount 1/4\" phono jack", stretchable = false, zOrder = IDIYComponent.COMPONENT, description = "Enclosed panel mount 1/4\" phono jack", zOrder = IDIYComponent.COMPONENT,
instanceNamePrefix = "J", autoEdit = false, transformer = ClosedJackTransformer.class) instanceNamePrefix = "J", autoEdit = false, transformer = ClosedJackTransformer.class)
public class ClosedJack1_4 extends AbstractMultiPartComponent<String> { public class ClosedJack1_4 extends AbstractMultiPartComponent<String> {
@@ -269,7 +270,7 @@ public class ClosedJack1_4 extends AbstractMultiPartComponent<String> {
Rectangle bounds = body[0].getBounds(); Rectangle bounds = body[0].getBounds();
int centerX = bounds.x + bounds.width / 2; int centerX = bounds.x + bounds.width / 2;
int centerY = bounds.y + bounds.height / 2; int centerY = bounds.y + bounds.height / 2;
drawCenteredText(g2d, name, centerX, centerY, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); StringUtils.drawCenteredText(g2d, name, centerX, centerY, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
drawSelectionOutline(g2d, componentState, outlineMode, project, drawingObserver); drawSelectionOutline(g2d, componentState, outlineMode, project, drawingObserver);
} }
@@ -363,5 +364,10 @@ public class ClosedJack1_4 extends AbstractMultiPartComponent<String> {
return "Ring"; return "Ring";
} }
return null; return null;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
} }
} }
@@ -43,6 +43,7 @@ import org.diylc.components.transform.DIL_ICTransformer;
import org.diylc.core.ComponentState; import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver; import org.diylc.core.IDrawingObserver;
import org.diylc.core.ISwitch;
import org.diylc.core.Project; import org.diylc.core.Project;
import org.diylc.core.Theme; import org.diylc.core.Theme;
import org.diylc.core.VisibilityPolicy; import org.diylc.core.VisibilityPolicy;
@@ -55,9 +56,9 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "DIP Switch", author = "Branislav Stojkovic", category = "Electro-Mechanical", @ComponentDescriptor(name = "DIP Switch", author = "Branislav Stojkovic", category = "Electro-Mechanical",
instanceNamePrefix = "SW", description = "Dual-in-line package switch", stretchable = false, instanceNamePrefix = "SW", description = "Dual-in-line package switch",
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = DIL_ICTransformer.class) zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = DIL_ICTransformer.class)
public class DIPSwitch extends AbstractTransparentComponent<String> { public class DIPSwitch extends AbstractTransparentComponent<String> implements ISwitch {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -312,7 +313,8 @@ public class DIPSwitch extends AbstractTransparentComponent<String> {
IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) { if (checkPointsClipped(g2d.getClip())) {
return; return;
} }
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
Area mainArea = getBody()[0]; Area mainArea = getBody()[0];
if (!outlineMode) { if (!outlineMode) {
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2; int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
@@ -512,5 +514,44 @@ public class DIPSwitch extends AbstractTransparentComponent<String> {
public int getValue() { public int getValue() {
return Integer.parseInt(toString()); return Integer.parseInt(toString());
} }
}
@Override
public int getPositionCount() {
return (int) Math.pow(2, getSwitchCount().getValue());
}
@Override
public String getPositionName(int position) {
String binary = toBinary(position);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < getSwitchCount().getValue(); i++) {
if (sb.length() > 0)
sb.append("-");
sb.append(binary.charAt(i) == '0' ? "OFF" : "ON");
}
return sb.toString();
}
@Override
public boolean arePointsConnected(int index1, int index2, int position) {
String binary = toBinary(position);
return Math.abs(index1 - index2) == getSwitchCount().getValue() && binary.charAt(index1 < index2 ? index1 : index2) == '1';
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
}
private String toBinary(int n) {
StringBuilder builder = new StringBuilder();
do {
builder.append(n % 2);
n = n / 2;
} while (n > 0);
while (builder.length() < getSwitchCount().getValue())
builder.append("0");
return builder.toString();
} }
} }
@@ -52,7 +52,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Fuse Holder (Panel)", category = "Electro-Mechanical", author = "Branislav Stojkovic", @ComponentDescriptor(name = "Fuse Holder (Panel)", category = "Electro-Mechanical", author = "Branislav Stojkovic",
description = "Panel mounted fuse holder", stretchable = false, zOrder = IDIYComponent.COMPONENT, description = "Panel mounted fuse holder", zOrder = IDIYComponent.COMPONENT,
instanceNamePrefix = "FH", autoEdit = false) instanceNamePrefix = "FH", autoEdit = false)
public class FuseHolderPanel extends AbstractMultiPartComponent<String> { public class FuseHolderPanel extends AbstractMultiPartComponent<String> {
@@ -69,7 +69,7 @@ public class FuseHolderPanel extends AbstractMultiPartComponent<String> {
private static Color BORDER_COLOR = BODY_COLOR.darker(); private static Color BORDER_COLOR = BODY_COLOR.darker();
private static Color LABEL_COLOR = Color.white; private static Color LABEL_COLOR = Color.white;
protected Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0)}; protected Point[] controlPoints = new Point[] { new Point(0, 0), new Point(0, 0) };
transient protected Area[] body; transient protected Area[] body;
protected String name; protected String name;
protected String value = ""; protected String value = "";
@@ -330,5 +330,10 @@ public class FuseHolderPanel extends AbstractMultiPartComponent<String> {
public void setLabelColor(Color labelColor) { public void setLabelColor(Color labelColor) {
this.labelColor = labelColor; this.labelColor = labelColor;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
} }
} }
@@ -50,7 +50,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "IEC Socket", category = "Electro-Mechanical", author = "Branislav Stojkovic", @ComponentDescriptor(name = "IEC Socket", category = "Electro-Mechanical", author = "Branislav Stojkovic",
description = "Panel mounted IEC power socket", stretchable = false, zOrder = IDIYComponent.COMPONENT, description = "Panel mounted IEC power socket", zOrder = IDIYComponent.COMPONENT,
instanceNamePrefix = "IEC", autoEdit = false) instanceNamePrefix = "IEC", autoEdit = false)
public class IECSocket extends AbstractMultiPartComponent<String> { public class IECSocket extends AbstractMultiPartComponent<String> {
@@ -384,5 +384,10 @@ public class IECSocket extends AbstractMultiPartComponent<String> {
public void setBorderColor(Color borderColor) { public void setBorderColor(Color borderColor) {
this.borderColor = borderColor; this.borderColor = borderColor;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
} }
} }
@@ -54,7 +54,7 @@ import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Mini Relay", author = "Branislav Stojkovic", category = "Electro-Mechanical", @ComponentDescriptor(name = "Mini Relay", author = "Branislav Stojkovic", category = "Electro-Mechanical",
instanceNamePrefix = "RY", description = "Miniature PCB mount relay, like Omron G5V-1 or G5V-2", instanceNamePrefix = "RY", description = "Miniature PCB mount relay, like Omron G5V-1 or G5V-2",
stretchable = false, zOrder = IDIYComponent.COMPONENT) zOrder = IDIYComponent.COMPONENT)
public class MiniRelay extends AbstractTransparentComponent<String> { public class MiniRelay extends AbstractTransparentComponent<String> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -302,7 +302,9 @@ public class MiniRelay extends AbstractTransparentComponent<String> {
} }
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : BODY_COLOR); g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : BODY_COLOR);
g2d.fill(mainArea); g2d.fill(mainArea);
g2d.setComposite(oldComposite); g2d.setComposite(oldComposite);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2; int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
@@ -423,6 +425,11 @@ public class MiniRelay extends AbstractTransparentComponent<String> {
updateControlPoints(); updateControlPoints();
// Invalidate body // Invalidate body
this.body = null; this.body = null;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
} }
public static enum RelayType { public static enum RelayType {
@@ -51,7 +51,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Mini Toggle Switch", category = "Electro-Mechanical", author = "Branislav Stojkovic", @ComponentDescriptor(name = "Mini Toggle Switch", category = "Electro-Mechanical", author = "Branislav Stojkovic",
description = "Panel mounted mini toggle switch", stretchable = false, zOrder = IDIYComponent.COMPONENT, description = "Panel mounted mini toggle switch", zOrder = IDIYComponent.COMPONENT,
instanceNamePrefix = "SW", autoEdit = false) instanceNamePrefix = "SW", autoEdit = false)
public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchType> implements ISwitch { public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchType> implements ISwitch {
@@ -393,11 +393,16 @@ public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchT
} }
// switch stuff // switch stuff
//
// @Override
// public String getControlPointNodeName(int index) {
// // we don't want the switch to produce any nodes, it just makes connections
// return null;
// }
@Override @Override
public String getControlPointNodeName(int index) { public boolean canPointMoveFreely(int pointIndex) {
// we don't want the switch to produce any nodes, it just makes connections return false;
return null;
} }
@Override @Override
@@ -33,6 +33,7 @@ import java.awt.geom.Ellipse2D;
import java.awt.geom.RoundRectangle2D; import java.awt.geom.RoundRectangle2D;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.awt.StringUtils;
import org.diylc.common.HorizontalAlignment; import org.diylc.common.HorizontalAlignment;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache; import org.diylc.common.ObjectCache;
@@ -52,7 +53,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Open 1/4\" Jack", category = "Electro-Mechanical", author = "Branislav Stojkovic", @ComponentDescriptor(name = "Open 1/4\" Jack", category = "Electro-Mechanical", author = "Branislav Stojkovic",
description = "Switchcraft-style open panel mount 1/4\" phono jack, stereo and mono", stretchable = false, description = "Switchcraft-style open panel mount 1/4\" phono jack, stereo and mono",
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "J") zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "J")
public class OpenJack1_4 extends AbstractMultiPartComponent<String> { public class OpenJack1_4 extends AbstractMultiPartComponent<String> {
@@ -170,12 +171,12 @@ public class OpenJack1_4 extends AbstractMultiPartComponent<String> {
rotation.transform(ringOrSwitchLabel, ringOrSwitchLabel); rotation.transform(ringOrSwitchLabel, ringOrSwitchLabel);
rotation.transform(sleeveLabel, sleeveLabel); rotation.transform(sleeveLabel, sleeveLabel);
} }
drawCenteredText(g2d, "T", tipLabel.x, tipLabel.y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); StringUtils.drawCenteredText(g2d, "T", tipLabel.x, tipLabel.y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
drawCenteredText(g2d, "S", sleeveLabel.x, sleeveLabel.y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); StringUtils.drawCenteredText(g2d, "S", sleeveLabel.x, sleeveLabel.y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
if (getType() == OpenJackType.STEREO) if (getType() == OpenJackType.STEREO)
drawCenteredText(g2d, "R", ringOrSwitchLabel.x, ringOrSwitchLabel.y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); StringUtils.drawCenteredText(g2d, "R", ringOrSwitchLabel.x, ringOrSwitchLabel.y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
if (getType() == OpenJackType.SWITCHED) if (getType() == OpenJackType.SWITCHED)
drawCenteredText(g2d, "Sw", ringOrSwitchLabel.x, ringOrSwitchLabel.y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); StringUtils.drawCenteredText(g2d, "Sw", ringOrSwitchLabel.x, ringOrSwitchLabel.y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
} }
drawSelectionOutline(g2d, componentState, outlineMode, project, drawingObserver); drawSelectionOutline(g2d, componentState, outlineMode, project, drawingObserver);
@@ -346,7 +347,7 @@ public class OpenJack1_4 extends AbstractMultiPartComponent<String> {
@EditableProperty @EditableProperty
public Integer getAngle() { public Integer getAngle() {
if (angle == null) { if (angle == null) {
if (orientation != null) if (orientation != null && orientation != Orientation.DEFAULT)
angle = Integer.parseInt(orientation.name().replace("_", "")); angle = Integer.parseInt(orientation.name().replace("_", ""));
else else
angle = 0; angle = 0;
@@ -399,6 +400,11 @@ public class OpenJack1_4 extends AbstractMultiPartComponent<String> {
return null; return null;
} }
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
}
public enum OpenJackType { public enum OpenJackType {
MONO, STEREO, SWITCHED; MONO, STEREO, SWITCHED;
@@ -52,7 +52,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Pilot Lamp Holder", category = "Electro-Mechanical", author = "Branislav Stojkovic", @ComponentDescriptor(name = "Pilot Lamp Holder", category = "Electro-Mechanical", author = "Branislav Stojkovic",
description = "Fender-style pilot bulb holder for T2 and T-3 ¼ miniature bayonet lamps", stretchable = false, description = "Fender-style pilot bulb holder for T2 and T-3 ¼ miniature bayonet lamps",
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "PL") zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "PL")
public class PilotLampHolder extends AbstractMultiPartComponent<String> { public class PilotLampHolder extends AbstractMultiPartComponent<String> {
@@ -389,7 +389,7 @@ public class PilotLampHolder extends AbstractMultiPartComponent<String> {
@EditableProperty @EditableProperty
public Integer getAngle() { public Integer getAngle() {
if (angle == null) { if (angle == null) {
if (orientation != null) if (orientation != null && orientation != Orientation.DEFAULT)
angle = Integer.parseInt(orientation.name().replace("_", "")); angle = Integer.parseInt(orientation.name().replace("_", ""));
else else
angle = 0; angle = 0;
@@ -404,6 +404,11 @@ public class PilotLampHolder extends AbstractMultiPartComponent<String> {
body = null; body = null;
} }
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
}
protected double getTheta() { protected double getTheta() {
return Math.toRadians(getAngle()); return Math.toRadians(getAngle());
} }
@@ -32,6 +32,7 @@ import java.awt.geom.Area;
import java.awt.geom.Ellipse2D; import java.awt.geom.Ellipse2D;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.awt.StringUtils;
import org.diylc.common.HorizontalAlignment; import org.diylc.common.HorizontalAlignment;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache; import org.diylc.common.ObjectCache;
@@ -50,7 +51,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Plastic DC Jack", category = "Electro-Mechanical", author = "Branislav Stojkovic", @ComponentDescriptor(name = "Plastic DC Jack", category = "Electro-Mechanical", author = "Branislav Stojkovic",
description = "Panel mount plastic DC jack", stretchable = false, zOrder = IDIYComponent.COMPONENT, description = "Panel mount plastic DC jack", zOrder = IDIYComponent.COMPONENT,
instanceNamePrefix = "J", autoEdit = false) instanceNamePrefix = "J", autoEdit = false)
public class PlasticDCJack extends AbstractMultiPartComponent<String> { public class PlasticDCJack extends AbstractMultiPartComponent<String> {
@@ -182,9 +183,9 @@ public class PlasticDCJack extends AbstractMultiPartComponent<String> {
int spacing = (int) SPACING.convertToPixels(); int spacing = (int) SPACING.convertToPixels();
g2d.setColor(MARKING_COLOR); g2d.setColor(MARKING_COLOR);
g2d.setFont(project.getFont().deriveFont(12f)); g2d.setFont(project.getFont().deriveFont(12f));
drawCenteredText(g2d, getPolarity() == DCPolarity.CENTER_NEGATIVE ? "+" : "-", controlPoints[0].x, StringUtils.drawCenteredText(g2d, getPolarity() == DCPolarity.CENTER_NEGATIVE ? "+" : "-", controlPoints[0].x,
controlPoints[0].y - spacing * 7 / 16, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); controlPoints[0].y - spacing * 7 / 16, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
drawCenteredText(g2d, getPolarity() == DCPolarity.CENTER_NEGATIVE ? "_" : "+", controlPoints[2].x, StringUtils.drawCenteredText(g2d, getPolarity() == DCPolarity.CENTER_NEGATIVE ? "_" : "+", controlPoints[2].x,
controlPoints[2].y - spacing * 3 / 4, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); controlPoints[2].y - spacing * 3 / 4, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
} }
@@ -261,5 +262,10 @@ public class PlasticDCJack extends AbstractMultiPartComponent<String> {
public void setPolarity(DCPolarity polarity) { public void setPolarity(DCPolarity polarity) {
this.polarity = polarity; this.polarity = polarity;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
} }
} }
@@ -52,8 +52,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "RCA Jack", category = "Electro-Mechanical", author = "Branislav Stojkovic", @ComponentDescriptor(name = "RCA Jack", category = "Electro-Mechanical", author = "Branislav Stojkovic",
description = "Panel mount RCA phono jack socket", stretchable = false, description = "Panel mount RCA phono jack socket", zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "J")
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "J")
public class RCAJack extends AbstractMultiPartComponent<String> { public class RCAJack extends AbstractMultiPartComponent<String> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -319,5 +318,10 @@ public class RCAJack extends AbstractMultiPartComponent<String> {
@Override @Override
public String getControlPointNodeName(int index) { public String getControlPointNodeName(int index) {
return getName() + (index == 0 ? "Tip" : "Sleeve"); return getName() + (index == 0 ? "Tip" : "Sleeve");
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
} }
} }
@@ -1,473 +0,0 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
//package org.diylc.components.electromechanical;
//
//import java.awt.AlphaComposite;
//import java.awt.Color;
//import java.awt.Composite;
//import java.awt.FontMetrics;
//import java.awt.Graphics2D;
//import java.awt.Point;
//import java.awt.Rectangle;
//import java.awt.geom.Area;
//import java.awt.geom.Rectangle2D;
//import java.awt.geom.RoundRectangle2D;
//
//import org.diylc.appframework.miscutils.ConfigurationManager;
//import org.diylc.common.Display;
//import org.diylc.common.IPlugInPort;
//import org.diylc.common.ObjectCache;
//import org.diylc.common.Orientation;
//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 = "Subminiature DIL Relay", author = "Branislav Stojkovic", category = "Electromechanical",
// instanceNamePrefix = "RY", description = "Subminiature DIL relay with one or two poles", stretchable = false,
// zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE)
//public class SubminiatureDILRelay extends AbstractTransparentComponent<String> {
//
// private static final long serialVersionUID = 1L;
//
// public static Color BODY_COLOR = Color.decode("#EDEDD5");
// public static Color BORDER_COLOR = BODY_COLOR.darker();
// public static Color PIN_COLOR = Color.decode("#00B2EE");
// public static Color PIN_BORDER_COLOR = PIN_COLOR.darker();
// public static Color INDENT_COLOR = Color.gray.darker();
// public static Color LABEL_COLOR = Color.darkGray;
// public static int EDGE_RADIUS = 6;
// public static Size PIN_SIZE = new Size(0.04d, SizeUnit.in);
// public static Size INDENT_SIZE = new Size(0.05d, SizeUnit.in);
//
// public static Size PIN_SPACING = new Size(0.2d, SizeUnit.in);
// public static Size ROW_SPACING = new Size(0.3d, SizeUnit.in);
// public static Size SECTION_SPACING = new Size(0.3d, SizeUnit.in);
//
// private String value = "";
// private Orientation orientation = Orientation.DEFAULT;
// private PinCount pinCount = PinCount._4;
// private Size pinSpacing = PIN_SPACING;
// private Size rowSpacing = ROW_SPACING;
// private Size sectionSpacing = SECTION_SPACING;
// private Point[] controlPoints = new Point[] {new Point(0, 0)};
// protected Display display = Display.NAME;
// private Color bodyColor = BODY_COLOR;
// private Color borderColor = BORDER_COLOR;
// private Color labelColor = LABEL_COLOR;
// private Color indentColor = INDENT_COLOR;
// transient private Area[] body;
//
// public SubminiatureDILRelay() {
// super();
// updateControlPoints();
// }
//
// @EditableProperty
// public String getValue() {
// return value;
// }
//
// public void setValue(String value) {
// this.value = value;
// }
//
// @EditableProperty
// public Orientation getOrientation() {
// return orientation;
// }
//
// public void setOrientation(Orientation orientation) {
// this.orientation = orientation;
// updateControlPoints();
// // Reset body shape.
// body = null;
// }
//
// @EditableProperty(name = "Contacts")
// public PinCount getPinCount() {
// return pinCount;
// }
//
// public void setPinCount(PinCount pinCount) {
// this.pinCount = pinCount;
// updateControlPoints();
// // Reset body shape;
// body = null;
// }
//
// @EditableProperty(name = "Pin spacing")
// public Size getPinSpacing() {
// return pinSpacing;
// }
//
// public void setPinSpacing(Size pinSpacing) {
// this.pinSpacing = pinSpacing;
// updateControlPoints();
// // Reset body shape;
// body = null;
// }
//
// @EditableProperty(name = "Row spacing")
// public Size getRowSpacing() {
// return rowSpacing;
// }
//
// public void setRowSpacing(Size rowSpacing) {
// this.rowSpacing = rowSpacing;
// updateControlPoints();
// // Reset body shape;
// body = null;
// }
//
// @EditableProperty(name = "Section spacing")
// public Size getSectionSpacing() {
// return sectionSpacing;
// }
//
// public void setSectionSpacing(Size sectionSpacing) {
// this.sectionSpacing = sectionSpacing;
// updateControlPoints();
// // Reset body shape;
// body = null;
// }
//
// @EditableProperty
// public Display getDisplay() {
// if (display == null) {
// display = Display.VALUE;
// }
// return display;
// }
//
// public void setDisplay(Display display) {
// this.display = display;
// }
//
// @Override
// public int getControlPointCount() {
// return controlPoints.length;
// }
//
// @Override
// public Point getControlPoint(int index) {
// return controlPoints[index];
// }
//
// @Override
// public boolean isControlPointSticky(int index) {
// return true;
// }
//
// @Override
// public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
// return VisibilityPolicy.NEVER;
// }
//
// @Override
// public void setControlPoint(Point point, int index) {
// controlPoints[index].setLocation(point);
// body = null;
// }
//
// private void updateControlPoints() {
// Point firstPoint = controlPoints[0];
// controlPoints = new Point[pinCount.getValue() * 2];
// controlPoints[0] = firstPoint;
// int pinSpacing = (int) this.pinSpacing.convertToPixels();
// int sectionSpacing = (int) this.sectionSpacing.convertToPixels();
// int rowSpacing = (int) this.rowSpacing.convertToPixels();
// // Update control points.
// int dx1;
// int dy1;
// int dx2;
// int dy2;
// for (int i = 0; i < pinCount.getValue(); i++) {
// int spacing = i == pinCount.getValue() - 1 ? sectionSpacing + (i - 1) * pinSpacing : i * pinSpacing;
// switch (orientation) {
// case DEFAULT:
// dx1 = 0;
// dy1 = spacing;
// dx2 = rowSpacing;
// dy2 = spacing;
// break;
// case _90:
// dx1 = -spacing;
// dy1 = 0;
// dx2 = -spacing;
// dy2 = rowSpacing;
// break;
// case _180:
// dx1 = 0;
// dy1 = -spacing;
// dx2 = -rowSpacing;
// dy2 = -spacing;
// break;
// case _270:
// dx1 = spacing;
// dy1 = 0;
// dx2 = spacing;
// dy2 = -rowSpacing;
// break;
// default:
// throw new RuntimeException("Unexpected orientation: " + orientation);
// }
// controlPoints[i] = new Point(firstPoint.x + dx1, firstPoint.y + dy1);
// controlPoints[i + pinCount.getValue()] = new Point(firstPoint.x + dx2, firstPoint.y + dy2);
// }
// }
//
// public Area[] getBody() {
// if (body == null) {
// body = new Area[2];
//
// int pinSize = (int) PIN_SIZE.convertToPixels();
//
// int minX = Integer.MAX_VALUE;
// int maxX = Integer.MIN_VALUE;
// int minY = Integer.MAX_VALUE;
// int maxY = Integer.MIN_VALUE;
// for (int i = 0; i < this.controlPoints.length; i++) {
// if (this.controlPoints[i].x > maxX)
// maxX = this.controlPoints[i].x;
// if (this.controlPoints[i].x < minX)
// minX = this.controlPoints[i].x;
// if (this.controlPoints[i].y > maxY)
// maxY = this.controlPoints[i].y;
// if (this.controlPoints[i].y < minY)
// minY = this.controlPoints[i].y;
// }
// int width = maxX - minX;
// int height = maxY - minY;
//
// Area indentation = null;
// int indentationSize = getClosestOdd(INDENT_SIZE.convertToPixels());
// switch (orientation) {
// case DEFAULT:
// indentation =
// new Area(new Rectangle2D.Double(minX + width / 2 - indentationSize / 2, minY - indentationSize / 2
// - pinSize, indentationSize, indentationSize));
// break;
// case _90:
// indentation =
// new Area(new Rectangle2D.Double(minX + width - indentationSize / 2 + pinSize, minY + height / 2
// - indentationSize / 2, indentationSize, indentationSize));
// break;
// case _180:
// indentation =
// new Area(new Rectangle2D.Double(minX + width / 2 - indentationSize / 2, minY + height - indentationSize
// / 2 + pinSize, indentationSize, indentationSize));
// break;
// case _270:
// indentation =
// new Area(new Rectangle2D.Double(minX - indentationSize / 2 - pinSize, minY + height / 2 - indentationSize
// / 2, indentationSize, indentationSize));
// break;
// default:
// throw new RuntimeException("Unexpected orientation: " + orientation);
// }
//
// body[0] =
// new Area(new RoundRectangle2D.Double(minX - pinSize, minY - pinSize, width + 2 * pinSize, height + 2
// * pinSize, EDGE_RADIUS, EDGE_RADIUS));
// body[1] = indentation;
// if (indentation != null) {
// indentation.intersect(body[0]);
// }
// }
// return body;
// }
//
// @Override
// public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
// IDrawingObserver drawingObserver) {
// if (checkPointsClipped(g2d.getClip())) {
// return;
// }
// Area mainArea = getBody()[0];
//
// 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 : getBodyColor());
// g2d.fill(mainArea);
// 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
// : getBorderColor();
// }
// g2d.setColor(finalBorderColor);
// g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
// if (outlineMode) {
// Area area = new Area(mainArea);
// area.subtract(getBody()[1]);
// g2d.draw(area);
// } else {
// g2d.draw(mainArea);
// if (getBody()[1] != null) {
// g2d.setColor(getIndentColor());
// g2d.fill(getBody()[1]);
// }
// }
//
// if (!outlineMode) {
// int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
// for (Point point : controlPoints) {
// g2d.setColor(PIN_COLOR);
// g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
// g2d.setColor(PIN_BORDER_COLOR);
// g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
// }
// }
//
// // Draw label.
// g2d.setFont(LABEL_FONT);
// 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
// : getLabelColor();
// }
// g2d.setColor(finalLabelColor);
// FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
// String label = "";
// label = (getDisplay() == Display.NAME) ? getName() : getValue();
// if (getDisplay() == Display.NONE) {
// label = "";
// }
// if (getDisplay() == Display.BOTH) {
// label = getName() + " " + (getValue() == null ? "" : getValue().toString());
// }
// Rectangle2D rect = fontMetrics.getStringBounds(label, g2d);
// int textHeight = (int) (rect.getHeight());
// int textWidth = (int) (rect.getWidth());
// // Center text horizontally and vertically
// Rectangle bounds = mainArea.getBounds();
// int x = bounds.x + (bounds.width - textWidth) / 2;
// int y = bounds.y + (bounds.height - textHeight) / 2 + fontMetrics.getAscent();
// g2d.drawString(label, x, y);
// }
//
// @Override
// public void drawIcon(Graphics2D g2d, int width, int height) {
// int radius = 6 * width / 32;
// g2d.setColor(BODY_COLOR);
// g2d.fillRoundRect(width / 6, 1, 4 * width / 6, height - 4, radius, radius);
// g2d.setColor(BORDER_COLOR);
// g2d.drawRoundRect(width / 6, 1, 4 * width / 6, height - 4, radius, radius);
// int pinSize = 2 * width / 32;
// g2d.setColor(PIN_COLOR);
// for (int i = 0; i < 4; i++) {
// if (i == 1)
// continue;
// g2d.fillOval(width / 3 - pinSize, (height / 5) * (i + 1) - 1, pinSize, pinSize);
// g2d.fillOval(2 * width / 3 + 1, (height / 5) * (i + 1) - 1, pinSize, pinSize);
// }
// }
//
// @EditableProperty(name = "Body")
// public Color getBodyColor() {
// if (bodyColor == null) {
// bodyColor = BODY_COLOR;
// }
// return bodyColor;
// }
//
// public void setBodyColor(Color bodyColor) {
// this.bodyColor = bodyColor;
// }
//
// @EditableProperty(name = "Border")
// public Color getBorderColor() {
// if (borderColor == null) {
// borderColor = BORDER_COLOR;
// }
// return borderColor;
// }
//
// public void setBorderColor(Color borderColor) {
// this.borderColor = borderColor;
// }
//
// @EditableProperty(name = "Label")
// public Color getLabelColor() {
// if (labelColor == null) {
// labelColor = LABEL_COLOR;
// }
// return labelColor;
// }
//
// public void setLabelColor(Color labelColor) {
// this.labelColor = labelColor;
// }
//
// @EditableProperty(name = "Indent")
// public Color getIndentColor() {
// if (indentColor == null) {
// indentColor = INDENT_COLOR;
// }
// return indentColor;
// }
//
// public void setIndentColor(Color indentColor) {
// this.indentColor = indentColor;
// }
//
// public static enum PinCount {
//
// _3, _4, _5;
//
// @Override
// public String toString() {
// return name().replace("_", "").concat(" per side");
// }
//
// public int getValue() {
// return Integer.parseInt(name().replace("_", ""));
// }
// }
//}
@@ -26,6 +26,7 @@ import java.awt.Shape;
import java.awt.geom.AffineTransform; import java.awt.geom.AffineTransform;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.awt.StringUtils;
import org.diylc.common.HorizontalAlignment; import org.diylc.common.HorizontalAlignment;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
import org.diylc.common.Orientation; import org.diylc.common.Orientation;
@@ -90,8 +91,8 @@ public abstract class AbstractGuitarPickup extends AbstractTransparentComponent<
break; break;
} }
drawCenteredText(g2d, "N", (points[0].x + points[1].x) / 2 + dx, (points[0].y + points[1].y) / 2 + dy, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); StringUtils.drawCenteredText(g2d, "N", (points[0].x + points[1].x) / 2 + dx, (points[0].y + points[1].y) / 2 + dy, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
drawCenteredText(g2d, "S", (points[2].x + points[3].x) / 2 + dx, (points[2].y + points[3].y) / 2 + dy, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); StringUtils.drawCenteredText(g2d, "S", (points[2].x + points[3].x) / 2 + dx, (points[2].y + points[3].y) / 2 + dy, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
} }
protected void drawMainLabel(Graphics2D g2d, Project project, boolean outlineMode, ComponentState componentState) { protected void drawMainLabel(Graphics2D g2d, Project project, boolean outlineMode, ComponentState componentState) {
@@ -120,7 +121,7 @@ public abstract class AbstractGuitarPickup extends AbstractTransparentComponent<
} }
g2d.translate(0, getMainLabelYOffset()); g2d.translate(0, getMainLabelYOffset());
drawCenteredText(g2d, getName(), 0, 0, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); StringUtils.drawCenteredText(g2d, getName(), 0, 0, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
g2d.setTransform(originalTx); g2d.setTransform(originalTx);
} }
@@ -189,6 +190,11 @@ public abstract class AbstractGuitarPickup extends AbstractTransparentComponent<
body = null; body = null;
} }
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
}
@EditableProperty @EditableProperty
public Polarity getPolarity() { public Polarity getPolarity() {
if (polarity == null) if (polarity == null)
@@ -21,6 +21,7 @@ import java.awt.Color;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Point; import java.awt.Point;
import org.diylc.awt.StringUtils;
import org.diylc.common.HorizontalAlignment; import org.diylc.common.HorizontalAlignment;
import org.diylc.common.OrientationHV; import org.diylc.common.OrientationHV;
import org.diylc.common.VerticalAlignment; import org.diylc.common.VerticalAlignment;
@@ -60,11 +61,11 @@ public abstract class AbstractSingleOrHumbuckerPickup extends AbstractGuitarPick
} }
if (getPolarity() == Polarity.North || getPolarity() == Polarity.South) { if (getPolarity() == Polarity.North || getPolarity() == Polarity.South) {
drawCenteredText(g2d, getPolarity().name().substring(0, 1), (points[1].x + points[2].x) / 2 + dx, (points[1].y + points[2].y) / 2 + dy, HorizontalAlignment.CENTER, StringUtils.drawCenteredText(g2d, getPolarity().name().substring(0, 1), (points[1].x + points[2].x) / 2 + dx, (points[1].y + points[2].y) / 2 + dy, HorizontalAlignment.CENTER,
VerticalAlignment.CENTER); VerticalAlignment.CENTER);
} else { } else {
drawCenteredText(g2d, "N", (points[0].x + points[1].x) / 2 + dx, (points[0].y + points[1].y) / 2 + dy, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); StringUtils.drawCenteredText(g2d, "N", (points[0].x + points[1].x) / 2 + dx, (points[0].y + points[1].y) / 2 + dy, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
drawCenteredText(g2d, "S", (points[2].x + points[3].x) / 2 + dx, (points[2].y + points[3].y) / 2 + dy, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); StringUtils.drawCenteredText(g2d, "S", (points[2].x + points[3].x) / 2 + dx, (points[2].y + points[3].y) / 2 + dy, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
} }
} }
@@ -49,7 +49,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Humbucker Pickup", category = "Guitar", author = "Branislav Stojkovic", @ComponentDescriptor(name = "Humbucker Pickup", category = "Guitar", author = "Branislav Stojkovic",
description = "Double-coil humbucker guitar pickup (PAF, Mini Humbuckers, Filtertrons)", stretchable = false, description = "Double-coil humbucker guitar pickup (PAF, Mini Humbuckers, Filtertrons)",
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "PKP", autoEdit = false, zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "PKP", autoEdit = false,
keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "Guitar Wiring Diagram") keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "Guitar Wiring Diagram")
public class HumbuckerPickup extends AbstractGuitarPickup { public class HumbuckerPickup extends AbstractGuitarPickup {
@@ -50,7 +50,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Jazz Bass Pickup", category = "Guitar", author = "Branislav Stojkovic", @ComponentDescriptor(name = "Jazz Bass Pickup", category = "Guitar", author = "Branislav Stojkovic",
description = "Single coil pickup for Jazz Bass and similar guitars", stretchable = false, description = "Single coil pickup for Jazz Bass and similar guitars",
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "PKP", autoEdit = false, zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "PKP", autoEdit = false,
keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "Guitar Wiring Diagram") keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "Guitar Wiring Diagram")
public class JazzBassPickup extends AbstractSingleOrHumbuckerPickup { public class JazzBassPickup extends AbstractSingleOrHumbuckerPickup {
@@ -51,7 +51,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "LP Toggle Switch", category = "Guitar", author = "Branislav Stojkovic", @ComponentDescriptor(name = "LP Toggle Switch", category = "Guitar", author = "Branislav Stojkovic",
description = "Les Paul style 3 position toggle switch", stretchable = false, zOrder = IDIYComponent.COMPONENT, description = "Les Paul style 3 position toggle switch", zOrder = IDIYComponent.COMPONENT,
instanceNamePrefix = "SW") instanceNamePrefix = "SW")
public class LPSwitch extends AbstractTransparentComponent<String> implements ISwitch { public class LPSwitch extends AbstractTransparentComponent<String> implements ISwitch {
@@ -299,6 +299,11 @@ public class LPSwitch extends AbstractTransparentComponent<String> implements IS
this.controlPoints[index].setLocation(point); this.controlPoints[index].setLocation(point);
// Invalidate the body // Invalidate the body
body = null; body = null;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
} }
@Override @Override
@@ -323,12 +328,12 @@ public class LPSwitch extends AbstractTransparentComponent<String> implements IS
body = null; body = null;
} }
@Override // @Override
public String getControlPointNodeName(int index) { // public String getControlPointNodeName(int index) {
// we don't want the switch to produce any nodes, it just makes connections // // we don't want the switch to produce any nodes, it just makes connections
return null; // return null;
} // }
//
// switch stuff // switch stuff
@Override @Override
@@ -53,7 +53,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Lever Switch", category = "Guitar", author = "Branislav Stojkovic", @ComponentDescriptor(name = "Lever Switch", category = "Guitar", author = "Branislav Stojkovic",
description = "Strat-style lever switch", stretchable = false, zOrder = IDIYComponent.COMPONENT, description = "Strat-style lever switch", zOrder = IDIYComponent.COMPONENT,
instanceNamePrefix = "SW", keywordPolicy = KeywordPolicy.SHOW_TAG, instanceNamePrefix = "SW", keywordPolicy = KeywordPolicy.SHOW_TAG,
keywordTag = "Guitar Wiring Diagram") keywordTag = "Guitar Wiring Diagram")
public class LeverSwitch extends AbstractTransparentComponent<String> implements ISwitch { public class LeverSwitch extends AbstractTransparentComponent<String> implements ISwitch {
@@ -428,11 +428,11 @@ public class LeverSwitch extends AbstractTransparentComponent<String> implements
} }
} }
@Override // @Override
public String getControlPointNodeName(int index) { // public String getControlPointNodeName(int index) {
// we don't want the switch to produce any nodes, it just makes connections // // we don't want the switch to produce any nodes, it just makes connections
return null; // return null;
} // }
// switch stuff // switch stuff
@@ -475,5 +475,10 @@ public class LeverSwitch extends AbstractTransparentComponent<String> implements
return (index1 == 0 || index1 == 12 || index2 == 11 || index2 == 23) && index2 - index1 == position + 1; return (index1 == 0 || index1 == 12 || index2 == 11 || index2 == 23) && index2 - index1 == position + 1;
} }
return false; return false;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
} }
} }
@@ -52,7 +52,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "P-90 Single Coil Pickup", category = "Guitar", author = "Branislav Stojkovic", @ComponentDescriptor(name = "P-90 Single Coil Pickup", category = "Guitar", author = "Branislav Stojkovic",
description = "Single coil P-90 guitar pickup, both \"dog ear\" and \"soap bar\"", stretchable = false, description = "Single coil P-90 guitar pickup, both \"dog ear\" and \"soap bar\"",
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "PKP", autoEdit = false, zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "PKP", autoEdit = false,
keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "Guitar Wiring Diagram") keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "Guitar Wiring Diagram")
public class P90Pickup extends AbstractSingleOrHumbuckerPickup { public class P90Pickup extends AbstractSingleOrHumbuckerPickup {
@@ -50,7 +50,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "P- Bass Pickup", category = "Guitar", author = "Branislav Stojkovic", @ComponentDescriptor(name = "P- Bass Pickup", category = "Guitar", author = "Branislav Stojkovic",
description = "Split-coil pickup for P-Bass and similar guitars", stretchable = false, description = "Split-coil pickup for P-Bass and similar guitars",
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "PKP", autoEdit = false, zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "PKP", autoEdit = false,
keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "Guitar Wiring Diagram") keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "Guitar Wiring Diagram")
public class PBassPickup extends AbstractSingleOrHumbuckerPickup { public class PBassPickup extends AbstractSingleOrHumbuckerPickup {
@@ -52,7 +52,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Single Coil Pickup", category = "Guitar", author = "Branislav Stojkovic", @ComponentDescriptor(name = "Single Coil Pickup", category = "Guitar", author = "Branislav Stojkovic",
description = "Single coil guitar pickup, both Strat and Tele style", stretchable = false, description = "Single coil guitar pickup, both Strat and Tele style",
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "PKP", autoEdit = false, zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "PKP", autoEdit = false,
keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "Guitar Wiring Diagram") keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "Guitar Wiring Diagram")
public class SingleCoilPickup extends AbstractSingleOrHumbuckerPickup { public class SingleCoilPickup extends AbstractSingleOrHumbuckerPickup {
@@ -45,7 +45,7 @@ import org.diylc.utils.BomEntry;
import org.diylc.utils.BomMaker; import org.diylc.utils.BomMaker;
@ComponentDescriptor(name = "Bill of Materials", author = "Branislav Stojkovic", category = "Misc", description = "", @ComponentDescriptor(name = "Bill of Materials", author = "Branislav Stojkovic", category = "Misc", description = "",
instanceNamePrefix = "BOM", zOrder = IDIYComponent.TEXT, stretchable = false, bomPolicy = BomPolicy.NEVER_SHOW, instanceNamePrefix = "BOM", zOrder = IDIYComponent.TEXT, bomPolicy = BomPolicy.NEVER_SHOW,
autoEdit = false) autoEdit = false)
public class BOM extends AbstractComponent<Void> { public class BOM extends AbstractComponent<Void> {
@@ -40,7 +40,7 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Ground", author = "Branislav Stojkovic", category = "Schematic Symbols", @ComponentDescriptor(name = "Ground", author = "Branislav Stojkovic", category = "Schematic Symbols",
instanceNamePrefix = "GND", description = "Ground schematic symbol", stretchable = false, instanceNamePrefix = "GND", description = "Ground schematic symbol",
zOrder = IDIYComponent.COMPONENT, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false) zOrder = IDIYComponent.COMPONENT, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false)
public class GroundSymbol extends AbstractComponent<Void> { public class GroundSymbol extends AbstractComponent<Void> {
@@ -133,12 +133,17 @@ public class GroundSymbol extends AbstractComponent<Void> {
@Override @Override
public void setControlPoint(Point point, int index) { public void setControlPoint(Point point, int index) {
this.point = point; this.point.setLocation(point);
} }
//
// @Override
// public String getControlPointNodeName(int index) {
// return getName();
// }
@Override @Override
public String getControlPointNodeName(int index) { public String getCommonPointName(int pointIndex) {
return getName(); return "GND";
} }
@Override @Override
@@ -51,7 +51,7 @@ import com.thoughtworks.xstream.annotations.XStreamConverter;
@ComponentDescriptor(name = "Image", author = "Branislav Stojkovic", category = "Misc", @ComponentDescriptor(name = "Image", author = "Branislav Stojkovic", category = "Misc",
description = "User defined image", instanceNamePrefix = "Img", zOrder = IDIYComponent.COMPONENT, description = "User defined image", instanceNamePrefix = "Img", zOrder = IDIYComponent.COMPONENT,
flexibleZOrder = true, stretchable = false, bomPolicy = BomPolicy.NEVER_SHOW) flexibleZOrder = true, bomPolicy = BomPolicy.NEVER_SHOW)
public class Image extends AbstractTransparentComponent<Void> { public class Image extends AbstractTransparentComponent<Void> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -44,7 +44,7 @@ import org.diylc.core.annotations.EditableProperty;
@ComponentDescriptor(name = "Label", author = "Branislav Stojkovic", category = "Misc", @ComponentDescriptor(name = "Label", author = "Branislav Stojkovic", category = "Misc",
description = "User defined label", instanceNamePrefix = "L", zOrder = IDIYComponent.TEXT, flexibleZOrder = true, description = "User defined label", instanceNamePrefix = "L", zOrder = IDIYComponent.TEXT, flexibleZOrder = true,
stretchable = false, bomPolicy = BomPolicy.NEVER_SHOW, transformer = TextTransformer.class) bomPolicy = BomPolicy.NEVER_SHOW, transformer = TextTransformer.class)
public class Label extends AbstractComponent<String> { public class Label extends AbstractComponent<String> {
public static String DEFAULT_TEXT = "Double click to edit text"; public static String DEFAULT_TEXT = "Double click to edit text";
@@ -244,7 +244,7 @@ public class Label extends AbstractComponent<String> {
this.color = color; this.color = color;
} }
@EditableProperty(name = "Vertical alignment") @EditableProperty(name = "Vertical Alignment")
public VerticalAlignment getVerticalAlignment() { public VerticalAlignment getVerticalAlignment() {
if (verticalAlignment == null) { if (verticalAlignment == null) {
verticalAlignment = VerticalAlignment.CENTER; verticalAlignment = VerticalAlignment.CENTER;
@@ -256,7 +256,7 @@ public class Label extends AbstractComponent<String> {
this.verticalAlignment = verticalAlignment; this.verticalAlignment = verticalAlignment;
} }
@EditableProperty(name = "Horizontal alignment") @EditableProperty(name = "Horizontal Alignment")
public HorizontalAlignment getHorizontalAlignment() { public HorizontalAlignment getHorizontalAlignment() {
if (horizontalAlignment == null) { if (horizontalAlignment == null) {
horizontalAlignment = HorizontalAlignment.CENTER; horizontalAlignment = HorizontalAlignment.CENTER;
@@ -46,7 +46,7 @@ import org.diylc.core.annotations.EditableProperty;
@ComponentDescriptor(name = "PCB Text", author = "Branislav Stojkovic", category = "Misc", @ComponentDescriptor(name = "PCB Text", author = "Branislav Stojkovic", category = "Misc",
description = "Mirrored text for PCB artwork", instanceNamePrefix = "L", zOrder = IDIYComponent.TRACE, description = "Mirrored text for PCB artwork", instanceNamePrefix = "L", zOrder = IDIYComponent.TRACE,
flexibleZOrder = false, stretchable = false, bomPolicy = BomPolicy.NEVER_SHOW, transformer = TextTransformer.class) flexibleZOrder = false, bomPolicy = BomPolicy.NEVER_SHOW, transformer = TextTransformer.class)
public class PCBText extends AbstractComponent<Void> { public class PCBText extends AbstractComponent<Void> {
public static String DEFAULT_TEXT = "Double click to edit text"; public static String DEFAULT_TEXT = "Double click to edit text";
@@ -116,14 +116,18 @@ public class PCBText extends AbstractComponent<Void> {
case _270: case _270:
g2d.rotate(Math.PI * 3 / 2, point.x, point.y); g2d.rotate(Math.PI * 3 / 2, point.x, point.y);
break; break;
} }
AffineTransform oldTx = g2d.getTransform();
// Flip horizontally // Flip horizontally
AffineTransform tx = AffineTransform.getScaleInstance(-1, 1); AffineTransform tx = AffineTransform.getScaleInstance(-1, 1);
tx.translate(-2 * x - textWidth, 0); tx.translate(-2 * x - textWidth, 0);
g2d.transform(tx); g2d.transform(tx);
g2d.drawString(text, x, y); g2d.drawString(text, x, y);
g2d.setTransform(oldTx);
} }
@Override @Override
@@ -0,0 +1,227 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
package org.diylc.components.misc;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.Rectangle2D;
import org.diylc.awt.StringUtils;
import org.diylc.common.HorizontalAlignment;
import org.diylc.components.AbstractComponent;
import org.diylc.components.transform.TextTransformer;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.BomPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.annotations.MultiLineText;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Auto-Wrap Label", author = "Branislav Stojkovic", category = "Misc",
description = "User defined label with auto-wrapped text", instanceNamePrefix = "L", zOrder = IDIYComponent.TEXT, flexibleZOrder = true,
bomPolicy = BomPolicy.NEVER_SHOW, transformer = TextTransformer.class)
public class WrapLabel extends AbstractComponent<String> {
private static final long serialVersionUID = 1L;
public static Size DEFAULT_WIDTH = new Size(1.5d, SizeUnit.in);
public static Size DEFAULT_HEIGHT = new Size(0.5d, SizeUnit.in);
protected Point[] controlPoints = new Point[] {new Point(0, 0),
new Point((int) DEFAULT_WIDTH.convertToPixels(), (int) DEFAULT_HEIGHT.convertToPixels())};
protected Point firstPoint = new Point();
protected Point secondPoint = new Point();
private Font font = LABEL_FONT;
private Color color = LABEL_COLOR;
private HorizontalAlignment horizontalAlignment = HorizontalAlignment.LEFT;
private String value = "The quick brown fox jumped over a lazy dog";
public WrapLabel() {
}
@MultiLineText
@EditableProperty
@Override
public String getValue() {
return value;
}
@Override
public void setValue(String value) {
this.value = value;
}
@Override
public int getControlPointCount() {
return 2;
}
@Override
public Point getControlPoint(int index) {
return controlPoints[index];
}
@Override
public void setControlPoint(Point point, int index) {
controlPoints[index].setLocation(point);
firstPoint.setLocation(Math.min(controlPoints[0].x, controlPoints[1].x),
Math.min(controlPoints[0].y, controlPoints[1].y));
secondPoint.setLocation(Math.max(controlPoints[0].x, controlPoints[1].x),
Math.max(controlPoints[0].y, controlPoints[1].y));
}
@Override
public boolean isControlPointSticky(int index) {
return false;
}
@Override
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
return VisibilityPolicy.WHEN_SELECTED;
}
@EditableProperty
public Font getFont() {
return font;
}
public void setFont(Font font) {
this.font = font;
}
//Bold and italic fields are named to be alphabetically after Font. This is
// important!
@EditableProperty(name = "Font Bold")
public boolean getBold() {
return font.isBold();
}
public void setBold(boolean bold) {
if (bold) {
if (font.isItalic()) {
font = font.deriveFont(Font.BOLD + Font.ITALIC);
} else {
font = font.deriveFont(Font.BOLD);
}
} else {
if (font.isItalic()) {
font = font.deriveFont(Font.ITALIC);
} else {
font = font.deriveFont(Font.PLAIN);
}
}
}
@EditableProperty(name = "Font Italic")
public boolean getItalic() {
return font.isItalic();
}
public void setItalic(boolean italic) {
if (italic) {
if (font.isBold()) {
font = font.deriveFont(Font.BOLD + Font.ITALIC);
} else {
font = font.deriveFont(Font.ITALIC);
}
} else {
if (font.isBold()) {
font = font.deriveFont(Font.BOLD);
} else {
font = font.deriveFont(Font.PLAIN);
}
}
}
@EditableProperty(name = "Font Size")
public int getFontSize() {
return font.getSize();
}
public void setFontSize(int size) {
font = font.deriveFont((float) size);
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
IDrawingObserver drawingObserver) {
g2d.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED : color);
g2d.setFont(font);
int x = firstPoint.x;
int y = firstPoint.y;
int maxWidth = secondPoint.x - firstPoint.x;
StringUtils.drawWrappedText(value, g2d, x, y, maxWidth, horizontalAlignment);
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.setColor(LABEL_COLOR);
g2d.setFont(LABEL_FONT.deriveFont(10f * width / 32).deriveFont(Font.PLAIN));
FontMetrics fontMetrics = g2d.getFontMetrics();
Rectangle2D rect = fontMetrics.getStringBounds("Wrap", g2d);
int textHeight = (int) (rect.getHeight());
int textWidth = (int) (rect.getWidth());
int x = (width - textWidth) / 2 + 1;
int y = (int) (4f * width / 32) + fontMetrics.getAscent();
g2d.drawString("Wrap", x, y);
y += g2d.getFont().getSize();
g2d.drawString("Text", x, y);
}
@EditableProperty
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
@EditableProperty(name = "Horizontal Alignment")
public HorizontalAlignment getHorizontalAlignment() {
if (horizontalAlignment == null) {
horizontalAlignment = HorizontalAlignment.CENTER;
}
return horizontalAlignment;
}
public void setHorizontalAlignment(HorizontalAlignment alignment) {
this.horizontalAlignment = alignment;
}
}
@@ -34,6 +34,7 @@ import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D; import java.awt.geom.RoundRectangle2D;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.awt.StringUtils;
import org.diylc.common.Display; import org.diylc.common.Display;
import org.diylc.common.HorizontalAlignment; import org.diylc.common.HorizontalAlignment;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
@@ -57,7 +58,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Audio Transformer", author = "Branislav Stojkovic", category = "Passive", @ComponentDescriptor(name = "Audio Transformer", author = "Branislav Stojkovic", category = "Passive",
instanceNamePrefix = "TR", description = "Small signal audio transformer with EI core", stretchable = false, instanceNamePrefix = "TR", description = "Small signal audio transformer with EI core",
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = DIL_ICTransformer.class) zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = DIL_ICTransformer.class)
public class AudioTransformer extends AbstractMultiPartComponent<String> { public class AudioTransformer extends AbstractMultiPartComponent<String> {
@@ -315,11 +316,11 @@ public class AudioTransformer extends AbstractMultiPartComponent<String> {
AffineTransform tx = getTx(); AffineTransform tx = getTx();
if (tx != null) if (tx != null)
tx.transform(wPoint, wPoint); tx.transform(wPoint, wPoint);
drawCenteredText(g2d, "P", wPoint.x, wPoint.y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); StringUtils.drawCenteredText(g2d, "P", wPoint.x, wPoint.y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
wPoint = new Point((int) (controlPoints[0].x + windingSpacing.convertToPixels() - project.getFontSize()), (int) (controlPoints[0].y + leadSpacing.convertToPixels())); wPoint = new Point((int) (controlPoints[0].x + windingSpacing.convertToPixels() - project.getFontSize()), (int) (controlPoints[0].y + leadSpacing.convertToPixels()));
if (tx != null) if (tx != null)
tx.transform(wPoint, wPoint); tx.transform(wPoint, wPoint);
drawCenteredText(g2d, "S", wPoint.x, wPoint.y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); StringUtils.drawCenteredText(g2d, "S", wPoint.x, wPoint.y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
// Draw label. // Draw label.
Color finalLabelColor; Color finalLabelColor;
@@ -517,5 +518,10 @@ public class AudioTransformer extends AbstractMultiPartComponent<String> {
public void setSecondaryCT(boolean secondaryCT) { public void setSecondaryCT(boolean secondaryCT) {
this.secondaryCT = secondaryCT; this.secondaryCT = secondaryCT;
updateControlPoints(); updateControlPoints();
} }
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
}
} }
@@ -33,6 +33,7 @@ import java.text.DecimalFormat;
import java.text.Format; import java.text.Format;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.awt.StringUtils;
import org.diylc.common.Display; import org.diylc.common.Display;
import org.diylc.common.HorizontalAlignment; import org.diylc.common.HorizontalAlignment;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
@@ -56,7 +57,7 @@ import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Multi-Section Capacitor", author = "Branislav Stojkovic", category = "Passive", @ComponentDescriptor(name = "Multi-Section Capacitor", author = "Branislav Stojkovic", category = "Passive",
instanceNamePrefix = "C", description = "Multi-section vertically mounted electrolytic capacitor, similar to JJ, CE and others", instanceNamePrefix = "C", description = "Multi-section vertically mounted electrolytic capacitor, similar to JJ, CE and others",
stretchable = false, zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE) zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE)
public class MultiSectionCapacitor extends AbstractTransparentComponent<Capacitance[]> { public class MultiSectionCapacitor extends AbstractTransparentComponent<Capacitance[]> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -414,7 +415,7 @@ public class MultiSectionCapacitor extends AbstractTransparentComponent<Capacita
Rectangle bounds = area[0].getBounds(); Rectangle bounds = area[0].getBounds();
drawCenteredText(g2d, label, bounds.x + bounds.width / 2, bounds.y + bounds.height / 2, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); StringUtils.drawCenteredText(g2d, label, bounds.x + bounds.width / 2, bounds.y + bounds.height / 2, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
// draw polarity markers // draw polarity markers
g2d.setColor(pinColor.darker()); g2d.setColor(pinColor.darker());
@@ -515,5 +516,10 @@ public class MultiSectionCapacitor extends AbstractTransparentComponent<Capacita
public void setPinColor(Color pinColor) { public void setPinColor(Color pinColor) {
this.pinColor = pinColor; this.pinColor = pinColor;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
} }
} }
@@ -52,7 +52,7 @@ import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Potentiometer", author = "Branislav Stojkovic", category = "Passive", @ComponentDescriptor(name = "Potentiometer", author = "Branislav Stojkovic", category = "Passive",
creationMethod = CreationMethod.SINGLE_CLICK, instanceNamePrefix = "VR", creationMethod = CreationMethod.SINGLE_CLICK, instanceNamePrefix = "VR",
description = "Panel mount potentiometer with solder lugs", zOrder = IDIYComponent.COMPONENT, stretchable = false, description = "Panel mount potentiometer with solder lugs", zOrder = IDIYComponent.COMPONENT,
transformer = PotentiometerTransformer.class) transformer = PotentiometerTransformer.class)
public class PotentiometerPanel extends AbstractPotentiometer { public class PotentiometerPanel extends AbstractPotentiometer {
@@ -468,6 +468,11 @@ public class PotentiometerPanel extends AbstractPotentiometer {
return (index1 + 1) + "-" + (index2 + 1); return (index1 + 1) + "-" + (index2 + 1);
return null; return null;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
} }
public enum Type { public enum Type {
@@ -24,6 +24,7 @@ package org.diylc.components.passive;
import java.awt.Color; import java.awt.Color;
import java.awt.FontMetrics; import java.awt.FontMetrics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Polygon; import java.awt.Polygon;
import java.awt.Shape; import java.awt.Shape;
import java.awt.geom.GeneralPath; import java.awt.geom.GeneralPath;
@@ -36,7 +37,7 @@ import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.KeywordPolicy; import org.diylc.core.annotations.KeywordPolicy;
@ComponentDescriptor(name = "Potentiometer", author = "MCbx", category = "Schematic Symbols", @ComponentDescriptor(name = "Potentiometer", author = "MCbx", category = "Schematic Symbols",
instanceNamePrefix = "VR", description = "Potentiometer symbol", stretchable = false, instanceNamePrefix = "VR", description = "Potentiometer symbol",
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "Schematic") zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "Schematic")
public class PotentiometerSymbol extends Abstract3LegSymbol { public class PotentiometerSymbol extends Abstract3LegSymbol {
@@ -47,7 +48,8 @@ public class PotentiometerSymbol extends Abstract3LegSymbol {
} }
public Shape[] getBody() { public Shape[] getBody() {
Shape[] body = new Shape[3]; Shape[] body = new Shape[3];
Point[] controlPoints = getControlPoints();
int x = controlPoints[0].x; int x = controlPoints[0].x;
int y = controlPoints[0].y; int y = controlPoints[0].y;
int pinSpacing = (int) PIN_SPACING.convertToPixels(); int pinSpacing = (int) PIN_SPACING.convertToPixels();
@@ -48,7 +48,7 @@ import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Transformer Coil", author = "Branislav Stojkovic", category = "Schematic Symbols", instanceNamePrefix = "L", @ComponentDescriptor(name = "Transformer Coil", author = "Branislav Stojkovic", category = "Schematic Symbols", instanceNamePrefix = "L",
description = "Transformer coil symbol. Use multiple instances together with \"Transformer Core Symbol\"<br>to draw transformer schematics.", description = "Transformer coil symbol. Use multiple instances together with \"Transformer Core Symbol\"<br>to draw transformer schematics.",
stretchable = false, zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_TAG, zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_TAG,
keywordTag = "Schematic") keywordTag = "Schematic")
public class TransformerCoil extends AbstractComponent<org.diylc.core.measures.Voltage> { public class TransformerCoil extends AbstractComponent<org.diylc.core.measures.Voltage> {
@@ -281,5 +281,10 @@ public class TransformerCoil extends AbstractComponent<org.diylc.core.measures.V
} }
return body; return body;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
} }
} }
@@ -46,8 +46,7 @@ import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Transformer Core", author = "Branislav Stojkovic", category = "Schematic Symbols", instanceNamePrefix = "T", @ComponentDescriptor(name = "Transformer Core", author = "Branislav Stojkovic", category = "Schematic Symbols", instanceNamePrefix = "T",
description = "Transformer core symbol. Use multiple instances together with \"Transformer Coil Symbol\"<br>to draw transformer schematics.", description = "Transformer core symbol. Use multiple instances together with \"Transformer Coil Symbol\"<br>to draw transformer schematics.",
stretchable = true, zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_TAG, zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_TAG, creationMethod = CreationMethod.POINT_BY_POINT, keywordTag = "Schematic")
creationMethod = CreationMethod.POINT_BY_POINT, keywordTag = "Schematic")
public class TransformerCore extends AbstractComponent<Void> { public class TransformerCore extends AbstractComponent<Void> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -154,6 +153,10 @@ public class TransformerCore extends AbstractComponent<Void> {
@Override @Override
public void setValue(Void value) { public void setValue(Void value) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
} }
} }
@@ -49,8 +49,7 @@ import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Trimmer Potentiometer", author = "Branislav Stojkovic", category = "Passive", @ComponentDescriptor(name = "Trimmer Potentiometer", author = "Branislav Stojkovic", category = "Passive",
creationMethod = CreationMethod.SINGLE_CLICK, instanceNamePrefix = "VR", creationMethod = CreationMethod.SINGLE_CLICK, instanceNamePrefix = "VR",
description = "Various types of board mounted trimmer potentiometers", zOrder = IDIYComponent.COMPONENT, description = "Various types of board mounted trimmer potentiometers", zOrder = IDIYComponent.COMPONENT)
stretchable = false)
public class TrimmerPotentiometer extends AbstractPotentiometer { public class TrimmerPotentiometer extends AbstractPotentiometer {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -529,6 +528,11 @@ public class TrimmerPotentiometer extends AbstractPotentiometer {
updateControlPoints(); updateControlPoints();
body = null; body = null;
} }
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
}
public static enum TrimmerType { public static enum TrimmerType {
FLAT_SMALL("Horizontal Small 1"), FLAT_SMALL2("Horizontal Small 2"), FLAT_XSMALL("Horizontal X-Small"), FLAT_LARGE( FLAT_SMALL("Horizontal Small 1"), FLAT_SMALL2("Horizontal Small 2"), FLAT_XSMALL("Horizontal X-Small"), FLAT_LARGE(
@@ -196,4 +196,16 @@ public abstract class AbstractTransistorPackage extends AbstractTransparentCompo
public void setPinout(TransistorPinout pinout) { public void setPinout(TransistorPinout pinout) {
this.pinout = pinout; this.pinout = pinout;
} }
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
}
@Override
public String getControlPointNodeName(int index) {
if (index >= 3)
return null;
return Integer.toString(index + 1);
}
} }
@@ -22,6 +22,7 @@
package org.diylc.components.semiconductors; package org.diylc.components.semiconductors;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Polygon; import java.awt.Polygon;
import java.awt.Shape; import java.awt.Shape;
import java.awt.geom.AffineTransform; import java.awt.geom.AffineTransform;
@@ -36,7 +37,7 @@ import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.annotations.KeywordPolicy; import org.diylc.core.annotations.KeywordPolicy;
@ComponentDescriptor(name = "BJT", author = "Branislav Stojkovic", category = "Schematic Symbols", @ComponentDescriptor(name = "BJT", author = "Branislav Stojkovic", category = "Schematic Symbols",
instanceNamePrefix = "Q", description = "Bipolar junction transistor schematic symbol", stretchable = false, instanceNamePrefix = "Q", description = "Bipolar junction transistor schematic symbol",
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_TAG_AND_VALUE, keywordTag = "Schematic") zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_TAG_AND_VALUE, keywordTag = "Schematic")
public class BJTSymbol extends Abstract3LegSymbol { public class BJTSymbol extends Abstract3LegSymbol {
@@ -45,7 +46,8 @@ public class BJTSymbol extends Abstract3LegSymbol {
protected BJTPolarity polarity = BJTPolarity.NPN; protected BJTPolarity polarity = BJTPolarity.NPN;
public Shape[] getBody() { public Shape[] getBody() {
Shape[] body = new Shape[3]; Shape[] body = new Shape[3];
Point[] controlPoints = getControlPoints();
int x = controlPoints[0].x; int x = controlPoints[0].x;
int y = controlPoints[0].y; int y = controlPoints[0].y;
int pinSpacing = (int) PIN_SPACING.convertToPixels(); int pinSpacing = (int) PIN_SPACING.convertToPixels();
@@ -35,6 +35,7 @@ import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D; import java.awt.geom.RoundRectangle2D;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.awt.StringUtils;
import org.diylc.common.Display; import org.diylc.common.Display;
import org.diylc.common.HorizontalAlignment; import org.diylc.common.HorizontalAlignment;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
@@ -61,7 +62,7 @@ import org.diylc.core.measures.Voltage;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Bridge Rectifier", author = "Branislav Stojkovic", category = "Semiconductors", @ComponentDescriptor(name = "Bridge Rectifier", author = "Branislav Stojkovic", category = "Semiconductors",
instanceNamePrefix = "BR", description = "Few variations of bridge rectifier chips", stretchable = false, instanceNamePrefix = "BR", description = "Few variations of bridge rectifier chips",
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = DIL_ICTransformer.class) zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = DIL_ICTransformer.class)
public class BridgeRectifier extends AbstractTransparentComponent<String> { public class BridgeRectifier extends AbstractTransparentComponent<String> {
@@ -561,7 +562,7 @@ public class BridgeRectifier extends AbstractTransparentComponent<String> {
break; break;
} }
drawCenteredText(g2d, pointLabels[i], point.x + dx, point.y + dy, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); StringUtils.drawCenteredText(g2d, pointLabels[i], point.x + dx, point.y + dy, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
} }
} }
@@ -581,10 +582,10 @@ public class BridgeRectifier extends AbstractTransparentComponent<String> {
g2d.fillOval(width * 2 / 8, height * 6 / 8 - pinSize, pinSize, pinSize); g2d.fillOval(width * 2 / 8, height * 6 / 8 - pinSize, pinSize, pinSize);
g2d.setColor(LABEL_COLOR); g2d.setColor(LABEL_COLOR);
g2d.setFont(LABEL_FONT.deriveFont(8f * width / 32)); g2d.setFont(LABEL_FONT.deriveFont(8f * width / 32));
drawCenteredText(g2d, "+", width * 2 / 8 + 1, height * 2 / 8 + 4 * width / 32, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); StringUtils.drawCenteredText(g2d, "+", width * 2 / 8 + 1, height * 2 / 8 + 4 * width / 32, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
drawCenteredText(g2d, "-", width * 2 / 8 + 1, height * 6 / 8 - 5 * width / 32, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); StringUtils.drawCenteredText(g2d, "-", width * 2 / 8 + 1, height * 6 / 8 - 5 * width / 32, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
drawCenteredText(g2d, "~", width * 6 / 8 - 2 * width / 32, height * 2 / 8 + 5 * width / 32, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); StringUtils.drawCenteredText(g2d, "~", width * 6 / 8 - 2 * width / 32, height * 2 / 8 + 5 * width / 32, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
drawCenteredText(g2d, "~", width * 6 / 8 - 2 * width / 32, height * 6 / 8 - 5 * width / 32, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); StringUtils.drawCenteredText(g2d, "~", width * 6 / 8 - 2 * width / 32, height * 6 / 8 - 5 * width / 32, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
} }
@EditableProperty(name = "Body") @EditableProperty(name = "Body")
@@ -661,6 +662,11 @@ public class BridgeRectifier extends AbstractTransparentComponent<String> {
public void setLabelOriantation(LabelOriantation labelOriantation) { public void setLabelOriantation(LabelOriantation labelOriantation) {
this.labelOriantation = labelOriantation; this.labelOriantation = labelOriantation;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
} }
public static enum RectifierType { public static enum RectifierType {
@@ -56,7 +56,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "DIP IC", author = "Branislav Stojkovic", category = "Semiconductors", @ComponentDescriptor(name = "DIP IC", author = "Branislav Stojkovic", category = "Semiconductors",
instanceNamePrefix = "IC", description = "Dual-in-line package IC", stretchable = false, instanceNamePrefix = "IC", description = "Dual-in-line package IC",
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = DIL_ICTransformer.class) zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = DIL_ICTransformer.class)
public class DIL_IC extends AbstractTransparentComponent<String> { public class DIL_IC extends AbstractTransparentComponent<String> {
@@ -536,6 +536,11 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
public void setDisplayNumbers(DisplayNumbers numbers) { public void setDisplayNumbers(DisplayNumbers numbers) {
this.displayNumbers = numbers; this.displayNumbers = numbers;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
} }
public static enum PinCount { public static enum PinCount {
@@ -21,39 +21,40 @@
*/ */
package org.diylc.components.semiconductors; package org.diylc.components.semiconductors;
import java.awt.AlphaComposite; import java.awt.AlphaComposite;
import java.awt.Color; import java.awt.Color;
import java.awt.Composite; import java.awt.Composite;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Point; import java.awt.Point;
import java.awt.Polygon; import java.awt.Polygon;
import java.awt.Shape; import java.awt.Shape;
import java.awt.geom.Area; import java.awt.geom.Area;
import java.awt.geom.GeneralPath; import java.awt.geom.GeneralPath;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.common.Display; import org.diylc.awt.StringUtils;
import org.diylc.common.HorizontalAlignment; import org.diylc.common.Display;
import org.diylc.common.IPlugInPort; import org.diylc.common.HorizontalAlignment;
import org.diylc.common.ObjectCache; import org.diylc.common.IPlugInPort;
import org.diylc.common.VerticalAlignment; import org.diylc.common.ObjectCache;
import org.diylc.components.AbstractTransparentComponent; import org.diylc.common.VerticalAlignment;
import org.diylc.core.ComponentState; import org.diylc.components.AbstractTransparentComponent;
import org.diylc.core.IDIYComponent; import org.diylc.core.ComponentState;
import org.diylc.core.IDrawingObserver; import org.diylc.core.IDIYComponent;
import org.diylc.core.Project; import org.diylc.core.IDrawingObserver;
import org.diylc.core.Theme; import org.diylc.core.Project;
import org.diylc.core.VisibilityPolicy; import org.diylc.core.Theme;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.KeywordPolicy; import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size; import org.diylc.core.annotations.KeywordPolicy;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.Size;
import org.diylc.utils.Constants; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
@ComponentDescriptor(name = "IC", author = "Branislav Stojkovic", category = "Schematic Symbols", @ComponentDescriptor(name = "IC", author = "Branislav Stojkovic", category = "Schematic Symbols",
instanceNamePrefix = "IC", description = "IC symbol with 3 or 5 contacts", stretchable = false, instanceNamePrefix = "IC", description = "IC symbol with 3 or 5 contacts",
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_TAG_AND_VALUE, keywordTag = "Schematic") zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_TAG_AND_VALUE, keywordTag = "Schematic")
public class ICSymbol extends AbstractTransparentComponent<String> { public class ICSymbol extends AbstractTransparentComponent<String> {
@@ -134,12 +135,12 @@ public class ICSymbol extends AbstractTransparentComponent<String> {
if (display == Display.BOTH) { if (display == Display.BOTH) {
label = getName() + " " + (getValue() == null ? "" : getValue().toString()); label = getName() + " " + (getValue() == null ? "" : getValue().toString());
} }
drawCenteredText(g2d, label, x, controlPoints[0].y + pinSpacing, HorizontalAlignment.CENTER, StringUtils.drawCenteredText(g2d, label, x, controlPoints[0].y + pinSpacing, HorizontalAlignment.CENTER,
VerticalAlignment.CENTER); VerticalAlignment.CENTER);
// Draw +/- markers // Draw +/- markers
drawCenteredText(g2d, getFlip() ? "+" : "-", controlPoints[0].x + pinSpacing, controlPoints[0].y, HorizontalAlignment.CENTER, StringUtils.drawCenteredText(g2d, getFlip() ? "+" : "-", controlPoints[0].x + pinSpacing, controlPoints[0].y, HorizontalAlignment.CENTER,
VerticalAlignment.CENTER); VerticalAlignment.CENTER);
drawCenteredText(g2d, getFlip() ? "-" : "+", controlPoints[1].x + pinSpacing, controlPoints[1].y, HorizontalAlignment.CENTER, StringUtils.drawCenteredText(g2d, getFlip() ? "-" : "+", controlPoints[1].x + pinSpacing, controlPoints[1].y, HorizontalAlignment.CENTER,
VerticalAlignment.CENTER); VerticalAlignment.CENTER);
} }
@@ -156,8 +157,8 @@ public class ICSymbol extends AbstractTransparentComponent<String> {
g2d.fill(area); g2d.fill(area);
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.setFont(LABEL_FONT.deriveFont(8f)); g2d.setFont(LABEL_FONT.deriveFont(8f));
drawCenteredText(g2d, "-", 3 * margin, height / 3, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); StringUtils.drawCenteredText(g2d, "-", 3 * margin, height / 3, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
drawCenteredText(g2d, "+", 3 * margin + 1, height * 2 / 3, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); StringUtils.drawCenteredText(g2d, "+", 3 * margin + 1, height * 2 / 3, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
// g2d.setStroke(new BasicStroke(1f, BasicStroke.CAP_ROUND, // g2d.setStroke(new BasicStroke(1f, BasicStroke.CAP_ROUND,
// BasicStroke.JOIN_ROUND)); // BasicStroke.JOIN_ROUND));
g2d.draw(area); g2d.draw(area);
@@ -295,5 +296,10 @@ public class ICSymbol extends AbstractTransparentComponent<String> {
public void setDisplay(Display display) { public void setDisplay(Display display) {
this.display = display; this.display = display;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
} }
} }
@@ -22,10 +22,11 @@
package org.diylc.components.semiconductors; package org.diylc.components.semiconductors;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Polygon; import java.awt.Polygon;
import java.awt.Shape; import java.awt.Shape;
import java.awt.geom.GeneralPath; import java.awt.geom.GeneralPath;
import org.diylc.common.ObjectCache; import org.diylc.common.ObjectCache;
import org.diylc.components.Abstract3LegSymbol; import org.diylc.components.Abstract3LegSymbol;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
@@ -34,7 +35,7 @@ import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.annotations.KeywordPolicy; import org.diylc.core.annotations.KeywordPolicy;
@ComponentDescriptor(name = "JFET", author = "Branislav Stojkovic", category = "Schematic Symbols", @ComponentDescriptor(name = "JFET", author = "Branislav Stojkovic", category = "Schematic Symbols",
instanceNamePrefix = "Q", description = "JFET transistor schematic symbol", stretchable = false, instanceNamePrefix = "Q", description = "JFET transistor schematic symbol",
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_TAG_AND_VALUE, keywordTag = "Schematic") zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_TAG_AND_VALUE, keywordTag = "Schematic")
public class JFETSymbol extends Abstract3LegSymbol { public class JFETSymbol extends Abstract3LegSymbol {
@@ -43,7 +44,8 @@ public class JFETSymbol extends Abstract3LegSymbol {
protected FETPolarity polarity = FETPolarity.NEGATIVE; protected FETPolarity polarity = FETPolarity.NEGATIVE;
public Shape[] getBody() { public Shape[] getBody() {
Shape[] body = new Shape[3]; Shape[] body = new Shape[3];
Point[] controlPoints = getControlPoints();
int x = controlPoints[0].x; int x = controlPoints[0].x;
int y = controlPoints[0].y; int y = controlPoints[0].y;
int pinSpacing = (int) PIN_SPACING.convertToPixels(); int pinSpacing = (int) PIN_SPACING.convertToPixels();
@@ -31,6 +31,7 @@ import java.awt.geom.Path2D;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.awt.StringUtils;
import org.diylc.common.Display; import org.diylc.common.Display;
import org.diylc.common.HorizontalAlignment; import org.diylc.common.HorizontalAlignment;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
@@ -51,7 +52,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Logic Gate", author = "Branislav Stojkovic", category = "Schematic Symbols", @ComponentDescriptor(name = "Logic Gate", author = "Branislav Stojkovic", category = "Schematic Symbols",
instanceNamePrefix = "LG", description = "Basic logic gate schematic symbols", stretchable = false, instanceNamePrefix = "LG", description = "Basic logic gate schematic symbols",
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_TAG_AND_VALUE, keywordTag = "Schematic") zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_TAG_AND_VALUE, keywordTag = "Schematic")
public class LogicGateSymbol extends AbstractTransparentComponent<String> { public class LogicGateSymbol extends AbstractTransparentComponent<String> {
@@ -132,7 +133,7 @@ public class LogicGateSymbol extends AbstractTransparentComponent<String> {
if (display == Display.BOTH) { if (display == Display.BOTH) {
label = getName() + " " + (getValue() == null ? "" : getValue().toString()); label = getName() + " " + (getValue() == null ? "" : getValue().toString());
} }
drawCenteredText(g2d, label, x, controlPoints[0].y + (getControlPointCount() == 2 ? 0 : pinSpacing), HorizontalAlignment.CENTER, StringUtils.drawCenteredText(g2d, label, x, controlPoints[0].y + (getControlPointCount() == 2 ? 0 : pinSpacing), HorizontalAlignment.CENTER,
VerticalAlignment.CENTER); VerticalAlignment.CENTER);
} }
@@ -317,6 +318,11 @@ public class LogicGateSymbol extends AbstractTransparentComponent<String> {
public void setDisplay(Display display) { public void setDisplay(Display display) {
this.display = display; this.display = display;
} }
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
}
public enum GateType { public enum GateType {
Buffer(false), Not(true), Or(false), And(false), Xor(false), Nor(true), Nand(true), Xnor(true); Buffer(false), Not(true), Or(false), And(false), Xor(false), Nor(true), Nand(true), Xnor(true);
@@ -22,10 +22,11 @@
package org.diylc.components.semiconductors; package org.diylc.components.semiconductors;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Polygon; import java.awt.Polygon;
import java.awt.Shape; import java.awt.Shape;
import java.awt.geom.GeneralPath; import java.awt.geom.GeneralPath;
import org.diylc.common.ObjectCache; import org.diylc.common.ObjectCache;
import org.diylc.components.Abstract3LegSymbol; import org.diylc.components.Abstract3LegSymbol;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
@@ -34,7 +35,7 @@ import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.annotations.KeywordPolicy; import org.diylc.core.annotations.KeywordPolicy;
@ComponentDescriptor(name = "MOSFET", author = "Branislav Stojkovic", category = "Schematic Symbols", @ComponentDescriptor(name = "MOSFET", author = "Branislav Stojkovic", category = "Schematic Symbols",
instanceNamePrefix = "Q", description = "MOSFET transistor schematic symbol", stretchable = false, instanceNamePrefix = "Q", description = "MOSFET transistor schematic symbol",
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_TAG_AND_VALUE, keywordTag = "Schematic") zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_TAG_AND_VALUE, keywordTag = "Schematic")
public class MOSFETSymbol extends Abstract3LegSymbol { public class MOSFETSymbol extends Abstract3LegSymbol {
@@ -43,7 +44,8 @@ public class MOSFETSymbol extends Abstract3LegSymbol {
protected FETPolarity polarity = FETPolarity.NEGATIVE; protected FETPolarity polarity = FETPolarity.NEGATIVE;
public Shape[] getBody() { public Shape[] getBody() {
Shape[] body = new Shape[3]; Shape[] body = new Shape[3];
Point[] controlPoints = getControlPoints();
int x = controlPoints[0].x; int x = controlPoints[0].x;
int y = controlPoints[0].y; int y = controlPoints[0].y;
int pinSpacing = (int) PIN_SPACING.convertToPixels(); int pinSpacing = (int) PIN_SPACING.convertToPixels();
@@ -55,7 +55,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "SIP IC", author = "Branislav Stojkovic", category = "Semiconductors", @ComponentDescriptor(name = "SIP IC", author = "Branislav Stojkovic", category = "Semiconductors",
instanceNamePrefix = "IC", description = "Single-in-line package IC", stretchable = false, instanceNamePrefix = "IC", description = "Single-in-line package IC",
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = SIL_ICTransformer.class) zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = SIL_ICTransformer.class)
public class SIL_IC extends AbstractTransparentComponent<String> { public class SIL_IC extends AbstractTransparentComponent<String> {
@@ -143,6 +143,11 @@ public class SIL_IC extends AbstractTransparentComponent<String> {
updateControlPoints(); updateControlPoints();
// Reset body shape; // Reset body shape;
body = null; body = null;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
} }
@EditableProperty @EditableProperty
@@ -51,7 +51,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Transistor (TO-1)", author = "Branislav Stojkovic", category = "Semiconductors", @ComponentDescriptor(name = "Transistor (TO-1)", author = "Branislav Stojkovic", category = "Semiconductors",
instanceNamePrefix = "Q", description = "Transistor with small metal body", stretchable = false, instanceNamePrefix = "Q", description = "Transistor with small metal body",
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = TO1Transformer.class) zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = TO1Transformer.class)
public class TransistorTO1 extends AbstractTransistorPackage { public class TransistorTO1 extends AbstractTransistorPackage {
@@ -51,7 +51,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Transistor (TO-220)", author = "Branislav Stojkovic", category = "Semiconductors", @ComponentDescriptor(name = "Transistor (TO-220)", author = "Branislav Stojkovic", category = "Semiconductors",
instanceNamePrefix = "Q", description = "Transistors with metal tab for heat sink mounting", stretchable = false, instanceNamePrefix = "Q", description = "Transistors with metal tab for heat sink mounting",
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = TO220Transformer.class) zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = TO220Transformer.class)
public class TransistorTO220 extends AbstractTransistorPackage { public class TransistorTO220 extends AbstractTransistorPackage {
@@ -56,7 +56,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Transistor (TO-3)", author = "Branislav Stojkovic", category = "Semiconductors", @ComponentDescriptor(name = "Transistor (TO-3)", author = "Branislav Stojkovic", category = "Semiconductors",
instanceNamePrefix = "Q", description = "Transistor with large metal body", stretchable = false, instanceNamePrefix = "Q", description = "Transistor with large metal body",
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE) zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE)
public class TransistorTO3 extends AbstractTransparentComponent<String> { public class TransistorTO3 extends AbstractTransparentComponent<String> {
@@ -51,7 +51,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Transistor (TO-92)", author = "Branislav Stojkovic", category = "Semiconductors", @ComponentDescriptor(name = "Transistor (TO-92)", author = "Branislav Stojkovic", category = "Semiconductors",
instanceNamePrefix = "Q", description = "Transistor with small plastic or epoxy body", stretchable = false, instanceNamePrefix = "Q", description = "Transistor with small plastic or epoxy body",
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = TO92Transformer.class) zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = TO92Transformer.class)
public class TransistorTO92 extends AbstractTransistorPackage { public class TransistorTO92 extends AbstractTransistorPackage {
@@ -31,7 +31,7 @@ import java.awt.Rectangle;
import java.awt.geom.Area; import java.awt.geom.Area;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D; import java.awt.geom.RoundRectangle2D;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.common.Display; import org.diylc.common.Display;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
@@ -405,6 +405,11 @@ public abstract class PassiveSMDComponent<T> extends AbstractTransparentComponen
public void setLabelColor(Color labelColor) { public void setLabelColor(Color labelColor) {
this.labelColor = labelColor; this.labelColor = labelColor;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
} }
public static enum SMDSize { public static enum SMDSize {
@@ -31,7 +31,7 @@ import org.diylc.core.annotations.PositiveMeasureValidator;
import org.diylc.core.measures.Capacitance; import org.diylc.core.measures.Capacitance;
@ComponentDescriptor(name = "SMD Capacitor", author = "Branislav Stojkovic", category = "SMD", @ComponentDescriptor(name = "SMD Capacitor", author = "Branislav Stojkovic", category = "SMD",
instanceNamePrefix = "C", description = "Surface mount capacitor", stretchable = false, instanceNamePrefix = "C", description = "Surface mount capacitor",
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE) zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE)
public class SMDCapacitor extends PassiveSMDComponent<Capacitance> { public class SMDCapacitor extends PassiveSMDComponent<Capacitance> {
@@ -31,7 +31,7 @@ import org.diylc.core.annotations.PositiveMeasureValidator;
import org.diylc.core.measures.Resistance; import org.diylc.core.measures.Resistance;
@ComponentDescriptor(name = "SMD Resistor", author = "Branislav Stojkovic", category = "SMD", instanceNamePrefix = "C", @ComponentDescriptor(name = "SMD Resistor", author = "Branislav Stojkovic", category = "SMD", instanceNamePrefix = "C",
description = "Surface mount resistor", stretchable = false, zOrder = IDIYComponent.COMPONENT, description = "Surface mount resistor", zOrder = IDIYComponent.COMPONENT,
keywordPolicy = KeywordPolicy.SHOW_VALUE) keywordPolicy = KeywordPolicy.SHOW_VALUE)
public class SMDResistor extends PassiveSMDComponent<Resistance> { public class SMDResistor extends PassiveSMDComponent<Resistance> {
@@ -21,30 +21,31 @@
*/ */
package org.diylc.components.tube; package org.diylc.components.tube;
import java.awt.Color; import java.awt.Color;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Point; import java.awt.Point;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.Shape; import java.awt.Shape;
import java.awt.geom.AffineTransform; import java.awt.geom.AffineTransform;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.common.Display; import org.diylc.awt.StringUtils;
import org.diylc.common.HorizontalAlignment; import org.diylc.common.Display;
import org.diylc.common.IPlugInPort; import org.diylc.common.HorizontalAlignment;
import org.diylc.common.ObjectCache; import org.diylc.common.IPlugInPort;
import org.diylc.common.Orientation; import org.diylc.common.ObjectCache;
import org.diylc.common.VerticalAlignment; import org.diylc.common.Orientation;
import org.diylc.components.AbstractComponent; import org.diylc.common.VerticalAlignment;
import org.diylc.components.semiconductors.SymbolFlipping; import org.diylc.components.AbstractComponent;
import org.diylc.core.ComponentState; import org.diylc.components.semiconductors.SymbolFlipping;
import org.diylc.core.IDrawingObserver; import org.diylc.core.ComponentState;
import org.diylc.core.Project; import org.diylc.core.IDrawingObserver;
import org.diylc.core.Theme; import org.diylc.core.Project;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.Theme;
import org.diylc.core.measures.Size; import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.Size;
import org.diylc.utils.Constants; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
public abstract class AbstractTubeSymbol extends AbstractComponent<String> { public abstract class AbstractTubeSymbol extends AbstractComponent<String> {
@@ -121,7 +122,7 @@ public abstract class AbstractTubeSymbol extends AbstractComponent<String> {
if (display == Display.BOTH) { if (display == Display.BOTH) {
label = getName() + " " + (getValue() == null ? "" : getValue().toString()); label = getName() + " " + (getValue() == null ? "" : getValue().toString());
} }
drawCenteredText(g2d, label, rect.x + rect.width, rect.y + rect.height, HorizontalAlignment.RIGHT, StringUtils.drawCenteredText(g2d, label, rect.x + rect.width, rect.y + rect.height, HorizontalAlignment.RIGHT,
VerticalAlignment.BOTTOM); VerticalAlignment.BOTTOM);
} }
@@ -296,5 +297,10 @@ public abstract class AbstractTubeSymbol extends AbstractComponent<String> {
for (int i = 1; i < this.controlPoints.length; i++) { for (int i = 1; i < this.controlPoints.length; i++) {
rotate.transform(this.controlPoints[i], this.controlPoints[i]); rotate.transform(this.controlPoints[i], this.controlPoints[i]);
} }
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
} }
} }
@@ -38,7 +38,7 @@ import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.annotations.KeywordPolicy; import org.diylc.core.annotations.KeywordPolicy;
@ComponentDescriptor(name = "Diode", author = "Branislav Stojkovic", category = "Schematic Symbols", @ComponentDescriptor(name = "Diode", author = "Branislav Stojkovic", category = "Schematic Symbols",
instanceNamePrefix = "V", description = "Diode tube symbol", stretchable = false, zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "V", description = "Diode tube symbol", zOrder = IDIYComponent.COMPONENT,
keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = TubeSymbolTransformer.class) keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = TubeSymbolTransformer.class)
public class DiodeSymbol extends AbstractTubeSymbol { public class DiodeSymbol extends AbstractTubeSymbol {
@@ -37,7 +37,7 @@ import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.annotations.KeywordPolicy; import org.diylc.core.annotations.KeywordPolicy;
@ComponentDescriptor(name = "Pentode", author = "Branislav Stojkovic", category = "Schematic Symbols", @ComponentDescriptor(name = "Pentode", author = "Branislav Stojkovic", category = "Schematic Symbols",
instanceNamePrefix = "V", description = "Pentode tube symbol", stretchable = false, instanceNamePrefix = "V", description = "Pentode tube symbol",
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE,
transformer = TubeSymbolTransformer.class) transformer = TubeSymbolTransformer.class)
public class PentodeSymbol extends AbstractTubeSymbol { public class PentodeSymbol extends AbstractTubeSymbol {
@@ -37,7 +37,7 @@ import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.annotations.KeywordPolicy; import org.diylc.core.annotations.KeywordPolicy;
@ComponentDescriptor(name = "Triode", author = "Branislav Stojkovic", category = "Schematic Symbols", @ComponentDescriptor(name = "Triode", author = "Branislav Stojkovic", category = "Schematic Symbols",
instanceNamePrefix = "V", description = "Triode tube symbol", stretchable = false, instanceNamePrefix = "V", description = "Triode tube symbol",
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE,
transformer = TubeSymbolTransformer.class) transformer = TubeSymbolTransformer.class)
public class TriodeSymbol extends AbstractTubeSymbol { public class TriodeSymbol extends AbstractTubeSymbol {
@@ -33,6 +33,7 @@ import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.awt.StringUtils;
import org.diylc.common.HorizontalAlignment; import org.diylc.common.HorizontalAlignment;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache; import org.diylc.common.ObjectCache;
@@ -53,7 +54,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Tube Socket", author = "Branislav Stojkovic", category = "Tubes", @ComponentDescriptor(name = "Tube Socket", author = "Branislav Stojkovic", category = "Tubes",
instanceNamePrefix = "V", description = "Various types of tube/valve sockets", stretchable = false, instanceNamePrefix = "V", description = "Various types of tube/valve sockets",
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE) zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE)
public class TubeSocket extends AbstractTransparentComponent<String> { public class TubeSocket extends AbstractTransparentComponent<String> {
@@ -314,7 +315,7 @@ public class TubeSocket extends AbstractTransparentComponent<String> {
double theta = Math.atan2(controlPoints[i + 1].y - controlPoints[0].y, controlPoints[i + 1].x - controlPoints[0].x); double theta = Math.atan2(controlPoints[i + 1].y - controlPoints[0].y, controlPoints[i + 1].x - controlPoints[0].x);
double x = controlPoints[i + 1].x - Math.cos(theta) * electrodeLabelOffset; double x = controlPoints[i + 1].x - Math.cos(theta) * electrodeLabelOffset;
double y = controlPoints[i + 1].y - Math.sin(theta) * electrodeLabelOffset; double y = controlPoints[i + 1].y - Math.sin(theta) * electrodeLabelOffset;
drawCenteredText(g2d, label, (int)x, (int)y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER); StringUtils.drawCenteredText(g2d, label, (int)x, (int)y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
} }
} }
} }
@@ -83,20 +83,13 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
public String getFontName() { public String getFontName() {
return new JLabel().getFont().getName(); return new JLabel().getFont().getName();
} }
public List<Summary> summarize(List<Netlist> netlists, Node preferredOutput) throws TreeException {
List<Summary> summaries = new ArrayList<Summary>();
for (Netlist n : netlists)
summaries.add(summarize(n, preferredOutput));
return summaries;
}
private int positiveCount; private int positiveCount;
private int negativeCount; private int negativeCount;
private int noiseCount; private int noiseCount;
private Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException { protected Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException {
List<String> notes = new ArrayList<String>(); List<String> notes = new ArrayList<String>();
Tree tree = constructTree(netlist); Tree tree = constructTree(netlist);
@@ -48,17 +48,8 @@ public class SpiceAnalyzer extends NetlistAnalyzer implements INetlistAnalyzer {
public String getFontName() { public String getFontName() {
return "Courier New"; return "Courier New";
} }
@Override
public List<Summary> summarize(List<Netlist> netlists, Node preferredOutput) throws TreeException {
List<Summary> summaries = new ArrayList<Summary>();
for (Netlist n : netlists)
summaries.add(summarize(n, preferredOutput));
return summaries;
}
private Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException { protected Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException {
// grab all components that are in the netlist // grab all components that are in the netlist
List<IDIYComponent<?>> allComponents = new ArrayList<IDIYComponent<?>>(extractComponents(netlist)); List<IDIYComponent<?>> allComponents = new ArrayList<IDIYComponent<?>>(extractComponents(netlist));
Collections.sort(allComponents, new Comparator<IDIYComponent<?>>() { Collections.sort(allComponents, new Comparator<IDIYComponent<?>>() {
@@ -113,7 +104,7 @@ public class SpiceAnalyzer extends NetlistAnalyzer implements INetlistAnalyzer {
// output to spice // output to spice
for (int i = 0; i < c.getControlPointCount(); i++) { for (int i = 0; i < c.getControlPointCount(); i++) {
sb.append(fill(Integer.toString(nodeIndices[i]), 5)); sb.append(fill(formatSpiceNode(nodeIndices[i]), 5));
sb.append(" "); sb.append(" ");
} }
@@ -130,6 +121,10 @@ public class SpiceAnalyzer extends NetlistAnalyzer implements INetlistAnalyzer {
return new Summary(netlist, sb.toString()); return new Summary(netlist, sb.toString());
} }
private static String formatSpiceNode(int i) {
return String.format("N%03d" , i);
}
private String fill(String source, int desiredLength) { private String fill(String source, int desiredLength) {
String res = source; String res = source;
for (int i = 0; i < desiredLength - source.length(); i++) for (int i = 0; i < desiredLength - source.length(); i++)
+1 -1
View File
@@ -7,7 +7,7 @@
<property name="jar.dir" value="${build.dir}/jar" /> <property name="jar.dir" value="${build.dir}/jar" />
<property name="report.dir" value="${build.dir}/junitreport" /> <property name="report.dir" value="${build.dir}/junitreport" />
<property name="main.class" value="org.diylc.DIYLCStarter" /> <property name="main.class" value="org.diylc.DIYLCStarter" />
<property name="diylc.version" value="3.56.0" /> <property name="diylc.version" value="3.57.0" />
<property name="classes.dir" value="${build.dir}/temp/${ant.project.name}/classes" /> <property name="classes.dir" value="${build.dir}/temp/${ant.project.name}/classes" />
<property name="test.classes.dir" value="${build.dir}/temp/${ant.project.name}/test.classes" /> <property name="test.classes.dir" value="${build.dir}/temp/${ant.project.name}/test.classes" />
+2 -1
View File
@@ -2,4 +2,5 @@
#org.diylc.presenter.InstantiationManager.MAX_RECENT_COMPONENTS=20 #org.diylc.presenter.InstantiationManager.MAX_RECENT_COMPONENTS=20
#org.diylc.swing.plugins.canvas.CanvasPanel.USE_HARDWARE_ACCELLERATION=true #org.diylc.swing.plugins.canvas.CanvasPanel.USE_HARDWARE_ACCELLERATION=true
#org.diylc.swingframework.ruler.Ruler.USE_HARDWARE_ACCELLERATION=true #org.diylc.swingframework.ruler.Ruler.USE_HARDWARE_ACCELLERATION=true
#org.diylc.swing.gui.editor.PropertyEditorDialog.SHOW_DEFAULT_BOXES=true #org.diylc.swing.gui.editor.PropertyEditorDialog.SHOW_DEFAULT_BOXES=true
#org.diylc.swing.plugins.autosave.AutoSavePlugin.MAX_TOTAL_SIZE_MB=64
Binary file not shown.
Binary file not shown.
@@ -1667,7 +1667,7 @@ public class ActionFactory {
@Override @Override
public List<Netlist> doInBackground() throws Exception { public List<Netlist> doInBackground() throws Exception {
return plugInPort.extractNetlists(); return plugInPort.extractNetlists(true);
} }
@Override @Override
@@ -1722,7 +1722,7 @@ public class ActionFactory {
@Override @Override
public List<Summary> doInBackground() throws Exception { public List<Summary> doInBackground() throws Exception {
List<Netlist> netlists = plugInPort.extractNetlists(); List<Netlist> netlists = plugInPort.extractNetlists(true);
if (netlists == null || netlists.isEmpty()) { if (netlists == null || netlists.isEmpty()) {
throw new Exception("The generated netlist is empty, nothing to show."); throw new Exception("The generated netlist is empty, nothing to show.");
} }
@@ -66,7 +66,9 @@ public interface ISwingUI extends IView {
* @param action {@link Action} to inser * @param action {@link Action} to inser
* @param menuName name of the menu to insert into * @param menuName name of the menu to insert into
*/ */
void injectMenuAction(Action action, String menuName); void injectMenuAction(Action action, String menuName);
void injectMenuComponent(JComponent component);
/** /**
* Injects a custom submenu into application's main menu. If the specified menu does not exist it * Injects a custom submenu into application's main menu. If the specified menu does not exist it
@@ -36,7 +36,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import javax.swing.Action; import javax.swing.Action;
import javax.swing.BoxLayout; import javax.swing.BoxLayout;
import javax.swing.ButtonGroup; import javax.swing.ButtonGroup;
@@ -55,7 +55,7 @@ import javax.swing.SwingWorker;
import javax.swing.Timer; import javax.swing.Timer;
import javax.swing.event.MenuEvent; import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener; import javax.swing.event.MenuListener;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager; import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.common.BadPositionException; import org.diylc.common.BadPositionException;
@@ -69,6 +69,7 @@ import org.diylc.images.IconLoader;
import org.diylc.presenter.Presenter; import org.diylc.presenter.Presenter;
import org.diylc.swing.IDynamicSubmenuHandler; import org.diylc.swing.IDynamicSubmenuHandler;
import org.diylc.swing.ISwingUI; import org.diylc.swing.ISwingUI;
import org.diylc.swing.gui.actionbar.ActionBarPlugin;
import org.diylc.swing.gui.editor.PropertyEditorDialog; import org.diylc.swing.gui.editor.PropertyEditorDialog;
import org.diylc.swing.plugins.autosave.AutoSavePlugin; import org.diylc.swing.plugins.autosave.AutoSavePlugin;
import org.diylc.swing.plugins.canvas.CanvasPlugin; import org.diylc.swing.plugins.canvas.CanvasPlugin;
@@ -125,7 +126,8 @@ public class MainFrame extends JFrame implements ISwingUI {
presenter.installPlugin(new ConfigPlugin(this)); presenter.installPlugin(new ConfigPlugin(this));
presenter.installPlugin(new LayersMenuPlugin(this)); presenter.installPlugin(new LayersMenuPlugin(this));
presenter.installPlugin(new CloudPlugIn(this)); presenter.installPlugin(new CloudPlugIn(this));
presenter.installPlugin(new HelpMenuPlugin(this)); presenter.installPlugin(new HelpMenuPlugin(this));
presenter.installPlugin(new ActionBarPlugin(this));
presenter.installPlugin(new StatusBar(this)); presenter.installPlugin(new StatusBar(this));
@@ -313,7 +315,7 @@ public class MainFrame extends JFrame implements ISwingUI {
menu.add(action); menu.add(action);
} }
} }
} }
@Override @Override
public void injectSubmenu(String name, Icon icon, String parentMenuName) { public void injectSubmenu(String name, Icon icon, String parentMenuName) {
@@ -323,6 +325,11 @@ public class MainFrame extends JFrame implements ISwingUI {
submenu.setIcon(icon); submenu.setIcon(icon);
menu.add(submenu); menu.add(submenu);
menuMap.put(name, submenu); menuMap.put(name, submenu);
}
@Override
public void injectMenuComponent(JComponent component) {
getMainMenuBar().add(component);
} }
@Override @Override
@@ -185,7 +185,7 @@ public class TemplateDialog extends JDialog {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
plugInPort.loadProject(presenter.getCurrentProject(), true); plugInPort.loadProject(presenter.getCurrentProject(), true, null);
dispose(); dispose();
} }
}); });

Some files were not shown because too many files have changed in this diff Show More