outline mode

improved auto-create for pads
This commit is contained in:
bancika
2011-03-05 19:53:19 +00:00
parent 79c29dc349
commit 943d123ca9
46 changed files with 546 additions and 224 deletions
@@ -5,7 +5,7 @@
</entry>
<entry>
<string>lastPath</string>
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
<string>C:\Documents and Settings\Branislav Stojkovic\My Documents\Downloads</string>
</entry>
<entry>
<string>abnormalExit</string>
@@ -31,6 +31,12 @@
<blue>240</blue>
<alpha>240</alpha>
</gridColor>
<outlineColor>
<red>0</red>
<green>0</green>
<blue>0</blue>
<alpha>255</alpha>
</outlineColor>
</org.diylc.core.Theme>
</entry>
<entry>
@@ -45,6 +51,10 @@
<string>hiQualityRender</string>
<boolean>false</boolean>
</entry>
<entry>
<string>outline</string>
<boolean>true</boolean>
</entry>
<entry>
<string>exportGrid</string>
<boolean>true</boolean>
@@ -63,11 +73,11 @@
</entry>
<entry>
<string>autoCreatePads</string>
<boolean>false</boolean>
<boolean>true</boolean>
</entry>
<entry>
<string>continuousCreation</string>
<boolean>false</boolean>
<boolean>true</boolean>
</entry>
<entry>
<string>showTemplatesAtStartup</string>
@@ -32,5 +32,9 @@ public enum DrawOption {
/**
* Anti-aliasing is used when drawing.
*/
ANTIALIASING;
ANTIALIASING,
/**
* Draw components in outline mode.
*/
OUTLINE_MODE;
}
@@ -43,6 +43,8 @@ public interface IPlugInPort {
public static final String AUTO_EDIT_KEY = "autoEdit";
public static final String ABNORMAL_EXIT_KEY = "abnormalExit";
public static final String WHEEL_ZOOM_KEY = "wheelZoom";
public static final String OUTLINE_KEY = "outline";
public static final String THEME_KEY = "theme";
/**
* Returns size of the canvas that takes project dimensions into account as
@@ -63,8 +63,8 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) {
return;
}
@@ -13,14 +13,19 @@ import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import org.diylc.common.Display;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.core.ComponentState;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.Theme;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
import com.diyfever.gui.miscutils.ConfigurationManager;
/**
* Base class for all leaded components such as resistors or capacitors. Has two
@@ -45,7 +50,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
protected Color bodyColor = Color.white;
protected Color borderColor = Color.black;
protected Color labelColor = LABEL_COLOR;
protected Display display = Display.NAME;
protected Display display = Display.VALUE;
protected AbstractLeadedComponent() {
super();
@@ -60,8 +65,8 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
double distance = points[0].distance(points[1]);
Shape shape = getBodyShape();
// If there's no body, just draw the line connecting the ending points.
@@ -74,13 +79,32 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
int width = getClosestOdd(this.width.convertToPixels());
Shape body = new Ellipse2D.Double(points[0].x - width / 2, points[0].y - width / 2,
width, width);
g2d.setColor(bodyColor);
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
/ MAX_ALPHA));
}
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : bodyColor);
g2d.fill(body);
Color finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor;
g2d.setComposite(oldComposite);
Color finalBorderColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : theme
.getOutlineColor();
} else {
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: borderColor;
}
g2d.setColor(finalBorderColor);
g2d.draw(body);
drawLead(g2d, componentState);
if (!outlineMode) {
drawLead(g2d, componentState);
}
} else {
// Normal mode with component body in the center and two lead parts.
Rectangle shapeRect = shape.getBounds();
@@ -99,23 +123,42 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
}
if (bodyColor != null) {
if (bodyColor != null) {
g2d.setColor(bodyColor);
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : bodyColor);
g2d.fill(shape);
}
}
decorateComponentBody(g2d);
decorateComponentBody(g2d, outlineMode);
g2d.setComposite(oldComposite);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
Color finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor;
Color finalBorderColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : theme
.getOutlineColor();
} else {
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: borderColor;
}
g2d.setColor(finalBorderColor);
g2d.draw(shape);
// Draw label.
g2d.setFont(LABEL_FONT);
Color finalLabelFont = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: labelColor;
g2d.setColor(finalLabelFont);
Color finalLabelColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalLabelColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED : theme
.getOutlineColor();
} else {
finalLabelColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: labelColor;
}
g2d.setColor(finalLabelColor);
FontMetrics fontMetrics = g2d.getFontMetrics();
String label = display == Display.NAME ? getName() : getValue().toString();
// Adjust label angle if needed to make sure that it's readable.
@@ -128,30 +171,31 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
calculateLabelYCoordinate(shapeRect, textRect, fontMetrics));
// Go back to the original transformation to draw leads.
g2d.setTransform(oldTransform);
int leadThickness = getClosestOdd(getLeadThickness());
double leadLength = (distance - shapeRect.width) / 2 - leadThickness / 2;
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
Color leadColor = shouldShadeLeads() ? getLeadColor(componentState).darker()
: getLeadColor(componentState);
g2d.setColor(leadColor);
int endX = (int) (points[0].x + Math.cos(theta) * leadLength);
int endY = (int) Math.round(points[0].y + Math.sin(theta) * leadLength);
g2d.drawLine(points[0].x, points[0].y, endX, endY);
endX = (int) (points[1].x + Math.cos(theta - Math.PI) * leadLength);
endY = (int) Math.round(points[1].y + Math.sin(theta - Math.PI) * leadLength);
g2d.drawLine(points[1].x, points[1].y, endX, endY);
if (shouldShadeLeads()) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
leadColor = getLeadColor(componentState);
if (!outlineMode) {
g2d.setTransform(oldTransform);
int leadThickness = getClosestOdd(getLeadThickness());
double leadLength = (distance - shapeRect.width) / 2 - leadThickness / 2;
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
Color leadColor = shouldShadeLeads() ? getLeadColor(componentState).darker()
: getLeadColor(componentState);
g2d.setColor(leadColor);
g2d.drawLine(points[0].x, points[0].y, (int) (points[0].x + Math.cos(theta)
* leadLength), (int) (points[0].y + Math.sin(theta) * leadLength));
g2d
.drawLine(points[1].x, points[1].y, (int) (points[1].x + Math.cos(theta
- Math.PI)
* leadLength), (int) (points[1].y + Math.sin(theta - Math.PI)
* leadLength));
int endX = (int) (points[0].x + Math.cos(theta) * leadLength);
int endY = (int) Math.round(points[0].y + Math.sin(theta) * leadLength);
g2d.drawLine(points[0].x, points[0].y, endX, endY);
endX = (int) (points[1].x + Math.cos(theta - Math.PI) * leadLength);
endY = (int) Math.round(points[1].y + Math.sin(theta - Math.PI) * leadLength);
g2d.drawLine(points[1].x, points[1].y, endX, endY);
if (shouldShadeLeads()) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
leadColor = getLeadColor(componentState);
g2d.setColor(leadColor);
g2d.drawLine(points[0].x, points[0].y, (int) (points[0].x + Math.cos(theta)
* leadLength), (int) (points[0].y + Math.sin(theta) * leadLength));
g2d.drawLine(points[1].x, points[1].y, (int) (points[1].x + Math.cos(theta
- Math.PI)
* leadLength), (int) (points[1].y + Math.sin(theta - Math.PI)
* leadLength));
}
}
}
}
@@ -170,7 +214,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
}
}
protected void decorateComponentBody(Graphics2D g2d) {
protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
// Do nothing.
}
@@ -103,10 +103,11 @@ public interface IDIYComponent<T> extends Serializable {
*
* @param g2d
* @param componentState
* @param outlineMode
* @param project
* @param drawingObserver
*/
void draw(Graphics2D g2d, ComponentState componentState, Project project,
void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
IDrawingObserver drawingObserver);
/**
@@ -10,12 +10,14 @@ public class Theme implements Serializable {
private String name;
private Color bgColor;
private Color gridColor;
private Color outlineColor;
public Theme(String name, Color bgColor, Color gridColor) {
public Theme(String name, Color bgColor, Color gridColor, Color outlineColor) {
super();
this.name = name;
this.bgColor = bgColor;
this.gridColor = gridColor;
this.outlineColor = outlineColor;
}
public String getName() {
@@ -30,12 +32,17 @@ public class Theme implements Serializable {
return gridColor;
}
public Color getOutlineColor() {
return outlineColor;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((bgColor == null) ? 0 : bgColor.hashCode());
result = prime * result + ((gridColor == null) ? 0 : gridColor.hashCode());
result = prime * result + ((outlineColor == null) ? 0 : outlineColor.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@@ -59,6 +66,11 @@ public class Theme implements Serializable {
return false;
} else if (!gridColor.equals(other.gridColor))
return false;
if (outlineColor == null) {
if (other.outlineColor != null)
return false;
} else if (!outlineColor.equals(other.outlineColor))
return false;
if (name == null) {
if (other.name != null)
return false;
@@ -46,14 +46,14 @@ public class DrawingManager {
public static int CONTROL_POINT_SIZE = 7;
public static final String ZOOM_KEY = "zoom";
public static final String THEME_KEY = "theme";
public static String DEBUG_COMPONENT_AREAS = "org.diylc.debugComponentAreas";
public static Color GRID_COLOR = new Color(240, 240, 240);
public static Color CONTROL_POINT_COLOR = Color.black;
public static Color CONTROL_POINT_COLOR = Color.blue;
public static Color SELECTED_CONTROL_POINT_COLOR = Color.green;
private Theme theme = new Theme("Light", Constants.CANVAS_COLOR, GRID_COLOR);
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;
@@ -80,10 +80,6 @@ public class DrawingManager {
String debugComponentAreasStr = System.getProperty(DEBUG_COMPONENT_AREAS);
debugComponentAreas = debugComponentAreasStr != null
&& debugComponentAreasStr.equalsIgnoreCase("true");
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(THEME_KEY, null);
if (theme != null) {
this.theme = theme;
}
}
/**
@@ -220,7 +216,8 @@ public class DrawingManager {
}
// Draw the component through the g2dWrapper.
try {
component.draw(g2dWrapper, state, 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);
@@ -235,7 +232,7 @@ public class DrawingManager {
// Draw control points.
if (drawOptions.contains(DrawOption.CONTROL_POINTS)) {
// Draw unselected points first to make sure they are below.
if (dragInProgress) {
if (dragInProgress || drawOptions.contains(DrawOption.OUTLINE_MODE)) {
for (IDIYComponent<?> component : project.getComponents()) {
for (int i = 0; i < component.getControlPointCount(); i++) {
VisibilityPolicy visibilityPolicy = component
@@ -247,7 +244,6 @@ public class DrawingManager {
&& !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
@@ -283,7 +279,8 @@ public class DrawingManager {
g2dWrapper.startedDrawingComponent();
g2dWrapper.setComposite(slotComposite);
try {
componentSlot.draw(g2dWrapper, ComponentState.NORMAL, project, g2dWrapper);
componentSlot.draw(g2dWrapper, ComponentState.NORMAL, drawOptions
.contains(DrawOption.OUTLINE_MODE), project, g2dWrapper);
} catch (Exception e) {
LOG.error("Error drawing " + componentSlot.getName(), e);
failedComponents.add(componentSlot);
@@ -393,7 +390,7 @@ public class DrawingManager {
public void setTheme(Theme theme) {
this.theme = theme;
ConfigurationManager.getInstance().writeValue(THEME_KEY, theme);
ConfigurationManager.getInstance().writeValue(IPlugInPort.THEME_KEY, theme);
messageDispatcher.dispatchMessage(EventType.REPAINT);
}
}
@@ -800,7 +800,8 @@ public class Presenter implements IPlugInPort {
for (int j = i + 1; j < controlPoints.length; j++) {
if (controlPoints[i] != null && controlPoints[j] != null
&& controlPoints[i].equals(controlPoints[j])) {
// Control points collision detected, cannot make this move.
// Control points collision detected, cannot make
// this move.
return true;
}
}
@@ -1171,13 +1172,25 @@ public class Presenter implements IPlugInPort {
currentProject.getComponents().add(component);
}
if (canCreatePads
&& ConfigurationManager.getInstance().readBoolean(IPlugInPort.AUTO_PADS_KEY, false)) {
&& ConfigurationManager.getInstance().readBoolean(IPlugInPort.AUTO_PADS_KEY, false)
&& !(component instanceof SolderPad)) {
ComponentType padType = ComponentProcessor.getInstance().extractComponentTypeFrom(
SolderPad.class);
for (int i = 0; i < component.getControlPointCount(); i++) {
if (component.isControlPointSticky(i)) {
SolderPad pad = new SolderPad();
pad.setControlPoint(component.getControlPoint(i), 0);
addComponent(pad, ComponentProcessor.getInstance().extractComponentTypeFrom(
SolderPad.class), false);
try {
IDIYComponent<?> pad = instantiationManager.instantiateComponent(padType,
component.getControlPoint(i), currentProject);
pad.setControlPoint(component.getControlPoint(i), 0);
addComponent(pad, padType, false);
} catch (Exception e) {
LOG.warn("Could not auto-create solder pad", e);
}
// SolderPad pad = new SolderPad();
// pad.setControlPoint(component.getControlPoint(i), 0);
// addComponent(pad,
// ComponentProcessor.getInstance().extractComponentTypeFrom(
// SolderPad.class), false);
}
}
}
@@ -21,6 +21,7 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.VolatileImage;
import java.util.EnumSet;
import java.util.Set;
import javax.swing.AbstractAction;
import javax.swing.JComponent;
@@ -47,11 +48,11 @@ class CanvasPanel extends JComponent implements Autoscroll {
private static boolean USE_HARDWARE_ACCELLERATION = false;
static final EnumSet<DrawOption> DRAW_OPTIONS = EnumSet.of(DrawOption.GRID,
DrawOption.SELECTION, DrawOption.ZOOM, DrawOption.CONTROL_POINTS);
static final EnumSet<DrawOption> DRAW_OPTIONS_ANTI_ALIASING = EnumSet.of(DrawOption.GRID,
DrawOption.SELECTION, DrawOption.ZOOM, DrawOption.ANTIALIASING,
DrawOption.CONTROL_POINTS);
// static final EnumSet<DrawOption> DRAW_OPTIONS = EnumSet.of(DrawOption.GRID,
// DrawOption.SELECTION, DrawOption.ZOOM, DrawOption.CONTROL_POINTS);
// static final EnumSet<DrawOption> DRAW_OPTIONS_ANTI_ALIASING = EnumSet.of(DrawOption.GRID,
// DrawOption.SELECTION, DrawOption.ZOOM, DrawOption.ANTIALIASING,
// DrawOption.CONTROL_POINTS);
public CanvasPanel(IPlugInPort plugInPort) {
super();
@@ -114,9 +115,15 @@ class CanvasPanel extends JComponent implements Autoscroll {
}
Graphics2D g2d = (Graphics2D) bufferImage.getGraphics();
g2d.setClip(getVisibleRect());
plugInPort.draw(g2d, ConfigurationManager.getInstance().readBoolean(
IPlugInPort.ANTI_ALIASING_KEY, true) ? DRAW_OPTIONS_ANTI_ALIASING : DRAW_OPTIONS,
null);
Set<DrawOption> drawOptions = EnumSet.of(DrawOption.GRID, DrawOption.SELECTION,
DrawOption.ZOOM, DrawOption.CONTROL_POINTS);
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.ANTI_ALIASING_KEY, true)) {
drawOptions.add(DrawOption.ANTIALIASING);
}
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.OUTLINE_KEY, false)) {
drawOptions.add(DrawOption.OUTLINE_MODE);
}
plugInPort.draw(g2d, drawOptions, null);
if (USE_HARDWARE_ACCELLERATION) {
VolatileImage volatileImage = (VolatileImage) bufferImage;
do {
@@ -52,6 +52,8 @@ public class ConfigPlugin implements IPlugIn {
"Hi-Quality Rendering", IPlugInPort.HI_QUALITY_RENDER_KEY, false), CONFIG_MENU);
swingUI.injectMenuAction(ActionFactory.getInstance().createConfigAction(plugInPort,
"Mouse Wheel Zoom", IPlugInPort.WHEEL_ZOOM_KEY, false), CONFIG_MENU);
swingUI.injectMenuAction(ActionFactory.getInstance().createConfigAction(plugInPort,
"Outline Mode", IPlugInPort.OUTLINE_KEY, false), CONFIG_MENU);
swingUI.injectMenuAction(ActionFactory.getInstance().createConfigAction(plugInPort,
"Snap to Grid", IPlugInPort.SNAP_TO_GRID_KEY, true), CONFIG_MENU);
swingUI.injectMenuAction(ActionFactory.getInstance().createConfigAction(plugInPort,
@@ -33,16 +33,19 @@ public class ProjectDrawingProvider implements IDrawingProvider {
@Override
public void draw(Graphics g) {
EnumSet<DrawOption> options = EnumSet.of(DrawOption.ANTIALIASING);
EnumSet<DrawOption> drawOptions = EnumSet.of(DrawOption.ANTIALIASING);
if (useZoom) {
options.add(DrawOption.ZOOM);
drawOptions.add(DrawOption.ZOOM);
}
if (showGridWhenNeeded
&& ConfigurationManager.getInstance().readBoolean(IPlugInPort.EXPORT_GRID_KEY,
false)) {
options.add(DrawOption.GRID);
drawOptions.add(DrawOption.GRID);
}
plugInPort.draw((Graphics2D) g, options, null);
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.OUTLINE_KEY, false)) {
drawOptions.add(DrawOption.OUTLINE_MODE);
}
plugInPort.draw((Graphics2D) g, drawOptions, null);
}
@Override
@@ -5,6 +5,8 @@ import java.awt.Color;
import java.awt.Stroke;
import java.awt.Toolkit;
import org.diylc.core.Theme;
public class Constants {
public static final int PIXELS_PER_INCH = 200;
@@ -15,4 +17,9 @@ public class Constants {
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 Color TRANSPARENT_COLOR = new Color(0, 0, 0, 0);
}
@@ -133,8 +133,8 @@ public class MockDIYComponent implements IDIYComponent<Capacitance> {
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
g2d.setColor(componentState.equals(ComponentState.SELECTED) ? color : color.darker());
g2d.fillRect(leftTopCorner.x, leftTopCorner.y, 200, 50);
}
@@ -12,4 +12,10 @@
<blue>193</blue>
<alpha>255</alpha>
</gridColor>
<outlineColor>
<red>255</red>
<green>255</green>
<blue>255</blue>
<alpha>255</alpha>
</outlineColor>
</org.diylc.core.Theme>
@@ -12,4 +12,10 @@
<blue>40</blue>
<alpha>255</alpha>
</gridColor>
<outlineColor>
<red>255</red>
<green>255</green>
<blue>255</blue>
<alpha>255</alpha>
</outlineColor>
</org.diylc.core.Theme>
@@ -1,15 +1,21 @@
<org.diylc.core.Theme>
<name>Light</name>
<bgColor>
<red>255</red>
<green>255</green>
<blue>255</blue>
<alpha>255</alpha>
</bgColor>
<gridColor>
<red>240</red>
<green>240</green>
<blue>240</blue>
<alpha>240</alpha>
</gridColor>
<name>Light</name>
<bgColor>
<red>255</red>
<green>255</green>
<blue>255</blue>
<alpha>255</alpha>
</bgColor>
<gridColor>
<red>240</red>
<green>240</green>
<blue>240</blue>
<alpha>240</alpha>
</gridColor>
<outlineColor>
<red>0</red>
<green>0</green>
<blue>0</blue>
<alpha>255</alpha>
</outlineColor>
</org.diylc.core.Theme>
@@ -309,5 +309,29 @@
</changes>
<url>http://code.google.com/p/diy-layout-creator/downloads/list</url>
</com.diyfever.gui.update.Version>
<com.diyfever.gui.update.Version>
<versionNumber>
<major>3</major>
<minor>0</minor>
<build>9</build>
</versionNumber>
<releaseDate>2011-03-03 20:00:00.000 CET</releaseDate>
<name></name>
<changes>
<com.diyfever.gui.update.Change>
<changeType>BUG_FIX</changeType>
<description>Auto-created solder pads aren't assigned with default settings and name</description>
</com.diyfever.gui.update.Change>
<com.diyfever.gui.update.Change>
<changeType>IMPROVEMENT</changeType>
<description></description>
</com.diyfever.gui.update.Change>
<com.diyfever.gui.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Outline mode that resembles PCB silkscreen</description>
</com.diyfever.gui.update.Change>
</changes>
<url>http://code.google.com/p/diy-layout-creator/downloads/list</url>
</com.diyfever.gui.update.Version>
</a>
</java.util.Arrays_-ArrayList>
@@ -4,6 +4,7 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/xstream-1.3.1.jar"/>
<classpathentry kind="lib" path="lib/log4j-1.2.15.jar"/>
<classpathentry kind="lib" path="lib/bancika-gui-framework.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/DIYLC"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -5,8 +5,8 @@ import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Shape;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.components.AbstractTransparentComponent;
import org.diylc.core.ComponentState;
@@ -17,6 +17,9 @@ import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
import com.diyfever.gui.miscutils.ConfigurationManager;
public abstract class AbstractBoard extends AbstractTransparentComponent<String> {
@@ -38,7 +41,7 @@ public abstract class AbstractBoard extends AbstractTransparentComponent<String>
protected Color borderColor = BORDER_COLOR;
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
IDrawingObserver drawingObserver) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
if (componentState != ComponentState.DRAGGING) {
@@ -41,14 +41,14 @@ public class EyeletBoard extends AbstractBoard {
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
Shape clip = g2d.getClip();
if (checkPointsClipped(clip) && !clip.contains(firstPoint.x, secondPoint.y)
&& !clip.contains(secondPoint.x, firstPoint.y)) {
return;
}
super.draw(g2d, componentState, project, drawingObserver);
super.draw(g2d, componentState, outlineMode, project, drawingObserver);
if (componentState != ComponentState.DRAGGING) {
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
@@ -37,14 +37,14 @@ public class MarshallPerfBoard extends AbstractBoard {
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
Shape clip = g2d.getClip();
if (checkPointsClipped(clip) && !clip.contains(firstPoint.x, secondPoint.y)
&& !clip.contains(secondPoint.x, firstPoint.y)) {
return;
}
super.draw(g2d, componentState, project, drawingObserver);
super.draw(g2d, componentState, outlineMode, project, drawingObserver);
if (componentState != ComponentState.DRAGGING) {
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
@@ -33,14 +33,14 @@ public class PerfBoard extends AbstractBoard {
protected Color padColor = COPPER_COLOR;
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
Shape clip = g2d.getClip();
if (checkPointsClipped(clip) && !clip.contains(firstPoint.x, secondPoint.y)
&& !clip.contains(secondPoint.x, firstPoint.y)) {
return;
}
super.draw(g2d, componentState, project, drawingObserver);
super.draw(g2d, componentState, outlineMode, project, drawingObserver);
if (componentState != ComponentState.DRAGGING) {
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
@@ -35,14 +35,14 @@ public class VeroBoard extends AbstractBoard {
protected OrientationHV orientation = OrientationHV.HORIZONTAL;
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
Shape clip = g2d.getClip();
if (checkPointsClipped(clip) && !clip.contains(firstPoint.x, secondPoint.y)
&& !clip.contains(secondPoint.x, firstPoint.y)) {
return;
}
super.draw(g2d, componentState, project, drawingObserver);
super.draw(g2d, componentState, outlineMode, project, drawingObserver);
if (componentState != ComponentState.DRAGGING) {
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
@@ -9,7 +9,6 @@ import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.Theme;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
@@ -33,8 +32,8 @@ public class Eyelet extends AbstractComponent<String> {
private String value = "";
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) {
return;
}
@@ -32,8 +32,8 @@ public class SolderPad extends AbstractComponent<Void> {
private Type type = Type.ROUND;
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) {
return;
}
@@ -33,8 +33,8 @@ public class TraceCut extends AbstractComponent<Void> {
protected Point point = new Point(0, 0);
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) {
return;
}
@@ -8,6 +8,7 @@ import java.awt.Point;
import java.awt.Shape;
import java.awt.geom.RoundRectangle2D;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.components.AbstractTransparentComponent;
import org.diylc.core.ComponentState;
@@ -20,6 +21,9 @@ import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
import com.diyfever.gui.miscutils.ConfigurationManager;
@ComponentDescriptor(name = "Mini Toggle Switch", category = "Electromechanical", author = "Branislav Stojkovic", description = "Panel mounted mini toggle switch", stretchable = false, zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "SW")
public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchType> {
@@ -166,8 +170,8 @@ public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchT
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) {
return;
}
@@ -179,27 +183,40 @@ public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchT
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
/ MAX_ALPHA));
}
g2d.setColor(BODY_COLOR);
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : BODY_COLOR);
g2d.fill(body);
g2d.setComposite(oldComposite);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : BORDER_COLOR);
Color finalBorderColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : theme
.getOutlineColor();
} else {
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: BORDER_COLOR;
}
g2d.setColor(finalBorderColor);
g2d.draw(body);
}
// Do not track these changes because the whole switch has been tracked
// so far.
drawingObserver.stopTracking();
// Draw lugs.
int circleDiameter = getClosestOdd((int) CIRCLE_SIZE.convertToPixels());
int lugWidth = getClosestOdd((int) LUG_WIDTH.convertToPixels());
int lugHeight = getClosestOdd((int) LUG_HEIGHT.convertToPixels());
for (Point p : controlPoints) {
g2d.setColor(CIRCLE_COLOR);
g2d.fillOval(p.x - circleDiameter / 2, p.y - circleDiameter / 2, circleDiameter,
circleDiameter);
g2d.setColor(LUG_COLOR);
g2d.fillRect(p.x - lugWidth / 2, p.y - lugHeight / 2, lugWidth, lugHeight);
if (!outlineMode) {
int circleDiameter = getClosestOdd((int) CIRCLE_SIZE.convertToPixels());
int lugWidth = getClosestOdd((int) LUG_WIDTH.convertToPixels());
int lugHeight = getClosestOdd((int) LUG_HEIGHT.convertToPixels());
for (Point p : controlPoints) {
g2d.setColor(CIRCLE_COLOR);
g2d.fillOval(p.x - circleDiameter / 2, p.y - circleDiameter / 2, circleDiameter,
circleDiameter);
g2d.setColor(LUG_COLOR);
g2d.fillRect(p.x - lugWidth / 2, p.y - lugHeight / 2, lugWidth, lugHeight);
}
}
}
@@ -14,7 +14,6 @@ import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.Theme;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
@@ -37,8 +36,8 @@ public class BOM extends AbstractComponent<Void> {
private Point point = new Point(0, 0);
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
List<BomEntry> bom = BomMaker.getInstance().createBom(project.getComponents());
// Cleanup entries that do not have a value set.
Iterator<BomEntry> iterator = bom.iterator();
@@ -13,7 +13,6 @@ import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.Theme;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
@@ -42,8 +41,8 @@ public class Image extends AbstractTransparentComponent<Void> {
private byte scale = 50;
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
double s = 1d * scale / DEFAULT_SCALE;
Point endPoint = new Point((int) (image.getIconWidth() * s),
(int) (image.getIconHeight() * s));
@@ -30,8 +30,8 @@ public class Label extends AbstractComponent<Void> {
private boolean center = true;
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
g2d.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED : color);
g2d.setFont(font);
FontMetrics fontMetrics = g2d.getFontMetrics();
@@ -5,6 +5,7 @@ import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.components.AbstractLeadedComponent;
import org.diylc.core.CreationMethod;
@@ -16,6 +17,9 @@ import org.diylc.core.measures.Capacitance;
import org.diylc.core.measures.CapacitanceUnit;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
import com.diyfever.gui.miscutils.ConfigurationManager;
@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> {
@@ -118,15 +122,24 @@ public class AxialElectrolyticCapacitor extends AbstractLeadedComponent<Capacita
}
@Override
protected void decorateComponentBody(Graphics2D g2d) {
protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
if (polarized) {
int markerLength = (int) (getLength().convertToPixels() * 0.2);
g2d.setColor(markerColor);
int width = getClosestOdd(getWidth().convertToPixels());
g2d
.fillRect((int) getLength().convertToPixels() - markerLength, 0, markerLength,
width);
g2d.setColor(tickColor);
int markerLength = (int) (getLength().convertToPixels() * 0.2);
if (!outlineMode) {
g2d.setColor(markerColor);
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);
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()
@@ -87,7 +87,7 @@ public class CapacitorSymbol extends AbstractSchematicLeadedSymbol<Capacitance>
}
@Override
protected void decorateComponentBody(Graphics2D g2d) {
protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
if (polarized) {
// Draw + sign.
g2d.setColor(getBorderColor());
@@ -159,8 +159,8 @@ public class PotentiometerPanel extends AbstractPotentiometer {
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
for (Area shape : getBody()) {
if (shape != null) {
@@ -7,6 +7,7 @@ import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.components.AbstractLeadedComponent;
import org.diylc.core.CreationMethod;
@@ -18,6 +19,9 @@ import org.diylc.core.measures.Capacitance;
import org.diylc.core.measures.CapacitanceUnit;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
import com.diyfever.gui.miscutils.ConfigurationManager;
@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 AbstractLeadedComponent<Capacitance> {
@@ -86,16 +90,25 @@ public class RadialElectrolytic extends AbstractLeadedComponent<Capacitance> {
}
@Override
protected void decorateComponentBody(Graphics2D g2d) {
protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
if (polarized) {
int totalDiameter = getClosestOdd(getLength().convertToPixels());
Area area = new Area(getBodyShape());
area
.subtract(new Area(new Rectangle2D.Double(0, 0, totalDiameter * 0.8,
totalDiameter)));
g2d.setColor(markerColor);
g2d.fill(area);
g2d.setColor(tickColor);
if (!outlineMode) {
Area area = new Area(getBodyShape());
area.subtract(new Area(new Rectangle2D.Double(0, 0, totalDiameter * 0.8,
totalDiameter)));
g2d.setColor(markerColor);
g2d.fill(area);
}
Color finalTickColor;
if (outlineMode) {
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) (totalDiameter * 0.9), totalDiameter / 2
- (int) (totalDiameter * 0.05), (int) (totalDiameter * 0.9), totalDiameter / 2
@@ -104,9 +104,9 @@ public class Resistor extends AbstractLeadedComponent<Resistance> {
}
@Override
protected void decorateComponentBody(Graphics2D g2d) {
protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
// int width = getWidth().convertToPixels();
if (colorCode == ResistorColorCode.NONE) {
if (colorCode == ResistorColorCode.NONE || outlineMode) {
return;
}
int height = getClosestOdd(getWidth().convertToPixels());
@@ -241,8 +241,8 @@ public class TrimmerPotentiometer extends AbstractPotentiometer {
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) {
return;
}
@@ -12,6 +12,7 @@ import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.common.Orientation;
import org.diylc.components.AbstractTransparentComponent;
@@ -19,11 +20,15 @@ import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.Theme;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
import com.diyfever.gui.miscutils.ConfigurationManager;
@ComponentDescriptor(name = "DIL IC", author = "Branislav Stojkovic", category = "Semiconductors", instanceNamePrefix = "IC", description = "IC with rectangular housing and two parallel rows of pins", stretchable = false, zOrder = IDIYComponent.COMPONENT)
public class DIL_IC extends AbstractTransparentComponent<String> {
@@ -248,38 +253,69 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) {
return;
}
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
Area mainArea = getBody()[0];
for (Point point : controlPoints) {
g2d.setColor(PIN_COLOR);
g2d.fillRect(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
g2d.setColor(PIN_BORDER_COLOR);
g2d.drawRect(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
if (!outlineMode) {
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
for (Point point : controlPoints) {
g2d.setColor(PIN_COLOR);
g2d.fillRect(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
g2d.setColor(PIN_BORDER_COLOR);
g2d.drawRect(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
}
}
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
/ MAX_ALPHA));
}
g2d.setColor(BODY_COLOR);
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : BODY_COLOR);
g2d.fill(mainArea);
g2d.setComposite(oldComposite);
g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : BORDER_COLOR);
Color finalBorderColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : theme
.getOutlineColor();
} else {
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : BORDER_COLOR;
}
g2d.setColor(finalBorderColor);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.draw(mainArea);
if (getBody()[1] != null) {
g2d.setColor(INDENT_COLOR);
g2d.fill(getBody()[1]);
if (outlineMode) {
Area area = new Area(mainArea);
area.subtract(getBody()[1]);
g2d.draw(area);
} else {
g2d.draw(mainArea);
if (getBody()[1] != null) {
g2d.setColor(INDENT_COLOR);
g2d.fill(getBody()[1]);
}
}
// Draw label.
g2d.setFont(LABEL_FONT);
g2d.setColor(LABEL_COLOR);
Color finalLabelColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalLabelColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED : theme
.getOutlineColor();
} else {
finalLabelColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: LABEL_COLOR;
}
g2d.setColor(finalLabelColor);
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
Rectangle2D rect = fontMetrics.getStringBounds(getName(), g2d);
int textHeight = (int) (rect.getHeight());
@@ -5,13 +5,18 @@ import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;
import org.diylc.common.IPlugInPort;
import org.diylc.components.AbstractLeadedComponent;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
import org.diylc.core.Theme;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
import com.diyfever.gui.miscutils.ConfigurationManager;
@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> {
@@ -20,7 +25,7 @@ public class DiodePlastic extends AbstractLeadedComponent<String> {
public static Size DEFAULT_WIDTH = new Size(1d / 4, SizeUnit.in);
public static Size DEFAULT_HEIGHT = new Size(1d / 8, SizeUnit.in);
public static Size MARKER_WIDTH = new Size(1.5d, SizeUnit.mm);
public static Size MARKER_WIDTH = new Size(1d, SizeUnit.mm);
public static Color BODY_COLOR = Color.darkGray;
public static Color MARKER_COLOR = Color.decode("#DDDDDD");
public static Color LABEL_COLOR = Color.white;
@@ -80,8 +85,16 @@ public class DiodePlastic extends AbstractLeadedComponent<String> {
}
@Override
protected void decorateComponentBody(Graphics2D g2d) {
g2d.setColor(markerColor);
protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
Color finalMarkerColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalMarkerColor = theme.getOutlineColor();
} else {
finalMarkerColor = markerColor;
}
g2d.setColor(finalMarkerColor);
int width = (int) getLength().convertToPixels();
int markerWidth = (int) MARKER_WIDTH.convertToPixels();
g2d.fillRect(width - markerWidth, 0, markerWidth, getClosestOdd(getWidth()
@@ -83,13 +83,15 @@ public class LED extends AbstractLeadedComponent<String> {
}
@Override
protected void decorateComponentBody(Graphics2D g2d) {
int size = getClosestOdd((int) (getLength().convertToPixels() * 1.2));
int innerSize = getClosestOdd(getLength().convertToPixels());
int x = (size - innerSize) / 2;
Shape s = new Ellipse2D.Double(x, x, innerSize, innerSize);
g2d.setColor(getBorderColor());
g2d.draw(s);
protected void decorateComponentBody(Graphics2D g2d, boolean outlineMode) {
if (!outlineMode) {
int size = getClosestOdd((int) (getLength().convertToPixels() * 1.2));
int innerSize = getClosestOdd(getLength().convertToPixels());
int x = (size - innerSize) / 2;
Shape s = new Ellipse2D.Double(x, x, innerSize, innerSize);
g2d.setColor(getBorderColor());
g2d.draw(s);
}
}
@EditableProperty(name = "Size")
@@ -10,6 +10,7 @@ import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.common.Orientation;
import org.diylc.components.AbstractTransparentComponent;
@@ -23,6 +24,9 @@ import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
import com.diyfever.gui.miscutils.ConfigurationManager;
@ComponentDescriptor(name = "Transistor (TO-220 package)", author = "Branislav Stojkovic", category = "Semiconductors", instanceNamePrefix = "Q", description = "Transistors with metal tab for heat sink mounting", stretchable = false, zOrder = IDIYComponent.COMPONENT)
public class TransistorTO220 extends AbstractTransparentComponent<String> {
@@ -40,7 +44,7 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
public static Size PIN_SPACING = new Size(0.1d, SizeUnit.in);
public static Size BODY_WIDTH = new Size(0.4d, SizeUnit.in);
public static Size BODY_HEIGHT = new Size(4.5d, SizeUnit.mm);
public static Size TAB_THICKNESS = new Size(0.05d, SizeUnit.in);
public static Size TAB_THICKNESS = new Size(1d, SizeUnit.mm);
private String value = "";
private Orientation orientation = Orientation.DEFAULT;
@@ -173,8 +177,8 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) {
return;
}
@@ -186,29 +190,63 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
/ MAX_ALPHA));
}
g2d.setColor(bodyColor);
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : bodyColor);
g2d.fill(mainArea);
g2d.setColor(tabColor);
Color finalTabColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalTabColor = theme.getOutlineColor();
} else {
finalTabColor = tabColor;
}
g2d.setColor(finalTabColor);
g2d.fill(tabArea);
g2d.setComposite(oldComposite);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.setColor(tabBorderColor);
g2d.draw(tabArea);
g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor);
if (!outlineMode) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.setColor(tabBorderColor);
g2d.draw(tabArea);
}
Color finalBorderColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : theme
.getOutlineColor();
} else {
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor;
}
g2d.setColor(finalBorderColor);
g2d.draw(mainArea);
// Draw pins.
for (Point point : controlPoints) {
g2d.setColor(PIN_COLOR);
g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
g2d.setColor(PIN_BORDER_COLOR);
g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
if (!outlineMode) {
for (Point point : controlPoints) {
g2d.setColor(PIN_COLOR);
g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
g2d.setColor(PIN_BORDER_COLOR);
g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
}
}
// Draw label.
g2d.setFont(LABEL_FONT);
g2d.setColor(LABEL_COLOR);
Color finalLabelColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalLabelColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED : theme
.getOutlineColor();
} else {
finalLabelColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: LABEL_COLOR;
}
g2d.setColor(finalLabelColor);
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
Rectangle2D rect = fontMetrics.getStringBounds(getName(), g2d);
int textHeight = (int) (rect.getHeight());
@@ -11,6 +11,7 @@ import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.common.Orientation;
import org.diylc.components.AbstractTransparentComponent;
@@ -24,6 +25,9 @@ import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
import com.diyfever.gui.miscutils.ConfigurationManager;
@ComponentDescriptor(name = "Transistor (TO-92 package)", author = "Branislav Stojkovic", category = "Semiconductors", instanceNamePrefix = "Q", description = "Transistor with small plastic or epoxy body", stretchable = false, zOrder = IDIYComponent.COMPONENT)
public class TransistorTO92 extends AbstractTransparentComponent<String> {
@@ -165,8 +169,8 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
if (checkPointsClipped(g2d.getClip())) {
return;
}
@@ -177,24 +181,48 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
/ MAX_ALPHA));
}
g2d.setColor(bodyColor);
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : bodyColor);
g2d.fill(mainArea);
g2d.setComposite(oldComposite);
g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor);
Color finalBorderColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : theme
.getOutlineColor();
} else {
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor;
}
g2d.setColor(finalBorderColor);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
g2d.draw(mainArea);
for (Point point : controlPoints) {
g2d.setColor(PIN_COLOR);
g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
g2d.setColor(PIN_BORDER_COLOR);
g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
if (!outlineMode) {
for (Point point : controlPoints) {
g2d.setColor(PIN_COLOR);
g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
g2d.setColor(PIN_BORDER_COLOR);
g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
}
}
// Draw label.
g2d.setFont(LABEL_FONT);
g2d.setColor(LABEL_COLOR);
Color finalLabelColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalLabelColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED : theme
.getOutlineColor();
} else {
finalLabelColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: LABEL_COLOR;
}
g2d.setColor(finalLabelColor);
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
Rectangle2D rect = fontMetrics.getStringBounds(getName(), g2d);
int textHeight = (int) (rect.getHeight());
@@ -9,6 +9,7 @@ import java.awt.Shape;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.common.Orientation;
import org.diylc.components.AbstractTransparentComponent;
@@ -16,11 +17,15 @@ import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.Theme;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
import com.diyfever.gui.miscutils.ConfigurationManager;
@ComponentDescriptor(name = "Tube Socket", author = "Branislav Stojkovic", category = "Tubes", instanceNamePrefix = "V", description = "Various types of tube/valve sockets", stretchable = false, zOrder = IDIYComponent.COMPONENT)
public class TubeSocket extends AbstractTransparentComponent<String> {
@@ -186,8 +191,8 @@ public class TubeSocket extends AbstractTransparentComponent<String> {
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
// g2d.setColor(Color.black);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
// for (int i = 0; i < controlPoints.length; i++) {
@@ -202,22 +207,34 @@ public class TubeSocket extends AbstractTransparentComponent<String> {
/ MAX_ALPHA));
}
if (componentState != ComponentState.DRAGGING) {
g2d.setColor(BODY_COLOR);
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : BODY_COLOR);
g2d.fill(body);
}
g2d.setComposite(oldComposite);
g2d.setColor(componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : BORDER_COLOR);
Color finalBorderColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(
IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : theme
.getOutlineColor();
} else {
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : BORDER_COLOR;
}
g2d.setColor(finalBorderColor);
g2d.draw(body);
// Draw pins
int pinSize = getClosestOdd(PIN_SIZE.convertToPixels());
for (int i = 1; i < controlPoints.length; i++) {
g2d.setColor(PIN_COLOR);
g2d.fillOval(controlPoints[i].x - pinSize / 2, controlPoints[i].y - pinSize / 2,
pinSize, pinSize);
g2d.setColor(PIN_BORDER_COLOR);
g2d.drawOval(controlPoints[i].x - pinSize / 2, controlPoints[i].y - pinSize / 2,
pinSize, pinSize);
if (!outlineMode) {
int pinSize = getClosestOdd(PIN_SIZE.convertToPixels());
for (int i = 1; i < controlPoints.length; i++) {
g2d.setColor(PIN_COLOR);
g2d.fillOval(controlPoints[i].x - pinSize / 2, controlPoints[i].y - pinSize / 2,
pinSize, pinSize);
g2d.setColor(PIN_BORDER_COLOR);
g2d.drawOval(controlPoints[i].x - pinSize / 2, controlPoints[i].y - pinSize / 2,
pinSize, pinSize);
}
}
}