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];
@@ -82,12 +82,13 @@ public class ElectrolyticCanCapacitor extends AbstractTransparentComponent<Capac
private Color bodyColor = BODY_COLOR;
private Color baseColor = BASE_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;
// 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);
break;
case _90:
case DEFAULT:
controlPoints[1].setLocation(x + pinSpacing / 2, y + pinSpacing / 2);
controlPoints[2].setLocation(x - pinSpacing / 2, y + pinSpacing / 2);
break;
case _180:
case _90:
controlPoints[1].setLocation(x - pinSpacing / 2, y - pinSpacing / 2);
controlPoints[2].setLocation(x - pinSpacing / 2, y + pinSpacing / 2);
break;
case _270:
case _180:
controlPoints[1].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);
break;
default:
throw new RuntimeException("Unexpected orientation: " + orientation);
}
} else {
double theta = Math.PI * 2 / newCount;
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:
case DEFAULT:
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:
case DEFAULT:
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:
case DEFAULT:
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++) {
@@ -508,5 +503,14 @@ 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;
}
}