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>
<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>
<changeType>NEW_FEATURE</changeType>
<description>Added "Sub-Mini" tube</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Added "Tag Strip" component for point-to-point layouts</description>
Binary file not shown.
@@ -1,23 +1,20 @@
/*
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/>.
*
* 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.tube;
@@ -32,6 +29,7 @@ import java.awt.Shape;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.common.Display;
@@ -53,31 +51,33 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
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> {
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 PIN_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.03d, SizeUnit.in);
public static Size PIN_SPACING = new Size(0.1d, SizeUnit.in);
public static Color LABEL_COLOR = Color.black;
public static Size LEAD_SPACING = new Size(0.1d, 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_HEIGHT = new Size(9d, SizeUnit.mm);
public static Size DIAMETER = new Size(0.4d, 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_THICKNESS = new Size(0.8d, SizeUnit.mm);
public static Size LEAD_LENGTH = new Size(0.4d, SizeUnit.in);
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 Orientation orientation = Orientation.DEFAULT;
private Point[] controlPoints = new Point[] { new Point(0, 0),
new Point(0, 0), new Point(0, 0) };
transient private Shape[] body;
private Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0)};
transient private Area[] body;
private Color bodyColor = BODY_COLOR;
private Color borderColor = BORDER_COLOR;
private Display display = Display.NAME;
@@ -88,7 +88,8 @@ public class SubminiTube extends AbstractTransparentComponent<String> {
private Size diameter = DIAMETER;
private Size length = LENGTH;
private PinCount pinCount = PinCount._8;
private Size leadSpacing = PIN_SPACING;
private Size leadSpacing = LEAD_SPACING;
private Color labelColor = LABEL_COLOR;
public SubminiTube() {
super();
@@ -133,7 +134,7 @@ public class SubminiTube extends AbstractTransparentComponent<String> {
@Override
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
return VisibilityPolicy.NEVER;
return VisibilityPolicy.ALWAYS;
}
@Override
@@ -143,11 +144,12 @@ public class SubminiTube extends AbstractTransparentComponent<String> {
}
private void updateControlPoints() {
int pinSpacing = (int) PIN_SPACING.convertToPixels();
int leadSpacing = (int) getLeadSpacing().convertToPixels();
// Update control points.
int x = controlPoints[0].x;
int y = controlPoints[0].y;
int newPointCount = getPinCount().getValue();
int newPointCount = getPinCount().getValue()
+ ((getPinArrangement() == PinArrangement.Circular && !folded) || getTopLead() ? 1 : 0);
// Need a new array
if (newPointCount != controlPoints.length) {
controlPoints = new Point[newPointCount];
@@ -155,185 +157,184 @@ public class SubminiTube extends AbstractTransparentComponent<String> {
controlPoints[i] = new Point(x, y);
}
}
double length = getLength().convertToPixels();
double leadLength = getLeadLength().convertToPixels();
double diameter = getDiameter().convertToPixels();
int dx;
int dy;
if (folded) {
if (folded || getPinArrangement() == PinArrangement.Inline) {
switch (orientation) {
case DEFAULT:
dx = 0;
dy = pinSpacing;
dy = leadSpacing;
break;
case _90:
dx = -pinSpacing;
dx = -leadSpacing;
dy = 0;
break;
case _180:
dx = 0;
dy = -pinSpacing;
dy = -leadSpacing;
break;
case _270:
dx = pinSpacing;
dx = leadSpacing;
dy = 0;
break;
default:
throw new RuntimeException("Unexpected orientation: "
+ orientation);
throw new RuntimeException("Unexpected orientation: " + orientation);
}
for (int i = 1; i < controlPoints.length; i++) {
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) {
case DEFAULT:
controlPoints[1].setLocation(x, y + pinSpacing);
controlPoints[2].setLocation(x, y + 2 * pinSpacing);
if (folded)
dx += length + leadLength + diameter / 2;
else
dx = -leadSpacing;
dy = 0;
break;
case _90:
controlPoints[1].setLocation(x - pinSpacing, y);
controlPoints[2].setLocation(x - 2 * pinSpacing, y);
dx = 0;
if (folded)
dy += length + leadLength + diameter / 2;
else
dy = -leadSpacing;
break;
case _180:
controlPoints[1].setLocation(x, y - pinSpacing);
controlPoints[2].setLocation(x, y - 2 * pinSpacing);
if (folded)
dx -= length + leadLength + diameter / 2;
else
dx = leadSpacing;
dy = 0;
break;
case _270:
controlPoints[1].setLocation(x + pinSpacing, y);
controlPoints[2].setLocation(x + 2 * pinSpacing, y);
dx = 0;
if (folded)
dy -= length + leadLength + diameter / 2;
else
dy = leadSpacing;
break;
default:
throw new RuntimeException("Unexpected orientation: "
+ orientation);
}
controlPoints[controlPoints.length - 1].setLocation(centerX + dx, centerY + dy);
}
} 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) {
body = new Shape[2];
body = new Area[2];
int x = controlPoints[0].x;
int y = controlPoints[0].y;
int pinSpacing = (int) PIN_SPACING.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 length = getLength().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) {
case DEFAULT:
if (folded) {
body[0] = new Rectangle2D.Double(x + leadLength, y
+ pinSpacing - bodyWidth / 2, bodyHeight, bodyWidth);
body[1] = new Area(new Rectangle2D.Double(x + leadLength
+ 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);
}
body[0] = new Area(new RoundRectangle2D.Double(centerX + leadLength, centerY - diameter / 2,
length, diameter, edgeRadius, edgeRadius));
body[0].add(new Area(new RoundRectangle2D.Double(centerX + leadLength + length - diameter / 2, centerY - diameter / 8,
diameter, diameter / 4, diameter / 4, diameter / 4)));
break;
case _90:
if (folded) {
body[0] = new Rectangle2D.Double(x - pinSpacing - bodyWidth
/ 2, y + leadLength, bodyWidth, bodyHeight);
body[1] = new Area(new Rectangle2D.Double(x - pinSpacing
- 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);
}
body[0] = new Area(new RoundRectangle2D.Double(centerX - diameter / 2, centerY + leadLength,
diameter, length, edgeRadius, edgeRadius));
body[0].add(new Area(new RoundRectangle2D.Double(centerX - diameter / 8, centerY + leadLength + length - diameter / 2,
diameter / 4, diameter, diameter / 4, diameter / 4)));
break;
case _180:
if (folded) {
body[0] = new Rectangle2D.Double(x - leadLength
- bodyHeight, y - pinSpacing - bodyWidth / 2,
bodyHeight, bodyWidth);
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);
}
body[0] = new Area(new RoundRectangle2D.Double(centerX - leadLength - length, centerY - diameter / 2,
length, diameter, edgeRadius, edgeRadius));
body[0].add(new Area(new RoundRectangle2D.Double(centerX - leadLength - length - diameter / 2, centerY - diameter / 8,
diameter, diameter / 4, diameter / 4, diameter / 4)));
break;
case _270:
if (folded) {
body[0] = new Rectangle2D.Double(x + pinSpacing - bodyWidth
/ 2, y - leadLength - bodyHeight, bodyWidth,
bodyHeight);
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);
}
body[0] = new Area(new RoundRectangle2D.Double(centerX - diameter / 2, centerY - leadLength - length,
diameter, length, edgeRadius, edgeRadius));
body[0].add(new Area(new RoundRectangle2D.Double(centerX - diameter / 8, centerY - leadLength - length - diameter / 2,
diameter / 4, diameter, diameter / 4, diameter / 4)));
break;
default:
throw new RuntimeException("Unexpected orientation: "
+ orientation);
throw new RuntimeException("Unexpected orientation: " + orientation);
}
} else {
body[0] = new Area(new Ellipse2D.Double(centerX - diameter / 2, centerY - diameter / 2, diameter,
diameter));
}
}
return body;
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState,
boolean outlineMode, Project project,
IDrawingObserver drawingObserver) {
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) {
return;
}
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
int pinSize = (int) LEAD_THICKNESS.convertToPixels() / 2 * 2;
Shape mainArea = getBody()[0];
Shape tabArea = getBody()[1];
Composite oldComposite = g2d.getComposite();
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));
}
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : bodyColor);
g2d.fill(mainArea);
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
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));
g2d.draw(mainArea);
g2d.setComposite(oldComposite);
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY,
Constants.DEFAULT_THEME);
// Draw pins.
@@ -344,76 +345,76 @@ public class SubminiTube extends AbstractTransparentComponent<String> {
Color finalPinBorderColor;
if (outlineMode) {
finalPinColor = new Color(0, 0, 0, 0);
finalPinBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR
finalPinBorderColor =
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
? SELECTION_COLOR
: theme.getOutlineColor();
} else {
finalPinColor = METAL_COLOR;
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) {
case DEFAULT:
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
leadThickness));
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
g2d.setColor(finalPinBorderColor);
g2d.drawLine(point.x, point.y, point.x + leadLength
- leadThickness / 2, point.y);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
leadThickness - 2));
g2d.drawLine(point.x, point.y, point.x + leadLength - leadThickness / 2, (int)(startY + increment * i));
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
g2d.setColor(finalPinColor);
g2d.drawLine(point.x, point.y, point.x + leadLength
- leadThickness / 2, point.y);
g2d.drawLine(point.x, point.y, point.x + leadLength - leadThickness / 2, (int)(startY + increment * i));
break;
case _90:
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
leadThickness));
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
g2d.setColor(finalPinBorderColor);
g2d.drawLine(point.x, point.y, point.x, point.y
+ leadLength - leadThickness / 2);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
leadThickness - 2));
g2d.drawLine(point.x, point.y, (int)(startX + increment * i), point.y + leadLength - leadThickness / 2);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
g2d.setColor(finalPinColor);
g2d.drawLine(point.x, point.y, point.x, point.y
+ leadLength - leadThickness / 2);
g2d.drawLine(point.x, point.y, (int)(startX + increment * i), point.y + leadLength - leadThickness / 2);
break;
case _180:
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
leadThickness));
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
g2d.setColor(finalPinBorderColor);
g2d.drawLine(point.x, point.y, point.x - leadLength
- leadThickness / 2, point.y);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
leadThickness - 2));
g2d.drawLine(point.x, point.y, point.x - leadLength - leadThickness / 2, (int)(startY + increment * i));
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
g2d.setColor(finalPinColor);
g2d.drawLine(point.x, point.y, point.x - leadLength
- leadThickness / 2, point.y);
g2d.drawLine(point.x, point.y, point.x - leadLength - leadThickness / 2, (int)(startY + increment * i));
break;
case _270:
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
leadThickness));
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
g2d.setColor(finalPinBorderColor);
g2d.drawLine(point.x, point.y, point.x, point.y
- leadLength);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
leadThickness - 2));
g2d.drawLine(point.x, point.y, (int)(startX + increment * i), point.y - leadLength);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
g2d.setColor(finalPinColor);
g2d.drawLine(point.x, point.y, point.x, point.y
- leadLength);
g2d.drawLine(point.x, point.y, (int)(startX + increment * i), point.y - leadLength);
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 {
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.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);
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);
}
}
}
@@ -422,13 +423,15 @@ public class SubminiTube extends AbstractTransparentComponent<String> {
g2d.setFont(project.getFont());
Color finalLabelColor;
if (outlineMode) {
finalLabelColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
finalLabelColor =
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
? LABEL_COLOR_SELECTED
: theme.getOutlineColor();
} else {
finalLabelColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: LABEL_COLOR;
finalLabelColor =
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
? LABEL_COLOR_SELECTED
: getLabelColor();
}
g2d.setColor(finalLabelColor);
String label = "";
@@ -437,8 +440,7 @@ public class SubminiTube extends AbstractTransparentComponent<String> {
label = "";
}
if (getDisplay() == Display.BOTH) {
label = getName() + " "
+ (getValue() == null ? "" : getValue().toString());
label = getName() + " " + (getValue() == null ? "" : getValue().toString());
}
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
Rectangle2D rect = fontMetrics.getStringBounds(label, g2d);
@@ -447,37 +449,48 @@ public class SubminiTube extends AbstractTransparentComponent<String> {
// 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);
int y = bounds.y + (bounds.height - textHeight) / 2 + fontMetrics.getAscent();
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
public void drawIcon(Graphics2D g2d, int width, int height) {
int margin = 2 * width / 32;
int bodySize = width * 5 / 10;
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);
Area area = new Area(new Ellipse2D.Double(2, 2, width - 4, width - 4));
int center = width / 2;
g2d.setColor(BODY_COLOR);
g2d.fillRect((width - bodySize) / 2, margin + tabSize, bodySize,
bodySize);
g2d.setColor(BORDER_COLOR);
g2d.drawRect((width - bodySize) / 2, margin + tabSize, bodySize,
bodySize);
g2d.setColor(METAL_COLOR);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2));
g2d.drawLine(width / 2, margin + tabSize + bodySize, width / 2, height
- margin);
g2d.drawLine(width / 2 - bodySize / 3, margin + tabSize + bodySize,
width / 2 - bodySize / 3, height - margin);
g2d.drawLine(width / 2 + bodySize / 3, margin + tabSize + bodySize,
width / 2 + bodySize / 3, height - margin);
g2d.fill(area);
g2d.setColor(BODY_COLOR.darker());
g2d.draw(area);
int radius = width / 2 - 7;
for (int i = 1; i < 8; i++) {
int x = (int) (center + Math.cos(i * Math.PI / 4) * radius);
int y = (int) (center + Math.sin(i * Math.PI / 4) * radius);
g2d.setColor(PIN_COLOR);
g2d.fillOval(x - 1, y - 1, 2, 2);
g2d.setColor(PIN_BORDER_COLOR);
g2d.drawOval(x - 1, y - 1, 2, 2);
}
}
@EditableProperty(name = "Body")
@@ -505,6 +518,7 @@ public class SubminiTube extends AbstractTransparentComponent<String> {
public void setFolded(boolean folded) {
this.folded = folded;
updateControlPoints();
// Invalidate the body
this.body = null;
}
@@ -542,6 +556,9 @@ public class SubminiTube extends AbstractTransparentComponent<String> {
public void setPinArrangement(PinArrangement pinArrangement) {
this.leadArrangement = pinArrangement;
updateControlPoints();
// invalidate the body
this.body = null;
}
@EditableProperty(name = "Top Lead")
@@ -581,6 +598,8 @@ public class SubminiTube extends AbstractTransparentComponent<String> {
public void setPinCount(PinCount pinCount) {
this.pinCount = pinCount;
updateControlPoints();
// invalidate the body
this.body = null;
}
@EditableProperty(name = "Lead Spacing")
@@ -591,6 +610,22 @@ public class SubminiTube extends AbstractTransparentComponent<String> {
public void setLeadSpacing(Size leadSpacing) {
this.leadSpacing = leadSpacing;
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 {
@@ -343,9 +343,9 @@ public class TubeSocket extends AbstractTransparentComponent<String> {
Area area = new Area(new Ellipse2D.Double(1, 1, width - 2, width - 2));
int center = width / 2;
area.subtract(new Area(new Ellipse2D.Double(center - 2, center - 2, 5, 5)));
g2d.setColor(getColor());
g2d.setColor(BODY_COLOR);
g2d.fill(area);
g2d.setColor(getColor().darker());
g2d.setColor(BODY_COLOR.darker());
g2d.draw(area);
int radius = width / 2 - 6;
Binary file not shown.
Binary file not shown.