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:
Branislav Stojkovic
2019-01-07 10:35:55 +01:00
parent 54b0519f09
commit 8be8c23213
6 changed files with 92 additions and 60 deletions
Binary file not shown.
@@ -57,20 +57,20 @@ import org.diylc.utils.Constants;
@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",
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;
public static Color BODY_COLOR = Color.decode("#6B6DCE");
public static Color BASE_COLOR = Color.decode("#333333");
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 PIN_COLOR = METAL_COLOR;// Color.decode("#00B2EE");
// public static Color PIN_BORDER_COLOR = PIN_COLOR.darker();
public static Color LABEL_COLOR = Color.white;
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 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 Capacitance[] value = new Capacitance[3];
@@ -83,11 +83,12 @@ public class ElectrolyticCanCapacitor extends AbstractTransparentComponent<Capac
private Color baseColor = BASE_COLOR;
private Color borderColor = BORDER_COLOR;
private Color labelColor = LABEL_COLOR;
private Color pinColor = PIN_COLOR;
protected Display display = Display.NAME;
// private Size pinSpacing = PIN_SPACING;
private Size diameter = BODY_DIAMETER;
public ElectrolyticCanCapacitor() {
public MultiSectionCapacitor() {
super();
updateControlPoints();
}
@@ -184,9 +185,7 @@ public class ElectrolyticCanCapacitor extends AbstractTransparentComponent<Capac
}
private void updateControlPoints() {
// int pinSpacing = (int) getPinSpacing().convertToPixels();
int pinSpacing = (int) (getDiameter().convertToPixels() * RELATIVE_DIAMETER);
// switch (getS)
int pinSpacing = (int) (getDiameter().convertToPixels() * RELATIVE_DIAMETERS[value == null || value.length == 1 ? 0 : 1]);
int newCount = value.length + 1;
if (newCount != controlPoints.length) {
@@ -206,69 +205,68 @@ public class ElectrolyticCanCapacitor extends AbstractTransparentComponent<Capac
if (newCount == 2) {
switch (orientation) {
case DEFAULT:
controlPoints[1].setLocation(x + pinSpacing, y);
break;
case _90:
controlPoints[1].setLocation(x, y + pinSpacing);
break;
case _180:
case _90:
controlPoints[1].setLocation(x - pinSpacing, y);
break;
case _270:
case _180:
controlPoints[1].setLocation(x, y- pinSpacing);
break;
case _270:
controlPoints[1].setLocation(x + pinSpacing, y);
break;
default:
throw new RuntimeException("Unexpected orientation: " + orientation);
}
} else if (newCount == 3) {
switch (orientation) {
case DEFAULT:
controlPoints[1].setLocation(x + pinSpacing / 2, y - pinSpacing / 2);
controlPoints[2].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);
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);
break;
case _180:
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;
case _270:
controlPoints[1].setLocation(x - pinSpacing / 2, y - pinSpacing / 2);
controlPoints[2].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);
break;
default:
throw new RuntimeException("Unexpected orientation: " + orientation);
}
} else {
double theta = Math.PI * 2 / newCount;
double centerX;
double centerY;
double theta0;
switch (orientation) {
case DEFAULT:
centerX = x + pinSpacing / 2;
centerY = y;
theta0 = -Math.PI;
break;
case _90:
centerX = x;
centerY = y + pinSpacing / 2;
theta0 = -Math.PI / 2;
break;
case _180:
case _90:
centerX = x - pinSpacing / 2;
centerY = y;
theta0 = 0;
break;
case _270:
case _180:
centerX = x;
centerY = y - pinSpacing / 2;
theta0 = Math.PI / 2;
break;
case _270:
centerX = x + pinSpacing / 2;
centerY = y;
theta0 = -Math.PI;
break;
default:
throw new RuntimeException("Unexpected orientation: " + orientation);
}
@@ -285,49 +283,46 @@ public class ElectrolyticCanCapacitor extends AbstractTransparentComponent<Capac
double centerY;
int x = controlPoints[0].x;
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) {
switch (orientation) {
case DEFAULT:
centerX = x + pinSpacing / 2;
centerY = y;
break;
case _90:
centerX = x;
centerY = y + pinSpacing / 2;
break;
case _180:
case _90:
centerX = x - pinSpacing / 2;
centerY = y;
break;
case _270:
case _180:
centerX = x;
centerY = y - pinSpacing / 2;
break;
case _270:
centerX = x + pinSpacing / 2;
centerY = y;
break;
default:
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 {
switch (orientation) {
case DEFAULT:
centerX = x + pinSpacing / 2;
centerY = y;
break;
case _90:
centerX = x;
centerY = y + pinSpacing / 2;
break;
case _180:
case _90:
centerX = x - pinSpacing / 2;
centerY = y;
break;
case _270:
case _180:
centerX = x;
centerY = y - pinSpacing / 2;
break;
case _270:
centerX = x + pinSpacing / 2;
centerY = y;
break;
default:
throw new RuntimeException("Unexpected orientation: " + orientation);
}
@@ -382,10 +377,10 @@ public class ElectrolyticCanCapacitor extends AbstractTransparentComponent<Capac
for (Point point : controlPoints) {
if (!outlineMode) {
g2d.setColor(PIN_COLOR);
g2d.setColor(pinColor);
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);
}
@@ -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);
// draw polarity markers
g2d.setColor(PIN_BORDER_COLOR);
g2d.setColor(pinColor.darker());
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2f));
double markerSize = pinSize * 0.7;
for (int i = 0; i < controlPoints.length; i++) {
@@ -509,4 +504,13 @@ public class ElectrolyticCanCapacitor extends AbstractTransparentComponent<Capac
public void setDisplay(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,7 +149,7 @@ public class TreePanel extends JPanel {
Collections.sort(blockNames);
if (!blockNames.equals(TreePanel.this.blocks)) {
LOG.info("Detected block change");
refreshBlocks(blockNames);
refreshBuildingBlocks(blockNames);
} else
LOG.info("Detected no block change");
} else
@@ -157,6 +157,15 @@ public class TreePanel extends JPanel {
}
});
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);
}
@@ -194,7 +203,7 @@ public class TreePanel extends JPanel {
if (newBlocks != null) {
List<String> blockNames = new ArrayList<String>(newBlocks.keySet());
Collections.sort(blockNames);
refreshBlocks(blockNames);
refreshBuildingBlocks(blockNames);
this.blocks = blockNames;
} else {
this.blocks = new ArrayList<String>();
@@ -235,7 +244,7 @@ public class TreePanel extends JPanel {
getTreeModel().nodeStructureChanged(getRecentNode());
}
private void refreshBlocks(List<String> blocks) {
private void refreshBuildingBlocks(List<String> blocks) {
getBlocksNode().removeAllChildren();
for (final String block : blocks) {
Payload payload = new Payload(block, new MouseAdapter() {
@@ -598,6 +607,9 @@ public class TreePanel extends JPanel {
setPreferredSize(new Dimension(0, 0));
}
String shortCutHtml = "";
String variantsHtml = "";
if (payload.isVisible()) {
HashMap<String, String> shortcutMap =
(HashMap<String, String>) ConfigurationManager.getInstance().readObject(TreePanel.COMPONENT_SHORTCUT_KEY,
@@ -608,14 +620,22 @@ public class TreePanel extends JPanel {
if (shortcutMap != null && shortcutMap.containsValue(identifier)) {
for (String key : shortcutMap.keySet()) {
if (shortcutMap.get(key).equals(identifier)) {
setText("<html>"
+ payload.toString()
+ " <a style=\"text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black; background-color: #eeeeee; color: #666666;\"><sup>&nbsp;"
+ key + "&nbsp;</sup></a></html>");
shortCutHtml = " <a style=\"text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black; background-color: #eeeeee; color: #666666;\">&nbsp;"
+ key + "&nbsp;</a>";
}
}
}
}
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;
+8
View File
@@ -2094,6 +2094,14 @@
<releaseDate>2018-12-26 00:00:00.000 CET</releaseDate>
<name></name>
<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>
<changeType>BUG_FIX</changeType>
<description>Fix "Mouse Wheel Zoom" feature that got broken in 3.46.1</description>