mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Added visual indicator to the component tree showing how many variants,
if any, exist for a component Rename multi-section cap class
This commit is contained in:
Binary file not shown.
+56
-52
@@ -57,20 +57,20 @@ 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)
|
stretchable = false, zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE)
|
||||||
public class ElectrolyticCanCapacitor extends AbstractTransparentComponent<Capacitance[]> {
|
public class MultiSectionCapacitor extends AbstractTransparentComponent<Capacitance[]> {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public static Color BODY_COLOR = Color.decode("#6B6DCE");
|
public static Color BODY_COLOR = Color.decode("#6B6DCE");
|
||||||
public static Color BASE_COLOR = Color.decode("#333333");
|
public static Color BASE_COLOR = Color.decode("#333333");
|
||||||
public static Color BORDER_COLOR = BODY_COLOR.darker();
|
public static Color BORDER_COLOR = BODY_COLOR.darker();
|
||||||
public static Color PIN_COLOR = Color.decode("#00B2EE");
|
public static Color PIN_COLOR = METAL_COLOR;// Color.decode("#00B2EE");
|
||||||
public static Color PIN_BORDER_COLOR = PIN_COLOR.darker();
|
// public static Color PIN_BORDER_COLOR = PIN_COLOR.darker();
|
||||||
public static Color LABEL_COLOR = Color.white;
|
public static Color LABEL_COLOR = Color.white;
|
||||||
public static Size PIN_SIZE = new Size(0.08d, SizeUnit.in);
|
public static Size PIN_SIZE = new Size(0.08d, SizeUnit.in);
|
||||||
// public static Size PIN_SPACING = new Size(0.05d, SizeUnit.in);
|
// public static Size PIN_SPACING = new Size(0.05d, SizeUnit.in);
|
||||||
public static Size BODY_DIAMETER = new Size(1d, SizeUnit.in);
|
public static Size BODY_DIAMETER = new Size(1d, SizeUnit.in);
|
||||||
private static double RELATIVE_DIAMETER = 0.6d;
|
private static double[] RELATIVE_DIAMETERS = new double[] { 0.4d, 0.6d };
|
||||||
private static final Format format = new DecimalFormat("0.#####");
|
private static final Format format = new DecimalFormat("0.#####");
|
||||||
|
|
||||||
private Capacitance[] value = new Capacitance[3];
|
private Capacitance[] value = new Capacitance[3];
|
||||||
@@ -82,12 +82,13 @@ public class ElectrolyticCanCapacitor extends AbstractTransparentComponent<Capac
|
|||||||
private Color bodyColor = BODY_COLOR;
|
private Color bodyColor = BODY_COLOR;
|
||||||
private Color baseColor = BASE_COLOR;
|
private Color baseColor = BASE_COLOR;
|
||||||
private Color borderColor = BORDER_COLOR;
|
private Color borderColor = BORDER_COLOR;
|
||||||
private Color labelColor = LABEL_COLOR;
|
private Color labelColor = LABEL_COLOR;
|
||||||
|
private Color pinColor = PIN_COLOR;
|
||||||
protected Display display = Display.NAME;
|
protected Display display = Display.NAME;
|
||||||
// private Size pinSpacing = PIN_SPACING;
|
// private Size pinSpacing = PIN_SPACING;
|
||||||
private Size diameter = BODY_DIAMETER;
|
private Size diameter = BODY_DIAMETER;
|
||||||
|
|
||||||
public ElectrolyticCanCapacitor() {
|
public MultiSectionCapacitor() {
|
||||||
super();
|
super();
|
||||||
updateControlPoints();
|
updateControlPoints();
|
||||||
}
|
}
|
||||||
@@ -184,9 +185,7 @@ public class ElectrolyticCanCapacitor extends AbstractTransparentComponent<Capac
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateControlPoints() {
|
private void updateControlPoints() {
|
||||||
// int pinSpacing = (int) getPinSpacing().convertToPixels();
|
int pinSpacing = (int) (getDiameter().convertToPixels() * RELATIVE_DIAMETERS[value == null || value.length == 1 ? 0 : 1]);
|
||||||
int pinSpacing = (int) (getDiameter().convertToPixels() * RELATIVE_DIAMETER);
|
|
||||||
// switch (getS)
|
|
||||||
|
|
||||||
int newCount = value.length + 1;
|
int newCount = value.length + 1;
|
||||||
if (newCount != controlPoints.length) {
|
if (newCount != controlPoints.length) {
|
||||||
@@ -206,69 +205,68 @@ public class ElectrolyticCanCapacitor extends AbstractTransparentComponent<Capac
|
|||||||
if (newCount == 2) {
|
if (newCount == 2) {
|
||||||
switch (orientation) {
|
switch (orientation) {
|
||||||
case DEFAULT:
|
case DEFAULT:
|
||||||
controlPoints[1].setLocation(x + pinSpacing, y);
|
|
||||||
break;
|
|
||||||
case _90:
|
|
||||||
controlPoints[1].setLocation(x, y + pinSpacing);
|
controlPoints[1].setLocation(x, y + pinSpacing);
|
||||||
break;
|
break;
|
||||||
case _180:
|
case _90:
|
||||||
controlPoints[1].setLocation(x - pinSpacing, y);
|
controlPoints[1].setLocation(x - pinSpacing, y);
|
||||||
break;
|
break;
|
||||||
case _270:
|
case _180:
|
||||||
controlPoints[1].setLocation(x, y- pinSpacing);
|
controlPoints[1].setLocation(x, y- pinSpacing);
|
||||||
break;
|
break;
|
||||||
|
case _270:
|
||||||
|
controlPoints[1].setLocation(x + pinSpacing, y);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("Unexpected orientation: " + orientation);
|
throw new RuntimeException("Unexpected orientation: " + orientation);
|
||||||
}
|
}
|
||||||
} else if (newCount == 3) {
|
} else if (newCount == 3) {
|
||||||
switch (orientation) {
|
switch (orientation) {
|
||||||
case DEFAULT:
|
case DEFAULT:
|
||||||
controlPoints[1].setLocation(x + pinSpacing / 2, y - pinSpacing / 2);
|
|
||||||
controlPoints[2].setLocation(x + pinSpacing / 2, y + pinSpacing / 2);
|
|
||||||
break;
|
|
||||||
case _90:
|
|
||||||
controlPoints[1].setLocation(x + pinSpacing / 2, y + pinSpacing / 2);
|
controlPoints[1].setLocation(x + pinSpacing / 2, y + pinSpacing / 2);
|
||||||
controlPoints[2].setLocation(x - pinSpacing / 2, y + pinSpacing / 2);
|
controlPoints[2].setLocation(x - pinSpacing / 2, y + pinSpacing / 2);
|
||||||
break;
|
break;
|
||||||
case _180:
|
case _90:
|
||||||
controlPoints[1].setLocation(x - pinSpacing / 2, y - pinSpacing / 2);
|
controlPoints[1].setLocation(x - pinSpacing / 2, y - pinSpacing / 2);
|
||||||
controlPoints[2].setLocation(x - pinSpacing / 2, y + pinSpacing / 2);
|
controlPoints[2].setLocation(x - pinSpacing / 2, y + pinSpacing / 2);
|
||||||
break;
|
break;
|
||||||
case _270:
|
case _180:
|
||||||
controlPoints[1].setLocation(x - pinSpacing / 2, y - pinSpacing / 2);
|
controlPoints[1].setLocation(x - pinSpacing / 2, y - pinSpacing / 2);
|
||||||
controlPoints[2].setLocation(x + pinSpacing / 2, y - pinSpacing / 2);
|
controlPoints[2].setLocation(x + pinSpacing / 2, y - pinSpacing / 2);
|
||||||
break;
|
break;
|
||||||
|
case _270:
|
||||||
|
controlPoints[1].setLocation(x + pinSpacing / 2, y - pinSpacing / 2);
|
||||||
|
controlPoints[2].setLocation(x + pinSpacing / 2, y + pinSpacing / 2);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("Unexpected orientation: " + orientation);
|
throw new RuntimeException("Unexpected orientation: " + orientation);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
double theta = Math.PI * 2 / newCount;
|
double theta = Math.PI * 2 / newCount;
|
||||||
|
|
||||||
double centerX;
|
double centerX;
|
||||||
double centerY;
|
double centerY;
|
||||||
double theta0;
|
double theta0;
|
||||||
|
|
||||||
switch (orientation) {
|
switch (orientation) {
|
||||||
case DEFAULT:
|
case DEFAULT:
|
||||||
centerX = x + pinSpacing / 2;
|
|
||||||
centerY = y;
|
|
||||||
theta0 = -Math.PI;
|
|
||||||
break;
|
|
||||||
case _90:
|
|
||||||
centerX = x;
|
centerX = x;
|
||||||
centerY = y + pinSpacing / 2;
|
centerY = y + pinSpacing / 2;
|
||||||
theta0 = -Math.PI / 2;
|
theta0 = -Math.PI / 2;
|
||||||
break;
|
break;
|
||||||
case _180:
|
case _90:
|
||||||
centerX = x - pinSpacing / 2;
|
centerX = x - pinSpacing / 2;
|
||||||
centerY = y;
|
centerY = y;
|
||||||
theta0 = 0;
|
theta0 = 0;
|
||||||
break;
|
break;
|
||||||
case _270:
|
case _180:
|
||||||
centerX = x;
|
centerX = x;
|
||||||
centerY = y - pinSpacing / 2;
|
centerY = y - pinSpacing / 2;
|
||||||
theta0 = Math.PI / 2;
|
theta0 = Math.PI / 2;
|
||||||
break;
|
break;
|
||||||
|
case _270:
|
||||||
|
centerX = x + pinSpacing / 2;
|
||||||
|
centerY = y;
|
||||||
|
theta0 = -Math.PI;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("Unexpected orientation: " + orientation);
|
throw new RuntimeException("Unexpected orientation: " + orientation);
|
||||||
}
|
}
|
||||||
@@ -285,49 +283,46 @@ public class ElectrolyticCanCapacitor extends AbstractTransparentComponent<Capac
|
|||||||
double centerY;
|
double centerY;
|
||||||
int x = controlPoints[0].x;
|
int x = controlPoints[0].x;
|
||||||
int y = controlPoints[0].y;
|
int y = controlPoints[0].y;
|
||||||
int pinSpacing = (int) (getDiameter().convertToPixels() * RELATIVE_DIAMETER);
|
int pinSpacing = (int) (getDiameter().convertToPixels() * RELATIVE_DIAMETERS[value == null || value.length == 1 ? 0 : 1]);
|
||||||
if (controlPoints.length == 2 || controlPoints.length == 3) {
|
if (controlPoints.length == 2 || controlPoints.length == 3) {
|
||||||
switch (orientation) {
|
switch (orientation) {
|
||||||
case DEFAULT:
|
case DEFAULT:
|
||||||
centerX = x + pinSpacing / 2;
|
|
||||||
centerY = y;
|
|
||||||
break;
|
|
||||||
case _90:
|
|
||||||
centerX = x;
|
centerX = x;
|
||||||
centerY = y + pinSpacing / 2;
|
centerY = y + pinSpacing / 2;
|
||||||
break;
|
break;
|
||||||
case _180:
|
case _90:
|
||||||
centerX = x - pinSpacing / 2;
|
centerX = x - pinSpacing / 2;
|
||||||
centerY = y;
|
centerY = y;
|
||||||
break;
|
break;
|
||||||
case _270:
|
case _180:
|
||||||
centerX = x;
|
centerX = x;
|
||||||
centerY = y - pinSpacing / 2;
|
centerY = y - pinSpacing / 2;
|
||||||
break;
|
break;
|
||||||
|
case _270:
|
||||||
|
centerX = x + pinSpacing / 2;
|
||||||
|
centerY = y;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("Unexpected orientation: " + orientation);
|
throw new RuntimeException("Unexpected orientation: " + orientation);
|
||||||
}
|
}
|
||||||
// } else if (controlPoints.length == 3) {
|
|
||||||
// controlPoints[1].setLocation(x + pinSpacing, y);
|
|
||||||
// controlPoints[2].setLocation(x + pinSpacing / 2, y + pinSpacing / 2);
|
|
||||||
} else {
|
} else {
|
||||||
switch (orientation) {
|
switch (orientation) {
|
||||||
case DEFAULT:
|
case DEFAULT:
|
||||||
centerX = x + pinSpacing / 2;
|
|
||||||
centerY = y;
|
|
||||||
break;
|
|
||||||
case _90:
|
|
||||||
centerX = x;
|
centerX = x;
|
||||||
centerY = y + pinSpacing / 2;
|
centerY = y + pinSpacing / 2;
|
||||||
break;
|
break;
|
||||||
case _180:
|
case _90:
|
||||||
centerX = x - pinSpacing / 2;
|
centerX = x - pinSpacing / 2;
|
||||||
centerY = y;
|
centerY = y;
|
||||||
break;
|
break;
|
||||||
case _270:
|
case _180:
|
||||||
centerX = x;
|
centerX = x;
|
||||||
centerY = y - pinSpacing / 2;
|
centerY = y - pinSpacing / 2;
|
||||||
break;
|
break;
|
||||||
|
case _270:
|
||||||
|
centerX = x + pinSpacing / 2;
|
||||||
|
centerY = y;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("Unexpected orientation: " + orientation);
|
throw new RuntimeException("Unexpected orientation: " + orientation);
|
||||||
}
|
}
|
||||||
@@ -382,10 +377,10 @@ public class ElectrolyticCanCapacitor extends AbstractTransparentComponent<Capac
|
|||||||
|
|
||||||
for (Point point : controlPoints) {
|
for (Point point : controlPoints) {
|
||||||
if (!outlineMode) {
|
if (!outlineMode) {
|
||||||
g2d.setColor(PIN_COLOR);
|
g2d.setColor(pinColor);
|
||||||
g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
|
g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
|
||||||
}
|
}
|
||||||
g2d.setColor(outlineMode ? theme.getOutlineColor() : PIN_BORDER_COLOR);
|
g2d.setColor(outlineMode ? theme.getOutlineColor() : pinColor.darker());
|
||||||
g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
|
g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -419,7 +414,7 @@ public class ElectrolyticCanCapacitor extends AbstractTransparentComponent<Capac
|
|||||||
drawCenteredText(g2d, label, bounds.x + bounds.width / 2, bounds.y + bounds.height / 2, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
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(PIN_BORDER_COLOR);
|
g2d.setColor(pinColor.darker());
|
||||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2f));
|
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2f));
|
||||||
double markerSize = pinSize * 0.7;
|
double markerSize = pinSize * 0.7;
|
||||||
for (int i = 0; i < controlPoints.length; i++) {
|
for (int i = 0; i < controlPoints.length; i++) {
|
||||||
@@ -508,5 +503,14 @@ public class ElectrolyticCanCapacitor extends AbstractTransparentComponent<Capac
|
|||||||
|
|
||||||
public void setDisplay(Display display) {
|
public void setDisplay(Display display) {
|
||||||
this.display = display;
|
this.display = display;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EditableProperty(name = "Pin Color")
|
||||||
|
public Color getPinColor() {
|
||||||
|
return pinColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPinColor(Color pinColor) {
|
||||||
|
this.pinColor = pinColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
Binary file not shown.
@@ -149,13 +149,22 @@ public class TreePanel extends JPanel {
|
|||||||
Collections.sort(blockNames);
|
Collections.sort(blockNames);
|
||||||
if (!blockNames.equals(TreePanel.this.blocks)) {
|
if (!blockNames.equals(TreePanel.this.blocks)) {
|
||||||
LOG.info("Detected block change");
|
LOG.info("Detected block change");
|
||||||
refreshBlocks(blockNames);
|
refreshBuildingBlocks(blockNames);
|
||||||
} else
|
} else
|
||||||
LOG.info("Detected no block change");
|
LOG.info("Detected no block change");
|
||||||
} else
|
} else
|
||||||
LOG.info("Detected no block change");
|
LOG.info("Detected no block change");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.TEMPLATES_KEY, new IConfigListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void valueChanged(String key, Object value) {
|
||||||
|
LOG.info("Detected variants change, repainting the tree");
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
getTree().expandRow(0);
|
getTree().expandRow(0);
|
||||||
}
|
}
|
||||||
@@ -194,7 +203,7 @@ public class TreePanel extends JPanel {
|
|||||||
if (newBlocks != null) {
|
if (newBlocks != null) {
|
||||||
List<String> blockNames = new ArrayList<String>(newBlocks.keySet());
|
List<String> blockNames = new ArrayList<String>(newBlocks.keySet());
|
||||||
Collections.sort(blockNames);
|
Collections.sort(blockNames);
|
||||||
refreshBlocks(blockNames);
|
refreshBuildingBlocks(blockNames);
|
||||||
this.blocks = blockNames;
|
this.blocks = blockNames;
|
||||||
} else {
|
} else {
|
||||||
this.blocks = new ArrayList<String>();
|
this.blocks = new ArrayList<String>();
|
||||||
@@ -235,7 +244,7 @@ public class TreePanel extends JPanel {
|
|||||||
getTreeModel().nodeStructureChanged(getRecentNode());
|
getTreeModel().nodeStructureChanged(getRecentNode());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshBlocks(List<String> blocks) {
|
private void refreshBuildingBlocks(List<String> blocks) {
|
||||||
getBlocksNode().removeAllChildren();
|
getBlocksNode().removeAllChildren();
|
||||||
for (final String block : blocks) {
|
for (final String block : blocks) {
|
||||||
Payload payload = new Payload(block, new MouseAdapter() {
|
Payload payload = new Payload(block, new MouseAdapter() {
|
||||||
@@ -597,6 +606,9 @@ public class TreePanel extends JPanel {
|
|||||||
else
|
else
|
||||||
setPreferredSize(new Dimension(0, 0));
|
setPreferredSize(new Dimension(0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String shortCutHtml = "";
|
||||||
|
String variantsHtml = "";
|
||||||
|
|
||||||
if (payload.isVisible()) {
|
if (payload.isVisible()) {
|
||||||
HashMap<String, String> shortcutMap =
|
HashMap<String, String> shortcutMap =
|
||||||
@@ -608,14 +620,22 @@ public class TreePanel extends JPanel {
|
|||||||
if (shortcutMap != null && shortcutMap.containsValue(identifier)) {
|
if (shortcutMap != null && shortcutMap.containsValue(identifier)) {
|
||||||
for (String key : shortcutMap.keySet()) {
|
for (String key : shortcutMap.keySet()) {
|
||||||
if (shortcutMap.get(key).equals(identifier)) {
|
if (shortcutMap.get(key).equals(identifier)) {
|
||||||
setText("<html>"
|
shortCutHtml = " <a style=\"text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black; background-color: #eeeeee; color: #666666;\"> "
|
||||||
+ payload.toString()
|
+ key + " </a>";
|
||||||
+ " <a style=\"text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black; background-color: #eeeeee; color: #666666;\"><sup> "
|
|
||||||
+ key + " </sup></a></html>");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (payload.getComponentType() != null) {
|
||||||
|
List<Template> variants = plugInPort.getTemplatesFor(payload.getComponentType().getCategory(), payload.getComponentType().getName());
|
||||||
|
if (variants != null && !variants.isEmpty()) {
|
||||||
|
variantsHtml = " <a style=\"text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black; background-color: #D7FFC6; color: #666666;\">[+"
|
||||||
|
+ variants.size() + "]</a>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setText("<html>" + payload.toString() + shortCutHtml + variantsHtml + "</html>");
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -2093,7 +2093,15 @@
|
|||||||
</versionNumber>
|
</versionNumber>
|
||||||
<releaseDate>2018-12-26 00:00:00.000 CET</releaseDate>
|
<releaseDate>2018-12-26 00:00:00.000 CET</releaseDate>
|
||||||
<name></name>
|
<name></name>
|
||||||
<changes>
|
<changes>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>NEW_FEATURE</changeType>
|
||||||
|
<description>Multi-section Electrolytic "Can" Capacitor added</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>NEW_FEATURE</changeType>
|
||||||
|
<description>Added visual indicator to the component tree showing how many variants, if any, exist for a component</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>BUG_FIX</changeType>
|
<changeType>BUG_FIX</changeType>
|
||||||
<description>Fix "Mouse Wheel Zoom" feature that got broken in 3.46.1</description>
|
<description>Fix "Mouse Wheel Zoom" feature that got broken in 3.46.1</description>
|
||||||
|
|||||||
Reference in New Issue
Block a user