added cliff style jack

This commit is contained in:
bancika
2012-03-15 00:56:20 +00:00
parent d07965a3c0
commit f2a814e41c
11 changed files with 341 additions and 36 deletions
@@ -32,6 +32,7 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
public static Color LABEL_COLOR = Color.black; public static Color LABEL_COLOR = Color.black;
public static Color LABEL_COLOR_SELECTED = Color.red; public static Color LABEL_COLOR_SELECTED = Color.red;
public static Font LABEL_FONT = new Font("Tahoma", Font.PLAIN, 14); public static Font LABEL_FONT = new Font("Tahoma", Font.PLAIN, 14);
public static Color METAL_COLOR = Color.decode("#236B8E");
@EditableProperty(defaultable = false) @EditableProperty(defaultable = false)
@Override @Override
@@ -0,0 +1,307 @@
package org.diylc.components.electromechanical;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.RoundRectangle2D;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.common.HorizontalAlignment;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.common.Orientation;
import org.diylc.common.VerticalAlignment;
import org.diylc.components.AbstractTransparentComponent;
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.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Cliff 1/4\" Jack", category = "Electromechanical", author = "Branislav Stojkovic", description = "Cliff-style enclosed panel mount 1/4\" phono jack", stretchable = false, zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "J")
public class CliffJack extends AbstractTransparentComponent<String> {
private static final long serialVersionUID = 1L;
private static Size SPACING = new Size(0.3d, SizeUnit.in);
private static Size PIN_WIDTH = new Size(0.1d, SizeUnit.in);
private static Size PIN_THICKNESS = new Size(0.02d, SizeUnit.in);
private static Color BODY_COLOR = Color.decode("#555555");
private static Color NUT_COLOR = Color.decode("#999999");
private static Color BORDER_COLOR = Color.black;
private static Color LABEL_COLOR = Color.lightGray;
private static Size BODY_WIDTH = new Size(0.8d, SizeUnit.in);
private static Size BODY_LENGTH = new Size(1d, SizeUnit.in);
private static Size TAIL_LENGTH = new Size(0.1d, SizeUnit.in);
private Point[] controlPoints = new Point[] { new Point(0, 0) };
private JackType type = JackType.MONO;
private Orientation orientation = Orientation.DEFAULT;
private Shape[] body;
private String value = "";
public CliffJack() {
super();
updateControlPoints();
}
private void updateControlPoints() {
// invalidate body shape
body = null;
int x = controlPoints[0].x;
int y = controlPoints[0].y;
int spacing = (int) SPACING.convertToPixels();
controlPoints = new Point[type == JackType.STEREO ? 6 : 4];
controlPoints[0] = new Point(x, y);
controlPoints[1] = new Point(x, y + 2 * spacing);
controlPoints[2] = new Point(x + 2 * spacing, y);
controlPoints[3] = new Point(x + 2 * spacing, y + 2 * spacing);
if (type == JackType.STEREO) {
controlPoints[4] = new Point(x + spacing, y);
controlPoints[5] = new Point(x + spacing, y + 2 * spacing);
}
// Apply rotation if necessary
double angle = getAngle();
if (angle != 0) {
AffineTransform rotation = AffineTransform.getRotateInstance(angle, x, y);
for (int i = 1; i < controlPoints.length; i++) {
rotation.transform(controlPoints[i], controlPoints[i]);
}
}
}
private double getAngle() {
// Apply rotation if necessary
double angle;
switch (orientation) {
case _90:
angle = Math.PI / 2;
break;
case _180:
angle = Math.PI;
break;
case _270:
angle = Math.PI * 3 / 2;
break;
default:
angle = 0;
}
return angle;
}
public Shape[] getBody() {
if (body == null) {
body = new Shape[5];
// Create body.
int bodyLength = (int) BODY_LENGTH.convertToPixels();
int bodyWidth = (int) BODY_WIDTH.convertToPixels();
int centerX = (controlPoints[0].x + controlPoints[3].x) / 2;
int centerY = (controlPoints[0].y + controlPoints[3].y) / 2;
body[0] = new Rectangle(centerX - bodyLength / 2, centerY - bodyWidth / 2, bodyLength,
bodyWidth);
int tailLength = (int) TAIL_LENGTH.convertToPixels();
body[1] = new RoundRectangle2D.Double(centerX - bodyLength / 2 - tailLength, centerY
- bodyWidth / 4, tailLength * 2, bodyWidth / 2, tailLength, tailLength);
Area tailArea = new Area(body[1]);
tailArea.subtract(new Area(body[0]));
body[1] = tailArea;
body[2] = new Rectangle(centerX + bodyLength / 2, centerY - bodyWidth / 4, tailLength,
bodyWidth / 2);
body[3] = new Rectangle(centerX + bodyLength / 2 + tailLength, centerY - bodyWidth / 4,
tailLength, bodyWidth / 2);
tailArea = new Area(body[3]);
int radius = bodyLength / 2 + tailLength * 2;
tailArea.intersect(new Area(new Ellipse2D.Double(centerX - radius, centerY - radius,
radius * 2, radius * 2)));
body[3] = tailArea;
// Apply rotation if necessary
double angle = getAngle();
if (angle != 0) {
AffineTransform rotation = AffineTransform.getRotateInstance(angle, centerX,
centerY);
for (int i = 0; i < body.length; i++) {
if (body[i] != null) {
Area area = new Area(body[i]);
area.transform(rotation);
body[i] = area;
}
}
}
// Create pins.
Area pins = new Area();
int pinWidth = (int) PIN_WIDTH.convertToPixels();
int pinThickness = (int) PIN_THICKNESS.convertToPixels();
for (int i = 0; i < getControlPointCount(); i++) {
Point point = getControlPoint(i);
Rectangle pin;
if (orientation == Orientation.DEFAULT || orientation == Orientation._180) {
pin = new Rectangle(point.x - pinWidth / 2, point.y - pinThickness / 2,
pinWidth, pinThickness);
} else {
pin = new Rectangle(point.x - pinThickness / 2, point.y - pinWidth / 2,
pinThickness, pinWidth);
}
pins.add(new Area(pin));
}
body[4] = pins;
}
return body;
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
Shape[] body = getBody();
// Rectangle bounds = body.getBounds();
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
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(outlineMode ? Constants.TRANSPARENT_COLOR : BODY_COLOR);
// GradientPaint gradient;
// if (orientation == Orientation.DEFAULT || orientation ==
// Orientation._180) {
// gradient = new GradientPaint(bounds.x, bounds.y, BORDER_COLOR,
// bounds.x, bounds.y
// + bounds.height / 2, BODY_COLOR, true);
// } else {
// gradient = new GradientPaint(bounds.x, bounds.y, BORDER_COLOR,
// bounds.x
// + bounds.width / 2, bounds.y, BODY_COLOR, true);
// }
// Paint oldPaint = g2d.getPaint();
// g2d.setPaint(gradient);
for (int i = 0; i < body.length - 1; i++) {
// Nut is brighter colored.
if (i == body.length - 2)
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : NUT_COLOR);
g2d.fill(body[i]);
}
// g2d.setPaint(oldPaint);
g2d.setComposite(oldComposite);
}
g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : BORDER_COLOR);
for (int i = 0; i < body.length - 1; i++) {
g2d.draw(body[i]);
}
// Pins are the last piece.
Shape pins = body[body.length - 1];
g2d.setColor(METAL_COLOR);
g2d.fill(pins);
g2d.setColor(METAL_COLOR.darker());
g2d.draw(pins);
Color finalLabelColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
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);
g2d.setFont(LABEL_FONT);
int centerX = (controlPoints[0].x + controlPoints[3].x) / 2;
int centerY = (controlPoints[0].y + controlPoints[3].y) / 2;
drawCenteredText(g2d, name, centerX, centerY, HorizontalAlignment.CENTER,
VerticalAlignment.CENTER);
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
// TODO Auto-generated method stub
}
@Override
public int getControlPointCount() {
return controlPoints.length;
}
@Override
public Point getControlPoint(int index) {
return controlPoints[index];
}
@Override
public void setControlPoint(Point point, int index) {
controlPoints[index] = point;
updateControlPoints();
}
@Override
public boolean isControlPointSticky(int index) {
return true;
}
@Override
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
return VisibilityPolicy.NEVER;
}
@EditableProperty
@Override
public String getValue() {
return value;
}
@Override
public void setValue(String value) {
this.value = value;
}
@EditableProperty
public JackType getType() {
return type;
}
public void setType(JackType type) {
this.type = type;
updateControlPoints();
}
@EditableProperty
public Orientation getOrientation() {
return orientation;
}
public void setOrientation(Orientation orientation) {
this.orientation = orientation;
updateControlPoints();
}
}
@@ -0,0 +1,11 @@
package org.diylc.components.electromechanical;
public enum JackType {
MONO, STEREO;
@Override
public String toString() {
return name().substring(0, 1) + name().substring(1).toLowerCase();
}
}
@@ -33,12 +33,11 @@ public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchT
private static Size MARGIN = new Size(0.08d, SizeUnit.in); private static Size MARGIN = new Size(0.08d, SizeUnit.in);
private static Size CIRCLE_SIZE = new Size(0.09d, SizeUnit.in); private static Size CIRCLE_SIZE = new Size(0.09d, SizeUnit.in);
private static Size LUG_WIDTH = new Size(0.060d, SizeUnit.in); private static Size LUG_WIDTH = new Size(0.060d, SizeUnit.in);
private static Size LUG_HEIGHT = new Size(0.03d, SizeUnit.in); private static Size LUG_THICKNESS = new Size(0.02d, SizeUnit.in);
private static Color BODY_COLOR = Color.decode("#3299CC"); private static Color BODY_COLOR = Color.decode("#3299CC");
private static Color BORDER_COLOR = BODY_COLOR.darker(); private static Color BORDER_COLOR = BODY_COLOR.darker();
private static Color CIRCLE_COLOR = Color.red; private static Color CIRCLE_COLOR = Color.decode("#FFFFAA");
private static Color LUG_COLOR = Color.decode("#00B2EE");
protected Point[] controlPoints = new Point[] { new Point(0, 0) }; protected Point[] controlPoints = new Point[] { new Point(0, 0) };
transient protected RoundRectangle2D body; transient protected RoundRectangle2D body;
@@ -205,17 +204,17 @@ public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchT
// so far. // so far.
drawingObserver.stopTracking(); drawingObserver.stopTracking();
// Draw lugs. // Draw lugs.
if (!outlineMode) { int circleDiameter = getClosestOdd((int) CIRCLE_SIZE.convertToPixels());
int circleDiameter = getClosestOdd((int) CIRCLE_SIZE.convertToPixels()); int lugWidth = getClosestOdd((int) LUG_WIDTH.convertToPixels());
int lugWidth = getClosestOdd((int) LUG_WIDTH.convertToPixels()); int lugHeight = getClosestOdd((int) LUG_THICKNESS.convertToPixels());
int lugHeight = getClosestOdd((int) LUG_HEIGHT.convertToPixels()); for (Point p : controlPoints) {
for (Point p : controlPoints) { if (!outlineMode) {
g2d.setColor(CIRCLE_COLOR); g2d.setColor(CIRCLE_COLOR);
g2d.fillOval(p.x - circleDiameter / 2, p.y - circleDiameter / 2, circleDiameter, g2d.fillOval(p.x - circleDiameter / 2, p.y - circleDiameter / 2, circleDiameter,
circleDiameter); circleDiameter);
g2d.setColor(LUG_COLOR);
g2d.fillRect(p.x - lugWidth / 2, p.y - lugHeight / 2, lugWidth, lugHeight);
} }
g2d.setColor(METAL_COLOR);
g2d.fillRect(p.x - lugWidth / 2, p.y - lugHeight / 2, lugWidth, lugHeight);
} }
} }
@@ -261,9 +260,12 @@ public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchT
g2d.fillRoundRect(width / 4, 1, width / 2, height - 2, circleSize, circleSize); g2d.fillRoundRect(width / 4, 1, width / 2, height - 2, circleSize, circleSize);
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.drawRoundRect(width / 4, 1, width / 2, height - 2, circleSize, circleSize); g2d.drawRoundRect(width / 4, 1, width / 2, height - 2, circleSize, circleSize);
g2d.setColor(CIRCLE_COLOR);
for (int i = 1; i <= 3; i++) { for (int i = 1; i <= 3; i++) {
g2d.setColor(CIRCLE_COLOR);
g2d.fillOval(width / 2 - circleSize / 2, i * height / 4 - 3, circleSize, circleSize); g2d.fillOval(width / 2 - circleSize / 2, i * height / 4 - 3, circleSize, circleSize);
g2d.setColor(METAL_COLOR);
g2d.drawLine(width / 2 - circleSize / 2 + 1, i * height / 4 - 1, width / 2 + circleSize
/ 2 - 1, i * height / 4 - 1);
} }
} }
} }
@@ -23,7 +23,7 @@ public class GroundSymbol extends AbstractComponent<Void> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public static Color COLOR = Color.black; public static Color COLOR = Color.black;
public static Size SIZE = new Size(0.1d, SizeUnit.in); public static Size SIZE = new Size(0.15d, SizeUnit.in);
private Point point = new Point(0, 0); private Point point = new Point(0, 0);
private Color color = COLOR; private Color color = COLOR;
@@ -2,20 +2,10 @@ package org.diylc.components.semiconductors;
public enum BJTPolarity { public enum BJTPolarity {
NPN("NPN"), PNP("PNP"); NPN, PNP;
private String title;
private BJTPolarity(String title) {
this.title = title;
}
public String getTitle() {
return title;
}
@Override @Override
public String toString() { public String toString() {
return title; return name();
} }
} }
@@ -2,20 +2,10 @@ package org.diylc.components.semiconductors;
public enum FETPolarity { public enum FETPolarity {
NEGATIVE("Negative"), POSITIVE("Positive"); NEGATIVE, POSITIVE;
private String title;
private FETPolarity(String title) {
this.title = title;
}
public String getTitle() {
return title;
}
@Override @Override
public String toString() { public String toString() {
return title; return name().substring(0, 1) + name().substring(1).toLowerCase();
} }
} }
@@ -530,6 +530,10 @@
<releaseDate>2012-03-09 20:00:00.000 CET</releaseDate> <releaseDate>2012-03-09 20:00:00.000 CET</releaseDate>
<name></name> <name></name>
<changes> <changes>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Cliff-style closed 1/4" jack</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change> <org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType> <changeType>NEW_FEATURE</changeType>
<description>Ground Symbol</description> <description>Ground Symbol</description>