change format to ggl

This commit is contained in:
Branislav Stojkovic
2016-10-23 17:17:46 +02:00
parent 81a0ff1d44
commit 5ec0616a1e
236 changed files with 25772 additions and 27152 deletions
@@ -30,10 +30,9 @@ public class ComponentType {
private boolean autoEdit; private boolean autoEdit;
private boolean rotatable; private boolean rotatable;
public ComponentType(String name, String description, CreationMethod creationMethod, public ComponentType(String name, String description, CreationMethod creationMethod, String category,
String category, String namePrefix, String author, Icon icon, String namePrefix, String author, Icon icon, Class<? extends IDIYComponent<?>> instanceClass, double zOrder,
Class<? extends IDIYComponent<?>> instanceClass, double zOrder, boolean flexibleZOrder, boolean flexibleZOrder, boolean stretchable, BomPolicy bomPolicy, boolean autoEdit, boolean rotatable) {
boolean stretchable, BomPolicy bomPolicy, boolean autoEdit, boolean rotatable) {
super(); super();
this.name = name; this.name = name;
this.description = description; this.description = description;
@@ -12,13 +12,12 @@ import java.awt.Graphics;
public enum DrawOption { public enum DrawOption {
/** /**
* Selection rectangle will be drawn when needed and selected components may * Selection rectangle will be drawn when needed and selected components may be rendered
* be rendered differently. * differently.
*/ */
SELECTION, SELECTION,
/** /**
* Selected zoom level will be applied to scale the {@link Graphics} before * Selected zoom level will be applied to scale the {@link Graphics} before drawing.
* drawing.
*/ */
ZOOM, ZOOM,
/** /**
@@ -6,74 +6,70 @@ import java.awt.geom.Point2D;
import org.diylc.core.Project; import org.diylc.core.Project;
/** /**
* Enumerates all possible events between {@link IPlugInPort} and * Enumerates all possible events between {@link IPlugInPort} and {@link IPlugIn}. Some events
* {@link IPlugIn}. Some events overlap so be careful which ones you subscribe * overlap so be careful which ones you subscribe for and how you process them.
* for and how you process them.
* *
* @author Branislav Stojkovic * @author Branislav Stojkovic
*/ */
public enum EventType { public enum EventType {
/** /**
* Called when zoom level changes. Typically only one parameter of type * Called when zoom level changes. Typically only one parameter of type {@link Double} is passed
* {@link Double} is passed with new zoom level. * with new zoom level.
*/ */
ZOOM_CHANGED, ZOOM_CHANGED,
/** /**
* Called when a new project is loaded. New {@link Project} is the first * Called when a new project is loaded. New {@link Project} is the first parameter. Boolean flag
* parameter. Boolean flag is the second parameter and it's true when new * is the second parameter and it's true when new project is loaded, false when the same project
* project is loaded, false when the same project has been either reloaded * has been either reloaded or loaded with undo/redo operations.
* or loaded with undo/redo operations.
*/ */
PROJECT_LOADED, PROJECT_LOADED,
/** /**
* Called when either current file name or modified flag are changed. The * Called when either current file name or modified flag are changed. The first parameter is the
* first parameter is the current file name, the second one is a boolean * current file name, the second one is a boolean modified flag.
* modified flag.
*/ */
FILE_STATUS_CHANGED, FILE_STATUS_CHANGED,
/** /**
* Called when selection rectangle is changed. Object of type * Called when selection rectangle is changed. Object of type {@link Rectangle} is the only
* {@link Rectangle} is the only parameter and it contains the new selection * parameter and it contains the new selection rectangle.
* rectangle.
*/ */
SELECTION_RECT_CHANGED, SELECTION_RECT_CHANGED,
/** /**
* Called when component selection is changed. New * Called when component selection is changed. New {@link ComponentSelection} is attached as a
* {@link ComponentSelection} is attached as a parameter. * parameter.
*/ */
SELECTION_CHANGED, SELECTION_CHANGED,
/** /**
* Called when selection size changes, together with a {@link Point2D} * Called when selection size changes, together with a {@link Point2D} object containing selection
* object containing selection size (x = width, y = height). Size is * size (x = width, y = height). Size is expressed in the default measure (cm for metric, inches
* expressed in the default measure (cm for metric, inches for imperial). * for imperial).
*/ */
REPAINT, REPAINT,
/** /**
* Called when new component slot has been changed. The only parameter is * Called when new component slot has been changed. The only parameter is {@link ComponentType}
* {@link ComponentType} and may be null. * and may be null.
*/ */
SLOT_CHANGED, SLOT_CHANGED,
/** /**
* Called when the current project has been modified. Two instances of * Called when the current project has been modified. Two instances of {@link Project} are passed
* {@link Project} are passed as parameters, one before and one after the * as parameters, one before and one after the change. The third parameter is a string containing
* change. The third parameter is a string containing change description. * change description.
*/ */
PROJECT_MODIFIED, PROJECT_MODIFIED,
/** /**
* Called when control points under the cursor are changed. A single * Called when control points under the cursor are changed. A single parameter is passed, an
* parameter is passed, an instance of * instance of <code>Map<IDIYComponent<?>, Set<Integer>></code> containing all the components and
* <code>Map<IDIYComponent<?>, Set<Integer>></code> containing all the * indices of their control points that are under the cursor.
* components and indices of their control points that are under the cursor.
*/ */
AVAILABLE_CTRL_POINTS_CHANGED, AVAILABLE_CTRL_POINTS_CHANGED,
/** /**
* Called when mouse cursor is moved. Point object is passed, containing the * Called when mouse cursor is moved. Point object is passed, containing the current cursor
* current cursor location (not taking zoom into account). * location (not taking zoom into account).
*/ */
MOUSE_MOVED, MOUSE_MOVED,
/** /**
* Called when a layer status is changed. The first parameter is a set of indices of locked layers. All layers not included are considered unlocked. * Called when a layer status is changed. The first parameter is a set of indices of locked
* layers. All layers not included are considered unlocked.
*/ */
LAYER_STATE_CHANGED, LAYER_STATE_CHANGED,
/** /**
@@ -17,6 +17,5 @@ public interface IKeyProcessor {
* *
* @return true if the event should be consumed * @return true if the event should be consumed
*/ */
boolean keyPressed(int key, boolean ctrlDown, boolean shiftDown, boolean keyPressed(int key, boolean ctrlDown, boolean shiftDown, boolean altDown);
boolean altDown);
} }
@@ -16,8 +16,7 @@ public interface IMouseProcessor {
* @param altDown * @param altDown
* @param clickCount * @param clickCount
*/ */
void mouseClicked(Point point, int button, boolean ctrlDown, boolean shiftDown, boolean altDown, void mouseClicked(Point point, int button, boolean ctrlDown, boolean shiftDown, boolean altDown, int clickCount);
int clickCount);
/** /**
* Notifies the presenter that mouse is moved. * Notifies the presenter that mouse is moved.
@@ -10,8 +10,8 @@ import org.diylc.appframework.simplemq.IMessageListener;
public interface IPlugIn extends IMessageListener<EventType> { public interface IPlugIn extends IMessageListener<EventType> {
/** /**
* Method that connects the plug-in with {@link IPlugInPort}. Called by the * Method that connects the plug-in with {@link IPlugInPort}. Called by the application when
* application when plug-in is installed. * plug-in is installed.
* *
* @param plugInPort * @param plugInPort
*/ */
@@ -18,9 +18,9 @@ import org.diylc.core.Template;
import org.diylc.core.Theme; import org.diylc.core.Theme;
/** /**
* Interface for communication between plug-ins and the application. Plug-ins * Interface for communication between plug-ins and the application. Plug-ins may acquire
* may acquire information or make changes through this interface. Application * information or make changes through this interface. Application events are dispatched to plug-ins
* events are dispatched to plug-ins through {@link MessageDispatcher} * through {@link MessageDispatcher}
* *
* @author Branislav Stojkovic * @author Branislav Stojkovic
* *
@@ -58,10 +58,9 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
public static final int BUTTON3 = 3; public static final int BUTTON3 = 3;
/** /**
* Returns size of the canvas that takes project dimensions into account as * Returns size of the canvas that takes project dimensions into account as well as zoom level.
* well as zoom level. Each dimension is calculated as the product of the * Each dimension is calculated as the product of the actual size and the number of pixels per
* actual size and the number of pixels per unit. If <code>useZoom</code> is * unit. If <code>useZoom</code> is set to true, the result is scaled by zoom factor.
* set to true, the result is scaled by zoom factor.
* *
* @param useZoom * @param useZoom
* *
@@ -70,8 +69,7 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
Dimension getCanvasDimensions(boolean useZoom); Dimension getCanvasDimensions(boolean useZoom);
/** /**
* Returns an instance of {@link Cursor} that should be used at the * Returns an instance of {@link Cursor} that should be used at the specified location.
* specified location.
* *
* Note: point coordinates are scaled for zoom factor. * Note: point coordinates are scaled for zoom factor.
* *
@@ -126,29 +124,27 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
boolean isProjectModified(); boolean isProjectModified();
/** /**
* Shows a user dialog if there are changes to confirm that it's safe to * Shows a user dialog if there are changes to confirm that it's safe to proceed.
* proceed.
* *
* @return true, if file actions (new, open, close) can be taken * @return true, if file actions (new, open, close) can be taken
*/ */
boolean allowFileAction(); boolean allowFileAction();
/** /**
* Returns all available {@link ComponentType}s classified by category. * Returns all available {@link ComponentType}s classified by category. Result is a {@link Map}
* Result is a {@link Map} between category name to a {@link List} of all * between category name to a {@link List} of all {@link ComponentType}s that share that category
* {@link ComponentType}s that share that category name. * name.
* *
* @return * @return
*/ */
Map<String, List<ComponentType>> getComponentTypes(); Map<String, List<ComponentType>> getComponentTypes();
/** /**
* Draws project on the provided {@link Graphics2D}. If the provided filter * Draws project on the provided {@link Graphics2D}. If the provided filter is not null, it will
* is not null, it will be used to filter the components that are shown. * be used to filter the components that are shown.
* *
* @param g2d * @param g2d
* @param drawOptions * @param drawOptions specific drawing options
* specific drawing options
* @param filter * @param filter
*/ */
void draw(Graphics2D g2d, Set<DrawOption> drawOptions, IComponentFiler filter); void draw(Graphics2D g2d, Set<DrawOption> drawOptions, IComponentFiler filter);
@@ -156,8 +152,7 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
Double[] getAvailableZoomLevels(); Double[] getAvailableZoomLevels();
/** /**
* Returns current zoom level where <code>zoomLevel = 1.0d</code> means * Returns current zoom level where <code>zoomLevel = 1.0d</code> means 100%.
* 100%.
* *
* @return current zoom level * @return current zoom level
*/ */
@@ -166,8 +161,7 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
/** /**
* Changes current zoom level where <code>zoomLevel = 1.0d</code> means 100% * Changes current zoom level where <code>zoomLevel = 1.0d</code> means 100%
* *
* @param zoomLevel * @param zoomLevel new zoom leve
* new zoom leve
*/ */
void setZoomLevel(double zoomLevel); void setZoomLevel(double zoomLevel);
@@ -191,31 +185,25 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
void deleteSelectedComponents(); void deleteSelectedComponents();
/** /**
* Sets default value for the specified property name for currently selected * Sets default value for the specified property name for currently selected component types.
* component types.
* *
* @param propertyName * @param propertyName display name for property
* display name for property * @param value new default value, must not be null
* @param value
* new default value, must not be null
*/ */
void setSelectionDefaultPropertyValue(String propertyName, Object value); void setSelectionDefaultPropertyValue(String propertyName, Object value);
/** /**
* Sets default value for the specified property name for projects. * Sets default value for the specified property name for projects.
* *
* @param propertyName * @param propertyName display name for property
* display name for property * @param value new default value, must not be null
* @param value
* new default value, must not be null
*/ */
void setProjectDefaultPropertyValue(String propertyName, Object value); void setProjectDefaultPropertyValue(String propertyName, Object value);
/** /**
* @return a list of properties that are mutual for all the selected * @return a list of properties that are mutual for all the selected components. Resulting list
* components. Resulting list may be empty if selected components do * may be empty if selected components do not have mutual properties or can be null if the
* not have mutual properties or can be null if the selection is * selection is empty.
* empty.
*/ */
List<PropertyWrapper> getMutualSelectionProperties(); List<PropertyWrapper> getMutualSelectionProperties();
@@ -239,8 +227,8 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
ComponentType getNewComponentTypeSlot(); ComponentType getNewComponentTypeSlot();
/** /**
* Sets the new component slot. Specified component type will be used to * Sets the new component slot. Specified component type will be used to instantiate new
* instantiate new component. * component.
* *
* @param componentType * @param componentType
* @param template * @param template
@@ -265,8 +253,8 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
void ungroupSelectedComponents(); void ungroupSelectedComponents();
/** /**
* Locks or unlocks the specified layer. All components within +- 0.5 range * Locks or unlocks the specified layer. All components within +- 0.5 range will be affected by
* will be affected by the change as well. * the change as well.
* *
* @param layerZOrder * @param layerZOrder
* @param locked * @param locked
@@ -274,8 +262,7 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
void setLayerLocked(int layerZOrder, boolean locked); void setLayerLocked(int layerZOrder, boolean locked);
/** /**
* @return selection size expressed in either inches or centimeters, based * @return selection size expressed in either inches or centimeters, based on the user preference.
* on the user preference.
*/ */
Point2D calculateSelectionDimension(); Point2D calculateSelectionDimension();
@@ -16,17 +16,15 @@ public interface ISelectionProcessor {
List<IDIYComponent<?>> getSelectedComponents(); List<IDIYComponent<?>> getSelectedComponents();
/** /**
* Updates the selection with the specified list of component. Also, updates * Updates the selection with the specified list of component. Also, updates control point map
* control point map with all components that are stuck to the newly * with all components that are stuck to the newly selected components.
* selected components.
* *
* @param newSelection * @param newSelection
*/ */
void updateSelection(List<IDIYComponent<?>> newSelection); void updateSelection(List<IDIYComponent<?>> newSelection);
/** /**
* Finds all components at the specified location, sorted by z-index from * Finds all components at the specified location, sorted by z-index from top to bottom.
* top to bottom.
* *
* @param point * @param point
* @return * @return
@@ -34,8 +32,8 @@ public interface ISelectionProcessor {
List<IDIYComponent<?>> findComponentsAt(Point point); List<IDIYComponent<?>> findComponentsAt(Point point);
/** /**
* Expands the current selection to include surrounding components. Options * Expands the current selection to include surrounding components. Options are controlled with
* are controlled with <code>expansionMode</code> flag. * <code>expansionMode</code> flag.
* *
* @param expansionMode * @param expansionMode
*/ */
@@ -44,16 +42,15 @@ public interface ISelectionProcessor {
/** /**
* Selects all components in the project. * Selects all components in the project.
* *
* @param int layer if > 0, designates which layer to select. If <= 0 we * @param int layer if > 0, designates which layer to select. If <= 0 we should select all
* should select all regardless of layer * regardless of layer
*/ */
void selectAll(int layer); void selectAll(int layer);
/** /**
* Rotates selection for 90 degrees. * Rotates selection for 90 degrees.
* *
* @param direction * @param direction 1 for clockwise, -1 for counter-clockwise
* 1 for clockwise, -1 for counter-clockwise
*/ */
void rotateSelection(int direction); void rotateSelection(int direction);
} }
@@ -25,8 +25,7 @@ public interface ITask<T> {
void failed(Exception e); void failed(Exception e);
/** /**
* Called if background thread is executed correctly, the result is passed * Called if background thread is executed correctly, the result is passed as a parameter.
* as a parameter.
* *
* @param result * @param result
*/ */
@@ -7,8 +7,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* Repository for object that may be reused, such as {@link Stroke} or * Repository for object that may be reused, such as {@link Stroke} or {@link AlphaComposite}.
* {@link AlphaComposite}.
* *
* @author Branislav Stojkovic * @author Branislav Stojkovic
*/ */
@@ -23,8 +22,7 @@ public class ObjectCache {
return instance; return instance;
} }
private ObjectCache() { private ObjectCache() {}
}
private Map<Integer, Stroke> basicStrokeMap = new HashMap<Integer, Stroke>(); private Map<Integer, Stroke> basicStrokeMap = new HashMap<Integer, Stroke>();
@@ -5,8 +5,8 @@ import java.lang.reflect.InvocationTargetException;
import org.diylc.core.IPropertyValidator; import org.diylc.core.IPropertyValidator;
/** /**
* Entity class for editable properties extracted from component objects. * Entity class for editable properties extracted from component objects. Represents a single
* Represents a single editable property together with it's current value. * editable property together with it's current value.
* *
* @author Branislav Stojkovic * @author Branislav Stojkovic
*/ */
@@ -22,8 +22,8 @@ public class PropertyWrapper implements Cloneable {
private boolean unique = true; private boolean unique = true;
private boolean changed = false; private boolean changed = false;
public PropertyWrapper(String name, Class<?> type, String getter, public PropertyWrapper(String name, Class<?> type, String getter, String setter, boolean defaultable,
String setter, boolean defaultable, IPropertyValidator validator) { IPropertyValidator validator) {
super(); super();
this.name = name; this.name = name;
this.type = type; this.type = type;
@@ -33,9 +33,8 @@ public class PropertyWrapper implements Cloneable {
this.validator = validator; this.validator = validator;
} }
public void readFrom(Object object) throws IllegalArgumentException, public void readFrom(Object object) throws IllegalArgumentException, IllegalAccessException,
IllegalAccessException, InvocationTargetException, InvocationTargetException, SecurityException, NoSuchMethodException {
SecurityException, NoSuchMethodException {
this.value = object.getClass().getMethod(getter).invoke(object); this.value = object.getClass().getMethod(getter).invoke(object);
} }
@@ -48,9 +47,8 @@ public class PropertyWrapper implements Cloneable {
// } // }
// } // }
public void writeTo(Object object) throws IllegalArgumentException, public void writeTo(Object object) throws IllegalArgumentException, IllegalAccessException,
IllegalAccessException, InvocationTargetException, InvocationTargetException, SecurityException, NoSuchMethodException {
SecurityException, NoSuchMethodException {
object.getClass().getMethod(setter, type).invoke(object, this.value); object.getClass().getMethod(setter, type).invoke(object, this.value);
} }
@@ -106,8 +104,8 @@ public class PropertyWrapper implements Cloneable {
// } // }
@Override @Override
public Object clone() throws CloneNotSupportedException { public Object clone() throws CloneNotSupportedException {
PropertyWrapper clone = new PropertyWrapper(this.name, this.type, this.getter, PropertyWrapper clone =
this.setter, this.defaultable, this.validator); new PropertyWrapper(this.name, this.type, this.getter, this.setter, this.defaultable, this.validator);
clone.value = this.value; clone.value = this.value;
clone.changed = this.changed; clone.changed = this.changed;
clone.unique = this.unique; clone.unique = this.unique;
@@ -21,12 +21,11 @@ import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
/** /**
* Abstract implementation of {@link IDIYComponent} that contains component name * Abstract implementation of {@link IDIYComponent} that contains component name and toString.
* and toString.
* *
* IMPORTANT: to improve performance, all fields except for <code>Point</code> * IMPORTANT: to improve performance, all fields except for <code>Point</code> and
* and <code>Point</code> arrays should be immutable. Failing to comply with * <code>Point</code> arrays should be immutable. Failing to comply with this can result in annoying
* this can result in annoying and hard to trace bugs. * and hard to trace bugs.
* *
* @author Branislav Stojkovic * @author Branislav Stojkovic
* *
@@ -71,8 +70,7 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
} }
/** /**
* Returns the closest odd number, i.e. x when x is odd, or x + 1 when x is * Returns the closest odd number, i.e. x when x is odd, or x + 1 when x is even.
* even.
* *
* @param x * @param x
* @return * @return
@@ -114,8 +112,8 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
return !clip.intersects(rect); return !clip.intersects(rect);
} }
protected void drawCenteredText(Graphics2D g2d, String text, int x, int y, protected void drawCenteredText(Graphics2D g2d, String text, int x, int y, HorizontalAlignment horizontalAlignment,
HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment) { VerticalAlignment verticalAlignment) {
FontMetrics fontMetrics = g2d.getFontMetrics(); FontMetrics fontMetrics = g2d.getFontMetrics();
Rectangle stringBounds = fontMetrics.getStringBounds(text, g2d).getBounds(); Rectangle stringBounds = fontMetrics.getStringBounds(text, g2d).getBounds();
@@ -157,8 +155,7 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
public IDIYComponent<T> clone() throws CloneNotSupportedException { public IDIYComponent<T> clone() throws CloneNotSupportedException {
try { try {
// Instantiate object of the same type // Instantiate object of the same type
AbstractComponent<T> newInstance = (AbstractComponent<T>) this.getClass() AbstractComponent<T> newInstance = (AbstractComponent<T>) this.getClass().getConstructors()[0].newInstance();
.getConstructors()[0].newInstance();
Class<?> clazz = this.getClass(); Class<?> clazz = this.getClass();
while (AbstractComponent.class.isAssignableFrom(clazz)) { while (AbstractComponent.class.isAssignableFrom(clazz)) {
Field[] fields = clazz.getDeclaredFields(); Field[] fields = clazz.getDeclaredFields();
@@ -167,19 +164,15 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
// Copy over all non-static, non-final fields that are declared // Copy over all non-static, non-final fields that are declared
// in AbstractComponent or one of it's child classes // in AbstractComponent or one of it's child classes
for (Field field : fields) { for (Field field : fields) {
if (!Modifier.isStatic(field.getModifiers()) if (!Modifier.isStatic(field.getModifiers()) && !Modifier.isFinal(field.getModifiers())) {
&& !Modifier.isFinal(field.getModifiers())) {
field.setAccessible(true); field.setAccessible(true);
Object value = field.get(this); Object value = field.get(this);
// Deep copy point arrays. // Deep copy point arrays.
// TODO: something nicer // TODO: something nicer
if (value != null if (value != null && value.getClass().isArray()
&& value.getClass().isArray() && value.getClass().getComponentType().isAssignableFrom(Point.class)) {
&& value.getClass().getComponentType() Object newArray = Array.newInstance(value.getClass().getComponentType(), Array.getLength(value));
.isAssignableFrom(Point.class)) {
Object newArray = Array.newInstance(
value.getClass().getComponentType(), Array.getLength(value));
for (int i = 0; i < Array.getLength(value); i++) { for (int i = 0; i < Array.getLength(value); i++) {
Point p = (Point) Array.get(value, i); Point p = (Point) Array.get(value, i);
Array.set(newArray, i, new Point(p)); Array.set(newArray, i, new Point(p));
@@ -198,8 +191,7 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
} }
return newInstance; return newInstance;
} catch (Exception e) { } catch (Exception e) {
throw new CloneNotSupportedException("Could not clone the component. Reason: " throw new CloneNotSupportedException("Could not clone the component. Reason: " + e.getMessage());
+ e.getMessage());
} }
} }
@@ -218,8 +210,7 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
// in // in
// AbstractComponent or one of it's child classes // AbstractComponent or one of it's child classes
for (Field field : fields) { for (Field field : fields) {
if (!Modifier.isStatic(field.getModifiers()) if (!Modifier.isStatic(field.getModifiers()) && !Modifier.isFinal(field.getModifiers())) {
&& !Modifier.isFinal(field.getModifiers())) {
field.setAccessible(true); field.setAccessible(true);
try { try {
Object value = field.get(this); Object value = field.get(this);
@@ -24,11 +24,9 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
public static Color GUIDELINE_COLOR = Color.blue; public static Color GUIDELINE_COLOR = Color.blue;
public static Size DEFAULT_SIZE = new Size(1d, SizeUnit.in); public static Size DEFAULT_SIZE = new Size(1d, SizeUnit.in);
protected Point[] controlPoints = new Point[] { protected Point[] controlPoints = new Point[] {new Point(0, 0),
new Point(0, 0),
new Point((int) (DEFAULT_SIZE.convertToPixels() / 2), 0), new Point((int) (DEFAULT_SIZE.convertToPixels() / 2), 0),
new Point((int) (DEFAULT_SIZE.convertToPixels() / 2), (int) (DEFAULT_SIZE new Point((int) (DEFAULT_SIZE.convertToPixels() / 2), (int) (DEFAULT_SIZE.convertToPixels())),
.convertToPixels())),
new Point((int) DEFAULT_SIZE.convertToPixels(), (int) DEFAULT_SIZE.convertToPixels())}; new Point((int) DEFAULT_SIZE.convertToPixels(), (int) DEFAULT_SIZE.convertToPixels())};
protected Color color = getDefaultColor(); protected Color color = getDefaultColor();
@@ -42,8 +40,7 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
* @param componentState * @param componentState
* @param theme * @param theme
*/ */
protected abstract void drawCurve(CubicCurve2D curve, Graphics2D g2d, protected abstract void drawCurve(CubicCurve2D curve, Graphics2D g2d, ComponentState componentState);
ComponentState componentState);
/** /**
* @return default color. * @return default color.
@@ -54,8 +51,8 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
public void drawIcon(Graphics2D g2d, int width, int height) { public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.setColor(getDefaultColor().darker()); g2d.setColor(getDefaultColor().darker());
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(3)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(3));
CubicCurve2D curve = new CubicCurve2D.Double(1, height - 1, width / 4, height / 3, CubicCurve2D curve =
3 * width / 4, 2 * height / 3, width - 1, 1); new CubicCurve2D.Double(1, height - 1, width / 4, height / 3, 3 * width / 4, 2 * height / 3, width - 1, 1);
g2d.draw(curve); g2d.draw(curve);
g2d.setColor(getDefaultColor()); g2d.setColor(getDefaultColor());
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
@@ -63,8 +60,8 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
} }
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
Project project, IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) { if (checkPointsClipped(g2d.getClip())) {
return; return;
} }
@@ -73,22 +70,18 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
drawingObserver.stopTracking(); drawingObserver.stopTracking();
g2d.setStroke(Constants.DASHED_STROKE); g2d.setStroke(Constants.DASHED_STROKE);
g2d.setColor(GUIDELINE_COLOR); g2d.setColor(GUIDELINE_COLOR);
g2d.drawLine(controlPoints[0].x, controlPoints[0].y, controlPoints[1].x, g2d.drawLine(controlPoints[0].x, controlPoints[0].y, controlPoints[1].x, controlPoints[1].y);
controlPoints[1].y); g2d.drawLine(controlPoints[1].x, controlPoints[1].y, controlPoints[2].x, controlPoints[2].y);
g2d.drawLine(controlPoints[1].x, controlPoints[1].y, controlPoints[2].x, g2d.drawLine(controlPoints[2].x, controlPoints[2].y, controlPoints[3].x, controlPoints[3].y);
controlPoints[2].y);
g2d.drawLine(controlPoints[2].x, controlPoints[2].y, controlPoints[3].x,
controlPoints[3].y);
drawingObserver.startTracking(); drawingObserver.startTracking();
} }
CubicCurve2D curve = new CubicCurve2D.Double(controlPoints[0].x, controlPoints[0].y, CubicCurve2D curve =
controlPoints[1].x, controlPoints[1].y, controlPoints[2].x, controlPoints[2].y, new CubicCurve2D.Double(controlPoints[0].x, controlPoints[0].y, controlPoints[1].x, controlPoints[1].y,
controlPoints[3].x, controlPoints[3].y); controlPoints[2].x, controlPoints[2].y, controlPoints[3].x, controlPoints[3].y);
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
/ MAX_ALPHA));
} }
// g2d.setColor(color.darker()); // g2d.setColor(color.darker());
// g2d.setStroke(new BasicStroke(thickness)); // g2d.setStroke(new BasicStroke(thickness));
@@ -193,8 +186,7 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
case TWO: case TWO:
switch (index) { switch (index) {
case 1: case 1:
Point center = new Point((point.x + controlPoints[0].x) / 2, Point center = new Point((point.x + controlPoints[0].x) / 2, (point.y + controlPoints[0].y) / 2);
(point.y + controlPoints[0].y) / 2);
controlPoints[1].setLocation(center); controlPoints[1].setLocation(center);
controlPoints[2].setLocation(center); controlPoints[2].setLocation(center);
controlPoints[3].setLocation(point); controlPoints[3].setLocation(point);
@@ -27,9 +27,9 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
/** /**
* Base class for all leaded components such as resistors or capacitors. Has two * Base class for all leaded components such as resistors or capacitors. Has two control points and
* control points and draws leads between them. Also, it positions and draws the * draws leads between them. Also, it positions and draws the shape of the component as specified by
* shape of the component as specified by a child class. * a child class.
* *
* @author Branislav Stojkovic * @author Branislav Stojkovic
*/ */
@@ -77,7 +77,8 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
// When ending points are too close draw the component in standing // When ending points are too close draw the component in standing
// mode. // mode.
int width = getClosestOdd(this.width.convertToPixels()); int width = getClosestOdd(this.width.convertToPixels());
Shape body = new Ellipse2D.Double((getFlipStanding() ? points[1] : points[0]).x - width / 2, Shape body =
new Ellipse2D.Double((getFlipStanding() ? points[1] : points[0]).x - width / 2,
(getFlipStanding() ? points[1] : points[0]).y - width / 2, width, width); (getFlipStanding() ? points[1] : points[0]).y - width / 2, width, width);
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
@@ -88,13 +89,15 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
g2d.setComposite(oldComposite); g2d.setComposite(oldComposite);
Color finalBorderColor; Color finalBorderColor;
if (outlineMode) { if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Theme theme =
Constants.DEFAULT_THEME); (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : theme.getOutlineColor(); componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: theme.getOutlineColor();
} else { } else {
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor; componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: borderColor;
} }
g2d.setColor(finalBorderColor); g2d.setColor(finalBorderColor);
@@ -117,7 +120,8 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
int leadThickness = getClosestOdd(getLeadThickness()); int leadThickness = getClosestOdd(getLeadThickness());
double leadLength = (distance - calculatePinSpacing(shapeRect)) / 2 - leadThickness / 2; double leadLength = (distance - calculatePinSpacing(shapeRect)) / 2 - leadThickness / 2;
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
Color leadColor = shouldShadeLeads() ? getLeadColorForPainting(componentState).darker() Color leadColor =
shouldShadeLeads() ? getLeadColorForPainting(componentState).darker()
: getLeadColorForPainting(componentState); : getLeadColorForPainting(componentState);
g2d.setColor(leadColor); g2d.setColor(leadColor);
int endX = (int) (points[0].x + Math.cos(theta) * leadLength); int endX = (int) (points[0].x + Math.cos(theta) * leadLength);
@@ -168,13 +172,15 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
Color finalBorderColor; Color finalBorderColor;
if (outlineMode) { if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Theme theme =
Constants.DEFAULT_THEME); (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : theme.getOutlineColor(); componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: theme.getOutlineColor();
} else { } else {
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor; componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: borderColor;
} }
g2d.setColor(finalBorderColor); g2d.setColor(finalBorderColor);
g2d.draw(shape); g2d.draw(shape);
@@ -230,13 +236,15 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
} }
Color finalLabelColor; Color finalLabelColor;
if (outlineMode) { if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Theme theme =
Constants.DEFAULT_THEME); (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalLabelColor = componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING finalLabelColor =
? LABEL_COLOR_SELECTED : theme.getOutlineColor(); componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: theme.getOutlineColor();
} else { } else {
finalLabelColor = componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING finalLabelColor =
? LABEL_COLOR_SELECTED : labelColor; componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: labelColor;
} }
g2d.setColor(finalLabelColor); g2d.setColor(finalLabelColor);
FontMetrics fontMetrics = g2d.getFontMetrics(); FontMetrics fontMetrics = g2d.getFontMetrics();
@@ -264,8 +272,8 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
private void drawLead(Graphics2D g2d, ComponentState componentState) { private void drawLead(Graphics2D g2d, ComponentState componentState) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(getLeadThickness())); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(getLeadThickness()));
Color leadColor = shouldShadeLeads() ? getLeadColorForPainting(componentState).darker() Color leadColor =
: getLeadColorForPainting(componentState); shouldShadeLeads() ? getLeadColorForPainting(componentState).darker() : getLeadColorForPainting(componentState);
g2d.setColor(leadColor); g2d.setColor(leadColor);
g2d.drawLine(points[0].x, points[0].y, points[1].x, points[1].y); g2d.drawLine(points[0].x, points[0].y, points[1].x, points[1].y);
if (shouldShadeLeads()) { if (shouldShadeLeads()) {
@@ -309,18 +317,16 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
protected abstract Size getDefaultWidth(); protected abstract Size getDefaultWidth();
/** /**
* @return shape that represents component body. Shape should not be * @return shape that represents component body. Shape should not be transformed and should be
* transformed and should be referenced to (0, 0). * referenced to (0, 0).
*/ */
protected abstract Shape getBodyShape(); protected abstract Shape getBodyShape();
/** /**
* Controls how component shape should be placed relative to start and end * Controls how component shape should be placed relative to start and end point.
* point.
* *
* @return <code>true<code> if shape rect should be used to center the component or <code>false</code> * @return <code>true<code> if shape rect should be used to center the component or <code>false</code>
* to place the component relative to <code>length</code> and * to place the component relative to <code>length</code> and <code>width</code> values.
* <code>width</code> values.
*/ */
protected boolean useShapeRectAsPosition() { protected boolean useShapeRectAsPosition() {
return true; return true;
@@ -441,8 +447,8 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
} }
/** /**
* Override this method with @EditableProperty annotation in child classes * Override this method with @EditableProperty annotation in child classes where standing mode is
* where standing mode is supported * supported
* *
* @return * @return
*/ */
@@ -7,15 +7,14 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
/** /**
* Base class for radial components. The same as {@link AbstractRadialComponent} * Base class for radial components. The same as {@link AbstractRadialComponent} but with added pin
* but with added pin spacing. * spacing.
* *
* @author bancika * @author bancika
* *
* @param <T> * @param <T>
*/ */
public abstract class AbstractRadialComponent<T> extends public abstract class AbstractRadialComponent<T> extends AbstractLeadedComponent<T> {
AbstractLeadedComponent<T> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -41,8 +41,7 @@ public abstract class AbstractSchematicLeadedSymbol<T> extends AbstractLeadedCom
} }
@Override @Override
protected int calculateLabelYCoordinate(Rectangle2D shapeRect, Rectangle2D textRect, protected int calculateLabelYCoordinate(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics) {
FontMetrics fontMetrics) {
if (labelPosition == LabelPosition.ABOVE) { if (labelPosition == LabelPosition.ABOVE) {
return -1; return -1;
} else { } else {
@@ -67,7 +66,7 @@ public abstract class AbstractSchematicLeadedSymbol<T> extends AbstractLeadedCom
@Override @Override
protected Color getLeadColorForPainting(ComponentState componentState) { protected Color getLeadColorForPainting(ComponentState componentState) {
return componentState == ComponentState.SELECTED return componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : getLeadColor(); : getLeadColor();
} }
} }
@@ -8,6 +8,5 @@ package org.diylc.core;
public class AllowAllValidator implements IPropertyValidator { public class AllowAllValidator implements IPropertyValidator {
@Override @Override
public void validate(Object value) throws ValidationException { public void validate(Object value) throws ValidationException {}
}
} }
@@ -2,7 +2,5 @@ package org.diylc.core;
public enum ExpansionMode { public enum ExpansionMode {
ALL, ALL, SAME_TYPE, IMMEDIATE,
SAME_TYPE,
IMMEDIATE,
} }
@@ -8,25 +8,21 @@ import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
/** /**
* Interface for component instance. Implementation classes of this interface * Interface for component instance. Implementation classes of this interface will be instantiated
* will be instantiated by the application when component is added to the * by the application when component is added to the canvas. <br>
* canvas. <br>
* <br> * <br>
* <b>Implementing classes should meet the following: </b> * <b>Implementing classes should meet the following: </b>
* <ul> * <ul>
* <li>Must have an empty constructor.</li> * <li>Must have an empty constructor.</li>
* <li>Class should be annotated with {@link ComponentDescriptor}.</li> * <li>Class should be annotated with {@link ComponentDescriptor}.</li>
* <li>Getters for properties editable by users should be annotated with * <li>Getters for properties editable by users should be annotated with {@link EditableProperty}.</li>
* {@link EditableProperty}.</li> * <li>Component configuration should be stored int <code>public static</code> fields so they can be
* <li>Component configuration should be stored int <code>public static</code> * set through config file.</li>
* fields so they can be set through config file.</li>
* </ul> * </ul>
* *
* @author Branislav Stojkovic * @author Branislav Stojkovic
* *
* @param <T> * @param <T> type of component values, e.g. Resistance for resistors or String for transistors.
* type of component values, e.g. Resistance for resistors or String
* for transistors.
*/ */
public interface IDIYComponent<T> extends Serializable { public interface IDIYComponent<T> extends Serializable {
@@ -61,9 +57,9 @@ public interface IDIYComponent<T> extends Serializable {
void setValue(T value); void setValue(T value);
/** /**
* @return number of control points for this component instance. May vary * @return number of control points for this component instance. May vary between two instances of
* between two instances of the same type, e.g. DIL IC with 8 and 16 * the same type, e.g. DIL IC with 8 and 16 pins will have 8 or 16 pins although they are
* pins will have 8 or 16 pins although they are of the same type. * of the same type.
*/ */
int getControlPointCount(); int getControlPointCount();
@@ -83,16 +79,14 @@ public interface IDIYComponent<T> extends Serializable {
/** /**
* @param index * @param index
* @return true, if the specified control point may stick to control points * @return true, if the specified control point may stick to control points of other components.
* of other components.
*/ */
boolean isControlPointSticky(int index); boolean isControlPointSticky(int index);
/** /**
* @param index * @param index
* @return true, if the specified control point may overlap with other * @return true, if the specified control point may overlap with other control points <b>of the
* control points <b>of the same component</b>. The other control * same component</b>. The other control point must be able to overlap too.
* point must be able to overlap too.
*/ */
boolean canControlPointOverlap(int index); boolean canControlPointOverlap(int index);
@@ -107,13 +101,12 @@ public interface IDIYComponent<T> extends Serializable {
* @param project * @param project
* @param drawingObserver * @param drawingObserver
*/ */
void draw(Graphics2D g2d, ComponentState componentState, void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
boolean outlineMode, Project project,
IDrawingObserver drawingObserver); IDrawingObserver drawingObserver);
/** /**
* Draws icon representation of the component. This should not depend on * Draws icon representation of the component. This should not depend on component state, i.e. it
* component state, i.e. it should be treated as a static method. * should be treated as a static method.
* *
* @param g2d * @param g2d
* @param width * @param width
@@ -1,9 +1,8 @@
package org.diylc.core; package org.diylc.core;
/** /**
* Interface for tracking component drawing process. Components may use it to * Interface for tracking component drawing process. Components may use it to stop or restart
* stop or restart tracking. Anything drawn while tracking is stopped will not * tracking. Anything drawn while tracking is stopped will not be added to the mouse hot-spot area.
* be added to the mouse hot-spot area.
* *
* @author Branislav Stojkovic * @author Branislav Stojkovic
*/ */
@@ -9,8 +9,7 @@ public interface IPropertyValidator {
/** /**
* @param value * @param value
* @throws ValidationException * @throws ValidationException if validation fails. Message will contain the reason.
* if validation fails. Message will contain the reason.
*/ */
void validate(Object value) throws ValidationException; void validate(Object value) throws ValidationException;
} }
@@ -16,9 +16,9 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
/** /**
* Entity class that defines a project. Contains project properties and a * Entity class that defines a project. Contains project properties and a collection of
* collection of components.This class is serialized to file. Some filed getters * components.This class is serialized to file. Some filed getters are tagged with
* are tagged with {@link EditableProperty} to enable for user to edit them. * {@link EditableProperty} to enable for user to edit them.
* *
* @author Branislav Stojkovic * @author Branislav Stojkovic
*/ */
@@ -1,4 +1,3 @@
package org.diylc.core; package org.diylc.core;
public class ValidationException extends Exception { public class ValidationException extends Exception {
@@ -1,7 +1,5 @@
package org.diylc.core.annotations; package org.diylc.core.annotations;
public enum BomPolicy { public enum BomPolicy {
SHOW_ALL_NAMES, SHOW_ALL_NAMES, SHOW_ONLY_TYPE_NAME, NEVER_SHOW,
SHOW_ONLY_TYPE_NAME,
NEVER_SHOW,
} }
@@ -7,8 +7,7 @@ import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
/** /**
* Annotation for {@link IDIYComponent} implementation. Describes component * Annotation for {@link IDIYComponent} implementation. Describes component properties.
* properties.
* *
* @author Branislav Stojkovic * @author Branislav Stojkovic
*/ */
@@ -27,8 +26,8 @@ public @interface ComponentDescriptor {
/** /**
* @return method that should be used to create a component. If * @return method that should be used to create a component. If
* <code>CreationMethod.POINT_BY_POINT</code> is used, user will * <code>CreationMethod.POINT_BY_POINT</code> is used, user will have to select ending
* have to select ending points before the component is created. * points before the component is created.
*/ */
CreationMethod creationMethod() default CreationMethod.SINGLE_CLICK; CreationMethod creationMethod() default CreationMethod.SINGLE_CLICK;
@@ -43,8 +42,8 @@ public @interface ComponentDescriptor {
String author(); String author();
/** /**
* @return prefix that will be used to generate component instance names, * @return prefix that will be used to generate component instance names, e.g. "R" for resistors
* e.g. "R" for resistors or "Q" for transistors. * or "Q" for transistors.
*/ */
String instanceNamePrefix(); String instanceNamePrefix();
@@ -54,15 +53,14 @@ public @interface ComponentDescriptor {
double zOrder(); double zOrder();
/** /**
* @return true if the component may go beyond it's predefined layer. In * @return true if the component may go beyond it's predefined layer. In that case,
* that case, <code>zOrder</code> is used as initial z order of the * <code>zOrder</code> is used as initial z order of the component.
* component.
*/ */
boolean flexibleZOrder() default false; boolean flexibleZOrder() default false;
/** /**
* @return when false, moving one control point will cause all the others to * @return when false, moving one control point will cause all the others to move together with
* move together with it. * it.
*/ */
boolean stretchable() default true; boolean stretchable() default true;
@@ -72,8 +70,7 @@ public @interface ComponentDescriptor {
BomPolicy bomPolicy() default BomPolicy.SHOW_ALL_NAMES; BomPolicy bomPolicy() default BomPolicy.SHOW_ALL_NAMES;
/** /**
* @return when true, component editor dialog should be shown in Auto-Edit * @return when true, component editor dialog should be shown in Auto-Edit mode.
* mode.
*/ */
boolean autoEdit() default true; boolean autoEdit() default true;
@@ -7,9 +7,9 @@ import org.diylc.core.AllowAllValidator;
import org.diylc.core.IPropertyValidator; import org.diylc.core.IPropertyValidator;
/** /**
* Used to annotate editable component property. Editable property XYZ must have * Used to annotate editable component property. Editable property XYZ must have both getter and
* both getter and setter named <code>getXYZ</code> and <code>setXYZ</code> * setter named <code>getXYZ</code> and <code>setXYZ</code> respectively and this annotation must be
* respectively and this annotation must be placed on the getter method. * placed on the getter method.
* *
* @author Branislav Stojkovic * @author Branislav Stojkovic
*/ */
@@ -17,9 +17,8 @@ import org.diylc.core.IPropertyValidator;
public @interface EditableProperty { public @interface EditableProperty {
/** /**
* Returns property name. If left blank property name will be extracted from * Returns property name. If left blank property name will be extracted from the getter name, e.g.
* the getter name, e.g. getter <code>getXYZ</code> will induce property * getter <code>getXYZ</code> will induce property name <code>XYZ</code>. <br>
* name <code>XYZ</code>. <br>
* Default value is blank. * Default value is blank.
* *
* @return * @return
@@ -36,6 +35,7 @@ public @interface EditableProperty {
/** /**
* Class of validator to use to * Class of validator to use to
*
* @return * @return
*/ */
Class<? extends IPropertyValidator> validatorClass() default AllowAllValidator.class; Class<? extends IPropertyValidator> validatorClass() default AllowAllValidator.class;
@@ -8,12 +8,11 @@ public class Resistance extends AbstractMeasure<ResistanceUnit> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final Color[] COLOR_DIGITS = new Color[] { Color.black, Color.decode("#8B4513"), private static final Color[] COLOR_DIGITS = new Color[] {Color.black, Color.decode("#8B4513"), Color.red,
Color.red, Color.orange, Color.yellow, Color.decode("#76EE00"), Color.blue, Color.orange, Color.yellow, Color.decode("#76EE00"), Color.blue, Color.decode("#91219E"), Color.lightGray,
Color.decode("#91219E"), Color.lightGray, Color.white }; Color.white};
private static final Color[] COLOR_MULTIPLIER = new Color[] { Color.lightGray.brighter(), private static final Color[] COLOR_MULTIPLIER = new Color[] {Color.lightGray.brighter(), Color.decode("#FFB90F"),
Color.decode("#FFB90F"), Color.black, Color.decode("#8B4513"), Color.red, Color.orange, Color.black, Color.decode("#8B4513"), Color.red, Color.orange, Color.yellow, Color.decode("#76EE00"), Color.blue};
Color.yellow, Color.decode("#76EE00"), Color.blue };
// public Resistance() { // public Resistance() {
// super(); // super();
@@ -15,23 +15,20 @@ import javax.swing.ImageIcon;
*/ */
public enum IconLoader { public enum IconLoader {
Delete("delete.png"), Add("add.png"), FolderOut("folder_out.png"), Garbage("garbage.png"), DiskBlue( Delete("delete.png"), Add("add.png"), FolderOut("folder_out.png"), Garbage("garbage.png"), DiskBlue("disk_blue.png"), SaveAs(
"disk_blue.png"), SaveAs("save_as.png"), Exit("exit.png"), DocumentPlainYellow( "save_as.png"), Exit("exit.png"), DocumentPlainYellow("document_plain_yellow.png"), PhotoScenery(
"document_plain_yellow.png"), PhotoScenery("photo_scenery.png"), LightBulbOn( "photo_scenery.png"), LightBulbOn("lightbulb_on.png"), LightBulbOff("lightbulb_off.png"), NotebookAdd(
"lightbulb_on.png"), LightBulbOff("lightbulb_off.png"), NotebookAdd("notebook_add.png"), FormGreen( "notebook_add.png"), FormGreen("form_green.png"), Gears("gears.png"), About("about.png"), WindowColors(
"form_green.png"), Gears("gears.png"), About("about.png"), WindowColors( "window_colors.png"), WindowGear("window_gear.png"), NavigateCheck("navigate_check.png"), Undo("undo.png"), Error(
"window_colors.png"), WindowGear("window_gear.png"), NavigateCheck("navigate_check.png"), Undo( "error.png"), Warning("warning.png"), ZoomSmall("zoom_small.png"), MoveSmall("move_small.png"), Print("print.png"), PDF(
"undo.png"), Error("error.png"), Warning("warning.png"), ZoomSmall("zoom_small.png"), MoveSmall( "pdf.png"), Excel("excel.png"), CSV("csv.png"), HTML("html.png"), Image("image.png"), Cut("cut.png"), Copy(
"move_small.png"), Print("print.png"), PDF("pdf.png"), Excel("excel.png"), CSV( "copy.png"), Paste("paste.png"), Selection("selection.png"), BOM("bom.png"), BlackBoard("blackboard.png"), IdCard(
"csv.png"), HTML("html.png"), Image("image.png"), Cut("cut.png"), Copy("copy.png"), Paste( "id_card.png"), IdCardAdd("id_card_add.png"), Chest("chest.png"), Upload("upload.png"), Wrench("wrench.png"), Group(
"paste.png"), Selection("selection.png"), BOM("bom.png"), BlackBoard("blackboard.png"), IdCard( "group.png"), Ungroup("ungroup.png"), TraceMask("trace_mask.png"), Faq("faq.png"), Component("component.png"), Plugin(
"id_card.png"), IdCardAdd("id_card_add.png"), Chest("chest.png"), Upload("upload.png"), Wrench( "plugin.png"), Manual("manual.png"), Donate("donate.png"), Bug("bug.png"), IconLarge("icon_large.png"), IconMedium(
"wrench.png"), Group("group.png"), Ungroup("ungroup.png"), TraceMask("trace_mask.png"), Faq(
"faq.png"), Component("component.png"), Plugin("plugin.png"), Manual("manual.png"), Donate(
"donate.png"), Bug("bug.png"), IconLarge("icon_large.png"), IconMedium(
"icon_medium.png"), IconSmall("icon_small.png"), DocumentEdit("document_edit.png"), EditComponent( "icon_medium.png"), IconSmall("icon_small.png"), DocumentEdit("document_edit.png"), EditComponent(
"edit_component.png"), Size("size.png"), Front("front.png"), Back("back.png"), Pens( "edit_component.png"), Size("size.png"), Front("front.png"), Back("back.png"), Pens("pens.png"), Sort("sort.png"), ElementsSelection(
"pens.png"), Sort("sort.png"), ElementsSelection("elements_selection.png"); "elements_selection.png");
protected String name; protected String name;
@@ -19,9 +19,8 @@ public class ProjectEntity implements Serializable {
super(); super();
} }
public ProjectEntity(int id, String name, String description, String owner, public ProjectEntity(int id, String name, String description, String owner, String category, String updated,
String category, String updated, String thumbnailUrl, String thumbnailUrl, String downloadUrl) {
String downloadUrl) {
super(); super();
this.id = id; this.id = id;
this.name = name; this.name = name;
@@ -114,17 +113,13 @@ public class ProjectEntity implements Serializable {
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result result = prime * result + ((category == null) ? 0 : category.hashCode());
+ ((category == null) ? 0 : category.hashCode()); result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result result = prime * result + ((downloadUrl == null) ? 0 : downloadUrl.hashCode());
+ ((description == null) ? 0 : description.hashCode());
result = prime * result
+ ((downloadUrl == null) ? 0 : downloadUrl.hashCode());
result = prime * result + id; result = prime * result + id;
result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((owner == null) ? 0 : owner.hashCode()); result = prime * result + ((owner == null) ? 0 : owner.hashCode());
result = prime * result result = prime * result + ((thumbnailUrl == null) ? 0 : thumbnailUrl.hashCode());
+ ((thumbnailUrl == null) ? 0 : thumbnailUrl.hashCode());
result = prime * result + ((updated == null) ? 0 : updated.hashCode()); result = prime * result + ((updated == null) ? 0 : updated.hashCode());
return result; return result;
} }
@@ -23,13 +23,10 @@ public interface ServiceAPI {
* @param email * @param email
* @param website * @param website
* @param bio * @param bio
* @return "Success" if the operation is successful or error message if it * @return "Success" if the operation is successful or error message if it failed.
* failed.
*/ */
String createUser(@ParamName("username") String username, String createUser(@ParamName("username") String username, @ParamName("password") String password,
@ParamName("password") String password, @ParamName("email") String email, @ParamName("website") String website, @ParamName("bio") String bio);
@ParamName("email") String email,
@ParamName("website") String website, @ParamName("bio") String bio);
/*** /***
* Updates user details using token to authenticate. * Updates user details using token to authenticate.
@@ -40,14 +37,11 @@ public interface ServiceAPI {
* @param email * @param email
* @param website * @param website
* @param bio * @param bio
* @return "Success" if the operation is successful or error message if it * @return "Success" if the operation is successful or error message if it failed.
* failed.
*/ */
String updateUserDetails(@ParamName("username") String username, String updateUserDetails(@ParamName("username") String username, @ParamName("token") String token,
@ParamName("token") String token, @ParamName("machineId") String machineId, @ParamName("email") String email, @ParamName("website") String website,
@ParamName("machineId") String machineId, @ParamName("bio") String bio);
@ParamName("email") String email,
@ParamName("website") String website, @ParamName("bio") String bio);
/*** /***
* Tries to login with the provided credentials and machineId. * Tries to login with the provided credentials and machineId.
@@ -55,11 +49,9 @@ public interface ServiceAPI {
* @param username * @param username
* @param password * @param password
* @param machineId * @param machineId
* @return login token if the login was successful or string literal "Error" * @return login token if the login was successful or string literal "Error" if it failed.
* if it failed.
*/ */
String login(@ParamName("username") String username, String login(@ParamName("username") String username, @ParamName("password") String password,
@ParamName("password") String password,
@ParamName("machineId") String machineId); @ParamName("machineId") String machineId);
/*** /***
@@ -68,25 +60,21 @@ public interface ServiceAPI {
* @param username * @param username
* @param password * @param password
* @param machineId * @param machineId
* @return string with an error message if it fails, or an instance of * @return string with an error message if it fails, or an instance of {@link UserEntity} if it
* {@link UserEntity} if it succeeds. * succeeds.
*/ */
Object getUserDetails(@ParamName("username") String username, Object getUserDetails(@ParamName("username") String username, @ParamName("token") String token,
@ParamName("token") String token,
@ParamName("machineId") String machineId); @ParamName("machineId") String machineId);
/*** /***
* Tries to authenticate with the token that was previously created by * Tries to authenticate with the token that was previously created by calling login() function.
* calling login() function.
* *
* @param username * @param username
* @param password * @param password
* @param machineId * @param machineId
* @return "Success" if the login is successful or error message if it * @return "Success" if the login is successful or error message if it failed.
* failed.
*/ */
String loginWithToken(@ParamName("username") String username, String loginWithToken(@ParamName("username") String username, @ParamName("token") String token,
@ParamName("token") String token,
@ParamName("machineId") String machineId); @ParamName("machineId") String machineId);
/*** /***
@@ -96,16 +84,13 @@ public interface ServiceAPI {
* @param token * @param token
* @param machineId * @param machineId
* @param password * @param password
* @return "Success" if the login is successful or error message if it * @return "Success" if the login is successful or error message if it failed.
* failed.
*/ */
String updatePassword(@ParamName("username") String username, String updatePassword(@ParamName("username") String username, @ParamName("oldPassword") String oldPassword,
@ParamName("oldPassword") String oldPassword,
@ParamName("newPassword") String newPassword); @ParamName("newPassword") String newPassword);
/*** /***
* Searches for projects that meet the specified search criteria. Supports * Searches for projects that meet the specified search criteria. Supports pagination.
* pagination.
* *
* @param criteria * @param criteria
* @param category * @param category
@@ -113,15 +98,12 @@ public interface ServiceAPI {
* @param page * @param page
* @param itemsPerPage * @param itemsPerPage
* @param sort * @param sort
* @return string with error message if the error occurred or a list of * @return string with error message if the error occurred or a list of {@link ProjectEntity}
* {@link ProjectEntity} objects. * objects.
*/ */
Object search(@ParamName("criteria") String criteria, Object search(@ParamName("criteria") String criteria, @ParamName("category") String category,
@ParamName("category") String category, @ParamName("format") String format, @ParamName("page") Integer page,
@ParamName("format") String format, @ParamName("itemsPerPage") Integer itemsPerPage, @ParamName("sort") String sort);
@ParamName("page") Integer page,
@ParamName("itemsPerPage") Integer itemsPerPage,
@ParamName("sort") String sort);
/** /**
* Uploads a project using token to authenticate. * Uploads a project using token to authenticate.
@@ -136,19 +118,13 @@ public interface ServiceAPI {
* @param keywords * @param keywords
* @param thumbnail * @param thumbnail
* @param project * @param project
* @return "Success" if the upload was successful or error message if it * @return "Success" if the upload was successful or error message if it failed.
* failed.
*/ */
String upload(@ParamName("username") String username, String upload(@ParamName("username") String username, @ParamName("token") String token,
@ParamName("token") String token, @ParamName("machineId") String machineId, @ParamName("projectName") String projectName,
@ParamName("machineId") String machineId, @ParamName("category") String category, @ParamName("description") String description,
@ParamName("projectName") String projectName, @ParamName("diylcVersion") String diylcVersion, @ParamName("keywords") String keywords,
@ParamName("category") String category, @ParamName("thumbnail") File thumbnail, @ParamName("project") File project);
@ParamName("description") String description,
@ParamName("diylcVersion") String diylcVersion,
@ParamName("keywords") String keywords,
@ParamName("thumbnail") File thumbnail,
@ParamName("project") File project);
/** /**
* @return a {@link List} of available categories. * @return a {@link List} of available categories.
@@ -57,8 +57,7 @@ public class UserEntity implements Serializable {
int result = 1; int result = 1;
result = prime * result + ((bio == null) ? 0 : bio.hashCode()); result = prime * result + ((bio == null) ? 0 : bio.hashCode());
result = prime * result + ((email == null) ? 0 : email.hashCode()); result = prime * result + ((email == null) ? 0 : email.hashCode());
result = prime * result result = prime * result + ((username == null) ? 0 : username.hashCode());
+ ((username == null) ? 0 : username.hashCode());
result = prime * result + ((website == null) ? 0 : website.hashCode()); result = prime * result + ((website == null) ? 0 : website.hashCode());
return result; return result;
} }
@@ -36,8 +36,8 @@ public class CloudPresenter {
private boolean loggedIn = false; private boolean loggedIn = false;
public CloudPresenter(CloudListener listener) { public CloudPresenter(CloudListener listener) {
serviceUrl = ConfigurationManager.getInstance().readString( serviceUrl =
ServiceAPI.URL_KEY, "http://www.diy-fever.com/diylc/api/v1"); ConfigurationManager.getInstance().readString(ServiceAPI.URL_KEY, "http://www.diy-fever.com/diylc/api/v1");
ProxyFactory factory = new ProxyFactory(new PhpFlatProxy()); ProxyFactory factory = new ProxyFactory(new PhpFlatProxy());
service = factory.createProxy(ServiceAPI.class, serviceUrl); service = factory.createProxy(ServiceAPI.class, serviceUrl);
if (service == null) if (service == null)
@@ -45,8 +45,7 @@ public class CloudPresenter {
this.listener = listener; this.listener = listener;
} }
public boolean logIn(String username, String password) public boolean logIn(String username, String password) throws CloudException {
throws CloudException {
if (service == null) if (service == null)
return false; return false;
LOG.info("Trying to login to cloud as " + username); LOG.info("Trying to login to cloud as " + username);
@@ -63,8 +62,7 @@ public class CloudPresenter {
return false; return false;
} else { } else {
LOG.info("Login success"); LOG.info("Login success");
ConfigurationManager.getInstance().writeValue(USERNAME_KEY, ConfigurationManager.getInstance().writeValue(USERNAME_KEY, username);
username);
ConfigurationManager.getInstance().writeValue(TOKEN_KEY, res); ConfigurationManager.getInstance().writeValue(TOKEN_KEY, res);
listener.loggedIn(); listener.loggedIn();
this.loggedIn = true; this.loggedIn = true;
@@ -76,10 +74,8 @@ public class CloudPresenter {
if (service == null) if (service == null)
return false; return false;
String username = ConfigurationManager.getInstance().readString( String username = ConfigurationManager.getInstance().readString(USERNAME_KEY, null);
USERNAME_KEY, null); String token = ConfigurationManager.getInstance().readString(TOKEN_KEY, null);
String token = ConfigurationManager.getInstance().readString(TOKEN_KEY,
null);
if (username != null && token != null) { if (username != null && token != null) {
LOG.info("Trying to login to cloud using a token as " + username); LOG.info("Trying to login to cloud using a token as " + username);
@@ -119,16 +115,13 @@ public class CloudPresenter {
try { try {
res = service.getCategories(); res = service.getCategories();
if (res != null && res.equals(ERROR)) if (res != null && res.equals(ERROR))
throw new CloudException( throw new CloudException("Could not fetch categories from the server.");
"Could not fetch categories from the server.");
if (res instanceof List<?>) { if (res instanceof List<?>) {
List<String> cats = (List<String>) res; List<String> cats = (List<String>) res;
cats.add(0, ""); cats.add(0, "");
categories = cats.toArray(new String[0]); categories = cats.toArray(new String[0]);
} else { } else {
throw new CloudException( throw new CloudException("Unexpected server response received for category list: " + res.getClass().getName());
"Unexpected server response received for category list: "
+ res.getClass().getName());
} }
} catch (Exception e) { } catch (Exception e) {
throw new CloudException(e); throw new CloudException(e);
@@ -137,20 +130,17 @@ public class CloudPresenter {
return categories; return categories;
} }
public void upload(String projectName, String category, String description, public void upload(String projectName, String category, String description, String keywords, String diylcVersion,
String keywords, String diylcVersion, File thumbnail, File project) File thumbnail, File project) throws IOException, CloudException {
throws IOException, CloudException { String username = ConfigurationManager.getInstance().readString(USERNAME_KEY, null);
String username = ConfigurationManager.getInstance().readString( String token = ConfigurationManager.getInstance().readString(TOKEN_KEY, null);
USERNAME_KEY, null);
String token = ConfigurationManager.getInstance().readString(TOKEN_KEY,
null);
if (username == null || token == null) if (username == null || token == null)
throw new CloudException("Login failed. Please try to login again."); throw new CloudException("Login failed. Please try to login again.");
try { try {
String res = service.upload(username, token, getMachineId(), String res =
projectName, category, description, diylcVersion, keywords, service.upload(username, token, getMachineId(), projectName, category, description, diylcVersion, keywords,
thumbnail, project); thumbnail, project);
if (!res.equals(SUCCESS)) if (!res.equals(SUCCESS))
throw new CloudException(res); throw new CloudException(res);
@@ -160,11 +150,10 @@ public class CloudPresenter {
} }
public void createUserAccount(String username, String password, public void createUserAccount(String username, String password, String email, String website, String bio)
String email, String website, String bio) throws CloudException { throws CloudException {
try { try {
String res = service.createUser(username, password, email, website, String res = service.createUser(username, password, email, website, bio);
bio);
if (res == null) if (res == null)
throw new CloudException("Could not create user account."); throw new CloudException("Could not create user account.");
if (!SUCCESS.equals(res)) if (!SUCCESS.equals(res))
@@ -175,10 +164,8 @@ public class CloudPresenter {
} }
public UserEntity getUserDetails() throws CloudException { public UserEntity getUserDetails() throws CloudException {
String username = ConfigurationManager.getInstance().readString( String username = ConfigurationManager.getInstance().readString(USERNAME_KEY, null);
USERNAME_KEY, null); String token = ConfigurationManager.getInstance().readString(TOKEN_KEY, null);
String token = ConfigurationManager.getInstance().readString(TOKEN_KEY,
null);
Object res; Object res;
try { try {
@@ -190,15 +177,11 @@ public class CloudPresenter {
throw new CloudException(res.toString()); throw new CloudException(res.toString());
if (res instanceof UserEntity) if (res instanceof UserEntity)
return (UserEntity) res; return (UserEntity) res;
throw new CloudException( throw new CloudException("Unexpected server response received for category list: " + res.getClass().getName());
"Unexpected server response received for category list: "
+ res.getClass().getName());
} }
public void updatePassword(String oldPassword, String newPassword) public void updatePassword(String oldPassword, String newPassword) throws CloudException {
throws CloudException { String username = ConfigurationManager.getInstance().readString(USERNAME_KEY, null);
String username = ConfigurationManager.getInstance().readString(
USERNAME_KEY, null);
String res; String res;
try { try {
@@ -210,17 +193,13 @@ public class CloudPresenter {
throw new CloudException(res); throw new CloudException(res);
} }
public void updateUserDetails(String email, String website, String bio) public void updateUserDetails(String email, String website, String bio) throws CloudException {
throws CloudException { String username = ConfigurationManager.getInstance().readString(USERNAME_KEY, null);
String username = ConfigurationManager.getInstance().readString( String token = ConfigurationManager.getInstance().readString(TOKEN_KEY, null);
USERNAME_KEY, null);
String token = ConfigurationManager.getInstance().readString(TOKEN_KEY,
null);
String res; String res;
try { try {
res = service.updateUserDetails(username, token, getMachineId(), res = service.updateUserDetails(username, token, getMachineId(), email, website, bio);
email, website, bio);
} catch (Exception e) { } catch (Exception e) {
throw new CloudException(e); throw new CloudException(e);
} }
@@ -228,21 +207,17 @@ public class CloudPresenter {
throw new CloudException(res); throw new CloudException(res);
} }
public List<ProjectEntity> search(String criteria, String category, public List<ProjectEntity> search(String criteria, String category, String sortOrder, int pageNumber, int itemsPerPage)
String sortOrder, int pageNumber, int itemsPerPage)
throws CloudException { throws CloudException {
try { try {
Object res = service.search(criteria, category, "json", pageNumber, Object res = service.search(criteria, category, "json", pageNumber, itemsPerPage, sortOrder);
itemsPerPage, sortOrder);
if (res == null) if (res == null)
throw new CloudException("Failed to retreive search results."); throw new CloudException("Failed to retreive search results.");
if (res instanceof String) if (res instanceof String)
throw new CloudException(res.toString()); throw new CloudException(res.toString());
if (res instanceof List<?>) if (res instanceof List<?>)
return (List<ProjectEntity>) res; return (List<ProjectEntity>) res;
throw new CloudException( throw new CloudException("Unexpected server response received for search results: " + res.getClass().getName());
"Unexpected server response received for search results: "
+ res.getClass().getName());
} catch (Exception e) { } catch (Exception e) {
throw new CloudException(e); throw new CloudException(e);
} }
@@ -261,8 +236,7 @@ public class CloudPresenter {
try { try {
InetAddress ip = InetAddress.getLocalHost(); InetAddress ip = InetAddress.getLocalHost();
NetworkInterface network = NetworkInterface NetworkInterface network = NetworkInterface.getByInetAddress(ip);
.getByInetAddress(ip);
byte[] mac = network.getHardwareAddress(); byte[] mac = network.getHardwareAddress();
@@ -73,11 +73,11 @@ public class ComparatorFactory {
@Override @Override
public int compare(IDIYComponent<?> o1, IDIYComponent<?> o2) { public int compare(IDIYComponent<?> o1, IDIYComponent<?> o2) {
ComponentType type1 = ComponentProcessor.getInstance() ComponentType type1 =
.extractComponentTypeFrom( ComponentProcessor.getInstance().extractComponentTypeFrom(
(Class<? extends IDIYComponent<?>>) o1.getClass()); (Class<? extends IDIYComponent<?>>) o1.getClass());
ComponentType type2 = ComponentProcessor.getInstance() ComponentType type2 =
.extractComponentTypeFrom( ComponentProcessor.getInstance().extractComponentTypeFrom(
(Class<? extends IDIYComponent<?>>) o2.getClass()); (Class<? extends IDIYComponent<?>>) o2.getClass());
return new Double(type1.getZOrder()).compareTo(type2.getZOrder()); return new Double(type1.getZOrder()).compareTo(type2.getZOrder());
} }
@@ -102,12 +102,10 @@ public class ComponentProcessor {
// Draw component icon. // Draw component icon.
try { try {
IDIYComponent<?> componentInstance = (IDIYComponent<?>) clazz.newInstance(); IDIYComponent<?> componentInstance = (IDIYComponent<?>) clazz.newInstance();
Image image = new BufferedImage(Presenter.ICON_SIZE, Presenter.ICON_SIZE, Image image =
java.awt.image.BufferedImage.TYPE_INT_ARGB); new BufferedImage(Presenter.ICON_SIZE, Presenter.ICON_SIZE, java.awt.image.BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = (Graphics2D) image.getGraphics(); Graphics2D g2d = (Graphics2D) image.getGraphics();
g2d g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
// g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, // g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
// RenderingHints.VALUE_STROKE_PURE); // RenderingHints.VALUE_STROKE_PURE);
@@ -116,9 +114,9 @@ public class ComponentProcessor {
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
ComponentType componentType = new ComponentType(name, description, creationMethod, ComponentType componentType =
category, namePrefix, author, icon, clazz, zOrder, flexibleZOrder, stretchable, new ComponentType(name, description, creationMethod, category, namePrefix, author, icon, clazz, zOrder,
bomPolicy, autoEdit, rotatable); flexibleZOrder, stretchable, bomPolicy, autoEdit, rotatable);
componentTypeMap.put(clazz.getName(), componentType); componentTypeMap.put(clazz.getName(), componentType);
return componentType; return componentType;
} }
@@ -137,8 +135,7 @@ public class ComponentProcessor {
for (Method method : clazz.getMethods()) { for (Method method : clazz.getMethods()) {
if (method.getName().startsWith("get")) { if (method.getName().startsWith("get")) {
try { try {
if (method.isAnnotationPresent(EditableProperty.class) if (method.isAnnotationPresent(EditableProperty.class) && !method.isAnnotationPresent(Deprecated.class)) {
&& !method.isAnnotationPresent(Deprecated.class)) {
EditableProperty annotation = method.getAnnotation(EditableProperty.class); EditableProperty annotation = method.getAnnotation(EditableProperty.class);
String name; String name;
if (annotation.name().equals("")) { if (annotation.name().equals("")) {
@@ -146,18 +143,15 @@ public class ComponentProcessor {
} else { } else {
name = annotation.name(); name = annotation.name();
} }
IPropertyValidator validator = getPropertyValidator(annotation IPropertyValidator validator = getPropertyValidator(annotation.validatorClass());
.validatorClass()); Method setter = clazz.getMethod("set" + method.getName().substring(3), method.getReturnType());
Method setter = clazz.getMethod("set" + method.getName().substring(3), PropertyWrapper property =
method.getReturnType()); new PropertyWrapper(name, method.getReturnType(), method.getName(), setter.getName(),
PropertyWrapper property = new PropertyWrapper(name,
method.getReturnType(), method.getName(), setter.getName(),
annotation.defaultable(), validator); annotation.defaultable(), validator);
properties.add(property); properties.add(property);
} }
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
LOG.debug("No matching setter found for \"" + method.getName() LOG.debug("No matching setter found for \"" + method.getName() + "\". Skipping...");
+ "\". Skipping...");
} }
} }
} }
@@ -179,14 +173,12 @@ public class ComponentProcessor {
} }
/** /**
* Returns properties that have the same value for all the selected * Returns properties that have the same value for all the selected components.
* components.
* *
* @param selectedComponents * @param selectedComponents
* @return * @return
*/ */
public List<PropertyWrapper> getMutualSelectionProperties( public List<PropertyWrapper> getMutualSelectionProperties(List<IDIYComponent<?>> selectedComponents) throws Exception {
List<IDIYComponent<?>> selectedComponents) throws Exception {
if (selectedComponents.isEmpty()) { if (selectedComponents.isEmpty()) {
return null; return null;
} }
@@ -208,8 +200,7 @@ public class ComponentProcessor {
// their values match. // their values match.
for (PropertyWrapper oldProperty : properties) { for (PropertyWrapper oldProperty : properties) {
if (newProperties.contains(oldProperty)) { if (newProperties.contains(oldProperty)) {
PropertyWrapper newProperty = newProperties.get(newProperties PropertyWrapper newProperty = newProperties.get(newProperties.indexOf(oldProperty));
.indexOf(oldProperty));
if (newProperty.getValue() != null && newProperty.getValue() != null) { if (newProperty.getValue() != null && newProperty.getValue() != null) {
if (!newProperty.getValue().equals(oldProperty.getValue())) if (!newProperty.getValue().equals(oldProperty.getValue()))
// Values don't match, so the property is not unique // Values don't match, so the property is not unique
@@ -33,8 +33,8 @@ import org.diylc.core.VisibilityPolicy;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
/** /**
* Utility that deals with painting {@link Project} on the {@link Graphics2D} * Utility that deals with painting {@link Project} on the {@link Graphics2D} and keeps areas taken
* and keeps areas taken by each drawn component. * by each drawn component.
* *
* @author Branislav Stojkovic * @author Branislav Stojkovic
*/ */
@@ -51,8 +51,8 @@ public class DrawingManager {
public static Color CONTROL_POINT_COLOR = Color.blue; public static Color CONTROL_POINT_COLOR = Color.blue;
public static Color SELECTED_CONTROL_POINT_COLOR = Color.green; public static Color SELECTED_CONTROL_POINT_COLOR = Color.green;
private Theme theme = (Theme) ConfigurationManager.getInstance() private Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY,
.readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); Constants.DEFAULT_THEME);
// Keeps Area object of each drawn component. // Keeps Area object of each drawn component.
private Map<IDIYComponent<?>, Area> componentAreaMap; private Map<IDIYComponent<?>, Area> componentAreaMap;
@@ -60,10 +60,8 @@ public class DrawingManager {
// determine which components are invalidated when they are not in the map. // determine which components are invalidated when they are not in the map.
private Map<IDIYComponent<?>, ComponentState> lastDrawnStateMap; private Map<IDIYComponent<?>, ComponentState> lastDrawnStateMap;
private Composite slotComposite = AlphaComposite.getInstance( private Composite slotComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
AlphaComposite.SRC_OVER, 0.3f); private Composite lockedComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
private Composite lockedComposite = AlphaComposite.getInstance(
AlphaComposite.SRC_OVER, 0.3f);
private List<IDIYComponent<?>> failedComponents = new ArrayList<IDIYComponent<?>>(); private List<IDIYComponent<?>> failedComponents = new ArrayList<IDIYComponent<?>>();
private double zoomLevel = 1d;// ConfigurationManager.getInstance().readDouble(ZOOM_KEY, private double zoomLevel = 1d;// ConfigurationManager.getInstance().readDouble(ZOOM_KEY,
@@ -78,15 +76,12 @@ public class DrawingManager {
this.messageDispatcher = messageDispatcher; this.messageDispatcher = messageDispatcher;
componentAreaMap = new HashMap<IDIYComponent<?>, Area>(); componentAreaMap = new HashMap<IDIYComponent<?>, Area>();
lastDrawnStateMap = new HashMap<IDIYComponent<?>, ComponentState>(); lastDrawnStateMap = new HashMap<IDIYComponent<?>, ComponentState>();
String debugComponentAreasStr = System String debugComponentAreasStr = System.getProperty(DEBUG_COMPONENT_AREAS);
.getProperty(DEBUG_COMPONENT_AREAS); debugComponentAreas = debugComponentAreasStr != null && debugComponentAreasStr.equalsIgnoreCase("true");
debugComponentAreas = debugComponentAreasStr != null
&& debugComponentAreasStr.equalsIgnoreCase("true");
} }
/** /**
* Paints the project onto the canvas and returns the list of components * Paints the project onto the canvas and returns the list of components that failed to draw.
* that failed to draw.
* *
* @param g2d * @param g2d
* @param project * @param project
@@ -101,13 +96,10 @@ public class DrawingManager {
* @param dragInProgress * @param dragInProgress
* @return * @return
*/ */
public List<IDIYComponent<?>> drawProject(Graphics2D g2d, Project project, public List<IDIYComponent<?>> drawProject(Graphics2D g2d, Project project, Set<DrawOption> drawOptions,
Set<DrawOption> drawOptions, IComponentFiler filter, IComponentFiler filter, Rectangle selectionRect, List<IDIYComponent<?>> selectedComponents,
Rectangle selectionRect, List<IDIYComponent<?>> selectedComponents, Set<IDIYComponent<?>> lockedComponents, Set<IDIYComponent<?>> groupedComponents, List<Point> controlPointSlot,
Set<IDIYComponent<?>> lockedComponents, List<IDIYComponent<?>> componentSlot, boolean dragInProgress) {
Set<IDIYComponent<?>> groupedComponents,
List<Point> controlPointSlot, List<IDIYComponent<?>> componentSlot,
boolean dragInProgress) {
failedComponents.clear(); failedComponents.clear();
if (project == null) { if (project == null) {
return failedComponents; return failedComponents;
@@ -115,41 +107,26 @@ public class DrawingManager {
G2DWrapper g2dWrapper = new G2DWrapper(g2d); G2DWrapper g2dWrapper = new G2DWrapper(g2d);
if (drawOptions.contains(DrawOption.ANTIALIASING)) { if (drawOptions.contains(DrawOption.ANTIALIASING)) {
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
} else { } else {
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
RenderingHints.VALUE_ANTIALIAS_OFF); g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
} }
if (ConfigurationManager.getInstance().readBoolean( if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.HI_QUALITY_RENDER_KEY, false)) {
IPlugInPort.HI_QUALITY_RENDER_KEY, false)) { g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
RenderingHints.VALUE_COLOR_RENDER_QUALITY); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_DITHERING,
RenderingHints.VALUE_DITHER_ENABLE);
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
// g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, // g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
// RenderingHints.VALUE_STROKE_PURE); // RenderingHints.VALUE_STROKE_PURE);
} else { } else {
g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);
RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED); g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED);
g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
RenderingHints.VALUE_COLOR_RENDER_SPEED); g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
RenderingHints.VALUE_RENDER_SPEED);
g2d.setRenderingHint(RenderingHints.KEY_DITHERING,
RenderingHints.VALUE_DITHER_DISABLE);
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
} }
double zoom = 1d; double zoom = 1d;
@@ -170,13 +147,10 @@ public class DrawingManager {
if (drawOptions.contains(DrawOption.GRID) && gridType != GridType.NONE) { if (drawOptions.contains(DrawOption.GRID) && gridType != GridType.NONE) {
double zoomStep = project.getGridSpacing().convertToPixels() * zoom; double zoomStep = project.getGridSpacing().convertToPixels() * zoom;
if (gridType == GridType.CROSSHAIR) { if (gridType == GridType.CROSSHAIR) {
g2d.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, g2d.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10f, new float[] {
BasicStroke.JOIN_MITER, 10f, new float[] { (float) zoomStep / 2, (float) zoomStep / 2}, (float) zoomStep / 4));
(float) zoomStep / 2, (float) zoomStep / 2 },
(float) zoomStep / 4));
} else if (gridType == GridType.DOT) { } else if (gridType == GridType.DOT) {
g2d.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, g2d.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10f, new float[] {1f,
BasicStroke.JOIN_MITER, 10f, new float[] { 1f,
(float) zoomStep - 1}, 0f)); (float) zoomStep - 1}, 0f));
} }
@@ -206,8 +180,7 @@ public class DrawingManager {
continue; continue;
} }
ComponentState state = ComponentState.NORMAL; ComponentState state = ComponentState.NORMAL;
if (drawOptions.contains(DrawOption.SELECTION) if (drawOptions.contains(DrawOption.SELECTION) && selectedComponents.contains(component)) {
&& selectedComponents.contains(component)) {
if (dragInProgress) { if (dragInProgress) {
state = ComponentState.DRAGGING; state = ComponentState.DRAGGING;
} else { } else {
@@ -229,9 +202,7 @@ public class DrawingManager {
} }
// Draw the component through the g2dWrapper. // Draw the component through the g2dWrapper.
try { try {
component.draw(g2dWrapper, state, drawOptions component.draw(g2dWrapper, state, drawOptions.contains(DrawOption.OUTLINE_MODE), project, g2dWrapper);
.contains(DrawOption.OUTLINE_MODE), project,
g2dWrapper);
} catch (Exception e) { } catch (Exception e) {
LOG.error("Error drawing " + component.getName(), e); LOG.error("Error drawing " + component.getName(), e);
failedComponents.add(component); failedComponents.add(component);
@@ -250,20 +221,15 @@ public class DrawingManager {
if (dragInProgress || drawOptions.contains(DrawOption.OUTLINE_MODE)) { if (dragInProgress || drawOptions.contains(DrawOption.OUTLINE_MODE)) {
for (IDIYComponent<?> component : project.getComponents()) { for (IDIYComponent<?> component : project.getComponents()) {
for (int i = 0; i < component.getControlPointCount(); i++) { for (int i = 0; i < component.getControlPointCount(); i++) {
VisibilityPolicy visibilityPolicy = component VisibilityPolicy visibilityPolicy = component.getControlPointVisibilityPolicy(i);
.getControlPointVisibilityPolicy(i);
if ((groupedComponents.contains(component) if ((groupedComponents.contains(component)
&& (visibilityPolicy == VisibilityPolicy.ALWAYS || (selectedComponents && (visibilityPolicy == VisibilityPolicy.ALWAYS || (selectedComponents.contains(component) && visibilityPolicy == VisibilityPolicy.WHEN_SELECTED)) || (!groupedComponents
.contains(component) && visibilityPolicy == VisibilityPolicy.WHEN_SELECTED)) || (!groupedComponents .contains(component) && !selectedComponents.contains(component) && component
.contains(component)
&& !selectedComponents.contains(component) && component
.getControlPointVisibilityPolicy(i) == VisibilityPolicy.ALWAYS))) { .getControlPointVisibilityPolicy(i) == VisibilityPolicy.ALWAYS))) {
g2dWrapper.setColor(CONTROL_POINT_COLOR); g2dWrapper.setColor(CONTROL_POINT_COLOR);
Point controlPoint = component.getControlPoint(i); Point controlPoint = component.getControlPoint(i);
int pointSize = CONTROL_POINT_SIZE - 2; int pointSize = CONTROL_POINT_SIZE - 2;
g2dWrapper.fillOval(controlPoint.x - pointSize / 2, g2dWrapper.fillOval(controlPoint.x - pointSize / 2, controlPoint.y - pointSize / 2, pointSize, pointSize);
controlPoint.y - pointSize / 2, pointSize,
pointSize);
} }
} }
} }
@@ -278,16 +244,11 @@ public class DrawingManager {
Point controlPoint = component.getControlPoint(i); Point controlPoint = component.getControlPoint(i);
int pointSize = CONTROL_POINT_SIZE; int pointSize = CONTROL_POINT_SIZE;
g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR.darker());
.darker()); g2dWrapper.fillOval(controlPoint.x - pointSize / 2, controlPoint.y - pointSize / 2, pointSize, pointSize);
g2dWrapper.fillOval(controlPoint.x - pointSize / 2,
controlPoint.y - pointSize / 2, pointSize,
pointSize);
g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR); g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR);
g2dWrapper.fillOval(controlPoint.x - CONTROL_POINT_SIZE g2dWrapper.fillOval(controlPoint.x - CONTROL_POINT_SIZE / 2 + 1, controlPoint.y - CONTROL_POINT_SIZE / 2
/ 2 + 1, controlPoint.y - CONTROL_POINT_SIZE + 1, CONTROL_POINT_SIZE - 2, CONTROL_POINT_SIZE - 2);
/ 2 + 1, CONTROL_POINT_SIZE - 2,
CONTROL_POINT_SIZE - 2);
} }
} }
} }
@@ -300,9 +261,8 @@ public class DrawingManager {
for (IDIYComponent<?> component : componentSlot) { for (IDIYComponent<?> component : componentSlot) {
try { try {
component.draw(g2dWrapper, ComponentState.NORMAL, component.draw(g2dWrapper, ComponentState.NORMAL, drawOptions.contains(DrawOption.OUTLINE_MODE), project,
drawOptions.contains(DrawOption.OUTLINE_MODE), g2dWrapper);
project, g2dWrapper);
} catch (Exception e) { } catch (Exception e) {
LOG.error("Error drawing " + component.getName(), e); LOG.error("Error drawing " + component.getName(), e);
@@ -317,12 +277,10 @@ public class DrawingManager {
for (Point point : controlPointSlot) { for (Point point : controlPointSlot) {
if (point != null) { if (point != null) {
g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR.darker()); g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR.darker());
g2dWrapper.fillOval(point.x - CONTROL_POINT_SIZE / 2, g2dWrapper.fillOval(point.x - CONTROL_POINT_SIZE / 2, point.y - CONTROL_POINT_SIZE / 2, CONTROL_POINT_SIZE,
point.y - CONTROL_POINT_SIZE / 2, CONTROL_POINT_SIZE);
CONTROL_POINT_SIZE, CONTROL_POINT_SIZE);
g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR); g2dWrapper.setColor(SELECTED_CONTROL_POINT_COLOR);
g2dWrapper.fillOval(point.x - CONTROL_POINT_SIZE / 2 + 1, g2dWrapper.fillOval(point.x - CONTROL_POINT_SIZE / 2 + 1, point.y - CONTROL_POINT_SIZE / 2 + 1,
point.y - CONTROL_POINT_SIZE / 2 + 1,
CONTROL_POINT_SIZE - 2, CONTROL_POINT_SIZE - 2); CONTROL_POINT_SIZE - 2, CONTROL_POINT_SIZE - 2);
} }
} }
@@ -337,8 +295,7 @@ public class DrawingManager {
// } // }
// At the end draw selection rectangle if needed. // At the end draw selection rectangle if needed.
if (drawOptions.contains(DrawOption.SELECTION) if (drawOptions.contains(DrawOption.SELECTION) && (selectionRect != null)) {
&& (selectionRect != null)) {
g2d.setColor(Color.white); g2d.setColor(Color.white);
g2d.draw(selectionRect); g2d.draw(selectionRect);
g2d.setColor(Color.black); g2d.setColor(Color.black);
@@ -393,8 +350,7 @@ public class DrawingManager {
return components; return components;
} }
public Dimension getCanvasDimensions(Project project, Double zoomLevel, public Dimension getCanvasDimensions(Project project, Double zoomLevel, boolean useZoom) {
boolean useZoom) {
double width = project.getWidth().convertToPixels(); double width = project.getWidth().convertToPixels();
double height = project.getHeight().convertToPixels(); double height = project.getHeight().convertToPixels();
if (useZoom) { if (useZoom) {
@@ -418,8 +374,7 @@ public class DrawingManager {
public void setTheme(Theme theme) { public void setTheme(Theme theme) {
this.theme = theme; this.theme = theme;
ConfigurationManager.getInstance().writeValue(IPlugInPort.THEME_KEY, ConfigurationManager.getInstance().writeValue(IPlugInPort.THEME_KEY, theme);
theme);
messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.REPAINT);
} }
} }
@@ -41,12 +41,11 @@ import java.util.Map;
import org.diylc.core.IDrawingObserver; import org.diylc.core.IDrawingObserver;
/** /**
* {@link Graphics2D} wrapper that keeps track of all drawing actions and * {@link Graphics2D} wrapper that keeps track of all drawing actions and creates an {@link Area}
* creates an {@link Area} that corresponds to drawn objects. Before each * that corresponds to drawn objects. Before each component is drawn,
* component is drawn, {@link #startedDrawingComponent()} should be called. * {@link #startedDrawingComponent()} should be called. After the component is drawn, area may be
* After the component is drawn, area may be retrieved using * retrieved using {@link #finishedDrawingComponent()}. Graphics configuration (color, font, etc) is
* {@link #finishedDrawingComponent()}. Graphics configuration (color, font, * reset between each two components.
* etc) is reset between each two components.
* *
* @author Branislav Stojkovic * @author Branislav Stojkovic
*/ */
@@ -99,8 +98,7 @@ class G2DWrapper extends Graphics2D implements IDrawingObserver {
} }
/** /**
* Reverts {@link Graphics2D} settings and returns area drawn by component * Reverts {@link Graphics2D} settings and returns area drawn by component in the meantime.
* in the meantime.
* *
* @return * @return
*/ */
@@ -172,14 +170,13 @@ class G2DWrapper extends Graphics2D implements IDrawingObserver {
case PathIterator.SEG_LINETO: case PathIterator.SEG_LINETO:
// Represent straight line with a rectangle. // Represent straight line with a rectangle.
Point2D nextPoint = new Point2D.Double(coord[0], coord[1]); Point2D nextPoint = new Point2D.Double(coord[0], coord[1]);
Double theta = Math.atan2(nextPoint.getY() - prevPoint.getY(), nextPoint.getX() Double theta = Math.atan2(nextPoint.getY() - prevPoint.getY(), nextPoint.getX() - prevPoint.getX());
- prevPoint.getX()); double width =
double width = Math.sqrt(Math.pow(nextPoint.getX() - prevPoint.getX(), 2) Math.sqrt(Math.pow(nextPoint.getX() - prevPoint.getX(), 2)
+ Math.pow(nextPoint.getY() - prevPoint.getY(), 2)); + Math.pow(nextPoint.getY() - prevPoint.getY(), 2));
double midX = (prevPoint.getX() + nextPoint.getX()) / 2; double midX = (prevPoint.getX() + nextPoint.getX()) / 2;
double midY = (prevPoint.getY() + nextPoint.getY()) / 2; double midY = (prevPoint.getY() + nextPoint.getY()) / 2;
Rectangle2D rect = new Rectangle2D.Double(midX - width / 2, midY - thickness / 2, Rectangle2D rect = new Rectangle2D.Double(midX - width / 2, midY - thickness / 2, width, thickness);
width, thickness);
Area area = new Area(rect); Area area = new Area(rect);
area.transform(AffineTransform.getRotateInstance(theta, midX, midY)); area.transform(AffineTransform.getRotateInstance(theta, midX, midY));
// area.transform(currentTx); // area.transform(currentTx);
@@ -188,14 +185,15 @@ class G2DWrapper extends Graphics2D implements IDrawingObserver {
prevPoint = nextPoint; prevPoint = nextPoint;
break; break;
case PathIterator.SEG_CUBICTO: case PathIterator.SEG_CUBICTO:
CubicCurve2D cubicCurve = new CubicCurve2D.Double(prevPoint.getX(), prevPoint CubicCurve2D cubicCurve =
.getY(), coord[0], coord[1], coord[2], coord[3], coord[4], coord[5]); new CubicCurve2D.Double(prevPoint.getX(), prevPoint.getY(), coord[0], coord[1], coord[2], coord[3],
coord[4], coord[5]);
addCubicCurveArea(cubicCurve); addCubicCurveArea(cubicCurve);
prevPoint = new Point2D.Double(coord[4], coord[5]); prevPoint = new Point2D.Double(coord[4], coord[5]);
break; break;
case PathIterator.SEG_QUADTO: case PathIterator.SEG_QUADTO:
QuadCurve2D quadCurve = new QuadCurve2D.Double(prevPoint.getX(), prevPoint.getY(), QuadCurve2D quadCurve =
coord[0], coord[1], coord[2], coord[3]); new QuadCurve2D.Double(prevPoint.getX(), prevPoint.getY(), coord[0], coord[1], coord[2], coord[3]);
addQuadCurveArea(quadCurve); addQuadCurveArea(quadCurve);
prevPoint = new Point2D.Double(coord[3], coord[3]); prevPoint = new Point2D.Double(coord[3], coord[3]);
break; break;
@@ -205,8 +203,8 @@ class G2DWrapper extends Graphics2D implements IDrawingObserver {
} }
/** /**
* Adds a cubic curve to the component area. It uses subdivision to * Adds a cubic curve to the component area. It uses subdivision to approximate the curve with a
* approximate the curve with a series of straight lines. * series of straight lines.
* *
* @param curve * @param curve
*/ */
@@ -225,8 +223,8 @@ class G2DWrapper extends Graphics2D implements IDrawingObserver {
} }
/** /**
* Adds a quad curve to the component area. It uses subdivision to * Adds a quad curve to the component area. It uses subdivision to approximate the curve with a
* approximate the curve with a series of straight lines. * series of straight lines.
* *
* @param curve * @param curve
*/ */
@@ -299,8 +297,9 @@ class G2DWrapper extends Graphics2D implements IDrawingObserver {
Rectangle2D rect = fontMetrics.getStringBounds(str, canvasGraphics); Rectangle2D rect = fontMetrics.getStringBounds(str, canvasGraphics);
Point2D point = new Point2D.Double(x, y); Point2D point = new Point2D.Double(x, y);
// currentTx.transform(point, point); // currentTx.transform(point, point);
Rectangle2D finalRec = new Rectangle2D.Double(rect.getX() + point.getX(), rect.getY() + point.getY(), rect Rectangle2D finalRec =
.getWidth(), rect.getHeight()); new Rectangle2D.Double(rect.getX() + point.getX(), rect.getY() + point.getY(), rect.getWidth(),
rect.getHeight());
appendShape(finalRec); appendShape(finalRec);
} }
} }
@@ -311,8 +310,7 @@ class G2DWrapper extends Graphics2D implements IDrawingObserver {
if (drawingComponent && trackingAllowed) { if (drawingComponent && trackingAllowed) {
FontMetrics fontMetrics = canvasGraphics.getFontMetrics(); FontMetrics fontMetrics = canvasGraphics.getFontMetrics();
Rectangle2D rect = fontMetrics.getStringBounds(str, canvasGraphics); Rectangle2D rect = fontMetrics.getStringBounds(str, canvasGraphics);
appendShape(new Rectangle2D.Double(rect.getX() + x, rect.getY() + y, rect.getWidth(), appendShape(new Rectangle2D.Double(rect.getX() + x, rect.getY() + y, rect.getWidth(), rect.getHeight()));
rect.getHeight()));
} }
} }
@@ -529,22 +527,21 @@ class G2DWrapper extends Graphics2D implements IDrawingObserver {
} }
@Override @Override
public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) {
ImageObserver observer) {
// FIXME: map // FIXME: map
return canvasGraphics.drawImage(img, x, y, width, height, bgcolor, observer); return canvasGraphics.drawImage(img, x, y, width, height, bgcolor, observer);
} }
@Override @Override
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2,
int sx2, int sy2, ImageObserver observer) { ImageObserver observer) {
// FIXME: map // FIXME: map
return canvasGraphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer); return canvasGraphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer);
} }
@Override @Override
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2,
int sx2, int sy2, Color bgcolor, ImageObserver observer) { Color bgcolor, ImageObserver observer) {
// FIXME: map // FIXME: map
return drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer); return drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer);
} }
@@ -28,8 +28,7 @@ import org.diylc.core.measures.Size;
*/ */
public class InstantiationManager { public class InstantiationManager {
private static final Logger LOG = Logger private static final Logger LOG = Logger.getLogger(InstantiationManager.class);
.getLogger(InstantiationManager.class);
public static int MAX_RECENT_COMPONENTS = 16; public static int MAX_RECENT_COMPONENTS = 16;
@@ -39,13 +38,11 @@ public class InstantiationManager {
private Point firstControlPoint; private Point firstControlPoint;
private Point potentialControlPoint; private Point potentialControlPoint;
private static final ComponentType clipboardType = new ComponentType( private static final ComponentType clipboardType = new ComponentType("Clipboard contents",
"Clipboard contents", "Components from the clipboard", "Components from the clipboard", CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, false, null,
CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, false, true);
false, null, false, true);
public InstantiationManager() { public InstantiationManager() {}
}
public ComponentType getComponentTypeSlot() { public ComponentType getComponentTypeSlot() {
return componentTypeSlot; return componentTypeSlot;
@@ -67,8 +64,8 @@ public class InstantiationManager {
return potentialControlPoint; return potentialControlPoint;
} }
public void setComponentTypeSlot(ComponentType componentTypeSlot, public void setComponentTypeSlot(ComponentType componentTypeSlot, Template template, Project currentProject)
Template template, Project currentProject) throws Exception { throws Exception {
this.componentTypeSlot = componentTypeSlot; this.componentTypeSlot = componentTypeSlot;
this.template = template; this.template = template;
if (componentTypeSlot == null) { if (componentTypeSlot == null) {
@@ -79,8 +76,7 @@ public class InstantiationManager {
this.componentSlot = null; this.componentSlot = null;
break; break;
case SINGLE_CLICK: case SINGLE_CLICK:
this.componentSlot = instantiateComponent(componentTypeSlot, this.componentSlot = instantiateComponent(componentTypeSlot, template, new Point(0, 0), currentProject);
template, new Point(0, 0), currentProject);
break; break;
} }
} }
@@ -88,11 +84,9 @@ public class InstantiationManager {
this.potentialControlPoint = null; this.potentialControlPoint = null;
} }
public void instatiatePointByPoint(Point scaledPoint, Project currentProject) public void instatiatePointByPoint(Point scaledPoint, Project currentProject) throws Exception {
throws Exception {
firstControlPoint = scaledPoint; firstControlPoint = scaledPoint;
componentSlot = instantiateComponent(componentTypeSlot, template, componentSlot = instantiateComponent(componentTypeSlot, template, firstControlPoint, currentProject);
firstControlPoint, currentProject);
// Set the other control point to the same location, we'll // Set the other control point to the same location, we'll
// move it later when mouse moves. // move it later when mouse moves.
@@ -115,8 +109,7 @@ public class InstantiationManager {
return changeMade; return changeMade;
} }
public void pasteComponents(List<IDIYComponent<?>> components, public void pasteComponents(List<IDIYComponent<?>> components, Point scaledPoint, boolean snapToGrid, Size gridSpacing) {
Point scaledPoint, boolean snapToGrid, Size gridSpacing) {
// Adjust location of components so they are centered under the mouse // Adjust location of components so they are centered under the mouse
// cursor // cursor
int minX = Integer.MAX_VALUE; int minX = Integer.MAX_VALUE;
@@ -177,8 +170,7 @@ public class InstantiationManager {
* @param gridSpacing * @param gridSpacing
* @return true if we need to refresh the canvas * @return true if we need to refresh the canvas
*/ */
public boolean updateSingleClick(Point scaledPoint, boolean snapToGrid, public boolean updateSingleClick(Point scaledPoint, boolean snapToGrid, Size gridSpacing) {
Size gridSpacing) {
if (potentialControlPoint == null) { if (potentialControlPoint == null) {
potentialControlPoint = new Point(0, 0); potentialControlPoint = new Point(0, 0);
} }
@@ -212,15 +204,12 @@ public class InstantiationManager {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public List<IDIYComponent<?>> instantiateComponent( public List<IDIYComponent<?>> instantiateComponent(ComponentType componentType, Template template, Point point,
ComponentType componentType, Template template, Point point,
Project currentProject) throws Exception { Project currentProject) throws Exception {
LOG.info("Instatiating component of type: " LOG.info("Instatiating component of type: " + componentType.getInstanceClass().getName());
+ componentType.getInstanceClass().getName());
// Instantiate the component. // Instantiate the component.
IDIYComponent<?> component = componentType.getInstanceClass() IDIYComponent<?> component = componentType.getInstanceClass().newInstance();
.newInstance();
component.setName(createUniqueName(componentType, currentProject)); component.setName(createUniqueName(componentType, currentProject));
@@ -239,12 +228,11 @@ public class InstantiationManager {
fillWithDefaultProperties(component, template); fillWithDefaultProperties(component, template);
// Write to recent components // Write to recent components
List<String> recentComponentTypes = (List<String>) ConfigurationManager List<String> recentComponentTypes =
.getInstance().readObject(IPlugInPort.RECENT_COMPONENTS_KEY, (List<String>) ConfigurationManager.getInstance().readObject(IPlugInPort.RECENT_COMPONENTS_KEY,
new ArrayList<ComponentType>()); new ArrayList<ComponentType>());
String className = componentType.getInstanceClass().getName(); String className = componentType.getInstanceClass().getName();
if (recentComponentTypes.size() == 0 if (recentComponentTypes.size() == 0 || !recentComponentTypes.get(0).equals(className)) {
|| !recentComponentTypes.get(0).equals(className)) {
// Remove if it's already somewhere in the list. // Remove if it's already somewhere in the list.
recentComponentTypes.remove(className); recentComponentTypes.remove(className);
// Add to the end of the list. // Add to the end of the list.
@@ -253,8 +241,7 @@ public class InstantiationManager {
if (recentComponentTypes.size() > MAX_RECENT_COMPONENTS) { if (recentComponentTypes.size() > MAX_RECENT_COMPONENTS) {
recentComponentTypes.remove(recentComponentTypes.size() - 1); recentComponentTypes.remove(recentComponentTypes.size() - 1);
} }
ConfigurationManager.getInstance().writeValue( ConfigurationManager.getInstance().writeValue(IPlugInPort.RECENT_COMPONENTS_KEY, recentComponentTypes);
IPlugInPort.RECENT_COMPONENTS_KEY, recentComponentTypes);
} }
List<IDIYComponent<?>> list = new ArrayList<IDIYComponent<?>>(); List<IDIYComponent<?>> list = new ArrayList<IDIYComponent<?>>();
@@ -262,8 +249,7 @@ public class InstantiationManager {
return list; return list;
} }
public String createUniqueName(ComponentType componentType, public String createUniqueName(ComponentType componentType, Project currentProject) {
Project currentProject) {
boolean exists = true; boolean exists = true;
List<IDIYComponent<?>> components = currentProject.getComponents(); List<IDIYComponent<?>> components = currentProject.getComponents();
String[] takenNames = new String[components.size()]; String[] takenNames = new String[components.size()];
@@ -284,9 +270,8 @@ public class InstantiationManager {
} }
/** /**
* Finds any properties that have default values and injects default values. * Finds any properties that have default values and injects default values. Typically it should
* Typically it should be used for {@link IDIYComponent} and {@link Project} * be used for {@link IDIYComponent} and {@link Project} objects.
* objects.
* *
* @param object * @param object
* @param template * @param template
@@ -296,35 +281,29 @@ public class InstantiationManager {
* @throws NoSuchMethodException * @throws NoSuchMethodException
* @throws SecurityException * @throws SecurityException
*/ */
public void fillWithDefaultProperties(Object object, Template template) public void fillWithDefaultProperties(Object object, Template template) throws IllegalArgumentException,
throws IllegalArgumentException, IllegalAccessException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchMethodException {
InvocationTargetException, SecurityException, NoSuchMethodException {
// Extract properties. // Extract properties.
List<PropertyWrapper> properties = ComponentProcessor.getInstance() List<PropertyWrapper> properties = ComponentProcessor.getInstance().extractProperties(object.getClass());
.extractProperties(object.getClass());
Map<String, PropertyWrapper> propertyCache = new HashMap<String, PropertyWrapper>(); Map<String, PropertyWrapper> propertyCache = new HashMap<String, PropertyWrapper>();
// Override with default values if available. // Override with default values if available.
for (PropertyWrapper property : properties) { for (PropertyWrapper property : properties) {
propertyCache.put(property.getName(), property); propertyCache.put(property.getName(), property);
Object defaultValue = ConfigurationManager.getInstance() Object defaultValue =
.readObject( ConfigurationManager.getInstance().readObject(
Presenter.DEFAULTS_KEY_PREFIX Presenter.DEFAULTS_KEY_PREFIX + object.getClass().getName() + ":" + property.getName(), null);
+ object.getClass().getName() + ":"
+ property.getName(), null);
if (defaultValue != null) { if (defaultValue != null) {
property.setValue(defaultValue); property.setValue(defaultValue);
property.writeTo(object); property.writeTo(object);
} }
} }
if (template != null) { if (template != null) {
for (Map.Entry<String, Object> pair : template.getValues() for (Map.Entry<String, Object> pair : template.getValues().entrySet()) {
.entrySet()) {
PropertyWrapper property = propertyCache.get(pair.getKey()); PropertyWrapper property = propertyCache.get(pair.getKey());
if (property == null) { if (property == null) {
LOG.warn("Cannot find property " + pair.getKey()); LOG.warn("Cannot find property " + pair.getKey());
} else { } else {
LOG.debug("Filling value from template for " LOG.debug("Filling value from template for " + pair.getKey());
+ pair.getKey());
property.setValue(pair.getValue()); property.setValue(pair.getValue());
property.writeTo(object); property.writeTo(object);
} }
@@ -338,16 +317,12 @@ public class InstantiationManager {
* @param component * @param component
* @param template * @param template
*/ */
public void loadComponentShapeFromTemplate(IDIYComponent<?> component, public void loadComponentShapeFromTemplate(IDIYComponent<?> component, Template template) {
Template template) { if (template != null && template.getPoints() != null
if (template != null && template.getPoints().size() >= component.getControlPointCount()) {
&& template.getPoints() != null
&& template.getPoints().size() >= component
.getControlPointCount()) {
for (int i = 0; i < component.getControlPointCount(); i++) { for (int i = 0; i < component.getControlPointCount(); i++) {
Point p = new Point(component.getControlPoint(0)); Point p = new Point(component.getControlPoint(0));
p.translate(template.getPoints().get(i).x, template.getPoints() p.translate(template.getPoints().get(i).x, template.getPoints().get(i).y);
.get(i).y);
component.setControlPoint(p, i); component.setControlPoint(p, i);
} }
} }
@@ -358,21 +333,18 @@ public class InstantiationManager {
LOG.debug("Component slot is empty, cannot rotate"); LOG.debug("Component slot is empty, cannot rotate");
return; return;
} }
List<PropertyWrapper> properties = ComponentProcessor.getInstance() List<PropertyWrapper> properties =
.extractProperties(this.componentTypeSlot.getInstanceClass()); ComponentProcessor.getInstance().extractProperties(this.componentTypeSlot.getInstanceClass());
PropertyWrapper angleProperty = null; PropertyWrapper angleProperty = null;
for (PropertyWrapper propertyWrapper : properties) { for (PropertyWrapper propertyWrapper : properties) {
if (propertyWrapper.getType().getName().equals( if (propertyWrapper.getType().getName().equals(Orientation.class.getName())
Orientation.class.getName()) || propertyWrapper.getType().getName().equals(OrientationHV.class.getName())) {
|| propertyWrapper.getType().getName().equals(
OrientationHV.class.getName())) {
angleProperty = propertyWrapper; angleProperty = propertyWrapper;
break; break;
} }
} }
if (angleProperty == null) { if (angleProperty == null) {
LOG LOG.debug("Component in the slot does not have a property of type Orientation, cannot rotate");
.debug("Component in the slot does not have a property of type Orientation, cannot rotate");
return; return;
} }
try { try {
@@ -380,14 +352,10 @@ public class InstantiationManager {
angleProperty.readFrom(component); angleProperty.readFrom(component);
Object value = angleProperty.getValue(); Object value = angleProperty.getValue();
if (value instanceof Orientation) { if (value instanceof Orientation) {
angleProperty angleProperty.setValue(Orientation.values()[(((Orientation) value).ordinal() + 1)
.setValue(Orientation.values()[(((Orientation) value)
.ordinal() + 1)
% Orientation.values().length]); % Orientation.values().length]);
} else if (value instanceof OrientationHV) { } else if (value instanceof OrientationHV) {
angleProperty angleProperty.setValue(OrientationHV.values()[(((OrientationHV) value).ordinal() + 1)
.setValue(OrientationHV.values()[(((OrientationHV) value)
.ordinal() + 1)
% OrientationHV.values().length]); % OrientationHV.values().length]);
} }
angleProperty.writeTo(component); angleProperty.writeTo(component);
@@ -11,8 +11,8 @@ import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
/** /**
* Serializes {@link Point} objects by converting coordinates from pixels to * Serializes {@link Point} objects by converting coordinates from pixels to inches, thus avoiding
* inches, thus avoiding the resolution to affect point placement. * the resolution to affect point placement.
* *
* @author Branislav Stojkovic * @author Branislav Stojkovic
*/ */
@@ -29,8 +29,7 @@ public class PointConverter implements Converter {
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
double x = Double.parseDouble(reader.getAttribute("x")); double x = Double.parseDouble(reader.getAttribute("x"));
double y = Double.parseDouble(reader.getAttribute("y")); double y = Double.parseDouble(reader.getAttribute("y"));
return new Point((int) Math.round(x * Constants.PIXELS_PER_INCH), (int) Math.round(y return new Point((int) Math.round(x * Constants.PIXELS_PER_INCH), (int) Math.round(y * Constants.PIXELS_PER_INCH));
* Constants.PIXELS_PER_INCH));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@@ -124,8 +124,8 @@ public class ProjectFileManager {
} }
} }
public Project deserializeProjectFromFile(String fileName, List<String> warnings) public Project deserializeProjectFromFile(String fileName, List<String> warnings) throws SAXException, IOException,
throws SAXException, IOException, ParserConfigurationException { ParserConfigurationException {
LOG.info(String.format("loadProjectFromFile(%s)", fileName)); LOG.info(String.format("loadProjectFromFile(%s)", fileName));
Project project; Project project;
File file = new File(fileName); File file = new File(fileName);
@@ -137,8 +137,7 @@ public class ProjectFileManager {
project = parseV3File(fileName); project = parseV3File(fileName);
} else { } else {
if (!doc.getDocumentElement().getNodeName().equalsIgnoreCase("layout")) { if (!doc.getDocumentElement().getNodeName().equalsIgnoreCase("layout")) {
throw new IllegalArgumentException( throw new IllegalArgumentException("Could not open DIY file. Root node is not named 'Layout'.");
"Could not open DIY file. Root node is not named 'Layout'.");
} }
String formatVersion = doc.getDocumentElement().getAttribute("formatVersion"); String formatVersion = doc.getDocumentElement().getAttribute("formatVersion");
if (formatVersion == null || formatVersion.trim().isEmpty()) { if (formatVersion == null || formatVersion.trim().isEmpty()) {
@@ -171,8 +170,7 @@ public class ProjectFileManager {
} }
public void fireFileStatusChanged() { public void fireFileStatusChanged() {
messageDispatcher.dispatchMessage(EventType.FILE_STATUS_CHANGED, getCurrentFileName(), messageDispatcher.dispatchMessage(EventType.FILE_STATUS_CHANGED, getCurrentFileName(), isModified());
isModified());
} }
private Project parseV1File(Element root, List<String> warnings) { private Project parseV1File(Element root, List<String> warnings) {
@@ -204,11 +202,12 @@ public class ProjectFileManager {
throw new IllegalArgumentException("Unrecognized board type: " + type); throw new IllegalArgumentException("Unrecognized board type: " + type);
} }
board.setName("Main board"); board.setName("Main board");
Point referencePoint = new Point(CalcUtils.roundToGrid(x, V1_GRID_SPACING), CalcUtils Point referencePoint =
.roundToGrid(y, V1_GRID_SPACING)); new Point(CalcUtils.roundToGrid(x, V1_GRID_SPACING), CalcUtils.roundToGrid(y, V1_GRID_SPACING));
board.setControlPoint(referencePoint, 0); board.setControlPoint(referencePoint, 0);
board.setControlPoint(new Point(CalcUtils.roundToGrid(x + boardWidth, V1_GRID_SPACING), board.setControlPoint(
CalcUtils.roundToGrid(y + boardHeight, V1_GRID_SPACING)), 1); new Point(CalcUtils.roundToGrid(x + boardWidth, V1_GRID_SPACING), CalcUtils.roundToGrid(y + boardHeight,
V1_GRID_SPACING)), 1);
project.getComponents().add(board); project.getComponents().add(board);
NodeList childNodes = root.getChildNodes(); NodeList childNodes = root.getChildNodes();
@@ -219,10 +218,8 @@ public class ProjectFileManager {
String nameAttr = node.getAttributes().getNamedItem("Name").getNodeValue(); String nameAttr = node.getAttributes().getNamedItem("Name").getNodeValue();
Node valueNode = node.getAttributes().getNamedItem("Value"); Node valueNode = node.getAttributes().getNamedItem("Value");
String valueAttr = valueNode == null ? null : valueNode.getNodeValue(); String valueAttr = valueNode == null ? null : valueNode.getNodeValue();
int x1Attr = Integer.parseInt(node.getAttributes().getNamedItem("X1") int x1Attr = Integer.parseInt(node.getAttributes().getNamedItem("X1").getNodeValue());
.getNodeValue()); int y1Attr = Integer.parseInt(node.getAttributes().getNamedItem("Y1").getNodeValue());
int y1Attr = Integer.parseInt(node.getAttributes().getNamedItem("Y1")
.getNodeValue());
Point point1 = convertV1CoordinatesToV3Point(referencePoint, x1Attr, y1Attr); Point point1 = convertV1CoordinatesToV3Point(referencePoint, x1Attr, y1Attr);
Point point2 = null; Point point2 = null;
Integer x2Attr = null; Integer x2Attr = null;
@@ -232,12 +229,9 @@ public class ProjectFileManager {
String colorAttr = node.getAttributes().getNamedItem("Color").getNodeValue(); String colorAttr = node.getAttributes().getNamedItem("Color").getNodeValue();
color = V1_COLOR_MAP.get(colorAttr.toLowerCase()); color = V1_COLOR_MAP.get(colorAttr.toLowerCase());
} }
if (node.getAttributes().getNamedItem("X2") != null if (node.getAttributes().getNamedItem("X2") != null && node.getAttributes().getNamedItem("Y2") != null) {
&& node.getAttributes().getNamedItem("Y2") != null) { x2Attr = Integer.parseInt(node.getAttributes().getNamedItem("X2").getNodeValue());
x2Attr = Integer.parseInt(node.getAttributes().getNamedItem("X2") y2Attr = Integer.parseInt(node.getAttributes().getNamedItem("Y2").getNodeValue());
.getNodeValue());
y2Attr = Integer.parseInt(node.getAttributes().getNamedItem("Y2")
.getNodeValue());
point2 = convertV1CoordinatesToV3Point(referencePoint, x2Attr, y2Attr); point2 = convertV1CoordinatesToV3Point(referencePoint, x2Attr, y2Attr);
} }
IDIYComponent<?> component = null; IDIYComponent<?> component = null;
@@ -251,8 +245,7 @@ public class ProjectFileManager {
label.setText(valueAttr); label.setText(valueAttr);
label.setHorizontalAlignment(HorizontalAlignment.LEFT); label.setHorizontalAlignment(HorizontalAlignment.LEFT);
label.setVerticalAlignment(VerticalAlignment.CENTER); label.setVerticalAlignment(VerticalAlignment.CENTER);
label.setControlPoint(convertV1CoordinatesToV3Point(referencePoint, x1Attr, label.setControlPoint(convertV1CoordinatesToV3Point(referencePoint, x1Attr, y1Attr), 0);
y1Attr), 0);
component = label; component = label;
} else if (nodeName.equalsIgnoreCase("pad")) { } else if (nodeName.equalsIgnoreCase("pad")) {
LOG.debug("Recognized " + nodeName); LOG.debug("Recognized " + nodeName);
@@ -261,8 +254,7 @@ public class ProjectFileManager {
if (color != null) { if (color != null) {
pad.setColor(color); pad.setColor(color);
} }
pad.setControlPoint(convertV1CoordinatesToV3Point(referencePoint, x1Attr, pad.setControlPoint(convertV1CoordinatesToV3Point(referencePoint, x1Attr, y1Attr), 0);
y1Attr), 0);
component = pad; component = pad;
} else if (nodeName.equalsIgnoreCase("trace")) { } else if (nodeName.equalsIgnoreCase("trace")) {
LOG.debug("Recognized " + nodeName); LOG.debug("Recognized " + nodeName);
@@ -475,8 +467,7 @@ public class ProjectFileManager {
Point p = new Point(pot.getControlPoint(j)); Point p = new Point(pot.getControlPoint(j));
p.translate(point1.x, point1.y + delta); p.translate(point1.x, point1.y + delta);
pot.setControlPoint(p, j); pot.setControlPoint(p, j);
} };
;
} }
component = pot; component = pot;
} else { } else {
@@ -497,15 +488,14 @@ public class ProjectFileManager {
} }
} }
} }
Collections.sort(project.getComponents(), ComparatorFactory.getInstance() Collections.sort(project.getComponents(), ComparatorFactory.getInstance().getComponentZOrderComparator());
.getComponentZOrderComparator());
return project; return project;
} }
private Point convertV1CoordinatesToV3Point(Point reference, int x, int y) { private Point convertV1CoordinatesToV3Point(Point reference, int x, int y) {
Point point = new Point(reference); Point point = new Point(reference);
point.translate((int) (x * Constants.PIXELS_PER_INCH * V1_GRID_SPACING.getValue()), point.translate((int) (x * Constants.PIXELS_PER_INCH * V1_GRID_SPACING.getValue()), (int) (y
(int) (y * Constants.PIXELS_PER_INCH * V1_GRID_SPACING.getValue())); * Constants.PIXELS_PER_INCH * V1_GRID_SPACING.getValue()));
return point; return point;
} }
@@ -25,13 +25,11 @@ public class BomMaker {
return instance; return instance;
} }
private BomMaker() { private BomMaker() {}
}
public List<BomEntry> createBom(List<IDIYComponent<?>> components) { public List<BomEntry> createBom(List<IDIYComponent<?>> components) {
Map<String, BomEntry> entryMap = new LinkedHashMap<String, BomEntry>(); Map<String, BomEntry> entryMap = new LinkedHashMap<String, BomEntry>();
List<IDIYComponent<?>> sortedComponents = new ArrayList<IDIYComponent<?>>( List<IDIYComponent<?>> sortedComponents = new ArrayList<IDIYComponent<?>>(components);
components);
Collections.sort(sortedComponents, new Comparator<IDIYComponent<?>>() { Collections.sort(sortedComponents, new Comparator<IDIYComponent<?>>() {
@Override @Override
@@ -56,10 +54,9 @@ public class BomMaker {
} }
}); });
for (IDIYComponent<?> component : sortedComponents) { for (IDIYComponent<?> component : sortedComponents) {
ComponentType type = ComponentProcessor.getInstance() ComponentType type =
.extractComponentTypeFrom( ComponentProcessor.getInstance().extractComponentTypeFrom(
(Class<? extends IDIYComponent<?>>) component (Class<? extends IDIYComponent<?>>) component.getClass());
.getClass());
if (type.getBomPolicy() == BomPolicy.NEVER_SHOW) if (type.getBomPolicy() == BomPolicy.NEVER_SHOW)
continue; continue;
String name = component.getName(); String name = component.getName();
@@ -78,9 +75,9 @@ public class BomMaker {
entry.setName(entry.getName() + ", " + name); entry.setName(entry.getName() + ", " + name);
} }
} else { } else {
entryMap.put(key, new BomEntry(type.getName(), type entryMap.put(key,
.getBomPolicy() == BomPolicy.SHOW_ALL_NAMES ? name new BomEntry(type.getName(), type.getBomPolicy() == BomPolicy.SHOW_ALL_NAMES ? name : type.getName(),
: type.getName(), value, 1)); value, 1));
} }
} }
} }
@@ -10,16 +10,15 @@ import org.diylc.core.Theme;
public class Constants { public class Constants {
public static final int PIXELS_PER_INCH = 200; public static final int PIXELS_PER_INCH = 200;
public static final double PIXEL_SIZE = 1d * PIXELS_PER_INCH public static final double PIXEL_SIZE = 1d * PIXELS_PER_INCH / Toolkit.getDefaultToolkit().getScreenResolution();
/ Toolkit.getDefaultToolkit().getScreenResolution();
public static Color CANVAS_COLOR = Color.white; public static Color CANVAS_COLOR = Color.white;
public static final Stroke DASHED_STROKE = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, public static final Stroke DASHED_STROKE = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10f,
BasicStroke.JOIN_MITER, 10f, new float[] { 2.0f }, 0.0f); new float[] {2.0f}, 0.0f);
public static final Theme DEFAULT_THEME = new Theme("Light", Constants.CANVAS_COLOR, new Color( public static final Theme DEFAULT_THEME = new Theme("Light", Constants.CANVAS_COLOR, new Color(240, 240, 240),
240, 240, 240), Color.black); Color.black);
public static final Color TRANSPARENT_COLOR = new Color(0, 0, 0, 0); public static final Color TRANSPARENT_COLOR = new Color(0, 0, 0, 0);
@@ -14,8 +14,7 @@ public class ClassProcessorTest {
@Test @Test
public void testExtractProperties() { public void testExtractProperties() {
List<PropertyWrapper> properties = ComponentProcessor.getInstance().extractProperties( List<PropertyWrapper> properties = ComponentProcessor.getInstance().extractProperties(MockDIYComponent.class);
MockDIYComponent.class);
assertNotNull(properties); assertNotNull(properties);
assertEquals(4, properties.size()); assertEquals(4, properties.size());
}; };
@@ -19,7 +19,8 @@ import org.diylc.core.measures.ResistanceUnit;
import org.diylc.core.measures.Size; import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Mock", author = "bancika", category = "Sample", instanceNamePrefix = "M", description = "test", zOrder = IDIYComponent.COMPONENT) @ComponentDescriptor(name = "Mock", author = "bancika", category = "Sample", instanceNamePrefix = "M",
description = "test", zOrder = IDIYComponent.COMPONENT)
public class MockDIYComponent extends AbstractComponent<Capacitance> { public class MockDIYComponent extends AbstractComponent<Capacitance> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -32,8 +33,7 @@ public class MockDIYComponent extends AbstractComponent<Capacitance> {
private Point leftTopCorner = new Point(0, 0); private Point leftTopCorner = new Point(0, 0);
private String name = "something"; private String name = "something";
public MockDIYComponent(String testField, Capacitance c, Resistance r, Size s, Color color, public MockDIYComponent(String testField, Capacitance c, Resistance r, Size s, Color color, Point leftTopCorner) {
Point leftTopCorner) {
super(); super();
this.testField = testField; this.testField = testField;
this.c = c; this.c = c;
@@ -133,8 +133,8 @@ public class MockDIYComponent extends AbstractComponent<Capacitance> {
} }
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
Project project, IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
g2d.setColor(componentState.equals(ComponentState.SELECTED) ? color : color.darker()); g2d.setColor(componentState.equals(ComponentState.SELECTED) ? color : color.darker());
g2d.fillRect(leftTopCorner.x, leftTopCorner.y, 200, 50); g2d.fillRect(leftTopCorner.x, leftTopCorner.y, 200, 50);
} }
@@ -30,8 +30,7 @@ public abstract class AbstractBoard extends AbstractTransparentComponent<String>
public static Size DEFAULT_HEIGHT = new Size(1.2d, SizeUnit.in); public static Size DEFAULT_HEIGHT = new Size(1.2d, SizeUnit.in);
protected String value = ""; protected String value = "";
protected Point[] controlPoints = new Point[] { protected Point[] controlPoints = new Point[] {new Point(0, 0),
new Point(0, 0),
new Point((int) DEFAULT_WIDTH.convertToPixels(), (int) DEFAULT_HEIGHT.convertToPixels())}; new Point((int) DEFAULT_WIDTH.convertToPixels(), (int) DEFAULT_HEIGHT.convertToPixels())};
protected Point firstPoint = new Point(); protected Point firstPoint = new Point();
protected Point secondPoint = new Point(); protected Point secondPoint = new Point();
@@ -42,27 +41,24 @@ public abstract class AbstractBoard extends AbstractTransparentComponent<String>
protected Boolean drawCoordinates = true; protected Boolean drawCoordinates = true;
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
Project project, IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
if (componentState != ComponentState.DRAGGING) { if (componentState != ComponentState.DRAGGING) {
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
/ MAX_ALPHA));
} }
g2d.setColor(boardColor); g2d.setColor(boardColor);
g2d.fillRect(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y g2d.fillRect(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y);
- firstPoint.y);
g2d.setComposite(oldComposite); g2d.setComposite(oldComposite);
} }
// Do not track any changes that follow because the whole board has been // Do not track any changes that follow because the whole board has been
// tracked so far. // tracked so far.
drawingObserver.stopTracking(); drawingObserver.stopTracking();
g2d.setColor(componentState == ComponentState.SELECTED g2d.setColor(componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor); : borderColor);
g2d.drawRect(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y g2d.drawRect(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y);
- firstPoint.y);
} }
protected void drawCoordinates(Graphics2D g2d, int spacing) { protected void drawCoordinates(Graphics2D g2d, int spacing) {
@@ -75,16 +71,16 @@ public abstract class AbstractBoard extends AbstractTransparentComponent<String>
int t = 1; int t = 1;
while (p.y < secondPoint.y - spacing) { while (p.y < secondPoint.y - spacing) {
p.y += spacing; p.y += spacing;
super.drawCenteredText(g2d, getCoordinateLabel(t++), p.x + 2, p.y, super.drawCenteredText(g2d, getCoordinateLabel(t++), p.x + 2, p.y, HorizontalAlignment.LEFT,
HorizontalAlignment.LEFT, VerticalAlignment.CENTER); VerticalAlignment.CENTER);
} }
p = new Point(firstPoint); p = new Point(firstPoint);
t = 1; t = 1;
while (p.x < secondPoint.x - spacing) { while (p.x < secondPoint.x - spacing) {
p.x += spacing; p.x += spacing;
super.drawCenteredText(g2d, getCoordinateLabel(t++), p.x, p.y - 2, super.drawCenteredText(g2d, getCoordinateLabel(t++), p.x, p.y - 2, HorizontalAlignment.CENTER,
HorizontalAlignment.CENTER, VerticalAlignment.TOP); VerticalAlignment.TOP);
} }
} }
@@ -164,10 +160,10 @@ public abstract class AbstractBoard extends AbstractTransparentComponent<String>
@Override @Override
public void setControlPoint(Point point, int index) { public void setControlPoint(Point point, int index) {
controlPoints[index].setLocation(point); controlPoints[index].setLocation(point);
firstPoint.setLocation(Math.min(controlPoints[0].x, controlPoints[1].x), Math.min( firstPoint.setLocation(Math.min(controlPoints[0].x, controlPoints[1].x),
controlPoints[0].y, controlPoints[1].y)); Math.min(controlPoints[0].y, controlPoints[1].y));
secondPoint.setLocation(Math.max(controlPoints[0].x, controlPoints[1].x), Math.max( secondPoint.setLocation(Math.max(controlPoints[0].x, controlPoints[1].x),
controlPoints[0].y, controlPoints[1].y)); Math.max(controlPoints[0].y, controlPoints[1].y));
} }
@EditableProperty @EditableProperty
@@ -10,7 +10,9 @@ import org.diylc.core.Project;
import org.diylc.core.annotations.BomPolicy; import org.diylc.core.annotations.BomPolicy;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
@ComponentDescriptor(name = "Blank Board", category = "Boards", author = "Branislav Stojkovic", zOrder = IDIYComponent.BOARD, instanceNamePrefix = "Board", description = "Blank circuit board", bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false) @ComponentDescriptor(name = "Blank Board", category = "Boards", author = "Branislav Stojkovic",
zOrder = IDIYComponent.BOARD, instanceNamePrefix = "Board", description = "Blank circuit board",
bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false)
public class BlankBoard extends AbstractBoard { public class BlankBoard extends AbstractBoard {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -25,12 +27,10 @@ public class BlankBoard extends AbstractBoard {
} }
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
boolean outlineMode, Project project,
IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
Shape clip = g2d.getClip(); Shape clip = g2d.getClip();
if (checkPointsClipped(clip) if (checkPointsClipped(clip) && !clip.contains(firstPoint.x, secondPoint.y)
&& !clip.contains(firstPoint.x, secondPoint.y)
&& !clip.contains(secondPoint.x, firstPoint.y)) { && !clip.contains(secondPoint.x, firstPoint.y)) {
return; return;
} }
@@ -18,7 +18,9 @@ import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.measures.Size; import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Breadboard", category = "Boards", author = "Branislav Stojkovic", description = "Prototyping solderless breadboard", instanceNamePrefix = "BB", stretchable = false, zOrder = IDIYComponent.BOARD, bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false) @ComponentDescriptor(name = "Breadboard", category = "Boards", author = "Branislav Stojkovic",
description = "Prototyping solderless breadboard", instanceNamePrefix = "BB", stretchable = false,
zOrder = IDIYComponent.BOARD, bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false)
public class Breadboard extends AbstractComponent<Void> { public class Breadboard extends AbstractComponent<Void> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -41,8 +43,7 @@ public class Breadboard extends AbstractComponent<Void> {
protected Point point = new Point(0, 0); protected Point point = new Point(0, 0);
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
boolean outlineMode, Project project,
IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) { if (checkPointsClipped(g2d.getClip())) {
return; return;
@@ -56,8 +57,7 @@ public class Breadboard extends AbstractComponent<Void> {
int width = (int) (23 * project.getGridSpacing().convertToPixels()); int width = (int) (23 * project.getGridSpacing().convertToPixels());
int height = (int) (31 * project.getGridSpacing().convertToPixels()); int height = (int) (31 * project.getGridSpacing().convertToPixels());
g2d.fillRoundRect(point.x, point.y, width, height, bodyArc, bodyArc); g2d.fillRoundRect(point.x, point.y, width, height, bodyArc, bodyArc);
g2d.setColor(componentState == ComponentState.SELECTED g2d.setColor(componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: BORDER_COLOR); : BORDER_COLOR);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.drawRoundRect(point.x, point.y, width, height, bodyArc, bodyArc); g2d.drawRoundRect(point.x, point.y, width, height, bodyArc, bodyArc);
@@ -66,15 +66,15 @@ public class Breadboard extends AbstractComponent<Void> {
// draw lines // draw lines
g2d.setColor(PLUS_COLOR); g2d.setColor(PLUS_COLOR);
g2d.drawLine((int) (point.x + spacing), (int) (point.y + spacing), g2d.drawLine((int) (point.x + spacing), (int) (point.y + spacing), (int) (point.x + spacing),
(int) (point.x + spacing), (int) (point.y + 30 * spacing)); (int) (point.y + 30 * spacing));
g2d.drawLine((int) (point.x + 19 * spacing), (int) (point.y + spacing), g2d.drawLine((int) (point.x + 19 * spacing), (int) (point.y + spacing), (int) (point.x + 19 * spacing),
(int) (point.x + 19 * spacing), (int) (point.y + 30 * spacing)); (int) (point.y + 30 * spacing));
g2d.setColor(MINUS_COLOR); g2d.setColor(MINUS_COLOR);
g2d.drawLine((int) (point.x + 4 * spacing), (int) (point.y + spacing), g2d.drawLine((int) (point.x + 4 * spacing), (int) (point.y + spacing), (int) (point.x + 4 * spacing),
(int) (point.x + 4 * spacing), (int) (point.y + 30 * spacing)); (int) (point.y + 30 * spacing));
g2d.drawLine((int) (point.x + 22 * spacing), (int) (point.y + spacing), g2d.drawLine((int) (point.x + 22 * spacing), (int) (point.y + spacing), (int) (point.x + 22 * spacing),
(int) (point.x + 22 * spacing), (int) (point.y + 30 * spacing)); (int) (point.y + 30 * spacing));
int holeSize = getClosestOdd(HOLE_SIZE.convertToPixels()); int holeSize = getClosestOdd(HOLE_SIZE.convertToPixels());
int holeArc = (int) HOLE_ARC.convertToPixels(); int holeArc = (int) HOLE_ARC.convertToPixels();
@@ -94,33 +94,23 @@ public class Breadboard extends AbstractComponent<Void> {
} else { } else {
coordinateX = (int) (point.x + offset + 10.5 * spacing); coordinateX = (int) (point.x + offset + 10.5 * spacing);
} }
drawCenteredText(g2d, new Integer(y + 1).toString(), drawCenteredText(g2d, new Integer(y + 1).toString(), coordinateX, (int) (point.y + (y + 1) * spacing),
coordinateX, (int) (point.y + (y + 1) * spacing), section == 0 ? HorizontalAlignment.RIGHT : HorizontalAlignment.LEFT, VerticalAlignment.CENTER);
section == 0 ? HorizontalAlignment.RIGHT
: HorizontalAlignment.LEFT,
VerticalAlignment.CENTER);
for (int x = 0; x < 5; x++) { for (int x = 0; x < 5; x++) {
int holeX = (int) (point.x + offset + (x + 6) * spacing); int holeX = (int) (point.x + offset + (x + 6) * spacing);
int holeY = (int) (point.y + (y + 1) * spacing); int holeY = (int) (point.y + (y + 1) * spacing);
g2d.setColor(HOLE_COLOR); g2d.setColor(HOLE_COLOR);
g2d.fillRoundRect(holeX - holeSize / 2, holeY - holeSize g2d.fillRoundRect(holeX - holeSize / 2, holeY - holeSize / 2, holeSize, holeSize, holeArc, holeArc);
/ 2, holeSize, holeSize, holeArc, holeArc);
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.drawRoundRect(holeX - holeSize / 2, holeY - holeSize g2d.drawRoundRect(holeX - holeSize / 2, holeY - holeSize / 2, holeSize, holeSize, holeArc, holeArc);
/ 2, holeSize, holeSize, holeArc, holeArc);
// Draw horizontal labels // Draw horizontal labels
if (y == 0) { if (y == 0) {
g2d.setColor(COORDINATE_COLOR); g2d.setColor(COORDINATE_COLOR);
drawCenteredText(g2d, new String(new byte[] { (byte) (a drawCenteredText(g2d, new String(new byte[] {(byte) (a + x + 5 * section)}), holeX, (int) (point.y),
+ x + 5 * section) }), holeX, (int) (point.y), HorizontalAlignment.CENTER, VerticalAlignment.TOP);
HorizontalAlignment.CENTER, drawCenteredText(g2d, new String(new byte[] {(byte) (a + x + 5 * section)}), holeX, (int) (point.y
VerticalAlignment.TOP); + spacing * 30 + COORDINATE_FONT_SIZE / 2), HorizontalAlignment.CENTER, VerticalAlignment.TOP);
drawCenteredText(g2d, new String(new byte[] { (byte) (a
+ x + 5 * section) }), holeX, (int) (point.y
+ spacing * 30 + COORDINATE_FONT_SIZE / 2),
HorizontalAlignment.CENTER,
VerticalAlignment.TOP);
} }
} }
} }
@@ -136,11 +126,9 @@ public class Breadboard extends AbstractComponent<Void> {
int holeX = (int) (point.x + offset + (x + 2) * spacing); int holeX = (int) (point.x + offset + (x + 2) * spacing);
int holeY = (int) (point.y + (y + 1 + 0.5) * spacing); int holeY = (int) (point.y + (y + 1 + 0.5) * spacing);
g2d.setColor(HOLE_COLOR); g2d.setColor(HOLE_COLOR);
g2d.fillRoundRect(holeX - holeSize / 2, holeY - holeSize g2d.fillRoundRect(holeX - holeSize / 2, holeY - holeSize / 2, holeSize, holeSize, holeArc, holeArc);
/ 2, holeSize, holeSize, holeArc, holeArc);
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.drawRoundRect(holeX - holeSize / 2, holeY - holeSize g2d.drawRoundRect(holeX - holeSize / 2, holeY - holeSize / 2, holeSize, holeSize, holeArc, holeArc);
/ 2, holeSize, holeSize, holeArc, holeArc);
} }
} }
} }
@@ -151,51 +139,40 @@ public class Breadboard extends AbstractComponent<Void> {
int factor = 32 / width; int factor = 32 / width;
int arc = 4 / factor; int arc = 4 / factor;
g2d.setColor(FILL_COLOR); g2d.setColor(FILL_COLOR);
g2d.fillRect(2 / factor, 2 / factor, width - 4 / factor, height - 4 g2d.fillRect(2 / factor, 2 / factor, width - 4 / factor, height - 4 / factor);
/ factor);
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.drawRect(2 / factor, 2 / factor, width - 4 / factor, height - 4 g2d.drawRect(2 / factor, 2 / factor, width - 4 / factor, height - 4 / factor);
/ factor);
g2d.setColor(HOLE_COLOR); g2d.setColor(HOLE_COLOR);
g2d.fillRoundRect(width / 3 - 2 / factor, width / 3 - 2 / factor, g2d.fillRoundRect(width / 3 - 2 / factor, width / 3 - 2 / factor, getClosestOdd(5.0 / factor),
getClosestOdd(5.0 / factor), getClosestOdd(5.0 / factor), arc,
arc);
g2d.setColor(BORDER_COLOR);
g2d.drawRoundRect(width / 3 - 2 / factor, width / 3 - 2 / factor,
getClosestOdd(5.0 / factor), getClosestOdd(5.0 / factor), arc,
arc);
g2d.setColor(HOLE_COLOR);
g2d.fillRoundRect(2 * width / 3 - 2 / factor, width / 3 - 2 / factor,
getClosestOdd(5.0 / factor), getClosestOdd(5.0 / factor), arc,
arc);
g2d.setColor(BORDER_COLOR);
g2d.drawRoundRect(2 * width / 3 - 2 / factor, width / 3 - 2 / factor,
getClosestOdd(5.0 / factor), getClosestOdd(5.0 / factor), arc,
arc);
g2d.setColor(HOLE_COLOR);
g2d.fillRoundRect(width / 3 - 2 / factor, 2 * width / 3 - 2 / factor,
getClosestOdd(5.0 / factor), getClosestOdd(5.0 / factor), arc,
arc);
g2d.setColor(BORDER_COLOR);
g2d.drawRoundRect(width / 3 - 2 / factor, 2 * width / 3 - 2 / factor,
getClosestOdd(5.0 / factor), getClosestOdd(5.0 / factor), arc,
arc);
g2d.setColor(HOLE_COLOR);
g2d.fillRoundRect(2 * width / 3 - 2 / factor, 2 * width / 3 - 2
/ factor, getClosestOdd(5.0 / factor),
getClosestOdd(5.0 / factor), arc, arc); getClosestOdd(5.0 / factor), arc, arc);
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.drawRoundRect(2 * width / 3 - 2 / factor, 2 * width / 3 - 2 g2d.drawRoundRect(width / 3 - 2 / factor, width / 3 - 2 / factor, getClosestOdd(5.0 / factor),
/ factor, getClosestOdd(5.0 / factor), getClosestOdd(5.0 / factor), arc, arc);
g2d.setColor(HOLE_COLOR);
g2d.fillRoundRect(2 * width / 3 - 2 / factor, width / 3 - 2 / factor, getClosestOdd(5.0 / factor),
getClosestOdd(5.0 / factor), arc, arc);
g2d.setColor(BORDER_COLOR);
g2d.drawRoundRect(2 * width / 3 - 2 / factor, width / 3 - 2 / factor, getClosestOdd(5.0 / factor),
getClosestOdd(5.0 / factor), arc, arc);
g2d.setColor(HOLE_COLOR);
g2d.fillRoundRect(width / 3 - 2 / factor, 2 * width / 3 - 2 / factor, getClosestOdd(5.0 / factor),
getClosestOdd(5.0 / factor), arc, arc);
g2d.setColor(BORDER_COLOR);
g2d.drawRoundRect(width / 3 - 2 / factor, 2 * width / 3 - 2 / factor, getClosestOdd(5.0 / factor),
getClosestOdd(5.0 / factor), arc, arc);
g2d.setColor(HOLE_COLOR);
g2d.fillRoundRect(2 * width / 3 - 2 / factor, 2 * width / 3 - 2 / factor, getClosestOdd(5.0 / factor),
getClosestOdd(5.0 / factor), arc, arc);
g2d.setColor(BORDER_COLOR);
g2d.drawRoundRect(2 * width / 3 - 2 / factor, 2 * width / 3 - 2 / factor, getClosestOdd(5.0 / factor),
getClosestOdd(5.0 / factor), arc, arc); getClosestOdd(5.0 / factor), arc, arc);
g2d.setColor(MINUS_COLOR); g2d.setColor(MINUS_COLOR);
g2d.drawLine(width / 2, 2 / factor, width / 2, height - 4 g2d.drawLine(width / 2, 2 / factor, width / 2, height - 4 / factor);
/ factor);
} }
@Override @Override
@@ -229,8 +206,7 @@ public class Breadboard extends AbstractComponent<Void> {
} }
@Override @Override
public void setValue(Void value) { public void setValue(Void value) {}
}
@Deprecated @Deprecated
@Override @Override
@@ -17,7 +17,9 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Eyelet Board", category = "Boards", author = "Branislav Stojkovic", zOrder = IDIYComponent.BOARD, instanceNamePrefix = "Board", description = "Perforated board with eyelets", bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false) @ComponentDescriptor(name = "Eyelet Board", category = "Boards", author = "Branislav Stojkovic",
zOrder = IDIYComponent.BOARD, instanceNamePrefix = "Board", description = "Perforated board with eyelets",
bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false)
public class EyeletBoard extends AbstractBoard { public class EyeletBoard extends AbstractBoard {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -41,8 +43,8 @@ public class EyeletBoard extends AbstractBoard {
} }
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
Project project, IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
Shape clip = g2d.getClip(); Shape clip = g2d.getClip();
if (checkPointsClipped(clip) && !clip.contains(firstPoint.x, secondPoint.y) if (checkPointsClipped(clip) && !clip.contains(firstPoint.x, secondPoint.y)
&& !clip.contains(secondPoint.x, firstPoint.y)) { && !clip.contains(secondPoint.x, firstPoint.y)) {
@@ -51,8 +53,7 @@ public class EyeletBoard extends AbstractBoard {
super.draw(g2d, componentState, outlineMode, project, drawingObserver); super.draw(g2d, componentState, outlineMode, project, drawingObserver);
if (componentState != ComponentState.DRAGGING) { if (componentState != ComponentState.DRAGGING) {
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
/ MAX_ALPHA));
} }
Point p = new Point(firstPoint); Point p = new Point(firstPoint);
int diameter = getClosestOdd((int) EYELET_SIZE.convertToPixels()); int diameter = getClosestOdd((int) EYELET_SIZE.convertToPixels());
@@ -69,11 +70,9 @@ public class EyeletBoard extends AbstractBoard {
g2d.setColor(eyeletColor.darker()); g2d.setColor(eyeletColor.darker());
g2d.drawOval(p.x - diameter / 2, p.y - diameter / 2, diameter, diameter); g2d.drawOval(p.x - diameter / 2, p.y - diameter / 2, diameter, diameter);
g2d.setColor(Constants.CANVAS_COLOR); g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(p.x - holeDiameter / 2, p.y - holeDiameter / 2, holeDiameter, g2d.fillOval(p.x - holeDiameter / 2, p.y - holeDiameter / 2, holeDiameter, holeDiameter);
holeDiameter);
g2d.setColor(eyeletColor.darker()); g2d.setColor(eyeletColor.darker());
g2d.drawOval(p.x - holeDiameter / 2, p.y - holeDiameter / 2, holeDiameter, g2d.drawOval(p.x - holeDiameter / 2, p.y - holeDiameter / 2, holeDiameter, holeDiameter);
holeDiameter);
} }
} }
super.drawCoordinates(g2d, spacing); super.drawCoordinates(g2d, spacing);
@@ -110,8 +109,10 @@ public class EyeletBoard extends AbstractBoard {
g2d.setColor(EYELET_COLOR.darker()); g2d.setColor(EYELET_COLOR.darker());
g2d.drawOval(width / 4, width / 4, width / 2, width / 2); g2d.drawOval(width / 4, width / 4, width / 2, width / 2);
g2d.setColor(Constants.CANVAS_COLOR); g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(width / 2 - 2 / factor, width / 2 - 2 / factor, getClosestOdd(5.0 / factor), getClosestOdd(5.0 / factor)); g2d.fillOval(width / 2 - 2 / factor, width / 2 - 2 / factor, getClosestOdd(5.0 / factor),
getClosestOdd(5.0 / factor));
g2d.setColor(EYELET_COLOR.darker()); g2d.setColor(EYELET_COLOR.darker());
g2d.drawOval(width / 2 - 2 / factor, width / 2 - 2 / factor, getClosestOdd(5.0 / factor), getClosestOdd(5.0 / factor)); g2d.drawOval(width / 2 - 2 / factor, width / 2 - 2 / factor, getClosestOdd(5.0 / factor),
getClosestOdd(5.0 / factor));
} }
} }
@@ -17,7 +17,10 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Marshall Style Perf Board", category = "Boards", author = "Branislav Stojkovic", zOrder = IDIYComponent.BOARD, instanceNamePrefix = "Board", description = "Perforated board as found on some Marshall and Trainwreck amps", bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false) @ComponentDescriptor(name = "Marshall Style Perf Board", category = "Boards", author = "Branislav Stojkovic",
zOrder = IDIYComponent.BOARD, instanceNamePrefix = "Board",
description = "Perforated board as found on some Marshall and Trainwreck amps",
bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false)
public class MarshallPerfBoard extends AbstractBoard { public class MarshallPerfBoard extends AbstractBoard {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -37,20 +40,17 @@ public class MarshallPerfBoard extends AbstractBoard {
} }
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
boolean outlineMode, Project project,
IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
Shape clip = g2d.getClip(); Shape clip = g2d.getClip();
if (checkPointsClipped(clip) if (checkPointsClipped(clip) && !clip.contains(firstPoint.x, secondPoint.y)
&& !clip.contains(firstPoint.x, secondPoint.y)
&& !clip.contains(secondPoint.x, firstPoint.y)) { && !clip.contains(secondPoint.x, firstPoint.y)) {
return; return;
} }
super.draw(g2d, componentState, outlineMode, project, drawingObserver); super.draw(g2d, componentState, outlineMode, project, drawingObserver);
if (componentState != ComponentState.DRAGGING) { if (componentState != ComponentState.DRAGGING) {
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance( g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
} }
Point p = new Point(firstPoint); Point p = new Point(firstPoint);
int holeDiameter = getClosestOdd((int) HOLE_SIZE.convertToPixels()); int holeDiameter = getClosestOdd((int) HOLE_SIZE.convertToPixels());
@@ -62,11 +62,9 @@ public class MarshallPerfBoard extends AbstractBoard {
while (p.x < secondPoint.x - spacing - holeDiameter) { while (p.x < secondPoint.x - spacing - holeDiameter) {
p.x += spacing; p.x += spacing;
g2d.setColor(Constants.CANVAS_COLOR); g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(p.x - holeDiameter / 2, g2d.fillOval(p.x - holeDiameter / 2, p.y - holeDiameter / 2, holeDiameter, holeDiameter);
p.y - holeDiameter / 2, holeDiameter, holeDiameter);
g2d.setColor(borderColor); g2d.setColor(borderColor);
g2d.drawOval(p.x - holeDiameter / 2, g2d.drawOval(p.x - holeDiameter / 2, p.y - holeDiameter / 2, holeDiameter, holeDiameter);
p.y - holeDiameter / 2, holeDiameter, holeDiameter);
} }
} }
super.drawCoordinates(g2d, spacing); super.drawCoordinates(g2d, spacing);
@@ -86,38 +84,36 @@ public class MarshallPerfBoard extends AbstractBoard {
public void drawIcon(Graphics2D g2d, int width, int height) { public void drawIcon(Graphics2D g2d, int width, int height) {
int factor = 32 / width; int factor = 32 / width;
g2d.setColor(BOARD_COLOR); g2d.setColor(BOARD_COLOR);
g2d.fillRect(2 / factor, 2 / factor, width - 4 / factor, height - 4 g2d.fillRect(2 / factor, 2 / factor, width - 4 / factor, height - 4 / factor);
/ factor);
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.drawRect(2 / factor, 2 / factor, width - 4 / factor, height - 4 g2d.drawRect(2 / factor, 2 / factor, width - 4 / factor, height - 4 / factor);
/ factor);
g2d.setColor(Constants.CANVAS_COLOR); g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(width / 3 - 2 / factor, width / 3 - 2 / factor, g2d.fillOval(width / 3 - 2 / factor, width / 3 - 2 / factor, getClosestOdd(5.0 / factor),
getClosestOdd(5.0 / factor), getClosestOdd(5.0 / factor)); getClosestOdd(5.0 / factor));
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.drawOval(width / 3 - 2 / factor, width / 3 - 2 / factor, g2d.drawOval(width / 3 - 2 / factor, width / 3 - 2 / factor, getClosestOdd(5.0 / factor),
getClosestOdd(5.0 / factor), getClosestOdd(5.0 / factor)); getClosestOdd(5.0 / factor));
g2d.setColor(Constants.CANVAS_COLOR); g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(2 * width / 3 - 2 / factor, width / 3 - 2 / factor, g2d.fillOval(2 * width / 3 - 2 / factor, width / 3 - 2 / factor, getClosestOdd(5.0 / factor),
getClosestOdd(5.0 / factor), getClosestOdd(5.0 / factor)); getClosestOdd(5.0 / factor));
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.drawOval(2 * width / 3 - 2 / factor, width / 3 - 2 / factor, g2d.drawOval(2 * width / 3 - 2 / factor, width / 3 - 2 / factor, getClosestOdd(5.0 / factor),
getClosestOdd(5.0 / factor), getClosestOdd(5.0 / factor)); getClosestOdd(5.0 / factor));
g2d.setColor(Constants.CANVAS_COLOR); g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(width / 3 - 2 / factor, 2 * width / 3 - 2 / factor, g2d.fillOval(width / 3 - 2 / factor, 2 * width / 3 - 2 / factor, getClosestOdd(5.0 / factor),
getClosestOdd(5.0 / factor), getClosestOdd(5.0 / factor)); getClosestOdd(5.0 / factor));
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.drawOval(width / 3 - 2 / factor, 2 * width / 3 - 2 / factor, g2d.drawOval(width / 3 - 2 / factor, 2 * width / 3 - 2 / factor, getClosestOdd(5.0 / factor),
getClosestOdd(5.0 / factor), getClosestOdd(5.0 / factor)); getClosestOdd(5.0 / factor));
g2d.setColor(Constants.CANVAS_COLOR); g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(2 * width / 3 - 2 / factor, 2 * width / 3 - 2 / factor, g2d.fillOval(2 * width / 3 - 2 / factor, 2 * width / 3 - 2 / factor, getClosestOdd(5.0 / factor),
getClosestOdd(5.0 / factor), getClosestOdd(5.0 / factor)); getClosestOdd(5.0 / factor));
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.drawOval(2 * width / 3 - 2 / factor, 2 * width / 3 - 2 / factor, g2d.drawOval(2 * width / 3 - 2 / factor, 2 * width / 3 - 2 / factor, getClosestOdd(5.0 / factor),
getClosestOdd(5.0 / factor), getClosestOdd(5.0 / factor)); getClosestOdd(5.0 / factor));
} }
} }
@@ -17,7 +17,9 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; 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", bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false) @ComponentDescriptor(name = "Perf Board w/ Pads", category = "Boards", author = "Branislav Stojkovic",
zOrder = IDIYComponent.BOARD, instanceNamePrefix = "Board", description = "Perforated board with solder pads",
bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false)
public class PerfBoard extends AbstractBoard { public class PerfBoard extends AbstractBoard {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -33,20 +35,17 @@ public class PerfBoard extends AbstractBoard {
protected Color padColor = COPPER_COLOR; protected Color padColor = COPPER_COLOR;
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
boolean outlineMode, Project project,
IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
Shape clip = g2d.getClip(); Shape clip = g2d.getClip();
if (checkPointsClipped(clip) if (checkPointsClipped(clip) && !clip.contains(firstPoint.x, secondPoint.y)
&& !clip.contains(firstPoint.x, secondPoint.y)
&& !clip.contains(secondPoint.x, firstPoint.y)) { && !clip.contains(secondPoint.x, firstPoint.y)) {
return; return;
} }
super.draw(g2d, componentState, outlineMode, project, drawingObserver); super.draw(g2d, componentState, outlineMode, project, drawingObserver);
if (componentState != ComponentState.DRAGGING) { if (componentState != ComponentState.DRAGGING) {
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance( g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
} }
Point p = new Point(firstPoint); Point p = new Point(firstPoint);
int diameter = getClosestOdd((int) PAD_SIZE.convertToPixels()); int diameter = getClosestOdd((int) PAD_SIZE.convertToPixels());
@@ -59,17 +58,13 @@ public class PerfBoard extends AbstractBoard {
while (p.x < secondPoint.x - spacing - diameter) { while (p.x < secondPoint.x - spacing - diameter) {
p.x += spacing; p.x += spacing;
g2d.setColor(padColor); g2d.setColor(padColor);
g2d.fillOval(p.x - diameter / 2, p.y - diameter / 2, g2d.fillOval(p.x - diameter / 2, p.y - diameter / 2, diameter, diameter);
diameter, diameter);
g2d.setColor(padColor.darker()); g2d.setColor(padColor.darker());
g2d.drawOval(p.x - diameter / 2, p.y - diameter / 2, g2d.drawOval(p.x - diameter / 2, p.y - diameter / 2, diameter, diameter);
diameter, diameter);
g2d.setColor(Constants.CANVAS_COLOR); g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(p.x - holeDiameter / 2, g2d.fillOval(p.x - holeDiameter / 2, p.y - holeDiameter / 2, holeDiameter, holeDiameter);
p.y - holeDiameter / 2, holeDiameter, holeDiameter);
g2d.setColor(padColor.darker()); g2d.setColor(padColor.darker());
g2d.drawOval(p.x - holeDiameter / 2, g2d.drawOval(p.x - holeDiameter / 2, p.y - holeDiameter / 2, holeDiameter, holeDiameter);
p.y - holeDiameter / 2, holeDiameter, holeDiameter);
} }
} }
super.drawCoordinates(g2d, spacing); super.drawCoordinates(g2d, spacing);
@@ -98,20 +93,18 @@ public class PerfBoard extends AbstractBoard {
public void drawIcon(Graphics2D g2d, int width, int height) { public void drawIcon(Graphics2D g2d, int width, int height) {
int factor = 32 / width; int factor = 32 / width;
g2d.setColor(BOARD_COLOR); g2d.setColor(BOARD_COLOR);
g2d.fillRect(2 / factor, 2 / factor, width - 4 / factor, height - 4 g2d.fillRect(2 / factor, 2 / factor, width - 4 / factor, height - 4 / factor);
/ factor);
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.drawRect(2 / factor, 2 / factor, width - 4 / factor, height - 4 g2d.drawRect(2 / factor, 2 / factor, width - 4 / factor, height - 4 / factor);
/ factor);
g2d.setColor(COPPER_COLOR); g2d.setColor(COPPER_COLOR);
g2d.fillOval(width / 4, width / 4, width / 2, width / 2); g2d.fillOval(width / 4, width / 4, width / 2, width / 2);
g2d.setColor(COPPER_COLOR.darker()); g2d.setColor(COPPER_COLOR.darker());
g2d.drawOval(width / 4, width / 4, width / 2, width / 2); g2d.drawOval(width / 4, width / 4, width / 2, width / 2);
g2d.setColor(Constants.CANVAS_COLOR); g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(width / 2 - 2 / factor, width / 2 - 2 / factor, g2d.fillOval(width / 2 - 2 / factor, width / 2 - 2 / factor, getClosestOdd(5.0 / factor),
getClosestOdd(5.0 / factor), getClosestOdd(5.0 / factor)); getClosestOdd(5.0 / factor));
g2d.setColor(COPPER_COLOR.darker()); g2d.setColor(COPPER_COLOR.darker());
g2d.drawOval(width / 2 - 2 / factor, width / 2 - 2 / factor, g2d.drawOval(width / 2 - 2 / factor, width / 2 - 2 / factor, getClosestOdd(5.0 / factor),
getClosestOdd(5.0 / factor), getClosestOdd(5.0 / factor)); getClosestOdd(5.0 / factor));
} }
} }
@@ -18,7 +18,9 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "TriPad Board", category = "Boards", author = "Hauke Juhls", zOrder = IDIYComponent.BOARD, instanceNamePrefix = "Board", description = "Perforated FR4 board with copper strips connecting 3 holes in a row (aka TriPad Board)") @ComponentDescriptor(name = "TriPad Board", category = "Boards", author = "Hauke Juhls", zOrder = IDIYComponent.BOARD,
instanceNamePrefix = "Board",
description = "Perforated FR4 board with copper strips connecting 3 holes in a row (aka TriPad Board)")
public class TriPadBoard extends AbstractBoard { public class TriPadBoard extends AbstractBoard {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -37,12 +39,10 @@ public class TriPadBoard extends AbstractBoard {
protected OrientationHV orientation = OrientationHV.HORIZONTAL; protected OrientationHV orientation = OrientationHV.HORIZONTAL;
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
boolean outlineMode, Project project,
IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
Shape clip = g2d.getClip(); Shape clip = g2d.getClip();
if (checkPointsClipped(clip) if (checkPointsClipped(clip) && !clip.contains(firstPoint.x, secondPoint.y)
&& !clip.contains(firstPoint.x, secondPoint.y)
&& !clip.contains(secondPoint.x, firstPoint.y)) { && !clip.contains(secondPoint.x, firstPoint.y)) {
return; return;
} }
@@ -50,8 +50,7 @@ public class TriPadBoard extends AbstractBoard {
if (componentState != ComponentState.DRAGGING) { if (componentState != ComponentState.DRAGGING) {
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance( g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
} }
Point p = new Point(firstPoint); Point p = new Point(firstPoint);
int stripSize = getClosestOdd((int) STRIP_SIZE.convertToPixels()); int stripSize = getClosestOdd((int) STRIP_SIZE.convertToPixels());
@@ -69,19 +68,16 @@ public class TriPadBoard extends AbstractBoard {
int spacesToDraw = stripSpan; int spacesToDraw = stripSpan;
if (remainingSpace < (stripSize + (stripSpan * spacing))) { if (remainingSpace < (stripSize + (stripSpan * spacing))) {
spacesToDraw = (remainingSpace - stripSize) spacesToDraw = (remainingSpace - stripSize) / spacing;
/ spacing;
} }
g2d.setColor(stripColor); g2d.setColor(stripColor);
g2d.fillRect(p.x + spacing - stripSize / 2, p.y g2d.fillRect(p.x + spacing - stripSize / 2, p.y - stripSize / 2, spacing * (spacesToDraw - 1) + stripSize,
- stripSize / 2, spacing * (spacesToDraw - 1) stripSize);
+ stripSize, stripSize);
g2d.setColor(stripColor.darker()); g2d.setColor(stripColor.darker());
g2d.drawRect(p.x + spacing - stripSize / 2, p.y g2d.drawRect(p.x + spacing - stripSize / 2, p.y - stripSize / 2, spacing * (spacesToDraw - 1) + stripSize,
- stripSize / 2, spacing * (spacesToDraw - 1) stripSize);
+ stripSize, stripSize);
p.x += spacing * spacesToDraw; p.x += spacing * spacesToDraw;
} }
@@ -92,11 +88,9 @@ public class TriPadBoard extends AbstractBoard {
while (p.x < secondPoint.x - spacing - holeSize) { while (p.x < secondPoint.x - spacing - holeSize) {
p.x += spacing; p.x += spacing;
g2d.setColor(Constants.CANVAS_COLOR); g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(p.x - holeSize / 2, p.y - holeSize / 2, g2d.fillOval(p.x - holeSize / 2, p.y - holeSize / 2, holeSize, holeSize);
holeSize, holeSize);
g2d.setColor(stripColor.darker()); g2d.setColor(stripColor.darker());
g2d.drawOval(p.x - holeSize / 2, p.y - holeSize / 2, g2d.drawOval(p.x - holeSize / 2, p.y - holeSize / 2, holeSize, holeSize);
holeSize, holeSize);
} }
} }
} else { } else {
@@ -110,18 +104,15 @@ public class TriPadBoard extends AbstractBoard {
int spacesToDraw = stripSpan; int spacesToDraw = stripSpan;
if (remainingSpace < (stripSize + (stripSpan * spacing))) { if (remainingSpace < (stripSize + (stripSpan * spacing))) {
spacesToDraw = (remainingSpace - stripSize) spacesToDraw = (remainingSpace - stripSize) / spacing;
/ spacing;
} }
g2d.setColor(stripColor); g2d.setColor(stripColor);
g2d.fillRect(p.x - stripSize / 2, p.y + spacing g2d.fillRect(p.x - stripSize / 2, p.y + spacing - stripSize / 2, stripSize, spacing * (spacesToDraw - 1)
- stripSize / 2, stripSize, spacing + stripSize);
* (spacesToDraw - 1) + stripSize);
g2d.setColor(stripColor.darker()); g2d.setColor(stripColor.darker());
g2d.drawRect(p.x - stripSize / 2, p.y + spacing g2d.drawRect(p.x - stripSize / 2, p.y + spacing - stripSize / 2, stripSize, spacing * (spacesToDraw - 1)
- stripSize / 2, stripSize, spacing + stripSize);
* (spacesToDraw - 1) + stripSize);
p.y += spacing * spacesToDraw; p.y += spacing * spacesToDraw;
} }
@@ -132,11 +123,9 @@ public class TriPadBoard extends AbstractBoard {
while (p.y < secondPoint.y - spacing - holeSize) { while (p.y < secondPoint.y - spacing - holeSize) {
p.y += spacing; p.y += spacing;
g2d.setColor(Constants.CANVAS_COLOR); g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(p.x - holeSize / 2, p.y - holeSize / 2, g2d.fillOval(p.x - holeSize / 2, p.y - holeSize / 2, holeSize, holeSize);
holeSize, holeSize);
g2d.setColor(stripColor.darker()); g2d.setColor(stripColor.darker());
g2d.drawOval(p.x - holeSize / 2, p.y - holeSize / 2, g2d.drawOval(p.x - holeSize / 2, p.y - holeSize / 2, holeSize, holeSize);
holeSize, holeSize);
} }
} }
} }
@@ -184,15 +173,12 @@ public class TriPadBoard extends AbstractBoard {
for (int row = 0; row < 5; row++) { for (int row = 0; row < 5; row++) {
g2d.setColor(STRIP_COLOR); g2d.setColor(STRIP_COLOR);
g2d.fillRect(0, row * verticalSpacing + 2, horizontalIndent / 2 g2d.fillRect(0, row * verticalSpacing + 2, horizontalIndent / 2 + horizontalSpacing, verticalSpacing - 1);
+ horizontalSpacing, verticalSpacing - 1);
g2d.setColor(STRIP_COLOR); g2d.setColor(STRIP_COLOR);
g2d.fillRect(horizontalSpacing + 2, row * verticalSpacing + 2, g2d.fillRect(horizontalSpacing + 2, row * verticalSpacing + 2, horizontalSpacing * 3 - 1, verticalSpacing - 1);
horizontalSpacing * 3 - 1, verticalSpacing - 1);
g2d.fillRect(horizontalSpacing * 4 + 2, row * verticalSpacing + 2, g2d.fillRect(horizontalSpacing * 4 + 2, row * verticalSpacing + 2, horizontalIndent / 2 + horizontalSpacing,
horizontalIndent / 2 + horizontalSpacing,
verticalSpacing - 1); verticalSpacing - 1);
} }
@@ -19,7 +19,10 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; 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", bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false) @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",
bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false)
public class VeroBoard extends AbstractBoard { public class VeroBoard extends AbstractBoard {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -36,12 +39,10 @@ public class VeroBoard extends AbstractBoard {
protected OrientationHV orientation = OrientationHV.HORIZONTAL; protected OrientationHV orientation = OrientationHV.HORIZONTAL;
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
boolean outlineMode, Project project,
IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
Shape clip = g2d.getClip(); Shape clip = g2d.getClip();
if (checkPointsClipped(clip) if (checkPointsClipped(clip) && !clip.contains(firstPoint.x, secondPoint.y)
&& !clip.contains(firstPoint.x, secondPoint.y)
&& !clip.contains(secondPoint.x, firstPoint.y)) { && !clip.contains(secondPoint.x, firstPoint.y)) {
return; return;
} }
@@ -49,8 +50,7 @@ public class VeroBoard extends AbstractBoard {
if (componentState != ComponentState.DRAGGING) { if (componentState != ComponentState.DRAGGING) {
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance( g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
} }
Point p = new Point(firstPoint); Point p = new Point(firstPoint);
int stripSize = getClosestOdd((int) STRIP_SIZE.convertToPixels()); int stripSize = getClosestOdd((int) STRIP_SIZE.convertToPixels());
@@ -62,19 +62,15 @@ public class VeroBoard extends AbstractBoard {
p.x = firstPoint.x; p.x = firstPoint.x;
p.y += spacing; p.y += spacing;
g2d.setColor(stripColor); g2d.setColor(stripColor);
g2d.fillRect(p.x + spacing / 2, p.y - stripSize / 2, g2d.fillRect(p.x + spacing / 2, p.y - stripSize / 2, secondPoint.x - spacing - p.x, stripSize);
secondPoint.x - spacing - p.x, stripSize);
g2d.setColor(stripColor.darker()); g2d.setColor(stripColor.darker());
g2d.drawRect(p.x + spacing / 2, p.y - stripSize / 2, g2d.drawRect(p.x + spacing / 2, p.y - stripSize / 2, secondPoint.x - spacing - p.x, stripSize);
secondPoint.x - spacing - p.x, stripSize);
while (p.x < secondPoint.x - spacing - holeSize) { while (p.x < secondPoint.x - spacing - holeSize) {
p.x += spacing; p.x += spacing;
g2d.setColor(Constants.CANVAS_COLOR); g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(p.x - holeSize / 2, p.y - holeSize / 2, g2d.fillOval(p.x - holeSize / 2, p.y - holeSize / 2, holeSize, holeSize);
holeSize, holeSize);
g2d.setColor(stripColor.darker()); g2d.setColor(stripColor.darker());
g2d.drawOval(p.x - holeSize / 2, p.y - holeSize / 2, g2d.drawOval(p.x - holeSize / 2, p.y - holeSize / 2, holeSize, holeSize);
holeSize, holeSize);
} }
} }
} else { } else {
@@ -82,19 +78,15 @@ public class VeroBoard extends AbstractBoard {
p.x += spacing; p.x += spacing;
p.y = firstPoint.y; p.y = firstPoint.y;
g2d.setColor(stripColor); g2d.setColor(stripColor);
g2d.fillRect(p.x - stripSize / 2, p.y + spacing / 2, g2d.fillRect(p.x - stripSize / 2, p.y + spacing / 2, stripSize, secondPoint.y - spacing - p.y);
stripSize, secondPoint.y - spacing - p.y);
g2d.setColor(stripColor.darker()); g2d.setColor(stripColor.darker());
g2d.drawRect(p.x - stripSize / 2, p.y + spacing / 2, g2d.drawRect(p.x - stripSize / 2, p.y + spacing / 2, stripSize, secondPoint.y - spacing - p.y);
stripSize, secondPoint.y - spacing - p.y);
while (p.y < secondPoint.y - spacing - holeSize) { while (p.y < secondPoint.y - spacing - holeSize) {
p.y += spacing; p.y += spacing;
g2d.setColor(Constants.CANVAS_COLOR); g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(p.x - holeSize / 2, p.y - holeSize / 2, g2d.fillOval(p.x - holeSize / 2, p.y - holeSize / 2, holeSize, holeSize);
holeSize, holeSize);
g2d.setColor(stripColor.darker()); g2d.setColor(stripColor.darker());
g2d.drawOval(p.x - holeSize / 2, p.y - holeSize / 2, g2d.drawOval(p.x - holeSize / 2, p.y - holeSize / 2, holeSize, holeSize);
holeSize, holeSize);
} }
} }
} }
@@ -134,24 +126,22 @@ public class VeroBoard extends AbstractBoard {
public void drawIcon(Graphics2D g2d, int width, int height) { public void drawIcon(Graphics2D g2d, int width, int height) {
int factor = 32 / width; int factor = 32 / width;
g2d.setColor(BOARD_COLOR); g2d.setColor(BOARD_COLOR);
g2d.fillRect(2 / factor, 2 / factor, width - 4 / factor, height - 4 g2d.fillRect(2 / factor, 2 / factor, width - 4 / factor, height - 4 / factor);
/ factor);
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.drawRect(2 / factor, 2 / factor, width - 4 / factor, height - 4 g2d.drawRect(2 / factor, 2 / factor, width - 4 / factor, height - 4 / factor);
/ factor);
g2d.setColor(STRIP_COLOR); g2d.setColor(STRIP_COLOR);
g2d.fillRect(4 / factor, width / 4, width - 8 / factor, width / 2); g2d.fillRect(4 / factor, width / 4, width - 8 / factor, width / 2);
g2d.setColor(STRIP_COLOR.darker()); g2d.setColor(STRIP_COLOR.darker());
g2d.drawRect(4 / factor, width / 4, width - 8 / factor, width / 2); g2d.drawRect(4 / factor, width / 4, width - 8 / factor, width / 2);
g2d.setColor(Constants.CANVAS_COLOR); g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(width / 3 - 2 / factor, width / 2 - 2 / factor, g2d.fillOval(width / 3 - 2 / factor, width / 2 - 2 / factor, getClosestOdd(5.0 / factor),
getClosestOdd(5.0 / factor), getClosestOdd(5.0 / factor)); getClosestOdd(5.0 / factor));
g2d.fillOval(2 * width / 3 - 2 / factor, width / 2 - 2 / factor, g2d.fillOval(2 * width / 3 - 2 / factor, width / 2 - 2 / factor, getClosestOdd(5.0 / factor),
getClosestOdd(5.0 / factor), getClosestOdd(5.0 / factor)); getClosestOdd(5.0 / factor));
g2d.setColor(STRIP_COLOR.darker()); g2d.setColor(STRIP_COLOR.darker());
g2d.drawOval(width / 3 - 2 / factor, width / 2 - 2 / factor, g2d.drawOval(width / 3 - 2 / factor, width / 2 - 2 / factor, getClosestOdd(5.0 / factor),
getClosestOdd(5.0 / factor), getClosestOdd(5.0 / factor)); getClosestOdd(5.0 / factor));
g2d.drawOval(2 * width / 3 - 2 / factor, width / 2 - 2 / factor, g2d.drawOval(2 * width / 3 - 2 / factor, width / 2 - 2 / factor, getClosestOdd(5.0 / factor),
getClosestOdd(5.0 / factor), getClosestOdd(5.0 / factor)); getClosestOdd(5.0 / factor));
} }
} }
@@ -17,7 +17,10 @@ import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size; import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; 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, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false) @ComponentDescriptor(name = "Copper Trace", author = "Branislav Stojkovic", category = "Connectivity",
creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "Trace",
description = "Straight copper trace", zOrder = IDIYComponent.TRACE, bomPolicy = BomPolicy.NEVER_SHOW,
autoEdit = false)
public class CopperTrace extends AbstractLeadedComponent<Void> { public class CopperTrace extends AbstractLeadedComponent<Void> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -42,8 +45,8 @@ public class CopperTrace extends AbstractLeadedComponent<Void> {
@Override @Override
protected Color getLeadColorForPainting(ComponentState componentState) { protected Color getLeadColorForPainting(ComponentState componentState) {
return componentState == ComponentState.SELECTED return componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : getLeadColor(); : getLeadColor();
} }
@Override @Override
@@ -118,8 +121,7 @@ public class CopperTrace extends AbstractLeadedComponent<Void> {
} }
@Override @Override
public void setValue(Void value) { public void setValue(Void value) {}
}
@Override @Override
protected Shape getBodyShape() { protected Shape getBodyShape() {
@@ -15,7 +15,9 @@ import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size; import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; 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, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false) @ComponentDescriptor(name = "Curved Trace", author = "Branislav Stojkovic", category = "Connectivity",
instanceNamePrefix = "Trace", description = "Curved copper trace with two control points",
zOrder = IDIYComponent.TRACE, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false)
public class CurvedTrace extends AbstractCurvedComponent<Void> { public class CurvedTrace extends AbstractCurvedComponent<Void> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -35,8 +37,9 @@ public class CurvedTrace extends AbstractCurvedComponent<Void> {
protected void drawCurve(CubicCurve2D curve, Graphics2D g2d, ComponentState componentState) { protected void drawCurve(CubicCurve2D curve, Graphics2D g2d, ComponentState componentState) {
int thickness = (int) size.convertToPixels(); int thickness = (int) size.convertToPixels();
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(thickness)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(thickness));
Color curveColor = componentState == ComponentState.SELECTED Color curveColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : color; componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: color;
g2d.setColor(curveColor); g2d.setColor(curveColor);
g2d.draw(curve); g2d.draw(curve);
} }
@@ -68,8 +71,7 @@ public class CurvedTrace extends AbstractCurvedComponent<Void> {
} }
@Override @Override
public void setValue(Void value) { public void setValue(Void value) {}
}
@Override @Override
public Byte getAlpha() { public Byte getAlpha() {
@@ -17,7 +17,9 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Dot", category = "Connectivity", author = "Branislav Stojkovic", description = "Connector dot", instanceNamePrefix = "Dot", stretchable = false, zOrder = IDIYComponent.COMPONENT, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false) @ComponentDescriptor(name = "Dot", category = "Connectivity", author = "Branislav Stojkovic",
description = "Connector dot", instanceNamePrefix = "Dot", stretchable = false, zOrder = IDIYComponent.COMPONENT,
bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false)
public class Dot extends AbstractComponent<Void> { public class Dot extends AbstractComponent<Void> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -30,26 +32,22 @@ public class Dot extends AbstractComponent<Void> {
private Point point = new Point(0, 0); private Point point = new Point(0, 0);
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
boolean outlineMode, Project project,
IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) { if (checkPointsClipped(g2d.getClip())) {
return; return;
} }
int diameter = getClosestOdd((int) getSize().convertToPixels()); int diameter = getClosestOdd((int) getSize().convertToPixels());
g2d.setColor(componentState == ComponentState.SELECTED g2d.setColor(componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: color); : color);
g2d.fillOval(point.x - diameter / 2, point.y - diameter / 2, diameter, g2d.fillOval(point.x - diameter / 2, point.y - diameter / 2, diameter, diameter);
diameter);
} }
@Override @Override
public void drawIcon(Graphics2D g2d, int width, int height) { public void drawIcon(Graphics2D g2d, int width, int height) {
int diameter = 7 * width / 32; int diameter = 7 * width / 32;
g2d.setColor(COLOR); g2d.setColor(COLOR);
g2d.fillOval((width - diameter) / 2, (height - diameter) / 2, diameter, g2d.fillOval((width - diameter) / 2, (height - diameter) / 2, diameter, diameter);
diameter);
} }
@EditableProperty @EditableProperty
@@ -106,6 +104,5 @@ public class Dot extends AbstractComponent<Void> {
} }
@Override @Override
public void setValue(Void value) { public void setValue(Void value) {}
}
} }
@@ -17,7 +17,9 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Eyelet", category = "Connectivity", author = "Branislav Stojkovic", description = "Eyelet or turret terminal", instanceNamePrefix = "Eyelet", stretchable = false, zOrder = IDIYComponent.TRACE + 0.1, bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false) @ComponentDescriptor(name = "Eyelet", category = "Connectivity", author = "Branislav Stojkovic",
description = "Eyelet or turret terminal", instanceNamePrefix = "Eyelet", stretchable = false,
zOrder = IDIYComponent.TRACE + 0.1, bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false)
public class Eyelet extends AbstractComponent<String> { public class Eyelet extends AbstractComponent<String> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -33,8 +35,8 @@ public class Eyelet extends AbstractComponent<String> {
private String value = ""; private String value = "";
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
Project project, IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) { if (checkPointsClipped(g2d.getClip())) {
return; return;
} }
@@ -42,16 +44,14 @@ public class Eyelet extends AbstractComponent<String> {
int holeDiameter = getClosestOdd((int) holeSize.convertToPixels()); int holeDiameter = getClosestOdd((int) holeSize.convertToPixels());
g2d.setColor(color); g2d.setColor(color);
g2d.fillOval(point.x - diameter / 2, point.y - diameter / 2, diameter, diameter); g2d.fillOval(point.x - diameter / 2, point.y - diameter / 2, diameter, diameter);
g2d.setColor(componentState == ComponentState.SELECTED g2d.setColor(componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : color.darker()); : color.darker());
g2d.drawOval(point.x - diameter / 2, point.y - diameter / 2, diameter, diameter); g2d.drawOval(point.x - diameter / 2, point.y - diameter / 2, diameter, diameter);
g2d.setColor(Constants.CANVAS_COLOR); g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(point.x - holeDiameter / 2, point.y - holeDiameter / 2, holeDiameter, g2d.fillOval(point.x - holeDiameter / 2, point.y - holeDiameter / 2, holeDiameter, holeDiameter);
holeDiameter); g2d.setColor(componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
g2d.setColor(componentState == ComponentState.SELECTED : color.darker());
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : color.darker()); g2d.drawOval(point.x - holeDiameter / 2, point.y - holeDiameter / 2, holeDiameter, holeDiameter);
g2d.drawOval(point.x - holeDiameter / 2, point.y - holeDiameter / 2, holeDiameter,
holeDiameter);
} }
@Override @Override
@@ -63,11 +63,9 @@ public class Eyelet extends AbstractComponent<String> {
g2d.setColor(COLOR.darker()); g2d.setColor(COLOR.darker());
g2d.drawOval((width - diameter) / 2, (height - diameter) / 2, diameter, diameter); g2d.drawOval((width - diameter) / 2, (height - diameter) / 2, diameter, diameter);
g2d.setColor(Constants.CANVAS_COLOR); g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval((width - holeDiameter) / 2, (height - holeDiameter) / 2, holeDiameter, g2d.fillOval((width - holeDiameter) / 2, (height - holeDiameter) / 2, holeDiameter, holeDiameter);
holeDiameter);
g2d.setColor(COLOR.darker()); g2d.setColor(COLOR.darker());
g2d.drawOval((width - holeDiameter) / 2, (height - holeDiameter) / 2, holeDiameter, g2d.drawOval((width - holeDiameter) / 2, (height - holeDiameter) / 2, holeDiameter, holeDiameter);
holeDiameter);
} }
@EditableProperty @EditableProperty
@@ -19,7 +19,9 @@ import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size; import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Ground Fill", author = "Branislav Stojkovic", category = "Connectivity", instanceNamePrefix = "GF", description = "Polygonal ground fill area", zOrder = IDIYComponent.TRACE, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false) @ComponentDescriptor(name = "Ground Fill", author = "Branislav Stojkovic", category = "Connectivity",
instanceNamePrefix = "GF", description = "Polygonal ground fill area", zOrder = IDIYComponent.TRACE,
bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false)
public class GroundFill extends AbstractComponent<Void> { public class GroundFill extends AbstractComponent<Void> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -28,11 +30,8 @@ public class GroundFill extends AbstractComponent<Void> {
public static Size DEFAULT_WIDTH = new Size(1.5d, SizeUnit.in); public static Size DEFAULT_WIDTH = new Size(1.5d, SizeUnit.in);
public static Size DEFAULT_HEIGHT = new Size(1.2d, SizeUnit.in); public static Size DEFAULT_HEIGHT = new Size(1.2d, SizeUnit.in);
protected Point[] controlPoints = new Point[] { protected Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, (int) DEFAULT_HEIGHT.convertToPixels()),
new Point(0, 0), new Point((int) DEFAULT_WIDTH.convertToPixels(), (int) DEFAULT_HEIGHT.convertToPixels()),
new Point(0, (int) DEFAULT_HEIGHT.convertToPixels()),
new Point((int) DEFAULT_WIDTH.convertToPixels(),
(int) DEFAULT_HEIGHT.convertToPixels()),
new Point((int) DEFAULT_WIDTH.convertToPixels(), 0)}; new Point((int) DEFAULT_WIDTH.convertToPixels(), 0)};
protected Color color = COLOR; protected Color color = COLOR;
@@ -40,12 +39,11 @@ public class GroundFill extends AbstractComponent<Void> {
private PCBLayer layer = PCBLayer._1; private PCBLayer layer = PCBLayer._1;
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
boolean outlineMode, Project project,
IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
Color fillColor = componentState == ComponentState.SELECTED Color fillColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: color; : color;
g2d.setColor(fillColor); g2d.setColor(fillColor);
int[] xPoints = new int[controlPoints.length]; int[] xPoints = new int[controlPoints.length];
@@ -108,8 +106,8 @@ public class GroundFill extends AbstractComponent<Void> {
if (oldPointCount < newPointCount) { if (oldPointCount < newPointCount) {
this.controlPoints[newPointCount - 1] = this.controlPoints[oldPointCount - 1]; this.controlPoints[newPointCount - 1] = this.controlPoints[oldPointCount - 1];
for (int i = oldPointCount - 1; i < newPointCount - 1; i++) { for (int i = oldPointCount - 1; i < newPointCount - 1; i++) {
this.controlPoints[i] = new Point( this.controlPoints[i] =
(this.controlPoints[i - 1].x + this.controlPoints[newPointCount - 1].x) / 2, new Point((this.controlPoints[i - 1].x + this.controlPoints[newPointCount - 1].x) / 2,
(this.controlPoints[i - 1].y + this.controlPoints[newPointCount - 1].y) / 2); (this.controlPoints[i - 1].y + this.controlPoints[newPointCount - 1].y) / 2);
} }
} }
@@ -137,8 +135,7 @@ public class GroundFill extends AbstractComponent<Void> {
@Deprecated @Deprecated
@Override @Override
public void setValue(Void value) { public void setValue(Void value) {}
}
@Override @Override
public void drawIcon(Graphics2D g2d, int width, int height) { public void drawIcon(Graphics2D g2d, int width, int height) {
@@ -13,7 +13,9 @@ import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
import org.diylc.utils.Constants; 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, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false) @ComponentDescriptor(name = "Hookup Wire", author = "Branislav Stojkovic", category = "Connectivity",
instanceNamePrefix = "W", description = "Flexible wire with two control points", zOrder = IDIYComponent.COMPONENT,
bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false)
public class HookupWire extends AbstractCurvedComponent<Void> { public class HookupWire extends AbstractCurvedComponent<Void> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -29,21 +31,18 @@ public class HookupWire extends AbstractCurvedComponent<Void> {
} }
@Override @Override
protected void drawCurve(CubicCurve2D curve, Graphics2D g2d, protected void drawCurve(CubicCurve2D curve, Graphics2D g2d, ComponentState componentState) {
ComponentState componentState) { int thickness =
int thickness = (int) (Math.pow(Math.E, -1.12436 - 0.11594 (int) (Math.pow(Math.E, -1.12436 - 0.11594 * gauge.getValue()) * Constants.PIXELS_PER_INCH * (1 + 2 * INSULATION_THICKNESS_PCT));
* gauge.getValue()) Color curveColor =
* Constants.PIXELS_PER_INCH * (1 + 2 * INSULATION_THICKNESS_PCT)); componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
Color curveColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: color.darker(); : color.darker();
g2d.setColor(curveColor); g2d.setColor(curveColor);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(thickness)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(thickness));
g2d.draw(curve); g2d.draw(curve);
if (componentState == ComponentState.NORMAL) { if (componentState == ComponentState.NORMAL) {
g2d.setColor(color); g2d.setColor(color);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke( g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(thickness - 2));
thickness - 2));
g2d.draw(curve); g2d.draw(curve);
} }
} }
@@ -63,6 +62,5 @@ public class HookupWire extends AbstractCurvedComponent<Void> {
} }
@Override @Override
public void setValue(Void value) { public void setValue(Void value) {}
}
} }
@@ -15,7 +15,9 @@ import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size; 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, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false) @ComponentDescriptor(name = "Jumper", author = "Branislav Stojkovic", category = "Connectivity",
creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "J", description = "",
zOrder = IDIYComponent.COMPONENT, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false)
public class Jumper extends AbstractLeadedComponent<Void> { public class Jumper extends AbstractLeadedComponent<Void> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -42,8 +44,8 @@ public class Jumper extends AbstractLeadedComponent<Void> {
@Override @Override
public Color getLeadColorForPainting(ComponentState componentState) { public Color getLeadColorForPainting(ComponentState componentState) {
return componentState == ComponentState.SELECTED return componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : getLeadColor(); : getLeadColor();
} }
@Override @Override
@@ -85,8 +87,7 @@ public class Jumper extends AbstractLeadedComponent<Void> {
} }
@Override @Override
public void setValue(Void value) { public void setValue(Void value) {}
}
@Override @Override
protected Shape getBodyShape() { protected Shape getBodyShape() {
@@ -17,7 +17,9 @@ import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size; import org.diylc.core.measures.Size;
@ComponentDescriptor(name = "Line", author = "Branislav Stojkovic", category = "Shapes", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "LN", description = "", zOrder = IDIYComponent.COMPONENT, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false) @ComponentDescriptor(name = "Line", author = "Branislav Stojkovic", category = "Shapes",
creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "LN", description = "",
zOrder = IDIYComponent.COMPONENT, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false)
public class Line extends AbstractLeadedComponent<Void> { public class Line extends AbstractLeadedComponent<Void> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -34,18 +36,17 @@ public class Line extends AbstractLeadedComponent<Void> {
} }
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
Project project, IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.setColor(color); g2d.setColor(color);
g2d.drawLine(getControlPoint(0).x, getControlPoint(0).y, getControlPoint(1).x, g2d.drawLine(getControlPoint(0).x, getControlPoint(0).y, getControlPoint(1).x, getControlPoint(1).y);
getControlPoint(1).y);
} }
@Override @Override
public Color getLeadColorForPainting(ComponentState componentState) { public Color getLeadColorForPainting(ComponentState componentState) {
return componentState == ComponentState.SELECTED return componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : color; : color;
} }
@Override @Override
@@ -92,8 +93,7 @@ public class Line extends AbstractLeadedComponent<Void> {
} }
@Override @Override
public void setValue(Void value) { public void setValue(Void value) {}
}
@Override @Override
protected Shape getBodyShape() { protected Shape getBodyShape() {
@@ -18,7 +18,9 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Solder Pad", category = "Connectivity", author = "Branislav Stojkovic", description = "Copper solder pad, round or square", instanceNamePrefix = "Pad", stretchable = false, zOrder = IDIYComponent.TRACE + 0.1, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false) @ComponentDescriptor(name = "Solder Pad", category = "Connectivity", author = "Branislav Stojkovic",
description = "Copper solder pad, round or square", instanceNamePrefix = "Pad", stretchable = false,
zOrder = IDIYComponent.TRACE + 0.1, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false)
public class SolderPad extends AbstractComponent<Void> { public class SolderPad extends AbstractComponent<Void> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -35,28 +37,23 @@ public class SolderPad extends AbstractComponent<Void> {
private PCBLayer layer = PCBLayer._1; private PCBLayer layer = PCBLayer._1;
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
boolean outlineMode, Project project,
IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) { if (checkPointsClipped(g2d.getClip())) {
return; return;
} }
int diameter = getClosestOdd((int) getSize().convertToPixels()); int diameter = getClosestOdd((int) getSize().convertToPixels());
int holeDiameter = getClosestOdd((int) getHoleSize().convertToPixels()); int holeDiameter = getClosestOdd((int) getHoleSize().convertToPixels());
g2d.setColor(componentState == ComponentState.SELECTED g2d.setColor(componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: color); : color);
if (type == Type.ROUND) { if (type == Type.ROUND) {
g2d.fillOval(point.x - diameter / 2, point.y - diameter / 2, g2d.fillOval(point.x - diameter / 2, point.y - diameter / 2, diameter, diameter);
diameter, diameter);
} else { } else {
g2d.fillRect(point.x - diameter / 2, point.y - diameter / 2, g2d.fillRect(point.x - diameter / 2, point.y - diameter / 2, diameter, diameter);
diameter, diameter);
} }
if (getHoleSize().getValue() > 0) { if (getHoleSize().getValue() > 0) {
g2d.setColor(Constants.CANVAS_COLOR); g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(point.x - holeDiameter / 2, g2d.fillOval(point.x - holeDiameter / 2, point.y - holeDiameter / 2, holeDiameter, holeDiameter);
point.y - holeDiameter / 2, holeDiameter, holeDiameter);
} }
} }
@@ -65,11 +62,9 @@ public class SolderPad extends AbstractComponent<Void> {
int diameter = getClosestOdd(width / 2); int diameter = getClosestOdd(width / 2);
int holeDiameter = 5; int holeDiameter = 5;
g2d.setColor(COLOR); g2d.setColor(COLOR);
g2d.fillOval((width - diameter) / 2, (height - diameter) / 2, diameter, g2d.fillOval((width - diameter) / 2, (height - diameter) / 2, diameter, diameter);
diameter);
g2d.setColor(Constants.CANVAS_COLOR); g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval((width - holeDiameter) / 2, (height - holeDiameter) / 2, g2d.fillOval((width - holeDiameter) / 2, (height - holeDiameter) / 2, holeDiameter, holeDiameter);
holeDiameter, holeDiameter);
} }
@EditableProperty @EditableProperty
@@ -159,8 +154,7 @@ public class SolderPad extends AbstractComponent<Void> {
} }
@Override @Override
public void setValue(Void value) { public void setValue(Void value) {}
}
static enum Type { static enum Type {
ROUND, SQUARE; ROUND, SQUARE;
@@ -19,7 +19,9 @@ import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size; import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; 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, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false) @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, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false)
public class TraceCut extends AbstractComponent<Void> { public class TraceCut extends AbstractComponent<Void> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -40,8 +42,7 @@ public class TraceCut extends AbstractComponent<Void> {
protected Point point = new Point(0, 0); protected Point point = new Point(0, 0);
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
boolean outlineMode, Project project,
IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) { if (checkPointsClipped(g2d.getClip())) {
return; return;
@@ -50,24 +51,18 @@ public class TraceCut extends AbstractComponent<Void> {
int cutWidth = getClosestOdd((int) CUT_WIDTH.convertToPixels()); int cutWidth = getClosestOdd((int) CUT_WIDTH.convertToPixels());
if (getCutBetweenHoles()) { if (getCutBetweenHoles()) {
int holeSpacing = getClosestOdd(getHoleSpacing().convertToPixels()); int holeSpacing = getClosestOdd(getHoleSpacing().convertToPixels());
g2d g2d.setColor(componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: boardColor); : boardColor);
g2d.fillRect(point.x - holeSpacing / 2 - cutWidth / 2, point.y - size / 2 - 1, g2d.fillRect(point.x - holeSpacing / 2 - cutWidth / 2, point.y - size / 2 - 1, cutWidth, size + 2);
cutWidth, size + 2);
} else { } else {
int dotDiameter = size - 6; int dotDiameter = size - 6;
g2d.setColor(fillColor); g2d.setColor(fillColor);
g2d.fillRect(point.x - size / 2, point.y - size / 2, size, size); g2d.fillRect(point.x - size / 2, point.y - size / 2, size, size);
g2d g2d.setColor(componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: borderColor); : borderColor);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.drawRect(point.x - size / 2, point.y - size / 2, size, size); g2d.drawRect(point.x - size / 2, point.y - size / 2, size, size);
g2d.fillOval(point.x - dotDiameter / 2, point.y - dotDiameter / 2, g2d.fillOval(point.x - dotDiameter / 2, point.y - dotDiameter / 2, dotDiameter, dotDiameter);
dotDiameter, dotDiameter);
} }
} }
@@ -80,8 +75,7 @@ public class TraceCut extends AbstractComponent<Void> {
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.drawRect((width - size) / 2, (height - size) / 2, size, size); g2d.drawRect((width - size) / 2, (height - size) / 2, size, size);
g2d.fillOval((width - dotDiameter) / 2, (height - dotDiameter) / 2, g2d.fillOval((width - dotDiameter) / 2, (height - dotDiameter) / 2, dotDiameter, dotDiameter);
dotDiameter, dotDiameter);
} }
@Override @Override
@@ -115,8 +109,7 @@ public class TraceCut extends AbstractComponent<Void> {
} }
@Override @Override
public void setValue(Void value) { public void setValue(Void value) {}
}
@EditableProperty @EditableProperty
public Size getSize() { public Size getSize() {
@@ -29,7 +29,9 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "9V Battery Snap", category = "Electromechanical", author = "Branislav Stojkovic", description = "", stretchable = false, zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "BTR", autoEdit = false) @ComponentDescriptor(name = "9V Battery Snap", category = "Electromechanical", author = "Branislav Stojkovic",
description = "", stretchable = false, zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "BTR",
autoEdit = false)
public class BatterySnap9V extends AbstractTransparentComponent<String> { public class BatterySnap9V extends AbstractTransparentComponent<String> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -48,16 +50,15 @@ public class BatterySnap9V extends AbstractTransparentComponent<String> {
private Color color = BODY_COLOR; private Color color = BODY_COLOR;
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
Project project, IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
Shape[] body = getBody(); Shape[] body = getBody();
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
if (componentState != ComponentState.DRAGGING) { if (componentState != ComponentState.DRAGGING) {
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
/ MAX_ALPHA));
} }
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : color); g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : color);
g2d.fill(body[0]); g2d.fill(body[0]);
@@ -69,15 +70,15 @@ public class BatterySnap9V extends AbstractTransparentComponent<String> {
Color finalBorderColor; Color finalBorderColor;
if (outlineMode) { if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject( Theme theme =
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : theme componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : color componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
.brighter(); : color.brighter();
} }
g2d.setColor(finalBorderColor); g2d.setColor(finalBorderColor);
@@ -102,14 +103,13 @@ public class BatterySnap9V extends AbstractTransparentComponent<String> {
int terminalBorder = (int) TERMINAL_BORDER.convertToPixels(); int terminalBorder = (int) TERMINAL_BORDER.convertToPixels();
Area mainArea = new Area(new Rectangle2D.Double(x, y - width / 2, length, width)); Area mainArea = new Area(new Rectangle2D.Double(x, y - width / 2, length, width));
mainArea.add(new Area(new Ellipse2D.Double(x + length - width / 2, y - width / 2, mainArea.add(new Area(new Ellipse2D.Double(x + length - width / 2, y - width / 2, width, width)));
width, width)));
body[0] = mainArea; body[0] = mainArea;
Area terminalArea = new Area(new Ellipse2D.Double(x + (totalLength - terminalSpacing) Area terminalArea =
/ 2 - terminalDiameter / 2, y - terminalDiameter / 2, terminalDiameter, new Area(new Ellipse2D.Double(x + (totalLength - terminalSpacing) / 2 - terminalDiameter / 2, y
terminalDiameter)); - terminalDiameter / 2, terminalDiameter, terminalDiameter));
int centerX = x + (totalLength + terminalSpacing) / 2; int centerX = x + (totalLength + terminalSpacing) / 2;
int[] terminalX = new int[6]; int[] terminalX = new int[6];
@@ -123,16 +123,14 @@ public class BatterySnap9V extends AbstractTransparentComponent<String> {
body[1] = terminalArea; body[1] = terminalArea;
terminalArea = new Area(new Ellipse2D.Double(x + (totalLength - terminalSpacing) / 2 terminalArea =
- terminalDiameter / 2 + terminalBorder, y - terminalDiameter / 2 new Area(new Ellipse2D.Double(
+ terminalBorder, terminalDiameter - 2 * terminalBorder, terminalDiameter - 2 x + (totalLength - terminalSpacing) / 2 - terminalDiameter / 2 + terminalBorder, y - terminalDiameter / 2
* terminalBorder)); + terminalBorder, terminalDiameter - 2 * terminalBorder, terminalDiameter - 2 * terminalBorder));
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
terminalX[i] = (int) (centerX + Math.cos(Math.PI / 3 * i) terminalX[i] = (int) (centerX + Math.cos(Math.PI / 3 * i) * (terminalDiameter / 2 + terminalBorder));
* (terminalDiameter / 2 + terminalBorder)); terminalY[i] = (int) (y + Math.sin(Math.PI / 3 * i) * (terminalDiameter / 2 + terminalBorder));
terminalY[i] = (int) (y + Math.sin(Math.PI / 3 * i)
* (terminalDiameter / 2 + terminalBorder));
} }
terminalArea.add(new Area(new Polygon(terminalX, terminalY, 6))); terminalArea.add(new Area(new Polygon(terminalX, terminalY, 6)));
@@ -173,8 +171,8 @@ public class BatterySnap9V extends AbstractTransparentComponent<String> {
g2d.setColor(BODY_COLOR.darker()); g2d.setColor(BODY_COLOR.darker());
g2d.drawRect(width / 4, width / 32 + width / 4, width / 2, width * 3 / 4 - 2 * width / 32); g2d.drawRect(width / 4, width / 32 + width / 4, width / 2, width * 3 / 4 - 2 * width / 32);
g2d.setColor(METAL_COLOR); g2d.setColor(METAL_COLOR);
g2d.fillOval(width / 4 + 3 * width / 32, width / 32 + 3 * width / 32, width / 2 - 6 * width g2d.fillOval(width / 4 + 3 * width / 32, width / 32 + 3 * width / 32, width / 2 - 6 * width / 32, width / 2 - 6
/ 32, width / 2 - 6 * width / 32); * width / 32);
int centerX = width / 2; int centerX = width / 2;
int centerY = height * 7 / 9; int centerY = height * 7 / 9;
@@ -188,8 +186,8 @@ public class BatterySnap9V extends AbstractTransparentComponent<String> {
} }
g2d.fillPolygon(terminalX, terminalY, 6); g2d.fillPolygon(terminalX, terminalY, 6);
g2d.setColor(METAL_COLOR.darker()); g2d.setColor(METAL_COLOR.darker());
g2d.drawOval(width / 4 + 3 * width / 32, width / 32 + 3 * width / 32, width / 2 - 6 * width g2d.drawOval(width / 4 + 3 * width / 32, width / 32 + 3 * width / 32, width / 2 - 6 * width / 32, width / 2 - 6
/ 32, width / 2 - 6 * width / 32); * width / 32);
g2d.drawPolygon(terminalX, terminalY, 6); g2d.drawPolygon(terminalX, terminalY, 6);
} }
@@ -31,7 +31,9 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Cliff 1/4\" Jack", category = "Electromechanical", author = "Branislav Stojkovic", description = "Cliff-style closed panel mount 1/4\" phono jack", stretchable = false, zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "J", autoEdit = false) @ComponentDescriptor(name = "Cliff 1/4\" Jack", category = "Electromechanical", author = "Branislav Stojkovic",
description = "Cliff-style closed panel mount 1/4\" phono jack", stretchable = false,
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "J", autoEdit = false)
public class CliffJack1_4 extends AbstractTransparentComponent<String> { public class CliffJack1_4 extends AbstractTransparentComponent<String> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -78,8 +80,7 @@ public class CliffJack1_4 extends AbstractTransparentComponent<String> {
// Apply rotation if necessary // Apply rotation if necessary
double angle = getAngle(); double angle = getAngle();
if (angle != 0) { if (angle != 0) {
AffineTransform rotation = AffineTransform.getRotateInstance(angle, AffineTransform rotation = AffineTransform.getRotateInstance(angle, x, y);
x, y);
for (int i = 1; i < controlPoints.length; i++) { for (int i = 1; i < controlPoints.length; i++) {
rotation.transform(controlPoints[i], controlPoints[i]); rotation.transform(controlPoints[i], controlPoints[i]);
} }
@@ -115,33 +116,29 @@ public class CliffJack1_4 extends AbstractTransparentComponent<String> {
int bodyWidth = (int) BODY_WIDTH.convertToPixels(); int bodyWidth = (int) BODY_WIDTH.convertToPixels();
int centerX = (controlPoints[0].x + controlPoints[3].x) / 2; int centerX = (controlPoints[0].x + controlPoints[3].x) / 2;
int centerY = (controlPoints[0].y + controlPoints[3].y) / 2; int centerY = (controlPoints[0].y + controlPoints[3].y) / 2;
body[0] = new Rectangle(centerX - bodyLength / 2, centerY body[0] = new Rectangle(centerX - bodyLength / 2, centerY - bodyWidth / 2, bodyLength, bodyWidth);
- bodyWidth / 2, bodyLength, bodyWidth);
int tailLength = (int) TAIL_LENGTH.convertToPixels(); int tailLength = (int) TAIL_LENGTH.convertToPixels();
body[1] = new RoundRectangle2D.Double(centerX - bodyLength / 2 body[1] =
- tailLength, centerY - bodyWidth / 4, tailLength * 2, new RoundRectangle2D.Double(centerX - bodyLength / 2 - tailLength, centerY - bodyWidth / 4, tailLength * 2,
bodyWidth / 2, tailLength, tailLength); bodyWidth / 2, tailLength, tailLength);
Area tailArea = new Area(body[1]); Area tailArea = new Area(body[1]);
tailArea.subtract(new Area(body[0])); tailArea.subtract(new Area(body[0]));
body[1] = tailArea; body[1] = tailArea;
body[2] = new Rectangle(centerX + bodyLength / 2, centerY body[2] = new Rectangle(centerX + bodyLength / 2, centerY - bodyWidth / 4, tailLength, bodyWidth / 2);
- bodyWidth / 4, tailLength, bodyWidth / 2);
body[3] = new Rectangle(centerX + bodyLength / 2 + tailLength, body[3] =
centerY - bodyWidth / 4, tailLength, bodyWidth / 2); new Rectangle(centerX + bodyLength / 2 + tailLength, centerY - bodyWidth / 4, tailLength, bodyWidth / 2);
tailArea = new Area(body[3]); tailArea = new Area(body[3]);
int radius = bodyLength / 2 + tailLength * 2; int radius = bodyLength / 2 + tailLength * 2;
tailArea.intersect(new Area(new Ellipse2D.Double(centerX - radius, tailArea.intersect(new Area(new Ellipse2D.Double(centerX - radius, centerY - radius, radius * 2, radius * 2)));
centerY - radius, radius * 2, radius * 2)));
body[3] = tailArea; body[3] = tailArea;
// Apply rotation if necessary // Apply rotation if necessary
double angle = getAngle(); double angle = getAngle();
if (angle != 0) { if (angle != 0) {
AffineTransform rotation = AffineTransform.getRotateInstance( AffineTransform rotation = AffineTransform.getRotateInstance(angle, centerX, centerY);
angle, centerX, centerY);
for (int i = 0; i < body.length; i++) { for (int i = 0; i < body.length; i++) {
if (body[i] != null) { if (body[i] != null) {
Area area = new Area(body[i]); Area area = new Area(body[i]);
@@ -159,13 +156,10 @@ public class CliffJack1_4 extends AbstractTransparentComponent<String> {
for (int i = 0; i < getControlPointCount(); i++) { for (int i = 0; i < getControlPointCount(); i++) {
Point point = getControlPoint(i); Point point = getControlPoint(i);
Rectangle pin; Rectangle pin;
if (orientation == Orientation.DEFAULT if (orientation == Orientation.DEFAULT || orientation == Orientation._180) {
|| orientation == Orientation._180) { pin = new Rectangle(point.x - pinWidth / 2, point.y - pinThickness / 2, pinWidth, pinThickness);
pin = new Rectangle(point.x - pinWidth / 2, point.y
- pinThickness / 2, pinWidth, pinThickness);
} else { } else {
pin = new Rectangle(point.x - pinThickness / 2, point.y pin = new Rectangle(point.x - pinThickness / 2, point.y - pinWidth / 2, pinThickness, pinWidth);
- pinWidth / 2, pinThickness, pinWidth);
} }
pins.add(new Area(pin)); pins.add(new Area(pin));
} }
@@ -176,8 +170,7 @@ public class CliffJack1_4 extends AbstractTransparentComponent<String> {
} }
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
boolean outlineMode, Project project,
IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
Shape[] body = getBody(); Shape[] body = getBody();
@@ -185,32 +178,27 @@ public class CliffJack1_4 extends AbstractTransparentComponent<String> {
if (componentState != ComponentState.DRAGGING) { if (componentState != ComponentState.DRAGGING) {
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance( g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
} }
g2d g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : BODY_COLOR);
.setColor(outlineMode ? Constants.TRANSPARENT_COLOR
: BODY_COLOR);
for (int i = 0; i < body.length - 1; i++) { for (int i = 0; i < body.length - 1; i++) {
// Nut is brighter colored. // Nut is brighter colored.
if (i == body.length - 2) if (i == body.length - 2)
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : NUT_COLOR);
: NUT_COLOR);
g2d.fill(body[i]); g2d.fill(body[i]);
} }
g2d.setComposite(oldComposite); g2d.setComposite(oldComposite);
} }
Color finalBorderColor; Color finalBorderColor;
Theme theme = (Theme) ConfigurationManager.getInstance().readObject( Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
if (outlineMode) { if (outlineMode) {
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: theme.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: BORDER_COLOR; : BORDER_COLOR;
} }
@@ -225,26 +213,24 @@ public class CliffJack1_4 extends AbstractTransparentComponent<String> {
g2d.setColor(METAL_COLOR); g2d.setColor(METAL_COLOR);
g2d.fill(pins); g2d.fill(pins);
} }
g2d.setColor(outlineMode ? theme.getOutlineColor() : METAL_COLOR g2d.setColor(outlineMode ? theme.getOutlineColor() : METAL_COLOR.darker());
.darker());
g2d.draw(pins); g2d.draw(pins);
Color finalLabelColor; Color finalLabelColor;
if (outlineMode) { if (outlineMode) {
finalLabelColor = componentState == ComponentState.SELECTED finalLabelColor =
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: theme.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalLabelColor = componentState == ComponentState.SELECTED finalLabelColor =
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: LABEL_COLOR; : LABEL_COLOR;
} }
g2d.setColor(finalLabelColor); g2d.setColor(finalLabelColor);
g2d.setFont(LABEL_FONT); g2d.setFont(LABEL_FONT);
int centerX = (controlPoints[0].x + controlPoints[3].x) / 2; int centerX = (controlPoints[0].x + controlPoints[3].x) / 2;
int centerY = (controlPoints[0].y + controlPoints[3].y) / 2; int centerY = (controlPoints[0].y + controlPoints[3].y) / 2;
drawCenteredText(g2d, name, centerX, centerY, drawCenteredText(g2d, name, centerX, centerY, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
} }
@Override @Override
@@ -253,25 +239,21 @@ public class CliffJack1_4 extends AbstractTransparentComponent<String> {
int tailWidth = getClosestOdd(width * 3 / 9); int tailWidth = getClosestOdd(width * 3 / 9);
g2d.setColor(BODY_COLOR); g2d.setColor(BODY_COLOR);
g2d.fillRoundRect((width - tailWidth) / 2, height / 2, tailWidth, g2d.fillRoundRect((width - tailWidth) / 2, height / 2, tailWidth, height / 2 - 2 * 32 / height, 4 * 32 / width,
height / 2 - 2 * 32 / height, 4 * 32 / width, 4 * 32 / width); 4 * 32 / width);
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.drawRoundRect((width - tailWidth) / 2, height / 2, tailWidth, g2d.drawRoundRect((width - tailWidth) / 2, height / 2, tailWidth, height / 2 - 2 * 32 / height, 4 * 32 / width,
height / 2 - 2 * 32 / height, 4 * 32 / width, 4 * 32 / width); 4 * 32 / width);
g2d.setColor(NUT_COLOR); g2d.setColor(NUT_COLOR);
g2d.fillRoundRect((width - tailWidth) / 2, 2 * 32 / height, tailWidth, g2d.fillRoundRect((width - tailWidth) / 2, 2 * 32 / height, tailWidth, height / 2, 4 * 32 / width, 4 * 32 / width);
height / 2, 4 * 32 / width, 4 * 32 / width);
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.drawRoundRect((width - tailWidth) / 2, 2 * 32 / height, tailWidth, g2d.drawRoundRect((width - tailWidth) / 2, 2 * 32 / height, tailWidth, height / 2, 4 * 32 / width, 4 * 32 / width);
height / 2, 4 * 32 / width, 4 * 32 / width);
g2d.setColor(BODY_COLOR); g2d.setColor(BODY_COLOR);
g2d.fillRect((width - bodyWidth) / 2, height / 7 + 1, bodyWidth, g2d.fillRect((width - bodyWidth) / 2, height / 7 + 1, bodyWidth, height * 5 / 7);
height * 5 / 7);
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.drawRect((width - bodyWidth) / 2, height / 7 + 1, bodyWidth, g2d.drawRect((width - bodyWidth) / 2, height / 7 + 1, bodyWidth, height * 5 / 7);
height * 5 / 7);
g2d.setColor(METAL_COLOR); g2d.setColor(METAL_COLOR);
int pinX1 = getClosestOdd((width - bodyWidth * 3 / 4) / 2); int pinX1 = getClosestOdd((width - bodyWidth * 3 / 4) / 2);
@@ -31,7 +31,9 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Closed 1/4\" Jack", category = "Electromechanical", author = "Branislav Stojkovic", description = "Enclosed panel mount 1/4\" phono jack", stretchable = false, zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "J", autoEdit = false) @ComponentDescriptor(name = "Closed 1/4\" Jack", category = "Electromechanical", author = "Branislav Stojkovic",
description = "Enclosed panel mount 1/4\" phono jack", stretchable = false, zOrder = IDIYComponent.COMPONENT,
instanceNamePrefix = "J", autoEdit = false)
public class ClosedJack1_4 extends AbstractTransparentComponent<String> { public class ClosedJack1_4 extends AbstractTransparentComponent<String> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -117,13 +119,11 @@ public class ClosedJack1_4 extends AbstractTransparentComponent<String> {
int lugHoleSize = (int) LUG_HOLE_SIZE.convertToPixels(); int lugHoleSize = (int) LUG_HOLE_SIZE.convertToPixels();
int bodyLength = (int) BODY_LENGTH.convertToPixels(); int bodyLength = (int) BODY_LENGTH.convertToPixels();
int bodyWidth = (int) BODY_WIDTH.convertToPixels(); int bodyWidth = (int) BODY_WIDTH.convertToPixels();
body[0] = new Area(new Rectangle(x + lugLength, y - bodyWidth / 2, bodyLength, body[0] = new Area(new Rectangle(x + lugLength, y - bodyWidth / 2, bodyLength, bodyWidth));
bodyWidth));
int shaftLength = (int) SHAFT_LENGTH.convertToPixels(); int shaftLength = (int) SHAFT_LENGTH.convertToPixels();
int shaftWidth = (int) SHAFT_WIDTH.convertToPixels(); int shaftWidth = (int) SHAFT_WIDTH.convertToPixels();
Area shaft = new Area(new Rectangle(x + lugLength + bodyLength, y - shaftWidth / 2, Area shaft = new Area(new Rectangle(x + lugLength + bodyLength, y - shaftWidth / 2, shaftLength, shaftWidth));
shaftLength, shaftWidth));
body[1] = shaft; body[1] = shaft;
double angle = getAngle(); double angle = getAngle();
@@ -134,8 +134,7 @@ public class ClosedJack1_4 extends AbstractTransparentComponent<String> {
GeneralPath path = new GeneralPath(); GeneralPath path = new GeneralPath();
int step = 4; int step = 4;
for (int i = x + lugLength + bodyLength + step; i <= x + lugLength + bodyLength for (int i = x + lugLength + bodyLength + step; i <= x + lugLength + bodyLength + shaftLength; i += step) {
+ shaftLength; i += step) {
Point p = new Point(i, y - shaftWidth / 2 + 1); Point p = new Point(i, y - shaftWidth / 2 + 1);
if (rotation != null) { if (rotation != null) {
rotation.transform(p, p); rotation.transform(p, p);
@@ -165,12 +164,10 @@ public class ClosedJack1_4 extends AbstractTransparentComponent<String> {
for (int i = 0; i < untransformedControlPoints.length; i++) { for (int i = 0; i < untransformedControlPoints.length; i++) {
Point point = untransformedControlPoints[i]; Point point = untransformedControlPoints[i];
Area lug = new Area(new Ellipse2D.Double(point.x - lugWidth / 2, point.y - lugWidth Area lug = new Area(new Ellipse2D.Double(point.x - lugWidth / 2, point.y - lugWidth / 2, lugWidth, lugWidth));
/ 2, lugWidth, lugWidth)); lug.add(new Area(new Rectangle(point.x, point.y - lugWidth / 2, lugLength, lugWidth)));
lug.add(new Area( lug.subtract(new Area(new Ellipse2D.Double(point.x - lugHoleSize / 2, point.y - lugHoleSize / 2, lugHoleSize,
new Rectangle(point.x, point.y - lugWidth / 2, lugLength, lugWidth))); lugHoleSize)));
lug.subtract(new Area(new Ellipse2D.Double(point.x - lugHoleSize / 2, point.y
- lugHoleSize / 2, lugHoleSize, lugHoleSize)));
lugs.add(lug); lugs.add(lug);
} }
@@ -190,8 +187,8 @@ public class ClosedJack1_4 extends AbstractTransparentComponent<String> {
} }
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
Project project, IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
Shape[] body = getBody(); Shape[] body = getBody();
// Rectangle bounds = body.getBounds(); // Rectangle bounds = body.getBounds();
@@ -200,8 +197,7 @@ public class ClosedJack1_4 extends AbstractTransparentComponent<String> {
if (componentState != ComponentState.DRAGGING) { if (componentState != ComponentState.DRAGGING) {
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
/ MAX_ALPHA));
} }
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : BODY_COLOR); g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : BODY_COLOR);
g2d.fill(body[0]); g2d.fill(body[0]);
@@ -214,14 +210,15 @@ public class ClosedJack1_4 extends AbstractTransparentComponent<String> {
Color finalBorderColor; Color finalBorderColor;
if (outlineMode) { if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject( Theme theme =
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : theme componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : BORDER_COLOR; componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: BORDER_COLOR;
} }
g2d.setColor(finalBorderColor); g2d.setColor(finalBorderColor);
@@ -239,14 +236,14 @@ public class ClosedJack1_4 extends AbstractTransparentComponent<String> {
Color finalLabelColor; Color finalLabelColor;
if (outlineMode) { if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject( Theme theme =
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalLabelColor = componentState == ComponentState.SELECTED finalLabelColor =
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED : theme componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalLabelColor = componentState == ComponentState.SELECTED finalLabelColor =
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: LABEL_COLOR; : LABEL_COLOR;
} }
g2d.setColor(finalLabelColor); g2d.setColor(finalLabelColor);
@@ -254,8 +251,7 @@ public class ClosedJack1_4 extends AbstractTransparentComponent<String> {
Rectangle bounds = body[0].getBounds(); Rectangle bounds = body[0].getBounds();
int centerX = bounds.x + bounds.width / 2; int centerX = bounds.x + bounds.width / 2;
int centerY = bounds.y + bounds.height / 2; int centerY = bounds.y + bounds.height / 2;
drawCenteredText(g2d, name, centerX, centerY, HorizontalAlignment.CENTER, drawCenteredText(g2d, name, centerX, centerY, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
VerticalAlignment.CENTER);
} }
@Override @Override
@@ -31,7 +31,9 @@ import org.diylc.core.measures.Voltage;
import org.diylc.core.measures.VoltageUnit; import org.diylc.core.measures.VoltageUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Mini Relay", author = "Branislav Stojkovic", category = "Electromechanical", instanceNamePrefix = "RY", description = "Miniature PCB mount relay, like Omron G5V-1 or G5V-2", stretchable = false, zOrder = IDIYComponent.COMPONENT) @ComponentDescriptor(name = "Mini Relay", author = "Branislav Stojkovic", category = "Electromechanical",
instanceNamePrefix = "RY", description = "Miniature PCB mount relay, like Omron G5V-1 or G5V-2",
stretchable = false, zOrder = IDIYComponent.COMPONENT)
public class MiniRelay extends AbstractTransparentComponent<String> { public class MiniRelay extends AbstractTransparentComponent<String> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -148,10 +150,12 @@ public class MiniRelay extends AbstractTransparentComponent<String> {
} }
controlPoints = new Point[pinCount]; controlPoints = new Point[pinCount];
controlPoints[0] = firstPoint; controlPoints[0] = firstPoint;
int pinSpacing = size == RelaySize.Miniature ? (int) MINI_PIN_SPACING int pinSpacing =
.convertToPixels() : (int) ULTRA_PIN_SPACING.convertToPixels(); size == RelaySize.Miniature ? (int) MINI_PIN_SPACING.convertToPixels() : (int) ULTRA_PIN_SPACING
int rowSpacing = size == RelaySize.Miniature ? (int) MINI_ROW_SPACING .convertToPixels();
.convertToPixels() : (int) ULTRA_ROW_SPACING.convertToPixels(); int rowSpacing =
size == RelaySize.Miniature ? (int) MINI_ROW_SPACING.convertToPixels() : (int) ULTRA_ROW_SPACING
.convertToPixels();
// Update control points. // Update control points.
int dx1; int dx1;
int dy1; int dy1;
@@ -160,8 +164,7 @@ public class MiniRelay extends AbstractTransparentComponent<String> {
int delta = 0; int delta = 0;
for (int i = 0; i < pinCount / 2; i++) { for (int i = 0; i < pinCount / 2; i++) {
if (i == 1) { if (i == 1) {
delta = size == RelaySize.Miniature ? (int) MINI_GAP delta = size == RelaySize.Miniature ? (int) MINI_GAP.convertToPixels() : (int) ULTRA_GAP.convertToPixels();
.convertToPixels() : (int) ULTRA_GAP.convertToPixels();
if (type == RelayType.SPDT) { if (type == RelayType.SPDT) {
delta += pinSpacing; delta += pinSpacing;
} }
@@ -192,12 +195,10 @@ public class MiniRelay extends AbstractTransparentComponent<String> {
dy2 = -rowSpacing; dy2 = -rowSpacing;
break; break;
default: default:
throw new RuntimeException("Unexpected orientation: " throw new RuntimeException("Unexpected orientation: " + orientation);
+ orientation);
} }
controlPoints[i] = new Point(firstPoint.x + dx1, firstPoint.y + dy1); controlPoints[i] = new Point(firstPoint.x + dx1, firstPoint.y + dy1);
controlPoints[i + pinCount / 2] = new Point(firstPoint.x + dx2, controlPoints[i + pinCount / 2] = new Point(firstPoint.x + dx2, firstPoint.y + dy2);
firstPoint.y + dy2);
} }
} }
@@ -211,63 +212,53 @@ public class MiniRelay extends AbstractTransparentComponent<String> {
int bodyMargin = getClosestOdd(BODY_MARGIN.convertToPixels()); int bodyMargin = getClosestOdd(BODY_MARGIN.convertToPixels());
int width = 0; int width = 0;
int height = 0; int height = 0;
int rowSpacing = size == RelaySize.Miniature ? (int) MINI_ROW_SPACING int rowSpacing =
.convertToPixels() size == RelaySize.Miniature ? (int) MINI_ROW_SPACING.convertToPixels() : (int) ULTRA_ROW_SPACING
: (int) ULTRA_ROW_SPACING.convertToPixels(); .convertToPixels();
Area indentation = null; Area indentation = null;
int indentationSize = getClosestOdd(INDENT_SIZE.convertToPixels()); int indentationSize = getClosestOdd(INDENT_SIZE.convertToPixels());
switch (orientation) { switch (orientation) {
case DEFAULT: case DEFAULT:
width = (int) (size == RelaySize.Miniature ? MINI_HEIGHT width = (int) (size == RelaySize.Miniature ? MINI_HEIGHT.convertToPixels() : ULTRA_HEIGHT.convertToPixels());
.convertToPixels() : ULTRA_HEIGHT.convertToPixels()); height = (int) (size == RelaySize.Miniature ? MINI_WIDTH.convertToPixels() : ULTRA_WIDTH.convertToPixels());
height = (int) (size == RelaySize.Miniature ? MINI_WIDTH
.convertToPixels() : ULTRA_WIDTH.convertToPixels());
x -= bodyMargin; x -= bodyMargin;
y -= bodyMargin; y -= bodyMargin;
indentation = new Area(new Rectangle2D.Double(centerX indentation =
- indentationSize / 2, y - indentationSize / 2, new Area(new Rectangle2D.Double(centerX - indentationSize / 2, y - indentationSize / 2, indentationSize,
indentationSize, indentationSize)); indentationSize));
break; break;
case _90: case _90:
width = (int) (size == RelaySize.Miniature ? MINI_WIDTH width = (int) (size == RelaySize.Miniature ? MINI_WIDTH.convertToPixels() : ULTRA_WIDTH.convertToPixels());
.convertToPixels() : ULTRA_WIDTH.convertToPixels()); height = (int) (size == RelaySize.Miniature ? MINI_HEIGHT.convertToPixels() : ULTRA_HEIGHT.convertToPixels());
height = (int) (size == RelaySize.Miniature ? MINI_HEIGHT
.convertToPixels() : ULTRA_HEIGHT.convertToPixels());
x -= -bodyMargin + width; x -= -bodyMargin + width;
y -= bodyMargin; y -= bodyMargin;
indentation = new Area(new Rectangle2D.Double(x + width indentation =
- indentationSize / 2, centerY - indentationSize / 2, new Area(new Rectangle2D.Double(x + width - indentationSize / 2, centerY - indentationSize / 2,
indentationSize, indentationSize)); indentationSize, indentationSize));
break; break;
case _180: case _180:
width = (int) (size == RelaySize.Miniature ? MINI_HEIGHT width = (int) (size == RelaySize.Miniature ? MINI_HEIGHT.convertToPixels() : ULTRA_HEIGHT.convertToPixels());
.convertToPixels() : ULTRA_HEIGHT.convertToPixels()); height = (int) (size == RelaySize.Miniature ? MINI_WIDTH.convertToPixels() : ULTRA_WIDTH.convertToPixels());
height = (int) (size == RelaySize.Miniature ? MINI_WIDTH
.convertToPixels() : ULTRA_WIDTH.convertToPixels());
x -= rowSpacing + bodyMargin; x -= rowSpacing + bodyMargin;
y -= -bodyMargin + height; y -= -bodyMargin + height;
indentation = new Area(new Rectangle2D.Double(centerX indentation =
- indentationSize / 2, new Area(new Rectangle2D.Double(centerX - indentationSize / 2, y + height - indentationSize / 2,
y + height - indentationSize / 2, indentationSize,
indentationSize));
break;
case _270:
width = (int) (size == RelaySize.Miniature ? MINI_WIDTH
.convertToPixels() : ULTRA_WIDTH.convertToPixels());
height = (int) (size == RelaySize.Miniature ? MINI_HEIGHT
.convertToPixels() : ULTRA_HEIGHT.convertToPixels());
x -= bodyMargin;
y -= bodyMargin + rowSpacing;
indentation = new Area(new Rectangle2D.Double(x
- indentationSize / 2, centerY - indentationSize / 2,
indentationSize, indentationSize)); indentationSize, indentationSize));
break; break;
case _270:
width = (int) (size == RelaySize.Miniature ? MINI_WIDTH.convertToPixels() : ULTRA_WIDTH.convertToPixels());
height = (int) (size == RelaySize.Miniature ? MINI_HEIGHT.convertToPixels() : ULTRA_HEIGHT.convertToPixels());
x -= bodyMargin;
y -= bodyMargin + rowSpacing;
indentation =
new Area(new Rectangle2D.Double(x - indentationSize / 2, centerY - indentationSize / 2, indentationSize,
indentationSize));
break;
default: default:
throw new RuntimeException("Unexpected orientation: " throw new RuntimeException("Unexpected orientation: " + orientation);
+ orientation);
} }
body[0] = new Area(new RoundRectangle2D.Double(centerX - width / 2, body[0] =
centerY - height / 2, width, height, EDGE_RADIUS, new Area(new RoundRectangle2D.Double(centerX - width / 2, centerY - height / 2, width, height, EDGE_RADIUS,
EDGE_RADIUS)); EDGE_RADIUS));
body[1] = indentation; body[1] = indentation;
if (indentation != null) { if (indentation != null) {
@@ -278,8 +269,7 @@ public class MiniRelay extends AbstractTransparentComponent<String> {
} }
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
boolean outlineMode, Project project,
IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) { if (checkPointsClipped(g2d.getClip())) {
return; return;
@@ -287,36 +277,31 @@ public class MiniRelay extends AbstractTransparentComponent<String> {
Area mainArea = getBody()[0]; Area mainArea = getBody()[0];
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance( g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
} }
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : BODY_COLOR); g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : BODY_COLOR);
g2d.fill(mainArea); g2d.fill(mainArea);
g2d.setComposite(oldComposite); g2d.setComposite(oldComposite);
Theme theme = (Theme) ConfigurationManager.getInstance().readObject( Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2; int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
for (Point point : controlPoints) { for (Point point : controlPoints) {
if (!outlineMode) { if (!outlineMode) {
g2d.setColor(PIN_COLOR); g2d.setColor(PIN_COLOR);
g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
pinSize, pinSize);
} }
g2d.setColor(outlineMode ? theme.getOutlineColor() g2d.setColor(outlineMode ? theme.getOutlineColor() : PIN_BORDER_COLOR);
: PIN_BORDER_COLOR); g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize,
pinSize);
} }
Color finalBorderColor; Color finalBorderColor;
if (outlineMode) { if (outlineMode) {
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: theme.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: BORDER_COLOR; : BORDER_COLOR;
} }
g2d.setColor(finalBorderColor); g2d.setColor(finalBorderColor);
@@ -336,12 +321,12 @@ public class MiniRelay extends AbstractTransparentComponent<String> {
g2d.setFont(LABEL_FONT); g2d.setFont(LABEL_FONT);
Color finalLabelColor; Color finalLabelColor;
if (outlineMode) { if (outlineMode) {
finalLabelColor = componentState == ComponentState.SELECTED finalLabelColor =
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: theme.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalLabelColor = componentState == ComponentState.SELECTED finalLabelColor =
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: LABEL_COLOR; : LABEL_COLOR;
} }
g2d.setColor(finalLabelColor); g2d.setColor(finalLabelColor);
@@ -360,8 +345,7 @@ public class MiniRelay extends AbstractTransparentComponent<String> {
// Center text horizontally and vertically // Center text horizontally and vertically
Rectangle bounds = mainArea.getBounds(); Rectangle bounds = mainArea.getBounds();
int x = bounds.x + (bounds.width - textWidth) / 2; int x = bounds.x + (bounds.width - textWidth) / 2;
int y = bounds.y + (bounds.height - textHeight) / 2 int y = bounds.y + (bounds.height - textHeight) / 2 + fontMetrics.getAscent();
+ fontMetrics.getAscent();
g2d.drawString(label, x, y); g2d.drawString(label, x, y);
} }
@@ -369,20 +353,16 @@ public class MiniRelay extends AbstractTransparentComponent<String> {
public void drawIcon(Graphics2D g2d, int width, int height) { public void drawIcon(Graphics2D g2d, int width, int height) {
int radius = 6 * width / 32; int radius = 6 * width / 32;
g2d.setColor(BODY_COLOR); g2d.setColor(BODY_COLOR);
g2d.fillRoundRect(width / 6, 1, 4 * width / 6, height - 4, radius, g2d.fillRoundRect(width / 6, 1, 4 * width / 6, height - 4, radius, radius);
radius);
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.drawRoundRect(width / 6, 1, 4 * width / 6, height - 4, radius, g2d.drawRoundRect(width / 6, 1, 4 * width / 6, height - 4, radius, radius);
radius);
int pinSize = 2 * width / 32; int pinSize = 2 * width / 32;
g2d.setColor(PIN_COLOR); g2d.setColor(PIN_COLOR);
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (i == 1) if (i == 1)
continue; continue;
g2d.fillOval(width / 4, (height / 5) * (i + 1) - 1, pinSize, g2d.fillOval(width / 4, (height / 5) * (i + 1) - 1, pinSize, pinSize);
pinSize); g2d.fillOval(3 * width / 4 - pinSize, (height / 5) * (i + 1) - 1, pinSize, pinSize);
g2d.fillOval(3 * width / 4 - pinSize, (height / 5) * (i + 1) - 1,
pinSize, pinSize);
} }
} }
@@ -27,9 +27,10 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Mini Toggle Switch", category = "Electromechanical", author = "Branislav Stojkovic", description = "Panel mounted mini toggle switch", stretchable = false, zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "SW", autoEdit = false) @ComponentDescriptor(name = "Mini Toggle Switch", category = "Electromechanical", author = "Branislav Stojkovic",
public class MiniToggleSwitch extends description = "Panel mounted mini toggle switch", stretchable = false, zOrder = IDIYComponent.COMPONENT,
AbstractTransparentComponent<ToggleSwitchType> { instanceNamePrefix = "SW", autoEdit = false)
public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchType> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -59,87 +60,61 @@ public class MiniToggleSwitch extends
int spacing = (int) SPACING.convertToPixels(); int spacing = (int) SPACING.convertToPixels();
switch (switchType) { switch (switchType) {
case SPST: case SPST:
controlPoints = new Point[] { firstPoint, controlPoints = new Point[] {firstPoint, new Point(firstPoint.x, firstPoint.y + spacing)};
new Point(firstPoint.x, firstPoint.y + spacing) };
break; break;
case SPDT: case SPDT:
controlPoints = new Point[] { firstPoint, controlPoints =
new Point(firstPoint.x, firstPoint.y + spacing), new Point[] {firstPoint, new Point(firstPoint.x, firstPoint.y + spacing),
new Point(firstPoint.x, firstPoint.y + 2 * spacing)}; new Point(firstPoint.x, firstPoint.y + 2 * spacing)};
break; break;
case DPDT: case DPDT:
controlPoints = new Point[] { controlPoints =
firstPoint, new Point[] {firstPoint, new Point(firstPoint.x, firstPoint.y + spacing),
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, 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 + spacing),
new Point(firstPoint.x + spacing, firstPoint.y + 2 new Point(firstPoint.x + spacing, firstPoint.y + 2 * spacing)};
* spacing) };
break; break;
case _3PDT: case _3PDT:
controlPoints = new Point[] { controlPoints =
firstPoint, new Point[] {firstPoint, new Point(firstPoint.x, firstPoint.y + spacing),
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, 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 + spacing),
new Point(firstPoint.x + spacing, firstPoint.y + 2 new Point(firstPoint.x + spacing, firstPoint.y + 2 * spacing),
* spacing),
new Point(firstPoint.x + 2 * spacing, firstPoint.y), new Point(firstPoint.x + 2 * spacing, firstPoint.y),
new Point(firstPoint.x + 2 * spacing, firstPoint.y new Point(firstPoint.x + 2 * spacing, firstPoint.y + spacing),
+ spacing), new Point(firstPoint.x + 2 * spacing, firstPoint.y + 2 * spacing)};
new Point(firstPoint.x + 2 * spacing, firstPoint.y + 2
* spacing) };
break; break;
case _4PDT: case _4PDT:
controlPoints = new Point[] { controlPoints =
firstPoint, new Point[] {firstPoint, new Point(firstPoint.x, firstPoint.y + spacing),
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, 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 + spacing),
new Point(firstPoint.x + spacing, firstPoint.y + 2 new Point(firstPoint.x + spacing, firstPoint.y + 2 * spacing),
* spacing),
new Point(firstPoint.x + 2 * spacing, firstPoint.y), new Point(firstPoint.x + 2 * spacing, firstPoint.y),
new Point(firstPoint.x + 2 * spacing, firstPoint.y new Point(firstPoint.x + 2 * spacing, firstPoint.y + spacing),
+ spacing), new Point(firstPoint.x + 2 * spacing, firstPoint.y + 2 * 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),
new Point(firstPoint.x + 3 * spacing, firstPoint.y new Point(firstPoint.x + 3 * spacing, firstPoint.y + spacing),
+ spacing), new Point(firstPoint.x + 3 * spacing, firstPoint.y + 2 * spacing)};
new Point(firstPoint.x + 3 * spacing, firstPoint.y + 2
* spacing) };
break; break;
case _5PDT: case _5PDT:
controlPoints = new Point[] { controlPoints =
firstPoint, new Point[] {firstPoint, new Point(firstPoint.x, firstPoint.y + spacing),
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, 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 + spacing),
new Point(firstPoint.x + spacing, firstPoint.y + 2 new Point(firstPoint.x + spacing, firstPoint.y + 2 * spacing),
* spacing),
new Point(firstPoint.x + 2 * spacing, firstPoint.y), new Point(firstPoint.x + 2 * spacing, firstPoint.y),
new Point(firstPoint.x + 2 * spacing, firstPoint.y new Point(firstPoint.x + 2 * spacing, firstPoint.y + spacing),
+ spacing), new Point(firstPoint.x + 2 * spacing, firstPoint.y + 2 * 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),
new Point(firstPoint.x + 3 * spacing, firstPoint.y new Point(firstPoint.x + 3 * spacing, firstPoint.y + spacing),
+ spacing), new Point(firstPoint.x + 3 * spacing, firstPoint.y + 2 * 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),
new Point(firstPoint.x + 4 * spacing, firstPoint.y new Point(firstPoint.x + 4 * spacing, firstPoint.y + spacing),
+ spacing), new Point(firstPoint.x + 4 * spacing, firstPoint.y + 2 * spacing)};
new Point(firstPoint.x + 4 * spacing, firstPoint.y + 2
* spacing) };
break; break;
} }
AffineTransform xform = AffineTransform.getRotateInstance(-Math.PI / 2, AffineTransform xform = AffineTransform.getRotateInstance(-Math.PI / 2, firstPoint.x, firstPoint.y);
firstPoint.x, firstPoint.y);
if (getOrientation() == OrientationHV.HORIZONTAL) { if (getOrientation() == OrientationHV.HORIZONTAL) {
for (int i = 1; i < controlPoints.length; i++) { for (int i = 1; i < controlPoints.length; i++) {
xform.transform(controlPoints[i], controlPoints[i]); xform.transform(controlPoints[i], controlPoints[i]);
@@ -215,36 +190,31 @@ public class MiniToggleSwitch extends
} }
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
boolean outlineMode, Project project,
IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) { if (checkPointsClipped(g2d.getClip())) {
return; return;
} }
Shape body = getBody(); Shape body = getBody();
Theme theme = (Theme) ConfigurationManager.getInstance().readObject( Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
// Draw body if available. // Draw body if available.
if (body != null) { if (body != null) {
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance( g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
} }
g2d g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : BODY_COLOR);
.setColor(outlineMode ? Constants.TRANSPARENT_COLOR
: BODY_COLOR);
g2d.fill(body); g2d.fill(body);
g2d.setComposite(oldComposite); g2d.setComposite(oldComposite);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
Color finalBorderColor; Color finalBorderColor;
if (outlineMode) { if (outlineMode) {
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: theme.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: BORDER_COLOR; : BORDER_COLOR;
} }
g2d.setColor(finalBorderColor); g2d.setColor(finalBorderColor);
@@ -260,16 +230,12 @@ public class MiniToggleSwitch extends
for (Point p : controlPoints) { for (Point p : controlPoints) {
if (outlineMode) { if (outlineMode) {
g2d.setColor(theme.getOutlineColor()); g2d.setColor(theme.getOutlineColor());
g2d.drawRect(p.x - lugWidth / 2, p.y - lugHeight / 2, lugWidth, g2d.drawRect(p.x - lugWidth / 2, p.y - lugHeight / 2, lugWidth, lugHeight);
lugHeight);
} else { } else {
g2d.setColor(CIRCLE_COLOR); g2d.setColor(CIRCLE_COLOR);
g2d.fillOval(p.x - circleDiameter / 2, g2d.fillOval(p.x - circleDiameter / 2, p.y - circleDiameter / 2, circleDiameter, circleDiameter);
p.y - circleDiameter / 2, circleDiameter,
circleDiameter);
g2d.setColor(METAL_COLOR); g2d.setColor(METAL_COLOR);
g2d.fillRect(p.x - lugWidth / 2, p.y - lugHeight / 2, lugWidth, g2d.fillRect(p.x - lugWidth / 2, p.y - lugHeight / 2, lugWidth, lugHeight);
lugHeight);
} }
} }
} }
@@ -281,39 +247,38 @@ public class MiniToggleSwitch extends
int spacing = (int) SPACING.convertToPixels(); int spacing = (int) SPACING.convertToPixels();
switch (switchType) { switch (switchType) {
case SPST: case SPST:
body = new RoundRectangle2D.Double(firstPoint.x - margin, body =
firstPoint.y - margin, 2 * margin, new RoundRectangle2D.Double(firstPoint.x - margin, firstPoint.y - margin, 2 * margin, 2 * margin
2 * margin + spacing, margin, margin); + spacing, margin, margin);
break; break;
case SPDT: case SPDT:
body = new RoundRectangle2D.Double(firstPoint.x - margin, body =
firstPoint.y - margin, 2 * margin, 2 * margin + 2 new RoundRectangle2D.Double(firstPoint.x - margin, firstPoint.y - margin, 2 * margin, 2 * margin + 2
* spacing, margin, margin); * spacing, margin, margin);
break; break;
case DPDT: case DPDT:
body = new RoundRectangle2D.Double(firstPoint.x - margin, body =
firstPoint.y - margin, 2 * margin + spacing, 2 * margin new RoundRectangle2D.Double(firstPoint.x - margin, firstPoint.y - margin, 2 * margin + spacing, 2
+ 2 * spacing, margin, margin); * margin + 2 * spacing, margin, margin);
break; break;
case _3PDT: case _3PDT:
body = new RoundRectangle2D.Double(firstPoint.x - margin, body =
firstPoint.y - margin, 2 * margin + 2 * spacing, 2 new RoundRectangle2D.Double(firstPoint.x - margin, firstPoint.y - margin, 2 * margin + 2 * spacing, 2
* margin + 2 * spacing, margin, margin); * margin + 2 * spacing, margin, margin);
break; break;
case _4PDT: case _4PDT:
body = new RoundRectangle2D.Double(firstPoint.x - margin, body =
firstPoint.y - margin, 2 * margin + 3 * spacing, 2 new RoundRectangle2D.Double(firstPoint.x - margin, firstPoint.y - margin, 2 * margin + 3 * spacing, 2
* margin + 2 * spacing, margin, margin); * margin + 2 * spacing, margin, margin);
break; break;
case _5PDT: case _5PDT:
body = new RoundRectangle2D.Double(firstPoint.x - margin, body =
firstPoint.y - margin, 2 * margin + 4 * spacing, 2 new RoundRectangle2D.Double(firstPoint.x - margin, firstPoint.y - margin, 2 * margin + 4 * spacing, 2
* margin + 2 * spacing, margin, margin); * margin + 2 * spacing, margin, margin);
break; break;
} }
if (getOrientation() == OrientationHV.HORIZONTAL) { if (getOrientation() == OrientationHV.HORIZONTAL) {
AffineTransform xform = AffineTransform.getRotateInstance( AffineTransform xform = AffineTransform.getRotateInstance(-Math.PI / 2, firstPoint.x, firstPoint.y);
-Math.PI / 2, firstPoint.x, firstPoint.y);
body = new Area(body); body = new Area(body);
((Area) body).transform(xform); ((Area) body).transform(xform);
} }
@@ -325,18 +290,15 @@ public class MiniToggleSwitch extends
public void drawIcon(Graphics2D g2d, int width, int height) { public void drawIcon(Graphics2D g2d, int width, int height) {
int circleSize = 5 * width / 32; int circleSize = 5 * width / 32;
g2d.setColor(BODY_COLOR); g2d.setColor(BODY_COLOR);
g2d.fillRoundRect(width / 4, 1, width / 2, height - 2, circleSize, g2d.fillRoundRect(width / 4, 1, width / 2, height - 2, circleSize, circleSize);
circleSize);
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.drawRoundRect(width / 4, 1, width / 2, height - 2, circleSize, g2d.drawRoundRect(width / 4, 1, width / 2, height - 2, circleSize, circleSize);
circleSize);
for (int i = 1; i <= 3; i++) { for (int i = 1; i <= 3; i++) {
g2d.setColor(CIRCLE_COLOR); g2d.setColor(CIRCLE_COLOR);
g2d.fillOval(width / 2 - circleSize / 2, i * height / 4 - 3, g2d.fillOval(width / 2 - circleSize / 2, i * height / 4 - 3, circleSize, circleSize);
circleSize, circleSize);
g2d.setColor(METAL_COLOR); g2d.setColor(METAL_COLOR);
g2d.drawLine(width / 2 - circleSize / 2 + 1, i * height / 4 - 1, g2d.drawLine(width / 2 - circleSize / 2 + 1, i * height / 4 - 1, width / 2 + circleSize / 2 - 1, i * height / 4
width / 2 + circleSize / 2 - 1, i * height / 4 - 1); - 1);
} }
} }
} }
@@ -28,7 +28,9 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Plastic DC Jack", category = "Electromechanical", author = "Branislav Stojkovic", description = "Panel mount plastic DC jack", stretchable = false, zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "J", autoEdit = false, rotatable = false) @ComponentDescriptor(name = "Plastic DC Jack", category = "Electromechanical", author = "Branislav Stojkovic",
description = "Panel mount plastic DC jack", stretchable = false, zOrder = IDIYComponent.COMPONENT,
instanceNamePrefix = "J", autoEdit = false, rotatable = false)
public class PlasticDCJack extends AbstractTransparentComponent<String> { public class PlasticDCJack extends AbstractTransparentComponent<String> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -42,8 +44,7 @@ public class PlasticDCJack extends AbstractTransparentComponent<String> {
private static Color BORDER_COLOR = Color.black; private static Color BORDER_COLOR = Color.black;
private static Color MARKING_COLOR = Color.lightGray; private static Color MARKING_COLOR = Color.lightGray;
private Point[] controlPoints = new Point[] { new Point(0, 0), private Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0)};
new Point(0, 0), new Point(0, 0) };
private String value = ""; private String value = "";
private DCPolarity polarity = DCPolarity.CENTER_NEGATIVE; private DCPolarity polarity = DCPolarity.CENTER_NEGATIVE;
transient private Shape[] body; transient private Shape[] body;
@@ -72,25 +73,21 @@ public class PlasticDCJack extends AbstractTransparentComponent<String> {
int y = controlPoints[0].y; int y = controlPoints[0].y;
int spacing = (int) SPACING.convertToPixels(); int spacing = (int) SPACING.convertToPixels();
int diameter = getClosestOdd(DIAMETER.convertToPixels()); int diameter = getClosestOdd(DIAMETER.convertToPixels());
body[0] = new Ellipse2D.Double(x - diameter / 2, y + spacing body[0] = new Ellipse2D.Double(x - diameter / 2, y + spacing - diameter / 2, diameter, diameter);
- diameter / 2, diameter, diameter);
int rectWidth = (int) (diameter / Math.sqrt(2)) - 2; int rectWidth = (int) (diameter / Math.sqrt(2)) - 2;
body[1] = new Rectangle(x - rectWidth / 2, y + spacing - rectWidth body[1] = new Rectangle(x - rectWidth / 2, y + spacing - rectWidth / 2, rectWidth, rectWidth);
/ 2, rectWidth, rectWidth);
int lugWidth = getClosestOdd(LUG_WIDTH.convertToPixels()); int lugWidth = getClosestOdd(LUG_WIDTH.convertToPixels());
int lugThickness = getClosestOdd(LUG_THICKNESS.convertToPixels()); int lugThickness = getClosestOdd(LUG_THICKNESS.convertToPixels());
Point groundPoint = controlPoints[controlPoints.length - 1]; Point groundPoint = controlPoints[controlPoints.length - 1];
Area groundLug = new Area(new Ellipse2D.Double(groundPoint.x Area groundLug =
+ spacing - lugWidth / 2, groundPoint.y - lugWidth / 2, new Area(new Ellipse2D.Double(groundPoint.x + spacing - lugWidth / 2, groundPoint.y - lugWidth / 2, lugWidth,
lugWidth, lugWidth)); lugWidth));
groundLug.add(new Area(new Rectangle(groundPoint.x, groundPoint.y groundLug.add(new Area(new Rectangle(groundPoint.x, groundPoint.y - lugWidth / 2, spacing, lugWidth)));
- lugWidth / 2, spacing, lugWidth))); groundLug.subtract(new Area(new Ellipse2D.Double(groundPoint.x + spacing - lugWidth / 6, groundPoint.y - lugWidth
groundLug.subtract(new Area(new Ellipse2D.Double(groundPoint.x / 6, lugWidth / 3, lugWidth / 3)));
+ spacing - lugWidth / 6, groundPoint.y - lugWidth / 6,
lugWidth / 3, lugWidth / 3)));
body[2] = groundLug; body[2] = groundLug;
Area lugArea = new Area(); Area lugArea = new Area();
@@ -98,13 +95,10 @@ public class PlasticDCJack extends AbstractTransparentComponent<String> {
Point point = controlPoints[i]; Point point = controlPoints[i];
if (i == getControlPointCount() - 1) { if (i == getControlPointCount() - 1) {
lugArea.add(new Area( lugArea.add(new Area(
new Rectangle(point.x - lugThickness / 2, point.y new Rectangle(point.x - lugThickness / 2, point.y - lugWidth / 2, lugThickness, lugWidth)));
- lugWidth / 2, lugThickness, lugWidth)));
} else { } else {
lugArea lugArea.add(new Area(
.add(new Area(new Rectangle(point.x - lugWidth / 2, new Rectangle(point.x - lugWidth / 2, point.y - lugThickness / 2, lugWidth, lugThickness)));
point.y - lugThickness / 2, lugWidth,
lugThickness)));
} }
} }
body[3] = lugArea; body[3] = lugArea;
@@ -113,8 +107,7 @@ public class PlasticDCJack extends AbstractTransparentComponent<String> {
} }
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
boolean outlineMode, Project project,
IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
Shape[] body = getBody(); Shape[] body = getBody();
@@ -122,12 +115,9 @@ public class PlasticDCJack extends AbstractTransparentComponent<String> {
if (componentState != ComponentState.DRAGGING) { if (componentState != ComponentState.DRAGGING) {
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance( g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
} }
g2d g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : BODY_COLOR);
.setColor(outlineMode ? Constants.TRANSPARENT_COLOR
: BODY_COLOR);
g2d.fill(body[0]); g2d.fill(body[0]);
if (!outlineMode) { if (!outlineMode) {
g2d.setColor(PHENOLIC_COLOR); g2d.setColor(PHENOLIC_COLOR);
@@ -136,16 +126,15 @@ public class PlasticDCJack extends AbstractTransparentComponent<String> {
g2d.setComposite(oldComposite); g2d.setComposite(oldComposite);
} }
Theme theme = (Theme) ConfigurationManager.getInstance().readObject( Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
Color finalBorderColor; Color finalBorderColor;
if (outlineMode) { if (outlineMode) {
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: theme.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: BORDER_COLOR; : BORDER_COLOR;
} }
@@ -164,22 +153,17 @@ public class PlasticDCJack extends AbstractTransparentComponent<String> {
g2d.fill(body[3]); g2d.fill(body[3]);
} }
g2d.setColor(outlineMode ? theme.getOutlineColor() : METAL_COLOR g2d.setColor(outlineMode ? theme.getOutlineColor() : METAL_COLOR.darker());
.darker());
g2d.draw(body[3]); g2d.draw(body[3]);
if (!outlineMode && getPolarity() != DCPolarity.NONE) { if (!outlineMode && getPolarity() != DCPolarity.NONE) {
int spacing = (int) SPACING.convertToPixels(); int spacing = (int) SPACING.convertToPixels();
g2d.setColor(MARKING_COLOR); g2d.setColor(MARKING_COLOR);
g2d.setFont(LABEL_FONT.deriveFont(12f)); g2d.setFont(LABEL_FONT.deriveFont(12f));
drawCenteredText(g2d, drawCenteredText(g2d, getPolarity() == DCPolarity.CENTER_NEGATIVE ? "+" : "-", controlPoints[0].x,
getPolarity() == DCPolarity.CENTER_NEGATIVE ? "+" : "-", controlPoints[0].y - spacing * 7 / 16, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
controlPoints[0].x, controlPoints[0].y - spacing * 7 / 16, drawCenteredText(g2d, getPolarity() == DCPolarity.CENTER_NEGATIVE ? "_" : "+", controlPoints[2].x,
HorizontalAlignment.CENTER, VerticalAlignment.CENTER); controlPoints[2].y - spacing * 3 / 4, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
drawCenteredText(g2d,
getPolarity() == DCPolarity.CENTER_NEGATIVE ? "_" : "+",
controlPoints[2].x, controlPoints[2].y - spacing * 3 / 4,
HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
} }
} }
@@ -188,32 +172,22 @@ public class PlasticDCJack extends AbstractTransparentComponent<String> {
int margin = 2 * 32 / width; int margin = 2 * 32 / width;
int diameter = getClosestOdd(width - margin); int diameter = getClosestOdd(width - margin);
g2d.setColor(BODY_COLOR); g2d.setColor(BODY_COLOR);
g2d.fillOval((width - diameter) / 2, (height - diameter) / 2, diameter, g2d.fillOval((width - diameter) / 2, (height - diameter) / 2, diameter, diameter);
diameter);
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.drawOval((width - diameter) / 2, (height - diameter) / 2, diameter, g2d.drawOval((width - diameter) / 2, (height - diameter) / 2, diameter, diameter);
diameter); int rectWidth = getClosestOdd(((width - 2 * margin) / Math.sqrt(2)) - margin / 2);
int rectWidth = getClosestOdd(((width - 2 * margin) / Math.sqrt(2))
- margin / 2);
g2d.setColor(PHENOLIC_COLOR); g2d.setColor(PHENOLIC_COLOR);
g2d.fillRect((width - rectWidth) / 2, (height - rectWidth) / 2, g2d.fillRect((width - rectWidth) / 2, (height - rectWidth) / 2, rectWidth, rectWidth);
rectWidth, rectWidth);
g2d.setColor(PHENOLIC_COLOR.darker()); g2d.setColor(PHENOLIC_COLOR.darker());
g2d.drawRect((width - rectWidth) / 2, (height - rectWidth) / 2, g2d.drawRect((width - rectWidth) / 2, (height - rectWidth) / 2, rectWidth, rectWidth);
rectWidth, rectWidth);
int lugWidth = 4 * 32 / width; int lugWidth = 4 * 32 / width;
g2d.setColor(METAL_COLOR); g2d.setColor(METAL_COLOR);
g2d.drawLine((width - lugWidth) / 2, height / 3, g2d.drawLine((width - lugWidth) / 2, height / 3, (width + lugWidth) / 2, height / 3);
(width + lugWidth) / 2, height / 3); g2d.drawLine(width * 2 / 3, (height - lugWidth) / 2, width * 2 / 3, (height + lugWidth) / 2);
g2d.drawLine(width * 2 / 3, (height - lugWidth) / 2, width * 2 / 3, g2d.fillOval((width - lugWidth) / 2, height * 2 / 3 - lugWidth / 2, lugWidth, lugWidth);
(height + lugWidth) / 2); g2d.fillRect(width / 2 - lugWidth * 3 / 2, height * 2 / 3 - lugWidth / 2, lugWidth * 3 / 2, lugWidth);
g2d.fillOval((width - lugWidth) / 2, height * 2 / 3 - lugWidth / 2,
lugWidth, lugWidth);
g2d.fillRect(width / 2 - lugWidth * 3 / 2, height * 2 / 3 - lugWidth
/ 2, lugWidth * 3 / 2, lugWidth);
g2d.setColor(PHENOLIC_COLOR); g2d.setColor(PHENOLIC_COLOR);
g2d.fillOval((width - margin) / 2, height * 2 / 3 - margin / 2, margin, g2d.fillOval((width - margin) / 2, height * 2 / 3 - margin / 2, margin, margin);
margin);
} }
@Override @Override
@@ -31,7 +31,9 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Humbucker Pickup", category = "Guitar", author = "Branislav Stojkovic", description = "PAF-style humbucker guitar pickup", stretchable = false, zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "PKP", autoEdit = false) @ComponentDescriptor(name = "Humbucker Pickup", category = "Guitar", author = "Branislav Stojkovic",
description = "PAF-style humbucker guitar pickup", stretchable = false, zOrder = IDIYComponent.COMPONENT,
instanceNamePrefix = "PKP", autoEdit = false)
public class HumbuckerPickup extends AbstractTransparentComponent<String> { public class HumbuckerPickup extends AbstractTransparentComponent<String> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -57,16 +59,15 @@ public class HumbuckerPickup extends AbstractTransparentComponent<String> {
private Color color = BODY_COLOR; private Color color = BODY_COLOR;
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
Project project, IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
Shape[] body = getBody(); Shape[] body = getBody();
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
if (componentState != ComponentState.DRAGGING) { if (componentState != ComponentState.DRAGGING) {
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
/ MAX_ALPHA));
} }
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : color); g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : color);
g2d.fill(body[0]); g2d.fill(body[0]);
@@ -78,14 +79,15 @@ public class HumbuckerPickup extends AbstractTransparentComponent<String> {
Color finalBorderColor; Color finalBorderColor;
if (outlineMode) { if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject( Theme theme =
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : theme componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : color.darker(); componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: color.darker();
} }
g2d.setColor(finalBorderColor); g2d.setColor(finalBorderColor);
@@ -98,21 +100,21 @@ public class HumbuckerPickup extends AbstractTransparentComponent<String> {
Color finalLabelColor; Color finalLabelColor;
if (outlineMode) { if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject( Theme theme =
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalLabelColor = componentState == ComponentState.SELECTED finalLabelColor =
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED : theme componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalLabelColor = componentState == ComponentState.SELECTED finalLabelColor =
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: LABEL_COLOR; : LABEL_COLOR;
} }
g2d.setColor(finalLabelColor); g2d.setColor(finalLabelColor);
g2d.setFont(LABEL_FONT); g2d.setFont(LABEL_FONT);
Rectangle bounds = body[0].getBounds(); Rectangle bounds = body[0].getBounds();
drawCenteredText(g2d, value, bounds.x + bounds.width / 2, bounds.y + bounds.height / 2, drawCenteredText(g2d, value, bounds.x + bounds.width / 2, bounds.y + bounds.height / 2, HorizontalAlignment.CENTER,
HorizontalAlignment.CENTER, VerticalAlignment.CENTER); VerticalAlignment.CENTER);
} }
public Shape[] getBody() { public Shape[] getBody() {
@@ -130,21 +132,20 @@ public class HumbuckerPickup extends AbstractTransparentComponent<String> {
int pointSize = getClosestOdd(POINT_SIZE.convertToPixels()); int pointSize = getClosestOdd(POINT_SIZE.convertToPixels());
int lipHoleSize = getClosestOdd(LIP_HOLE_SIZE.convertToPixels()); int lipHoleSize = getClosestOdd(LIP_HOLE_SIZE.convertToPixels());
body[0] = new Area(new RoundRectangle2D.Double(x + pointMargin - length, y body[0] =
- pointMargin, length, width, edgeRadius, edgeRadius)); new Area(new RoundRectangle2D.Double(x + pointMargin - length, y - pointMargin, length, width, edgeRadius,
body[1] = new Area(new RoundRectangle2D.Double(x + pointMargin - length - lipLength, y edgeRadius));
- pointMargin + width / 2 - lipWidth / 2, length + 2 * lipLength, lipWidth, body[1] =
edgeRadius / 2, edgeRadius / 2)); new Area(new RoundRectangle2D.Double(x + pointMargin - length - lipLength, y - pointMargin + width / 2
- lipWidth / 2, length + 2 * lipLength, lipWidth, edgeRadius / 2, edgeRadius / 2));
Area lipArea = new Area(body[1]); Area lipArea = new Area(body[1]);
lipArea.subtract(new Area(body[0])); lipArea.subtract(new Area(body[0]));
lipArea.subtract(new Area(new Ellipse2D.Double( lipArea.subtract(new Area(new Ellipse2D.Double(x + pointMargin - length - lipLength / 2, y - pointMargin + width
x + pointMargin - length - lipLength / 2, y - pointMargin + width / 2 / 2 - lipHoleSize / 2, lipHoleSize, lipHoleSize)));
lipArea.subtract(new Area(new Ellipse2D.Double(x + pointMargin + lipLength / 2, y - pointMargin + width / 2
- lipHoleSize / 2, lipHoleSize, lipHoleSize))); - lipHoleSize / 2, lipHoleSize, lipHoleSize)));
lipArea.subtract(new Area(new Ellipse2D.Double(x + pointMargin + lipLength / 2, y
- pointMargin + width / 2 - lipHoleSize / 2, lipHoleSize, lipHoleSize)));
body[1] = lipArea; body[1] = lipArea;
body[2] = new Area(new Ellipse2D.Double(x - pointSize / 2, y - pointSize / 2, body[2] = new Area(new Ellipse2D.Double(x - pointSize / 2, y - pointSize / 2, pointSize, pointSize));
pointSize, pointSize));
int poleSize = (int) POLE_SIZE.convertToPixels(); int poleSize = (int) POLE_SIZE.convertToPixels();
int poleSpacing = (int) POLE_SPACING.convertToPixels(); int poleSpacing = (int) POLE_SPACING.convertToPixels();
@@ -153,13 +154,13 @@ public class HumbuckerPickup extends AbstractTransparentComponent<String> {
int poleMargin = (length - poleSpacing * 5) / 2; int poleMargin = (length - poleSpacing * 5) / 2;
Area poleArea = new Area(); Area poleArea = new Area();
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
Ellipse2D pole = new Ellipse2D.Double(x + pointMargin - length + poleMargin + i Ellipse2D pole =
* poleSpacing - poleSize / 2, y - pointMargin + coilMargin - poleSize / 2, new Ellipse2D.Double(x + pointMargin - length + poleMargin + i * poleSpacing - poleSize / 2, y
poleSize, poleSize); - pointMargin + coilMargin - poleSize / 2, poleSize, poleSize);
poleArea.add(new Area(pole)); poleArea.add(new Area(pole));
pole = new Ellipse2D.Double(x + pointMargin - length + poleMargin + i * poleSpacing pole =
- poleSize / 2, y - pointMargin + width - coilMargin - poleSize / 2, new Ellipse2D.Double(x + pointMargin - length + poleMargin + i * poleSpacing - poleSize / 2, y
poleSize, poleSize); - pointMargin + width - coilMargin - poleSize / 2, poleSize, poleSize);
poleArea.add(new Area(pole)); poleArea.add(new Area(pole));
} }
body[3] = poleArea; body[3] = poleArea;
@@ -194,18 +195,16 @@ public class HumbuckerPickup extends AbstractTransparentComponent<String> {
int baseLength = 27 * width / 32; int baseLength = 27 * width / 32;
g2d.setColor(BODY_COLOR); g2d.setColor(BODY_COLOR);
g2d.fillRoundRect((width - baseWidth / 4) / 2, 0, baseWidth / 4, height - 1, g2d.fillRoundRect((width - baseWidth / 4) / 2, 0, baseWidth / 4, height - 1, 2 * width / 32, 2 * width / 32);
2 * width / 32, 2 * width / 32);
g2d.setColor(BODY_COLOR.darker()); g2d.setColor(BODY_COLOR.darker());
g2d.drawRoundRect((width - baseWidth / 4) / 2, 0, baseWidth / 4, height - 1, g2d.drawRoundRect((width - baseWidth / 4) / 2, 0, baseWidth / 4, height - 1, 2 * width / 32, 2 * width / 32);
2 * width / 32, 2 * width / 32);
g2d.setColor(BODY_COLOR); g2d.setColor(BODY_COLOR);
g2d.fillRoundRect((width - baseWidth) / 2, (height - baseLength) / 2, baseWidth, g2d.fillRoundRect((width - baseWidth) / 2, (height - baseLength) / 2, baseWidth, baseLength, 4 * width / 32,
baseLength, 4 * width / 32, 4 * width / 32); 4 * width / 32);
g2d.setColor(BODY_COLOR.darker()); g2d.setColor(BODY_COLOR.darker());
g2d.drawRoundRect((width - baseWidth) / 2, (height - baseLength) / 2, baseWidth, g2d.drawRoundRect((width - baseWidth) / 2, (height - baseLength) / 2, baseWidth, baseLength, 4 * width / 32,
baseLength, 4 * width / 32, 4 * width / 32); 4 * width / 32);
} }
@Override @Override
@@ -29,7 +29,9 @@
// import org.diylc.core.measures.SizeUnit; // import org.diylc.core.measures.SizeUnit;
// import org.diylc.utils.Constants; // import org.diylc.utils.Constants;
// //
////@ComponentDescriptor(name = "Les Paul Switch", category = "Guitar", author = "Branislav Stojkovic", description = "Les Paul-style 3 position switch", stretchable = false, zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "SW") // //@ComponentDescriptor(name = "Les Paul Switch", category = "Guitar", author =
// "Branislav Stojkovic", description = "Les Paul-style 3 position switch", stretchable = false,
// zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "SW")
// public class LPSwitch extends AbstractTransparentComponent<String> { // public class LPSwitch extends AbstractTransparentComponent<String> {
// //
// private static final long serialVersionUID = 1L; // private static final long serialVersionUID = 1L;
@@ -29,7 +29,9 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Lever Switch", category = "Guitar", author = "Branislav Stojkovic", description = "Strat-style lever switch", stretchable = false, zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "SW") @ComponentDescriptor(name = "Lever Switch", category = "Guitar", author = "Branislav Stojkovic",
description = "Strat-style lever switch", stretchable = false, zOrder = IDIYComponent.COMPONENT,
instanceNamePrefix = "SW")
public class LeverSwitch extends AbstractTransparentComponent<String> { public class LeverSwitch extends AbstractTransparentComponent<String> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -60,16 +62,15 @@ public class LeverSwitch extends AbstractTransparentComponent<String> {
} }
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
Project project, IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
Shape[] body = getBody(); Shape[] body = getBody();
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
if (componentState != ComponentState.DRAGGING) { if (componentState != ComponentState.DRAGGING) {
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
/ MAX_ALPHA));
} }
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : BASE_COLOR); g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : BASE_COLOR);
g2d.fill(body[0]); g2d.fill(body[0]);
@@ -80,30 +81,30 @@ public class LeverSwitch extends AbstractTransparentComponent<String> {
Color finalBorderColor; Color finalBorderColor;
if (outlineMode) { if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject( Theme theme =
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : theme componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : BASE_COLOR componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
.darker(); : BASE_COLOR.darker();
} }
g2d.setColor(finalBorderColor); g2d.setColor(finalBorderColor);
g2d.draw(body[0]); g2d.draw(body[0]);
if (outlineMode) { if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject( Theme theme =
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : theme componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : WAFER_COLOR componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
.darker(); : WAFER_COLOR.darker();
} }
g2d.draw(body[1]); g2d.draw(body[1]);
@@ -132,26 +133,23 @@ public class LeverSwitch extends AbstractTransparentComponent<String> {
int terminalWidth = getClosestOdd(TERMINAL_WIDTH.convertToPixels()); int terminalWidth = getClosestOdd(TERMINAL_WIDTH.convertToPixels());
int baseX = x - terminalLength / 2 - waferSpacing; int baseX = x - terminalLength / 2 - waferSpacing;
int baseY = y int baseY = y - (baseLength - terminalSpacing * (type == LeverSwitchType.DP3T ? 7 : 12)) / 2;
- (baseLength - terminalSpacing * (type == LeverSwitchType.DP3T ? 7 : 12)) / 2;
Area baseArea = new Area(new Rectangle2D.Double(baseX, baseY, baseWidth, baseLength)); Area baseArea = new Area(new Rectangle2D.Double(baseX, baseY, baseWidth, baseLength));
baseArea.subtract(new Area(new Ellipse2D.Double(baseX + baseWidth / 2 - holeSize / 2, baseArea.subtract(new Area(new Ellipse2D.Double(baseX + baseWidth / 2 - holeSize / 2, baseY
baseY + (baseLength - holeSpacing) / 2 - holeSize / 2, holeSize, holeSize))); + (baseLength - holeSpacing) / 2 - holeSize / 2, holeSize, holeSize)));
baseArea.subtract(new Area(new Ellipse2D.Double(baseX + baseWidth / 2 - holeSize / 2, baseArea.subtract(new Area(new Ellipse2D.Double(baseX + baseWidth / 2 - holeSize / 2, baseY
baseY + (baseLength - holeSpacing) / 2 - holeSize / 2 + holeSpacing, holeSize, + (baseLength - holeSpacing) / 2 - holeSize / 2 + holeSpacing, holeSize, holeSize)));
holeSize)));
body[0] = baseArea; body[0] = baseArea;
Area waferArea = new Area(new Rectangle2D.Double(x - terminalLength / 2 Area waferArea =
- waferThickness / 2, new Area(new Rectangle2D.Double(x - terminalLength / 2 - waferThickness / 2, y
y - (waferLength - terminalSpacing * (type == LeverSwitchType.DP3T ? 7 : 12)) - (waferLength - terminalSpacing * (type == LeverSwitchType.DP3T ? 7 : 12)) / 2, waferThickness,
/ 2, waferThickness, waferLength)); waferLength));
if (type == LeverSwitchType._4P5T) { if (type == LeverSwitchType._4P5T) {
waferArea.add(new Area(new Rectangle2D.Double(x - terminalLength / 2 waferArea.add(new Area(new Rectangle2D.Double(x - terminalLength / 2 - waferThickness / 2 + waferSpacing, y
- waferThickness / 2 + waferSpacing, y - (waferLength - terminalSpacing * (type == LeverSwitchType.DP3T ? 7 : 12)) / 2, waferThickness,
- (waferLength - terminalSpacing * (type == LeverSwitchType.DP3T ? 7 : 12)) waferLength)));
/ 2, waferThickness, waferLength)));
} }
body[1] = waferArea; body[1] = waferArea;
@@ -173,17 +171,14 @@ public class LeverSwitch extends AbstractTransparentComponent<String> {
Area terminalArea = new Area(); Area terminalArea = new Area();
for (Point point : controlPoints) { for (Point point : controlPoints) {
Area terminal = new Area(new RoundRectangle2D.Double(point.x - terminalLength / 2, Area terminal =
point.y - terminalWidth / 2, terminalLength, terminalWidth, new Area(new RoundRectangle2D.Double(point.x - terminalLength / 2, point.y - terminalWidth / 2,
terminalWidth / 2, terminalWidth / 2)); terminalLength, terminalWidth, terminalWidth / 2, terminalWidth / 2));
terminal.subtract(new Area( terminal.subtract(new Area(new RoundRectangle2D.Double(point.x - terminalLength / 4, point.y - terminalWidth
new RoundRectangle2D.Double(point.x - terminalLength / 4, point.y / 4, terminalLength / 2, terminalWidth / 2, terminalWidth / 2, terminalWidth / 2)));
- terminalWidth / 4, terminalLength / 2, terminalWidth / 2,
terminalWidth / 2, terminalWidth / 2)));
// Rotate the terminal if needed // Rotate the terminal if needed
if (theta != 0) { if (theta != 0) {
AffineTransform rotation = AffineTransform.getRotateInstance(theta, point.x, AffineTransform rotation = AffineTransform.getRotateInstance(theta, point.x, point.y);
point.y);
terminal.transform(rotation); terminal.transform(rotation);
} }
terminalArea.add(terminal); terminalArea.add(terminal);
@@ -215,24 +210,20 @@ public class LeverSwitch extends AbstractTransparentComponent<String> {
case DP3T: case DP3T:
controlPoints = new Point[8]; controlPoints = new Point[8];
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
controlPoints[i] = new Point(x - (i % 2 == 1 ? terminalLength : 0), y + i controlPoints[i] = new Point(x - (i % 2 == 1 ? terminalLength : 0), y + i * terminalSpacing);
* terminalSpacing);
} }
break; break;
case DP5T: case DP5T:
controlPoints = new Point[12]; controlPoints = new Point[12];
for (int i = 0; i < 12; i++) { for (int i = 0; i < 12; i++) {
controlPoints[i] = new Point(x, y + i * terminalSpacing controlPoints[i] = new Point(x, y + i * terminalSpacing + (i >= 6 ? terminalSpacing : 0));
+ (i >= 6 ? terminalSpacing : 0));
} }
break; break;
case _4P5T: case _4P5T:
controlPoints = new Point[24]; controlPoints = new Point[24];
for (int i = 0; i < 12; i++) { for (int i = 0; i < 12; i++) {
controlPoints[i] = new Point(x, y + i * terminalSpacing controlPoints[i] = new Point(x, y + i * terminalSpacing + (i >= 6 ? terminalSpacing : 0));
+ (i >= 6 ? terminalSpacing : 0)); controlPoints[i + 12] = new Point(x + waferSpacing, y + i * terminalSpacing + (i >= 6 ? terminalSpacing : 0));
controlPoints[i + 12] = new Point(x + waferSpacing, y + i * terminalSpacing
+ (i >= 6 ? terminalSpacing : 0));
} }
break; break;
} }
@@ -272,19 +263,17 @@ public class LeverSwitch extends AbstractTransparentComponent<String> {
Area terminals = new Area(); Area terminals = new Area();
int terminalLength = getClosestOdd(11 * width / 32); int terminalLength = getClosestOdd(11 * width / 32);
int terminalWidth = getClosestOdd(7 * width / 32); int terminalWidth = getClosestOdd(7 * width / 32);
Area terminal = new Area(new RoundRectangle2D.Double(width / 16 * 7, 4 * width / 32, Area terminal =
terminalLength, terminalWidth, terminalWidth / 2, terminalWidth / 2)); new Area(new RoundRectangle2D.Double(width / 16 * 7, 4 * width / 32, terminalLength, terminalWidth,
terminal.subtract(new Area(new RoundRectangle2D.Double(width / 16 * 7 + terminalLength / 4 terminalWidth / 2, terminalWidth / 2));
+ 1, 4 * width / 32 + terminalWidth / 4 + 1, terminalLength / 2, terminalWidth / 2, terminal.subtract(new Area(new RoundRectangle2D.Double(width / 16 * 7 + terminalLength / 4 + 1, 4 * width / 32
terminalWidth / 4, terminalWidth / 4))); + terminalWidth / 4 + 1, terminalLength / 2, terminalWidth / 2, terminalWidth / 4, terminalWidth / 4)));
terminals.add(terminal); terminals.add(terminal);
terminal = new Area(terminal); terminal = new Area(terminal);
terminal.transform(AffineTransform.getTranslateInstance(-terminalLength, terminalWidth + 2 terminal.transform(AffineTransform.getTranslateInstance(-terminalLength, terminalWidth + 2 * width / 32));
* width / 32));
terminals.add(terminal); terminals.add(terminal);
terminal = new Area(terminal); terminal = new Area(terminal);
terminal.transform(AffineTransform.getTranslateInstance(terminalLength, terminalWidth + 2 terminal.transform(AffineTransform.getTranslateInstance(terminalLength, terminalWidth + 2 * width / 32));
* width / 32));
terminals.add(terminal); terminals.add(terminal);
g2d.setColor(METAL_COLOR); g2d.setColor(METAL_COLOR);
g2d.fill(terminals); g2d.fill(terminals);
@@ -32,7 +32,9 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Strat Single Coil Pickup", category = "Guitar", author = "Branislav Stojkovic", description = "Strat-style single coil guitar pickup", stretchable = false, zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "PKP", autoEdit = false) @ComponentDescriptor(name = "Strat Single Coil Pickup", category = "Guitar", author = "Branislav Stojkovic",
description = "Strat-style single coil guitar pickup", stretchable = false, zOrder = IDIYComponent.COMPONENT,
instanceNamePrefix = "PKP", autoEdit = false)
public class SingleCoilPickup extends AbstractTransparentComponent<String> { public class SingleCoilPickup extends AbstractTransparentComponent<String> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -56,16 +58,15 @@ public class SingleCoilPickup extends AbstractTransparentComponent<String> {
private Color color = BODY_COLOR; private Color color = BODY_COLOR;
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
Project project, IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
Shape[] body = getBody(); Shape[] body = getBody();
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
if (componentState != ComponentState.DRAGGING) { if (componentState != ComponentState.DRAGGING) {
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
/ MAX_ALPHA));
} }
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : color); g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : color);
g2d.fill(body[0]); g2d.fill(body[0]);
@@ -76,15 +77,15 @@ public class SingleCoilPickup extends AbstractTransparentComponent<String> {
Color finalBorderColor; Color finalBorderColor;
if (outlineMode) { if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject( Theme theme =
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : theme componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : color componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
.brighter(); : color.brighter();
} }
g2d.setColor(finalBorderColor); g2d.setColor(finalBorderColor);
@@ -95,21 +96,21 @@ public class SingleCoilPickup extends AbstractTransparentComponent<String> {
Color finalLabelColor; Color finalLabelColor;
if (outlineMode) { if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject( Theme theme =
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalLabelColor = componentState == ComponentState.SELECTED finalLabelColor =
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED : theme componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalLabelColor = componentState == ComponentState.SELECTED finalLabelColor =
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: LABEL_COLOR; : LABEL_COLOR;
} }
g2d.setColor(finalLabelColor); g2d.setColor(finalLabelColor);
g2d.setFont(LABEL_FONT); g2d.setFont(LABEL_FONT);
Rectangle bounds = body[0].getBounds(); Rectangle bounds = body[0].getBounds();
drawCenteredText(g2d, value, bounds.x + bounds.width / 2, bounds.y + bounds.height / 2, drawCenteredText(g2d, value, bounds.x + bounds.width / 2, bounds.y + bounds.height / 2, HorizontalAlignment.CENTER,
HorizontalAlignment.CENTER, VerticalAlignment.CENTER); VerticalAlignment.CENTER);
} }
public Shape[] getBody() { public Shape[] getBody() {
@@ -126,30 +127,29 @@ public class SingleCoilPickup extends AbstractTransparentComponent<String> {
int holeSize = getClosestOdd(HOLE_SIZE.convertToPixels()); int holeSize = getClosestOdd(HOLE_SIZE.convertToPixels());
int holeMargin = getClosestOdd(HOLE_MARGIN.convertToPixels()); int holeMargin = getClosestOdd(HOLE_MARGIN.convertToPixels());
Area mainArea = new Area(new RoundRectangle2D.Double(x - length / 2, y - lipWidth / 2 Area mainArea =
- width, length, width, width, width)); new Area(new RoundRectangle2D.Double(x - length / 2, y - lipWidth / 2 - width, length, width, width, width));
mainArea.add(new Area(new Polygon(new int[] { x - length / 2 + width / 2, mainArea.add(new Area(new Polygon(new int[] {x - length / 2 + width / 2, x + length / 2 - width / 2,
x + length / 2 - width / 2, x + lipLength / 2, x - lipLength / 2 }, new int[] { x + lipLength / 2, x - lipLength / 2}, new int[] {y - lipWidth / 2, y - lipWidth / 2, y + lipWidth / 2,
y - lipWidth / 2, y - lipWidth / 2, y + lipWidth / 2, y + lipWidth / 2 }, 4))); y + lipWidth / 2}, 4)));
// Cutout holes // Cutout holes
mainArea.subtract(new Area(new Ellipse2D.Double(x - length / 2 + holeMargin - holeSize mainArea.subtract(new Area(new Ellipse2D.Double(x - length / 2 + holeMargin - holeSize / 2, y - lipWidth / 2
/ 2, y - lipWidth / 2 - width / 2 - holeSize / 2, holeSize, holeSize))); - width / 2 - holeSize / 2, holeSize, holeSize)));
mainArea.subtract(new Area(new Ellipse2D.Double(x + length / 2 - holeMargin - holeSize mainArea.subtract(new Area(new Ellipse2D.Double(x + length / 2 - holeMargin - holeSize / 2, y - lipWidth / 2
/ 2, y - lipWidth / 2 - width / 2 - holeSize / 2, holeSize, holeSize))); - width / 2 - holeSize / 2, holeSize, holeSize)));
body[0] = mainArea; body[0] = mainArea;
body[1] = new Area(new Ellipse2D.Double(x - pointSize / 2, y - pointSize / 2, body[1] = new Area(new Ellipse2D.Double(x - pointSize / 2, y - pointSize / 2, pointSize, pointSize));
pointSize, pointSize));
int poleSize = (int) POLE_SIZE.convertToPixels(); int poleSize = (int) POLE_SIZE.convertToPixels();
int poleSpacing = (int) POLE_SPACING.convertToPixels(); int poleSpacing = (int) POLE_SPACING.convertToPixels();
int poleMargin = (length - poleSpacing * 5) / 2; int poleMargin = (length - poleSpacing * 5) / 2;
Area poleArea = new Area(); Area poleArea = new Area();
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
Ellipse2D pole = new Ellipse2D.Double( Ellipse2D pole =
x - length / 2 + poleMargin + i * poleSpacing, y - lipWidth / 2 - width / 2 new Ellipse2D.Double(x - length / 2 + poleMargin + i * poleSpacing, y - lipWidth / 2 - width / 2 - poleSize
- poleSize / 2, poleSize, poleSize); / 2, poleSize, poleSize);
poleArea.add(new Area(pole)); poleArea.add(new Area(pole));
} }
body[2] = poleArea; body[2] = poleArea;
@@ -183,11 +183,9 @@ public class SingleCoilPickup extends AbstractTransparentComponent<String> {
int bodyWidth = 8 * width / 32; int bodyWidth = 8 * width / 32;
int bodyLength = 30 * width / 32; int bodyLength = 30 * width / 32;
g2d.setColor(BODY_COLOR); g2d.setColor(BODY_COLOR);
g2d.fillRoundRect((width - bodyWidth) / 2, (height - bodyLength) / 2, bodyWidth, g2d.fillRoundRect((width - bodyWidth) / 2, (height - bodyLength) / 2, bodyWidth, bodyLength, bodyWidth, bodyWidth);
bodyLength, bodyWidth, bodyWidth); g2d.fillPolygon(new int[] {width * 9 / 16, width * 9 / 16, width * 11 / 16, width * 11 / 16}, new int[] {
g2d.fillPolygon(new int[] { width * 9 / 16, width * 9 / 16, width * 11 / 16, width * 11 / 16 }, (height - bodyLength) / 2, (height + bodyLength) / 2, height * 5 / 8, height * 3 / 8}, 4);
new int[] { (height - bodyLength) / 2, (height + bodyLength) / 2, height * 5 / 8,
height * 3 / 8 }, 4);
g2d.setColor(Color.lightGray); g2d.setColor(Color.lightGray);
g2d.drawLine(width / 2, 4 * width / 32, width / 2, 4 * width / 32); g2d.drawLine(width / 2, 4 * width / 32, width / 2, 4 * width / 32);
@@ -23,7 +23,9 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.BomEntry; import org.diylc.utils.BomEntry;
import org.diylc.utils.BomMaker; import org.diylc.utils.BomMaker;
@ComponentDescriptor(name = "Bill of Materials", author = "Branislav Stojkovic", category = "Misc", description = "", instanceNamePrefix = "BOM", zOrder = IDIYComponent.TEXT, stretchable = false, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false) @ComponentDescriptor(name = "Bill of Materials", author = "Branislav Stojkovic", category = "Misc", description = "",
instanceNamePrefix = "BOM", zOrder = IDIYComponent.TEXT, stretchable = false, bomPolicy = BomPolicy.NEVER_SHOW,
autoEdit = false)
public class BOM extends AbstractComponent<Void> { public class BOM extends AbstractComponent<Void> {
public static Size DEFAULT_SIZE = new Size(10d, SizeUnit.cm); public static Size DEFAULT_SIZE = new Size(10d, SizeUnit.cm);
@@ -38,8 +40,8 @@ public class BOM extends AbstractComponent<Void> {
private Color color = COLOR; private Color color = COLOR;
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
Project project, IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
List<BomEntry> bom = BomMaker.getInstance().createBom(project.getComponents()); List<BomEntry> bom = BomMaker.getInstance().createBom(project.getComponents());
// Cleanup entries that do not have a value set. // Cleanup entries that do not have a value set.
Iterator<BomEntry> iterator = bom.iterator(); Iterator<BomEntry> iterator = bom.iterator();
@@ -50,8 +52,8 @@ public class BOM extends AbstractComponent<Void> {
} }
} }
g2d.setFont(LABEL_FONT); g2d.setFont(LABEL_FONT);
g2d.setColor(componentState == ComponentState.DRAGGING g2d.setColor(componentState == ComponentState.DRAGGING || componentState == ComponentState.SELECTED ? SELECTION_COLOR
|| componentState == ComponentState.SELECTED ? SELECTION_COLOR : getColor()); : getColor());
// Determine maximum name length and maximum value length to calculate // Determine maximum name length and maximum value length to calculate
// number of columns. // number of columns.
FontMetrics fontMetrics = g2d.getFontMetrics(); FontMetrics fontMetrics = g2d.getFontMetrics();
@@ -194,6 +196,5 @@ public class BOM extends AbstractComponent<Void> {
} }
@Override @Override
public void setValue(Void value) { public void setValue(Void value) {}
}
} }
@@ -18,7 +18,9 @@ import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size; import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Ground Symbol", author = "Branislav Stojkovic", category = "Schematics", instanceNamePrefix = "GND", description = "Ground schematic symbol", stretchable = false, zOrder = IDIYComponent.COMPONENT, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false) @ComponentDescriptor(name = "Ground Symbol", author = "Branislav Stojkovic", category = "Schematics",
instanceNamePrefix = "GND", description = "Ground schematic symbol", stretchable = false,
zOrder = IDIYComponent.COMPONENT, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false)
public class GroundSymbol extends AbstractComponent<Void> { public class GroundSymbol extends AbstractComponent<Void> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -32,8 +34,8 @@ public class GroundSymbol extends AbstractComponent<Void> {
private GroundSymbolType type = GroundSymbolType.DEFAULT; private GroundSymbolType type = GroundSymbolType.DEFAULT;
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
Project project, IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
int sizePx = (int) size.convertToPixels(); int sizePx = (int) size.convertToPixels();
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.setColor(color); g2d.setColor(color);
@@ -43,12 +45,13 @@ public class GroundSymbol extends AbstractComponent<Void> {
if (type == GroundSymbolType.DEFAULT) { if (type == GroundSymbolType.DEFAULT) {
int delta = sizePx / 7; int delta = sizePx / 7;
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
g2d.drawLine(x - sizePx / 2 + delta * i, y + sizePx / 6 * (i + 1), x + sizePx / 2 g2d.drawLine(x - sizePx / 2 + delta * i, y + sizePx / 6 * (i + 1), x + sizePx / 2 - delta * i, y + sizePx / 6
- delta * i, y + sizePx / 6 * (i + 1)); * (i + 1));
} }
} else { } else {
Polygon poly = new Polygon(new int[] { x - sizePx / 2, x + sizePx / 2, x }, new int[] { Polygon poly =
y + sizePx / 6, y + sizePx / 6, y + sizePx }, 3); new Polygon(new int[] {x - sizePx / 2, x + sizePx / 2, x}, new int[] {y + sizePx / 6, y + sizePx / 6,
y + sizePx}, 3);
g2d.draw(poly); g2d.draw(poly);
} }
} }
@@ -60,8 +63,8 @@ public class GroundSymbol extends AbstractComponent<Void> {
g2d.setColor(COLOR); g2d.setColor(COLOR);
g2d.drawLine(width / 2, margin * 2, width / 2, margin * 3 + height / 5); g2d.drawLine(width / 2, margin * 2, width / 2, margin * 3 + height / 5);
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
g2d.drawLine(margin * (i + 1), margin * (3 + i) + height / 5, width - margin * (i + 1), g2d.drawLine(margin * (i + 1), margin * (3 + i) + height / 5, width - margin * (i + 1), margin * (3 + i) + height
margin * (3 + i) + height / 5); / 5);
} }
} }
@@ -125,8 +128,7 @@ public class GroundSymbol extends AbstractComponent<Void> {
@Deprecated @Deprecated
@Override @Override
public void setValue(Void value) { public void setValue(Void value) {}
}
public static enum GroundSymbolType { public static enum GroundSymbolType {
DEFAULT("Default"), TRIANGLE("Triangle"); DEFAULT("Default"), TRIANGLE("Triangle");
@@ -22,7 +22,9 @@ import org.diylc.core.annotations.EditableProperty;
import com.thoughtworks.xstream.annotations.XStreamConverter; import com.thoughtworks.xstream.annotations.XStreamConverter;
@ComponentDescriptor(name = "Image", author = "Branislav Stojkovic", category = "Misc", description = "User defined image", instanceNamePrefix = "Img", zOrder = IDIYComponent.COMPONENT, flexibleZOrder = true, stretchable = false, bomPolicy = BomPolicy.NEVER_SHOW) @ComponentDescriptor(name = "Image", author = "Branislav Stojkovic", category = "Misc",
description = "User defined image", instanceNamePrefix = "Img", zOrder = IDIYComponent.COMPONENT,
flexibleZOrder = true, stretchable = false, bomPolicy = BomPolicy.NEVER_SHOW)
public class Image extends AbstractTransparentComponent<Void> { public class Image extends AbstractTransparentComponent<Void> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -44,30 +46,26 @@ public class Image extends AbstractTransparentComponent<Void> {
private byte scale = 50; private byte scale = 50;
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
boolean outlineMode, Project project,
IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
double s = 1d * scale / DEFAULT_SCALE; double s = 1d * scale / DEFAULT_SCALE;
Shape clip = g2d.getClip().getBounds(); Shape clip = g2d.getClip().getBounds();
if (!clip.intersects(new Rectangle2D.Double(point.getX(), point.getY(), if (!clip.intersects(new Rectangle2D.Double(point.getX(), point.getY(), image.getIconWidth() * s, image
image.getIconWidth() * s, image.getIconHeight() * s))) { .getIconHeight() * s))) {
return; return;
} }
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance( g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
} }
g2d.scale(s, s); g2d.scale(s, s);
g2d.drawImage(image.getImage(), (int) (point.x / s), g2d.drawImage(image.getImage(), (int) (point.x / s), (int) (point.y / s), null);
(int) (point.y / s), null);
if (componentState == ComponentState.SELECTED) { if (componentState == ComponentState.SELECTED) {
g2d.setComposite(oldComposite); g2d.setComposite(oldComposite);
g2d.scale(1 / s, 1 / s); g2d.scale(1 / s, 1 / s);
g2d.setColor(SELECTION_COLOR); g2d.setColor(SELECTION_COLOR);
g2d.drawRect(point.x, point.y, (int) (image.getIconWidth() * s), g2d.drawRect(point.x, point.y, (int) (image.getIconWidth() * s), (int) (image.getIconHeight() * s));
(int) (image.getIconHeight() * s));
} }
} }
@@ -130,6 +128,5 @@ public class Image extends AbstractTransparentComponent<Void> {
} }
@Override @Override
public void setValue(Void value) { public void setValue(Void value) {}
}
} }
@@ -20,7 +20,9 @@ import org.diylc.core.annotations.BomPolicy;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
@ComponentDescriptor(name = "Label", author = "Branislav Stojkovic", category = "Misc", description = "User defined label", instanceNamePrefix = "L", zOrder = IDIYComponent.TEXT, flexibleZOrder = true, stretchable = false, bomPolicy = BomPolicy.NEVER_SHOW) @ComponentDescriptor(name = "Label", author = "Branislav Stojkovic", category = "Misc",
description = "User defined label", instanceNamePrefix = "L", zOrder = IDIYComponent.TEXT, flexibleZOrder = true,
stretchable = false, bomPolicy = BomPolicy.NEVER_SHOW)
public class Label extends AbstractComponent<Void> { public class Label extends AbstractComponent<Void> {
public static String DEFAULT_TEXT = "Double click to edit text"; public static String DEFAULT_TEXT = "Double click to edit text";
@@ -38,12 +40,9 @@ public class Label extends AbstractComponent<Void> {
private Orientation orientation = Orientation.DEFAULT; private Orientation orientation = Orientation.DEFAULT;
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
boolean outlineMode, Project project,
IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
g2d g2d.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED : color);
.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED
: color);
g2d.setFont(font); g2d.setFont(font);
FontMetrics fontMetrics = g2d.getFontMetrics(); FontMetrics fontMetrics = g2d.getFontMetrics();
Rectangle2D rect = fontMetrics.getStringBounds(text, g2d); Rectangle2D rect = fontMetrics.getStringBounds(text, g2d);
@@ -64,8 +63,7 @@ public class Label extends AbstractComponent<Void> {
y = point.y + fontMetrics.getAscent(); y = point.y + fontMetrics.getAscent();
break; break;
default: default:
throw new RuntimeException("Unexpected alignment: " throw new RuntimeException("Unexpected alignment: " + getVerticalAlignment());
+ getVerticalAlignment());
} }
switch (getHorizontalAlignment()) { switch (getHorizontalAlignment()) {
case CENTER: case CENTER:
@@ -78,8 +76,7 @@ public class Label extends AbstractComponent<Void> {
x = point.x - textWidth; x = point.x - textWidth;
break; break;
default: default:
throw new RuntimeException("Unexpected alignment: " throw new RuntimeException("Unexpected alignment: " + getHorizontalAlignment());
+ getHorizontalAlignment());
} }
switch (getOrientation()) { switch (getOrientation()) {
@@ -99,8 +96,7 @@ public class Label extends AbstractComponent<Void> {
@Override @Override
public void drawIcon(Graphics2D g2d, int width, int height) { public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.setColor(LABEL_COLOR); g2d.setColor(LABEL_COLOR);
g2d.setFont(LABEL_FONT.deriveFont(13f * width / 32).deriveFont( g2d.setFont(LABEL_FONT.deriveFont(13f * width / 32).deriveFont(Font.PLAIN));
Font.PLAIN));
FontMetrics fontMetrics = g2d.getFontMetrics(); FontMetrics fontMetrics = g2d.getFontMetrics();
Rectangle2D rect = fontMetrics.getStringBounds("Abc", g2d); Rectangle2D rect = fontMetrics.getStringBounds("Abc", g2d);
@@ -268,6 +264,5 @@ public class Label extends AbstractComponent<Void> {
} }
@Override @Override
public void setValue(Void value) { public void setValue(Void value) {}
}
} }
@@ -21,7 +21,9 @@ import org.diylc.core.annotations.BomPolicy;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
@ComponentDescriptor(name = "PCB Text", author = "Branislav Stojkovic", category = "Misc", description = "Mirrored text for PCB artwork", instanceNamePrefix = "L", zOrder = IDIYComponent.TRACE, flexibleZOrder = false, stretchable = false, bomPolicy = BomPolicy.NEVER_SHOW) @ComponentDescriptor(name = "PCB Text", author = "Branislav Stojkovic", category = "Misc",
description = "Mirrored text for PCB artwork", instanceNamePrefix = "L", zOrder = IDIYComponent.TRACE,
flexibleZOrder = false, stretchable = false, bomPolicy = BomPolicy.NEVER_SHOW)
public class PCBText extends AbstractComponent<Void> { public class PCBText extends AbstractComponent<Void> {
public static String DEFAULT_TEXT = "Double click to edit text"; public static String DEFAULT_TEXT = "Double click to edit text";
@@ -39,12 +41,9 @@ public class PCBText extends AbstractComponent<Void> {
private Orientation orientation = Orientation.DEFAULT; private Orientation orientation = Orientation.DEFAULT;
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
boolean outlineMode, Project project,
IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
g2d g2d.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED : color);
.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED
: color);
g2d.setFont(font); g2d.setFont(font);
FontMetrics fontMetrics = g2d.getFontMetrics(); FontMetrics fontMetrics = g2d.getFontMetrics();
Rectangle2D rect = fontMetrics.getStringBounds(text, g2d); Rectangle2D rect = fontMetrics.getStringBounds(text, g2d);
@@ -65,8 +64,7 @@ public class PCBText extends AbstractComponent<Void> {
y = point.y + fontMetrics.getAscent(); y = point.y + fontMetrics.getAscent();
break; break;
default: default:
throw new RuntimeException("Unexpected alignment: " throw new RuntimeException("Unexpected alignment: " + getVerticalAlignment());
+ getVerticalAlignment());
} }
switch (getHorizontalAlignment()) { switch (getHorizontalAlignment()) {
case CENTER: case CENTER:
@@ -79,8 +77,7 @@ public class PCBText extends AbstractComponent<Void> {
x = point.x - textWidth; x = point.x - textWidth;
break; break;
default: default:
throw new RuntimeException("Unexpected alignment: " throw new RuntimeException("Unexpected alignment: " + getHorizontalAlignment());
+ getHorizontalAlignment());
} }
switch (getOrientation()) { switch (getOrientation()) {
@@ -106,8 +103,7 @@ public class PCBText extends AbstractComponent<Void> {
@Override @Override
public void drawIcon(Graphics2D g2d, int width, int height) { public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.setColor(LABEL_COLOR); g2d.setColor(LABEL_COLOR);
g2d.setFont(DEFAULT_FONT.deriveFont(15f * width / 32).deriveFont( g2d.setFont(DEFAULT_FONT.deriveFont(15f * width / 32).deriveFont(Font.BOLD));
Font.BOLD));
FontMetrics fontMetrics = g2d.getFontMetrics(); FontMetrics fontMetrics = g2d.getFontMetrics();
Rectangle2D rect = fontMetrics.getStringBounds("Abc", g2d); Rectangle2D rect = fontMetrics.getStringBounds("Abc", g2d);
@@ -277,6 +273,5 @@ public class PCBText extends AbstractComponent<Void> {
} }
@Override @Override
public void setValue(Void value) { public void setValue(Void value) {}
}
} }
@@ -9,8 +9,7 @@ import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.annotations.PositiveMeasureValidator; import org.diylc.core.annotations.PositiveMeasureValidator;
import org.diylc.core.measures.Resistance; import org.diylc.core.measures.Resistance;
public abstract class AbstractPotentiometer extends public abstract class AbstractPotentiometer extends AbstractTransparentComponent<Resistance> {
AbstractTransparentComponent<Resistance> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -47,8 +46,7 @@ public abstract class AbstractPotentiometer extends
@Override @Override
public String getValueForDisplay() { public String getValueForDisplay() {
return (resistance == null ? "" : resistance.toString()) + " " return (resistance == null ? "" : resistance.toString()) + " " + taper.toString();
+ taper.toString();
} }
@Override @Override
@@ -20,9 +20,10 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@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) @ComponentDescriptor(name = "Electrolytic Capacitor (axial)", author = "Branislav Stojkovic", category = "Passive",
public class AxialElectrolyticCapacitor extends creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "C",
AbstractLeadedComponent<Capacitance> { 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; private static final long serialVersionUID = 1L;
@@ -134,8 +135,7 @@ public class AxialElectrolyticCapacitor extends
@Override @Override
protected Shape getBodyShape() { protected Shape getBodyShape() {
return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(), return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(), getClosestOdd(getWidth().convertToPixels()));
getClosestOdd(getWidth().convertToPixels()));
} }
@Override @Override
@@ -145,27 +145,20 @@ public class AxialElectrolyticCapacitor extends
int markerLength = (int) (getLength().convertToPixels() * 0.2); int markerLength = (int) (getLength().convertToPixels() * 0.2);
if (!outlineMode) { if (!outlineMode) {
g2d.setColor(markerColor); g2d.setColor(markerColor);
g2d.fillRect( g2d.fillRect((int) getLength().convertToPixels() - markerLength, 0, markerLength, width);
(int) getLength().convertToPixels() - markerLength, 0,
markerLength, width);
} }
Color finalTickColor; Color finalTickColor;
if (outlineMode) { if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance() Theme theme =
.readObject(IPlugInPort.THEME_KEY, (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
Constants.DEFAULT_THEME);
finalTickColor = theme.getOutlineColor(); finalTickColor = theme.getOutlineColor();
} else { } else {
finalTickColor = tickColor; finalTickColor = tickColor;
} }
g2d.setColor(finalTickColor); g2d.setColor(finalTickColor);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2));
g2d.drawLine( g2d.drawLine((int) getLength().convertToPixels() - markerLength / 2, (int) (width / 2 - width * 0.15),
(int) getLength().convertToPixels() - markerLength / 2, (int) getLength().convertToPixels() - markerLength / 2, (int) (width / 2 + width * 0.15));
(int) (width / 2 - width * 0.15), (int) getLength()
.convertToPixels()
- markerLength / 2,
(int) (width / 2 + width * 0.15));
} }
} }
} }
@@ -15,7 +15,9 @@ import org.diylc.core.measures.Capacitance;
import org.diylc.core.measures.Size; import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; 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) @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> { public class AxialFilmCapacitor extends AbstractLeadedComponent<Capacitance> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -96,8 +98,7 @@ public class AxialFilmCapacitor extends AbstractLeadedComponent<Capacitance> {
@Override @Override
protected Shape getBodyShape() { protected Shape getBodyShape() {
return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(), return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(), getClosestOdd(getWidth().convertToPixels()));
getClosestOdd(getWidth().convertToPixels()));
} }
@EditableProperty(name = "Reverse (standing)") @EditableProperty(name = "Reverse (standing)")
@@ -14,7 +14,9 @@ import org.diylc.core.measures.Capacitance;
import org.diylc.core.measures.Size; import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Capacitor (schematic symbol)", author = "Branislav Stojkovic", category = "Schematics", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "C", description = "Capacitor schematic symbol with an optional polarity sign", zOrder = IDIYComponent.COMPONENT) @ComponentDescriptor(name = "Capacitor (schematic symbol)", author = "Branislav Stojkovic", category = "Schematics",
creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "C",
description = "Capacitor schematic symbol with an optional polarity sign", zOrder = IDIYComponent.COMPONENT)
public class CapacitorSymbol extends AbstractSchematicLeadedSymbol<Capacitance> { public class CapacitorSymbol extends AbstractSchematicLeadedSymbol<Capacitance> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -16,7 +16,9 @@ import org.diylc.core.measures.Resistance;
import org.diylc.core.measures.Size; import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Inductor (schematic symbol)", author = "Branislav Stojkovic", category = "Schematics", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "L", description = "Inductor schematic symbol", zOrder = IDIYComponent.COMPONENT) @ComponentDescriptor(name = "Inductor (schematic symbol)", author = "Branislav Stojkovic", category = "Schematics",
creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "L",
description = "Inductor schematic symbol", zOrder = IDIYComponent.COMPONENT)
public class InductorSymbol extends AbstractSchematicLeadedSymbol<Inductance> { public class InductorSymbol extends AbstractSchematicLeadedSymbol<Inductance> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -70,12 +72,9 @@ public class InductorSymbol extends AbstractSchematicLeadedSymbol<Inductance> {
GeneralPath polyline = new GeneralPath(); GeneralPath polyline = new GeneralPath();
polyline.moveTo(width / 8, height / 2); polyline.moveTo(width / 8, height / 2);
polyline.curveTo(width / 8, height / 4, width * 3 / 8, height / 4, polyline.curveTo(width / 8, height / 4, width * 3 / 8, height / 4, width * 3 / 8, height / 2);
width * 3 / 8, height / 2); polyline.curveTo(width * 3 / 8, height / 4, width * 5 / 8, height / 4, width * 5 / 8, height / 2);
polyline.curveTo(width * 3 / 8, height / 4, width * 5 / 8, height / 4, polyline.curveTo(width * 5 / 8, height / 4, width * 7 / 8, height / 4, width * 7 / 8, height / 2);
width * 5 / 8, height / 2);
polyline.curveTo(width * 5 / 8, height / 4, width * 7 / 8, height / 4,
width * 7 / 8, height / 2);
polyline.moveTo(width / 8, height * 6 / 10); polyline.moveTo(width / 8, height * 6 / 10);
polyline.lineTo(width * 7 / 8, height * 6 / 10); polyline.lineTo(width * 7 / 8, height * 6 / 10);
@@ -26,7 +26,9 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@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) @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 { public class PotentiometerPanel extends AbstractPotentiometer {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -46,8 +48,7 @@ public class PotentiometerPanel extends AbstractPotentiometer {
transient protected Area[] body = null; transient protected Area[] body = null;
public PotentiometerPanel() { public PotentiometerPanel() {
controlPoints = new Point[] { new Point(0, 0), new Point(0, 0), controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0)};
new Point(0, 0) };
updateControlPoints(); updateControlPoints();
} }
@@ -55,28 +56,20 @@ public class PotentiometerPanel extends AbstractPotentiometer {
int spacing = (int) this.spacing.convertToPixels(); int spacing = (int) this.spacing.convertToPixels();
switch (orientation) { switch (orientation) {
case DEFAULT: case DEFAULT:
controlPoints[1].setLocation(controlPoints[0].x + spacing, controlPoints[1].setLocation(controlPoints[0].x + spacing, controlPoints[0].y);
controlPoints[0].y); controlPoints[2].setLocation(controlPoints[0].x + 2 * spacing, controlPoints[0].y);
controlPoints[2].setLocation(controlPoints[0].x + 2 * spacing,
controlPoints[0].y);
break; break;
case _90: case _90:
controlPoints[1].setLocation(controlPoints[0].x, controlPoints[0].y controlPoints[1].setLocation(controlPoints[0].x, controlPoints[0].y + spacing);
+ spacing); controlPoints[2].setLocation(controlPoints[0].x, controlPoints[0].y + 2 * spacing);
controlPoints[2].setLocation(controlPoints[0].x, controlPoints[0].y
+ 2 * spacing);
break; break;
case _180: case _180:
controlPoints[1].setLocation(controlPoints[0].x - spacing, controlPoints[1].setLocation(controlPoints[0].x - spacing, controlPoints[0].y);
controlPoints[0].y); controlPoints[2].setLocation(controlPoints[0].x - 2 * spacing, controlPoints[0].y);
controlPoints[2].setLocation(controlPoints[0].x - 2 * spacing,
controlPoints[0].y);
break; break;
case _270: case _270:
controlPoints[1].setLocation(controlPoints[0].x, controlPoints[0].y controlPoints[1].setLocation(controlPoints[0].x, controlPoints[0].y - spacing);
- spacing); controlPoints[2].setLocation(controlPoints[0].x, controlPoints[0].y - 2 * spacing);
controlPoints[2].setLocation(controlPoints[0].x, controlPoints[0].y
- 2 * spacing);
break; break;
default: default:
break; break;
@@ -93,56 +86,51 @@ public class PotentiometerPanel extends AbstractPotentiometer {
int lugDiameter = getClosestOdd(this.lugDiameter.convertToPixels()); int lugDiameter = getClosestOdd(this.lugDiameter.convertToPixels());
int holeDiameter = getClosestOdd(this.lugDiameter.convertToPixels() / 2); int holeDiameter = getClosestOdd(this.lugDiameter.convertToPixels() / 2);
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
Area area = new Area(new Ellipse2D.Double(controlPoints[i].x Area area =
- lugDiameter / 2, new Area(new Ellipse2D.Double(controlPoints[i].x - lugDiameter / 2, controlPoints[i].y - lugDiameter / 2,
controlPoints[i].y - lugDiameter / 2, lugDiameter, lugDiameter, lugDiameter));
lugDiameter));
body[4 + i] = area; body[4 + i] = area;
} }
switch (orientation) { switch (orientation) {
case DEFAULT: case DEFAULT:
body[3] = new Area(new Ellipse2D.Double(controlPoints[0].x body[3] =
+ spacing - diameter / 2, controlPoints[0].y - spacing new Area(new Ellipse2D.Double(controlPoints[0].x + spacing - diameter / 2, controlPoints[0].y - spacing
/ 2 - diameter, diameter, diameter)); / 2 - diameter, diameter, diameter));
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
body[i] = new Area(new Rectangle2D.Double( body[i] =
controlPoints[i].x - holeDiameter / 2, new Area(new Rectangle2D.Double(controlPoints[i].x - holeDiameter / 2, controlPoints[i].y
controlPoints[i].y - (spacing + diameter) / 2, - (spacing + diameter) / 2, holeDiameter, (spacing + diameter) / 2));
holeDiameter, (spacing + diameter) / 2));
} }
break; break;
case _90: case _90:
body[3] = new Area(new Ellipse2D.Double(controlPoints[0].x body[3] =
+ spacing / 2, controlPoints[0].y + spacing - diameter new Area(new Ellipse2D.Double(controlPoints[0].x + spacing / 2, controlPoints[0].y + spacing - diameter
/ 2, diameter, diameter)); / 2, diameter, diameter));
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
body[i] = new Area(new Rectangle2D.Double( body[i] =
controlPoints[i].x, controlPoints[i].y new Area(new Rectangle2D.Double(controlPoints[i].x, controlPoints[i].y - holeDiameter / 2,
- holeDiameter / 2,
(spacing + diameter) / 2, holeDiameter)); (spacing + diameter) / 2, holeDiameter));
} }
break; break;
case _180: case _180:
body[3] = new Area(new Ellipse2D.Double(controlPoints[0].x body[3] =
- spacing - diameter / 2, controlPoints[0].y + spacing new Area(new Ellipse2D.Double(controlPoints[0].x - spacing - diameter / 2, controlPoints[0].y + spacing
/ 2, diameter, diameter)); / 2, diameter, diameter));
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
body[i] = new Area(new Rectangle2D.Double( body[i] =
controlPoints[i].x - holeDiameter / 2, new Area(new Rectangle2D.Double(controlPoints[i].x - holeDiameter / 2, controlPoints[i].y,
controlPoints[i].y, holeDiameter, holeDiameter, (spacing + diameter) / 2));
(spacing + diameter) / 2));
} }
break; break;
case _270: case _270:
body[3] = new Area(new Ellipse2D.Double(controlPoints[0].x body[3] =
- spacing / 2 - diameter, controlPoints[0].y - spacing new Area(new Ellipse2D.Double(controlPoints[0].x - spacing / 2 - diameter, controlPoints[0].y - spacing
- diameter / 2, diameter, diameter)); - diameter / 2, diameter, diameter));
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
body[i] = new Area(new Rectangle2D.Double( body[i] =
controlPoints[i].x - (spacing + diameter) / 2, new Area(new Rectangle2D.Double(controlPoints[i].x - (spacing + diameter) / 2, controlPoints[i].y
controlPoints[i].y - holeDiameter / 2, - holeDiameter / 2, (spacing + diameter) / 2, holeDiameter));
(spacing + diameter) / 2, holeDiameter));
} }
break; break;
default: default:
@@ -155,10 +143,8 @@ public class PotentiometerPanel extends AbstractPotentiometer {
} }
// Make holes in the lugs. // Make holes in the lugs.
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
body[4 + i].subtract(new Area(new Ellipse2D.Double( body[4 + i].subtract(new Area(new Ellipse2D.Double(controlPoints[i].x - holeDiameter / 2, controlPoints[i].y
controlPoints[i].x - holeDiameter / 2, - holeDiameter / 2, holeDiameter, holeDiameter)));
controlPoints[i].y - holeDiameter / 2, holeDiameter,
holeDiameter)));
} }
} }
return body; return body;
@@ -178,19 +164,16 @@ public class PotentiometerPanel extends AbstractPotentiometer {
} }
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
boolean outlineMode, Project project,
IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
Theme theme = (Theme) ConfigurationManager.getInstance().readObject( Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
for (Area shape : getBody()) { for (Area shape : getBody()) {
if (shape != null) { if (shape != null) {
g2d.setColor(bodyColor); g2d.setColor(bodyColor);
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance( g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
} }
if (!outlineMode) { if (!outlineMode) {
g2d.fill(shape); g2d.fill(shape);
@@ -198,12 +181,12 @@ public class PotentiometerPanel extends AbstractPotentiometer {
g2d.setComposite(oldComposite); g2d.setComposite(oldComposite);
Color finalBorderColor; Color finalBorderColor;
if (outlineMode) { if (outlineMode) {
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: theme.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: borderColor; : borderColor;
} }
g2d.setColor(finalBorderColor); g2d.setColor(finalBorderColor);
@@ -214,12 +197,12 @@ public class PotentiometerPanel extends AbstractPotentiometer {
g2d.setFont(LABEL_FONT); g2d.setFont(LABEL_FONT);
Color finalLabelColor; Color finalLabelColor;
if (outlineMode) { if (outlineMode) {
finalLabelColor = componentState == ComponentState.SELECTED finalLabelColor =
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: theme.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalLabelColor = componentState == ComponentState.SELECTED finalLabelColor =
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: LABEL_COLOR; : LABEL_COLOR;
} }
g2d.setColor(finalLabelColor); g2d.setColor(finalLabelColor);
@@ -235,8 +218,7 @@ public class PotentiometerPanel extends AbstractPotentiometer {
int x = (panelWidth - textWidth) / 2; int x = (panelWidth - textWidth) / 2;
int y = panelHeight / 2 - textHeight + fontMetrics.getAscent(); int y = panelHeight / 2 - textHeight + fontMetrics.getAscent();
g2d.drawString(getName(), (int) (bodyRect.getX() + x), (int) (bodyRect g2d.drawString(getName(), (int) (bodyRect.getX() + x), (int) (bodyRect.getY() + y));
.getY() + y));
// Draw value. // Draw value.
rect = fontMetrics.getStringBounds(getValueForDisplay(), g2d); rect = fontMetrics.getStringBounds(getValueForDisplay(), g2d);
@@ -247,8 +229,7 @@ public class PotentiometerPanel extends AbstractPotentiometer {
x = (panelWidth - textWidth) / 2; x = (panelWidth - textWidth) / 2;
y = panelHeight / 2 + fontMetrics.getAscent(); y = panelHeight / 2 + fontMetrics.getAscent();
g2d.drawString(getValueForDisplay(), (int) (bodyRect.getX() + x), g2d.drawString(getValueForDisplay(), (int) (bodyRect.getX() + x), (int) (bodyRect.getY() + y));
(int) (bodyRect.getY() + y));
} }
@Override @Override
@@ -256,27 +237,19 @@ public class PotentiometerPanel extends AbstractPotentiometer {
int margin = 4 * width / 32; int margin = 4 * width / 32;
int spacing = width / 3 - 1; int spacing = width / 3 - 1;
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.setStroke(ObjectCache.getInstance() g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2 * width / 32));
.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, g2d.drawLine(width / 2 + spacing, height / 2, width / 2 + spacing, height - margin);
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.drawLine(width / 2, height / 2, width / 2, height - margin);
g2d.setStroke(ObjectCache.getInstance() g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(4 * width / 32));
.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, g2d.drawLine(width / 2 + spacing, height - margin, width / 2 + spacing, height - margin);
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.drawLine(width / 2, height - margin, width / 2, height - margin);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.setColor(BODY_COLOR); g2d.setColor(BODY_COLOR);
g2d.fillOval(margin, margin / 2, width - 2 * margin, height - 2 g2d.fillOval(margin, margin / 2, width - 2 * margin, height - 2 * margin);
* margin);
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.drawOval(margin, margin / 2, width - 2 * margin, height - 2 g2d.drawOval(margin, margin / 2, width - 2 * margin, height - 2 * margin);
* margin);
} }
@EditableProperty @EditableProperty
@@ -12,7 +12,9 @@ import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.components.semiconductors.AbstractTransistorSymbol; import org.diylc.components.semiconductors.AbstractTransistorSymbol;
@ComponentDescriptor(name = "Potentiometer Symbol", author = "MCbx", category = "Schematics", instanceNamePrefix = " VR", description = "Potentiometer symbol", stretchable = false, zOrder = IDIYComponent.COMPONENT, rotatable = true) @ComponentDescriptor(name = "Potentiometer Symbol", author = "MCbx", category = "Schematics",
instanceNamePrefix = " VR", description = "Potentiometer symbol", stretchable = false,
zOrder = IDIYComponent.COMPONENT, rotatable = true)
public class PotentiometerSymbol extends AbstractTransistorSymbol { public class PotentiometerSymbol extends AbstractTransistorSymbol {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -31,21 +33,18 @@ public class PotentiometerSymbol extends AbstractTransistorSymbol {
GeneralPath polyline = new GeneralPath(); GeneralPath polyline = new GeneralPath();
polyline.moveTo(x + pinSpacing * 2, y - pinSpacing * 2); polyline.moveTo(x + pinSpacing * 2, y - pinSpacing * 2);
polyline.lineTo(x + pinSpacing * 2, y - pinSpacing * 2 + pinSpacing / 2); polyline.lineTo(x + pinSpacing * 2, y - pinSpacing * 2 + pinSpacing / 2);
polyline.lineTo(x + pinSpacing * 2 - pinSpacing / 4, polyline.lineTo(x + pinSpacing * 2 - pinSpacing / 4, (y - pinSpacing * 2) + pinSpacing / 2 + pinSpacing / 4);
(y - pinSpacing * 2) + pinSpacing / 2 + pinSpacing / 4);
polyline.lineTo(x + pinSpacing * 2 + pinSpacing / 4, (y - pinSpacing * 2) + 2 * pinSpacing / 2); polyline.lineTo(x + pinSpacing * 2 + pinSpacing / 4, (y - pinSpacing * 2) + 2 * pinSpacing / 2);
polyline.lineTo(x + pinSpacing * 2 - pinSpacing / 4, polyline.lineTo(x + pinSpacing * 2 - pinSpacing / 4, (y - pinSpacing * 2) + 3 * pinSpacing / 2 - pinSpacing / 8);
(y - pinSpacing * 2) + 3 * pinSpacing / 2 - pinSpacing / 8); polyline.lineTo(x + pinSpacing * 2 + pinSpacing / 4, (y - pinSpacing * 2) + 4 * pinSpacing / 2 - pinSpacing / 4);
polyline.lineTo(x + pinSpacing * 2 + pinSpacing / 4, polyline.lineTo(x + pinSpacing * 2 - pinSpacing / 4, (y - pinSpacing * 2) + 5 * pinSpacing / 2 - pinSpacing / 3
(y - pinSpacing * 2) + 4 * pinSpacing / 2 - pinSpacing / 4); - pinSpacing / 16);
polyline.lineTo(x + pinSpacing * 2 - pinSpacing / 4, polyline.lineTo(x + pinSpacing * 2 + pinSpacing / 4, (y - pinSpacing * 2) + 6 * pinSpacing / 2 - pinSpacing / 2
(y - pinSpacing * 2) + 5 * pinSpacing / 2 - pinSpacing / 3 - pinSpacing / 16); + pinSpacing / 16);
polyline.lineTo(x + pinSpacing * 2 + pinSpacing / 4, polyline.lineTo(x + pinSpacing * 2 - pinSpacing / 4, (y - pinSpacing * 2) + 7 * pinSpacing / 2 - pinSpacing / 2
(y - pinSpacing * 2) + 6 * pinSpacing / 2 - pinSpacing / 2 + pinSpacing / 16); - pinSpacing / 16);
polyline.lineTo(x + pinSpacing * 2 - pinSpacing / 4, polyline.lineTo(x + pinSpacing * 2 + pinSpacing / 4, (y - pinSpacing * 2) + 7 * pinSpacing / 2 - pinSpacing / 2
(y - pinSpacing * 2) + 7 * pinSpacing / 2 - pinSpacing / 2 - pinSpacing / 16); + pinSpacing / 4);
polyline.lineTo(x + pinSpacing * 2 + pinSpacing / 4,
(y - pinSpacing * 2) + 7 * pinSpacing / 2 - pinSpacing / 2 + pinSpacing / 4);
polyline.lineTo(x + pinSpacing * 2, (y - pinSpacing * 2) + 7 * pinSpacing / 2); polyline.lineTo(x + pinSpacing * 2, (y - pinSpacing * 2) + 7 * pinSpacing / 2);
polyline.lineTo(x + pinSpacing * 2, y + pinSpacing * 2); polyline.lineTo(x + pinSpacing * 2, y + pinSpacing * 2);
polyline.moveTo(x, y); polyline.moveTo(x, y);
@@ -91,8 +90,8 @@ public class PotentiometerSymbol extends AbstractTransistorSymbol {
return controlPoints[0].y; return controlPoints[0].y;
if (controlPoints[0].y > controlPoints[1].y && controlPoints[0].y > controlPoints[2].y) if (controlPoints[0].y > controlPoints[1].y && controlPoints[0].y > controlPoints[2].y)
return controlPoints[1].y - pinSpacing * 2 / 3; return controlPoints[1].y - pinSpacing * 2 / 3;
return 2 * ((int) (shapeRect.getHeight() - textRect.getHeight()) / 2 + fontMetrics.getAscent() return 2 * ((int) (shapeRect.getHeight() - textRect.getHeight()) / 2 + fontMetrics.getAscent() + (int) shapeRect
+ (int) shapeRect.getY()); .getY());
} }
@Override @Override
@@ -101,13 +100,13 @@ public class PotentiometerSymbol extends AbstractTransistorSymbol {
g2d.setColor(Color.blue); g2d.setColor(Color.blue);
g2d.drawLine(0, height / 2, 4, height / 2); g2d.drawLine(0, height / 2, 4, height / 2);
g2d.drawLine(width - 4, height / 2, width, height / 2); g2d.drawLine(width - 4, height / 2, width, height / 2);
g2d.drawPolyline(new int[] { 4, 6, 10, 14, 18, 22, 26, 28 }, new int[] { height / 2, height / 2 + 2, g2d.drawPolyline(new int[] {4, 6, 10, 14, 18, 22, 26, 28}, new int[] {height / 2, height / 2 + 2, height / 2 - 2,
height / 2 - 2, height / 2 + 2, height / 2 - 2, height / 2 + 2, height / 2 - 2, height / 2 }, 8); height / 2 + 2, height / 2 - 2, height / 2 + 2, height / 2 - 2, height / 2}, 8);
g2d.drawPolyline(new int[] {width / 2, width / 2 - 2}, new int[] {height, height / 2 + 2}, 2); g2d.drawPolyline(new int[] {width / 2, width / 2 - 2}, new int[] {height, height / 2 + 2}, 2);
g2d.fill(new Polygon(new int[] { width / 2 - 4, width / 2 + 2, width / 2 - 2 }, g2d.fill(new Polygon(new int[] {width / 2 - 4, width / 2 + 2, width / 2 - 2}, new int[] {height / 2 + 6,
new int[] { height / 2 + 6, height / 2 + 6, height / 2 + 2 }, 3)); height / 2 + 6, height / 2 + 2}, 3));
} }
} }
@@ -4,8 +4,8 @@ import org.diylc.core.measures.PowerUnit;
public enum Power { public enum Power {
EIGHT("1/8W"), QUARTER("1/4W"), HALF("1/2W"), ONE("1W"), TWO("2W"), FIVE("5W"), TEN("10W"), FIFTY( EIGHT("1/8W"), QUARTER("1/4W"), HALF("1/2W"), ONE("1W"), TWO("2W"), FIVE("5W"), TEN("10W"), FIFTY("50W"), HUNDRED(
"50W"), HUNDRED("100W"); "100W");
String label; String label;
@@ -15,7 +15,9 @@ import org.diylc.core.measures.Capacitance;
import org.diylc.core.measures.Size; import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; 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) @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 AbstractRadialComponent<Capacitance> { public class RadialCeramicDiskCapacitor extends AbstractRadialComponent<Capacitance> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -90,7 +92,6 @@ public class RadialCeramicDiskCapacitor extends AbstractRadialComponent<Capacita
@Override @Override
protected Shape getBodyShape() { protected Shape getBodyShape() {
return new Ellipse2D.Double(0f, 0f, getLength().convertToPixels(), getClosestOdd(getWidth() return new Ellipse2D.Double(0f, 0f, getLength().convertToPixels(), getClosestOdd(getWidth().convertToPixels()));
.convertToPixels()));
} }
} }
@@ -23,7 +23,9 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@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) @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 RadialElectrolytic extends AbstractRadialComponent<Capacitance> { public class RadialElectrolytic extends AbstractRadialComponent<Capacitance> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -90,18 +92,16 @@ public class RadialElectrolytic extends AbstractRadialComponent<Capacitance> {
public void drawIcon(Graphics2D g2d, int width, int height) { public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.setColor(BODY_COLOR); g2d.setColor(BODY_COLOR);
int margin = 3; int margin = 3;
Ellipse2D body = new Ellipse2D.Double(margin, margin, Ellipse2D body =
getClosestOdd(width - 2 * margin), getClosestOdd(width - 2 new Ellipse2D.Double(margin, margin, getClosestOdd(width - 2 * margin), getClosestOdd(width - 2 * margin));
* margin));
g2d.fill(body); g2d.fill(body);
Area marker = new Area(body); Area marker = new Area(body);
marker.subtract(new Area(new Rectangle2D.Double(margin, margin, width marker.subtract(new Area(new Rectangle2D.Double(margin, margin, width - 4 * margin, getClosestOdd(width - 2
- 4 * margin, getClosestOdd(width - 2 * margin)))); * margin))));
g2d.setColor(MARKER_COLOR); g2d.setColor(MARKER_COLOR);
g2d.fill(marker); g2d.fill(marker);
g2d.setColor(TICK_COLOR); g2d.setColor(TICK_COLOR);
g2d.drawLine(width - 2 * margin, height / 2 - 2, width - 2 * margin, g2d.drawLine(width - 2 * margin, height / 2 - 2, width - 2 * margin, height / 2 + 2);
height / 2 + 2);
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.draw(body); g2d.draw(body);
// g2d.setColor(COVER_COLOR.darker()); // g2d.setColor(COVER_COLOR.darker());
@@ -122,24 +122,18 @@ public class RadialElectrolytic extends AbstractRadialComponent<Capacitance> {
if (folded) { if (folded) {
Area area = new Area(getBodyShape()); Area area = new Area(getBodyShape());
if (invert) { if (invert) {
area.subtract(new Area(new Rectangle2D.Double( area.subtract(new Area(new Rectangle2D.Double(totalDiameter * 0.2, -height, totalDiameter, height * 2)));
totalDiameter * 0.2, -height, totalDiameter,
height * 2)));
} else { } else {
area.subtract(new Area(new Rectangle2D.Double(0, area.subtract(new Area(new Rectangle2D.Double(0, -height, totalDiameter * 0.8, height * 2)));
-height, totalDiameter * 0.8, height * 2)));
} }
g2d.setColor(markerColor); g2d.setColor(markerColor);
g2d.fill(area); g2d.fill(area);
} else { } else {
Area area = new Area(getBodyShape()); Area area = new Area(getBodyShape());
if (invert) { if (invert) {
area.subtract(new Area(new Rectangle2D.Double( area.subtract(new Area(new Rectangle2D.Double(totalDiameter * 0.2, 0, totalDiameter, totalDiameter)));
totalDiameter * 0.2, 0, totalDiameter,
totalDiameter)));
} else { } else {
area.subtract(new Area(new Rectangle2D.Double(0, 0, area.subtract(new Area(new Rectangle2D.Double(0, 0, totalDiameter * 0.8, totalDiameter)));
totalDiameter * 0.8, totalDiameter)));
} }
g2d.setColor(markerColor); g2d.setColor(markerColor);
g2d.fill(area); g2d.fill(area);
@@ -147,9 +141,8 @@ public class RadialElectrolytic extends AbstractRadialComponent<Capacitance> {
} }
Color finalTickColor; Color finalTickColor;
if (outlineMode) { if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance() Theme theme =
.readObject(IPlugInPort.THEME_KEY, (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
Constants.DEFAULT_THEME);
finalTickColor = theme.getOutlineColor(); finalTickColor = theme.getOutlineColor();
} else { } else {
finalTickColor = tickColor; finalTickColor = tickColor;
@@ -159,18 +152,13 @@ public class RadialElectrolytic extends AbstractRadialComponent<Capacitance> {
if (folded) { if (folded) {
int tickLength = height / 7; int tickLength = height / 7;
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
g2d.drawLine( g2d.drawLine((int) (totalDiameter * (invert ? 0.08 : 0.92)), -height / 2 + tickLength + i * tickLength * 2,
(int) (totalDiameter * (invert ? 0.08 : 0.92)), (int) (totalDiameter * (invert ? 0.08 : 0.92)), -height / 2 + tickLength + i * tickLength * 2
-height / 2 + tickLength + i * tickLength * 2,
(int) (totalDiameter * (invert ? 0.08 : 0.92)),
-height / 2 + tickLength + i * tickLength * 2
+ tickLength); + tickLength);
} }
} else { } else {
g2d.drawLine((int) (totalDiameter * (invert ? 0.1 : 0.9)), g2d.drawLine((int) (totalDiameter * (invert ? 0.1 : 0.9)), totalDiameter / 2 - (int) (totalDiameter * 0.05),
totalDiameter / 2 - (int) (totalDiameter * 0.05), (int) (totalDiameter * (invert ? 0.1 : 0.9)), totalDiameter / 2 + (int) (totalDiameter * 0.05));
(int) (totalDiameter * (invert ? 0.1 : 0.9)),
totalDiameter / 2 + (int) (totalDiameter * 0.05));
} }
} }
// int coverDiameter = getClosestOdd(totalDiameter * 3 / 4); // int coverDiameter = getClosestOdd(totalDiameter * 3 / 4);
@@ -270,12 +258,9 @@ public class RadialElectrolytic extends AbstractRadialComponent<Capacitance> {
double height = (int) getHeight().convertToPixels(); double height = (int) getHeight().convertToPixels();
double diameter = (int) getLength().convertToPixels(); double diameter = (int) getLength().convertToPixels();
if (folded) { if (folded) {
return new RoundRectangle2D.Double(0f, -height / 2 return new RoundRectangle2D.Double(0f, -height / 2 - LEAD_THICKNESS.convertToPixels() / 2,
- LEAD_THICKNESS.convertToPixels() / 2, getClosestOdd(diameter), getClosestOdd(height), EDGE_RADIUS.convertToPixels(), EDGE_RADIUS.convertToPixels());
getClosestOdd(diameter), getClosestOdd(height), EDGE_RADIUS
.convertToPixels(), EDGE_RADIUS.convertToPixels());
} }
return new Ellipse2D.Double(0f, 0f, getClosestOdd(diameter), return new Ellipse2D.Double(0f, 0f, getClosestOdd(diameter), getClosestOdd(diameter));
getClosestOdd(diameter));
} }
} }
@@ -15,7 +15,9 @@ import org.diylc.core.measures.Capacitance;
import org.diylc.core.measures.Size; import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; 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) @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 AbstractRadialComponent<Capacitance> { public class RadialFilmCapacitor extends AbstractRadialComponent<Capacitance> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -92,8 +94,7 @@ public class RadialFilmCapacitor extends AbstractRadialComponent<Capacitance> {
@Override @Override
protected Shape getBodyShape() { protected Shape getBodyShape() {
double radius = getWidth().convertToPixels() * 0.7; double radius = getWidth().convertToPixels() * 0.7;
return new RoundRectangle2D.Double(0f, 0f, getLength() return new RoundRectangle2D.Double(0f, 0f, getLength().convertToPixels(), getClosestOdd(getWidth()
.convertToPixels(), .convertToPixels()), radius, radius);
getClosestOdd(getWidth().convertToPixels()), radius, radius);
} }
} }
@@ -17,7 +17,9 @@ import org.diylc.core.measures.Resistance;
import org.diylc.core.measures.Size; import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Resistor", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "R", description = "Resistor layout symbol", zOrder = IDIYComponent.COMPONENT) @ComponentDescriptor(name = "Resistor", author = "Branislav Stojkovic", category = "Passive",
creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "R", description = "Resistor layout symbol",
zOrder = IDIYComponent.COMPONENT)
public class Resistor extends AbstractLeadedComponent<Resistance> { public class Resistor extends AbstractLeadedComponent<Resistance> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -116,8 +118,7 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
@Override @Override
protected Shape getBodyShape() { protected Shape getBodyShape() {
return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(), return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(), getClosestOdd(getWidth().convertToPixels()));
getClosestOdd(getWidth().convertToPixels()));
} }
@Override @Override
@@ -14,7 +14,9 @@ import org.diylc.core.measures.Resistance;
import org.diylc.core.measures.Size; import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Resistor (schematic symbol)", author = "Branislav Stojkovic", category = "Schematics", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "R", description = "Resistor schematic symbol", zOrder = IDIYComponent.COMPONENT) @ComponentDescriptor(name = "Resistor (schematic symbol)", author = "Branislav Stojkovic", category = "Schematics",
creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "R",
description = "Resistor schematic symbol", zOrder = IDIYComponent.COMPONENT)
public class ResistorSymbol extends AbstractSchematicLeadedSymbol<Resistance> { public class ResistorSymbol extends AbstractSchematicLeadedSymbol<Resistance> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -25,8 +27,7 @@ public class ResistorSymbol extends AbstractSchematicLeadedSymbol<Resistance> {
private Resistance value = null; private Resistance value = null;
@Deprecated @Deprecated
private Power power = Power.HALF; private Power power = Power.HALF;
private org.diylc.core.measures.Power powerNew = new org.diylc.core.measures.Power(0.5, private org.diylc.core.measures.Power powerNew = new org.diylc.core.measures.Power(0.5, PowerUnit.W);
PowerUnit.W);
@EditableProperty @EditableProperty
public Resistance getValue() { public Resistance getValue() {
@@ -74,9 +75,8 @@ public class ResistorSymbol extends AbstractSchematicLeadedSymbol<Resistance> {
g2d.drawLine(0, height / 2, 4, height / 2); g2d.drawLine(0, height / 2, 4, height / 2);
g2d.drawLine(width - 4, height / 2, width, height / 2); g2d.drawLine(width - 4, height / 2, width, height / 2);
g2d.setColor(COLOR); g2d.setColor(COLOR);
g2d.drawPolyline(new int[] { 4, 6, 10, 14, 18, 22, 26, 28 }, new int[] { height / 2, g2d.drawPolyline(new int[] {4, 6, 10, 14, 18, 22, 26, 28}, new int[] {height / 2, height / 2 + 2, height / 2 - 2,
height / 2 + 2, height / 2 - 2, height / 2 + 2, height / 2 - 2, height / 2 + 2, height / 2 + 2, height / 2 - 2, height / 2 + 2, height / 2 - 2, height / 2}, 8);
height / 2 - 2, height / 2 }, 8);
} }
@Override @Override
@@ -6,7 +6,6 @@ public enum Taper {
@Override @Override
public String toString() { public String toString() {
return name().substring(0, 1).toUpperCase() return name().substring(0, 1).toUpperCase() + name().substring(1).toLowerCase().replace("_", " ");
+ name().substring(1).toLowerCase().replace("_", " ");
} }
} }
@@ -29,7 +29,10 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Trimmer Potentiometer", author = "Branislav Stojkovic", category = "Passive", creationMethod = CreationMethod.SINGLE_CLICK, instanceNamePrefix = "VR", description = "Various types of board mounted trimmer potentiometers", zOrder = IDIYComponent.COMPONENT, stretchable = false) @ComponentDescriptor(name = "Trimmer Potentiometer", author = "Branislav Stojkovic", category = "Passive",
creationMethod = CreationMethod.SINGLE_CLICK, instanceNamePrefix = "VR",
description = "Various types of board mounted trimmer potentiometers", zOrder = IDIYComponent.COMPONENT,
stretchable = false)
public class TrimmerPotentiometer extends AbstractPotentiometer { public class TrimmerPotentiometer extends AbstractPotentiometer {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -57,8 +60,7 @@ public class TrimmerPotentiometer extends AbstractPotentiometer {
protected TrimmerType type = TrimmerType.FLAT_SMALL; protected TrimmerType type = TrimmerType.FLAT_SMALL;
public TrimmerPotentiometer() { public TrimmerPotentiometer() {
controlPoints = new Point[] { new Point(0, 0), new Point(0, 0), controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0)};
new Point(0, 0) };
updateControlPoints(); updateControlPoints();
} }
@@ -184,10 +186,8 @@ public class TrimmerPotentiometer extends AbstractPotentiometer {
default: default:
break; break;
} }
controlPoints[1].setLocation(controlPoints[0].x + dx1, controlPoints[1].setLocation(controlPoints[0].x + dx1, controlPoints[0].y + dy1);
controlPoints[0].y + dy1); controlPoints[2].setLocation(controlPoints[0].x + dx2, controlPoints[0].y + dy2);
controlPoints[2].setLocation(controlPoints[0].x + dx2,
controlPoints[0].y + dy2);
} }
public Shape[] getBody() { public Shape[] getBody() {
@@ -196,14 +196,12 @@ public class TrimmerPotentiometer extends AbstractPotentiometer {
// Calculate the center point as center of the minimum bounding // Calculate the center point as center of the minimum bounding
// rectangle. // rectangle.
int centerX = (Math.max(Math.max(controlPoints[0].x, int centerX =
controlPoints[1].x), controlPoints[2].x) + Math.min(Math (Math.max(Math.max(controlPoints[0].x, controlPoints[1].x), controlPoints[2].x) + Math.min(
.min(controlPoints[0].x, controlPoints[1].x), Math.min(controlPoints[0].x, controlPoints[1].x), controlPoints[2].x)) / 2;
controlPoints[2].x)) / 2; int centerY =
int centerY = (Math.max(Math.max(controlPoints[0].y, (Math.max(Math.max(controlPoints[0].y, controlPoints[1].y), controlPoints[2].y) + Math.min(
controlPoints[1].y), controlPoints[2].y) + Math.min(Math Math.min(controlPoints[0].y, controlPoints[1].y), controlPoints[2].y)) / 2;
.min(controlPoints[0].y, controlPoints[1].y),
controlPoints[2].y)) / 2;
// Calculate body dimensions based on the selected type. // Calculate body dimensions based on the selected type.
int length = 0; int length = 0;
@@ -214,12 +212,12 @@ public class TrimmerPotentiometer extends AbstractPotentiometer {
length = getClosestOdd(FLAT_BODY_SIZE.convertToPixels()); length = getClosestOdd(FLAT_BODY_SIZE.convertToPixels());
width = length; width = length;
int shaftSize = getClosestOdd(FLAT_SHAFT_SIZE.convertToPixels()); int shaftSize = getClosestOdd(FLAT_SHAFT_SIZE.convertToPixels());
Area shaft = new Area(new Ellipse2D.Double(centerX - shaftSize Area shaft =
/ 2, centerY - shaftSize / 2, shaftSize, shaftSize)); new Area(new Ellipse2D.Double(centerX - shaftSize / 2, centerY - shaftSize / 2, shaftSize, shaftSize));
Area slot = new Area(new Rectangle2D.Double(centerX - shaftSize Area slot =
/ 2, centerY - shaftSize / 8, shaftSize, shaftSize / 4)); new Area(new Rectangle2D.Double(centerX - shaftSize / 2, centerY - shaftSize / 8, shaftSize,
slot.transform(AffineTransform.getRotateInstance(Math.PI / 4, shaftSize / 4));
centerX, centerY)); slot.transform(AffineTransform.getRotateInstance(Math.PI / 4, centerX, centerY));
shaft.subtract(slot); shaft.subtract(slot);
body[1] = shaft; body[1] = shaft;
break; break;
@@ -229,14 +227,12 @@ public class TrimmerPotentiometer extends AbstractPotentiometer {
width = getClosestOdd(VERTICAL_BODY_WIDTH.convertToPixels()); width = getClosestOdd(VERTICAL_BODY_WIDTH.convertToPixels());
break; break;
} }
if (orientation == Orientation.DEFAULT if (orientation == Orientation.DEFAULT || orientation == Orientation._180) {
|| orientation == Orientation._180) {
int p = length; int p = length;
length = width; length = width;
width = p; width = p;
} }
body[0] = new Rectangle2D.Double(centerX - length / 2, centerY body[0] = new Rectangle2D.Double(centerX - length / 2, centerY - width / 2, length, width);
- width / 2, length, width);
} }
return body; return body;
} }
@@ -255,8 +251,7 @@ public class TrimmerPotentiometer extends AbstractPotentiometer {
} }
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
boolean outlineMode, Project project,
IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) { if (checkPointsClipped(g2d.getClip())) {
return; return;
@@ -264,14 +259,12 @@ public class TrimmerPotentiometer extends AbstractPotentiometer {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
Shape mainShape = getBody()[0]; Shape mainShape = getBody()[0];
Shape shaftShape = getBody()[1]; Shape shaftShape = getBody()[1];
Theme theme = (Theme) ConfigurationManager.getInstance().readObject( Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
if (mainShape != null) { if (mainShape != null) {
g2d.setColor(bodyColor); g2d.setColor(bodyColor);
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance( g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
} }
if (!outlineMode) { if (!outlineMode) {
g2d.fill(mainShape); g2d.fill(mainShape);
@@ -285,12 +278,12 @@ public class TrimmerPotentiometer extends AbstractPotentiometer {
g2d.setComposite(oldComposite); g2d.setComposite(oldComposite);
Color finalBorderColor; Color finalBorderColor;
if (outlineMode) { if (outlineMode) {
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: theme.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: borderColor; : borderColor;
} }
g2d.setColor(finalBorderColor); g2d.setColor(finalBorderColor);
@@ -302,25 +295,22 @@ public class TrimmerPotentiometer extends AbstractPotentiometer {
for (Point point : controlPoints) { for (Point point : controlPoints) {
if (!outlineMode) { if (!outlineMode) {
g2d.setColor(PIN_COLOR); g2d.setColor(PIN_COLOR);
g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
pinSize, pinSize);
} }
g2d.setColor(outlineMode ? theme.getOutlineColor() g2d.setColor(outlineMode ? theme.getOutlineColor() : PIN_BORDER_COLOR);
: PIN_BORDER_COLOR); g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize,
pinSize);
} }
// Draw label. // Draw label.
g2d.setFont(LABEL_FONT); g2d.setFont(LABEL_FONT);
Color finalLabelColor; Color finalLabelColor;
if (outlineMode) { if (outlineMode) {
finalLabelColor = componentState == ComponentState.SELECTED finalLabelColor =
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: theme.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalLabelColor = componentState == ComponentState.SELECTED finalLabelColor =
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: LABEL_COLOR; : LABEL_COLOR;
} }
g2d.setColor(finalLabelColor); g2d.setColor(finalLabelColor);
@@ -345,8 +335,7 @@ public class TrimmerPotentiometer extends AbstractPotentiometer {
label = getName() + " " + (getValue() == null ? "" : getValue().toString()); label = getName() + " " + (getValue() == null ? "" : getValue().toString());
} }
g2d.drawString(label, (int) (bodyRect.getX() + x), (int) (bodyRect g2d.drawString(label, (int) (bodyRect.getX() + x), (int) (bodyRect.getY() + y));
.getY() + y));
} }
@Override @Override
@@ -359,12 +348,10 @@ public class TrimmerPotentiometer extends AbstractPotentiometer {
g2d.drawRect(margin, margin, width - 2 * margin, width - 2 * margin); g2d.drawRect(margin, margin, width - 2 * margin, width - 2 * margin);
int shaftSize = 11; int shaftSize = 11;
int slotSize = 2; int slotSize = 2;
Area area = new Area(new Ellipse2D.Double(width / 2 - shaftSize / 2, Area area =
width / 2 - shaftSize / 2, shaftSize, shaftSize)); new Area(new Ellipse2D.Double(width / 2 - shaftSize / 2, width / 2 - shaftSize / 2, shaftSize, shaftSize));
Area slot = new Area(new Rectangle2D.Double(0, Area slot = new Area(new Rectangle2D.Double(0, width / 2 - slotSize / 2, width, slotSize));
width / 2 - slotSize / 2, width, slotSize)); slot.transform(AffineTransform.getRotateInstance(Math.PI / 4, width / 2, width / 2));
slot.transform(AffineTransform.getRotateInstance(Math.PI / 4,
width / 2, width / 2));
area.subtract(slot); area.subtract(slot);
g2d.setColor(SHAFT_COLOR); g2d.setColor(SHAFT_COLOR);
g2d.fill(area); g2d.fill(area);
@@ -383,11 +370,9 @@ public class TrimmerPotentiometer extends AbstractPotentiometer {
g2d.drawOval(margin - pinSize / 2, 21 - pinSize / 2, pinSize, pinSize); g2d.drawOval(margin - pinSize / 2, 21 - pinSize / 2, pinSize, pinSize);
g2d.setColor(PIN_COLOR); g2d.setColor(PIN_COLOR);
g2d.fillOval(width - margin - pinSize / 2, width / 2 - pinSize / 2, g2d.fillOval(width - margin - pinSize / 2, width / 2 - pinSize / 2, pinSize, pinSize);
pinSize, pinSize);
g2d.setColor(PIN_BORDER_COLOR); g2d.setColor(PIN_BORDER_COLOR);
g2d.drawOval(width - margin - pinSize / 2, width / 2 - pinSize / 2, g2d.drawOval(width - margin - pinSize / 2, width / 2 - pinSize / 2, pinSize, pinSize);
pinSize, pinSize);
} }
@EditableProperty(name = "Body") @EditableProperty(name = "Body")
@@ -436,8 +421,7 @@ public class TrimmerPotentiometer extends AbstractPotentiometer {
@Override @Override
public String toString() { public String toString() {
return name().substring(0, 1) return name().substring(0, 1) + name().substring(1).toLowerCase().replace("_", " ");
+ name().substring(1).toLowerCase().replace("_", " ");
} }
} }
} }
@@ -51,9 +51,8 @@ public abstract class AbstractDiodeSymbol extends AbstractSchematicLeadedSymbol<
@Override @Override
protected Shape getBodyShape() { protected Shape getBodyShape() {
double width = getWidth().convertToPixels(); double width = getWidth().convertToPixels();
Polygon p = new Polygon( Polygon p =
new int[] { 0, 0, (int) (width / Math.sqrt(2)) }, new int[] { new Polygon(new int[] {0, 0, (int) (width / Math.sqrt(2))}, new int[] {0, (int) (width), (int) (width / 2)}, 3);
0, (int) (width), (int) (width / 2) }, 3);
// Area a = new Area(p); // Area a = new Area(p);
// int bandSize = (int) BAND_SIZE.convertToPixels(); // int bandSize = (int) BAND_SIZE.convertToPixels();
// a.add(new Area(new Rectangle2D.Double((int) (width / Math.sqrt(2)) + // a.add(new Area(new Rectangle2D.Double((int) (width / Math.sqrt(2)) +
@@ -63,8 +62,7 @@ public abstract class AbstractDiodeSymbol extends AbstractSchematicLeadedSymbol<
} }
@Override @Override
protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) { protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {}
}
@Deprecated @Deprecated
@Override @Override
@@ -35,8 +35,7 @@ public abstract class AbstractTransistorSymbol extends AbstractComponent<String>
public static SymbolFlipping FLIPPING = SymbolFlipping.NONE; public static SymbolFlipping FLIPPING = SymbolFlipping.NONE;
protected String value = ""; protected String value = "";
protected Point[] controlPoints = new Point[] { new Point(0, 0), new Point(0, 0), protected Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0)};
new Point(0, 0) };
protected Color color = COLOR; protected Color color = COLOR;
protected SymbolFlipping flip = FLIPPING; protected SymbolFlipping flip = FLIPPING;
protected Display display = Display.NAME; protected Display display = Display.NAME;
@@ -48,8 +47,8 @@ public abstract class AbstractTransistorSymbol extends AbstractComponent<String>
} }
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
Project project, IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) { if (checkPointsClipped(g2d.getClip())) {
return; return;
} }
@@ -58,8 +57,8 @@ public abstract class AbstractTransistorSymbol extends AbstractComponent<String>
if (componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING) { if (componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING) {
finalColor = SELECTION_COLOR; finalColor = SELECTION_COLOR;
} else if (outlineMode) { } else if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject( Theme theme =
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalColor = theme.getOutlineColor(); finalColor = theme.getOutlineColor();
} else { } else {
finalColor = color; finalColor = color;
@@ -75,18 +74,14 @@ public abstract class AbstractTransistorSymbol extends AbstractComponent<String>
int rotation = 0; int rotation = 0;
// determine rotation using control points // determine rotation using control points
if (controlPoints[1].x==controlPoints[2].x) if (controlPoints[1].x == controlPoints[2].x) {
{ if (controlPoints[0].x > controlPoints[1].x) {
if (controlPoints[0].x>controlPoints[1].x)
{
rotation = 180; rotation = 180;
} }
} }
if (controlPoints[1].y==controlPoints[2].y) if (controlPoints[1].y == controlPoints[2].y) {
{
rotation = 90; rotation = 90;
if (controlPoints[0].y>controlPoints[1].y) if (controlPoints[0].y > controlPoints[1].y) {
{
rotation = 270; rotation = 270;
} }
} }
@@ -112,20 +107,19 @@ public abstract class AbstractTransistorSymbol extends AbstractComponent<String>
g2d.setFont(LABEL_FONT); g2d.setFont(LABEL_FONT);
Color finalLabelColor; Color finalLabelColor;
if (outlineMode) { if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject( Theme theme =
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalLabelColor = componentState == ComponentState.SELECTED finalLabelColor =
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED : theme componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalLabelColor = componentState == ComponentState.SELECTED finalLabelColor =
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: LABEL_COLOR; : LABEL_COLOR;
} }
g2d.setColor(finalLabelColor); g2d.setColor(finalLabelColor);
String label = ""; String label = "";
label = display == Display.NAME ? getName() label = display == Display.NAME ? getName() : (getValue() == null ? "" : getValue().toString());
: (getValue() == null ? "" : getValue().toString());
if (display == Display.NONE) { if (display == Display.NONE) {
label = ""; label = "";
} }
@@ -137,8 +131,8 @@ public abstract class AbstractTransistorSymbol extends AbstractComponent<String>
Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d); Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d);
Rectangle shapeRect = body[0].getBounds().union(body[1].getBounds()).union(body[2].getBounds()); Rectangle shapeRect = body[0].getBounds().union(body[1].getBounds()).union(body[2].getBounds());
drawCenteredText(g2d, label, drawCenteredText(g2d, label, getLabelX(shapeRect, textRect, fontMetrics, outlineMode),
getLabelX(shapeRect, textRect, fontMetrics, outlineMode), getLabelY(shapeRect, textRect, fontMetrics, outlineMode), HorizontalAlignment.LEFT, VerticalAlignment.CENTER); getLabelY(shapeRect, textRect, fontMetrics, outlineMode), HorizontalAlignment.LEFT, VerticalAlignment.CENTER);
} }
@Override @Override
@@ -228,8 +222,8 @@ public abstract class AbstractTransistorSymbol extends AbstractComponent<String>
} }
/** /**
* Returns transistor shape consisting of 3 parts, in this order: main body, * Returns transistor shape consisting of 3 parts, in this order: main body, connectors, polarity
* connectors, polarity arrow. * arrow.
* *
* @return * @return
*/ */
@@ -12,7 +12,9 @@ import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
@ComponentDescriptor(name = "BJT Symbol", author = "Branislav Stojkovic", category = "Schematics", instanceNamePrefix = "Q", description = "Bipolar junction transistor schematic symbol", stretchable = false, zOrder = IDIYComponent.COMPONENT, rotatable = true) @ComponentDescriptor(name = "BJT Symbol", author = "Branislav Stojkovic", category = "Schematics",
instanceNamePrefix = "Q", description = "Bipolar junction transistor schematic symbol", stretchable = false,
zOrder = IDIYComponent.COMPONENT, rotatable = true)
public class BJTSymbol extends AbstractTransistorSymbol { public class BJTSymbol extends AbstractTransistorSymbol {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -49,22 +51,17 @@ public class BJTSymbol extends AbstractTransistorSymbol {
double theta; double theta;
if (polarity == BJTPolarity.NPN) { if (polarity == BJTPolarity.NPN) {
theta = Math.atan(1.0 / 3); theta = Math.atan(1.0 / 3);
arrow = new Area(new Polygon(new int[] { x + pinSpacing, arrow =
x + pinSpacing, x + pinSpacing * 10 / 6 }, new Area(new Polygon(new int[] {x + pinSpacing, x + pinSpacing, x + pinSpacing * 10 / 6}, new int[] {
new int[] { y - pinSpacing / 5 + pinSpacing / 2, y - pinSpacing / 5 + pinSpacing / 2, y + pinSpacing / 5 + pinSpacing / 2, y + pinSpacing / 2}, 3));
y + pinSpacing / 5 + pinSpacing / 2, arrow.transform(AffineTransform.getRotateInstance(theta, x + pinSpacing / 2, y + pinSpacing / 2));
y + pinSpacing / 2 }, 3));
arrow.transform(AffineTransform.getRotateInstance(theta, x
+ pinSpacing / 2, y + pinSpacing / 2));
} else { } else {
theta = -Math.atan(1.0 / 3); theta = -Math.atan(1.0 / 3);
arrow = new Area(new Polygon(new int[] { x + pinSpacing, arrow =
x + pinSpacing * 10 / 6, x + pinSpacing * 10 / 6 }, new Area(
new int[] { y - pinSpacing / 2, new Polygon(new int[] {x + pinSpacing, x + pinSpacing * 10 / 6, x + pinSpacing * 10 / 6}, new int[] {
y - pinSpacing / 5 - pinSpacing / 2, y - pinSpacing / 2, y - pinSpacing / 5 - pinSpacing / 2, y + pinSpacing / 5 - pinSpacing / 2}, 3));
y + pinSpacing / 5 - pinSpacing / 2 }, 3)); arrow.transform(AffineTransform.getRotateInstance(theta, x + pinSpacing / 2, y - pinSpacing / 2));
arrow.transform(AffineTransform.getRotateInstance(theta, x
+ pinSpacing / 2, y - pinSpacing / 2));
} }
body[2] = arrow; body[2] = arrow;
} }
@@ -85,8 +82,7 @@ public class BJTSymbol extends AbstractTransistorSymbol {
g2d.drawLine(width / 3, height / 3 + 1, width * 3 / 4, height / 4); g2d.drawLine(width / 3, height / 3 + 1, width * 3 / 4, height / 4);
g2d.drawLine(width * 3 / 4, height - 1, width * 3 / 4, height * 3 / 4); g2d.drawLine(width * 3 / 4, height - 1, width * 3 / 4, height * 3 / 4);
g2d.drawLine(width / 3, height * 2 / 3 - 1, width * 3 / 4, g2d.drawLine(width / 3, height * 2 / 3 - 1, width * 3 / 4, height * 3 / 4);
height * 3 / 4);
} }
@EditableProperty(name = "Polarity") @EditableProperty(name = "Polarity")
@@ -31,7 +31,9 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "DIP IC", author = "Branislav Stojkovic", category = "Semiconductors", instanceNamePrefix = "IC", description = "Dual-in-line package IC", stretchable = false, zOrder = IDIYComponent.COMPONENT) @ComponentDescriptor(name = "DIP IC", author = "Branislav Stojkovic", category = "Semiconductors",
instanceNamePrefix = "IC", description = "Dual-in-line package IC", stretchable = false,
zOrder = IDIYComponent.COMPONENT)
public class DIL_IC extends AbstractTransparentComponent<String> { public class DIL_IC extends AbstractTransparentComponent<String> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -209,8 +211,7 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
throw new RuntimeException("Unexpected orientation: " + orientation); throw new RuntimeException("Unexpected orientation: " + orientation);
} }
controlPoints[i] = new Point(firstPoint.x + dx1, firstPoint.y + dy1); controlPoints[i] = new Point(firstPoint.x + dx1, firstPoint.y + dy1);
controlPoints[i + pinCount.getValue() / 2] = new Point(firstPoint.x + dx2, firstPoint.y controlPoints[i + pinCount.getValue() / 2] = new Point(firstPoint.x + dx2, firstPoint.y + dy2);
+ dy2);
} }
} }
@@ -232,38 +233,41 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
height = (pinCount.getValue() / 2) * pinSpacing; height = (pinCount.getValue() / 2) * pinSpacing;
x += pinSize / 2; x += pinSize / 2;
y -= pinSpacing / 2; y -= pinSpacing / 2;
indentation = new Area(new Ellipse2D.Double(x + width / 2 - indentationSize / 2, y indentation =
- indentationSize / 2, indentationSize, indentationSize)); new Area(new Ellipse2D.Double(x + width / 2 - indentationSize / 2, y - indentationSize / 2,
indentationSize, indentationSize));
break; break;
case _90: case _90:
width = (pinCount.getValue() / 2) * pinSpacing; width = (pinCount.getValue() / 2) * pinSpacing;
height = rowSpacing - pinSize; height = rowSpacing - pinSize;
x -= (pinSpacing / 2) + width - pinSpacing; x -= (pinSpacing / 2) + width - pinSpacing;
y += pinSize / 2; y += pinSize / 2;
indentation = new Area(new Ellipse2D.Double(x + width - indentationSize / 2, y indentation =
+ height / 2 - indentationSize / 2, indentationSize, indentationSize)); new Area(new Ellipse2D.Double(x + width - indentationSize / 2, y + height / 2 - indentationSize / 2,
indentationSize, indentationSize));
break; break;
case _180: case _180:
width = rowSpacing - pinSize; width = rowSpacing - pinSize;
height = (pinCount.getValue() / 2) * pinSpacing; height = (pinCount.getValue() / 2) * pinSpacing;
x -= rowSpacing - pinSize / 2; x -= rowSpacing - pinSize / 2;
y -= (pinSpacing / 2) + height - pinSpacing; y -= (pinSpacing / 2) + height - pinSpacing;
indentation = new Area(new Ellipse2D.Double(x + width / 2 - indentationSize / 2, y indentation =
+ height - indentationSize / 2, indentationSize, indentationSize)); new Area(new Ellipse2D.Double(x + width / 2 - indentationSize / 2, y + height - indentationSize / 2,
indentationSize, indentationSize));
break; break;
case _270: case _270:
width = (pinCount.getValue() / 2) * pinSpacing; width = (pinCount.getValue() / 2) * pinSpacing;
height = rowSpacing - pinSize; height = rowSpacing - pinSize;
x -= pinSpacing / 2; x -= pinSpacing / 2;
y += pinSize / 2 - rowSpacing; y += pinSize / 2 - rowSpacing;
indentation = new Area(new Ellipse2D.Double(x - indentationSize / 2, y + height / 2 indentation =
- indentationSize / 2, indentationSize, indentationSize)); new Area(new Ellipse2D.Double(x - indentationSize / 2, y + height / 2 - indentationSize / 2,
indentationSize, indentationSize));
break; break;
default: default:
throw new RuntimeException("Unexpected orientation: " + orientation); throw new RuntimeException("Unexpected orientation: " + orientation);
} }
body[0] = new Area(new RoundRectangle2D.Double(x, y, width, height, EDGE_RADIUS, body[0] = new Area(new RoundRectangle2D.Double(x, y, width, height, EDGE_RADIUS, EDGE_RADIUS));
EDGE_RADIUS));
body[1] = indentation; body[1] = indentation;
if (indentation != null) { if (indentation != null) {
indentation.intersect(body[0]); indentation.intersect(body[0]);
@@ -273,8 +277,8 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
} }
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
Project project, IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) { if (checkPointsClipped(g2d.getClip())) {
return; return;
} }
@@ -290,8 +294,7 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
} }
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
/ MAX_ALPHA));
} }
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : getBodyColor()); g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : getBodyColor());
g2d.fill(mainArea); g2d.fill(mainArea);
@@ -299,14 +302,15 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
Color finalBorderColor; Color finalBorderColor;
if (outlineMode) { if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject( Theme theme =
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : theme componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalBorderColor = componentState == ComponentState.SELECTED finalBorderColor =
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : getBorderColor(); componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: getBorderColor();
} }
g2d.setColor(finalBorderColor); g2d.setColor(finalBorderColor);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
@@ -325,14 +329,14 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
g2d.setFont(LABEL_FONT); g2d.setFont(LABEL_FONT);
Color finalLabelColor; Color finalLabelColor;
if (outlineMode) { if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject( Theme theme =
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalLabelColor = componentState == ComponentState.SELECTED finalLabelColor =
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED : theme componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalLabelColor = componentState == ComponentState.SELECTED finalLabelColor =
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: getLabelColor(); : getLabelColor();
} }
g2d.setColor(finalLabelColor); g2d.setColor(finalLabelColor);
@@ -389,9 +393,7 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
if (pinNo > pinCount.getValue() / 2) { if (pinNo > pinCount.getValue() / 2) {
g2d.drawString(Integer.toString(pinCount.getValue() - j), textX1, textY1); g2d.drawString(Integer.toString(pinCount.getValue() - j), textX1, textY1);
j++; j++;
} } else {
else
{
g2d.drawString(Integer.toString(pinNo), textX2, textY2); g2d.drawString(Integer.toString(pinNo), textX2, textY2);
} }
} }
@@ -399,9 +401,7 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
if (pinNo > pinCount.getValue() / 2) { if (pinNo > pinCount.getValue() / 2) {
k++; k++;
g2d.drawString(Integer.toString(pinNo - (pinCount.getValue() / 2) + k), textX1, textY1); g2d.drawString(Integer.toString(pinNo - (pinCount.getValue() / 2) + k), textX1, textY1);
} } else {
else
{
g2d.drawString(Integer.toString(pinNo + j), textX2, textY2); g2d.drawString(Integer.toString(pinNo + j), textX2, textY2);
j++; j++;
} }
@@ -17,7 +17,9 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@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) @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> { public class DiodePlastic extends AbstractLeadedComponent<String> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -89,16 +91,15 @@ public class DiodePlastic extends AbstractLeadedComponent<String> {
@Override @Override
protected Shape getBodyShape() { protected Shape getBodyShape() {
return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(), return new Rectangle2D.Double(0f, 0f, getLength().convertToPixels(), getClosestOdd(getWidth().convertToPixels()));
getClosestOdd(getWidth().convertToPixels()));
} }
@Override @Override
protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) { protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
Color finalMarkerColor; Color finalMarkerColor;
if (outlineMode) { if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance() Theme theme =
.readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalMarkerColor = theme.getOutlineColor(); finalMarkerColor = theme.getOutlineColor();
} else { } else {
finalMarkerColor = markerColor; finalMarkerColor = markerColor;
@@ -106,8 +107,7 @@ public class DiodePlastic extends AbstractLeadedComponent<String> {
g2d.setColor(finalMarkerColor); g2d.setColor(finalMarkerColor);
int width = (int) getLength().convertToPixels(); int width = (int) getLength().convertToPixels();
int markerWidth = (int) MARKER_WIDTH.convertToPixels(); int markerWidth = (int) MARKER_WIDTH.convertToPixels();
g2d.fillRect(width - markerWidth, 0, markerWidth, g2d.fillRect(width - markerWidth, 0, markerWidth, getClosestOdd(getWidth().convertToPixels()));
getClosestOdd(getWidth().convertToPixels()));
} }
@EditableProperty(name = "Marker") @EditableProperty(name = "Marker")
@@ -10,7 +10,9 @@ import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.measures.Size; import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "Diode (schematic symbol)", author = "Branislav Stojkovic", category = "Schematics", creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "D", description = "Diode schematic symbol", zOrder = IDIYComponent.COMPONENT) @ComponentDescriptor(name = "Diode (schematic symbol)", author = "Branislav Stojkovic", category = "Schematics",
creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "D", description = "Diode schematic symbol",
zOrder = IDIYComponent.COMPONENT)
public class DiodeSymbol extends AbstractDiodeSymbol { public class DiodeSymbol extends AbstractDiodeSymbol {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -23,17 +25,14 @@ public class DiodeSymbol extends AbstractDiodeSymbol {
g2d.rotate(-Math.PI / 4, width / 2, height / 2); g2d.rotate(-Math.PI / 4, width / 2, height / 2);
g2d.setColor(LEAD_COLOR); g2d.setColor(LEAD_COLOR);
g2d.drawLine(0, height / 2, (width - size) / 2, height / 2); g2d.drawLine(0, height / 2, (width - size) / 2, height / 2);
g2d.drawLine((int) (width + size / Math.sqrt(2) + bandSize) / 2, g2d.drawLine((int) (width + size / Math.sqrt(2) + bandSize) / 2, height / 2, width, height / 2);
height / 2, width, height / 2);
g2d.setColor(COLOR); g2d.setColor(COLOR);
g2d.fill(new Polygon(new int[] { (width - size) / 2, g2d.fill(new Polygon(new int[] {(width - size) / 2, (width - size) / 2,
(width - size) / 2, (int) ((width - size) / 2 + size / Math.sqrt(2))}, new int[] {(height - size) / 2, (height + size) / 2,
(int) ((width - size) / 2 + size / Math.sqrt(2)) }, new int[] { height / 2}, 3));
(height - size) / 2, (height + size) / 2, height / 2 }, 3));
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(bandSize)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(bandSize));
g2d.drawLine((int) ((width - size) / 2 + size / Math.sqrt(2)), g2d.drawLine((int) ((width - size) / 2 + size / Math.sqrt(2)), (height - size) / 2,
(height - size) / 2, (int) ((width - size) / 2 + size (int) ((width - size) / 2 + size / Math.sqrt(2)), (height + size) / 2);
/ Math.sqrt(2)), (height + size) / 2);
} }
@Override @Override
@@ -42,7 +41,6 @@ public class DiodeSymbol extends AbstractDiodeSymbol {
int bandSize = (int) BAND_SIZE.convertToPixels(); int bandSize = (int) BAND_SIZE.convertToPixels();
g2d.setColor(getBodyColor()); g2d.setColor(getBodyColor());
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(bandSize)); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(bandSize));
g2d.drawLine((int) (width / Math.sqrt(2)) + bandSize, 0, (int) (width g2d.drawLine((int) (width / Math.sqrt(2)) + bandSize, 0, (int) (width / Math.sqrt(2) + bandSize), (int) width);
/ Math.sqrt(2) + bandSize), (int) width);
} }
} }
@@ -30,7 +30,9 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit; import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants; import org.diylc.utils.Constants;
@ComponentDescriptor(name = "IC Symbol", author = "Branislav Stojkovic", category = "Schematics", instanceNamePrefix = "IC", description = "IC symbol with 3 or 5 contacts", stretchable = false, zOrder = IDIYComponent.COMPONENT, rotatable = false) @ComponentDescriptor(name = "IC Symbol", author = "Branislav Stojkovic", category = "Schematics",
instanceNamePrefix = "IC", description = "IC symbol with 3 or 5 contacts", stretchable = false,
zOrder = IDIYComponent.COMPONENT, rotatable = false)
public class ICSymbol extends AbstractTransparentComponent<String> { public class ICSymbol extends AbstractTransparentComponent<String> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -41,8 +43,8 @@ public class ICSymbol extends AbstractTransparentComponent<String> {
protected ICPointCount icPointCount = ICPointCount._5; protected ICPointCount icPointCount = ICPointCount._5;
protected String value = ""; protected String value = "";
protected Point[] controlPoints = new Point[] { new Point(0, 0), new Point(0, 0), protected Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0), new Point(0, 0),
new Point(0, 0), new Point(0, 0), new Point(0, 0) }; new Point(0, 0)};
protected Color bodyColor = BODY_COLOR; protected Color bodyColor = BODY_COLOR;
protected Color borderColor = BORDER_COLOR; protected Color borderColor = BORDER_COLOR;
protected Display display = Display.NAME; protected Display display = Display.NAME;
@@ -54,16 +56,15 @@ public class ICSymbol extends AbstractTransparentComponent<String> {
} }
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
Project project, IDrawingObserver drawingObserver) { IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) { if (checkPointsClipped(g2d.getClip())) {
return; return;
} }
int pinSpacing = (int) PIN_SPACING.convertToPixels(); int pinSpacing = (int) PIN_SPACING.convertToPixels();
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
/ MAX_ALPHA));
} }
Shape[] body = getBody(); Shape[] body = getBody();
@@ -73,8 +74,8 @@ public class ICSymbol extends AbstractTransparentComponent<String> {
g2d.setComposite(oldComposite); g2d.setComposite(oldComposite);
Color finalBorderColor; Color finalBorderColor;
if (outlineMode) { if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject( Theme theme =
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalBorderColor = theme.getOutlineColor(); finalBorderColor = theme.getOutlineColor();
} else { } else {
finalBorderColor = borderColor; finalBorderColor = borderColor;
@@ -90,14 +91,14 @@ public class ICSymbol extends AbstractTransparentComponent<String> {
g2d.setFont(LABEL_FONT); g2d.setFont(LABEL_FONT);
Color finalLabelColor; Color finalLabelColor;
if (outlineMode) { if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject( Theme theme =
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalLabelColor = componentState == ComponentState.SELECTED finalLabelColor =
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED : theme componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
.getOutlineColor(); : theme.getOutlineColor();
} else { } else {
finalLabelColor = componentState == ComponentState.SELECTED finalLabelColor =
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: LABEL_COLOR; : LABEL_COLOR;
} }
g2d.setColor(finalLabelColor); g2d.setColor(finalLabelColor);
@@ -110,21 +111,21 @@ public class ICSymbol extends AbstractTransparentComponent<String> {
if (display == Display.BOTH) { if (display == Display.BOTH) {
label = getName() + " " + (getValue() == null ? "" : getValue().toString()); label = getName() + " " + (getValue() == null ? "" : getValue().toString());
} }
drawCenteredText(g2d, label, x, drawCenteredText(g2d, label, x, controlPoints[0].y + pinSpacing, HorizontalAlignment.CENTER,
controlPoints[0].y + pinSpacing, HorizontalAlignment.CENTER,
VerticalAlignment.CENTER); VerticalAlignment.CENTER);
// Draw +/- markers // Draw +/- markers
drawCenteredText(g2d, "-", controlPoints[0].x + pinSpacing, controlPoints[0].y, drawCenteredText(g2d, "-", controlPoints[0].x + pinSpacing, controlPoints[0].y, HorizontalAlignment.CENTER,
HorizontalAlignment.CENTER, VerticalAlignment.CENTER); VerticalAlignment.CENTER);
drawCenteredText(g2d, "+", controlPoints[1].x + pinSpacing, controlPoints[1].y, drawCenteredText(g2d, "+", controlPoints[1].x + pinSpacing, controlPoints[1].y, HorizontalAlignment.CENTER,
HorizontalAlignment.CENTER, VerticalAlignment.CENTER); VerticalAlignment.CENTER);
} }
@Override @Override
public void drawIcon(Graphics2D g2d, int width, int height) { public void drawIcon(Graphics2D g2d, int width, int height) {
int margin = 3 * width / 32; int margin = 3 * width / 32;
Area area = new Area(new Polygon(new int[] { margin, margin, width - margin }, new int[] { Area area =
margin, height - margin, height / 2 }, 3)); new Area(new Polygon(new int[] {margin, margin, width - margin},
new int[] {margin, height - margin, height / 2}, 3));
// area.subtract(new Area(new Rectangle2D.Double(0, 0, 2 * margin, // area.subtract(new Area(new Rectangle2D.Double(0, 0, 2 * margin,
// height))); // height)));
area.intersect(new Area(new Rectangle2D.Double(2 * margin, 0, width, height))); area.intersect(new Area(new Rectangle2D.Double(2 * margin, 0, width, height)));
@@ -132,10 +133,8 @@ public class ICSymbol extends AbstractTransparentComponent<String> {
g2d.fill(area); g2d.fill(area);
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.setFont(LABEL_FONT.deriveFont(8f)); g2d.setFont(LABEL_FONT.deriveFont(8f));
drawCenteredText(g2d, "-", 3 * margin, height / 3, HorizontalAlignment.CENTER, drawCenteredText(g2d, "-", 3 * margin, height / 3, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
VerticalAlignment.CENTER); drawCenteredText(g2d, "+", 3 * margin + 1, height * 2 / 3, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
drawCenteredText(g2d, "+", 3 * margin + 1, height * 2 / 3, HorizontalAlignment.CENTER,
VerticalAlignment.CENTER);
// g2d.setStroke(new BasicStroke(1f, BasicStroke.CAP_ROUND, // g2d.setStroke(new BasicStroke(1f, BasicStroke.CAP_ROUND,
// BasicStroke.JOIN_ROUND)); // BasicStroke.JOIN_ROUND));
g2d.draw(area); g2d.draw(area);
@@ -176,9 +175,9 @@ public class ICSymbol extends AbstractTransparentComponent<String> {
int pinSpacing = (int) PIN_SPACING.convertToPixels(); int pinSpacing = (int) PIN_SPACING.convertToPixels();
int x = controlPoints[0].x; int x = controlPoints[0].x;
int y = controlPoints[0].y; int y = controlPoints[0].y;
Shape triangle = new Polygon(new int[] { x + pinSpacing / 2, x + pinSpacing * 11 / 2, Shape triangle =
x + pinSpacing / 2 }, new int[] { y - pinSpacing * 3 / 2, y + pinSpacing, new Polygon(new int[] {x + pinSpacing / 2, x + pinSpacing * 11 / 2, x + pinSpacing / 2}, new int[] {
y + pinSpacing * 7 / 2 }, 3); y - pinSpacing * 3 / 2, y + pinSpacing, y + pinSpacing * 7 / 2}, 3);
body[0] = triangle; body[0] = triangle;
GeneralPath polyline = new GeneralPath(); GeneralPath polyline = new GeneralPath();
@@ -10,7 +10,9 @@ import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
@ComponentDescriptor(name = "JFET Symbol", author = "Branislav Stojkovic", category = "Schematics", instanceNamePrefix = "Q", description = "JFET transistor schematic symbol", stretchable = false, zOrder = IDIYComponent.COMPONENT, rotatable = true) @ComponentDescriptor(name = "JFET Symbol", author = "Branislav Stojkovic", category = "Schematics",
instanceNamePrefix = "Q", description = "JFET transistor schematic symbol", stretchable = false,
zOrder = IDIYComponent.COMPONENT, rotatable = true)
public class JFETSymbol extends AbstractTransistorSymbol { public class JFETSymbol extends AbstractTransistorSymbol {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -45,13 +47,13 @@ public class JFETSymbol extends AbstractTransistorSymbol {
Polygon arrow; Polygon arrow;
if (polarity == FETPolarity.NEGATIVE) { if (polarity == FETPolarity.NEGATIVE) {
arrow = new Polygon(new int[] { x + pinSpacing * 2 / 6, x + pinSpacing * 2 / 6, arrow =
x + pinSpacing * 6 / 6 }, new int[] { y - pinSpacing / 5, new Polygon(new int[] {x + pinSpacing * 2 / 6, x + pinSpacing * 2 / 6, x + pinSpacing * 6 / 6}, new int[] {
y + pinSpacing / 5, y }, 3); y - pinSpacing / 5, y + pinSpacing / 5, y}, 3);
} else { } else {
arrow = new Polygon(new int[] { x + pinSpacing / 6, x + pinSpacing * 5 / 6, arrow =
x + pinSpacing * 5 / 6 }, new int[] { y, y + pinSpacing / 5, new Polygon(new int[] {x + pinSpacing / 6, x + pinSpacing * 5 / 6, x + pinSpacing * 5 / 6}, new int[] {y,
y - pinSpacing / 5 }, 3); y + pinSpacing / 5, y - pinSpacing / 5}, 3);
} }
body[2] = arrow; body[2] = arrow;
} }

Some files were not shown because too many files have changed in this diff Show More