don't group pasted components

fix: click twice on a building block makes components jump to top-left
various minor updates
This commit is contained in:
Branislav Stojkovic
2018-12-25 16:49:18 +01:00
parent 48a6857738
commit e9615d4d64
25 changed files with 2963 additions and 2331 deletions
@@ -38,7 +38,7 @@ import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Chassis Panel", author = "Branislav Stojkovic", category = "Electromechanical",
@ComponentDescriptor(name = "Chassis Panel", author = "Branislav Stojkovic", category = "Electro-Mechanical",
instanceNamePrefix = "CP", description = "One side of a chassis, with or withouth rounded edges",
zOrder = IDIYComponent.CHASSIS, bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false,
transformer = SimpleComponentTransformer.class)
@@ -1,75 +1,75 @@
/*
*
* 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.chassis;
import java.awt.AlphaComposite;
import java.awt.Composite;
import java.awt.Graphics2D;
import org.diylc.common.ObjectCache;
import org.diylc.common.SimpleComponentTransformer;
import org.diylc.components.shapes.AbstractShape;
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.BomPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
@ComponentDescriptor(name = "Elliptical Cutout", author = "Branislav Stojkovic", category = "Electromechanical",
instanceNamePrefix = "ELC", description = "Elliptical chassis cutout", zOrder = IDIYComponent.CHASSIS + 0.1,
bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false, transformer = SimpleComponentTransformer.class)
public class EllipticalCutout extends AbstractShape {
private static final long serialVersionUID = 1L;
public EllipticalCutout() {
this.borderColor = LIGHT_METAL_COLOR.darker();
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
IDrawingObserver drawingObserver) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke((int) borderThickness.convertToPixels()));
if (componentState != ComponentState.DRAGGING) {
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
}
g2d.setColor(color);
g2d.fillOval(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y);
g2d.setComposite(oldComposite);
}
// Do not track any changes that follow because the whole oval has been
// tracked so far.
drawingObserver.stopTracking();
g2d.setColor(componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: borderColor);
g2d.drawOval(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y);
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
int factor = 32 / width;
g2d.setColor(COLOR);
g2d.fillOval(2 / factor, 2 / factor, width - 4 / factor, height - 4 / factor);
g2d.setColor(LIGHT_METAL_COLOR.darker());
g2d.drawOval(2 / factor, 2 / factor, width - 4 / factor, height - 4 / factor);
}
}
/*
*
* 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.chassis;
import java.awt.AlphaComposite;
import java.awt.Composite;
import java.awt.Graphics2D;
import org.diylc.common.ObjectCache;
import org.diylc.common.SimpleComponentTransformer;
import org.diylc.components.shapes.AbstractShape;
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.BomPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
@ComponentDescriptor(name = "Elliptical Cutout", author = "Branislav Stojkovic", category = "Electro-Mechanical",
instanceNamePrefix = "ELC", description = "Elliptical chassis cutout", zOrder = IDIYComponent.CHASSIS + 0.1,
bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false, transformer = SimpleComponentTransformer.class)
public class EllipticalCutout extends AbstractShape {
private static final long serialVersionUID = 1L;
public EllipticalCutout() {
this.borderColor = LIGHT_METAL_COLOR.darker();
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
IDrawingObserver drawingObserver) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke((int) borderThickness.convertToPixels()));
if (componentState != ComponentState.DRAGGING) {
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
}
g2d.setColor(color);
g2d.fillOval(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y);
g2d.setComposite(oldComposite);
}
// Do not track any changes that follow because the whole oval has been
// tracked so far.
drawingObserver.stopTracking();
g2d.setColor(componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: borderColor);
g2d.drawOval(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y);
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
int factor = 32 / width;
g2d.setColor(COLOR);
g2d.fillOval(2 / factor, 2 / factor, width - 4 / factor, height - 4 / factor);
g2d.setColor(LIGHT_METAL_COLOR.darker());
g2d.drawOval(2 / factor, 2 / factor, width - 4 / factor, height - 4 / factor);
}
}
@@ -1,125 +1,125 @@
/*
*
* 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.chassis;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.Point;
import java.util.Arrays;
import org.diylc.common.ObjectCache;
import org.diylc.common.SimpleComponentTransformer;
import org.diylc.components.shapes.AbstractShape;
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.BomPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
@ComponentDescriptor(name = "Polygonal Cutout", author = "Branislav Stojkovic", category = "Electromechanical",
instanceNamePrefix = "POLYC", description = "Polygonal chassis cutout", zOrder = IDIYComponent.CHASSIS + 0.1,
bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false, transformer = SimpleComponentTransformer.class)
public class PolygonalCutout extends AbstractShape {
private static final long serialVersionUID = 1L;
protected PointCount pointCount = PointCount._4;
public PolygonalCutout() {
super();
this.borderColor = LIGHT_METAL_COLOR.darker();
this.controlPoints =
new Point[] {new Point(0, 0), new Point(0, (int) DEFAULT_HEIGHT.convertToPixels()),
new Point((int) DEFAULT_WIDTH.convertToPixels(), (int) DEFAULT_HEIGHT.convertToPixels()),
new Point((int) DEFAULT_WIDTH.convertToPixels(), 0)};
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
IDrawingObserver drawingObserver) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke((int) borderThickness.convertToPixels()));
g2d.setColor(color);
int[] xPoints = new int[controlPoints.length];
int[] yPoints = new int[controlPoints.length];
for (int i = 0; i < controlPoints.length; i++) {
xPoints[i] = controlPoints[i].x;
yPoints[i] = controlPoints[i].y;
}
Composite oldComposite = g2d.getComposite();
if (this.alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(3, 1.0F * this.alpha / MAX_ALPHA));
}
g2d.fillPolygon(xPoints, yPoints, controlPoints.length);
g2d.setComposite(oldComposite);
// Do not track any changes that follow because the whole board has been
// tracked so far.
drawingObserver.stopTracking();
Color lineColor =
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: borderColor;
g2d.setColor(lineColor);
g2d.drawPolygon(xPoints, yPoints, controlPoints.length);
}
@EditableProperty(name = "Edges")
public PointCount getPointCount() {
return pointCount;
}
public void setPointCount(PointCount pointCount) {
if (this.pointCount == pointCount)
return;
int oldPointCount = Integer.parseInt(this.pointCount.toString());
int newPointCount = Integer.parseInt(pointCount.toString());
this.controlPoints = Arrays.copyOf(this.controlPoints, newPointCount);
if (oldPointCount < newPointCount) {
this.controlPoints[newPointCount - 1] = this.controlPoints[oldPointCount - 1];
for (int i = oldPointCount - 1; i < newPointCount - 1; i++) {
this.controlPoints[i] =
new Point((this.controlPoints[i - 1].x + this.controlPoints[newPointCount - 1].x) / 2,
(this.controlPoints[i - 1].y + this.controlPoints[newPointCount - 1].y) / 2);
}
}
this.pointCount = pointCount;
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
int factor = 32 / width;
g2d.setColor(COLOR);
int[] x = {2 / factor, width - 2 / factor, width - 4 / factor, 3 / factor};
int[] y = {4 / factor, 2 / factor, height - 5 / factor, height - 2 / factor};
g2d.fillPolygon(x, y, 4);
g2d.setColor(LIGHT_METAL_COLOR.darker());
g2d.drawPolygon(x, y, 4);
}
public enum PointCount {
_3, _4, _5, _6, _7, _8;
public String toString() {
return name().substring(1);
};
}
}
/*
*
* 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.chassis;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.Point;
import java.util.Arrays;
import org.diylc.common.ObjectCache;
import org.diylc.common.SimpleComponentTransformer;
import org.diylc.components.shapes.AbstractShape;
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.BomPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
@ComponentDescriptor(name = "Polygonal Cutout", author = "Branislav Stojkovic", category = "Electro-Mechanical",
instanceNamePrefix = "POLYC", description = "Polygonal chassis cutout", zOrder = IDIYComponent.CHASSIS + 0.1,
bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false, transformer = SimpleComponentTransformer.class)
public class PolygonalCutout extends AbstractShape {
private static final long serialVersionUID = 1L;
protected PointCount pointCount = PointCount._4;
public PolygonalCutout() {
super();
this.borderColor = LIGHT_METAL_COLOR.darker();
this.controlPoints =
new Point[] {new Point(0, 0), new Point(0, (int) DEFAULT_HEIGHT.convertToPixels()),
new Point((int) DEFAULT_WIDTH.convertToPixels(), (int) DEFAULT_HEIGHT.convertToPixels()),
new Point((int) DEFAULT_WIDTH.convertToPixels(), 0)};
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
IDrawingObserver drawingObserver) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke((int) borderThickness.convertToPixels()));
g2d.setColor(color);
int[] xPoints = new int[controlPoints.length];
int[] yPoints = new int[controlPoints.length];
for (int i = 0; i < controlPoints.length; i++) {
xPoints[i] = controlPoints[i].x;
yPoints[i] = controlPoints[i].y;
}
Composite oldComposite = g2d.getComposite();
if (this.alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(3, 1.0F * this.alpha / MAX_ALPHA));
}
g2d.fillPolygon(xPoints, yPoints, controlPoints.length);
g2d.setComposite(oldComposite);
// Do not track any changes that follow because the whole board has been
// tracked so far.
drawingObserver.stopTracking();
Color lineColor =
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: borderColor;
g2d.setColor(lineColor);
g2d.drawPolygon(xPoints, yPoints, controlPoints.length);
}
@EditableProperty(name = "Edges")
public PointCount getPointCount() {
return pointCount;
}
public void setPointCount(PointCount pointCount) {
if (this.pointCount == pointCount)
return;
int oldPointCount = Integer.parseInt(this.pointCount.toString());
int newPointCount = Integer.parseInt(pointCount.toString());
this.controlPoints = Arrays.copyOf(this.controlPoints, newPointCount);
if (oldPointCount < newPointCount) {
this.controlPoints[newPointCount - 1] = this.controlPoints[oldPointCount - 1];
for (int i = oldPointCount - 1; i < newPointCount - 1; i++) {
this.controlPoints[i] =
new Point((this.controlPoints[i - 1].x + this.controlPoints[newPointCount - 1].x) / 2,
(this.controlPoints[i - 1].y + this.controlPoints[newPointCount - 1].y) / 2);
}
}
this.pointCount = pointCount;
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
int factor = 32 / width;
g2d.setColor(COLOR);
int[] x = {2 / factor, width - 2 / factor, width - 4 / factor, 3 / factor};
int[] y = {4 / factor, 2 / factor, height - 5 / factor, height - 2 / factor};
g2d.fillPolygon(x, y, 4);
g2d.setColor(LIGHT_METAL_COLOR.darker());
g2d.drawPolygon(x, y, 4);
}
public enum PointCount {
_3, _4, _5, _6, _7, _8;
public String toString() {
return name().substring(1);
};
}
}
@@ -1,92 +1,92 @@
/*
*
* 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.chassis;
import java.awt.AlphaComposite;
import java.awt.Composite;
import java.awt.Graphics2D;
import org.diylc.common.ObjectCache;
import org.diylc.common.SimpleComponentTransformer;
import org.diylc.components.shapes.AbstractShape;
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.BomPolicy;
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 = "Rectangular Cutout", author = "Branislav Stojkovic", category = "Electromechanical",
instanceNamePrefix = "RECTC", description = "Rectangular chassis cutout, with or without rounded edges",
zOrder = IDIYComponent.CHASSIS + 0.1, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false,
transformer = SimpleComponentTransformer.class)
public class RectangularCutout extends AbstractShape {
private static final long serialVersionUID = 1L;
protected Size edgeRadius = new Size(0d, SizeUnit.mm);
public RectangularCutout() {
this.borderColor = LIGHT_METAL_COLOR.darker();
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
IDrawingObserver drawingObserver) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke((int) borderThickness.convertToPixels()));
int radius = (int) edgeRadius.convertToPixels();
if (componentState != ComponentState.DRAGGING) {
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
}
g2d.setColor(color);
g2d.fillRoundRect(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y, radius,
radius);
g2d.setComposite(oldComposite);
}
// Do not track any changes that follow because the whole rect has been
// tracked so far.
drawingObserver.stopTracking();
g2d.setColor(componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: borderColor);
g2d.drawRoundRect(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y, radius,
radius);
}
@EditableProperty(name = "Radius")
public Size getEdgeRadius() {
return edgeRadius;
}
public void setEdgeRadius(Size edgeRadius) {
this.edgeRadius = edgeRadius;
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
int factor = 32 / width;
g2d.setColor(COLOR);
g2d.fillRect(2 / factor, 4 / factor, width - 4 / factor, height - 8 / factor);
g2d.setColor(LIGHT_METAL_COLOR.darker());
g2d.drawRect(2 / factor, 4 / factor, width - 4 / factor, height - 8 / factor);
}
}
/*
*
* 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.chassis;
import java.awt.AlphaComposite;
import java.awt.Composite;
import java.awt.Graphics2D;
import org.diylc.common.ObjectCache;
import org.diylc.common.SimpleComponentTransformer;
import org.diylc.components.shapes.AbstractShape;
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.BomPolicy;
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 = "Rectangular Cutout", author = "Branislav Stojkovic", category = "Electro-Mechanical",
instanceNamePrefix = "RECTC", description = "Rectangular chassis cutout, with or without rounded edges",
zOrder = IDIYComponent.CHASSIS + 0.1, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false,
transformer = SimpleComponentTransformer.class)
public class RectangularCutout extends AbstractShape {
private static final long serialVersionUID = 1L;
protected Size edgeRadius = new Size(0d, SizeUnit.mm);
public RectangularCutout() {
this.borderColor = LIGHT_METAL_COLOR.darker();
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
IDrawingObserver drawingObserver) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke((int) borderThickness.convertToPixels()));
int radius = (int) edgeRadius.convertToPixels();
if (componentState != ComponentState.DRAGGING) {
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
}
g2d.setColor(color);
g2d.fillRoundRect(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y, radius,
radius);
g2d.setComposite(oldComposite);
}
// Do not track any changes that follow because the whole rect has been
// tracked so far.
drawingObserver.stopTracking();
g2d.setColor(componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: borderColor);
g2d.drawRoundRect(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y, radius,
radius);
}
@EditableProperty(name = "Radius")
public Size getEdgeRadius() {
return edgeRadius;
}
public void setEdgeRadius(Size edgeRadius) {
this.edgeRadius = edgeRadius;
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
int factor = 32 / width;
g2d.setColor(COLOR);
g2d.fillRect(2 / factor, 4 / factor, width - 4 / factor, height - 8 / factor);
g2d.setColor(LIGHT_METAL_COLOR.darker());
g2d.drawRect(2 / factor, 4 / factor, width - 4 / factor, height - 8 / factor);
}
}
@@ -51,7 +51,7 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
@ComponentDescriptor(name = "9V Battery Snap", category = "Electromechanical", author = "Branislav Stojkovic",
@ComponentDescriptor(name = "9V Battery Snap", category = "Electro-Mechanical", author = "Branislav Stojkovic",
description = "", stretchable = false, zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "BTR",
autoEdit = false, transformer = BatterySnapTransformer.class)
public class BatterySnap9V extends AbstractTransparentComponent<String> {
@@ -53,7 +53,7 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Cliff 1/4\" Jack", category = "Electromechanical", author = "Branislav Stojkovic",
@ComponentDescriptor(name = "Cliff 1/4\" Jack", category = "Electro-Mechanical", author = "Branislav Stojkovic",
description = "Cliff-style closed panel mount 1/4\" phono jack", stretchable = false,
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "J", autoEdit = false, transformer = CliffJackTransformer.class)
public class CliffJack1_4 extends AbstractTransparentComponent<String> {
@@ -53,7 +53,7 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Closed 1/4\" Jack", category = "Electromechanical", author = "Branislav Stojkovic",
@ComponentDescriptor(name = "Closed 1/4\" Jack", category = "Electro-Mechanical", author = "Branislav Stojkovic",
description = "Enclosed panel mount 1/4\" phono jack", stretchable = false, zOrder = IDIYComponent.COMPONENT,
instanceNamePrefix = "J", autoEdit = false, transformer = ClosedJackTransformer.class)
public class ClosedJack1_4 extends AbstractTransparentComponent<String> {
@@ -52,7 +52,7 @@ import org.diylc.core.measures.Voltage;
import org.diylc.core.measures.VoltageUnit;
import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Mini Relay", author = "Branislav Stojkovic", category = "Electromechanical",
@ComponentDescriptor(name = "Mini Relay", author = "Branislav Stojkovic", category = "Electro-Mechanical",
instanceNamePrefix = "RY", description = "Miniature PCB mount relay, like Omron G5V-1 or G5V-2",
stretchable = false, zOrder = IDIYComponent.COMPONENT)
public class MiniRelay extends AbstractTransparentComponent<String> {
@@ -48,7 +48,7 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Mini Toggle Switch", category = "Electromechanical", author = "Branislav Stojkovic",
@ComponentDescriptor(name = "Mini Toggle Switch", category = "Electro-Mechanical", author = "Branislav Stojkovic",
description = "Panel mounted mini toggle switch", stretchable = false, zOrder = IDIYComponent.COMPONENT,
instanceNamePrefix = "SW", autoEdit = false)
public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchType> {
@@ -51,7 +51,7 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Open 1/4\" Jack", category = "Electromechanical", author = "Branislav Stojkovic",
@ComponentDescriptor(name = "Open 1/4\" Jack", category = "Electro-Mechanical", author = "Branislav Stojkovic",
description = "Switchcraft-style open panel mount 1/4\" phono jack, stereo and mono", stretchable = false,
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "J")
public class OpenJack1_4 extends AbstractTransparentComponent<String> {
@@ -49,7 +49,7 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Plastic DC Jack", category = "Electromechanical", author = "Branislav Stojkovic",
@ComponentDescriptor(name = "Plastic DC Jack", category = "Electro-Mechanical", author = "Branislav Stojkovic",
description = "Panel mount plastic DC jack", stretchable = false, zOrder = IDIYComponent.COMPONENT,
instanceNamePrefix = "J", autoEdit = false)
public class PlasticDCJack extends AbstractTransparentComponent<String> {
@@ -134,7 +134,7 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
body = null;
}
@EditableProperty(name = "Pin spacing")
@EditableProperty(name = "Pin Spacing")
public Size getPinSpacing() {
return pinSpacing;
}
@@ -146,7 +146,7 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
body = null;
}
@EditableProperty(name = "Row spacing")
@EditableProperty(name = "Row Spacing")
public Size getRowSpacing() {
return rowSpacing;
}
@@ -527,7 +527,7 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
this.indentColor = indentColor;
}
@EditableProperty(name = "Display pin numbers")
@EditableProperty(name = "Display Pin #s")
public DisplayNumbers getDisplayNumbers() {
return displayNumbers;
}
@@ -131,7 +131,7 @@ public class SIL_IC extends AbstractTransparentComponent<String> {
body = null;
}
@EditableProperty(name = "Pin spacing")
@EditableProperty(name = "Pin Spacing")
public Size getPinSpacing() {
return pinSpacing;
}
@@ -463,7 +463,7 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
this.body = null;
}
@EditableProperty(name = "Lead length")
@EditableProperty(name = "Lead Length")
public Size getLeadLength() {
if (leadLength == null) {
leadLength = LEAD_LENGTH;
@@ -477,7 +477,7 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
this.body = null;
}
@EditableProperty(name = "Tab border")
@EditableProperty(name = "Tab Border")
public Color getTabBorderColor() {
return tabBorderColor;
}
@@ -0,0 +1,623 @@
/*
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;
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.Rectangle;
import java.awt.Shape;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.common.Display;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.common.Orientation;
import org.diylc.components.AbstractTransparentComponent;
import org.diylc.components.transform.TO220Transformer;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.Theme;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.annotations.KeywordPolicy;
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)
public class SubminiTube extends AbstractTransparentComponent<String> {
private static final long serialVersionUID = 1L;
public static Color BODY_COLOR = Color.lightGray;
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 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);
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 Color bodyColor = BODY_COLOR;
private Color borderColor = BORDER_COLOR;
private Display display = Display.NAME;
private boolean folded = false;
private Size leadLength = LEAD_LENGTH;
private PinArrangement leadArrangement = PinArrangement.Circular;
private boolean topLead = false;
private Size diameter = DIAMETER;
private Size length = LENGTH;
private PinCount pinCount = PinCount._8;
private Size leadSpacing = PIN_SPACING;
public SubminiTube() {
super();
updateControlPoints();
}
@EditableProperty
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@EditableProperty
public Orientation getOrientation() {
return orientation;
}
public void setOrientation(Orientation orientation) {
this.orientation = orientation;
updateControlPoints();
// Reset body shape;
body = null;
}
@Override
public int getControlPointCount() {
return controlPoints.length;
}
@Override
public Point getControlPoint(int index) {
return controlPoints[index];
}
@Override
public boolean isControlPointSticky(int index) {
return true;
}
@Override
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
return VisibilityPolicy.NEVER;
}
@Override
public void setControlPoint(Point point, int index) {
controlPoints[index].setLocation(point);
body = null;
}
private void updateControlPoints() {
int pinSpacing = (int) PIN_SPACING.convertToPixels();
// Update control points.
int x = controlPoints[0].x;
int y = controlPoints[0].y;
int newPointCount = getPinCount().getValue();
// Need a new array
if (newPointCount != controlPoints.length) {
controlPoints = new Point[newPointCount];
for (int i = 0; i < controlPoints.length; i++) {
controlPoints[i] = new Point(x, y);
}
}
int dx;
int dy;
if (folded) {
switch (orientation) {
case DEFAULT:
dx = 0;
dy = pinSpacing;
break;
case _90:
dx = -pinSpacing;
dy = 0;
break;
case _180:
dx = 0;
dy = -pinSpacing;
break;
case _270:
dx = pinSpacing;
dy = 0;
break;
default:
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 {
switch (orientation) {
case DEFAULT:
controlPoints[1].setLocation(x, y + pinSpacing);
controlPoints[2].setLocation(x, y + 2 * pinSpacing);
break;
case _90:
controlPoints[1].setLocation(x - pinSpacing, y);
controlPoints[2].setLocation(x - 2 * pinSpacing, y);
break;
case _180:
controlPoints[1].setLocation(x, y - pinSpacing);
controlPoints[2].setLocation(x, y - 2 * pinSpacing);
break;
case _270:
controlPoints[1].setLocation(x + pinSpacing, y);
controlPoints[2].setLocation(x + 2 * pinSpacing, y);
break;
default:
throw new RuntimeException("Unexpected orientation: "
+ orientation);
}
}
}
public Shape[] getBody() {
if (body == null) {
body = new Shape[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 leadLength = getLeadLength().convertToPixels();
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);
}
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);
}
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);
}
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);
}
break;
default:
throw new RuntimeException("Unexpected orientation: "
+ orientation);
}
}
return body;
}
@Override
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;
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.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : bodyColor);
g2d.fill(mainArea);
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
// Draw pins.
if (folded) {
int leadThickness = getClosestOdd(LEAD_THICKNESS.convertToPixels());
int leadLength = (int) getLeadLength().convertToPixels();
Color finalPinColor;
Color finalPinBorderColor;
if (outlineMode) {
finalPinColor = new Color(0, 0, 0, 0);
finalPinBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: theme.getOutlineColor();
} else {
finalPinColor = METAL_COLOR;
finalPinBorderColor = METAL_COLOR.darker();
}
for (Point point : controlPoints) {
switch (orientation) {
case DEFAULT:
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.setColor(finalPinColor);
g2d.drawLine(point.x, point.y, point.x + leadLength
- leadThickness / 2, point.y);
break;
case _90:
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.setColor(finalPinColor);
g2d.drawLine(point.x, point.y, point.x, point.y
+ leadLength - leadThickness / 2);
break;
case _180:
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.setColor(finalPinColor);
g2d.drawLine(point.x, point.y, point.x - leadLength
- leadThickness / 2, point.y);
break;
case _270:
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.setColor(finalPinColor);
g2d.drawLine(point.x, point.y, point.x, point.y
- leadLength);
break;
}
}
} else {
if (!outlineMode) {
for (Point point : controlPoints) {
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);
}
}
}
// Draw label.
g2d.setFont(project.getFont());
Color finalLabelColor;
if (outlineMode) {
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;
}
g2d.setColor(finalLabelColor);
String label = "";
label = (getDisplay() == Display.NAME) ? getName() : getValue();
if (getDisplay() == Display.NONE) {
label = "";
}
if (getDisplay() == Display.BOTH) {
label = getName() + " "
+ (getValue() == null ? "" : getValue().toString());
}
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
Rectangle2D rect = fontMetrics.getStringBounds(label, g2d);
int textHeight = (int) (rect.getHeight());
int textWidth = (int) (rect.getWidth());
// 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);
}
@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);
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);
}
@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 boolean getFolded() {
return folded;
}
public void setFolded(boolean folded) {
this.folded = folded;
// Invalidate the body
this.body = null;
}
@EditableProperty(name = "Lead Length")
public Size getLeadLength() {
if (leadLength == null) {
leadLength = LEAD_LENGTH;
}
return leadLength;
}
public void setLeadLength(Size leadLength) {
this.leadLength = leadLength;
// Invalidate the body
this.body = null;
}
@EditableProperty
public Display getDisplay() {
if (display == null) {
display = Display.NAME;
}
return display;
}
public void setDisplay(Display display) {
this.display = display;
}
@EditableProperty(name = "Pin Arrangement")
public PinArrangement getPinArrangement() {
return leadArrangement;
}
public void setPinArrangement(PinArrangement pinArrangement) {
this.leadArrangement = pinArrangement;
}
@EditableProperty(name = "Top Lead")
public boolean getTopLead() {
return topLead;
}
public void setTopLead(boolean topLead) {
this.topLead = topLead;
updateControlPoints();
}
@EditableProperty
public Size getDiameter() {
return diameter;
}
public void setDiameter(Size diameter) {
this.diameter = diameter;
updateControlPoints();
}
@EditableProperty
public Size getLength() {
return length;
}
public void setLength(Size length) {
this.length = length;
}
@EditableProperty(name = "Lead Count")
public PinCount getPinCount() {
return pinCount;
}
public void setPinCount(PinCount pinCount) {
this.pinCount = pinCount;
updateControlPoints();
}
@EditableProperty(name = "Lead Spacing")
public Size getLeadSpacing() {
return leadSpacing;
}
public void setLeadSpacing(Size leadSpacing) {
this.leadSpacing = leadSpacing;
updateControlPoints();
}
public static enum PinArrangement {
Inline("In-line"), Circular("Circular");
private String label;
private PinArrangement(String label) {
this.label = label;
}
@Override
public String toString() {
return label;
}
}
public static enum PinCount {
_3, _4, _5, _6, _7, _8, _9, _10;
@Override
public String toString() {
return name().replace("_", "");
}
public int getValue() {
return Integer.parseInt(toString());
}
}
}