better scaling

added marshall board and trimmer
This commit is contained in:
bancika
2011-02-03 21:47:16 +00:00
parent 02d38bed01
commit 6eee1525ee
34 changed files with 576 additions and 104 deletions
@@ -27,7 +27,7 @@ public abstract class AbstractBoard extends AbstractTransparentComponent<String>
protected String value = "";
protected Point[] controlPoints = new Point[] { new Point(0, 0),
new Point(DEFAULT_WIDTH.convertToPixels(), DEFAULT_HEIGHT.convertToPixels()) };
new Point((int) DEFAULT_WIDTH.convertToPixels(), (int) DEFAULT_HEIGHT.convertToPixels()) };
protected Point firstPoint = new Point();
protected Point secondPoint = new Point();
@@ -40,9 +40,9 @@ public class EyeletBoard extends AbstractBoard {
/ MAX_ALPHA));
}
Point p = new Point(firstPoint);
int diameter = getClosestOdd(EYELET_SIZE.convertToPixels());
int holeDiameter = getClosestOdd(HOLE_SIZE.convertToPixels());
int spacing = this.spacing.convertToPixels();
int diameter = getClosestOdd((int) EYELET_SIZE.convertToPixels());
int holeDiameter = getClosestOdd((int) HOLE_SIZE.convertToPixels());
int spacing = (int) this.spacing.convertToPixels();
while (p.y < secondPoint.y - spacing) {
p.x = firstPoint.x;
@@ -0,0 +1,86 @@
package org.diylc.components.boards;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Marshall Style Perf Board", category = "Boards", author = "Branislav Stojkovic", zOrder = IDIYComponent.BOARD, instanceNamePrefix = "Board", description = "Perforated board as found on some Marshall and Trainwreck amps")
public class MarshallPerfBoard extends AbstractBoard {
private static final long serialVersionUID = 1L;
public static Color BOARD_COLOR = Color.decode("#CD8500");
public static Color BORDER_COLOR = BOARD_COLOR.darker();
public static Size SPACING = new Size(3 / 8d, SizeUnit.in);
public static Size HOLE_SIZE = new Size(1 / 8d, SizeUnit.in);
// private Area copperArea;
protected Size spacing = SPACING;
public MarshallPerfBoard() {
super();
this.boardColor = BOARD_COLOR;
this.borderColor = BORDER_COLOR;
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
super.draw(g2d, componentState, project, drawingObserver);
if (componentState != ComponentState.DRAGGING) {
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
/ MAX_ALPHA));
}
Point p = new Point(firstPoint);
int holeDiameter = getClosestOdd((int) HOLE_SIZE.convertToPixels());
int spacing = (int) this.spacing.convertToPixels();
while (p.y < secondPoint.y - spacing) {
p.x = firstPoint.x;
p.y += spacing;
while (p.x < secondPoint.x - spacing) {
p.x += spacing;
g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(p.x - holeDiameter / 2, p.y - holeDiameter / 2, holeDiameter,
holeDiameter);
g2d.setColor(borderColor);
g2d.drawOval(p.x - holeDiameter / 2, p.y - holeDiameter / 2, holeDiameter,
holeDiameter);
}
}
}
}
@EditableProperty
public Size getSpacing() {
return spacing;
}
public void setSpacing(Size spacing) {
this.spacing = spacing;
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.setColor(BOARD_COLOR);
g2d.fillRect(2, 2, width - 4, height - 4);
g2d.setColor(BORDER_COLOR);
g2d.drawRect(2, 2, width - 4, height - 4);
g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(width / 2 - 2, width / 2 - 2, 5, 5);
g2d.setColor(BORDER_COLOR);
g2d.drawOval(width / 2 - 2, width / 2 - 2, 5, 5);
}
}
@@ -40,9 +40,9 @@ public class PerfBoard extends AbstractBoard {
/ MAX_ALPHA));
}
Point p = new Point(firstPoint);
int diameter = getClosestOdd(PAD_SIZE.convertToPixels());
int holeDiameter = getClosestOdd(HOLE_SIZE.convertToPixels());
int spacing = this.spacing.convertToPixels();
int diameter = getClosestOdd((int) PAD_SIZE.convertToPixels());
int holeDiameter = getClosestOdd((int) HOLE_SIZE.convertToPixels());
int spacing = (int) this.spacing.convertToPixels();
while (p.y < secondPoint.y - spacing) {
p.x = firstPoint.x;
@@ -43,18 +43,18 @@ public class VeroBoard extends AbstractBoard {
/ MAX_ALPHA));
}
Point p = new Point(firstPoint);
int stripSize = getClosestOdd(STRIP_SIZE.convertToPixels());
int holeSize = getClosestOdd(HOLE_SIZE.convertToPixels());
int spacing = this.spacing.convertToPixels();
int stripSize = getClosestOdd((int) STRIP_SIZE.convertToPixels());
int holeSize = getClosestOdd((int) HOLE_SIZE.convertToPixels());
int spacing = (int) this.spacing.convertToPixels();
while (p.y < secondPoint.y - spacing) {
p.x = firstPoint.x;
p.y += spacing;
g2d.setColor(stripColor);
g2d.fillRect(p.x + SPACING.convertToPixels() / 2, p.y - stripSize / 2,
g2d.fillRect(p.x + spacing / 2, p.y - stripSize / 2,
secondPoint.x - spacing - p.x, stripSize);
g2d.setColor(stripColor.darker());
g2d.drawRect(p.x + SPACING.convertToPixels() / 2, p.y - stripSize / 2,
g2d.drawRect(p.x + spacing / 2, p.y - stripSize / 2,
secondPoint.x - spacing - p.x, stripSize);
while (p.x < secondPoint.x - spacing) {
p.x += spacing;
@@ -64,7 +64,7 @@ public class CopperTrace extends AbstractLeadedComponent<Void> {
@Override
protected int getLeadThickness() {
return getThickness().convertToPixels();
return (int) getThickness().convertToPixels();
}
@Override
@@ -30,7 +30,7 @@ public class CurvedTrace extends AbstractCurvedComponent<Void> {
@Override
protected void drawCurve(CubicCurve2D curve, Graphics2D g2d, ComponentState componentState) {
int thickness = size.convertToPixels();
int thickness = (int) size.convertToPixels();
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(thickness));
g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : color);
@@ -34,8 +34,8 @@ public class Eyelet extends AbstractComponent<String> {
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
int diameter = getClosestOdd(size.convertToPixels());
int holeDiameter = getClosestOdd(holeSize.convertToPixels());
int diameter = getClosestOdd((int) size.convertToPixels());
int holeDiameter = getClosestOdd((int) holeSize.convertToPixels());
g2d.setColor(color);
g2d.fillOval(point.x - diameter / 2, point.y - diameter / 2, diameter, diameter);
g2d.setColor(componentState == ComponentState.SELECTED
@@ -33,8 +33,8 @@ public class SolderPad extends AbstractComponent<Void> {
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
int diameter = getClosestOdd(size.convertToPixels());
int holeDiameter = getClosestOdd(HOLE_SIZE.convertToPixels());
int diameter = getClosestOdd((int) size.convertToPixels());
int holeDiameter = getClosestOdd((int) HOLE_SIZE.convertToPixels());
g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : color);
if (type == Type.ROUND) {
@@ -35,7 +35,7 @@ public class TraceCut extends AbstractComponent<Void> {
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
int size = getClosestOdd(this.size.convertToPixels());
int size = getClosestOdd((int) this.size.convertToPixels());
int dotDiameter = size - 6;
g2d.setColor(fillColor);
g2d.fillRect(point.x - size / 2, point.y - size / 2, size, size);
@@ -48,7 +48,7 @@ public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchT
private void updateControlPoints() {
Point firstPoint = controlPoints[0];
int spacing = SPACING.convertToPixels();
int spacing = (int) SPACING.convertToPixels();
switch (switchType) {
case SPST:
controlPoints = new Point[] { firstPoint,
@@ -187,9 +187,9 @@ public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchT
// so far.
drawingObserver.stopTracking();
// Draw lugs.
int circleDiameter = getClosestOdd(CIRCLE_SIZE.convertToPixels());
int lugWidth = getClosestOdd(LUG_WIDTH.convertToPixels());
int lugHeight = getClosestOdd(LUG_HEIGHT.convertToPixels());
int circleDiameter = getClosestOdd((int) CIRCLE_SIZE.convertToPixels());
int lugWidth = getClosestOdd((int) LUG_WIDTH.convertToPixels());
int lugHeight = getClosestOdd((int) LUG_HEIGHT.convertToPixels());
for (Point p : controlPoints) {
g2d.setColor(CIRCLE_COLOR);
g2d.fillOval(p.x - circleDiameter / 2, p.y - circleDiameter / 2, circleDiameter,
@@ -202,8 +202,8 @@ public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchT
public RoundRectangle2D getBody() {
if (body == null) {
Point firstPoint = controlPoints[0];
int margin = MARGIN.convertToPixels();
int spacing = SPACING.convertToPixels();
int margin = (int) MARGIN.convertToPixels();
int spacing = (int) SPACING.convertToPixels();
switch (switchType) {
case SPST:
body = new RoundRectangle2D.Double(firstPoint.x - margin, firstPoint.y - margin,
@@ -73,9 +73,9 @@ public class BOM extends AbstractComponent<Void> {
}
}
// Calculate maximum entry size.
int maxEntrySize = maxNameWidth + maxValueWidth + 2 * SPACING.convertToPixels();
int columnCount = size.convertToPixels() / maxEntrySize;
int columnWidth = size.convertToPixels() / columnCount;
int maxEntrySize = maxNameWidth + maxValueWidth + 2 * (int) SPACING.convertToPixels();
int columnCount = (int) size.convertToPixels() / maxEntrySize;
int columnWidth = (int) size.convertToPixels() / columnCount;
int entriesPerColumn = (int) Math.ceil(1.d * bom.size() / columnCount);
if (entriesPerColumn == 0) {
g2d.drawString(DEFAULT_TEXT, point.x, point.y);
@@ -122,11 +122,11 @@ public class AxialElectrolyticCapacitor extends AbstractLeadedComponent<Capacita
int markerLength = (int) (getLength().convertToPixels() * 0.2);
g2d.setColor(markerColor);
int width = getClosestOdd(getWidth().convertToPixels());
g2d.fillRect(getLength().convertToPixels() - markerLength, 0, markerLength, width);
g2d.fillRect((int) getLength().convertToPixels() - markerLength, 0, markerLength, width);
g2d.setColor(tickColor);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2));
g2d.drawLine(getLength().convertToPixels() - markerLength / 2,
(int) (width / 2 - width * 0.15), getLength().convertToPixels() - markerLength
g2d.drawLine((int) getLength().convertToPixels() - markerLength / 2,
(int) (width / 2 - width * 0.15), (int) getLength().convertToPixels() - markerLength
/ 2, (int) (width / 2 + width * 0.15));
}
}
@@ -47,7 +47,7 @@ public class PotentiometerPanel extends AbstractPotentiometer {
}
protected void updateControlPoints() {
int spacing = this.spacing.convertToPixels();
int spacing = (int) this.spacing.convertToPixels();
switch (orientation) {
case DEFAULT:
controlPoints[1].setLocation(controlPoints[0].x + spacing, controlPoints[0].y);
@@ -71,7 +71,7 @@ public class PotentiometerPanel extends AbstractPotentiometer {
}
public Area[] getBody() {
int spacing = this.spacing.convertToPixels();
int spacing = (int) this.spacing.convertToPixels();
int diameter = getClosestOdd(bodyDiameter.convertToPixels());
if (body == null) {
body = new Area[7];
@@ -0,0 +1,372 @@
package org.diylc.components.passive;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import org.diylc.common.ObjectCache;
import org.diylc.common.Orientation;
import org.diylc.core.ComponentState;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Trimmer Potentiometer", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.SINGLE_CLICK, instanceNamePrefix = "VR", description = "Various types of board mounted trimmer potentiometers", zOrder = IDIYComponent.COMPONENT, stretchable = false)
public class TrimmerPotentiometer extends AbstractPotentiometer {
private static final long serialVersionUID = 1L;
protected static Size FLAT_BODY_SIZE = new Size(9.5d, SizeUnit.mm);
protected static Size FLAT_SHAFT_SIZE = new Size(4d, SizeUnit.mm);
protected static Size VERTICAL_BODY_LENGTH = new Size(9.5d, SizeUnit.mm);
protected static Size VERTICAL_BODY_WIDTH = new Size(4.5d, SizeUnit.mm);
protected static Size SPACING = new Size(0.1d, SizeUnit.in);
private static Color BODY_COLOR = Color.decode("#FFFFE0");
private static Color BORDER_COLOR = Color.decode("#8E8E38");
private static Color SHAFT_COLOR = Color.decode("#FFFFE0");
private static Color SHAFT_BORDER_COLOR = Color.decode("#8E8E38");
public static Color PIN_COLOR = Color.decode("#00B2EE");
public static Color PIN_BORDER_COLOR = PIN_COLOR.darker();
public static Size PIN_SIZE = new Size(0.03d, SizeUnit.in);
protected Color bodyColor = BODY_COLOR;
protected Color borderColor = BORDER_COLOR;
// Array of 7 elements: 3 lug connectors, 1 pot body and 3 lugs
transient protected Shape[] body = null;
protected TrimmerType type = TrimmerType.FLAT_SMALL;
public TrimmerPotentiometer() {
controlPoints = new Point[] { new Point(0, 0), new Point(0, 0), new Point(0, 0) };
updateControlPoints();
}
protected void updateControlPoints() {
int spacing = (int) SPACING.convertToPixels();
int dx1 = 0;
int dy1 = 0;
int dx2 = 0;
int dy2 = 0;
switch (orientation) {
case DEFAULT:
switch (type) {
case FLAT_SMALL:
dx1 = 2 * spacing;
dy1 = spacing;
dx2 = 0;
dy2 = 2 * spacing;
break;
case FLAT_LARGE:
dx1 = 4 * spacing;
dy1 = spacing;
dx2 = 0;
dy2 = 2 * spacing;
break;
case VERTICAL_INLINE:
dx1 = 0;
dy1 = spacing;
dx2 = 0;
dy2 = 2 * spacing;
break;
case VERTICAL_OFFSET:
dx1 = spacing;
dy1 = spacing;
dx2 = 0;
dy2 = 2 * spacing;
break;
}
break;
case _90:
switch (type) {
case FLAT_SMALL:
dx1 = -spacing;
dy1 = 2 * spacing;
dx2 = -2 * spacing;
dy2 = 0;
break;
case FLAT_LARGE:
dx1 = -spacing;
dy1 = 4 * spacing;
dx2 = -2 * spacing;
dy2 = 0;
break;
case VERTICAL_INLINE:
dx1 = -spacing;
dy1 = 0;
dx2 = -2 * spacing;
dy2 = 0;
break;
case VERTICAL_OFFSET:
dx1 = -spacing;
dy1 = spacing;
dx2 = -2 * spacing;
dy2 = 0;
break;
}
break;
case _180:
switch (type) {
case FLAT_SMALL:
dx1 = -2 * spacing;
dy1 = -spacing;
dx2 = 0;
dy2 = -2 * spacing;
break;
case FLAT_LARGE:
dx1 = -4 * spacing;
dy1 = -spacing;
dx2 = 0;
dy2 = -2 * spacing;
break;
case VERTICAL_INLINE:
dx1 = 0;
dy1 = -spacing;
dx2 = 0;
dy2 = -2 * spacing;
break;
case VERTICAL_OFFSET:
dx1 = -spacing;
dy1 = -spacing;
dx2 = 0;
dy2 = -2 * spacing;
break;
}
break;
case _270:
switch (type) {
case FLAT_SMALL:
dx1 = spacing;
dy1 = -2 * spacing;
dx2 = 2 * spacing;
dy2 = 0;
break;
case FLAT_LARGE:
dx1 = spacing;
dy1 = -4 * spacing;
dx2 = 2 * spacing;
dy2 = 0;
break;
case VERTICAL_INLINE:
dx1 = spacing;
dy1 = 0;
dx2 = 2 * spacing;
dy2 = 0;
break;
case VERTICAL_OFFSET:
dx1 = spacing;
dy1 = -spacing;
dx2 = 2 * spacing;
dy2 = 0;
break;
}
break;
default:
break;
}
controlPoints[1].setLocation(controlPoints[0].x + dx1, controlPoints[0].y + dy1);
controlPoints[2].setLocation(controlPoints[0].x + dx2, controlPoints[0].y + dy2);
}
public Shape[] getBody() {
if (body == null) {
body = new Shape[2];
// Calculate the center point as center of the minimum bounding
// rectangle.
int centerX = (Math.max(Math.max(controlPoints[0].x, controlPoints[1].x),
controlPoints[2].x) + Math.min(
Math.min(controlPoints[0].x, controlPoints[1].x), controlPoints[2].x)) / 2;
int centerY = (Math.max(Math.max(controlPoints[0].y, controlPoints[1].y),
controlPoints[2].y) + Math.min(
Math.min(controlPoints[0].y, controlPoints[1].y), controlPoints[2].y)) / 2;
// Calculate body dimensions based on the selected type.
int length = 0;
int width = 0;
switch (type) {
case FLAT_LARGE:
case FLAT_SMALL:
length = getClosestOdd(FLAT_BODY_SIZE.convertToPixels());
width = length;
int shaftSize = getClosestOdd(FLAT_SHAFT_SIZE.convertToPixels());
Area shaft = new Area(new Ellipse2D.Double(centerX - shaftSize / 2, centerY
- shaftSize / 2, shaftSize, shaftSize));
Area slot = new Area(new Rectangle2D.Double(centerX - shaftSize / 2, centerY
- shaftSize / 8, shaftSize, shaftSize / 4));
slot.transform(AffineTransform.getRotateInstance(Math.PI / 4, centerX, centerY));
shaft.subtract(slot);
body[1] = shaft;
break;
case VERTICAL_INLINE:
case VERTICAL_OFFSET:
length = getClosestOdd(VERTICAL_BODY_LENGTH.convertToPixels());
width = getClosestOdd(VERTICAL_BODY_WIDTH.convertToPixels());
break;
}
if (orientation == Orientation.DEFAULT || orientation == Orientation._180) {
int p = length;
length = width;
width = p;
}
body[0] = new Rectangle2D.Double(centerX - length / 2, centerY - width / 2, length,
width);
}
return body;
}
@Override
public void setControlPoint(Point point, int index) {
super.setControlPoint(point, index);
body = null;
}
@Override
public void setOrientation(Orientation orientation) {
super.setOrientation(orientation);
updateControlPoints();
body = null;
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
Shape mainShape = getBody()[0];
Shape shaftShape = getBody()[1];
if (mainShape != null) {
g2d.setColor(bodyColor);
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
/ MAX_ALPHA));
}
g2d.fill(mainShape);
if (shaftShape != null) {
g2d.setColor(SHAFT_COLOR);
g2d.fill(shaftShape);
g2d.setColor(SHAFT_BORDER_COLOR);
g2d.draw(shaftShape);
}
g2d.setComposite(oldComposite);
g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor);
g2d.draw(mainShape);
}
// Draw pins.
int pinSize = getClosestOdd(PIN_SIZE.convertToPixels());
for (Point point : controlPoints) {
g2d.setColor(PIN_COLOR);
g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
g2d.setColor(PIN_BORDER_COLOR);
g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
}
// Draw label.
g2d.setFont(LABEL_FONT);
g2d
.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED
: LABEL_COLOR);
FontMetrics fontMetrics = g2d.getFontMetrics();
Rectangle2D bodyRect = getBody()[0].getBounds2D();
Rectangle2D rect = fontMetrics.getStringBounds(getName(), g2d);
int textHeight = (int) rect.getHeight();
int textWidth = (int) rect.getWidth();
int panelHeight = (int) bodyRect.getHeight();
int panelWidth = (int) bodyRect.getWidth();
int x = (panelWidth - textWidth) / 2;
int y = (panelHeight - textHeight) / 2 + fontMetrics.getAscent();
g2d.drawString(getName(), (int) (bodyRect.getX() + x), (int) (bodyRect.getY() + y));
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
int margin = 4;
g2d.setColor(BODY_COLOR);
g2d.fillRect(margin, margin, width - 2 * margin, width - 2 * margin);
g2d.setColor(BORDER_COLOR);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.drawRect(margin, margin, width - 2 * margin, width - 2 * margin);
int shaftSize = 11;
int slotSize = 2;
Area area = new Area(new Ellipse2D.Double(width / 2 - shaftSize / 2, width / 2 - shaftSize / 2,
shaftSize, shaftSize));
Area slot = new Area(new Rectangle2D.Double(0, width / 2 - slotSize / 2, width, slotSize));
slot.transform(AffineTransform.getRotateInstance(Math.PI / 4, width / 2, width / 2));
area.subtract(slot);
g2d.setColor(SHAFT_COLOR);
g2d.fill(area);
g2d.setColor(SHAFT_BORDER_COLOR);
g2d.draw(area);
int pinSize = 3;
g2d.setColor(PIN_COLOR);
g2d.fillOval(margin - pinSize / 2, 10 - pinSize / 2, pinSize, pinSize);
g2d.setColor(PIN_BORDER_COLOR);
g2d.drawOval(margin - pinSize / 2, 10 - pinSize / 2, pinSize, pinSize);
g2d.setColor(PIN_COLOR);
g2d.fillOval(margin - pinSize / 2, 21 - pinSize / 2, pinSize, pinSize);
g2d.setColor(PIN_BORDER_COLOR);
g2d.drawOval(margin - pinSize / 2, 21 - pinSize / 2, pinSize, pinSize);
g2d.setColor(PIN_COLOR);
g2d.fillOval(width - margin - pinSize / 2, width / 2 - pinSize / 2, pinSize, pinSize);
g2d.setColor(PIN_BORDER_COLOR);
g2d.drawOval(width - margin - pinSize / 2, width / 2 - pinSize / 2, pinSize, pinSize);
}
@EditableProperty(name = "Body")
public Color getBodyColor() {
return bodyColor;
}
public void setBodyColor(Color bodyColor) {
this.bodyColor = bodyColor;
}
@EditableProperty(name = "Border")
public Color getBorderColor() {
return borderColor;
}
public void setBorderColor(Color borderColor) {
this.borderColor = borderColor;
}
@EditableProperty
public TrimmerType getType() {
return type;
}
public void setType(TrimmerType type) {
this.type = type;
updateControlPoints();
body = null;
}
public static enum TrimmerType {
FLAT_LARGE, FLAT_SMALL, VERTICAL_INLINE, VERTICAL_OFFSET;
@Override
public String toString() {
return name().substring(0, 1) + name().substring(1).toLowerCase().replace("_", " ");
}
}
}
@@ -146,6 +146,8 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
Point firstPoint = controlPoints[0];
controlPoints = new Point[pinCount.getValue()];
controlPoints[0] = firstPoint;
int pinSpacing = (int) this.pinSpacing.convertToPixels();
int rowSpacing = (int) this.rowSpacing.convertToPixels();
// Update control points.
int dx1;
int dy1;
@@ -155,27 +157,27 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
switch (orientation) {
case DEFAULT:
dx1 = 0;
dy1 = i * pinSpacing.convertToPixels();
dx2 = rowSpacing.convertToPixels();
dy2 = i * pinSpacing.convertToPixels();
dy1 = i * pinSpacing;
dx2 = rowSpacing;
dy2 = i * pinSpacing;
break;
case _90:
dx1 = -i * pinSpacing.convertToPixels();
dx1 = -i * pinSpacing;
dy1 = 0;
dx2 = -i * pinSpacing.convertToPixels();
dy2 = rowSpacing.convertToPixels();
dx2 = -i * pinSpacing;
dy2 = rowSpacing;
break;
case _180:
dx1 = 0;
dy1 = -i * pinSpacing.convertToPixels();
dx2 = -rowSpacing.convertToPixels();
dy2 = -i * pinSpacing.convertToPixels();
dy1 = -i * pinSpacing;
dx2 = -rowSpacing;
dy2 = -i * pinSpacing;
break;
case _270:
dx1 = i * pinSpacing.convertToPixels();
dx1 = i * pinSpacing;
dy1 = 0;
dx2 = i * pinSpacing.convertToPixels();
dy2 = -rowSpacing.convertToPixels();
dx2 = i * pinSpacing;
dy2 = -rowSpacing;
break;
default:
throw new RuntimeException("Unexpected orientation: " + orientation);
@@ -193,39 +195,41 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
int y = controlPoints[0].y;
int width;
int height;
int pinSize = PIN_SIZE.convertToPixels();
int pinSize = (int) PIN_SIZE.convertToPixels();
int pinSpacing = (int) this.pinSpacing.convertToPixels();
int rowSpacing = (int) this.rowSpacing.convertToPixels();
Area indentation = null;
int indentationSize = getClosestOdd(INDENT_SIZE.convertToPixels());
switch (orientation) {
case DEFAULT:
width = rowSpacing.convertToPixels() - pinSize;
height = (pinCount.getValue() / 2) * pinSpacing.convertToPixels();
width = rowSpacing - pinSize;
height = (pinCount.getValue() / 2) * pinSpacing;
x += pinSize / 2;
y -= pinSpacing.convertToPixels() / 2;
y -= pinSpacing / 2;
indentation = new Area(new Ellipse2D.Double(x + width / 2 - indentationSize / 2, y
- indentationSize / 2, indentationSize, indentationSize));
break;
case _90:
width = (pinCount.getValue() / 2) * pinSpacing.convertToPixels();
height = rowSpacing.convertToPixels() - pinSize;
x -= (pinSpacing.convertToPixels() / 2) + width - pinSpacing.convertToPixels();
width = (pinCount.getValue() / 2) * pinSpacing;
height = rowSpacing - pinSize;
x -= (pinSpacing / 2) + width - pinSpacing;
y += pinSize / 2;
indentation = new Area(new Ellipse2D.Double(x + width - indentationSize / 2, y
+ height / 2 - indentationSize / 2, indentationSize, indentationSize));
break;
case _180:
width = rowSpacing.convertToPixels() - pinSize;
height = (pinCount.getValue() / 2) * pinSpacing.convertToPixels();
x -= rowSpacing.convertToPixels() - pinSize / 2;
y -= (pinSpacing.convertToPixels() / 2) + height - pinSpacing.convertToPixels();
width = rowSpacing - pinSize;
height = (pinCount.getValue() / 2) * pinSpacing;
x -= rowSpacing - pinSize / 2;
y -= (pinSpacing / 2) + height - pinSpacing;
indentation = new Area(new Ellipse2D.Double(x + width / 2 - indentationSize / 2, y
+ height - indentationSize / 2, indentationSize, indentationSize));
break;
case _270:
width = (pinCount.getValue() / 2) * pinSpacing.convertToPixels();
height = rowSpacing.convertToPixels() - pinSize;
x -= pinSpacing.convertToPixels() / 2;
y += pinSize / 2 - rowSpacing.convertToPixels();
width = (pinCount.getValue() / 2) * pinSpacing;
height = rowSpacing - pinSize;
x -= pinSpacing / 2;
y += pinSize / 2 - rowSpacing;
indentation = new Area(new Ellipse2D.Double(x - indentationSize / 2, y + height / 2
- indentationSize / 2, indentationSize, indentationSize));
break;
@@ -245,7 +249,7 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
int pinSize = PIN_SIZE.convertToPixels() / 2 * 2;
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
Area mainArea = getBody()[0];
for (Point point : controlPoints) {
g2d.setColor(PIN_COLOR);
@@ -77,8 +77,8 @@ public class DiodePlastic extends AbstractLeadedComponent<String> {
@Override
protected void decorateComponentBody(Graphics2D g2d) {
g2d.setColor(markerColor);
int width = getLength().convertToPixels();
int markerWidth = MARKER_WIDTH.convertToPixels();
int width = (int) getLength().convertToPixels();
int markerWidth = (int) MARKER_WIDTH.convertToPixels();
g2d.fillRect(width - markerWidth, 0, markerWidth, getClosestOdd(getWidth()
.convertToPixels()));
}
@@ -103,7 +103,7 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
}
private void updateControlPoints() {
int pinSpacing = PIN_SPACING.convertToPixels();
int pinSpacing = (int) PIN_SPACING.convertToPixels();
// Update control points.
int x = controlPoints[0].x;
int y = controlPoints[0].y;
@@ -134,10 +134,10 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
body = new Shape[2];
int x = controlPoints[0].x;
int y = controlPoints[0].y;
int pinSpacing = PIN_SPACING.convertToPixels();
int pinSpacing = (int) PIN_SPACING.convertToPixels();
int bodyWidth = getClosestOdd(BODY_WIDTH.convertToPixels());
int bodyHeight = getClosestOdd(BODY_HEIGHT.convertToPixels());
int tabThickness = TAB_THICKNESS.convertToPixels();
int tabThickness = (int) TAB_THICKNESS.convertToPixels();
switch (orientation) {
case DEFAULT:
@@ -174,7 +174,7 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
int pinSize = PIN_SIZE.convertToPixels() / 2 * 2;
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
Shape mainArea = getBody()[0];
Shape tabArea = getBody()[1];
Composite oldComposite = g2d.getComposite();
@@ -194,6 +194,7 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor);
g2d.draw(mainArea);
// Draw pins.
for (Point point : controlPoints) {
g2d.setColor(PIN_COLOR);
g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
@@ -98,7 +98,7 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
}
private void updateControlPoints() {
int pinSpacing = PIN_SPACING.convertToPixels();
int pinSpacing = (int) PIN_SPACING.convertToPixels();
// Update control points.
int x = controlPoints[0].x;
int y = controlPoints[0].y;
@@ -128,7 +128,7 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
if (body == null) {
int x = controlPoints[0].x;
int y = controlPoints[0].y;
int pinSpacing = PIN_SPACING.convertToPixels();
int pinSpacing = (int) PIN_SPACING.convertToPixels();
int bodyDiameter = getClosestOdd(BODY_DIAMETER.convertToPixels());
switch (orientation) {
@@ -166,7 +166,7 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
int pinSize = PIN_SIZE.convertToPixels() / 2 * 2;
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
Area mainArea = getBody();
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {