mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 01:02:08 +10:00
Compare commits
73 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d6338f0427 | |||
| 5df467a254 | |||
| 7c4d82b28c | |||
| 6b7d1c4277 | |||
| a0ae53d53c | |||
| bd79ef2817 | |||
| 69e2296c23 | |||
| 7d3a7c30ca | |||
| bea19f326c | |||
| ba694add0c | |||
| f137a398dc | |||
| 15ac8ff2e9 | |||
| 1213dcaeac | |||
| 2ebcd1fe96 | |||
| 943d123ca9 | |||
| 79c29dc349 | |||
| 746b5fbe1a | |||
| 365c195091 | |||
| d89a500a5f | |||
| 085732fb2c | |||
| eab7654883 | |||
| 5488657984 | |||
| 1a256716db | |||
| 2b9c76e876 | |||
| 5ae8a3477e | |||
| 209e970c00 | |||
| ae96fb9eef | |||
| 401f2b5e6f | |||
| e2da0b884d | |||
| bcf390b888 | |||
| 144e8f0cfe | |||
| 84d744a80b | |||
| 5430ca71a3 | |||
| 4665d5d42e | |||
| 275918d079 | |||
| a83093519f | |||
| 2e14929eb1 | |||
| a0b7cdc30e | |||
| ab5c9ad143 | |||
| 4154225e71 | |||
| 3856af3e18 | |||
| 80e7ebcbe9 | |||
| abdf02eac8 | |||
| 746aadd8a2 | |||
| ac4496040f | |||
| d810096030 | |||
| 4727017be7 | |||
| b2dae15ee6 | |||
| 56e112ff81 | |||
| 6f5926e18e | |||
| b1f4773b10 | |||
| e5d33fb80d | |||
| b8545d27a1 | |||
| 70ac30473b | |||
| 4774e97ba2 | |||
| de7378c722 | |||
| e2b3ed1b0e | |||
| 99d38feb1c | |||
| a561f6a3f9 | |||
| 6eee1525ee | |||
| 02d38bed01 | |||
| b96bad2688 | |||
| 12ca93e2c9 | |||
| d9b9542883 | |||
| 9e04cff806 | |||
| 16600328cc | |||
| 85d7d8a450 | |||
| f358b5d87b | |||
| fa02280292 | |||
| 8ea53b6876 | |||
| 4d6e994555 | |||
| 10581c51fb | |||
| 2cf6b573a7 |
@@ -9,9 +9,9 @@
|
||||
<classpathentry kind="lib" path="lib/iText-2.1.7.jar"/>
|
||||
<classpathentry kind="lib" path="lib/cloning-1.5.jar"/>
|
||||
<classpathentry kind="lib" path="lib/objenesis-1.1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/bancika-gui-framework.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jettison-1.0.1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/poi-3.5-FINAL-20090928.jar"/>
|
||||
<classpathentry kind="lib" path="library/main.jar"/>
|
||||
<classpathentry kind="lib" path="lib/bancika-gui-framework.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -1,22 +0,0 @@
|
||||
<map>
|
||||
<entry>
|
||||
<string>lastPath</string>
|
||||
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop\oldFiles</string>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>zoom</string>
|
||||
<double>1.0</double>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>metric</string>
|
||||
<boolean>true</boolean>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>showTemplatesAtStartup</string>
|
||||
<boolean>false</boolean>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>default.org.diylc.components.semiconductors.TransistorTO92:Orientation</string>
|
||||
<org.diylc.common.Orientation>DEFAULT</org.diylc.common.Orientation>
|
||||
</entry>
|
||||
</map>
|
||||
Binary file not shown.
@@ -1,5 +0,0 @@
|
||||
package org.diylc.common;
|
||||
|
||||
public enum Power {
|
||||
|
||||
}
|
||||
@@ -1,249 +0,0 @@
|
||||
package org.diylc.components;
|
||||
|
||||
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.Rectangle2D;
|
||||
|
||||
import org.diylc.common.Display;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.VisibilityPolicy;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
|
||||
/**
|
||||
* Base class for all leaded components such as resistors or capacitors. Has two
|
||||
* control points and draws leads between them. Also, it positions and draws the
|
||||
* shape of the component as specified by a child class.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComponent<T> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Color LEAD_COLOR = Color.decode("#236B8E");
|
||||
public static Size LEAD_THICKNESS = new Size(0.6d, SizeUnit.mm);
|
||||
public static Size DEFAULT_SIZE = new Size(1d, SizeUnit.in);
|
||||
|
||||
protected Size length;
|
||||
protected Size width;
|
||||
protected Point[] points = new Point[] {
|
||||
new Point((int) (-DEFAULT_SIZE.convertToPixels() / 2), 0),
|
||||
new Point(DEFAULT_SIZE.convertToPixels() / 2, 0) };
|
||||
protected Color bodyColor = Color.white;
|
||||
protected Color borderColor = Color.black;
|
||||
protected Color labelColor = LABEL_COLOR;
|
||||
protected Display display = Display.NAME;
|
||||
|
||||
protected AbstractLeadedComponent() {
|
||||
super();
|
||||
try {
|
||||
this.length = getDefaultLength().clone();
|
||||
this.width = getDefaultWidth().clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
// This should never happen because Size supports cloning.
|
||||
} catch (NullPointerException e) {
|
||||
// This will happen if components do not have any shape.
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||
IDrawingObserver drawingObserver) {
|
||||
double distance = points[0].distance(points[1]);
|
||||
Shape shape = getBodyShape();
|
||||
if (shape == null) {
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
|
||||
getLeadThickness().convertToPixels()));
|
||||
g2d.setColor(shouldShadeLeads() ? getLeadColor(componentState).darker()
|
||||
: getLeadColor(componentState));
|
||||
g2d.drawLine(points[0].x, points[0].y, points[1].x, points[1].y);
|
||||
if (shouldShadeLeads()) {
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
|
||||
getLeadThickness().convertToPixels() - 2));
|
||||
g2d.setColor(getLeadColor(componentState));
|
||||
g2d.drawLine(points[0].x, points[0].y, points[1].x, points[1].y);
|
||||
}
|
||||
return;
|
||||
}
|
||||
Rectangle shapeRect = shape.getBounds();
|
||||
double leadLenght = (distance - shapeRect.width) / 2;
|
||||
Double theta = Math.atan2(points[1].y - points[0].y, points[1].x - points[0].x);
|
||||
// Transform graphics to draw the body in the right place and at the
|
||||
// right angle.
|
||||
g2d.translate((points[0].x + points[1].x - shapeRect.width) / 2,
|
||||
(points[0].y + points[1].y - shapeRect.height) / 2);
|
||||
g2d.rotate(theta, shapeRect.width / 2, shapeRect.height / 2);
|
||||
// Draw body.
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
if (alpha < MAX_ALPHA) {
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
|
||||
/ MAX_ALPHA));
|
||||
}
|
||||
g2d.setColor(bodyColor);
|
||||
g2d.fill(shape);
|
||||
decorateComponentBody(g2d);
|
||||
g2d.setComposite(oldComposite);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
g2d.setColor(componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor);
|
||||
g2d.draw(shape);
|
||||
// Draw leads.
|
||||
int leadThickness = getClosestOdd(getLeadThickness().convertToPixels());
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
|
||||
g2d.setColor(shouldShadeLeads() ? getLeadColor(componentState).darker()
|
||||
: getLeadColor(componentState));
|
||||
g2d.drawLine((int) (shapeRect.width - distance) / 2, (int) shapeRect.height / 2,
|
||||
(int) ((shapeRect.width - distance) / 2 + leadLenght) - leadThickness / 2,
|
||||
(int) shapeRect.height / 2);
|
||||
g2d.drawLine((int) (shapeRect.width + distance) / 2, (int) shapeRect.height / 2,
|
||||
(int) ((shapeRect.width + distance) / 2 - leadLenght) + leadThickness / 2,
|
||||
(int) shapeRect.height / 2);
|
||||
if (shouldShadeLeads()) {
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
|
||||
g2d.setColor(getLeadColor(componentState));
|
||||
g2d.drawLine((int) (shapeRect.width - distance) / 2, (int) shapeRect.height / 2,
|
||||
(int) ((shapeRect.width - distance) / 2 + leadLenght) - leadThickness / 2,
|
||||
(int) shapeRect.height / 2);
|
||||
g2d.drawLine((int) (shapeRect.width + distance) / 2, (int) shapeRect.height / 2,
|
||||
(int) ((shapeRect.width + distance) / 2 - leadLenght) + leadThickness / 2,
|
||||
(int) shapeRect.height / 2);
|
||||
}
|
||||
// Do not track the label because that area was already covered.
|
||||
drawingObserver.stopTracking();
|
||||
// Draw label.
|
||||
g2d.setFont(LABEL_FONT);
|
||||
g2d.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED : labelColor);
|
||||
FontMetrics fontMetrics = g2d.getFontMetrics();
|
||||
String label = display == Display.NAME ? getName() : getValue().toString();
|
||||
// Adjust label angle if needed to make sure that it's readable.
|
||||
if ((theta >= Math.PI / 2 && theta <= Math.PI)
|
||||
|| (theta < -Math.PI / 2 && theta > -Math.PI)) {
|
||||
g2d.rotate(Math.PI, shapeRect.width / 2, shapeRect.height / 2);
|
||||
}
|
||||
Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d);
|
||||
g2d.drawString(label, (int) (shapeRect.width - textRect.getWidth()) / 2,
|
||||
(int) (shapeRect.height - textRect.getHeight()) / 2 + fontMetrics.getAscent());
|
||||
}
|
||||
|
||||
protected void decorateComponentBody(Graphics2D g2d) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
protected boolean shouldShadeLeads() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return default component length.
|
||||
*/
|
||||
protected abstract Size getDefaultLength();
|
||||
|
||||
/**
|
||||
* Returns default component width.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract Size getDefaultWidth();
|
||||
|
||||
/**
|
||||
* @return shape that represents component body. Shape should not be
|
||||
* transformed and should be referenced to (0, 0).
|
||||
*/
|
||||
protected abstract Shape getBodyShape();
|
||||
|
||||
/**
|
||||
* @return default lead thickness. Override this method to change it.
|
||||
*/
|
||||
protected Size getLeadThickness() {
|
||||
return LEAD_THICKNESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return default lead color. Override this method to change it.
|
||||
*/
|
||||
protected Color getLeadColor(ComponentState componentState) {
|
||||
return componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : LEAD_COLOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getControlPointCount() {
|
||||
return points.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
return (Point) points[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControlPointSticky(int index) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.ALWAYS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
points[index].setLocation(point);
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Color")
|
||||
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(name = "Length", defaultable = true)
|
||||
public Size getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public void setLength(Size length) {
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Width", defaultable = true)
|
||||
public Size getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void setWidth(Size width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Display getDisplay() {
|
||||
return display;
|
||||
}
|
||||
|
||||
public void setDisplay(Display display) {
|
||||
this.display = display;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package org.diylc.components;
|
||||
|
||||
import java.awt.Point;
|
||||
|
||||
public abstract class AbstractSinglePointComponent extends AbstractComponent<Void> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected Point point = new Point(0, 0);
|
||||
|
||||
@Override
|
||||
public int getControlPointCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
return point;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
this.point.setLocation(point);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public Void getValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public void setValue(Void value) {
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package org.diylc.swing.gui.editor;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JColorChooser;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
|
||||
|
||||
public class FontEditor extends JLabel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public FontEditor(final PropertyWrapper property) {
|
||||
super("Click to edit");
|
||||
setOpaque(true);
|
||||
setHorizontalAlignment(SwingConstants.CENTER);
|
||||
setBorder(BorderFactory.createEtchedBorder());
|
||||
setBackground((Color) property.getValue());
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
addMouseListener(new MouseAdapter() {
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
// JFo
|
||||
Color newColor = JColorChooser.showDialog(FontEditor.this, "Choose Color",
|
||||
getBackground());
|
||||
if (newColor != null) {
|
||||
property.setValue(newColor);
|
||||
setBackground(newColor);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBackground(Color bg) {
|
||||
if (bg.getRed() < 127 || bg.getBlue() < 127 || bg.getGreen() < 127) {
|
||||
setForeground(Color.white);
|
||||
} else {
|
||||
setForeground(Color.black);
|
||||
}
|
||||
super.setBackground(bg);
|
||||
}
|
||||
}
|
||||
@@ -1,657 +0,0 @@
|
||||
package org.diylc.utils.dnd;
|
||||
|
||||
/* Copyright (c) 2003-2006 Timothy Wall, All Rights Reserved */
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.HierarchyEvent;
|
||||
import java.awt.event.HierarchyListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.geom.Area;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLayeredPane;
|
||||
import javax.swing.RootPaneContainer;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
/**
|
||||
* Provide a method for consistently augmenting the appearance of a given
|
||||
* component by painting something on it <i>after</i> the component itself gets
|
||||
* painted. If not explicitly removed via {@link #dispose}, an instance of this
|
||||
* object will live as long as its target component.
|
||||
* <p>
|
||||
* By default, the decorator matches the location and size of the decorated
|
||||
* component, but the bounds can be adjusted by overriding
|
||||
* {@link #getDecorationBounds()}. The {@link #synch()} method should be called
|
||||
* whenever the bounds returned by {@link #getDecorationBounds()} would change.
|
||||
* <p>
|
||||
* The decoration is clipped to the bounds set on the decoration, which does not
|
||||
* necessarily need to be the same as the decorated component bounds. The
|
||||
* decoration may extend beyond the decorated component bounds, or it may be
|
||||
* reduced to a smaller region.
|
||||
*/
|
||||
// TODO: should probably do some locking on Component.getTreeLock()
|
||||
// TODO: synch underlying cursor when decorator covers more than
|
||||
// one component; the cursor should change if the decoration exceeds the
|
||||
// component's bounds
|
||||
public abstract class AbstractComponentDecorator {
|
||||
public static final Rectangle DEFAULT_BOUNDS = null;
|
||||
public static final int TOP = 0;
|
||||
// Disabled for now, since it doesn't work properly
|
||||
private static final int BOTTOM = -1;
|
||||
/**
|
||||
* Account for the difference between the decorator actual origin and the
|
||||
* logical origin we want to pass to the {@link #paint} method.
|
||||
*/
|
||||
private Point originOffset = new Point(0, 0);
|
||||
|
||||
private Painter painter;
|
||||
private JComponent component;
|
||||
private Container parent;
|
||||
private Listener listener;
|
||||
private int layerOffset;
|
||||
private int position;
|
||||
private Rectangle bounds;
|
||||
|
||||
/** Create a decorator for the given component. */
|
||||
public AbstractComponentDecorator(JComponent c) {
|
||||
this(c, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a decorator for the given component, indicating the layer offset
|
||||
* from the target component. Negative values mean the decoration is painted
|
||||
* <em>before</em> the target component is painted.
|
||||
*/
|
||||
public AbstractComponentDecorator(JComponent c, int layerOffset) {
|
||||
this(c, layerOffset, TOP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a decorator with the given position within its layer. Use
|
||||
* {@link #TOP} to cover other decorations, or {@link #BOTTOM} to be covered
|
||||
* by other decorations.
|
||||
* <p>
|
||||
* WARNING: BOTTOM doesn't currently work, probably a JLayeredPane bug in
|
||||
* either the code or documentation.
|
||||
*
|
||||
* @see JLayeredPane
|
||||
*/
|
||||
public AbstractComponentDecorator(JComponent c, int layerOffset, int position) {
|
||||
component = c;
|
||||
this.layerOffset = layerOffset;
|
||||
this.position = position;
|
||||
this.bounds = DEFAULT_BOUNDS;
|
||||
parent = c.getParent();
|
||||
painter = new Painter();
|
||||
listener = new Listener();
|
||||
component.addHierarchyListener(listener);
|
||||
component.addComponentListener(listener);
|
||||
component.addPropertyChangeListener(listener);
|
||||
attach();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the text to be displayed when the mouse is over the decoration.
|
||||
*
|
||||
* @see JComponent#setToolTipText(String)
|
||||
*/
|
||||
public void setToolTipText(String text) {
|
||||
painter.setToolTipText(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the currently set default tooltip text.
|
||||
*
|
||||
* @see JComponent#setToolTipText
|
||||
*/
|
||||
public String getToolTipText() {
|
||||
return painter.getToolTipText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide for different tool tips depending on the actual location over the
|
||||
* decoration. Note that if you <em>only</em> override this method, you must
|
||||
* also invoke {@link #setToolTipText(String)} with a non-<span
|
||||
* class="javakeyword">null</span> argument.
|
||||
*
|
||||
* @see JComponent#getToolTipText(MouseEvent)
|
||||
*/
|
||||
public String getToolTipText(MouseEvent e) {
|
||||
return getToolTipText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate whether any of the decoration is visible. The decoration may be
|
||||
* clipped by ancestor scroll panes or by being moved outside if the visible
|
||||
* region of its parent window.
|
||||
*/
|
||||
public boolean isVisible() {
|
||||
return painter.isVisible();
|
||||
}
|
||||
|
||||
/** Use this to change the visibility of the decoration. */
|
||||
public void setVisible(boolean visible) {
|
||||
painter.setVisible(visible);
|
||||
}
|
||||
|
||||
protected void attach() {
|
||||
Window w = SwingUtilities.getWindowAncestor(component);
|
||||
if (w instanceof RootPaneContainer) {
|
||||
JLayeredPane lp = ((RootPaneContainer) w).getLayeredPane();
|
||||
Component layeredChild = component;
|
||||
int layer = JLayeredPane.DRAG_LAYER.intValue();
|
||||
if (this instanceof BackgroundPainter) {
|
||||
layer = ((BackgroundPainter) this).layer;
|
||||
painter.setDecoratedLayer(layer);
|
||||
} else if (layeredChild == lp) {
|
||||
// Is this the best layer to use?
|
||||
painter.setDecoratedLayer(layer);
|
||||
} else {
|
||||
while (layeredChild.getParent() != lp) {
|
||||
layeredChild = layeredChild.getParent();
|
||||
}
|
||||
int base = lp.getLayer(layeredChild);
|
||||
// NOTE: JLayeredPane doesn't properly repaint an overlapping
|
||||
// child when an obscured child calls repaint() if the two
|
||||
// are in the same layer, so we use the next-higher layer
|
||||
// instead of simply using a different position within the
|
||||
// layer.
|
||||
layer = base + layerOffset;
|
||||
if (layerOffset < 0) {
|
||||
BackgroundPainter bp = (BackgroundPainter) lp
|
||||
.getClientProperty(BackgroundPainter.key(base));
|
||||
if (bp == null) {
|
||||
bp = new BackgroundPainter(lp, base);
|
||||
}
|
||||
}
|
||||
painter.setDecoratedLayer(base);
|
||||
}
|
||||
lp.add(painter, new Integer(layer), position);
|
||||
} else {
|
||||
// Always detach when the target component's window is null
|
||||
// or is not a suitable container,
|
||||
// otherwise we might prevent GC of the component
|
||||
Container parent = painter.getParent();
|
||||
if (parent != null) {
|
||||
parent.remove(painter);
|
||||
}
|
||||
}
|
||||
// Track size changes in any viewport parent
|
||||
if (parent != null) {
|
||||
parent.removeComponentListener(listener);
|
||||
}
|
||||
parent = component.getParent();
|
||||
if (parent != null) {
|
||||
parent.addComponentListener(listener);
|
||||
}
|
||||
synch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the size of the decorator matches the current decoration bounds
|
||||
* with appropriate clipping to viewports.
|
||||
*/
|
||||
protected void synch() {
|
||||
Container painterParent = painter.getParent();
|
||||
if (painterParent != null) {
|
||||
Rectangle decorated = getDecorationBounds();
|
||||
Rectangle clipRect = clipDecorationBounds(decorated);
|
||||
|
||||
Point pt = SwingUtilities
|
||||
.convertPoint(component, clipRect.x, clipRect.y, painterParent);
|
||||
if (clipRect.width <= 0 || clipRect.height <= 0) {
|
||||
setPainterBounds(-1, -1, 0, 0);
|
||||
setVisible(false);
|
||||
} else {
|
||||
setPainterBounds(pt.x, pt.y, clipRect.width, clipRect.height);
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
||||
painter.repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjust the painting offsets and size of the decoration to account for
|
||||
* ancestor clipping. This might be due to scroll panes or having the
|
||||
* decoration lie outside the parent layered pane.
|
||||
*/
|
||||
protected Rectangle clipDecorationBounds(Rectangle decorated) {
|
||||
// Amount we have to translate the Graphics context
|
||||
originOffset.x = decorated.x;
|
||||
originOffset.y = decorated.y;
|
||||
// If the the component is obscured (by a viewport or some
|
||||
// other means), use the painter bounds to clip to the visible
|
||||
// bounds. Doing may change the actual origin, so adjust our
|
||||
// origin offset accordingly
|
||||
Rectangle visible = getClippingRect(component, decorated);
|
||||
Rectangle clipRect = decorated.intersection(visible);
|
||||
if (decorated.x < visible.x)
|
||||
originOffset.x += visible.x - decorated.x;
|
||||
if (decorated.y < visible.y)
|
||||
originOffset.y += visible.y - decorated.y;
|
||||
return clipRect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return any clipping rectangle detected above the given component, in the
|
||||
* coordinate space of the given component. The given rectangle is desired
|
||||
* to be visible.
|
||||
*/
|
||||
private Rectangle getClippingRect(Container component, Rectangle desired) {
|
||||
Rectangle clip = component instanceof JComponent ? ((JComponent) component)
|
||||
.getVisibleRect()
|
||||
: new Rectangle(0, 0, component.getWidth(), component.getHeight());
|
||||
if (desired.x >= clip.x && desired.y >= clip.y
|
||||
&& desired.x + desired.width <= clip.x + clip.width
|
||||
&& desired.y + desired.height <= clip.y + clip.height) {
|
||||
// desired rect is within the current clip rect
|
||||
} else if (component.getParent() != null) {
|
||||
// Only apply the clip if it is actually smaller than the
|
||||
// component's visible area
|
||||
if (component != painter.getParent() && clip.x > 0 && clip.y > 0
|
||||
&& clip.width < component.getWidth() && clip.height < component.getHeight()) {
|
||||
// Don't alter the original rectangle
|
||||
desired = new Rectangle(desired);
|
||||
// Check for clipping further up the hierarchy
|
||||
desired.x += component.getX();
|
||||
desired.y += component.getY();
|
||||
clip = getClippingRect(component.getParent(), desired);
|
||||
clip.x -= component.getX();
|
||||
clip.y -= component.getY();
|
||||
}
|
||||
}
|
||||
return clip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the bounds, relative to the decorated component, of the
|
||||
* decoration. The default covers the entire component. Note that this
|
||||
* method will be called from the constructor, so be careful when overriding
|
||||
* and referencing derived class state.
|
||||
*/
|
||||
protected Rectangle getDecorationBounds() {
|
||||
return bounds != DEFAULT_BOUNDS ? bounds : new Rectangle(0, 0, component.getWidth(),
|
||||
component.getHeight());
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the bounds of the decoration, relative to the decorated component.
|
||||
* The special value {@link #DEFAULT_BOUNDS} means the bounds will track the
|
||||
* component bounds.
|
||||
*/
|
||||
public void setDecorationBounds(Rectangle bounds) {
|
||||
if (bounds == DEFAULT_BOUNDS) {
|
||||
this.bounds = bounds;
|
||||
} else {
|
||||
this.bounds = new Rectangle(bounds);
|
||||
}
|
||||
synch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the bounds of the decoration, relative to the decorated component.
|
||||
*/
|
||||
public void setDecorationBounds(int x, int y, int w, int h) {
|
||||
setDecorationBounds(new Rectangle(x, y, w, h));
|
||||
}
|
||||
|
||||
protected void setPainterBounds(int x, int y, int w, int h) {
|
||||
painter.setLocation(x, y);
|
||||
painter.setSize(w, h);
|
||||
repaint();
|
||||
}
|
||||
|
||||
protected JComponent getComponent() {
|
||||
return component;
|
||||
}
|
||||
|
||||
protected JComponent getPainter() {
|
||||
return painter;
|
||||
}
|
||||
|
||||
/** Set the cursor to appear anywhere over the decoration bounds. */
|
||||
public void setCursor(Cursor cursor) {
|
||||
painter.setCursor(cursor);
|
||||
}
|
||||
|
||||
/** Force a refresh of the underlying component and its decoration. */
|
||||
public void repaint() {
|
||||
component.repaint();
|
||||
painter.repaint();
|
||||
}
|
||||
|
||||
/** Stop decorating. */
|
||||
public void dispose() {
|
||||
component.removeHierarchyListener(listener);
|
||||
component.removeComponentListener(listener);
|
||||
component.removePropertyChangeListener(listener);
|
||||
if (parent != null) {
|
||||
parent.removeComponentListener(listener);
|
||||
parent = null;
|
||||
}
|
||||
Container painterParent = painter.getParent();
|
||||
if (painterParent != null) {
|
||||
Rectangle bounds = painter.getBounds();
|
||||
painterParent.remove(painter);
|
||||
painterParent.repaint(bounds.x, bounds.y, bounds.width, bounds.height);
|
||||
}
|
||||
component.repaint();
|
||||
component = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the decoration's appearance. The point (0,0) represents the upper
|
||||
* left corner of the decorated component. The default clip mask will be the
|
||||
* extents of the decoration bounds, as indicated by
|
||||
* {@link #getDecorationBounds()}, which defaults to the decorated component
|
||||
* bounds.
|
||||
*/
|
||||
public abstract void paint(Graphics g);
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + " on " + getComponent();
|
||||
}
|
||||
|
||||
private static Field nComponents;
|
||||
static {
|
||||
try {
|
||||
nComponents = Container.class.getDeclaredField("ncomponents");
|
||||
nComponents.setAccessible(true);
|
||||
} catch (Exception e) {
|
||||
nComponents = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean useSimpleBackground() {
|
||||
return nComponents == null;
|
||||
}
|
||||
|
||||
/** Used to hook into the Swing painting architecture. */
|
||||
private class Painter extends JComponent {
|
||||
private int base;
|
||||
private Cursor cursor;
|
||||
|
||||
public JComponent getComponent() {
|
||||
return AbstractComponentDecorator.this.getComponent();
|
||||
}
|
||||
|
||||
public void setDecoratedLayer(int base) {
|
||||
this.base = base;
|
||||
}
|
||||
|
||||
public int getDecoratedLayer() {
|
||||
return base;
|
||||
}
|
||||
|
||||
public boolean isBackgroundDecoration() {
|
||||
return layerOffset < 0;
|
||||
}
|
||||
|
||||
/** Set the cursor to something else. */
|
||||
public void setCursor(Cursor cursor) {
|
||||
Cursor oldCursor = getCursor();
|
||||
// Make sure the cursor actually changed, otherwise
|
||||
// we get cursor flicker (notably on w32 title bars)
|
||||
if (oldCursor == null && cursor != null || oldCursor != null
|
||||
&& !oldCursor.equals(cursor)) {
|
||||
this.cursor = cursor;
|
||||
super.setCursor(cursor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cursor of the decorated component, or the last cursor set
|
||||
* by {@link #setCursor}.
|
||||
*/
|
||||
public Cursor getCursor() {
|
||||
return cursor != null ? cursor : component.getCursor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegate to the containing decorator to perform the paint.
|
||||
*/
|
||||
public void paint(Graphics g) {
|
||||
if (!component.isShowing())
|
||||
return;
|
||||
Graphics g2 = g.create();
|
||||
g2.translate(-originOffset.x, -originOffset.y);
|
||||
AbstractComponentDecorator.this.paint(g2);
|
||||
g2.dispose();
|
||||
/*
|
||||
* g = g.create(); g.setClip(null); g.setColor(Color.red);
|
||||
* g.drawRect(0, 0, getWidth()-1, getHeight()-1);
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a decorator-specific tooltip, shown when within the
|
||||
* decorator's bounds.
|
||||
*/
|
||||
public String getToolTipText(MouseEvent e) {
|
||||
return AbstractComponentDecorator.this.getToolTipText(e);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Painter for " + AbstractComponentDecorator.this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a shared background painting mechanism for multiple decorations.
|
||||
* This ensures that the background is only painted once if more than one
|
||||
* background decorator is applied.
|
||||
*/
|
||||
private static class BackgroundPainter extends AbstractComponentDecorator {
|
||||
private static String key(int layer) {
|
||||
return "backgroundPainter for layer " + layer;
|
||||
}
|
||||
|
||||
private String key;
|
||||
private int layer;
|
||||
|
||||
public BackgroundPainter(JLayeredPane p, int layer) {
|
||||
super(p, 0, TOP);
|
||||
this.layer = layer;
|
||||
key = key(layer);
|
||||
p.putClientProperty(key, this);
|
||||
}
|
||||
|
||||
private int hideChildren(Container c) {
|
||||
if (c == null)
|
||||
return 0;
|
||||
int value = c.getComponentCount();
|
||||
try {
|
||||
nComponents.set(c, new Integer(0));
|
||||
} catch (Exception e) {
|
||||
return c.getComponentCount();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private void restoreChildren(Container c, int count) {
|
||||
if (c != null) {
|
||||
try {
|
||||
nComponents.set(c, new Integer(count));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void paintBackground(Graphics g, Component parent, JComponent jc) {
|
||||
int x = jc.getX();
|
||||
int y = jc.getY();
|
||||
int w = jc.getWidth();
|
||||
int h = jc.getHeight();
|
||||
paintBackground(g.create(x, y, w, h), jc);
|
||||
}
|
||||
|
||||
private void paintBackground(Graphics g, JComponent jc) {
|
||||
if (jc.isOpaque()) {
|
||||
if (useSimpleBackground()) {
|
||||
g.setColor(jc.getBackground());
|
||||
g.fillRect(0, 0, jc.getWidth(), jc.getHeight());
|
||||
} else {
|
||||
int count = hideChildren(jc);
|
||||
boolean db = jc.isDoubleBuffered();
|
||||
if (db)
|
||||
jc.setDoubleBuffered(false);
|
||||
jc.paint(g);
|
||||
if (db)
|
||||
jc.setDoubleBuffered(true);
|
||||
restoreChildren(jc, count);
|
||||
}
|
||||
}
|
||||
Component[] kids = jc.getComponents();
|
||||
for (int i = 0; i < kids.length; i++) {
|
||||
if (kids[i] instanceof JComponent) {
|
||||
paintBackground(g, jc, (JComponent) kids[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List findOpaque(Component root) {
|
||||
List list = new ArrayList();
|
||||
if (root.isOpaque() && root instanceof JComponent) {
|
||||
list.add(root);
|
||||
((JComponent) root).setOpaque(false);
|
||||
}
|
||||
if (root instanceof Container) {
|
||||
Component[] kids = ((Container) root).getComponents();
|
||||
for (int i = 0; i < kids.length; i++) {
|
||||
list.addAll(findOpaque(kids[i]));
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private List findDoubleBuffered(Component root) {
|
||||
List list = new ArrayList();
|
||||
if (root.isDoubleBuffered() && root instanceof JComponent) {
|
||||
list.add(root);
|
||||
((JComponent) root).setDoubleBuffered(false);
|
||||
}
|
||||
if (root instanceof Container) {
|
||||
Component[] kids = ((Container) root).getComponents();
|
||||
for (int i = 0; i < kids.length; i++) {
|
||||
list.addAll(findDoubleBuffered(kids[i]));
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private void paintForeground(Graphics g, JComponent jc) {
|
||||
List opaque = findOpaque(jc);
|
||||
List db = findDoubleBuffered(jc);
|
||||
jc.paint(g);
|
||||
for (Iterator i = opaque.iterator(); i.hasNext();) {
|
||||
((JComponent) i.next()).setOpaque(true);
|
||||
}
|
||||
for (Iterator i = db.iterator(); i.hasNext();) {
|
||||
((JComponent) i.next()).setDoubleBuffered(true);
|
||||
}
|
||||
}
|
||||
|
||||
/** Walk the list of "background" decorators and paint them. */
|
||||
public void paint(Graphics g) {
|
||||
|
||||
JLayeredPane lp = (JLayeredPane) getComponent();
|
||||
Component[] kids = lp.getComponents();
|
||||
// Construct an area of the intersection of all decorators
|
||||
Area area = new Area();
|
||||
List painters = new ArrayList();
|
||||
List components = new ArrayList();
|
||||
for (int i = kids.length - 1; i >= 0; i--) {
|
||||
if (kids[i] instanceof Painter) {
|
||||
Painter p = (Painter) kids[i];
|
||||
if (p.isBackgroundDecoration() && p.getDecoratedLayer() == layer
|
||||
&& p.isShowing()) {
|
||||
painters.add(p);
|
||||
area.add(new Area(p.getBounds()));
|
||||
}
|
||||
} else if (lp.getLayer(kids[i]) == layer && kids[i] instanceof JComponent) {
|
||||
components.add(kids[i]);
|
||||
}
|
||||
}
|
||||
if (painters.size() == 0) {
|
||||
dispose();
|
||||
return;
|
||||
}
|
||||
g.setClip(area);
|
||||
|
||||
// Paint background for that area
|
||||
for (Iterator i = components.iterator(); i.hasNext();) {
|
||||
JComponent c = (JComponent) i.next();
|
||||
paintBackground(g, lp, c);
|
||||
}
|
||||
|
||||
// Paint the bg decorators
|
||||
for (Iterator i = painters.iterator(); i.hasNext();) {
|
||||
Painter p = (Painter) i.next();
|
||||
p.paint(g.create(p.getX(), p.getY(), p.getWidth(), p.getHeight()));
|
||||
}
|
||||
// Paint foreground for the area
|
||||
for (Iterator i = components.iterator(); i.hasNext();) {
|
||||
JComponent c = (JComponent) i.next();
|
||||
paintForeground(g.create(c.getX(), c.getY(), c.getWidth(), c.getHeight()), c);
|
||||
}
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
getComponent().putClientProperty(key, null);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return key + " on " + getComponent();
|
||||
}
|
||||
}
|
||||
|
||||
/** Tracks changes to component configuration. */
|
||||
private final class Listener extends ComponentAdapter implements HierarchyListener,
|
||||
PropertyChangeListener {
|
||||
public void hierarchyChanged(HierarchyEvent e) {
|
||||
if ((e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) != 0) {
|
||||
attach();
|
||||
}
|
||||
}
|
||||
|
||||
public void propertyChange(PropertyChangeEvent e) {
|
||||
if (JLayeredPane.LAYER_PROPERTY.equals(e.getPropertyName())) {
|
||||
attach();
|
||||
}
|
||||
}
|
||||
|
||||
public void componentMoved(ComponentEvent e) {
|
||||
// FIXME figure out why attach works and synch doesn't
|
||||
// when painting a selection marquee over a decorated background
|
||||
attach();
|
||||
}
|
||||
|
||||
public void componentResized(ComponentEvent e) {
|
||||
// FIXME figure out why attach works and synch doesn't
|
||||
// when painting a selection marquee over a decorated background
|
||||
attach();
|
||||
}
|
||||
|
||||
public void componentHidden(ComponentEvent e) {
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
public void componentShown(ComponentEvent e) {
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,216 +0,0 @@
|
||||
package org.diylc.utils.dnd;
|
||||
|
||||
/* Copyright 2006 Timothy Wall All Rights Reserved. */
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Component;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLayeredPane;
|
||||
import javax.swing.RootPaneContainer;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.Timer;
|
||||
|
||||
/**
|
||||
* Provide a ghosted drag image which will appear on any instances of
|
||||
* {@link RootPaneContainer} in the current VM. Its location in screen
|
||||
* coordinates may be set via {@link #move}.
|
||||
* <p>
|
||||
* When the image is no longer needed, invoke {@link #dispose}, which hides the
|
||||
* graphic immediately, or {@link #returnToOrigin}, which moves the image to its
|
||||
* original location prior to invoking {@link #dispose}.
|
||||
*/
|
||||
public class GhostedDragImage extends AbstractComponentDecorator {
|
||||
|
||||
private Icon icon;
|
||||
// drag origin, relative to drag source
|
||||
private Point origin;
|
||||
// current drag location, relative to drag source
|
||||
private Point location;
|
||||
// offset of the image from the cursor
|
||||
private Point imageOffset;
|
||||
private List ghosts = new ArrayList();
|
||||
private Component dragSource;
|
||||
private float ghostAlpha = 0.5f;
|
||||
|
||||
/**
|
||||
* Create a ghosted drag image, using the given icon.
|
||||
*
|
||||
* @param dragSource
|
||||
* source of the drag
|
||||
* @param screenLocation
|
||||
* screen location where the drag started
|
||||
* @param icon
|
||||
* image to be drawn
|
||||
* @param imageOffset
|
||||
* offset of the image from the cursor
|
||||
*/
|
||||
public GhostedDragImage(JComponent dragSource, Point screenLocation, Icon icon,
|
||||
Point imageOffset) {
|
||||
this(dragSource, dragSource.getRootPane().getLayeredPane(), screenLocation, icon,
|
||||
imageOffset, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a ghosted drag image.
|
||||
*
|
||||
* @param dragSource
|
||||
* source of the drag
|
||||
* @param root
|
||||
* layered pane on which ghosted image is drawn
|
||||
* @param screenLocation
|
||||
* initial location of image, in screen coordinates
|
||||
* @param icon
|
||||
* icon to use for the ghost image
|
||||
* @param imageOffset
|
||||
* offset of the image within the drag source
|
||||
* @param trackFrames
|
||||
* if true, creates additional ghosts for all extant frames which
|
||||
* contain a {@link JLayeredPane} where the image can be painted.
|
||||
*/
|
||||
protected GhostedDragImage(JComponent dragSource, JLayeredPane root, Point screenLocation,
|
||||
Icon icon, Point imageOffset, boolean trackFrames) {
|
||||
super(root);
|
||||
this.dragSource = dragSource;
|
||||
this.icon = icon;
|
||||
this.imageOffset = imageOffset;
|
||||
Point loc = root.getLocationOnScreen();
|
||||
setLocation(screenLocation.x - loc.x + imageOffset.x, screenLocation.y - loc.y
|
||||
+ imageOffset.y);
|
||||
if (trackFrames) {
|
||||
Window w = SwingUtilities.getWindowAncestor(root);
|
||||
Frame[] frames = Frame.getFrames();
|
||||
// Log.debug("track " + frames.length + " other frames");
|
||||
for (int i = 0; i < frames.length; i++) {
|
||||
Frame frame = frames[i];
|
||||
if (frame instanceof RootPaneContainer && frame.isShowing() && frame != w) {
|
||||
// Log.debug("Track " + frame);
|
||||
JLayeredPane p = ((RootPaneContainer) frame).getLayeredPane();
|
||||
GhostedDragImage slave = new GhostedDragImage(dragSource, p, screenLocation,
|
||||
icon, imageOffset, false);
|
||||
ghosts.add(slave);
|
||||
slave.move(screenLocation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Set the transparency of the ghosted image. */
|
||||
public void setAlpha(float alpha) {
|
||||
ghostAlpha = alpha;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the decorator cursor matches the drag cursor, or we get cursor
|
||||
* flicker when autoscrolling.
|
||||
*/
|
||||
public void setCursor(Cursor cursor) {
|
||||
super.setCursor(cursor);
|
||||
for (Iterator i = ghosts.iterator(); i.hasNext();) {
|
||||
GhostedDragImage slave = (GhostedDragImage) i.next();
|
||||
slave.setCursor(cursor);
|
||||
}
|
||||
}
|
||||
|
||||
/** Make all ghosted images go away. */
|
||||
public void dispose() {
|
||||
location = origin;
|
||||
super.dispose();
|
||||
for (Iterator i = ghosts.iterator(); i.hasNext();) {
|
||||
GhostedDragImage slave = (GhostedDragImage) i.next();
|
||||
slave.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the location of the decoration within the layered pane. Keeps track
|
||||
* of the location relative to the drag source to facilitate moving back
|
||||
* with {@link #returnToOrigin}.
|
||||
*/
|
||||
private void setLocation(int x, int y) {
|
||||
location = SwingUtilities.convertPoint(getComponent(), x, y, dragSource);
|
||||
if (origin == null)
|
||||
origin = location;
|
||||
setDecorationBounds(x, y, icon.getIconWidth(), icon.getIconHeight());
|
||||
}
|
||||
|
||||
// Setting this non-zero provides some buffer around the drag image
|
||||
// which helps avoid cursor flicker as the cursor moves (especially
|
||||
// repomgr, probably due to slow repaint times).
|
||||
private static final int CURSOR_SIZE = 32;
|
||||
|
||||
/**
|
||||
* Adjust the bounds of the painting component to allow some buffer to avoid
|
||||
* cursor flicker when moving.
|
||||
*/
|
||||
protected Rectangle clipDecorationBounds(Rectangle decorated) {
|
||||
decorated.x -= CURSOR_SIZE;
|
||||
decorated.y -= CURSOR_SIZE;
|
||||
decorated.width += CURSOR_SIZE * 2;
|
||||
decorated.height += CURSOR_SIZE * 2;
|
||||
return super.clipDecorationBounds(decorated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the ghosted image to the requested location.
|
||||
*
|
||||
* @param screen
|
||||
* Where to draw the image, in screen coordinates
|
||||
*/
|
||||
public void move(Point screen) {
|
||||
// Log.debug("Move to " + screen);
|
||||
Point loc = getComponent().getLocationOnScreen();
|
||||
setLocation(screen.x - loc.x + imageOffset.x, screen.y - loc.y + imageOffset.y);
|
||||
for (Iterator i = ghosts.iterator(); i.hasNext();) {
|
||||
GhostedDragImage g = (GhostedDragImage) i.next();
|
||||
// Log.debug("Move on other frame");
|
||||
g.move(screen);
|
||||
}
|
||||
}
|
||||
|
||||
/** Paint the supplied image with transparency. */
|
||||
public void paint(Graphics graphics) {
|
||||
Rectangle r = getDecorationBounds();
|
||||
Graphics2D g = (Graphics2D) graphics.create();
|
||||
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, ghostAlpha));
|
||||
g.translate(CURSOR_SIZE, CURSOR_SIZE);
|
||||
icon.paintIcon(getPainter(), g, r.x, r.y);
|
||||
g.dispose();
|
||||
}
|
||||
|
||||
private static final int SLIDE_INTERVAL = 1000 / 24;
|
||||
|
||||
/** Animate the ghosted image returning to its origin. */
|
||||
public void returnToOrigin() {
|
||||
setCursor(null);
|
||||
final Timer timer = new Timer(SLIDE_INTERVAL, null);
|
||||
timer.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
int dx = (origin.x - location.x) / 2;
|
||||
int dy = (origin.y - location.y) / 2;
|
||||
if (dx != 0 || dy != 0) {
|
||||
Point loc = dragSource.getLocationOnScreen();
|
||||
Point where = new Point(loc.x + location.x + dx - imageOffset.x, loc.y
|
||||
+ location.y + dy - imageOffset.y);
|
||||
move(where);
|
||||
} else {
|
||||
timer.stop();
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
timer.start();
|
||||
}
|
||||
}
|
||||
@@ -1,142 +0,0 @@
|
||||
<java.util.Arrays_-ArrayList>
|
||||
<a class="com.diyfever.gui.update.Version-array">
|
||||
<com.diyfever.gui.update.Version>
|
||||
<versionNumber>
|
||||
<major>3</major>
|
||||
<minor>0</minor>
|
||||
<build>4</build>
|
||||
</versionNumber>
|
||||
<releaseDate>2011-01-27 21:00:00.000 CET</releaseDate>
|
||||
<name></name>
|
||||
<changes>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>BUG_FIX</changeType>
|
||||
<description>Copy/paste between two instances of the application</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>BUG_FIX</changeType>
|
||||
<description>Parsing numerical values in countries that use comma as decimal separator</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>BUG_FIX</changeType>
|
||||
<description>Dragging sticky points affects selectability of objects</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>BUG_FIX</changeType>
|
||||
<description>Click is sometimes not registered while adding a new component</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>BUG_FIX</changeType>
|
||||
<description>Fixed NPE when using default values</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Allow shape control points of curves to overlap</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Added DIL IC first pin indentation</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Added transparency to the potentiometer</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Reduced number of layers</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Import from v1 files can now read label and electrolytic capacitor components and trace/pad colors</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Added worker thread for longer file operation, so GUI doesn't freeze</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Added right click menu on the canvas</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Added "send to back" and "bring to front" options</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Added label component</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Added image component</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
</changes>
|
||||
<url>http://code.google.com/p/diy-layout-creator/downloads/list
|
||||
</url>
|
||||
</com.diyfever.gui.update.Version>
|
||||
<com.diyfever.gui.update.Version>
|
||||
<versionNumber>
|
||||
<major>3</major>
|
||||
<minor>0</minor>
|
||||
<build>5</build>
|
||||
</versionNumber>
|
||||
<releaseDate>2011-01-30 20:00:00.000 CET</releaseDate>
|
||||
<name></name>
|
||||
<changes>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>BUG_FIX</changeType>
|
||||
<description>Curved trace does not show control points</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>BUG_FIX</changeType>
|
||||
<description>Potentiometer draws wrong at 180 degrees</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Reset component selection when tab is changed</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Resistor can show color bands</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Electrolytic capacitor has a new icon and new looks</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Solder pad can be square</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Added keyboard shortcuts to some menu options</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>V1 file importer can recognize hookup wire and transistors</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Added support for creating and loading templates</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Added TO-92 transistor</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Added TO-220 transistor</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Added LED</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Added axial electrolytic capacitor</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
</changes>
|
||||
<url>http://code.google.com/p/diy-layout-creator/downloads/list
|
||||
</url>
|
||||
</com.diyfever.gui.update.Version>
|
||||
</a>
|
||||
</java.util.Arrays_-ArrayList>
|
||||
@@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/DIYLC"/>
|
||||
<classpathentry kind="lib" path="lib/xstream-1.3.1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/log4j-1.2.15.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Library</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -1,60 +0,0 @@
|
||||
<project name="main" basedir="." default="jar">
|
||||
<property name="src.dir" value="src" />
|
||||
|
||||
<property name="lib.dir" value="${basedir}/lib" />
|
||||
<property name="build.dir" value="${basedir}/build" />
|
||||
<property name="jar.dir" value="${build.dir}/jar" />
|
||||
<property name="report.dir" value="${build.dir}/junitreport" />
|
||||
|
||||
<property name="classes.dir" value="${build.dir}/temp/${ant.project.name}/classes" />
|
||||
<property name="test.classes.dir" value="${build.dir}/temp/${ant.project.name}/test.classes" />
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="${build.dir}" />
|
||||
</target>
|
||||
|
||||
<target name="compile">
|
||||
<mkdir dir="${classes.dir}" />
|
||||
<echo>Compile with JDK ${java.runtime.version}</echo>
|
||||
<javac encoding="8859_1" srcdir="${basedir}/${src.dir}" destdir="${classes.dir}" classpathref="class.path" />
|
||||
</target>
|
||||
|
||||
<target name="resource.copy">
|
||||
<copy todir="${classes.dir}">
|
||||
<fileset dir="${src.dir}">
|
||||
<exclude name="**/*.java" />
|
||||
</fileset>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="lib.copy">
|
||||
<copy todir="${jar.dir}/lib" overwrite="true">
|
||||
<fileset dir="${basedir}/lib">
|
||||
<exclude name="**/*dll" />
|
||||
</fileset>
|
||||
</copy>
|
||||
<copy todir="${jar.dir}" overwrite="true">
|
||||
<fileset dir="${basedir}/lib/" includes="**/*.dll" />
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<path id="class.path">
|
||||
<fileset dir="${basedir}">
|
||||
<include name="lib/**/*.jar" />
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
<target name="jar" depends="clean, lib.copy, resource.copy, compile">
|
||||
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}" />
|
||||
</target>
|
||||
|
||||
<target name="javadoc">
|
||||
<javadoc access="public" author="true" classpathref="class.path" destdir="doc" nodeprecated="false" nodeprecatedlist="false" noindex="false" nonavbar="false" notree="false" source="1.6" splitindex="true" use="true" version="true">
|
||||
<fileset dir="${src.dir}">
|
||||
<exclude name="**\.svn\**" />
|
||||
<include name="**/*.java" />
|
||||
</fileset>
|
||||
</javadoc>
|
||||
</target>
|
||||
|
||||
</project>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,118 +0,0 @@
|
||||
package org.diylc.components.boards;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Composite;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.components.AbstractTransparentComponent;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.VisibilityPolicy;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
|
||||
public abstract class AbstractBoard extends AbstractTransparentComponent<String> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Color BOARD_COLOR = Color.decode("#F8EBB3");
|
||||
public static Color BORDER_COLOR = BOARD_COLOR.darker();
|
||||
public static Size DEFAULT_WIDTH = new Size(1.5d, SizeUnit.in);
|
||||
public static Size DEFAULT_HEIGHT = new Size(1.2d, SizeUnit.in);
|
||||
|
||||
protected String value = "";
|
||||
protected Point[] controlPoints = new Point[] { new Point(0, 0),
|
||||
new Point(DEFAULT_WIDTH.convertToPixels(), DEFAULT_HEIGHT.convertToPixels()) };
|
||||
protected Point firstPoint = new Point();
|
||||
protected Point secondPoint = new Point();
|
||||
|
||||
protected Color boardColor = BOARD_COLOR;
|
||||
protected Color borderColor = BORDER_COLOR;
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||
IDrawingObserver drawingObserver) {
|
||||
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(boardColor);
|
||||
g2d.fillRect(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y
|
||||
- firstPoint.y);
|
||||
g2d.setComposite(oldComposite);
|
||||
}
|
||||
g2d.setColor(componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor);
|
||||
g2d.drawRect(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y
|
||||
- firstPoint.y);
|
||||
// Do not track any changes that follow because the whole board has been
|
||||
// tracked so far.
|
||||
drawingObserver.stopTracking();
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Color")
|
||||
public Color getBoardColor() {
|
||||
return boardColor;
|
||||
}
|
||||
|
||||
public void setBoardColor(Color boardColor) {
|
||||
this.boardColor = boardColor;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Border")
|
||||
public Color getBorderColor() {
|
||||
return borderColor;
|
||||
}
|
||||
|
||||
public void setBorderColor(Color borderColor) {
|
||||
this.borderColor = borderColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getControlPointCount() {
|
||||
return controlPoints.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
return controlPoints[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControlPointSticky(int index) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.WHEN_SELECTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
controlPoints[index].setLocation(point);
|
||||
firstPoint.setLocation(Math.min(controlPoints[0].x, controlPoints[1].x), Math.min(
|
||||
controlPoints[0].y, controlPoints[1].y));
|
||||
secondPoint.setLocation(Math.max(controlPoints[0].x, controlPoints[1].x), Math.max(
|
||||
controlPoints[0].y, controlPoints[1].y));
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
@Override
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package org.diylc.components.boards;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
|
||||
@ComponentDescriptor(name = "Blank Board", category = "Boards", author = "Branislav Stojkovic", zOrder = IDIYComponent.BOARD, instanceNamePrefix = "Board", description = "Blank circuit board")
|
||||
public class BlankBoard extends AbstractBoard {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
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 = "Eyelet Board", category = "Boards", author = "Branislav Stojkovic", zOrder = IDIYComponent.BOARD, instanceNamePrefix = "Board", description = "Perforated board with eyelets")
|
||||
public class EyeletBoard extends AbstractBoard {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Color EYELET_COLOR = Color.decode("#C3E4ED");
|
||||
|
||||
public static Size SPACING = new Size(0.3d, SizeUnit.in);
|
||||
public static Size EYELET_SIZE = new Size(1/8d, SizeUnit.in);
|
||||
public static Size HOLE_SIZE = new Size(2d, SizeUnit.mm);
|
||||
|
||||
// private Area copperArea;
|
||||
protected Size spacing = SPACING;
|
||||
protected Color eyeletColor = EYELET_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 diameter = getClosestOdd(EYELET_SIZE.convertToPixels());
|
||||
int holeDiameter = getClosestOdd(HOLE_SIZE.convertToPixels());
|
||||
int spacing = 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(eyeletColor);
|
||||
g2d.fillOval(p.x - diameter / 2, p.y - diameter / 2, diameter, diameter);
|
||||
g2d.setColor(eyeletColor.darker());
|
||||
g2d.drawOval(p.x - diameter / 2, p.y - diameter / 2, diameter, diameter);
|
||||
g2d.setColor(Constants.CANVAS_COLOR);
|
||||
g2d.fillOval(p.x - holeDiameter / 2, p.y - holeDiameter / 2, holeDiameter,
|
||||
holeDiameter);
|
||||
g2d.setColor(eyeletColor.darker());
|
||||
g2d.drawOval(p.x - holeDiameter / 2, p.y - holeDiameter / 2, holeDiameter,
|
||||
holeDiameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Eyelet color")
|
||||
public Color getEyeletColor() {
|
||||
return eyeletColor;
|
||||
}
|
||||
|
||||
public void setEyeletColor(Color padColor) {
|
||||
this.eyeletColor = padColor;
|
||||
}
|
||||
|
||||
@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(EYELET_COLOR);
|
||||
g2d.fillOval(width / 4, width / 4, width / 2, width / 2);
|
||||
g2d.setColor(EYELET_COLOR.darker());
|
||||
g2d.drawOval(width / 4, width / 4, width / 2, width / 2);
|
||||
g2d.setColor(Constants.CANVAS_COLOR);
|
||||
g2d.fillOval(width / 2 - 2, width / 2 - 2, 5, 5);
|
||||
g2d.setColor(EYELET_COLOR.darker());
|
||||
g2d.drawOval(width / 2 - 2, width / 2 - 2, 5, 5);
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
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 = "Perf Board w/ Pads", category = "Boards", author = "Branislav Stojkovic", zOrder = IDIYComponent.BOARD, instanceNamePrefix = "Board", description = "Perforated board with solder pads")
|
||||
public class PerfBoard extends AbstractBoard {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Color COPPER_COLOR = Color.decode("#DA8A67");
|
||||
|
||||
public static Size SPACING = new Size(0.1d, SizeUnit.in);
|
||||
public static Size PAD_SIZE = new Size(0.08d, SizeUnit.in);
|
||||
public static Size HOLE_SIZE = new Size(0.7d, SizeUnit.mm);
|
||||
|
||||
// private Area copperArea;
|
||||
protected Size spacing = SPACING;
|
||||
protected Color padColor = COPPER_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 diameter = getClosestOdd(PAD_SIZE.convertToPixels());
|
||||
int holeDiameter = getClosestOdd(HOLE_SIZE.convertToPixels());
|
||||
int spacing = 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(padColor);
|
||||
g2d.fillOval(p.x - diameter / 2, p.y - diameter / 2, diameter, diameter);
|
||||
g2d.setColor(padColor.darker());
|
||||
g2d.drawOval(p.x - diameter / 2, p.y - diameter / 2, diameter, diameter);
|
||||
g2d.setColor(Constants.CANVAS_COLOR);
|
||||
g2d.fillOval(p.x - holeDiameter / 2, p.y - holeDiameter / 2, holeDiameter,
|
||||
holeDiameter);
|
||||
g2d.setColor(padColor.darker());
|
||||
g2d.drawOval(p.x - holeDiameter / 2, p.y - holeDiameter / 2, holeDiameter,
|
||||
holeDiameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Pad color")
|
||||
public Color getPadColor() {
|
||||
return padColor;
|
||||
}
|
||||
|
||||
public void setPadColor(Color padColor) {
|
||||
this.padColor = padColor;
|
||||
}
|
||||
|
||||
@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(COPPER_COLOR);
|
||||
g2d.fillOval(width / 4, width / 4, width / 2, width / 2);
|
||||
g2d.setColor(COPPER_COLOR.darker());
|
||||
g2d.drawOval(width / 4, width / 4, width / 2, width / 2);
|
||||
g2d.setColor(Constants.CANVAS_COLOR);
|
||||
g2d.fillOval(width / 2 - 2, width / 2 - 2, 5, 5);
|
||||
g2d.setColor(COPPER_COLOR.darker());
|
||||
g2d.drawOval(width / 2 - 2, width / 2 - 2, 5, 5);
|
||||
}
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
package org.diylc.components.boards;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Composite;
|
||||
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 = "Vero Board", category = "Boards", author = "Branislav Stojkovic", zOrder = IDIYComponent.BOARD, instanceNamePrefix = "Board", description = "Perforated FR4 board with copper strips connecting all holes in a row")
|
||||
public class VeroBoard extends AbstractBoard {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Color STRIP_COLOR = Color.decode("#DA8A67");
|
||||
public static Color BORDER_COLOR = BOARD_COLOR.darker();
|
||||
|
||||
public static Size SPACING = new Size(0.1d, SizeUnit.in);
|
||||
public static Size STRIP_SIZE = new Size(0.07d, SizeUnit.in);
|
||||
public static Size HOLE_SIZE = new Size(0.7d, SizeUnit.mm);
|
||||
|
||||
protected Size spacing = SPACING;
|
||||
protected Color stripColor = STRIP_COLOR;
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||
IDrawingObserver drawingObserver) {
|
||||
super.draw(g2d, componentState, project, drawingObserver);
|
||||
|
||||
if (componentState != ComponentState.DRAGGING) {
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
if (alpha < MAX_ALPHA) {
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
|
||||
/ MAX_ALPHA));
|
||||
}
|
||||
Point p = new Point(firstPoint);
|
||||
int stripSize = getClosestOdd(STRIP_SIZE.convertToPixels());
|
||||
int holeSize = getClosestOdd(HOLE_SIZE.convertToPixels());
|
||||
int spacing = 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,
|
||||
secondPoint.x - spacing - p.x, stripSize);
|
||||
g2d.setColor(stripColor.darker());
|
||||
g2d.drawRect(p.x + SPACING.convertToPixels() / 2, p.y - stripSize / 2,
|
||||
secondPoint.x - spacing - p.x, stripSize);
|
||||
while (p.x < secondPoint.x - spacing) {
|
||||
p.x += spacing;
|
||||
g2d.setColor(Constants.CANVAS_COLOR);
|
||||
g2d.fillOval(p.x - holeSize / 2, p.y - holeSize / 2, holeSize, holeSize);
|
||||
g2d.setColor(stripColor.darker());
|
||||
g2d.drawOval(p.x - holeSize / 2, p.y - holeSize / 2, holeSize, holeSize);
|
||||
}
|
||||
}
|
||||
g2d.setComposite(oldComposite);
|
||||
}
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Strip color")
|
||||
public Color getStripColor() {
|
||||
return stripColor;
|
||||
}
|
||||
|
||||
public void setStripColor(Color padColor) {
|
||||
this.stripColor = padColor;
|
||||
}
|
||||
|
||||
@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(STRIP_COLOR);
|
||||
g2d.fillRect(4, width / 4, width - 8, width / 2);
|
||||
g2d.setColor(STRIP_COLOR.darker());
|
||||
g2d.drawRect(4, width / 4, width - 8, width / 2);
|
||||
g2d.setColor(Constants.CANVAS_COLOR);
|
||||
g2d.fillOval(width / 3 - 2, width / 2 - 2, 5, 5);
|
||||
g2d.fillOval(2 * width / 3 - 2, width / 2 - 2, 5, 5);
|
||||
g2d.setColor(STRIP_COLOR.darker());
|
||||
g2d.drawOval(width / 3 - 2, width / 2 - 2, 5, 5);
|
||||
g2d.drawOval(2 * width / 3 - 2, width / 2 - 2, 5, 5);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package org.diylc.components.connectivity;
|
||||
|
||||
public enum AWG {
|
||||
|
||||
_8, _10, _12, _14, _16, _18, _20, _22, _24, _26, _28, _30;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "#" + name().replace("_", "");
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return Integer.parseInt(name().replace("_", ""));
|
||||
}
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
package org.diylc.components.connectivity;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Shape;
|
||||
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.components.AbstractLeadedComponent;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.CreationMethod;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
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;
|
||||
|
||||
@ComponentDescriptor(name = "Copper Trace", author = "Branislav Stojkovic", category = "Connectivity", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "Trace", description = "Straight copper trace", zOrder = IDIYComponent.TRACE)
|
||||
public class CopperTrace extends AbstractLeadedComponent<Void> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Size THICKNESS = new Size(1d, SizeUnit.mm);
|
||||
public static Color COLOR = Color.black;
|
||||
|
||||
private Color leadColor = COLOR;
|
||||
private Size leadThickness = THICKNESS;
|
||||
|
||||
@Override
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(3));
|
||||
g2d.setColor(COLOR);
|
||||
g2d.drawLine(1, height - 2, width - 2, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Color getLeadColor(ComponentState componentState) {
|
||||
return componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : leadColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.WHEN_SELECTED;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Color")
|
||||
public Color getLeadColor() {
|
||||
return leadColor;
|
||||
}
|
||||
|
||||
public void setLeadColor(Color leadColor) {
|
||||
this.leadColor = leadColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
@EditableProperty(name = "Thickness")
|
||||
public Size getLeadThickness() {
|
||||
return leadThickness;
|
||||
}
|
||||
|
||||
public void setLeadThickness(Size leadThickness) {
|
||||
this.leadThickness = leadThickness;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldShadeLeads() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Color getBodyColor() {
|
||||
return super.getBodyColor();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public Color getBorderColor() {
|
||||
// TODO Auto-generated method stub
|
||||
return super.getBorderColor();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public Byte getAlpha() {
|
||||
return super.getAlpha();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public Size getLength() {
|
||||
return super.getLength();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public Size getWidth() {
|
||||
return super.getWidth();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public Void getValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public void setValue(Void value) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Shape getBodyShape() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Size getDefaultWidth() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Size getDefaultLength() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package org.diylc.components.connectivity;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.geom.CubicCurve2D;
|
||||
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.components.AbstractCurvedComponent;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
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 = "Curved Trace", author = "Branislav Stojkovic", category = "Connectivity", instanceNamePrefix = "Trace", description = "Curved copper trace with two control points", zOrder = IDIYComponent.TRACE)
|
||||
public class CurvedTrace extends AbstractCurvedComponent<Void> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Color COLOR = Color.black;
|
||||
public static Size SIZE = new Size(1d, SizeUnit.mm);
|
||||
|
||||
protected Size size = SIZE;
|
||||
|
||||
@Override
|
||||
protected Color getDefaultColor() {
|
||||
return COLOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawCurve(CubicCurve2D curve, Graphics2D g2d, ComponentState componentState) {
|
||||
int thickness = size.convertToPixels();
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(thickness));
|
||||
g2d.setColor(componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : color);
|
||||
g2d.draw(curve);
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Width")
|
||||
public Size getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(Size size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public Void getValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Void value) {
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public Byte getAlpha() {
|
||||
return super.getAlpha();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlpha(Byte alpha) {
|
||||
super.setAlpha(alpha);
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package org.diylc.components.connectivity;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.geom.CubicCurve2D;
|
||||
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.components.AbstractCurvedComponent;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Hookup Wire", author = "Branislav Stojkovic", category = "Connectivity", instanceNamePrefix = "W", description = "Flexible wire with two control points", zOrder = IDIYComponent.COMPONENT)
|
||||
public class HookupWire extends AbstractCurvedComponent<Void> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Color COLOR = Color.green;
|
||||
public static double INSULATION_THICKNESS_PCT = 0.3;
|
||||
|
||||
protected AWG gauge = AWG._22;
|
||||
|
||||
@Override
|
||||
protected Color getDefaultColor() {
|
||||
return COLOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawCurve(CubicCurve2D curve, Graphics2D g2d, ComponentState componentState) {
|
||||
int thickness = (int) (Math.
|
||||
pow(Math.E, -1.12436 - 0.11594 * gauge.getValue())
|
||||
* Constants.PIXELS_PER_INCH * (1 + 2 * INSULATION_THICKNESS_PCT));
|
||||
g2d.setColor(componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : color.darker());
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(thickness));
|
||||
g2d.draw(curve);
|
||||
if (componentState == ComponentState.NORMAL) {
|
||||
g2d.setColor(color);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(thickness - 2));
|
||||
g2d.draw(curve);
|
||||
}
|
||||
}
|
||||
|
||||
@EditableProperty(name = "AWG")
|
||||
public AWG getGauge() {
|
||||
return gauge;
|
||||
}
|
||||
|
||||
public void setGauge(AWG gauge) {
|
||||
this.gauge = gauge;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void getValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Void value) {
|
||||
}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
package org.diylc.components.connectivity;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Shape;
|
||||
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.components.AbstractLeadedComponent;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.CreationMethod;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.measures.Size;
|
||||
|
||||
@ComponentDescriptor(name = "Jumper", author = "Branislav Stojkovic", category = "Connectivity", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "J", description = "", zOrder = IDIYComponent.COMPONENT)
|
||||
public class Jumper extends AbstractLeadedComponent<Void> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Color COLOR = Color.blue;
|
||||
|
||||
@Override
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
g2d.setColor(COLOR);
|
||||
g2d.drawLine(1, height - 2, width - 2, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@EditableProperty(name = "Color")
|
||||
public Color getLeadColor(ComponentState componentState) {
|
||||
return componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : COLOR;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Color getBodyColor() {
|
||||
return super.getBodyColor();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public Color getBorderColor() {
|
||||
return super.getBorderColor();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public Byte getAlpha() {
|
||||
return super.getAlpha();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public Size getLength() {
|
||||
return super.getLength();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public Size getWidth() {
|
||||
return super.getWidth();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public Void getValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public void setValue(Void value) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Shape getBodyShape() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Size getDefaultWidth() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Size getDefaultLength() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
package org.diylc.components.connectivity;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
|
||||
import org.diylc.components.AbstractComponent;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.Project;
|
||||
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 = "Solder Pad", category = "Connectivity", author = "Branislav Stojkovic", description = "test", instanceNamePrefix = "Pad", stretchable = false, zOrder = IDIYComponent.TRACE + 0.1)
|
||||
public class SolderPad extends AbstractComponent<Void> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Size SIZE = new Size(0.09d, SizeUnit.in);
|
||||
public static Size HOLE_SIZE = new Size(0.8d, SizeUnit.mm);
|
||||
public static Color COLOR = Color.black;
|
||||
|
||||
private Size size = SIZE;
|
||||
private Color color = COLOR;
|
||||
private Point point = new Point(0, 0);
|
||||
private Type type = Type.ROUND;
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||
IDrawingObserver drawingObserver) {
|
||||
int diameter = getClosestOdd(size.convertToPixels());
|
||||
int holeDiameter = getClosestOdd(HOLE_SIZE.convertToPixels());
|
||||
g2d.setColor(componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : color);
|
||||
if (type == Type.ROUND) {
|
||||
g2d.fillOval(point.x - diameter / 2, point.y - diameter / 2, diameter, diameter);
|
||||
} else {
|
||||
g2d.fillRect(point.x - diameter / 2, point.y - diameter / 2, diameter, diameter);
|
||||
}
|
||||
g2d.setColor(Constants.CANVAS_COLOR);
|
||||
g2d.fillOval(point.x - holeDiameter / 2, point.y - holeDiameter / 2, holeDiameter,
|
||||
holeDiameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
int diameter = getClosestOdd(width / 2);
|
||||
int holeDiameter = 5;
|
||||
g2d.setColor(COLOR);
|
||||
g2d.fillOval((width - diameter) / 2, (height - diameter) / 2, diameter, diameter);
|
||||
g2d.setColor(Constants.CANVAS_COLOR);
|
||||
g2d.fillOval((width - holeDiameter) / 2, (height - holeDiameter) / 2, holeDiameter,
|
||||
holeDiameter);
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Size getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(Size size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public String getName() {
|
||||
return super.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getControlPointCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControlPointSticky(int index) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.NEVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
return point;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
this.point.setLocation(point);
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Color")
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public Void getValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Void value) {
|
||||
}
|
||||
|
||||
static enum Type {
|
||||
ROUND, SQUARE;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().substring(0, 1) + name().substring(1).toLowerCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,132 +0,0 @@
|
||||
package org.diylc.components.connectivity;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.components.AbstractComponent;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.Project;
|
||||
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;
|
||||
|
||||
@ComponentDescriptor(name = "Trace Cut", category = "Connectivity", author = "Branislav Stojkovic", description = "Designates the place where a trace on the vero board needs to be cut", instanceNamePrefix = "Cut", stretchable = false, zOrder = IDIYComponent.BOARD + 1)
|
||||
public class TraceCut extends AbstractComponent<Void> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Size SIZE = new Size(0.07d, SizeUnit.in);
|
||||
public static Color FILL_COLOR = Color.white;
|
||||
public static Color BORDER_COLOR = Color.red;
|
||||
public static Color SELECTION_COLOR = Color.blue;
|
||||
|
||||
private Size size = SIZE;
|
||||
private Color fillColor = FILL_COLOR;
|
||||
private Color borderColor = BORDER_COLOR;
|
||||
|
||||
protected Point point = new Point(0, 0);
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||
IDrawingObserver drawingObserver) {
|
||||
int size = getClosestOdd(this.size.convertToPixels());
|
||||
int dotDiameter = size - 6;
|
||||
g2d.setColor(fillColor);
|
||||
g2d.fillRect(point.x - size / 2, point.y - size / 2, size, size);
|
||||
g2d.setColor(componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
g2d.drawRect(point.x - size / 2, point.y - size / 2, size, size);
|
||||
g2d
|
||||
.fillOval(point.x - dotDiameter / 2, point.y - dotDiameter / 2, dotDiameter,
|
||||
dotDiameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
int size = 16;
|
||||
int dotDiameter = size / 4 * 2;
|
||||
g2d.setColor(FILL_COLOR);
|
||||
g2d.fillRect((width - size) / 2, (height - size) / 2, size, size);
|
||||
g2d.setColor(BORDER_COLOR);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
g2d.drawRect((width - size) / 2, (height - size) / 2, size, size);
|
||||
g2d.fillOval((width - dotDiameter) / 2, (height - dotDiameter) / 2, dotDiameter,
|
||||
dotDiameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getControlPointCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
return point;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControlPointSticky(int index) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.NEVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
this.point.setLocation(point);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public Void getValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public void setValue(Void value) {
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Size getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(Size size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Fill")
|
||||
public Color getFillColor() {
|
||||
return fillColor;
|
||||
}
|
||||
|
||||
public void setFillColor(Color fillColor) {
|
||||
this.fillColor = fillColor;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Border")
|
||||
public Color getBorderColor() {
|
||||
return borderColor;
|
||||
}
|
||||
|
||||
public void setBorderColor(Color borderColor) {
|
||||
this.borderColor = borderColor;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public String getName() {
|
||||
return super.getName();
|
||||
}
|
||||
}
|
||||
@@ -1,249 +0,0 @@
|
||||
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.Shape;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
|
||||
import org.diylc.common.ObjectCache;
|
||||
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.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;
|
||||
|
||||
@ComponentDescriptor(name = "Mini Toggle Switch", category = "Electromechanical", author = "Branislav Stojkovic", description = "Panel mounted mini toggle switch", stretchable = false, zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "SW")
|
||||
public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchType> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static Size SPACING = new Size(0.2d, 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 LUG_WIDTH = new Size(0.060d, SizeUnit.in);
|
||||
private static Size LUG_HEIGHT = new Size(0.03d, SizeUnit.in);
|
||||
|
||||
private static Color BODY_COLOR = Color.decode("#3299CC");
|
||||
private static Color BORDER_COLOR = BODY_COLOR.darker();
|
||||
private static Color CIRCLE_COLOR = Color.red;
|
||||
private static Color LUG_COLOR = Color.decode("#00B2EE");
|
||||
|
||||
protected Point[] controlPoints = new Point[] { new Point(0, 0) };
|
||||
protected RoundRectangle2D body;
|
||||
protected String name;
|
||||
protected ToggleSwitchType switchType = ToggleSwitchType.DPDT;
|
||||
|
||||
public MiniToggleSwitch() {
|
||||
super();
|
||||
updateControlPoints();
|
||||
}
|
||||
|
||||
private void updateControlPoints() {
|
||||
Point firstPoint = controlPoints[0];
|
||||
int spacing = SPACING.convertToPixels();
|
||||
switch (switchType) {
|
||||
case SPST:
|
||||
controlPoints = new Point[] { firstPoint,
|
||||
new Point(firstPoint.x, firstPoint.y + spacing) };
|
||||
break;
|
||||
case SPDT:
|
||||
controlPoints = new Point[] { firstPoint,
|
||||
new Point(firstPoint.x, firstPoint.y + spacing),
|
||||
new Point(firstPoint.x, firstPoint.y + 2 * spacing) };
|
||||
break;
|
||||
case DPDT:
|
||||
controlPoints = new Point[] { firstPoint,
|
||||
new Point(firstPoint.x, firstPoint.y + spacing),
|
||||
new Point(firstPoint.x, firstPoint.y + 2 * spacing),
|
||||
new Point(firstPoint.x + spacing, firstPoint.y),
|
||||
new Point(firstPoint.x + spacing, firstPoint.y + spacing),
|
||||
new Point(firstPoint.x + spacing, firstPoint.y + 2 * spacing) };
|
||||
break;
|
||||
case _3PDT:
|
||||
controlPoints = new Point[] { firstPoint,
|
||||
new Point(firstPoint.x, firstPoint.y + spacing),
|
||||
new Point(firstPoint.x, firstPoint.y + 2 * spacing),
|
||||
new Point(firstPoint.x + spacing, firstPoint.y),
|
||||
new Point(firstPoint.x + spacing, firstPoint.y + spacing),
|
||||
new Point(firstPoint.x + spacing, firstPoint.y + 2 * spacing),
|
||||
new Point(firstPoint.x + 2 * spacing, firstPoint.y),
|
||||
new Point(firstPoint.x + 2 * spacing, firstPoint.y + spacing),
|
||||
new Point(firstPoint.x + 2 * spacing, firstPoint.y + 2 * spacing) };
|
||||
break;
|
||||
case _4PDT:
|
||||
controlPoints = new Point[] { firstPoint,
|
||||
new Point(firstPoint.x, firstPoint.y + spacing),
|
||||
new Point(firstPoint.x, firstPoint.y + 2 * spacing),
|
||||
new Point(firstPoint.x + spacing, firstPoint.y),
|
||||
new Point(firstPoint.x + spacing, firstPoint.y + spacing),
|
||||
new Point(firstPoint.x + spacing, firstPoint.y + 2 * spacing),
|
||||
new Point(firstPoint.x + 2 * spacing, firstPoint.y),
|
||||
new Point(firstPoint.x + 2 * spacing, firstPoint.y + spacing),
|
||||
new Point(firstPoint.x + 2 * spacing, firstPoint.y + 2 * spacing),
|
||||
new Point(firstPoint.x + 3 * spacing, firstPoint.y),
|
||||
new Point(firstPoint.x + 3 * spacing, firstPoint.y + spacing),
|
||||
new Point(firstPoint.x + 3 * spacing, firstPoint.y + 2 * spacing) };
|
||||
break;
|
||||
case _5PDT:
|
||||
controlPoints = new Point[] { firstPoint,
|
||||
new Point(firstPoint.x, firstPoint.y + spacing),
|
||||
new Point(firstPoint.x, firstPoint.y + 2 * spacing),
|
||||
new Point(firstPoint.x + spacing, firstPoint.y),
|
||||
new Point(firstPoint.x + spacing, firstPoint.y + spacing),
|
||||
new Point(firstPoint.x + spacing, firstPoint.y + 2 * spacing),
|
||||
new Point(firstPoint.x + 2 * spacing, firstPoint.y),
|
||||
new Point(firstPoint.x + 2 * spacing, firstPoint.y + spacing),
|
||||
new Point(firstPoint.x + 2 * spacing, firstPoint.y + 2 * spacing),
|
||||
new Point(firstPoint.x + 3 * spacing, firstPoint.y),
|
||||
new Point(firstPoint.x + 3 * spacing, firstPoint.y + spacing),
|
||||
new Point(firstPoint.x + 3 * spacing, firstPoint.y + 2 * spacing),
|
||||
new Point(firstPoint.x + 4 * spacing, firstPoint.y),
|
||||
new Point(firstPoint.x + 4 * spacing, firstPoint.y + spacing),
|
||||
new Point(firstPoint.x + 4 * spacing, firstPoint.y + 2 * spacing) };
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@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 int getControlPointCount() {
|
||||
return controlPoints.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
controlPoints[index].setLocation(point);
|
||||
// Reset body shape.
|
||||
body = null;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Type")
|
||||
@Override
|
||||
public ToggleSwitchType getValue() {
|
||||
return switchType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(ToggleSwitchType value) {
|
||||
this.switchType = value;
|
||||
updateControlPoints();
|
||||
// Reset body shape.
|
||||
body = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||
IDrawingObserver drawingObserver) {
|
||||
Shape body = getBody();
|
||||
// Draw body if available.
|
||||
if (body != null) {
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
if (alpha < MAX_ALPHA) {
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
|
||||
/ MAX_ALPHA));
|
||||
}
|
||||
g2d.setColor(BODY_COLOR);
|
||||
g2d.fill(body);
|
||||
g2d.setComposite(oldComposite);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
g2d.setColor(componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : BORDER_COLOR);
|
||||
g2d.draw(body);
|
||||
}
|
||||
// Do not track these changes because the whole switch has been tracked
|
||||
// so far.
|
||||
drawingObserver.stopTracking();
|
||||
// Draw lugs.
|
||||
int circleDiameter = getClosestOdd(CIRCLE_SIZE.convertToPixels());
|
||||
int lugWidth = getClosestOdd(LUG_WIDTH.convertToPixels());
|
||||
int lugHeight = getClosestOdd(LUG_HEIGHT.convertToPixels());
|
||||
for (Point p : controlPoints) {
|
||||
g2d.setColor(CIRCLE_COLOR);
|
||||
g2d.fillOval(p.x - circleDiameter / 2, p.y - circleDiameter / 2, circleDiameter,
|
||||
circleDiameter);
|
||||
g2d.setColor(LUG_COLOR);
|
||||
g2d.fillRect(p.x - lugWidth / 2, p.y - lugHeight / 2, lugWidth, lugHeight);
|
||||
}
|
||||
}
|
||||
|
||||
public RoundRectangle2D getBody() {
|
||||
if (body == null) {
|
||||
Point firstPoint = controlPoints[0];
|
||||
int margin = MARGIN.convertToPixels();
|
||||
int spacing = SPACING.convertToPixels();
|
||||
switch (switchType) {
|
||||
case SPST:
|
||||
body = new RoundRectangle2D.Double(firstPoint.x - margin, firstPoint.y - margin,
|
||||
2 * margin, 2 * margin + spacing, margin, margin);
|
||||
break;
|
||||
case SPDT:
|
||||
body = new RoundRectangle2D.Double(firstPoint.x - margin, firstPoint.y - margin,
|
||||
2 * margin, 2 * margin + 2 * spacing, margin, margin);
|
||||
break;
|
||||
case DPDT:
|
||||
body = new RoundRectangle2D.Double(firstPoint.x - margin, firstPoint.y - margin, 2
|
||||
* margin + spacing, 2 * margin + 2 * spacing, margin, margin);
|
||||
break;
|
||||
case _3PDT:
|
||||
body = new RoundRectangle2D.Double(firstPoint.x - margin, firstPoint.y - margin, 2
|
||||
* margin + 2 * spacing, 2 * margin + 2 * spacing, margin, margin);
|
||||
break;
|
||||
case _4PDT:
|
||||
body = new RoundRectangle2D.Double(firstPoint.x - margin, firstPoint.y - margin, 2
|
||||
* margin + 3 * spacing, 2 * margin + 2 * spacing, margin, margin);
|
||||
break;
|
||||
case _5PDT:
|
||||
body = new RoundRectangle2D.Double(firstPoint.x - margin, firstPoint.y - margin, 2
|
||||
* margin + 4 * spacing, 2 * margin + 2 * spacing, margin, margin);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
int circleSize = 5 * width / 32;
|
||||
g2d.setColor(BODY_COLOR);
|
||||
g2d.fillRoundRect(width / 4, 1, width / 2, height - 2, circleSize, circleSize);
|
||||
g2d.setColor(BORDER_COLOR);
|
||||
g2d.drawRoundRect(width / 4, 1, width / 2, height - 2, circleSize, circleSize);
|
||||
g2d.setColor(CIRCLE_COLOR);
|
||||
for (int i = 1; i <= 3; i++) {
|
||||
g2d.fillOval(width / 2 - circleSize / 2, i * height / 4 - 3, circleSize, circleSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package org.diylc.components.electromechanical;
|
||||
|
||||
public enum ToggleSwitchType {
|
||||
|
||||
SPST, SPDT, DPDT, _3PDT, _4PDT, _5PDT;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().replace("_", "");
|
||||
}
|
||||
}
|
||||
@@ -1,171 +0,0 @@
|
||||
package org.diylc.components.misc;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.diylc.components.AbstractComponent;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.Project;
|
||||
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.swing.plugins.file.BomEntry;
|
||||
import org.diylc.swing.plugins.file.BomMaker;
|
||||
|
||||
@ComponentDescriptor(name = "Bill of Materials", author = "Branislav Stojkovic", category = "Misc", description = "", instanceNamePrefix = "BOM", zOrder = IDIYComponent.TEXT, stretchable = false)
|
||||
public class BOM extends AbstractComponent<Void> {
|
||||
|
||||
public static Size DEFAULT_SIZE = new Size(10d, SizeUnit.cm);
|
||||
public static Size SPACING = new Size(0.1d, SizeUnit.in);
|
||||
public static Color COLOR = Color.black;
|
||||
public static String DEFAULT_TEXT = "No components to show in the Bill of Materials";
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Size size = DEFAULT_SIZE;
|
||||
|
||||
private Point point = new Point(0, 0);
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||
IDrawingObserver drawingObserver) {
|
||||
List<BomEntry> bom = BomMaker.getInstance().createBom(project.getComponents());
|
||||
// Cleanup entries that do not have a value set.
|
||||
Iterator<BomEntry> iterator = bom.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
BomEntry entry = iterator.next();
|
||||
if (entry.getValue() == null || entry.getName().toLowerCase().contains("bom")) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
g2d.setFont(LABEL_FONT);
|
||||
g2d.setColor(componentState == ComponentState.DRAGGING
|
||||
|| componentState == ComponentState.SELECTED ? SELECTION_COLOR : COLOR);
|
||||
// Determine maximum name length and maximum value length to calculate
|
||||
// number of columns.
|
||||
FontMetrics fontMetrics = g2d.getFontMetrics();
|
||||
int maxNameWidth = 0;
|
||||
int maxValueWidth = 0;
|
||||
int maxHeight = 0;
|
||||
for (BomEntry entry : bom) {
|
||||
Rectangle2D stringBounds = fontMetrics.getStringBounds(entry.getName(), g2d);
|
||||
if (stringBounds.getWidth() > maxNameWidth) {
|
||||
maxNameWidth = (int) stringBounds.getWidth();
|
||||
}
|
||||
if (stringBounds.getHeight() > maxHeight) {
|
||||
maxHeight = (int) stringBounds.getHeight();
|
||||
}
|
||||
stringBounds = fontMetrics.getStringBounds(entry.getValue().toString(), g2d);
|
||||
if (stringBounds.getWidth() > maxValueWidth) {
|
||||
maxValueWidth = (int) stringBounds.getWidth();
|
||||
}
|
||||
if (stringBounds.getHeight() > maxHeight) {
|
||||
maxHeight = (int) stringBounds.getHeight();
|
||||
}
|
||||
}
|
||||
// Calculate maximum entry size.
|
||||
int maxEntrySize = maxNameWidth + maxValueWidth + 2 * SPACING.convertToPixels();
|
||||
int columnCount = size.convertToPixels() / maxEntrySize;
|
||||
int columnWidth = size.convertToPixels() / columnCount;
|
||||
int entriesPerColumn = (int) Math.ceil(1.d * bom.size() / columnCount);
|
||||
if (entriesPerColumn == 0) {
|
||||
g2d.drawString(DEFAULT_TEXT, point.x, point.y);
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < bom.size(); i++) {
|
||||
int columnIndex = i / entriesPerColumn;
|
||||
int rowIndex = i % entriesPerColumn;
|
||||
int x = point.x + columnIndex * columnWidth;
|
||||
int y = point.y + rowIndex * maxHeight;
|
||||
g2d.drawString(bom.get(i).getName(), x, y);
|
||||
x += maxNameWidth + SPACING.convertToPixels();
|
||||
g2d.drawString(bom.get(i).getValue().toString(), x, y);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
g2d.setColor(Color.white);
|
||||
g2d.fillRect(width / 8, 0, 6 * width / 8, height - 1);
|
||||
g2d.setColor(Color.black);
|
||||
g2d.drawRect(width / 8, 0, 6 * width / 8, height - 1);
|
||||
g2d.setFont(LABEL_FONT.deriveFont(1f * 9 * width / 32).deriveFont(Font.PLAIN));
|
||||
|
||||
FontMetrics fontMetrics = g2d.getFontMetrics();
|
||||
Rectangle2D rect = fontMetrics.getStringBounds("BOM", g2d);
|
||||
|
||||
int textHeight = (int) (rect.getHeight());
|
||||
int textWidth = (int) (rect.getWidth());
|
||||
|
||||
// Center text horizontally and vertically.
|
||||
int x = (width - textWidth) / 2 + 1;
|
||||
int y = textHeight + 2;
|
||||
|
||||
g2d.drawString("BOM", x, y);
|
||||
|
||||
g2d.setFont(g2d.getFont().deriveFont(1f * 5 * width / 32));
|
||||
|
||||
fontMetrics = g2d.getFontMetrics();
|
||||
rect = fontMetrics.getStringBounds("resistors", g2d);
|
||||
x = (width - textWidth) / 2 + 1;
|
||||
y = height / 2 + 2;
|
||||
g2d.drawString("resistors", x, y);
|
||||
y += rect.getHeight() - 1;
|
||||
g2d.drawString("tubes", x, y);
|
||||
y += rect.getHeight() - 1;
|
||||
g2d.drawString("diodes", x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getControlPointCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
return point;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControlPointSticky(int index) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.NEVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
this.point.setLocation(point);
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Width")
|
||||
public Size getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(Size size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public Void getValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Void value) {
|
||||
}
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
package org.diylc.components.misc;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.ImageObserver;
|
||||
import java.awt.image.MemoryImageSource;
|
||||
import java.awt.image.PixelGrabber;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.thoughtworks.xstream.converters.Converter;
|
||||
import com.thoughtworks.xstream.converters.MarshallingContext;
|
||||
import com.thoughtworks.xstream.converters.UnmarshallingContext;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
||||
|
||||
public class IconImageConverter implements Converter {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(IconImageConverter.class);
|
||||
|
||||
@Override
|
||||
public void marshal(Object object, HierarchicalStreamWriter writer, MarshallingContext context) {
|
||||
ImageIcon image = (ImageIcon) object;
|
||||
int width = image.getIconWidth();
|
||||
int height = image.getIconHeight();
|
||||
int[] pixels = new int[width * height];
|
||||
|
||||
if (image != null) {
|
||||
try {
|
||||
PixelGrabber pg = new PixelGrabber(image.getImage(), 0, 0, width, height, pixels,
|
||||
0, width);
|
||||
pg.grabPixels();
|
||||
if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
|
||||
LOG.error("Failed to load image contents");
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
LOG.error("Image load interrupted");
|
||||
}
|
||||
}
|
||||
LOG.debug("Writing image to file: " + width + "x" + height);
|
||||
writer.addAttribute("width", Integer.toString(width));
|
||||
writer.addAttribute("height", Integer.toString(height));
|
||||
StringBuilder dataBuilder = new StringBuilder();
|
||||
for (int pixel : pixels) {
|
||||
dataBuilder.append(Integer.toString(pixel, 16));
|
||||
dataBuilder.append(",");
|
||||
}
|
||||
writer.addAttribute("data", dataBuilder.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
|
||||
int width = Integer.parseInt(reader.getAttribute("width"));
|
||||
int height = Integer.parseInt(reader.getAttribute("height"));
|
||||
LOG.debug("Reading image from file: " + width + "x" + height);
|
||||
int[] pixels = new int[width * height];
|
||||
String data = reader.getAttribute("data");
|
||||
String[] splitData = data.split(",");
|
||||
for (int i = 0; i < splitData.length; i++) {
|
||||
if (!splitData[i].isEmpty()) {
|
||||
pixels[i] = Integer.parseInt(splitData[i], 16);
|
||||
}
|
||||
}
|
||||
|
||||
Toolkit toolkit = Toolkit.getDefaultToolkit();
|
||||
ColorModel colorModel = ColorModel.getRGBdefault();
|
||||
Image image = toolkit.createImage(new MemoryImageSource(width, height, colorModel, pixels,
|
||||
0, width));
|
||||
|
||||
BufferedImage bimg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
bimg.setRGB(0, 0, width, height, pixels, 0, width);
|
||||
File outputfile = new File("c:\\saved.png");
|
||||
try {
|
||||
ImageIO.write(bimg, "png", outputfile);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new ImageIcon(image);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConvert(Class clazz) {
|
||||
return ImageIcon.class.isAssignableFrom(clazz);
|
||||
}
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
package org.diylc.components.misc;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Composite;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
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.VisibilityPolicy;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamConverter;
|
||||
|
||||
@ComponentDescriptor(name = "Image", author = "Branislav Stojkovic", category = "Misc", description = "User defined image", instanceNamePrefix = "Img", zOrder = IDIYComponent.TEXT, stretchable = false)
|
||||
public class Image extends AbstractTransparentComponent<Void> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
public static String DEFAULT_TEXT = "Double click to edit text";
|
||||
private static ImageIcon ICON;
|
||||
private static byte DEFAULT_SCALE = 50;
|
||||
|
||||
static {
|
||||
String name = "image.png";
|
||||
java.net.URL imgURL = Image.class.getResource(name);
|
||||
if (imgURL != null) {
|
||||
ICON = new ImageIcon(imgURL, name);
|
||||
}
|
||||
}
|
||||
|
||||
private Point point = new Point(0, 0);
|
||||
@XStreamConverter(IconImageConverter.class)
|
||||
private ImageIcon image = ICON;
|
||||
private byte scale = 50;
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||
IDrawingObserver drawingObserver) {
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
if (alpha < MAX_ALPHA) {
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
|
||||
/ MAX_ALPHA));
|
||||
}
|
||||
double s = 1d * scale / DEFAULT_SCALE;
|
||||
g2d.scale(s, s);
|
||||
g2d.drawImage(image.getImage(), (int) (point.x / s), (int) (point.y / s), null);
|
||||
if (componentState == ComponentState.SELECTED) {
|
||||
g2d.setComposite(oldComposite);
|
||||
g2d.scale(1 / s, 1 / s);
|
||||
g2d.setColor(SELECTION_COLOR);
|
||||
g2d.drawRect(point.x, point.y, (int) (image.getIconWidth() * s), (int) (image
|
||||
.getIconHeight() * s));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
g2d.drawImage(ICON.getImage(), point.x, point.y, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getControlPointCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
return point;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControlPointSticky(int index) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.NEVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
this.point.setLocation(point);
|
||||
}
|
||||
|
||||
@EditableProperty(defaultable = false)
|
||||
public ImageIcon getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public void setImage(ImageIcon image) {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
@EditableProperty(defaultable = false)
|
||||
public byte getScale() {
|
||||
return scale;
|
||||
}
|
||||
|
||||
public void setScale(byte scale) {
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return super.getName();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public Void getValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Void value) {
|
||||
}
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
package org.diylc.components.misc;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.components.AbstractComponent;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.VisibilityPolicy;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
|
||||
@ComponentDescriptor(name = "Label", author = "Branislav Stojkovic", category = "Misc", description = "User defined label", instanceNamePrefix = "L", zOrder = IDIYComponent.TEXT, stretchable = false)
|
||||
public class Label extends AbstractComponent<Void> {
|
||||
|
||||
public static String DEFAULT_TEXT = "Double click to edit text";
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Point point = new Point(0, 0);
|
||||
private String text = DEFAULT_TEXT;
|
||||
private Font font = LABEL_FONT;
|
||||
private Color color = LABEL_COLOR;
|
||||
private boolean center = true;
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||
IDrawingObserver drawingObserver) {
|
||||
g2d.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED : color);
|
||||
g2d.setFont(font);
|
||||
FontMetrics fontMetrics = g2d.getFontMetrics();
|
||||
Rectangle2D rect = fontMetrics.getStringBounds(text, g2d);
|
||||
|
||||
int textHeight = (int) rect.getHeight();
|
||||
int textWidth = (int) rect.getWidth();
|
||||
|
||||
int x;
|
||||
int y;
|
||||
if (center) {
|
||||
// Center text horizontally and vertically
|
||||
x = point.x - textWidth / 2;
|
||||
y = point.y - textHeight / 2 + fontMetrics.getAscent();
|
||||
} else {
|
||||
x = point.x;
|
||||
y = point.y - textHeight;
|
||||
}
|
||||
|
||||
g2d.drawString(text, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
g2d.setColor(LABEL_COLOR);
|
||||
g2d.setFont(LABEL_FONT.deriveFont(13f * width / 32).deriveFont(Font.PLAIN));
|
||||
|
||||
FontMetrics fontMetrics = g2d.getFontMetrics();
|
||||
Rectangle2D rect = fontMetrics.getStringBounds("Abc", g2d);
|
||||
|
||||
int textHeight = (int) (rect.getHeight());
|
||||
int textWidth = (int) (rect.getWidth());
|
||||
|
||||
// Center text horizontally and vertically.
|
||||
int x = (width - textWidth) / 2 + 1;
|
||||
int y = (height - textHeight) / 2 + fontMetrics.getAscent();
|
||||
|
||||
g2d.drawString("Abc", x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getControlPointCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
return point;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControlPointSticky(int index) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.NEVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
this.point.setLocation(point);
|
||||
}
|
||||
|
||||
@EditableProperty(defaultable = false)
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public boolean getCenter() {
|
||||
return center;
|
||||
}
|
||||
|
||||
public void setCenter(boolean center) {
|
||||
this.center = center;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return super.getName();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public Void getValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Void value) {
|
||||
}
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
package org.diylc.components.misc;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.components.AbstractComponent;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.VisibilityPolicy;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
|
||||
@ComponentDescriptor(name = "Project Information", author = "Branislav Stojkovic", category = "Misc", description = "Draws a box with general project information", instanceNamePrefix = "BOM", zOrder = IDIYComponent.TEXT, stretchable = false)
|
||||
public class ProjectInformation extends AbstractComponent<Void> {
|
||||
|
||||
public static Size DEFAULT_SIZE = new Size(10d, SizeUnit.cm);
|
||||
public static Color COLOR = Color.black;
|
||||
public static String DEFAULT_TEXT = "No components to show in the Bill of Materials";
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Point point = new Point(0, 0);
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||
IDrawingObserver drawingObserver) {
|
||||
g2d.setFont(LABEL_FONT);
|
||||
g2d.setColor(componentState == ComponentState.DRAGGING
|
||||
|| componentState == ComponentState.SELECTED ? SELECTION_COLOR : COLOR);
|
||||
// FontMetrics fontMetrics = g2d.getFontMetrics();
|
||||
g2d.drawString(project.getTitle(), point.x, point.y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
g2d.setColor(Color.white);
|
||||
g2d.fillRect(width / 8, 0, 6 * width / 8, height - 1);
|
||||
g2d.setColor(Color.black);
|
||||
g2d.drawRect(width / 8, 0, 6 * width / 8, height - 1);
|
||||
g2d.setFont(LABEL_FONT.deriveFont(1f * 9 * width / 32).deriveFont(Font.PLAIN));
|
||||
|
||||
FontMetrics fontMetrics = g2d.getFontMetrics();
|
||||
Rectangle2D rect = fontMetrics.getStringBounds("BOM", g2d);
|
||||
|
||||
int textHeight = (int) (rect.getHeight());
|
||||
int textWidth = (int) (rect.getWidth());
|
||||
|
||||
// Center text horizontally and vertically.
|
||||
int x = (width - textWidth) / 2 + 1;
|
||||
int y = textHeight + 2;
|
||||
|
||||
g2d.drawString("BOM", x, y);
|
||||
|
||||
g2d.setFont(g2d.getFont().deriveFont(1f * 5 * width / 32));
|
||||
|
||||
fontMetrics = g2d.getFontMetrics();
|
||||
rect = fontMetrics.getStringBounds("resistors", g2d);
|
||||
x = (width - textWidth) / 2 + 1;
|
||||
y = height / 2 + 2;
|
||||
g2d.drawString("resistors", x, y);
|
||||
y += rect.getHeight() - 1;
|
||||
g2d.drawString("tubes", x, y);
|
||||
y += rect.getHeight() - 1;
|
||||
g2d.drawString("diodes", x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getControlPointCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
return point;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControlPointSticky(int index) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.NEVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
this.point.setLocation(point);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public Void getValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Void value) {
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.6 KiB |
@@ -1,85 +0,0 @@
|
||||
package org.diylc.components.passive;
|
||||
|
||||
import java.awt.Point;
|
||||
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.components.AbstractTransparentComponent;
|
||||
import org.diylc.core.VisibilityPolicy;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.measures.Resistance;
|
||||
import org.diylc.core.measures.ResistanceUnit;
|
||||
|
||||
public abstract class AbstractPotentiometer extends
|
||||
AbstractTransparentComponent<PotentiometerValue> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected Point[] controlPoints;
|
||||
|
||||
protected Resistance resistance = new Resistance(100d, ResistanceUnit.K);
|
||||
protected Orientation orientation = Orientation.DEFAULT;
|
||||
protected Taper taper = Taper.LIN;
|
||||
|
||||
@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].setLocation(point);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.NEVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControlPointSticky(int index) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Resistance getResistance() {
|
||||
return resistance;
|
||||
}
|
||||
|
||||
public void setResistance(Resistance resistance) {
|
||||
this.resistance = resistance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PotentiometerValue getValue() {
|
||||
return new PotentiometerValue(resistance, taper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(PotentiometerValue value) {
|
||||
this.resistance = value.getResistance();
|
||||
this.taper = value.getTaper();
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Taper getTaper() {
|
||||
return taper;
|
||||
}
|
||||
|
||||
public void setTaper(Taper taper) {
|
||||
this.taper = taper;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Orientation getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
|
||||
public void setOrientation(Orientation orientation) {
|
||||
this.orientation = orientation;
|
||||
}
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
package org.diylc.components.passive;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.components.AbstractLeadedComponent;
|
||||
import org.diylc.core.CreationMethod;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.measures.Capacitance;
|
||||
import org.diylc.core.measures.CapacitanceUnit;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
|
||||
@ComponentDescriptor(name = "Electrolytic Capacitor (axial)", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "C", description = "Axial electrolytic capacitor, similar to Sprague Atom, F&T, etc", zOrder = IDIYComponent.COMPONENT)
|
||||
public class AxialElectrolyticCapacitor extends AbstractLeadedComponent<Capacitance> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Size DEFAULT_WIDTH = new Size(1d / 2, SizeUnit.in);
|
||||
public static Size DEFAULT_HEIGHT = new Size(1d / 8, SizeUnit.in);
|
||||
public static Color BODY_COLOR = Color.decode("#EAADEA");
|
||||
public static Color BORDER_COLOR = BODY_COLOR.darker();
|
||||
public static Color MARKER_COLOR = Color.gray;
|
||||
public static Color TICK_COLOR = Color.white;
|
||||
|
||||
private Capacitance value = new Capacitance(1d, CapacitanceUnit.uF);
|
||||
|
||||
private Color markerColor = MARKER_COLOR;
|
||||
private Color tickColor = TICK_COLOR;
|
||||
private boolean polarized = true;
|
||||
|
||||
public AxialElectrolyticCapacitor() {
|
||||
super();
|
||||
this.bodyColor = BODY_COLOR;
|
||||
this.borderColor = BORDER_COLOR;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Capacitance getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Capacitance value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
g2d.rotate(-Math.PI / 4, width / 2, height / 2);
|
||||
g2d.setColor(LEAD_COLOR);
|
||||
g2d.drawLine(0, height / 2, width, height / 2);
|
||||
g2d.setColor(BODY_COLOR);
|
||||
g2d.fillRect(4, height / 2 - 3, width - 8, 6);
|
||||
g2d.setColor(MARKER_COLOR);
|
||||
g2d.fillRect(width - 9, height / 2 - 3, 5, 6);
|
||||
g2d.setColor(TICK_COLOR);
|
||||
g2d.drawLine(width - 6, height / 2 - 1, width - 6, height / 2 + 1);
|
||||
g2d.setColor(BORDER_COLOR);
|
||||
g2d.drawRect(4, height / 2 - 3, width - 8, 6);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Size getDefaultWidth() {
|
||||
return DEFAULT_HEIGHT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Size getDefaultLength() {
|
||||
return DEFAULT_WIDTH;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Marker")
|
||||
public Color getMarkerColor() {
|
||||
return markerColor;
|
||||
}
|
||||
|
||||
public void setMarkerColor(Color coverColor) {
|
||||
this.markerColor = coverColor;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Tick")
|
||||
public Color getTickColor() {
|
||||
return tickColor;
|
||||
}
|
||||
|
||||
public void setTickColor(Color tickColor) {
|
||||
this.tickColor = tickColor;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Polarized")
|
||||
public boolean getPolarized() {
|
||||
return polarized;
|
||||
}
|
||||
|
||||
public void setPolarized(boolean polarized) {
|
||||
this.polarized = polarized;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Shape getBodyShape() {
|
||||
return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(),
|
||||
getClosestOdd(getWidth().convertToPixels()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decorateComponentBody(Graphics2D g2d) {
|
||||
if (polarized) {
|
||||
int markerLength = (int) (getLength().convertToPixels() * 0.2);
|
||||
g2d.setColor(markerColor);
|
||||
int width = getClosestOdd(getWidth().convertToPixels());
|
||||
g2d.fillRect(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
|
||||
/ 2, (int) (width / 2 + width * 0.15));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package org.diylc.components.passive;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.components.AbstractLeadedComponent;
|
||||
import org.diylc.core.CreationMethod;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.measures.Capacitance;
|
||||
import org.diylc.core.measures.CapacitanceUnit;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
|
||||
@ComponentDescriptor(name = "Film Capacitor (axial)", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "C", description = "Axial film capacitor, similar to Mallory 150s", zOrder = IDIYComponent.COMPONENT)
|
||||
public class AxialFilmCapacitor extends AbstractLeadedComponent<Capacitance> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Size DEFAULT_WIDTH = new Size(1d / 2, SizeUnit.in);
|
||||
public static Size DEFAULT_HEIGHT = new Size(1d / 8, SizeUnit.in);
|
||||
public static Color BODY_COLOR = Color.decode("#FFE303");
|
||||
public static Color BORDER_COLOR = BODY_COLOR.darker();
|
||||
|
||||
private Capacitance value = new Capacitance(123d, CapacitanceUnit.nF);
|
||||
|
||||
public AxialFilmCapacitor() {
|
||||
super();
|
||||
this.bodyColor = BODY_COLOR;
|
||||
this.borderColor = BORDER_COLOR;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Capacitance getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Capacitance value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
g2d.rotate(-Math.PI / 4, width / 2, height / 2);
|
||||
g2d.setColor(LEAD_COLOR);
|
||||
g2d.drawLine(0, height / 2, width, height / 2);
|
||||
g2d.setColor(BODY_COLOR);
|
||||
g2d.fillRect(4, height / 2 - 3, width - 8, 6);
|
||||
g2d.setColor(BORDER_COLOR);
|
||||
g2d.drawRect(4, height / 2 - 3, width - 8, 6);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Size getDefaultWidth() {
|
||||
return DEFAULT_HEIGHT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Size getDefaultLength() {
|
||||
return DEFAULT_WIDTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Shape getBodyShape() {
|
||||
return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(),
|
||||
getClosestOdd(getWidth().convertToPixels()));
|
||||
}
|
||||
}
|
||||
@@ -1,161 +0,0 @@
|
||||
package org.diylc.components.passive;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.components.AbstractLeadedComponent;
|
||||
import org.diylc.core.CreationMethod;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.measures.Capacitance;
|
||||
import org.diylc.core.measures.CapacitanceUnit;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
|
||||
@ComponentDescriptor(name = "Electrolytic Capacitor", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "C", description = "Vertical mounted electrolytic capacitor, polarized or bipolar", zOrder = IDIYComponent.COMPONENT)
|
||||
public class ElectrolyticRadial extends AbstractLeadedComponent<Capacitance> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Size DEFAULT_SIZE = new Size(1d / 2, SizeUnit.in);
|
||||
public static Color BODY_COLOR = Color.decode("#EAADEA");
|
||||
public static Color BORDER_COLOR = BODY_COLOR.darker();
|
||||
public static Color MARKER_COLOR = Color.gray;
|
||||
public static Color TICK_COLOR = Color.white;
|
||||
|
||||
private Capacitance value = new Capacitance(1d, CapacitanceUnit.uF);
|
||||
|
||||
private Color markerColor = MARKER_COLOR;
|
||||
private Color tickColor = TICK_COLOR;
|
||||
private boolean polarized = true;
|
||||
|
||||
public ElectrolyticRadial() {
|
||||
super();
|
||||
this.bodyColor = BODY_COLOR;
|
||||
this.borderColor = BORDER_COLOR;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Capacitance getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Capacitance value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
g2d.setColor(BODY_COLOR);
|
||||
int margin = 3;
|
||||
Ellipse2D body = new Ellipse2D.Double(margin, margin, getClosestOdd(width - 2 * margin),
|
||||
getClosestOdd(width - 2 * margin));
|
||||
g2d.fill(body);
|
||||
Area marker = new Area(body);
|
||||
marker.subtract(new Area(new Rectangle2D.Double(margin, margin, width - 4 * margin,
|
||||
getClosestOdd(width - 2 * margin))));
|
||||
g2d.setColor(MARKER_COLOR);
|
||||
g2d.fill(marker);
|
||||
g2d.setColor(TICK_COLOR);
|
||||
g2d.drawLine(width - 2 * margin, height / 2 - 2, width - 2 * margin, height / 2 + 2);
|
||||
g2d.setColor(BORDER_COLOR);
|
||||
g2d.draw(body);
|
||||
// g2d.setColor(COVER_COLOR.darker());
|
||||
// g2d.drawLine(innerMargin + 2, innerMargin + 2, width - innerMargin -
|
||||
// 2, width - innerMargin
|
||||
// - 2);
|
||||
// g2d.drawLine(innerMargin + 2, width - innerMargin - 2, width -
|
||||
// innerMargin - 2,
|
||||
// innerMargin + 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decorateComponentBody(Graphics2D g2d) {
|
||||
if (polarized) {
|
||||
int totalDiameter = getClosestOdd(getLength().convertToPixels());
|
||||
Area area = new Area(getBodyShape());
|
||||
area
|
||||
.subtract(new Area(new Rectangle2D.Double(0, 0, totalDiameter * 0.8,
|
||||
totalDiameter)));
|
||||
g2d.setColor(markerColor);
|
||||
g2d.fill(area);
|
||||
g2d.setColor(tickColor);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2));
|
||||
g2d.drawLine((int) (totalDiameter * 0.9), totalDiameter / 2
|
||||
- (int) (totalDiameter * 0.05), (int) (totalDiameter * 0.9), totalDiameter / 2
|
||||
+ (int) (totalDiameter * 0.05));
|
||||
}
|
||||
// int coverDiameter = getClosestOdd(totalDiameter * 3 / 4);
|
||||
// g2d.setColor(coverColor);
|
||||
// int position = (totalDiameter - coverDiameter) / 2;
|
||||
// g2d.fillOval(position, position, coverDiameter, coverDiameter);
|
||||
// g2d.setColor(coverColor.darker());
|
||||
// g2d.drawLine(position + coverDiameter / 5, position + coverDiameter /
|
||||
// 5, position + 4
|
||||
// * coverDiameter / 5, position + 4 * coverDiameter / 5);
|
||||
// g2d.drawLine(position + coverDiameter / 5, position + 4 *
|
||||
// coverDiameter / 5, position + 4
|
||||
// * coverDiameter / 5, position + coverDiameter / 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Size getDefaultWidth() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public Size getWidth() {
|
||||
return super.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Size getDefaultLength() {
|
||||
// We'll reuse width property to set the diameter.
|
||||
return DEFAULT_SIZE;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Diameter")
|
||||
@Override
|
||||
public Size getLength() {
|
||||
return super.getLength();
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Marker")
|
||||
public Color getMarkerColor() {
|
||||
return markerColor;
|
||||
}
|
||||
|
||||
public void setMarkerColor(Color coverColor) {
|
||||
this.markerColor = coverColor;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Tick")
|
||||
public Color getTickColor() {
|
||||
return tickColor;
|
||||
}
|
||||
|
||||
public void setTickColor(Color tickColor) {
|
||||
this.tickColor = tickColor;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Polarized")
|
||||
public boolean getPolarized() {
|
||||
return polarized;
|
||||
}
|
||||
|
||||
public void setPolarized(boolean polarized) {
|
||||
this.polarized = polarized;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Shape getBodyShape() {
|
||||
return new Ellipse2D.Double(0f, 0f, getClosestOdd(getLength().convertToPixels()),
|
||||
getClosestOdd(getLength().convertToPixels()));
|
||||
}
|
||||
}
|
||||
@@ -1,278 +0,0 @@
|
||||
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.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 = "Potentiometer (panel mount)", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.SINGLE_CLICK, instanceNamePrefix = "VR", description = "Panel mount potentiometer with solder lugs", zOrder = IDIYComponent.COMPONENT, stretchable = false)
|
||||
public class PotentiometerPanel extends AbstractPotentiometer {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected static Size BODY_DIAMETER = new Size(1d, SizeUnit.in);
|
||||
protected static Size SPACING = new Size(0.3d, SizeUnit.in);
|
||||
protected static Size LUG_DIAMETER = new Size(0.15d, SizeUnit.in);
|
||||
protected static Color BODY_COLOR = Color.gray.brighter();
|
||||
protected static Color BORDER_COLOR = Color.gray;
|
||||
|
||||
protected Size bodyDiameter = BODY_DIAMETER;
|
||||
protected Size spacing = SPACING;
|
||||
protected Size lugDiameter = LUG_DIAMETER;
|
||||
protected Color bodyColor = BODY_COLOR;
|
||||
protected Color borderColor = BORDER_COLOR;
|
||||
// Array of 7 elements: 3 lug connectors, 1 pot body and 3 lugs
|
||||
protected Area[] body = null;
|
||||
|
||||
public PotentiometerPanel() {
|
||||
controlPoints = new Point[] { new Point(0, 0), new Point(0, 0), new Point(0, 0) };
|
||||
updateControlPoints();
|
||||
}
|
||||
|
||||
protected void updateControlPoints() {
|
||||
int spacing = this.spacing.convertToPixels();
|
||||
switch (orientation) {
|
||||
case DEFAULT:
|
||||
controlPoints[1].setLocation(controlPoints[0].x + spacing, controlPoints[0].y);
|
||||
controlPoints[2].setLocation(controlPoints[0].x + 2 * spacing, controlPoints[0].y);
|
||||
break;
|
||||
case _90:
|
||||
controlPoints[1].setLocation(controlPoints[0].x, controlPoints[0].y + spacing);
|
||||
controlPoints[2].setLocation(controlPoints[0].x, controlPoints[0].y + 2 * spacing);
|
||||
break;
|
||||
case _180:
|
||||
controlPoints[1].setLocation(controlPoints[0].x - spacing, controlPoints[0].y);
|
||||
controlPoints[2].setLocation(controlPoints[0].x - 2 * spacing, controlPoints[0].y);
|
||||
break;
|
||||
case _270:
|
||||
controlPoints[1].setLocation(controlPoints[0].x, controlPoints[0].y - spacing);
|
||||
controlPoints[2].setLocation(controlPoints[0].x, controlPoints[0].y - 2 * spacing);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public Area[] getBody() {
|
||||
int spacing = this.spacing.convertToPixels();
|
||||
int diameter = getClosestOdd(bodyDiameter.convertToPixels());
|
||||
if (body == null) {
|
||||
body = new Area[7];
|
||||
|
||||
// Add lugs.
|
||||
int lugDiameter = getClosestOdd(this.lugDiameter.convertToPixels());
|
||||
int holeDiameter = getClosestOdd(this.lugDiameter.convertToPixels() / 2);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Area area = new Area(new Ellipse2D.Double(controlPoints[i].x - lugDiameter / 2,
|
||||
controlPoints[i].y - lugDiameter / 2, lugDiameter, lugDiameter));
|
||||
body[4 + i] = area;
|
||||
}
|
||||
|
||||
switch (orientation) {
|
||||
case DEFAULT:
|
||||
body[3] = new Area(new Ellipse2D.Double(
|
||||
controlPoints[0].x + spacing - diameter / 2, controlPoints[0].y - spacing
|
||||
/ 2 - diameter, diameter, diameter));
|
||||
for (int i = 0; i < 3; i++) {
|
||||
body[i] = new Area(new Rectangle2D.Double(
|
||||
controlPoints[i].x - holeDiameter / 2, controlPoints[i].y
|
||||
- (spacing + diameter) / 2, holeDiameter,
|
||||
(spacing + diameter) / 2));
|
||||
}
|
||||
break;
|
||||
case _90:
|
||||
body[3] = new Area(new Ellipse2D.Double(controlPoints[0].x + spacing / 2,
|
||||
controlPoints[0].y + spacing - diameter / 2, diameter, diameter));
|
||||
for (int i = 0; i < 3; i++) {
|
||||
body[i] = new Area(new Rectangle2D.Double(controlPoints[i].x,
|
||||
controlPoints[i].y - holeDiameter / 2, (spacing + diameter) / 2,
|
||||
holeDiameter));
|
||||
}
|
||||
break;
|
||||
case _180:
|
||||
body[3] = new Area(new Ellipse2D.Double(
|
||||
controlPoints[0].x - spacing - diameter / 2, controlPoints[0].y + spacing
|
||||
/ 2, diameter, diameter));
|
||||
for (int i = 0; i < 3; i++) {
|
||||
body[i] = new Area(new Rectangle2D.Double(
|
||||
controlPoints[i].x - holeDiameter / 2, controlPoints[i].y,
|
||||
holeDiameter, (spacing + diameter) / 2));
|
||||
}
|
||||
break;
|
||||
case _270:
|
||||
body[3] = new Area(new Ellipse2D.Double(
|
||||
controlPoints[0].x - spacing / 2 - diameter, controlPoints[0].y - spacing
|
||||
- diameter / 2, diameter, diameter));
|
||||
for (int i = 0; i < 3; i++) {
|
||||
body[i] = new Area(new Rectangle2D.Double(controlPoints[i].x
|
||||
- (spacing + diameter) / 2, controlPoints[i].y - holeDiameter / 2,
|
||||
(spacing + diameter) / 2, holeDiameter));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 3; j < 7; j++) {
|
||||
body[i].subtract(body[j]);
|
||||
}
|
||||
}
|
||||
// Make holes in the lugs.
|
||||
for (int i = 0; i < 3; i++) {
|
||||
body[4 + i].subtract(new Area(new Ellipse2D.Double(controlPoints[i].x
|
||||
- holeDiameter / 2, controlPoints[i].y - holeDiameter / 2, holeDiameter,
|
||||
holeDiameter)));
|
||||
}
|
||||
}
|
||||
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));
|
||||
for (Area shape : getBody()) {
|
||||
if (shape != 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(shape);
|
||||
g2d.setComposite(oldComposite);
|
||||
g2d.setColor(componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|
||||
: borderColor);
|
||||
g2d.draw(shape);
|
||||
}
|
||||
}
|
||||
// Draw caption.
|
||||
g2d.setFont(LABEL_FONT);
|
||||
g2d
|
||||
.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED
|
||||
: LABEL_COLOR);
|
||||
FontMetrics fontMetrics = g2d.getFontMetrics();
|
||||
Rectangle2D bodyRect = getBody()[3].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 / 2 - textHeight + fontMetrics.getAscent();
|
||||
|
||||
g2d.drawString(getName(), (int) (bodyRect.getX() + x), (int) (bodyRect.getY() + y));
|
||||
|
||||
// Draw value.
|
||||
rect = fontMetrics.getStringBounds(getValue().toString(), g2d);
|
||||
|
||||
textHeight = (int) rect.getHeight();
|
||||
textWidth = (int) rect.getWidth();
|
||||
|
||||
x = (panelWidth - textWidth) / 2;
|
||||
y = panelHeight / 2 + fontMetrics.getAscent();
|
||||
|
||||
g2d.drawString(getValue().toString(), (int) (bodyRect.getX() + x),
|
||||
(int) (bodyRect.getY() + y));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
int margin = 4 * width / 32;
|
||||
int spacing = width / 3 - 1;
|
||||
g2d.setColor(BORDER_COLOR);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2 * width / 32));
|
||||
g2d.drawLine(width / 2 - spacing, height / 2, width / 2 - spacing, height - margin);
|
||||
g2d.drawLine(width / 2 + spacing, height / 2, width / 2 + spacing, height - margin);
|
||||
g2d.drawLine(width / 2, height / 2, width / 2, height - margin);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(4 * width / 32));
|
||||
g2d.drawLine(width / 2 - spacing, height - margin, width / 2 - spacing, height - margin);
|
||||
g2d.drawLine(width / 2 + spacing, height - margin, width / 2 + spacing, height - margin);
|
||||
g2d.drawLine(width / 2, height - margin, width / 2, height - margin);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
g2d.setColor(BODY_COLOR);
|
||||
g2d.fillOval(margin, margin / 2, width - 2 * margin, height - 2 * margin);
|
||||
g2d.setColor(BORDER_COLOR);
|
||||
g2d.drawOval(margin, margin / 2, width - 2 * margin, height - 2 * margin);
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Size getSpacing() {
|
||||
return spacing;
|
||||
}
|
||||
|
||||
public void setSpacing(Size spacing) {
|
||||
this.spacing = spacing;
|
||||
updateControlPoints();
|
||||
body = null;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Diameter")
|
||||
public Size getBodyDiameter() {
|
||||
return bodyDiameter;
|
||||
}
|
||||
|
||||
public void setBodyDiameter(Size bodyDiameter) {
|
||||
this.bodyDiameter = bodyDiameter;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Lug size")
|
||||
public Size getLugDiameter() {
|
||||
return lugDiameter;
|
||||
}
|
||||
|
||||
public void setLugDiameter(Size lugDiameter) {
|
||||
this.lugDiameter = lugDiameter;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package org.diylc.components.passive;
|
||||
|
||||
import org.diylc.core.measures.Resistance;
|
||||
|
||||
public class PotentiometerValue {
|
||||
|
||||
private Resistance resistance;
|
||||
private Taper taper;
|
||||
|
||||
public PotentiometerValue(Resistance resistance, Taper taper) {
|
||||
super();
|
||||
this.resistance = resistance;
|
||||
this.taper = taper;
|
||||
}
|
||||
|
||||
public Resistance getResistance() {
|
||||
return resistance;
|
||||
}
|
||||
|
||||
public Taper getTaper() {
|
||||
return taper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return resistance.toString() + " " + taper.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package org.diylc.components.passive;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
|
||||
import org.diylc.components.AbstractLeadedComponent;
|
||||
import org.diylc.core.CreationMethod;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.measures.Capacitance;
|
||||
import org.diylc.core.measures.CapacitanceUnit;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
|
||||
@ComponentDescriptor(name = "Ceramic Capacitor (radial)", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "C", description = "Standard radial ceramic capacitor", zOrder = IDIYComponent.COMPONENT)
|
||||
public class RadialCeramicDiskCapacitor extends AbstractLeadedComponent<Capacitance> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Size DEFAULT_WIDTH = new Size(1d / 2, SizeUnit.in);
|
||||
public static Size DEFAULT_HEIGHT = new Size(1d / 8, SizeUnit.in);
|
||||
public static Color BODY_COLOR = Color.decode("#F0E68C");
|
||||
public static Color BORDER_COLOR = BODY_COLOR.darker();
|
||||
|
||||
private Capacitance value = new Capacitance(123d, CapacitanceUnit.nF);
|
||||
|
||||
public RadialCeramicDiskCapacitor() {
|
||||
super();
|
||||
this.bodyColor = BODY_COLOR;
|
||||
this.borderColor = BORDER_COLOR;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Capacitance getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Capacitance value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
g2d.rotate(-Math.PI / 4, width / 2, height / 2);
|
||||
g2d.setColor(LEAD_COLOR);
|
||||
g2d.drawLine(0, height / 2, width, height / 2);
|
||||
g2d.setColor(BODY_COLOR);
|
||||
g2d.fillOval(4, height / 2 - 3, width - 8, 6);
|
||||
g2d.setColor(BORDER_COLOR);
|
||||
g2d.drawOval(4, height / 2 - 3, width - 8, 6);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Size getDefaultWidth() {
|
||||
return DEFAULT_HEIGHT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Size getDefaultLength() {
|
||||
return DEFAULT_WIDTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Shape getBodyShape() {
|
||||
return new Ellipse2D.Double(0f, 0f, getLength().convertToPixels(), getClosestOdd(getWidth()
|
||||
.convertToPixels()));
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
package org.diylc.components.passive;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
|
||||
import org.diylc.components.AbstractLeadedComponent;
|
||||
import org.diylc.core.CreationMethod;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.measures.Capacitance;
|
||||
import org.diylc.core.measures.CapacitanceUnit;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
|
||||
@ComponentDescriptor(name = "Film Capacitor (radial)", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "C", description = "Radial film capacitor, similar to Sprague Orange Drop", zOrder = IDIYComponent.COMPONENT)
|
||||
public class RadialFilmCapacitor extends AbstractLeadedComponent<Capacitance> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Size DEFAULT_WIDTH = new Size(1d, SizeUnit.in);
|
||||
public static Size DEFAULT_HEIGHT = new Size(1d / 4, SizeUnit.in);
|
||||
public static Color BODY_COLOR = Color.decode("#FF8000");
|
||||
public static Color BORDER_COLOR = BODY_COLOR.darker();
|
||||
|
||||
private Capacitance value = new Capacitance(123d, CapacitanceUnit.nF);
|
||||
|
||||
public RadialFilmCapacitor() {
|
||||
super();
|
||||
this.bodyColor = BODY_COLOR;
|
||||
this.borderColor = BORDER_COLOR;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Capacitance getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Capacitance value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
g2d.rotate(-Math.PI / 4, width / 2, height / 2);
|
||||
g2d.setColor(LEAD_COLOR);
|
||||
g2d.drawLine(0, height / 2, width, height / 2);
|
||||
g2d.setColor(BODY_COLOR);
|
||||
g2d.fillRoundRect(4, height / 2 - 3, width - 8, 6, 5, 5);
|
||||
g2d.setColor(BORDER_COLOR);
|
||||
g2d.drawRoundRect(4, height / 2 - 3, width - 8, 6, 5, 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Size getDefaultWidth() {
|
||||
return DEFAULT_HEIGHT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Size getDefaultLength() {
|
||||
return DEFAULT_WIDTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Shape getBodyShape() {
|
||||
double radius = getWidth().convertToPixels() * 0.7;
|
||||
return new RoundRectangle2D.Double(0f, 0f, getLength().convertToPixels(),
|
||||
getClosestOdd(getWidth().convertToPixels()), radius, radius);
|
||||
}
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
package org.diylc.components.passive;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.ResistorColorCode;
|
||||
import org.diylc.components.AbstractLeadedComponent;
|
||||
import org.diylc.core.CreationMethod;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.annotations.PositiveMeasureValidator;
|
||||
import org.diylc.core.measures.Resistance;
|
||||
import org.diylc.core.measures.ResistanceUnit;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
|
||||
@ComponentDescriptor(name = "Resistor", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "R", description = "test", zOrder = IDIYComponent.COMPONENT)
|
||||
public class Resistor extends AbstractLeadedComponent<Resistance> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Size DEFAULT_WIDTH = new Size(1d / 2, SizeUnit.in);
|
||||
public static Size DEFAULT_HEIGHT = new Size(1d / 8, SizeUnit.in);
|
||||
public static Color BODY_COLOR = Color.decode("#82CFFD");
|
||||
public static Color BORDER_COLOR = BODY_COLOR.darker();
|
||||
|
||||
private Resistance value = new Resistance(123d, ResistanceUnit.K);
|
||||
private ResistorColorCode colorCode = ResistorColorCode._5_BAND;
|
||||
|
||||
public Resistor() {
|
||||
super();
|
||||
this.bodyColor = BODY_COLOR;
|
||||
this.borderColor = BORDER_COLOR;
|
||||
}
|
||||
|
||||
@EditableProperty(validatorClass = PositiveMeasureValidator.class)
|
||||
public Resistance getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Resistance value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
g2d.rotate(-Math.PI / 4, width / 2, height / 2);
|
||||
g2d.setColor(LEAD_COLOR);
|
||||
g2d.drawLine(0, height / 2, width, height / 2);
|
||||
g2d.setColor(BODY_COLOR);
|
||||
g2d.fillRect(4, height / 2 - 3, width - 8, 6);
|
||||
g2d.setColor(Color.red);
|
||||
g2d.drawLine(7, height / 2 - 3, 7, height / 2 + 3);
|
||||
g2d.setColor(Color.orange);
|
||||
g2d.drawLine(11, height / 2 - 3, 11, height / 2 + 3);
|
||||
g2d.setColor(Color.black);
|
||||
g2d.drawLine(15, height / 2 - 3, 15, height / 2 + 3);
|
||||
g2d.setColor(BORDER_COLOR);
|
||||
g2d.drawRect(4, height / 2 - 3, width - 8, 6);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Size getDefaultWidth() {
|
||||
return DEFAULT_HEIGHT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Size getDefaultLength() {
|
||||
return DEFAULT_WIDTH;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Color code")
|
||||
public ResistorColorCode getColorCode() {
|
||||
return colorCode;
|
||||
}
|
||||
|
||||
public void setColorCode(ResistorColorCode colorCode) {
|
||||
this.colorCode = colorCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Shape getBodyShape() {
|
||||
return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(),
|
||||
getClosestOdd(getWidth().convertToPixels()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decorateComponentBody(Graphics2D g2d) {
|
||||
// int width = getWidth().convertToPixels();
|
||||
if (colorCode == ResistorColorCode.NONE) {
|
||||
return;
|
||||
}
|
||||
int height = getClosestOdd(getWidth().convertToPixels());
|
||||
Color[] bands = value.getColorCode(colorCode);
|
||||
int x = 4;
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2));
|
||||
for (int i = 0; i < bands.length; i++) {
|
||||
g2d.setColor(bands[i]);
|
||||
g2d.drawLine(x, 1, x, height - 1);
|
||||
x += 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package org.diylc.components.passive;
|
||||
|
||||
public enum Taper {
|
||||
|
||||
LIN, LOG, REV_LOG, W, S;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().substring(0, 1).toUpperCase()
|
||||
+ name().substring(1).toLowerCase().replace("_", " ");
|
||||
}
|
||||
}
|
||||
@@ -1,314 +0,0 @@
|
||||
package org.diylc.components.semiconductors;
|
||||
|
||||
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.geom.Area;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.Orientation;
|
||||
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.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;
|
||||
|
||||
@ComponentDescriptor(name = "DIL IC", author = "Branislav Stojkovic", category = "Semiconductors", instanceNamePrefix = "IC", description = "IC with rectangular housing and two parallel rows of pins", stretchable = false, zOrder = IDIYComponent.COMPONENT)
|
||||
public class DIL_IC extends AbstractTransparentComponent<String> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Color BODY_COLOR = Color.gray;
|
||||
public static Color BORDER_COLOR = Color.gray.darker();
|
||||
public static Color PIN_COLOR = Color.decode("#00B2EE");
|
||||
public static Color PIN_BORDER_COLOR = PIN_COLOR.darker();
|
||||
public static Color INDENT_COLOR = Color.gray.darker();
|
||||
public static Color LABEL_COLOR = Color.white;
|
||||
public static int EDGE_RADIUS = 6;
|
||||
public static Size PIN_SIZE = new Size(0.04d, SizeUnit.in);
|
||||
public static Size INDENT_SIZE = new Size(0.07d, SizeUnit.in);
|
||||
|
||||
private String value = "";
|
||||
private Orientation orientation = Orientation.DEFAULT;
|
||||
private PinCount pinCount = PinCount._8;
|
||||
private Size pinSpacing = new Size(0.1d, SizeUnit.in);
|
||||
private Size rowSpacing = new Size(0.3d, SizeUnit.in);
|
||||
private Point[] controlPoints = new Point[] { new Point(0, 0) };
|
||||
// new Point(0, pinSpacing.convertToPixels()),
|
||||
// new Point(0, 2 * pinSpacing.convertToPixels()),
|
||||
// new Point(0, 3 * pinSpacing.convertToPixels()),
|
||||
// new Point(3 * pinSpacing.convertToPixels(), 0),
|
||||
// new Point(3 * pinSpacing.convertToPixels(),
|
||||
// pinSpacing.convertToPixels()),
|
||||
// new Point(3 * pinSpacing.convertToPixels(), 2 *
|
||||
// pinSpacing.convertToPixels()),
|
||||
// new Point(3 * pinSpacing.convertToPixels(), 3 *
|
||||
// pinSpacing.convertToPixels()) };
|
||||
private Area body[];
|
||||
|
||||
public DIL_IC() {
|
||||
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;
|
||||
// Reset body shape;
|
||||
body = null;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Pins")
|
||||
public PinCount getPinCount() {
|
||||
return pinCount;
|
||||
}
|
||||
|
||||
public void setPinCount(PinCount pinCount) {
|
||||
this.pinCount = pinCount;
|
||||
updateControlPoints();
|
||||
// Reset body shape;
|
||||
body = null;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Pin spacing")
|
||||
public Size getPinSpacing() {
|
||||
return pinSpacing;
|
||||
}
|
||||
|
||||
public void setPinSpacing(Size pinSpacing) {
|
||||
this.pinSpacing = pinSpacing;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Row spacing")
|
||||
public Size getRowSpacing() {
|
||||
return rowSpacing;
|
||||
}
|
||||
|
||||
public void setRowSpacing(Size rowSpacing) {
|
||||
this.rowSpacing = rowSpacing;
|
||||
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() {
|
||||
Point firstPoint = controlPoints[0];
|
||||
controlPoints = new Point[pinCount.getValue()];
|
||||
controlPoints[0] = firstPoint;
|
||||
// Update control points.
|
||||
int dx1;
|
||||
int dy1;
|
||||
int dx2;
|
||||
int dy2;
|
||||
for (int i = 0; i < pinCount.getValue() / 2; i++) {
|
||||
switch (orientation) {
|
||||
case DEFAULT:
|
||||
dx1 = 0;
|
||||
dy1 = i * pinSpacing.convertToPixels();
|
||||
dx2 = rowSpacing.convertToPixels();
|
||||
dy2 = i * pinSpacing.convertToPixels();
|
||||
break;
|
||||
case _90:
|
||||
dx1 = -i * pinSpacing.convertToPixels();
|
||||
dy1 = 0;
|
||||
dx2 = -i * pinSpacing.convertToPixels();
|
||||
dy2 = rowSpacing.convertToPixels();
|
||||
break;
|
||||
case _180:
|
||||
dx1 = 0;
|
||||
dy1 = -i * pinSpacing.convertToPixels();
|
||||
dx2 = -rowSpacing.convertToPixels();
|
||||
dy2 = -i * pinSpacing.convertToPixels();
|
||||
break;
|
||||
case _270:
|
||||
dx1 = i * pinSpacing.convertToPixels();
|
||||
dy1 = 0;
|
||||
dx2 = i * pinSpacing.convertToPixels();
|
||||
dy2 = -rowSpacing.convertToPixels();
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unexpected orientation: " + orientation);
|
||||
}
|
||||
controlPoints[i] = new Point(firstPoint.x + dx1, firstPoint.y + dy1);
|
||||
controlPoints[i + pinCount.getValue() / 2] = new Point(firstPoint.x + dx2, firstPoint.y
|
||||
+ dy2);
|
||||
}
|
||||
}
|
||||
|
||||
public Area[] getBody() {
|
||||
if (body == null) {
|
||||
body = new Area[2];
|
||||
int x = controlPoints[0].x;
|
||||
int y = controlPoints[0].y;
|
||||
int width;
|
||||
int height;
|
||||
int pinSize = PIN_SIZE.convertToPixels();
|
||||
Area indentation = null;
|
||||
int indentationSize = getClosestOdd(INDENT_SIZE.convertToPixels());
|
||||
switch (orientation) {
|
||||
case DEFAULT:
|
||||
width = rowSpacing.convertToPixels() - pinSize;
|
||||
height = (pinCount.getValue() / 2) * pinSpacing.convertToPixels();
|
||||
x += pinSize / 2;
|
||||
y -= pinSpacing.convertToPixels() / 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();
|
||||
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();
|
||||
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();
|
||||
indentation = new Area(new Ellipse2D.Double(x - indentationSize / 2, y + height / 2
|
||||
- indentationSize / 2, indentationSize, indentationSize));
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unexpected orientation: " + orientation);
|
||||
}
|
||||
body[0] = new Area(new RoundRectangle2D.Double(x, y, width, height, EDGE_RADIUS,
|
||||
EDGE_RADIUS));
|
||||
body[1] = indentation;
|
||||
if (indentation != null) {
|
||||
indentation.intersect(body[0]);
|
||||
}
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||
IDrawingObserver drawingObserver) {
|
||||
int pinSize = PIN_SIZE.convertToPixels() / 2 * 2;
|
||||
Area mainArea = getBody()[0];
|
||||
for (Point point : controlPoints) {
|
||||
g2d.setColor(PIN_COLOR);
|
||||
g2d.fillRect(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
|
||||
g2d.setColor(PIN_BORDER_COLOR);
|
||||
g2d.drawRect(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
|
||||
}
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
if (alpha < MAX_ALPHA) {
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
|
||||
/ MAX_ALPHA));
|
||||
}
|
||||
g2d.setColor(BODY_COLOR);
|
||||
g2d.fill(mainArea);
|
||||
g2d.setComposite(oldComposite);
|
||||
g2d.setColor(componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : BORDER_COLOR);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
g2d.draw(mainArea);
|
||||
if (getBody()[1] != null) {
|
||||
g2d.setColor(INDENT_COLOR);
|
||||
g2d.fill(getBody()[1]);
|
||||
}
|
||||
// Draw label.
|
||||
g2d.setFont(LABEL_FONT);
|
||||
g2d.setColor(LABEL_COLOR);
|
||||
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
|
||||
Rectangle2D rect = fontMetrics.getStringBounds(getName(), 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(getName(), x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
int radius = 6 * width / 32;
|
||||
g2d.setColor(BODY_COLOR);
|
||||
g2d.fillRoundRect(width / 6, 1, 4 * width / 6, height - 4, radius, radius);
|
||||
g2d.setColor(BORDER_COLOR);
|
||||
g2d.drawRoundRect(width / 6, 1, 4 * width / 6, height - 4, radius, radius);
|
||||
int pinSize = 2 * width / 32;
|
||||
g2d.setColor(PIN_COLOR);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
g2d.fillRect(width / 6 - pinSize, (height / 5) * (i + 1) - 1, pinSize, pinSize);
|
||||
g2d.fillRect(5 * width / 6 + 1, (height / 5) * (i + 1) - 1, pinSize, pinSize);
|
||||
}
|
||||
}
|
||||
|
||||
public static enum PinCount {
|
||||
|
||||
_4, _8, _10, _12, _14, _16, _24, _32;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().replace("_", "");
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return Integer.parseInt(toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
package org.diylc.components.semiconductors;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.components.AbstractLeadedComponent;
|
||||
import org.diylc.core.CreationMethod;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
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 = "Diode (plastic)", author = "Branislav Stojkovic", category = "Semiconductors", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "D", description = "Plastic diode, like most rectifier, zener, schottky, etc.", zOrder = IDIYComponent.COMPONENT)
|
||||
public class DiodePlastic extends AbstractLeadedComponent<String> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Size DEFAULT_WIDTH = new Size(1d / 4, SizeUnit.in);
|
||||
public static Size DEFAULT_HEIGHT = new Size(1d / 8, SizeUnit.in);
|
||||
public static Size MARKER_WIDTH = new Size(1.5d, SizeUnit.mm);
|
||||
public static Color BODY_COLOR = Color.darkGray;
|
||||
public static Color MARKER_COLOR = Color.decode("#DDDDDD");
|
||||
public static Color LABEL_COLOR = Color.white;
|
||||
public static Color BORDER_COLOR = BODY_COLOR.darker();
|
||||
|
||||
private String value = "";
|
||||
private Color markerColor = MARKER_COLOR;
|
||||
|
||||
public DiodePlastic() {
|
||||
super();
|
||||
this.labelColor = LABEL_COLOR;
|
||||
this.bodyColor = BODY_COLOR;
|
||||
this.borderColor = BORDER_COLOR;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
g2d.rotate(-Math.PI / 4, width / 2, height / 2);
|
||||
g2d.setColor(LEAD_COLOR);
|
||||
g2d.drawLine(0, height / 2, width, height / 2);
|
||||
g2d.setColor(BODY_COLOR);
|
||||
g2d.fillRect(6, height / 2 - 3, width - 12, 6);
|
||||
g2d.setColor(MARKER_COLOR);
|
||||
int markerWidth = 4 * width / 32;
|
||||
g2d.fillRect(width - 6 - markerWidth, height / 2 - 3, markerWidth, 6);
|
||||
g2d.setColor(BORDER_COLOR);
|
||||
g2d.drawRect(6, height / 2 - 3, width - 12, 6);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Size getDefaultWidth() {
|
||||
return DEFAULT_HEIGHT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Size getDefaultLength() {
|
||||
return DEFAULT_WIDTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Shape getBodyShape() {
|
||||
return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(),
|
||||
getClosestOdd(getWidth().convertToPixels()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decorateComponentBody(Graphics2D g2d) {
|
||||
g2d.setColor(markerColor);
|
||||
int width = getLength().convertToPixels();
|
||||
int markerWidth = MARKER_WIDTH.convertToPixels();
|
||||
g2d.fillRect(width - markerWidth, 0, markerWidth, getClosestOdd(getWidth()
|
||||
.convertToPixels()));
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Marker")
|
||||
public Color getMarkerColor() {
|
||||
return markerColor;
|
||||
}
|
||||
|
||||
public void setMarkerColor(Color markerColor) {
|
||||
this.markerColor = markerColor;
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
package org.diylc.components.semiconductors;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.components.AbstractLeadedComponent;
|
||||
import org.diylc.core.CreationMethod;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
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 = "LED", author = "Branislav Stojkovic", category = "Semiconductors", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "D", description = "Light Emitting Diode", zOrder = IDIYComponent.COMPONENT)
|
||||
public class LED extends AbstractLeadedComponent<String> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Size DEFAULT_SIZE = new Size(5d, SizeUnit.mm);
|
||||
public static Color BODY_COLOR = Color.decode("#5DFC0A");
|
||||
public static Color BORDER_COLOR = BODY_COLOR.darker();
|
||||
|
||||
private String value = "";
|
||||
|
||||
public LED() {
|
||||
super();
|
||||
this.bodyColor = BODY_COLOR;
|
||||
this.borderColor = BORDER_COLOR;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
g2d.rotate(-Math.PI / 4, width / 2, height / 2);
|
||||
g2d.setColor(LEAD_COLOR);
|
||||
g2d.drawLine(0, height / 2, width, height / 2);
|
||||
|
||||
int margin = 4 * width / 32;
|
||||
Area area = new Area(new Ellipse2D.Double(margin, margin, width - 2 * margin, width - 2
|
||||
* margin));
|
||||
area.intersect(new Area(new Rectangle2D.Double(margin, margin, width - 5 * margin / 2,
|
||||
width - 2 * margin)));
|
||||
g2d.setColor(BODY_COLOR);
|
||||
g2d.fill(area);
|
||||
g2d.setColor(BORDER_COLOR);
|
||||
g2d.draw(area);
|
||||
g2d
|
||||
.drawOval(margin * 2 - 1, margin * 2 - 1, width - 4 * margin + 2, width - 4
|
||||
* margin + 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Size getDefaultWidth() {
|
||||
return DEFAULT_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Size getDefaultLength() {
|
||||
return DEFAULT_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Shape getBodyShape() {
|
||||
int size = getClosestOdd((int) (getLength().convertToPixels() * 1.2));
|
||||
Area area = new Area(new Ellipse2D.Double(0, 0, size, size));
|
||||
area.intersect(new Area(new Rectangle2D.Double(0, 0, getLength().convertToPixels() * 1.15,
|
||||
size)));
|
||||
return area;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decorateComponentBody(Graphics2D g2d) {
|
||||
int size = getClosestOdd((int) (getLength().convertToPixels() * 1.2));
|
||||
int innerSize = getClosestOdd(getLength().convertToPixels());
|
||||
int x = (size - innerSize) / 2;
|
||||
Shape s = new Ellipse2D.Double(x, x, innerSize, innerSize);
|
||||
g2d.setColor(getBorderColor());
|
||||
g2d.draw(s);
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Size")
|
||||
@Override
|
||||
public Size getLength() {
|
||||
return super.getLength();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Size getWidth() {
|
||||
return super.getWidth();
|
||||
}
|
||||
}
|
||||
@@ -1,265 +0,0 @@
|
||||
package org.diylc.components.semiconductors;
|
||||
|
||||
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.Rectangle2D;
|
||||
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.Orientation;
|
||||
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.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;
|
||||
|
||||
@ComponentDescriptor(name = "Transistor (TO-220 package)", author = "Branislav Stojkovic", category = "Semiconductors", instanceNamePrefix = "Q", description = "Transistors with metal tab for heat sink mounting", stretchable = false, zOrder = IDIYComponent.COMPONENT)
|
||||
public class TransistorTO220 extends AbstractTransparentComponent<String> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Color BODY_COLOR = Color.gray;
|
||||
public static Color BORDER_COLOR = Color.gray.darker();
|
||||
public static Color PIN_COLOR = Color.decode("#00B2EE");
|
||||
public static Color PIN_BORDER_COLOR = PIN_COLOR.darker();
|
||||
public static Color TAB_COLOR = Color.decode("#C3E4ED");
|
||||
public static Color TAB_BORDER_COLOR = TAB_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_HEIGHT = new Size(4.5d, SizeUnit.mm);
|
||||
public static Size TAB_THICKNESS = new Size(0.05d, SizeUnit.in);
|
||||
|
||||
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) };
|
||||
private Shape[] body;
|
||||
private Color bodyColor = BODY_COLOR;
|
||||
private Color borderColor = BORDER_COLOR;
|
||||
private Color tabColor = TAB_COLOR;
|
||||
private Color tabBorderColor = TAB_BORDER_COLOR;
|
||||
|
||||
public TransistorTO220() {
|
||||
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 = PIN_SPACING.convertToPixels();
|
||||
// Update control points.
|
||||
int x = controlPoints[0].x;
|
||||
int y = controlPoints[0].y;
|
||||
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 = PIN_SPACING.convertToPixels();
|
||||
int bodyWidth = getClosestOdd(BODY_WIDTH.convertToPixels());
|
||||
int bodyHeight = getClosestOdd(BODY_HEIGHT.convertToPixels());
|
||||
int tabThickness = TAB_THICKNESS.convertToPixels();
|
||||
|
||||
switch (orientation) {
|
||||
case DEFAULT:
|
||||
body[0] = new Rectangle2D.Double(x - bodyHeight / 2,
|
||||
y + pinSpacing - bodyWidth / 2, bodyHeight, bodyWidth);
|
||||
body[1] = new Rectangle2D.Double(x + bodyHeight / 2 - tabThickness, y + pinSpacing
|
||||
- bodyWidth / 2, tabThickness, bodyWidth);
|
||||
break;
|
||||
case _90:
|
||||
body[0] = new Rectangle2D.Double(x - pinSpacing - bodyWidth / 2,
|
||||
y - bodyHeight / 2, bodyWidth, bodyHeight);
|
||||
body[1] = new Rectangle2D.Double(x - pinSpacing - bodyWidth / 2, y + bodyHeight / 2
|
||||
- tabThickness, bodyWidth, tabThickness);
|
||||
break;
|
||||
case _180:
|
||||
body[0] = new Rectangle2D.Double(x - bodyHeight / 2,
|
||||
y - pinSpacing - bodyWidth / 2, bodyHeight, bodyWidth);
|
||||
body[1] = new Rectangle2D.Double(x - bodyHeight / 2,
|
||||
y - pinSpacing - bodyWidth / 2, tabThickness, bodyWidth);
|
||||
break;
|
||||
case _270:
|
||||
body[0] = new Rectangle2D.Double(x + pinSpacing - bodyWidth / 2,
|
||||
y - bodyHeight / 2, bodyWidth, bodyHeight);
|
||||
body[1] = new Rectangle2D.Double(x + pinSpacing - bodyWidth / 2,
|
||||
y - bodyHeight / 2, bodyWidth, tabThickness);
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unexpected orientation: " + orientation);
|
||||
}
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||
IDrawingObserver drawingObserver) {
|
||||
int pinSize = 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(bodyColor);
|
||||
g2d.fill(mainArea);
|
||||
g2d.setColor(tabColor);
|
||||
g2d.fill(tabArea);
|
||||
g2d.setComposite(oldComposite);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
g2d.setColor(tabBorderColor);
|
||||
g2d.draw(tabArea);
|
||||
g2d.setColor(componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor);
|
||||
g2d.draw(mainArea);
|
||||
|
||||
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(LABEL_COLOR);
|
||||
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
|
||||
Rectangle2D rect = fontMetrics.getStringBounds(getName(), 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(getName(), x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
g2d.setColor(BODY_COLOR);
|
||||
int margin = 2 * width / 32;
|
||||
int thickness = 7 * width / 32;
|
||||
g2d.fillRect(margin, (height - thickness) / 2, width - margin * 2, thickness);
|
||||
g2d.setColor(TAB_COLOR);
|
||||
g2d.fillRect(margin, (height + thickness) / 2 - margin - 1, width - margin * 2, margin);
|
||||
g2d.setColor(BORDER_COLOR);
|
||||
g2d.drawRect(margin, (height - thickness) / 2, width - margin * 2, thickness);
|
||||
}
|
||||
|
||||
@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(name = "Tab")
|
||||
public Color getTabColor() {
|
||||
return tabColor;
|
||||
}
|
||||
|
||||
public void setTabColor(Color tabColor) {
|
||||
this.tabColor = tabColor;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Tab border")
|
||||
public Color getTabBorderColor() {
|
||||
return tabBorderColor;
|
||||
}
|
||||
|
||||
public void setTabBorderColor(Color tabBorderColor) {
|
||||
this.tabBorderColor = tabBorderColor;
|
||||
}
|
||||
}
|
||||
@@ -1,236 +0,0 @@
|
||||
package org.diylc.components.semiconductors;
|
||||
|
||||
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.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.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.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;
|
||||
|
||||
@ComponentDescriptor(name = "Transistor (TO-92 package)", author = "Branislav Stojkovic", category = "Semiconductors", instanceNamePrefix = "Q", description = "Transistor with small plastic or epoxy body", stretchable = false, zOrder = IDIYComponent.COMPONENT)
|
||||
public class TransistorTO92 extends AbstractTransparentComponent<String> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Color BODY_COLOR = Color.gray;
|
||||
public static Color BORDER_COLOR = Color.gray.darker();
|
||||
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_DIAMETER = new Size(0.2d, SizeUnit.in);
|
||||
|
||||
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) };
|
||||
private Area body;
|
||||
private Color bodyColor = BODY_COLOR;
|
||||
private Color borderColor = BORDER_COLOR;
|
||||
|
||||
public TransistorTO92() {
|
||||
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 = PIN_SPACING.convertToPixels();
|
||||
// Update control points.
|
||||
int x = controlPoints[0].x;
|
||||
int y = controlPoints[0].y;
|
||||
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 Area getBody() {
|
||||
if (body == null) {
|
||||
int x = controlPoints[0].x;
|
||||
int y = controlPoints[0].y;
|
||||
int pinSpacing = PIN_SPACING.convertToPixels();
|
||||
int bodyDiameter = getClosestOdd(BODY_DIAMETER.convertToPixels());
|
||||
|
||||
switch (orientation) {
|
||||
case DEFAULT:
|
||||
body = new Area(new Ellipse2D.Double(x - bodyDiameter / 2, y + pinSpacing
|
||||
- bodyDiameter / 2, bodyDiameter, bodyDiameter));
|
||||
body.subtract(new Area(new Rectangle2D.Double(x - bodyDiameter, y + pinSpacing
|
||||
- bodyDiameter / 2, 3 * bodyDiameter / 4, bodyDiameter)));
|
||||
break;
|
||||
case _90:
|
||||
body = new Area(new Ellipse2D.Double(x - pinSpacing - bodyDiameter / 2, y
|
||||
- bodyDiameter / 2, bodyDiameter, bodyDiameter));
|
||||
body.subtract(new Area(new Rectangle2D.Double(x - pinSpacing - bodyDiameter / 2, y
|
||||
- bodyDiameter, bodyDiameter, 3 * bodyDiameter / 4)));
|
||||
break;
|
||||
case _180:
|
||||
body = new Area(new Ellipse2D.Double(x - bodyDiameter / 2, y - pinSpacing
|
||||
- bodyDiameter / 2, bodyDiameter, bodyDiameter));
|
||||
body.subtract(new Area(new Rectangle2D.Double(x + bodyDiameter / 4, y - pinSpacing
|
||||
- bodyDiameter / 2, 3 * bodyDiameter / 4, bodyDiameter)));
|
||||
break;
|
||||
case _270:
|
||||
body = new Area(new Ellipse2D.Double(x + pinSpacing - bodyDiameter / 2, y
|
||||
- bodyDiameter / 2, bodyDiameter, bodyDiameter));
|
||||
body.subtract(new Area(new Rectangle2D.Double(x + pinSpacing - bodyDiameter / 2, y
|
||||
+ bodyDiameter / 4, bodyDiameter, 3 * bodyDiameter / 4)));
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unexpected orientation: " + orientation);
|
||||
}
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||
IDrawingObserver drawingObserver) {
|
||||
int pinSize = PIN_SIZE.convertToPixels() / 2 * 2;
|
||||
Area mainArea = getBody();
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
if (alpha < MAX_ALPHA) {
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
|
||||
/ MAX_ALPHA));
|
||||
}
|
||||
g2d.setColor(bodyColor);
|
||||
g2d.fill(mainArea);
|
||||
g2d.setComposite(oldComposite);
|
||||
g2d.setColor(componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
g2d.draw(mainArea);
|
||||
|
||||
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(LABEL_COLOR);
|
||||
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
|
||||
Rectangle2D rect = fontMetrics.getStringBounds(getName(), 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(getName(), x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
int margin = 3 * width / 32;
|
||||
Area area = new Area(new Ellipse2D.Double(margin / 2, margin, width - 2 * margin, width - 2
|
||||
* margin));
|
||||
// area.subtract(new Area(new Rectangle2D.Double(0, 0, 2 * margin,
|
||||
// height)));
|
||||
area.intersect(new Area(new Rectangle2D.Double(2 * margin, 0, width, height)));
|
||||
g2d.setColor(BODY_COLOR);
|
||||
g2d.fill(area);
|
||||
g2d.setColor(BORDER_COLOR);
|
||||
g2d.draw(area);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
<map>
|
||||
<entry>
|
||||
<string>default.org.diylc.components.passive.TrimmerPotentiometer:Type</string>
|
||||
<org.diylc.components.passive.TrimmerPotentiometer_-TrimmerType>FLAT_LARGE</org.diylc.components.passive.TrimmerPotentiometer_-TrimmerType>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>lastPath</string>
|
||||
<string>C:\Documents and Settings\Branislav Stojkovic\My Documents\Downloads</string>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>abnormalExit</string>
|
||||
<boolean>false</boolean>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>stickyPoints</string>
|
||||
<boolean>true</boolean>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>theme</string>
|
||||
<org.diylc.core.Theme>
|
||||
<name>Light</name>
|
||||
<bgColor>
|
||||
<red>255</red>
|
||||
<green>255</green>
|
||||
<blue>255</blue>
|
||||
<alpha>255</alpha>
|
||||
</bgColor>
|
||||
<gridColor>
|
||||
<red>240</red>
|
||||
<green>240</green>
|
||||
<blue>240</blue>
|
||||
<alpha>240</alpha>
|
||||
</gridColor>
|
||||
<outlineColor>
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
<alpha>255</alpha>
|
||||
</outlineColor>
|
||||
</org.diylc.core.Theme>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>antiAliasing</string>
|
||||
<boolean>true</boolean>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>snapToGrid</string>
|
||||
<boolean>true</boolean>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>hiQualityRender</string>
|
||||
<boolean>false</boolean>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>outline</string>
|
||||
<boolean>true</boolean>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>exportGrid</string>
|
||||
<boolean>true</boolean>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>autoEdit</string>
|
||||
<boolean>false</boolean>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>wheelZoom</string>
|
||||
<boolean>false</boolean>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>default.org.diylc.components.misc.Label:Font Bold</string>
|
||||
<boolean>false</boolean>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>autoCreatePads</string>
|
||||
<boolean>true</boolean>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>continuousCreation</string>
|
||||
<boolean>true</boolean>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>showTemplatesAtStartup</string>
|
||||
<boolean>false</boolean>
|
||||
</entry>
|
||||
</map>
|
||||
Binary file not shown.
Binary file not shown.
@@ -39,6 +39,8 @@ public class DIYLCStarter {
|
||||
} catch (Exception e) {
|
||||
LOG.error("Could not initialize log4j configuration", e);
|
||||
}
|
||||
|
||||
LOG.debug("Java version: " + System.getProperty("java.runtime.version") + " by " + System.getProperty("java.vm.vendor"));
|
||||
|
||||
LOG.info("Starting DIYLC with working directory " + System.getProperty("user.dir"));
|
||||
|
||||
@@ -32,5 +32,9 @@ public enum DrawOption {
|
||||
/**
|
||||
* Anti-aliasing is used when drawing.
|
||||
*/
|
||||
ANTIALIASING;
|
||||
ANTIALIASING,
|
||||
/**
|
||||
* Draw components in outline mode.
|
||||
*/
|
||||
OUTLINE_MODE;
|
||||
}
|
||||
+55
-11
@@ -11,6 +11,8 @@ import java.util.Set;
|
||||
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.Theme;
|
||||
import org.diylc.swing.plugins.edit.ComponentTransferable;
|
||||
|
||||
import com.diyfever.gui.simplemq.IMessageListener;
|
||||
import com.diyfever.gui.simplemq.MessageDispatcher;
|
||||
@@ -30,7 +32,20 @@ import com.diyfever.gui.update.VersionNumber;
|
||||
*/
|
||||
public interface IPlugInPort {
|
||||
|
||||
public static final String CHECK_BOX_MENU_ITEM = "org.diylc.checkBoxMenuItem";
|
||||
public static final String ANTI_ALIASING_KEY = "antiAliasing";
|
||||
public static final String HI_QUALITY_RENDER_KEY = "hiQualityRender";
|
||||
public static final String EXPORT_GRID_KEY = "exportGrid";
|
||||
public static final String STICKY_POINTS_KEY = "stickyPoints";
|
||||
public static final String METRIC_KEY = "metric";
|
||||
public static final String SNAP_TO_GRID_KEY = "snapToGrid";
|
||||
public static final String AUTO_PADS_KEY = "autoCreatePads";
|
||||
public static final String CONTINUOUS_CREATION_KEY = "continuousCreation";
|
||||
public static final String AUTO_EDIT_KEY = "autoEdit";
|
||||
public static final String ABNORMAL_EXIT_KEY = "abnormalExit";
|
||||
public static final String WHEEL_ZOOM_KEY = "wheelZoom";
|
||||
public static final String OUTLINE_KEY = "outline";
|
||||
public static final String THEME_KEY = "theme";
|
||||
public static final String RECENT_COMPONENTS_KEY = "recentComponents";
|
||||
|
||||
/**
|
||||
* Returns size of the canvas that takes project dimensions into account as
|
||||
@@ -86,8 +101,9 @@ public interface IPlugInPort {
|
||||
* Saves the current project into the specified file.
|
||||
*
|
||||
* @param fileName
|
||||
* @param isBackup
|
||||
*/
|
||||
void saveProjectToFile(String fileName);
|
||||
void saveProjectToFile(String fileName, boolean isBackup);
|
||||
|
||||
/**
|
||||
* @return the current file name.
|
||||
@@ -154,8 +170,10 @@ public interface IPlugInPort {
|
||||
* @param ctrlDown
|
||||
* @param shiftDown
|
||||
* @param altDown
|
||||
* @param clickCount
|
||||
*/
|
||||
void mouseClicked(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown);
|
||||
void mouseClicked(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown,
|
||||
int clickCount);
|
||||
|
||||
/**
|
||||
* Notifies the presenter that mouse is moved.
|
||||
@@ -176,6 +194,15 @@ public interface IPlugInPort {
|
||||
*/
|
||||
List<IDIYComponent<?>> getSelectedComponents();
|
||||
|
||||
/**
|
||||
* Updates the selection with the specified list of component. Also, updates
|
||||
* control point map with all components that are stuck to the newly
|
||||
* selected components.
|
||||
*
|
||||
* @param newSelection
|
||||
*/
|
||||
void updateSelection(List<IDIYComponent<?>> newSelection);
|
||||
|
||||
/**
|
||||
* Selects all components in the project.
|
||||
*/
|
||||
@@ -260,14 +287,7 @@ public interface IPlugInPort {
|
||||
*/
|
||||
List<PropertyWrapper> getMutualSelectionProperties();
|
||||
|
||||
/**
|
||||
* Applies specified properties to all the selected components. If some of
|
||||
* the properties are not applicable to some of the selected components an
|
||||
* exception will be thrown.
|
||||
*
|
||||
* @param properties
|
||||
*/
|
||||
void applyPropertiesToSelection(List<PropertyWrapper> properties);
|
||||
void editSelection();
|
||||
|
||||
/**
|
||||
* @return a list of editable properties of the current project.
|
||||
@@ -328,4 +348,28 @@ public interface IPlugInPort {
|
||||
* Brings each of the selected components one step to front.
|
||||
*/
|
||||
void bringSelectionToFront();
|
||||
|
||||
/**
|
||||
* Causes the display to refresh.
|
||||
*/
|
||||
void refresh();
|
||||
|
||||
/**
|
||||
* @return currently selected theme.
|
||||
*/
|
||||
Theme getSelectedTheme();
|
||||
|
||||
/**
|
||||
* Changes the current theme.
|
||||
*
|
||||
* @param theme
|
||||
*/
|
||||
void setSelectedTheme(Theme theme);
|
||||
|
||||
/**
|
||||
* Renumbers all the selected components.
|
||||
*
|
||||
* @param xAxisFirst
|
||||
*/
|
||||
void renumberSelectedComponents(boolean xAxisFirst);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.diylc.common;
|
||||
|
||||
public enum LabelPosition {
|
||||
|
||||
ABOVE, BELOW;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().substring(0, 1) + name().substring(1).toLowerCase();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.diylc.common;
|
||||
|
||||
public enum OrientationHV {
|
||||
|
||||
VERTICAL, HORIZONTAL;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().substring(0, 1) + name().substring(1).toLowerCase();
|
||||
}
|
||||
}
|
||||
+25
-14
@@ -1,7 +1,6 @@
|
||||
package org.diylc.common;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.diylc.core.IPropertyValidator;
|
||||
|
||||
@@ -16,12 +15,14 @@ public class PropertyWrapper implements Cloneable {
|
||||
private String name;
|
||||
private Class<?> type;
|
||||
private Object value;
|
||||
private Method setter;
|
||||
private Method getter;
|
||||
private String setter;
|
||||
private String getter;
|
||||
private boolean defaultable;
|
||||
private IPropertyValidator validator;
|
||||
private boolean unique = true;
|
||||
private boolean changed = false;
|
||||
|
||||
public PropertyWrapper(String name, Class<?> type, Method getter, Method setter,
|
||||
public PropertyWrapper(String name, Class<?> type, String getter, String setter,
|
||||
boolean defaultable, IPropertyValidator validator) {
|
||||
super();
|
||||
this.name = name;
|
||||
@@ -33,8 +34,8 @@ public class PropertyWrapper implements Cloneable {
|
||||
}
|
||||
|
||||
public void readFrom(Object object) throws IllegalArgumentException, IllegalAccessException,
|
||||
InvocationTargetException {
|
||||
this.value = getter.invoke(object);
|
||||
InvocationTargetException, SecurityException, NoSuchMethodException {
|
||||
this.value = object.getClass().getMethod(getter).invoke(object);
|
||||
}
|
||||
|
||||
// public void readUniqueFrom(IDIYComponent component)
|
||||
@@ -47,8 +48,8 @@ public class PropertyWrapper implements Cloneable {
|
||||
// }
|
||||
|
||||
public void writeTo(Object object) throws IllegalArgumentException, IllegalAccessException,
|
||||
InvocationTargetException {
|
||||
setter.invoke(object, value);
|
||||
InvocationTargetException, SecurityException, NoSuchMethodException {
|
||||
object.getClass().getMethod(setter, type).invoke(object, this.value);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -74,6 +75,22 @@ public class PropertyWrapper implements Cloneable {
|
||||
public IPropertyValidator getValidator() {
|
||||
return validator;
|
||||
}
|
||||
|
||||
public boolean isUnique() {
|
||||
return unique;
|
||||
}
|
||||
|
||||
public void setUnique(boolean unique) {
|
||||
this.unique = unique;
|
||||
}
|
||||
|
||||
public boolean isChanged() {
|
||||
return changed;
|
||||
}
|
||||
|
||||
public void setChanged(boolean changed) {
|
||||
this.changed = changed;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public Object clone() throws CloneNotSupportedException {
|
||||
@@ -95,7 +112,6 @@ public class PropertyWrapper implements Cloneable {
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((setter == null) ? 0 : setter.hashCode());
|
||||
result = prime * result + ((type == null) ? 0 : type.hashCode());
|
||||
result = prime * result + ((value == null) ? 0 : value.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -130,11 +146,6 @@ public class PropertyWrapper implements Cloneable {
|
||||
return false;
|
||||
} else if (!type.equals(other.type))
|
||||
return false;
|
||||
if (value == null) {
|
||||
if (other.value != null)
|
||||
return false;
|
||||
} else if (!value.equals(other.value))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
+19
-5
@@ -2,6 +2,7 @@ package org.diylc.components;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Shape;
|
||||
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
@@ -19,11 +20,11 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected String name = "";
|
||||
|
||||
|
||||
public static Color SELECTION_COLOR = Color.red;
|
||||
public static Color LABEL_COLOR = Color.black;
|
||||
public static Color LABEL_COLOR_SELECTED = Color.red;
|
||||
public static Font LABEL_FONT = new Font("Tahoma", Font.PLAIN, 12);
|
||||
public static Font LABEL_FONT = new Font("Tahoma", Font.PLAIN, 14);
|
||||
|
||||
@EditableProperty(defaultable = false)
|
||||
@Override
|
||||
@@ -35,7 +36,7 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canControlPointOverlap(int index) {
|
||||
return false;
|
||||
@@ -53,7 +54,20 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
|
||||
* @param x
|
||||
* @return
|
||||
*/
|
||||
protected int getClosestOdd(int x) {
|
||||
return (x / 2) * 2 + 1;
|
||||
protected int getClosestOdd(double x) {
|
||||
return ((int) x / 2) * 2 + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param clip
|
||||
* @return true if none of the control points lie in the clip rectangle.
|
||||
*/
|
||||
protected boolean checkPointsClipped(Shape clip) {
|
||||
for (int i = 0; i < getControlPointCount(); i++) {
|
||||
if (clip.contains(getControlPoint(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+124
-11
@@ -24,12 +24,15 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
|
||||
public static Color GUIDELINE_COLOR = Color.blue;
|
||||
public static Size DEFAULT_SIZE = new Size(1d, SizeUnit.in);
|
||||
|
||||
protected Point[] controlPoints = new Point[] { new Point(0, 0),
|
||||
new Point(DEFAULT_SIZE.convertToPixels() / 2, 0),
|
||||
new Point(DEFAULT_SIZE.convertToPixels() / 2, DEFAULT_SIZE.convertToPixels()),
|
||||
new Point(DEFAULT_SIZE.convertToPixels(), DEFAULT_SIZE.convertToPixels()) };
|
||||
protected Point[] controlPoints = new Point[] {
|
||||
new Point(0, 0),
|
||||
new Point((int) (DEFAULT_SIZE.convertToPixels() / 2), 0),
|
||||
new Point((int) (DEFAULT_SIZE.convertToPixels() / 2), (int) (DEFAULT_SIZE
|
||||
.convertToPixels())),
|
||||
new Point((int) DEFAULT_SIZE.convertToPixels(), (int) DEFAULT_SIZE.convertToPixels()) };
|
||||
|
||||
protected Color color = getDefaultColor();
|
||||
protected PointCount pointCount = PointCount.FOUR;
|
||||
|
||||
/**
|
||||
* Draws the specified curve onto graphics.
|
||||
@@ -37,6 +40,7 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
|
||||
* @param curve
|
||||
* @param g2d
|
||||
* @param componentState
|
||||
* @param theme
|
||||
*/
|
||||
protected abstract void drawCurve(CubicCurve2D curve, Graphics2D g2d,
|
||||
ComponentState componentState);
|
||||
@@ -59,8 +63,11 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||
IDrawingObserver drawingObserver) {
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
|
||||
Project project, IDrawingObserver drawingObserver) {
|
||||
if (checkPointsClipped(g2d.getClip())) {
|
||||
return;
|
||||
}
|
||||
if (componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING) {
|
||||
// Do not track guidelines.
|
||||
drawingObserver.stopTracking();
|
||||
@@ -93,35 +100,133 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
|
||||
g2d.setComposite(oldComposite);
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Point Count")
|
||||
public PointCount getPointCount() {
|
||||
if (pointCount == null) {
|
||||
pointCount = PointCount.FOUR;
|
||||
}
|
||||
return pointCount;
|
||||
}
|
||||
|
||||
public void setPointCount(PointCount pointCount) {
|
||||
this.pointCount = pointCount;
|
||||
// Reset control points.
|
||||
for (int i = 0; i < getControlPointCount(); i++) {
|
||||
setControlPoint(getControlPoint(i), i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getControlPointCount() {
|
||||
return controlPoints.length;
|
||||
switch (getPointCount()) {
|
||||
case TWO:
|
||||
return 2;
|
||||
case THREE:
|
||||
return 3;
|
||||
case FOUR:
|
||||
return 4;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControlPointSticky(int index) {
|
||||
return index == 0 || index == 3;
|
||||
return index == 0 || index == getControlPointCount() - 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.WHEN_SELECTED;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canControlPointOverlap(int index) {
|
||||
// Only shape control points may overlap.
|
||||
return index == 1 || index == 2;
|
||||
switch (getPointCount()) {
|
||||
case TWO:
|
||||
return false;
|
||||
case THREE:
|
||||
return index == 1;
|
||||
case FOUR:
|
||||
return index == 1 || index == 2;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
if (index == 0) {
|
||||
return controlPoints[0];
|
||||
}
|
||||
switch (getPointCount()) {
|
||||
case TWO:
|
||||
switch (index) {
|
||||
case 1:
|
||||
return controlPoints[3];
|
||||
}
|
||||
case THREE:
|
||||
switch (index) {
|
||||
case 1:
|
||||
return controlPoints[1];
|
||||
case 2:
|
||||
return controlPoints[3];
|
||||
}
|
||||
case FOUR:
|
||||
switch (index) {
|
||||
case 1:
|
||||
return controlPoints[1];
|
||||
case 2:
|
||||
return controlPoints[2];
|
||||
case 3:
|
||||
return controlPoints[3];
|
||||
}
|
||||
}
|
||||
return controlPoints[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
controlPoints[index].setLocation(point);
|
||||
if (index == 0) {
|
||||
controlPoints[0].setLocation(point);
|
||||
} else {
|
||||
switch (getPointCount()) {
|
||||
case TWO:
|
||||
switch (index) {
|
||||
case 1:
|
||||
Point center = new Point((point.x + controlPoints[0].x) / 2,
|
||||
(point.y + controlPoints[0].y) / 2);
|
||||
controlPoints[1].setLocation(center);
|
||||
controlPoints[2].setLocation(center);
|
||||
controlPoints[3].setLocation(point);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case THREE:
|
||||
switch (index) {
|
||||
case 1:
|
||||
controlPoints[1].setLocation(point);
|
||||
controlPoints[2].setLocation(point);
|
||||
break;
|
||||
case 2:
|
||||
controlPoints[3].setLocation(point);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case FOUR:
|
||||
switch (index) {
|
||||
case 1:
|
||||
controlPoints[1].setLocation(point);
|
||||
break;
|
||||
case 2:
|
||||
controlPoints[2].setLocation(point);
|
||||
break;
|
||||
case 3:
|
||||
controlPoints[3].setLocation(point);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
@@ -133,4 +238,12 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
enum PointCount {
|
||||
TWO, THREE, FOUR;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().substring(0, 1) + name().substring(1).toLowerCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,336 @@
|
||||
package org.diylc.components;
|
||||
|
||||
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.AffineTransform;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.common.Display;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.core.ComponentState;
|
||||
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.EditableProperty;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
import com.diyfever.gui.miscutils.ConfigurationManager;
|
||||
|
||||
/**
|
||||
* Base class for all leaded components such as resistors or capacitors. Has two
|
||||
* control points and draws leads between them. Also, it positions and draws the
|
||||
* shape of the component as specified by a child class.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComponent<T> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Color LEAD_COLOR = Color.decode("#236B8E");
|
||||
public static Size LEAD_THICKNESS = new Size(0.6d, SizeUnit.mm);
|
||||
public static Size DEFAULT_SIZE = new Size(1d, SizeUnit.in);
|
||||
|
||||
protected Size length;
|
||||
protected Size width;
|
||||
protected Point[] points = new Point[] {
|
||||
new Point((int) (-DEFAULT_SIZE.convertToPixels() / 2), 0),
|
||||
new Point((int) (DEFAULT_SIZE.convertToPixels() / 2), 0) };
|
||||
protected Color bodyColor = Color.white;
|
||||
protected Color borderColor = Color.black;
|
||||
protected Color labelColor = LABEL_COLOR;
|
||||
protected Display display = Display.VALUE;
|
||||
|
||||
protected AbstractLeadedComponent() {
|
||||
super();
|
||||
try {
|
||||
this.length = getDefaultLength().clone();
|
||||
this.width = getDefaultWidth().clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
// This should never happen because Size supports cloning.
|
||||
} catch (NullPointerException e) {
|
||||
// This will happen if components do not have any shape.
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
|
||||
Project project, IDrawingObserver drawingObserver) {
|
||||
double distance = points[0].distance(points[1]);
|
||||
Shape shape = getBodyShape();
|
||||
// If there's no body, just draw the line connecting the ending points.
|
||||
if (shape == null) {
|
||||
drawLead(g2d, componentState);
|
||||
} else if (supportsStandingMode()
|
||||
&& length.convertToPixels() > points[0].distance(points[1])) {
|
||||
// When ending points are too close draw the component in standing
|
||||
// mode.
|
||||
int width = getClosestOdd(this.width.convertToPixels());
|
||||
Shape body = new Ellipse2D.Double(points[0].x - width / 2, points[0].y - width / 2,
|
||||
width, width);
|
||||
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(body);
|
||||
g2d.setComposite(oldComposite);
|
||||
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
|
||||
: borderColor;
|
||||
}
|
||||
|
||||
g2d.setColor(finalBorderColor);
|
||||
g2d.draw(body);
|
||||
if (!outlineMode) {
|
||||
drawLead(g2d, componentState);
|
||||
}
|
||||
} else {
|
||||
// Normal mode with component body in the center and two lead parts.
|
||||
Rectangle shapeRect = shape.getBounds();
|
||||
Double theta = Math.atan2(points[1].y - points[0].y, points[1].x - points[0].x);
|
||||
// Transform graphics to draw the body in the right place and at the
|
||||
// right angle.
|
||||
AffineTransform oldTransform = g2d.getTransform();
|
||||
g2d.translate((points[0].x + points[1].x - shapeRect.width) / 2, (points[0].y
|
||||
+ points[1].y - shapeRect.height) / 2);
|
||||
g2d.rotate(theta, shapeRect.width / 2, shapeRect.height / 2);
|
||||
// Draw body.
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
if (alpha < MAX_ALPHA) {
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
|
||||
/ MAX_ALPHA));
|
||||
}
|
||||
if (bodyColor != null) {
|
||||
if (bodyColor != null) {
|
||||
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : bodyColor);
|
||||
g2d.fill(shape);
|
||||
}
|
||||
}
|
||||
decorateComponentBody(g2d, outlineMode);
|
||||
g2d.setComposite(oldComposite);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
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
|
||||
: borderColor;
|
||||
}
|
||||
g2d.setColor(finalBorderColor);
|
||||
g2d.draw(shape);
|
||||
// Draw label.
|
||||
g2d.setFont(LABEL_FONT);
|
||||
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
|
||||
: labelColor;
|
||||
}
|
||||
g2d.setColor(finalLabelColor);
|
||||
FontMetrics fontMetrics = g2d.getFontMetrics();
|
||||
String label = display == Display.NAME ? getName() : getValue().toString();
|
||||
// Adjust label angle if needed to make sure that it's readable.
|
||||
if ((theta >= Math.PI / 2 && theta <= Math.PI)
|
||||
|| (theta < -Math.PI / 2 && theta > -Math.PI)) {
|
||||
g2d.rotate(Math.PI, shapeRect.width / 2, shapeRect.height / 2);
|
||||
}
|
||||
Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d);
|
||||
g2d.drawString(label, (int) (shapeRect.width - textRect.getWidth()) / 2,
|
||||
calculateLabelYCoordinate(shapeRect, textRect, fontMetrics));
|
||||
|
||||
// Go back to the original transformation to draw leads.
|
||||
if (!outlineMode) {
|
||||
g2d.setTransform(oldTransform);
|
||||
int leadThickness = getClosestOdd(getLeadThickness());
|
||||
double leadLength = (distance - shapeRect.width) / 2 - leadThickness / 2;
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
|
||||
Color leadColor = shouldShadeLeads() ? getLeadColor(componentState).darker()
|
||||
: getLeadColor(componentState);
|
||||
g2d.setColor(leadColor);
|
||||
int endX = (int) (points[0].x + Math.cos(theta) * leadLength);
|
||||
int endY = (int) Math.round(points[0].y + Math.sin(theta) * leadLength);
|
||||
g2d.drawLine(points[0].x, points[0].y, endX, endY);
|
||||
endX = (int) (points[1].x + Math.cos(theta - Math.PI) * leadLength);
|
||||
endY = (int) Math.round(points[1].y + Math.sin(theta - Math.PI) * leadLength);
|
||||
g2d.drawLine(points[1].x, points[1].y, endX, endY);
|
||||
if (shouldShadeLeads()) {
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
|
||||
leadColor = getLeadColor(componentState);
|
||||
g2d.setColor(leadColor);
|
||||
g2d.drawLine(points[0].x, points[0].y, (int) (points[0].x + Math.cos(theta)
|
||||
* leadLength), (int) (points[0].y + Math.sin(theta) * leadLength));
|
||||
g2d.drawLine(points[1].x, points[1].y, (int) (points[1].x + Math.cos(theta
|
||||
- Math.PI)
|
||||
* leadLength), (int) (points[1].y + Math.sin(theta - Math.PI)
|
||||
* leadLength));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void drawLead(Graphics2D g2d, ComponentState componentState) {
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(getLeadThickness()));
|
||||
Color leadColor = shouldShadeLeads() ? getLeadColor(componentState).darker()
|
||||
: getLeadColor(componentState);
|
||||
g2d.setColor(leadColor);
|
||||
g2d.drawLine(points[0].x, points[0].y, points[1].x, points[1].y);
|
||||
if (shouldShadeLeads()) {
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(getLeadThickness() - 2));
|
||||
leadColor = getLeadColor(componentState);
|
||||
g2d.setColor(leadColor);
|
||||
g2d.drawLine(points[0].x, points[0].y, points[1].x, points[1].y);
|
||||
}
|
||||
}
|
||||
|
||||
protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
protected int calculateLabelYCoordinate(Rectangle2D shapeRect, Rectangle2D textRect,
|
||||
FontMetrics fontMetrics) {
|
||||
return (int) (shapeRect.getHeight() - textRect.getHeight()) / 2 + fontMetrics.getAscent();
|
||||
}
|
||||
|
||||
protected boolean shouldShadeLeads() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean supportsStandingMode() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return default component length.
|
||||
*/
|
||||
protected abstract Size getDefaultLength();
|
||||
|
||||
/**
|
||||
* Returns default component width.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract Size getDefaultWidth();
|
||||
|
||||
/**
|
||||
* @return shape that represents component body. Shape should not be
|
||||
* transformed and should be referenced to (0, 0).
|
||||
*/
|
||||
protected abstract Shape getBodyShape();
|
||||
|
||||
/**
|
||||
* @return default lead thickness. Override this method to change it.
|
||||
*/
|
||||
protected int getLeadThickness() {
|
||||
return (int) LEAD_THICKNESS.convertToPixels();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return default lead color. Override this method to change it.
|
||||
*/
|
||||
protected Color getLeadColor(ComponentState componentState) {
|
||||
return componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : LEAD_COLOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getControlPointCount() {
|
||||
return points.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
return (Point) points[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControlPointSticky(int index) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.ALWAYS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
points[index].setLocation(point);
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Color")
|
||||
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(name = "Length", defaultable = true)
|
||||
public Size getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public void setLength(Size length) {
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Width", defaultable = true)
|
||||
public Size getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void setWidth(Size width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Display getDisplay() {
|
||||
return display;
|
||||
}
|
||||
|
||||
public void setDisplay(Display display) {
|
||||
this.display = display;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package org.diylc.components;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.common.LabelPosition;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
|
||||
public abstract class AbstractSchematicLeadedSymbol<T> extends AbstractLeadedComponent<T> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Color COLOR = Color.blue;
|
||||
public static Color LEAD_COLOR = Color.black;
|
||||
|
||||
protected LabelPosition labelPosition = LabelPosition.ABOVE;
|
||||
|
||||
public AbstractSchematicLeadedSymbol() {
|
||||
super();
|
||||
// We don't want to fill the body, so use null.
|
||||
this.bodyColor = null;
|
||||
this.borderColor = COLOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getBodyColor() {
|
||||
return super.getBodyColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldShadeLeads() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLeadThickness() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int calculateLabelYCoordinate(Rectangle2D shapeRect, Rectangle2D textRect,
|
||||
FontMetrics fontMetrics) {
|
||||
if (labelPosition == LabelPosition.ABOVE) {
|
||||
return -1;
|
||||
} else {
|
||||
return (int) (shapeRect.getHeight() + textRect.getHeight() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Label position")
|
||||
public LabelPosition getLabelPosition() {
|
||||
return labelPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
@EditableProperty(name = "Color")
|
||||
public Color getBorderColor() {
|
||||
return super.getBorderColor();
|
||||
}
|
||||
|
||||
public void setLabelPosition(LabelPosition labelPosition) {
|
||||
this.labelPosition = labelPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Color getLeadColor(ComponentState componentState) {
|
||||
return componentState == ComponentState.SELECTED
|
||||
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : LEAD_COLOR;
|
||||
}
|
||||
}
|
||||
@@ -103,10 +103,11 @@ public interface IDIYComponent<T> extends Serializable {
|
||||
*
|
||||
* @param g2d
|
||||
* @param componentState
|
||||
* @param outlineMode
|
||||
* @param project
|
||||
* @param drawingObserver
|
||||
*/
|
||||
void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||
void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
|
||||
IDrawingObserver drawingObserver);
|
||||
|
||||
/**
|
||||
@@ -1,5 +1,10 @@
|
||||
package org.diylc.core;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
|
||||
|
||||
/**
|
||||
* Base interface for the main GUI component.
|
||||
@@ -21,8 +26,13 @@ public interface IView {
|
||||
public static final int NO_OPTION = 1;
|
||||
public static final int CANCEL_OPTION = 2;
|
||||
public static final int OK_OPTION = 0;
|
||||
|
||||
public static final String CHECK_BOX_MENU_ITEM = "org.diylc.checkBoxMenuItem";
|
||||
public static final String RADIO_BUTTON_GROUP_KEY = "org.diylc.radioButtonGroup";
|
||||
|
||||
void showMessage(String message, String title, int messageType);
|
||||
|
||||
int showConfirmDialog(String message, String title, int optionType, int messageType);
|
||||
|
||||
boolean editProperties(List<PropertyWrapper> properties, Set<PropertyWrapper> defaultedProperties);
|
||||
}
|
||||
@@ -11,6 +11,8 @@ import org.diylc.core.annotations.PositiveMeasureValidator;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
|
||||
import com.diyfever.gui.update.VersionNumber;
|
||||
|
||||
/**
|
||||
* Entity class that defines a project. Contains project properties and a
|
||||
* collection of components.This class is serialized to file. Some filed getters
|
||||
@@ -27,6 +29,8 @@ public class Project implements Serializable {
|
||||
public static Size DEFAULT_HEIGHT = new Size(21d, SizeUnit.cm);
|
||||
public static Size DEFAULT_GRID_SPACING = new Size(0.1d, SizeUnit.in);
|
||||
|
||||
private VersionNumber fileVersion;
|
||||
|
||||
private String title;
|
||||
private String author;
|
||||
private String description;
|
||||
@@ -123,6 +127,14 @@ public class Project implements Serializable {
|
||||
public Set<Integer> getLockedLayers() {
|
||||
return lockedLayers;
|
||||
}
|
||||
|
||||
public VersionNumber getFileVersion() {
|
||||
return fileVersion;
|
||||
}
|
||||
|
||||
public void setFileVersion(VersionNumber fileVersion) {
|
||||
this.fileVersion = fileVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
@@ -0,0 +1,86 @@
|
||||
package org.diylc.core;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Theme implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String name;
|
||||
private Color bgColor;
|
||||
private Color gridColor;
|
||||
private Color outlineColor;
|
||||
|
||||
public Theme(String name, Color bgColor, Color gridColor, Color outlineColor) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.bgColor = bgColor;
|
||||
this.gridColor = gridColor;
|
||||
this.outlineColor = outlineColor;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Color getBgColor() {
|
||||
return bgColor;
|
||||
}
|
||||
|
||||
public Color getGridColor() {
|
||||
return gridColor;
|
||||
}
|
||||
|
||||
public Color getOutlineColor() {
|
||||
return outlineColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((bgColor == null) ? 0 : bgColor.hashCode());
|
||||
result = prime * result + ((gridColor == null) ? 0 : gridColor.hashCode());
|
||||
result = prime * result + ((outlineColor == null) ? 0 : outlineColor.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Theme other = (Theme) obj;
|
||||
if (bgColor == null) {
|
||||
if (other.bgColor != null)
|
||||
return false;
|
||||
} else if (!bgColor.equals(other.bgColor))
|
||||
return false;
|
||||
if (gridColor == null) {
|
||||
if (other.gridColor != null)
|
||||
return false;
|
||||
} else if (!gridColor.equals(other.gridColor))
|
||||
return false;
|
||||
if (outlineColor == null) {
|
||||
if (other.outlineColor != null)
|
||||
return false;
|
||||
} else if (!outlineColor.equals(other.outlineColor))
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user