Added "Sub-Mini" tube

This commit is contained in:
bancika
2020-04-15 19:53:10 +02:00
parent a18a226020
commit e78c6148c7
6 changed files with 574 additions and 535 deletions
@@ -2938,6 +2938,10 @@
<changeType>NEW_FEATURE</changeType> <changeType>NEW_FEATURE</changeType>
<description>Added "Find" functionality that locates and selects component(s) matching the search text</description> <description>Added "Find" functionality that locates and selects component(s) matching the search text</description>
</org.diylc.appframework.update.Change> </org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Added "Sub-Mini" tube</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change> <org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType> <changeType>NEW_FEATURE</changeType>
<description>Added "Tag Strip" component for point-to-point layouts</description> <description>Added "Tag Strip" component for point-to-point layouts</description>
Binary file not shown.
@@ -1,23 +1,20 @@
/* /*
*
DIY Layout Creator (DIYLC). * DIY Layout Creator (DIYLC). Copyright (c) 2009-2018 held jointly by the individual authors.
Copyright (c) 2009-2018 held jointly by the individual authors. *
* This file is part of DIYLC.
This file is part of DIYLC. *
* DIYLC is free software: you can redistribute it and/or modify it under the terms of the GNU
DIYLC is free software: you can redistribute it and/or modify * General Public License as published by the Free Software Foundation, either version 3 of the
it under the terms of the GNU General Public License as published by * License, or (at your option) any later version.
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
DIYLC is distributed in the hope that it will be useful, * Public License for more details.
but WITHOUT ANY WARRANTY; without even the implied warranty of *
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * You should have received a copy of the GNU General Public License along with DIYLC. If not, see
GNU General Public License for more details. * <http://www.gnu.org/licenses/>.
*
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.tube; package org.diylc.components.tube;
@@ -32,6 +29,7 @@ import java.awt.Shape;
import java.awt.geom.Area; import java.awt.geom.Area;
import java.awt.geom.Ellipse2D; import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
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;
@@ -53,31 +51,33 @@ 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;
//@ComponentDescriptor(name = "Sub-Mini Tube", author = "Branislav Stojkovic", category = "Tubes", instanceNamePrefix = "V", description = "Sub-miniature (pencil) vacuum tube", stretchable = false, zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = TO220Transformer.class) @ComponentDescriptor(name = "Sub-Mini Tube", author = "Branislav Stojkovic", category = "Tubes",
instanceNamePrefix = "V", description = "Sub-miniature (pencil) vacuum tube",
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE,
transformer = TO220Transformer.class)
public class SubminiTube extends AbstractTransparentComponent<String> { public class SubminiTube extends AbstractTransparentComponent<String> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public static Color BODY_COLOR = Color.lightGray; public static Color BODY_COLOR = Color.decode("#DDDDDD");
public static Color BORDER_COLOR = Color.gray; public static Color BORDER_COLOR = Color.gray;
public static Color PIN_COLOR = Color.decode("#00B2EE"); public static Color PIN_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.black;
public static Size PIN_SIZE = new Size(0.03d, SizeUnit.in); public static Size LEAD_SPACING = new Size(0.1d, SizeUnit.in);
public static Size PIN_SPACING = new Size(0.1d, SizeUnit.in);
public static Size BODY_WIDTH = new Size(0.4d, SizeUnit.in); public static Size BODY_WIDTH = new Size(0.4d, SizeUnit.in);
public static Size BODY_THICKNESS = new Size(4.5d, SizeUnit.mm); public static Size BODY_THICKNESS = new Size(4.5d, SizeUnit.mm);
public static Size BODY_HEIGHT = new Size(9d, SizeUnit.mm); public static Size BODY_HEIGHT = new Size(9d, SizeUnit.mm);
public static Size DIAMETER = new Size(0.4d, SizeUnit.in); public static Size DIAMETER = new Size(0.4d, SizeUnit.in);
public static Size LENGTH = new Size(1.375d, SizeUnit.in); public static Size LENGTH = new Size(1.375d, SizeUnit.in);
public static Size LEAD_LENGTH = new Size(0.2d, SizeUnit.in); public static Size LEAD_LENGTH = new Size(0.4d, SizeUnit.in);
public static Size LEAD_THICKNESS = new Size(0.8d, SizeUnit.mm); public static Size LEAD_THICKNESS = new Size(0.4d, SizeUnit.mm);
public static Size EDGE_RADIUS = new Size(2d, SizeUnit.mm);
private String value = ""; private String value = "";
private Orientation orientation = Orientation.DEFAULT; private Orientation orientation = Orientation.DEFAULT;
private Point[] controlPoints = new Point[] { new Point(0, 0), private Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0)};
new Point(0, 0), new Point(0, 0) }; transient private Area[] body;
transient private Shape[] body;
private Color bodyColor = BODY_COLOR; private Color bodyColor = BODY_COLOR;
private Color borderColor = BORDER_COLOR; private Color borderColor = BORDER_COLOR;
private Display display = Display.NAME; private Display display = Display.NAME;
@@ -88,7 +88,8 @@ public class SubminiTube extends AbstractTransparentComponent<String> {
private Size diameter = DIAMETER; private Size diameter = DIAMETER;
private Size length = LENGTH; private Size length = LENGTH;
private PinCount pinCount = PinCount._8; private PinCount pinCount = PinCount._8;
private Size leadSpacing = PIN_SPACING; private Size leadSpacing = LEAD_SPACING;
private Color labelColor = LABEL_COLOR;
public SubminiTube() { public SubminiTube() {
super(); super();
@@ -133,7 +134,7 @@ public class SubminiTube extends AbstractTransparentComponent<String> {
@Override @Override
public VisibilityPolicy getControlPointVisibilityPolicy(int index) { public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
return VisibilityPolicy.NEVER; return VisibilityPolicy.ALWAYS;
} }
@Override @Override
@@ -143,11 +144,12 @@ public class SubminiTube extends AbstractTransparentComponent<String> {
} }
private void updateControlPoints() { private void updateControlPoints() {
int pinSpacing = (int) PIN_SPACING.convertToPixels(); int leadSpacing = (int) getLeadSpacing().convertToPixels();
// Update control points. // Update control points.
int x = controlPoints[0].x; int x = controlPoints[0].x;
int y = controlPoints[0].y; int y = controlPoints[0].y;
int newPointCount = getPinCount().getValue(); int newPointCount = getPinCount().getValue()
+ ((getPinArrangement() == PinArrangement.Circular && !folded) || getTopLead() ? 1 : 0);
// Need a new array // Need a new array
if (newPointCount != controlPoints.length) { if (newPointCount != controlPoints.length) {
controlPoints = new Point[newPointCount]; controlPoints = new Point[newPointCount];
@@ -155,185 +157,184 @@ public class SubminiTube extends AbstractTransparentComponent<String> {
controlPoints[i] = new Point(x, y); controlPoints[i] = new Point(x, y);
} }
} }
double length = getLength().convertToPixels();
double leadLength = getLeadLength().convertToPixels();
double diameter = getDiameter().convertToPixels();
int dx; int dx;
int dy; int dy;
if (folded) { if (folded || getPinArrangement() == PinArrangement.Inline) {
switch (orientation) { switch (orientation) {
case DEFAULT: case DEFAULT:
dx = 0; dx = 0;
dy = pinSpacing; dy = leadSpacing;
break; break;
case _90: case _90:
dx = -pinSpacing; dx = -leadSpacing;
dy = 0; dy = 0;
break; break;
case _180: case _180:
dx = 0; dx = 0;
dy = -pinSpacing; dy = -leadSpacing;
break; break;
case _270: case _270:
dx = pinSpacing; dx = leadSpacing;
dy = 0; dy = 0;
break; break;
default: default:
throw new RuntimeException("Unexpected orientation: " throw new RuntimeException("Unexpected orientation: " + orientation);
+ orientation);
} }
for (int i = 1; i < controlPoints.length; i++) { for (int i = 1; i < controlPoints.length; i++) {
controlPoints[i].setLocation(controlPoints[0].x + i * dx, controlPoints[0].y + i * dy); controlPoints[i].setLocation(controlPoints[0].x + i * dx, controlPoints[0].y + i * dy);
} }
} else { if (getTopLead()) {
int centerX = (controlPoints[controlPoints.length - 2].x + x) / 2;
int centerY = (controlPoints[controlPoints.length - 2].y + y) / 2;
switch (orientation) { switch (orientation) {
case DEFAULT: case DEFAULT:
controlPoints[1].setLocation(x, y + pinSpacing); if (folded)
controlPoints[2].setLocation(x, y + 2 * pinSpacing); dx += length + leadLength + diameter / 2;
else
dx = -leadSpacing;
dy = 0;
break; break;
case _90: case _90:
controlPoints[1].setLocation(x - pinSpacing, y); dx = 0;
controlPoints[2].setLocation(x - 2 * pinSpacing, y); if (folded)
dy += length + leadLength + diameter / 2;
else
dy = -leadSpacing;
break; break;
case _180: case _180:
controlPoints[1].setLocation(x, y - pinSpacing); if (folded)
controlPoints[2].setLocation(x, y - 2 * pinSpacing); dx -= length + leadLength + diameter / 2;
else
dx = leadSpacing;
dy = 0;
break; break;
case _270: case _270:
controlPoints[1].setLocation(x + pinSpacing, y); dx = 0;
controlPoints[2].setLocation(x + 2 * pinSpacing, y); if (folded)
dy -= length + leadLength + diameter / 2;
else
dy = leadSpacing;
break; break;
default: }
throw new RuntimeException("Unexpected orientation: " controlPoints[controlPoints.length - 1].setLocation(centerX + dx, centerY + dy);
+ orientation); }
} else {
int pinCount = getPinCount().getValue();
Point firstPoint = controlPoints[0];
double angleIncrement = Math.PI * 2 / (pinCount + 1);
double initialAngleOffset = angleIncrement;
double r = (pinCount + 1) * leadSpacing / (2 * Math.PI);
controlPoints = new Point[pinCount + 1];
double theta = initialAngleOffset + getOrientation().toRadians();
controlPoints[0] = firstPoint;
for (int i = 0; i < pinCount; i++) {
controlPoints[i + 1] = new Point((int) (firstPoint.getX() + Math.cos(theta) * r),
(int) (firstPoint.getY() + Math.sin(theta) * r));
theta += angleIncrement;
} }
} }
} }
public Shape[] getBody() { public Area[] getBody() {
if (body == null) { if (body == null) {
body = new Shape[2]; body = new Area[2];
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(); double length = getLength().convertToPixels();
int bodyWidth = getClosestOdd(BODY_WIDTH.convertToPixels());
int bodyThickness = getClosestOdd(BODY_THICKNESS.convertToPixels());
int bodyHeight = getClosestOdd(BODY_HEIGHT.convertToPixels());
int tabThickness = 0; // (int) TAB_THICKNESS.convertToPixels();
int tabHeight = 0;// (int) TAB_HEIGHT.convertToPixels();
int tabHoleDiameter = 0;// (int)
// TAB_HOLE_DIAMETER.convertToPixels();
double leadLength = getLeadLength().convertToPixels(); double leadLength = getLeadLength().convertToPixels();
double diameter = getDiameter().convertToPixels();
double edgeRadius = EDGE_RADIUS.convertToPixels();
int centerX;
int centerY;
if (getPinArrangement() == PinArrangement.Circular && !folded) {
centerX = x;
centerY = y;
} else {
centerX = (controlPoints[controlPoints.length - (getTopLead() ? 2 : 1)].x + x) / 2;
centerY = (controlPoints[controlPoints.length - (getTopLead() ? 2 : 1)].y + y) / 2;
}
if (folded) {
switch (orientation) { switch (orientation) {
case DEFAULT: case DEFAULT:
if (folded) { body[0] = new Area(new RoundRectangle2D.Double(centerX + leadLength, centerY - diameter / 2,
body[0] = new Rectangle2D.Double(x + leadLength, y length, diameter, edgeRadius, edgeRadius));
+ pinSpacing - bodyWidth / 2, bodyHeight, bodyWidth); body[0].add(new Area(new RoundRectangle2D.Double(centerX + leadLength + length - diameter / 2, centerY - diameter / 8,
body[1] = new Area(new Rectangle2D.Double(x + leadLength diameter, diameter / 4, diameter / 4, diameter / 4)));
+ bodyHeight, y + pinSpacing - bodyWidth / 2,
tabHeight, bodyWidth));
((Area) body[1]).subtract(new Area(new Ellipse2D.Double(x
+ leadLength + bodyHeight + tabHeight / 2
- tabHoleDiameter / 2, y + pinSpacing
- tabHoleDiameter / 2, tabHoleDiameter,
tabHoleDiameter)));
} else {
body[0] = new Rectangle2D.Double(x - bodyThickness / 2, y
+ pinSpacing - bodyWidth / 2, bodyThickness,
bodyWidth);
body[1] = new Rectangle2D.Double(x + bodyThickness / 2
- tabThickness, y + pinSpacing - bodyWidth / 2,
tabThickness, bodyWidth);
}
break; break;
case _90: case _90:
if (folded) { body[0] = new Area(new RoundRectangle2D.Double(centerX - diameter / 2, centerY + leadLength,
body[0] = new Rectangle2D.Double(x - pinSpacing - bodyWidth diameter, length, edgeRadius, edgeRadius));
/ 2, y + leadLength, bodyWidth, bodyHeight); body[0].add(new Area(new RoundRectangle2D.Double(centerX - diameter / 8, centerY + leadLength + length - diameter / 2,
body[1] = new Area(new Rectangle2D.Double(x - pinSpacing diameter / 4, diameter, diameter / 4, diameter / 4)));
- bodyWidth / 2, y + leadLength + bodyHeight,
bodyWidth, tabHeight));
((Area) body[1]).subtract(new Area(new Ellipse2D.Double(x
- pinSpacing - tabHoleDiameter / 2, y + leadLength
+ bodyHeight + tabHeight / 2 - tabHoleDiameter / 2,
tabHoleDiameter, tabHoleDiameter)));
} else {
body[0] = new Rectangle2D.Double(x - pinSpacing - bodyWidth
/ 2, y - bodyThickness / 2, bodyWidth,
bodyThickness);
body[1] = new Rectangle2D.Double(x - pinSpacing - bodyWidth
/ 2, y + bodyThickness / 2 - tabThickness,
bodyWidth, tabThickness);
}
break; break;
case _180: case _180:
if (folded) { body[0] = new Area(new RoundRectangle2D.Double(centerX - leadLength - length, centerY - diameter / 2,
body[0] = new Rectangle2D.Double(x - leadLength length, diameter, edgeRadius, edgeRadius));
- bodyHeight, y - pinSpacing - bodyWidth / 2, body[0].add(new Area(new RoundRectangle2D.Double(centerX - leadLength - length - diameter / 2, centerY - diameter / 8,
bodyHeight, bodyWidth); diameter, diameter / 4, diameter / 4, diameter / 4)));
body[1] = new Area(new Rectangle2D.Double(x - leadLength
- bodyHeight - tabHeight, y - pinSpacing
- bodyWidth / 2, tabHeight, bodyWidth));
((Area) body[1]).subtract(new Area(new Ellipse2D.Double(x
- leadLength - bodyHeight - tabHeight / 2
- tabHoleDiameter / 2, y - pinSpacing
- tabHoleDiameter / 2, tabHoleDiameter,
tabHoleDiameter)));
} else {
body[0] = new Rectangle2D.Double(x - bodyThickness / 2, y
- pinSpacing - bodyWidth / 2, bodyThickness,
bodyWidth);
body[1] = new Rectangle2D.Double(x - bodyThickness / 2, y
- pinSpacing - bodyWidth / 2, tabThickness,
bodyWidth);
}
break; break;
case _270: case _270:
if (folded) { body[0] = new Area(new RoundRectangle2D.Double(centerX - diameter / 2, centerY - leadLength - length,
body[0] = new Rectangle2D.Double(x + pinSpacing - bodyWidth diameter, length, edgeRadius, edgeRadius));
/ 2, y - leadLength - bodyHeight, bodyWidth, body[0].add(new Area(new RoundRectangle2D.Double(centerX - diameter / 8, centerY - leadLength - length - diameter / 2,
bodyHeight); diameter / 4, diameter, diameter / 4, diameter / 4)));
body[1] = new Area(new Rectangle2D.Double(x + pinSpacing
- bodyWidth / 2, y - leadLength - bodyHeight
- tabHeight, bodyWidth, tabHeight));
((Area) body[1]).subtract(new Area(new Ellipse2D.Double(x
+ pinSpacing - tabHoleDiameter / 2, y - leadLength
- bodyHeight - tabHeight / 2 - tabHoleDiameter / 2,
tabHoleDiameter, tabHoleDiameter)));
} else {
body[0] = new Rectangle2D.Double(x + pinSpacing - bodyWidth
/ 2, y - bodyThickness / 2, bodyWidth,
bodyThickness);
body[1] = new Rectangle2D.Double(x + pinSpacing - bodyWidth
/ 2, y - bodyThickness / 2, bodyWidth, tabThickness);
}
break; break;
default: default:
throw new RuntimeException("Unexpected orientation: " throw new RuntimeException("Unexpected orientation: " + orientation);
+ orientation); }
} else {
body[0] = new Area(new Ellipse2D.Double(centerX - diameter / 2, centerY - diameter / 2, diameter,
diameter));
} }
} }
return body; return body;
} }
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
boolean outlineMode, Project project, Project project, IDrawingObserver drawingObserver) {
IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) { if (checkPointsClipped(g2d.getClip())) {
return; return;
} }
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2; int pinSize = (int) LEAD_THICKNESS.convertToPixels() / 2 * 2;
Shape mainArea = getBody()[0]; Shape mainArea = getBody()[0];
Shape tabArea = getBody()[1];
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance( g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
} }
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : bodyColor); g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : bodyColor);
g2d.fill(mainArea); g2d.fill(mainArea);
Theme theme = (Theme) ConfigurationManager.getInstance().readObject( Color finalBorderColor;
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); 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));
g2d.draw(mainArea);
g2d.setComposite(oldComposite);
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY,
Constants.DEFAULT_THEME);
// Draw pins. // Draw pins.
@@ -344,76 +345,76 @@ public class SubminiTube extends AbstractTransparentComponent<String> {
Color finalPinBorderColor; Color finalPinBorderColor;
if (outlineMode) { if (outlineMode) {
finalPinColor = new Color(0, 0, 0, 0); finalPinColor = new Color(0, 0, 0, 0);
finalPinBorderColor = componentState == ComponentState.SELECTED finalPinBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
? SELECTION_COLOR
: theme.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalPinColor = METAL_COLOR; finalPinColor = METAL_COLOR;
finalPinBorderColor = METAL_COLOR.darker(); finalPinBorderColor = METAL_COLOR.darker();
} }
for (Point point : controlPoints) {
int centerX = (controlPoints[controlPoints.length - (getTopLead() ? 2 : 1)].x + controlPoints[0].x) / 2;
int centerY = (controlPoints[controlPoints.length - (getTopLead() ? 2 : 1)].y + controlPoints[0].y) / 2;
double increment = getDiameter().convertToPixels() / getPinCount().getValue();
if (orientation == Orientation._90 || orientation == Orientation._180)
increment = -increment;
double startX = centerX - increment * (getPinCount().getValue() - 1) / 2;
double startY = centerY - increment * (getPinCount().getValue() - 1) / 2;
for (int i = 0; i < controlPoints.length - (getTopLead() ? 1 : 0); i++) {
Point point = controlPoints[i];
switch (orientation) { switch (orientation) {
case DEFAULT: case DEFAULT:
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke( g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
leadThickness));
g2d.setColor(finalPinBorderColor); g2d.setColor(finalPinBorderColor);
g2d.drawLine(point.x, point.y, point.x + leadLength g2d.drawLine(point.x, point.y, point.x + leadLength - leadThickness / 2, (int)(startY + increment * i));
- leadThickness / 2, point.y); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
leadThickness - 2));
g2d.setColor(finalPinColor); g2d.setColor(finalPinColor);
g2d.drawLine(point.x, point.y, point.x + leadLength g2d.drawLine(point.x, point.y, point.x + leadLength - leadThickness / 2, (int)(startY + increment * i));
- leadThickness / 2, point.y);
break; break;
case _90: case _90:
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke( g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
leadThickness));
g2d.setColor(finalPinBorderColor); g2d.setColor(finalPinBorderColor);
g2d.drawLine(point.x, point.y, point.x, point.y g2d.drawLine(point.x, point.y, (int)(startX + increment * i), point.y + leadLength - leadThickness / 2);
+ leadLength - leadThickness / 2); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
leadThickness - 2));
g2d.setColor(finalPinColor); g2d.setColor(finalPinColor);
g2d.drawLine(point.x, point.y, point.x, point.y g2d.drawLine(point.x, point.y, (int)(startX + increment * i), point.y + leadLength - leadThickness / 2);
+ leadLength - leadThickness / 2);
break; break;
case _180: case _180:
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke( g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
leadThickness));
g2d.setColor(finalPinBorderColor); g2d.setColor(finalPinBorderColor);
g2d.drawLine(point.x, point.y, point.x - leadLength g2d.drawLine(point.x, point.y, point.x - leadLength - leadThickness / 2, (int)(startY + increment * i));
- leadThickness / 2, point.y); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
leadThickness - 2));
g2d.setColor(finalPinColor); g2d.setColor(finalPinColor);
g2d.drawLine(point.x, point.y, point.x - leadLength g2d.drawLine(point.x, point.y, point.x - leadLength - leadThickness / 2, (int)(startY + increment * i));
- leadThickness / 2, point.y);
break; break;
case _270: case _270:
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke( g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
leadThickness));
g2d.setColor(finalPinBorderColor); g2d.setColor(finalPinBorderColor);
g2d.drawLine(point.x, point.y, point.x, point.y g2d.drawLine(point.x, point.y, (int)(startX + increment * i), point.y - leadLength);
- leadLength); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
leadThickness - 2));
g2d.setColor(finalPinColor); g2d.setColor(finalPinColor);
g2d.drawLine(point.x, point.y, point.x, point.y g2d.drawLine(point.x, point.y, (int)(startX + increment * i), point.y - leadLength);
- leadLength);
break; break;
} }
} }
if (getTopLead()) {
Point point = controlPoints[controlPoints.length - 1];
g2d.setColor(PIN_COLOR);
g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
g2d.setColor(outlineMode ? theme.getOutlineColor() : PIN_BORDER_COLOR);
g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
}
} else { } else {
if (!outlineMode) { if (!outlineMode) {
for (Point point : controlPoints) { for (int i = getPinArrangement() == PinArrangement.Circular && !topLead ? 1
: 0; i < controlPoints.length; i++) {
Point point = controlPoints[i];
g2d.setColor(PIN_COLOR); g2d.setColor(PIN_COLOR);
g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
pinSize, pinSize); g2d.setColor(outlineMode ? theme.getOutlineColor() : PIN_BORDER_COLOR);
g2d.setColor(outlineMode ? theme.getOutlineColor() g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
: PIN_BORDER_COLOR);
g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2,
pinSize, pinSize);
} }
} }
} }
@@ -422,13 +423,15 @@ public class SubminiTube extends AbstractTransparentComponent<String> {
g2d.setFont(project.getFont()); g2d.setFont(project.getFont());
Color finalLabelColor; Color finalLabelColor;
if (outlineMode) { if (outlineMode) {
finalLabelColor = componentState == ComponentState.SELECTED finalLabelColor =
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
? LABEL_COLOR_SELECTED
: theme.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalLabelColor = componentState == ComponentState.SELECTED finalLabelColor =
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
: LABEL_COLOR; ? LABEL_COLOR_SELECTED
: getLabelColor();
} }
g2d.setColor(finalLabelColor); g2d.setColor(finalLabelColor);
String label = ""; String label = "";
@@ -437,8 +440,7 @@ public class SubminiTube extends AbstractTransparentComponent<String> {
label = ""; label = "";
} }
if (getDisplay() == Display.BOTH) { if (getDisplay() == Display.BOTH) {
label = getName() + " " label = getName() + " " + (getValue() == null ? "" : getValue().toString());
+ (getValue() == null ? "" : getValue().toString());
} }
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont()); FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
Rectangle2D rect = fontMetrics.getStringBounds(label, g2d); Rectangle2D rect = fontMetrics.getStringBounds(label, g2d);
@@ -447,37 +449,48 @@ public class SubminiTube extends AbstractTransparentComponent<String> {
// Center text horizontally and vertically // Center text horizontally and vertically
Rectangle bounds = mainArea.getBounds(); Rectangle bounds = mainArea.getBounds();
int x = bounds.x + (bounds.width - textWidth) / 2; int x = bounds.x + (bounds.width - textWidth) / 2;
int y = bounds.y + (bounds.height - textHeight) / 2 int y = bounds.y + (bounds.height - textHeight) / 2 + fontMetrics.getAscent();
+ fontMetrics.getAscent();
g2d.drawString(label, x, y); int dx = 0;
int dy = 0;
if (getPinArrangement() == PinArrangement.Inline || getTopLead()) {
switch (getOrientation()) {
case DEFAULT:
dx = (int) LEAD_THICKNESS.convertToPixels() * 4;
break;
case _90:
dy = (int) LEAD_THICKNESS.convertToPixels() * 4;
break;
case _180:
dx = -(int) LEAD_THICKNESS.convertToPixels() * 4;
break;
case _270:
dy = -(int) LEAD_THICKNESS.convertToPixels() * 4;
break;
}
}
g2d.drawString(label, x + dx, y + dy);
} }
@Override @Override
public void drawIcon(Graphics2D g2d, int width, int height) { public void drawIcon(Graphics2D g2d, int width, int height) {
int margin = 2 * width / 32; Area area = new Area(new Ellipse2D.Double(2, 2, width - 4, width - 4));
int bodySize = width * 5 / 10; int center = width / 2;
int tabSize = bodySize * 6 / 10;
int holeSize = 5 * width / 32;
Area a = new Area(new Rectangle2D.Double((width - bodySize) / 2,
margin, bodySize, tabSize));
a.subtract(new Area(new Ellipse2D.Double(width / 2 - holeSize / 2,
margin + tabSize / 2 - holeSize / 2, holeSize, holeSize)));
g2d.setColor(BORDER_COLOR);
g2d.draw(a);
g2d.setColor(BODY_COLOR); g2d.setColor(BODY_COLOR);
g2d.fillRect((width - bodySize) / 2, margin + tabSize, bodySize, g2d.fill(area);
bodySize); g2d.setColor(BODY_COLOR.darker());
g2d.setColor(BORDER_COLOR); g2d.draw(area);
g2d.drawRect((width - bodySize) / 2, margin + tabSize, bodySize,
bodySize); int radius = width / 2 - 7;
g2d.setColor(METAL_COLOR); for (int i = 1; i < 8; i++) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2)); int x = (int) (center + Math.cos(i * Math.PI / 4) * radius);
g2d.drawLine(width / 2, margin + tabSize + bodySize, width / 2, height int y = (int) (center + Math.sin(i * Math.PI / 4) * radius);
- margin); g2d.setColor(PIN_COLOR);
g2d.drawLine(width / 2 - bodySize / 3, margin + tabSize + bodySize, g2d.fillOval(x - 1, y - 1, 2, 2);
width / 2 - bodySize / 3, height - margin); g2d.setColor(PIN_BORDER_COLOR);
g2d.drawLine(width / 2 + bodySize / 3, margin + tabSize + bodySize, g2d.drawOval(x - 1, y - 1, 2, 2);
width / 2 + bodySize / 3, height - margin); }
} }
@EditableProperty(name = "Body") @EditableProperty(name = "Body")
@@ -505,6 +518,7 @@ public class SubminiTube extends AbstractTransparentComponent<String> {
public void setFolded(boolean folded) { public void setFolded(boolean folded) {
this.folded = folded; this.folded = folded;
updateControlPoints();
// Invalidate the body // Invalidate the body
this.body = null; this.body = null;
} }
@@ -542,6 +556,9 @@ public class SubminiTube extends AbstractTransparentComponent<String> {
public void setPinArrangement(PinArrangement pinArrangement) { public void setPinArrangement(PinArrangement pinArrangement) {
this.leadArrangement = pinArrangement; this.leadArrangement = pinArrangement;
updateControlPoints();
// invalidate the body
this.body = null;
} }
@EditableProperty(name = "Top Lead") @EditableProperty(name = "Top Lead")
@@ -581,6 +598,8 @@ public class SubminiTube extends AbstractTransparentComponent<String> {
public void setPinCount(PinCount pinCount) { public void setPinCount(PinCount pinCount) {
this.pinCount = pinCount; this.pinCount = pinCount;
updateControlPoints(); updateControlPoints();
// invalidate the body
this.body = null;
} }
@EditableProperty(name = "Lead Spacing") @EditableProperty(name = "Lead Spacing")
@@ -591,6 +610,22 @@ public class SubminiTube extends AbstractTransparentComponent<String> {
public void setLeadSpacing(Size leadSpacing) { public void setLeadSpacing(Size leadSpacing) {
this.leadSpacing = leadSpacing; this.leadSpacing = leadSpacing;
updateControlPoints(); updateControlPoints();
// invalidate the body
this.body = null;
}
@EditableProperty(name = "Label")
public Color getLabelColor() {
return labelColor;
}
public void setLabelColor(Color labelColor) {
this.labelColor = labelColor;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
} }
public static enum PinArrangement { public static enum PinArrangement {
@@ -343,9 +343,9 @@ public class TubeSocket extends AbstractTransparentComponent<String> {
Area area = new Area(new Ellipse2D.Double(1, 1, width - 2, width - 2)); Area area = new Area(new Ellipse2D.Double(1, 1, width - 2, width - 2));
int center = width / 2; int center = width / 2;
area.subtract(new Area(new Ellipse2D.Double(center - 2, center - 2, 5, 5))); area.subtract(new Area(new Ellipse2D.Double(center - 2, center - 2, 5, 5)));
g2d.setColor(getColor()); g2d.setColor(BODY_COLOR);
g2d.fill(area); g2d.fill(area);
g2d.setColor(getColor().darker()); g2d.setColor(BODY_COLOR.darker());
g2d.draw(area); g2d.draw(area);
int radius = width / 2 - 6; int radius = width / 2 - 6;
Binary file not shown.
Binary file not shown.