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

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