hotspot tracking optimization

This commit is contained in:
bancika
2011-01-16 09:32:34 +00:00
parent b81d633ce5
commit 6f6d802829
17 changed files with 142 additions and 48 deletions
@@ -9,6 +9,7 @@ import java.awt.Point;
import java.awt.geom.CubicCurve2D; import java.awt.geom.CubicCurve2D;
import org.diylc.core.ComponentState; import org.diylc.core.ComponentState;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project; import org.diylc.core.Project;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size; import org.diylc.core.measures.Size;
@@ -57,8 +58,11 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
} }
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project) { public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
if (componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING) { if (componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING) {
// Do not track guidelines.
drawingObserver.stopTracking();
g2d.setStroke(new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10f, g2d.setStroke(new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10f,
new float[] { 2f, 3f }, 5f)); new float[] { 2f, 3f }, 5f));
g2d.setColor(GUIDELINE_COLOR); g2d.setColor(GUIDELINE_COLOR);
@@ -68,6 +72,7 @@ public abstract class AbstractCurvedComponent<T> extends AbstractTransparentComp
controlPoints[2].y); controlPoints[2].y);
g2d.drawLine(controlPoints[2].x, controlPoints[2].y, controlPoints[3].x, g2d.drawLine(controlPoints[2].x, controlPoints[2].y, controlPoints[3].x,
controlPoints[3].y); controlPoints[3].y);
drawingObserver.startTracking();
} }
CubicCurve2D curve = new CubicCurve2D.Double(controlPoints[0].x, controlPoints[0].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[1].x, controlPoints[1].y, controlPoints[2].x, controlPoints[2].y,
@@ -11,6 +11,7 @@ import java.awt.Rectangle;
import java.awt.Shape; import java.awt.Shape;
import org.diylc.core.ComponentState; import org.diylc.core.ComponentState;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project; import org.diylc.core.Project;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size; import org.diylc.core.measures.Size;
@@ -55,7 +56,8 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
} }
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project) { public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
double distance = points[0].distance(points[1]); double distance = points[0].distance(points[1]);
Shape shape = getBodyShape(); Shape shape = getBodyShape();
if (shape == null) { if (shape == null) {
@@ -92,6 +94,8 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
(int) ((shapeRect.width - distance) / 2 + leadLenght), (int) shapeRect.height / 2); (int) ((shapeRect.width - distance) / 2 + leadLenght), (int) shapeRect.height / 2);
g2d.drawLine((int) (shapeRect.width + distance) / 2, (int) shapeRect.height / 2, g2d.drawLine((int) (shapeRect.width + distance) / 2, (int) shapeRect.height / 2,
(int) ((shapeRect.width + distance) / 2 - leadLenght), (int) shapeRect.height / 2); (int) ((shapeRect.width + distance) / 2 - leadLenght), (int) shapeRect.height / 2);
// Do not track the label because that area was already covered.
drawingObserver.stopTracking();
// Draw label. // Draw label.
g2d.setFont(Constants.LABEL_FONT); g2d.setFont(Constants.LABEL_FONT);
g2d g2d
@@ -39,7 +39,7 @@ public interface IDIYComponent<T> extends Serializable {
public static final int ABOVE_BOARD = 6; public static final int ABOVE_BOARD = 6;
public static final int COMPONENT = 7; public static final int COMPONENT = 7;
public static final int ABOVE_COMPONENT = 8; public static final int ABOVE_COMPONENT = 8;
public static Color SELECTION_COLOR = Color.red; public static Color SELECTION_COLOR = Color.red;
/** /**
@@ -93,8 +93,10 @@ public interface IDIYComponent<T> extends Serializable {
* @param g2d * @param g2d
* @param componentState * @param componentState
* @param project * @param project
* @param drawingObserver
*/ */
void draw(Graphics2D g2d, ComponentState componentState, Project project); void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver);
/** /**
* Draws icon representation of the component. This should not depend on * Draws icon representation of the component. This should not depend on
@@ -0,0 +1,15 @@
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.
*
* @author Branislav Stojkovic
*/
public interface IDrawingObserver {
void stopTracking();
void startTracking();
}
@@ -37,6 +37,8 @@ import java.awt.image.renderable.RenderableImage;
import java.text.AttributedCharacterIterator; import java.text.AttributedCharacterIterator;
import java.util.Map; import java.util.Map;
import org.diylc.core.IDrawingObserver;
/** /**
* {@link Graphics2D} wrapper that keeps track of all drawing actions and * {@link Graphics2D} wrapper that keeps track of all drawing actions and
* creates an {@link Area} that corresponds to drawn objects. Before each * creates an {@link Area} that corresponds to drawn objects. Before each
@@ -47,12 +49,13 @@ import java.util.Map;
* *
* @author Branislav Stojkovic * @author Branislav Stojkovic
*/ */
class G2DWrapper extends Graphics2D { class G2DWrapper extends Graphics2D implements IDrawingObserver {
public static int LINE_SENSITIVITY_MARGIN = 2; public static int LINE_SENSITIVITY_MARGIN = 2;
public static int CURVE_SENSITIVITY = 6; public static int CURVE_SENSITIVITY = 6;
private boolean drawingComponent = false; private boolean drawingComponent = false;
private boolean trackingAllowed = true;
private Graphics2D canvasGraphics; private Graphics2D canvasGraphics;
private Stroke originalStroke; private Stroke originalStroke;
@@ -89,6 +92,7 @@ class G2DWrapper extends Graphics2D {
originalFont = canvasGraphics.getFont(); originalFont = canvasGraphics.getFont();
currentTx = new AffineTransform(); currentTx = new AffineTransform();
lastShape = null; lastShape = null;
startTracking();
} }
/** /**
@@ -107,13 +111,23 @@ class G2DWrapper extends Graphics2D {
return currentArea; return currentArea;
} }
@Override
public void startTracking() {
this.trackingAllowed = true;
}
@Override
public void stopTracking() {
this.trackingAllowed = false;
}
/** /**
* Appends shape interior to the current component area. * Appends shape interior to the current component area.
* *
* @param s * @param s
*/ */
private void appendShape(Shape s) { private void appendShape(Shape s) {
if (!drawingComponent) { if (!drawingComponent || !trackingAllowed) {
return; return;
} }
Area area = new Area(s); Area area = new Area(s);
@@ -129,7 +143,7 @@ class G2DWrapper extends Graphics2D {
*/ */
private void appendShapeOutline(Shape s) { private void appendShapeOutline(Shape s) {
// Do not add shape outline if the same shape has been filled recently. // Do not add shape outline if the same shape has been filled recently.
if (!drawingComponent || s.equals(lastShape)) { if (!drawingComponent || !trackingAllowed || s.equals(lastShape)) {
return; return;
} }
lastShape = s; lastShape = s;
@@ -235,7 +249,9 @@ class G2DWrapper extends Graphics2D {
@Override @Override
public void draw(Shape s) { public void draw(Shape s) {
canvasGraphics.draw(s); canvasGraphics.draw(s);
appendShapeOutline(s); if (drawingComponent && trackingAllowed) {
appendShapeOutline(s);
}
} }
@Override @Override
@@ -270,19 +286,23 @@ class G2DWrapper extends Graphics2D {
@Override @Override
public void drawString(String str, int x, int y) { public void drawString(String str, int x, int y) {
canvasGraphics.drawString(str, x, y); canvasGraphics.drawString(str, x, y);
FontMetrics fontMetrics = canvasGraphics.getFontMetrics(); if (drawingComponent && trackingAllowed) {
Rectangle2D rect = fontMetrics.getStringBounds(str, canvasGraphics); FontMetrics fontMetrics = canvasGraphics.getFontMetrics();
appendShape(new Rectangle2D.Double(rect.getX() + x, rect.getY() + y, rect.getWidth(), rect Rectangle2D rect = fontMetrics.getStringBounds(str, canvasGraphics);
.getHeight())); appendShape(new Rectangle2D.Double(rect.getX() + x, rect.getY() + y, rect.getWidth(),
rect.getHeight()));
}
} }
@Override @Override
public void drawString(String str, float x, float y) { public void drawString(String str, float x, float y) {
canvasGraphics.drawString(str, x, y); canvasGraphics.drawString(str, x, y);
FontMetrics fontMetrics = canvasGraphics.getFontMetrics(); if (drawingComponent && trackingAllowed) {
Rectangle2D rect = fontMetrics.getStringBounds(str, canvasGraphics); FontMetrics fontMetrics = canvasGraphics.getFontMetrics();
appendShape(new Rectangle2D.Double(rect.getX() + x, rect.getY() + y, rect.getWidth(), rect Rectangle2D rect = fontMetrics.getStringBounds(str, canvasGraphics);
.getHeight())); appendShape(new Rectangle2D.Double(rect.getX() + x, rect.getY() + y, rect.getWidth(),
rect.getHeight()));
}
} }
@Override @Override
@@ -508,19 +528,25 @@ class G2DWrapper extends Graphics2D {
@Override @Override
public void drawLine(int x1, int y1, int x2, int y2) { public void drawLine(int x1, int y1, int x2, int y2) {
canvasGraphics.drawLine(x1, y1, x2, y2); canvasGraphics.drawLine(x1, y1, x2, y2);
appendShapeOutline(new Line2D.Double(x1, y1, x2, y2)); if (drawingComponent && trackingAllowed) {
appendShapeOutline(new Line2D.Double(x1, y1, x2, y2));
}
} }
@Override @Override
public void drawOval(int x, int y, int width, int height) { public void drawOval(int x, int y, int width, int height) {
canvasGraphics.drawOval(x, y, width, height); canvasGraphics.drawOval(x, y, width, height);
appendShapeOutline(new Ellipse2D.Double(x, y, width, height)); if (drawingComponent && trackingAllowed) {
appendShapeOutline(new Ellipse2D.Double(x, y, width, height));
}
} }
@Override @Override
public void drawPolygon(int[] points, int[] points2, int points3) { public void drawPolygon(int[] points, int[] points2, int points3) {
canvasGraphics.drawPolygon(points, points2, points3); canvasGraphics.drawPolygon(points, points2, points3);
appendShapeOutline(new Polygon(points, points2, points3)); if (drawingComponent && trackingAllowed) {
appendShapeOutline(new Polygon(points, points2, points3));
}
} }
@Override @Override
@@ -531,43 +557,57 @@ class G2DWrapper extends Graphics2D {
@Override @Override
public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
canvasGraphics.drawRoundRect(x, y, width, height, arcWidth, arcHeight); canvasGraphics.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
appendShapeOutline(new RoundRectangle2D.Double(x, y, width, height, arcWidth, arcHeight)); if (drawingComponent && trackingAllowed) {
appendShapeOutline(new RoundRectangle2D.Double(x, y, width, height, arcWidth, arcHeight));
}
} }
@Override @Override
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) { public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
canvasGraphics.fillArc(x, y, width, height, startAngle, arcAngle); canvasGraphics.fillArc(x, y, width, height, startAngle, arcAngle);
appendShape(new Arc2D.Double(x, y, width, height, startAngle, arcAngle, Arc2D.PIE)); if (drawingComponent && trackingAllowed) {
appendShape(new Arc2D.Double(x, y, width, height, startAngle, arcAngle, Arc2D.PIE));
}
} }
@Override @Override
public void fillOval(int x, int y, int width, int height) { public void fillOval(int x, int y, int width, int height) {
canvasGraphics.fillOval(x, y, width, height); canvasGraphics.fillOval(x, y, width, height);
appendShape(new Ellipse2D.Double(x, y, width, height)); if (drawingComponent && trackingAllowed) {
appendShape(new Ellipse2D.Double(x, y, width, height));
}
} }
@Override @Override
public void fillPolygon(int[] points, int[] points2, int points3) { public void fillPolygon(int[] points, int[] points2, int points3) {
canvasGraphics.fillPolygon(points, points2, points3); canvasGraphics.fillPolygon(points, points2, points3);
appendShape(new Polygon(points, points2, points3)); if (drawingComponent && trackingAllowed) {
appendShape(new Polygon(points, points2, points3));
}
} }
@Override @Override
public void drawRect(int x, int y, int width, int height) { public void drawRect(int x, int y, int width, int height) {
canvasGraphics.drawRect(x, y, width, height); canvasGraphics.drawRect(x, y, width, height);
appendShapeOutline(new Rectangle(x, y, width, height)); if (drawingComponent && trackingAllowed) {
appendShapeOutline(new Rectangle(x, y, width, height));
}
} }
@Override @Override
public void fillRect(int x, int y, int width, int height) { public void fillRect(int x, int y, int width, int height) {
canvasGraphics.fillRect(x, y, width, height); canvasGraphics.fillRect(x, y, width, height);
appendShape(new Rectangle(x, y, width, height)); if (drawingComponent && trackingAllowed) {
appendShape(new Rectangle(x, y, width, height));
}
} }
@Override @Override
public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
canvasGraphics.fillRoundRect(x, y, width, height, arcWidth, arcHeight); canvasGraphics.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
appendShape(new RoundRectangle2D.Double(x, y, width, height, arcWidth, arcHeight)); if (drawingComponent && trackingAllowed) {
appendShape(new RoundRectangle2D.Double(x, y, width, height, arcWidth, arcHeight));
}
} }
@Override @Override
@@ -365,7 +365,7 @@ public class Presenter implements IPlugInPort {
} }
} }
// Draw the component through the g2dWrapper. // Draw the component through the g2dWrapper.
component.draw(g2dWrapper, state, currentProject); component.draw(g2dWrapper, state, currentProject, g2dWrapper);
componentAreaMap.put(component, g2dWrapper.finishedDrawingComponent()); componentAreaMap.put(component, g2dWrapper.finishedDrawingComponent());
} }
// Draw control points. // Draw control points.
@@ -6,6 +6,7 @@ import java.awt.Point;
import org.diylc.core.ComponentState; import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project; import org.diylc.core.Project;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
@@ -115,7 +116,8 @@ public class MockDIYComponent implements IDIYComponent<Capacitance> {
} }
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project) { public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
g2d.setColor(componentState.equals(ComponentState.SELECTED) ? color : color.darker()); g2d.setColor(componentState.equals(ComponentState.SELECTED) ? color : color.darker());
g2d.fillRect(leftTopCorner.x, leftTopCorner.y, 200, 50); g2d.fillRect(leftTopCorner.x, leftTopCorner.y, 200, 50);
} }
@@ -9,6 +9,7 @@ import java.awt.Point;
import org.diylc.components.AbstractTransparentComponent; import org.diylc.components.AbstractTransparentComponent;
import org.diylc.core.ComponentState; import org.diylc.core.ComponentState;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project; import org.diylc.core.Project;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size; import org.diylc.core.measures.Size;
@@ -32,7 +33,8 @@ public abstract class AbstractBoard extends AbstractTransparentComponent<String>
protected Color borderColor = BORDER_COLOR; protected Color borderColor = BORDER_COLOR;
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project) { public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
g2d.setStroke(new BasicStroke()); g2d.setStroke(new BasicStroke());
if (componentState != ComponentState.DRAGGING) { if (componentState != ComponentState.DRAGGING) {
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
@@ -49,6 +51,9 @@ public abstract class AbstractBoard extends AbstractTransparentComponent<String>
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor); || componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor);
g2d.drawRect(controlPoints[0].x, controlPoints[0].y, controlPoints[1].x g2d.drawRect(controlPoints[0].x, controlPoints[0].y, controlPoints[1].x
- controlPoints[0].x, controlPoints[1].y - controlPoints[0].y); - controlPoints[0].x, controlPoints[1].y - controlPoints[0].y);
// Do not track any changes that follow because the whole board has been
// tracked so far.
drawingObserver.stopTracking();
} }
@EditableProperty(name = "Color") @EditableProperty(name = "Color")
@@ -7,6 +7,7 @@ import java.awt.Point;
import org.diylc.core.ComponentState; import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project; import org.diylc.core.Project;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
@@ -30,9 +31,9 @@ public class PerfBoard extends AbstractBoard {
protected Color padColor = PAD_COLOR; protected Color padColor = PAD_COLOR;
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project) { public void draw(Graphics2D g2d, ComponentState componentState, Project project,
super.draw(g2d, componentState, project); IDrawingObserver drawingObserver) {
super.draw(g2d, componentState, project, drawingObserver);
if (componentState != ComponentState.DRAGGING) { if (componentState != ComponentState.DRAGGING) {
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
@@ -8,6 +8,7 @@ import java.awt.Point;
import org.diylc.core.ComponentState; import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project; import org.diylc.core.Project;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
@@ -32,8 +33,9 @@ public class VeroBoard extends AbstractBoard {
protected Color padColor = PAD_COLOR; protected Color padColor = PAD_COLOR;
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project) { public void draw(Graphics2D g2d, ComponentState componentState, Project project,
super.draw(g2d, componentState, project); IDrawingObserver drawingObserver) {
super.draw(g2d, componentState, project, drawingObserver);
if (componentState != ComponentState.DRAGGING) { if (componentState != ComponentState.DRAGGING) {
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
@@ -7,6 +7,7 @@ import java.awt.Point;
import org.diylc.components.AbstractComponent; import org.diylc.components.AbstractComponent;
import org.diylc.core.ComponentState; import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project; import org.diylc.core.Project;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
@@ -28,7 +29,8 @@ public class SolderPad extends AbstractComponent<Void> {
private Point point = new Point(0, 0); private Point point = new Point(0, 0);
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project) { public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
int diameter = getClosestOdd(size.convertToPixels()); int diameter = getClosestOdd(size.convertToPixels());
int holeDiameter = getClosestOdd(HOLE_SIZE.convertToPixels()); int holeDiameter = getClosestOdd(HOLE_SIZE.convertToPixels());
g2d.setColor(componentState == ComponentState.SELECTED g2d.setColor(componentState == ComponentState.SELECTED
@@ -94,7 +96,7 @@ public class SolderPad extends AbstractComponent<Void> {
public Void getValue() { public Void getValue() {
return null; return null;
} }
@Override @Override
public void setValue(Void value) { public void setValue(Void value) {
} }
@@ -7,6 +7,7 @@ import java.awt.Graphics2D;
import org.diylc.components.AbstractSinglePointComponent; import org.diylc.components.AbstractSinglePointComponent;
import org.diylc.core.ComponentState; import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project; import org.diylc.core.Project;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
@@ -28,7 +29,8 @@ public class TraceCut extends AbstractSinglePointComponent {
private Color borderColor = BORDER_COLOR; private Color borderColor = BORDER_COLOR;
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project) { public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
int size = this.size.convertToPixels() / 2 * 2; int size = this.size.convertToPixels() / 2 * 2;
int dotDiameter = (size / 3 * 2) / 2 * 2 + 1; int dotDiameter = (size / 3 * 2) / 2 * 2 + 1;
g2d.setColor(fillColor); g2d.setColor(fillColor);
@@ -12,6 +12,7 @@ import java.awt.geom.RoundRectangle2D;
import org.diylc.components.AbstractTransparentComponent; import org.diylc.components.AbstractTransparentComponent;
import org.diylc.core.ComponentState; import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project; import org.diylc.core.Project;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
@@ -153,7 +154,8 @@ public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchT
} }
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project) { public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
Shape body = getBody(); Shape body = getBody();
// Draw body if available. // Draw body if available.
if (body != null) { if (body != null) {
@@ -170,6 +172,9 @@ public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchT
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : BORDER_COLOR); || componentState == ComponentState.DRAGGING ? SELECTION_COLOR : BORDER_COLOR);
g2d.draw(body); g2d.draw(body);
} }
// Do not track these changes because the whole switch has been tracked
// so far.
drawingObserver.stopTracking();
// Draw lugs. // Draw lugs.
int circleDiameter = getClosestOdd(CIRCLE_SIZE.convertToPixels()); int circleDiameter = getClosestOdd(CIRCLE_SIZE.convertToPixels());
int lugWidth = getClosestOdd(LUG_WIDTH.convertToPixels()); int lugWidth = getClosestOdd(LUG_WIDTH.convertToPixels());
@@ -12,6 +12,7 @@ import java.util.List;
import org.diylc.components.AbstractComponent; import org.diylc.components.AbstractComponent;
import org.diylc.core.ComponentState; import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project; import org.diylc.core.Project;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
@@ -35,7 +36,8 @@ public class BOM extends AbstractComponent<Void> {
private Point point = new Point(0, 0); private Point point = new Point(0, 0);
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project) { public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
List<BomEntry> bom = BomMaker.getInstance().createBom(project.getComponents()); List<BomEntry> bom = BomMaker.getInstance().createBom(project.getComponents());
// Cleanup entries that do not have a value set. // Cleanup entries that do not have a value set.
Iterator<BomEntry> iterator = bom.iterator(); Iterator<BomEntry> iterator = bom.iterator();
@@ -10,6 +10,7 @@ import java.awt.geom.Rectangle2D;
import org.diylc.components.AbstractComponent; import org.diylc.components.AbstractComponent;
import org.diylc.core.ComponentState; import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project; import org.diylc.core.Project;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.measures.Size; import org.diylc.core.measures.Size;
@@ -28,7 +29,8 @@ public class ProjectInformation extends AbstractComponent<Void> {
private Point point = new Point(0, 0); private Point point = new Point(0, 0);
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project) { public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
g2d.setFont(Constants.LABEL_FONT); g2d.setFont(Constants.LABEL_FONT);
g2d.setColor(componentState == ComponentState.DRAGGING g2d.setColor(componentState == ComponentState.DRAGGING
|| componentState == ComponentState.SELECTED ? SELECTION_COLOR : COLOR); || componentState == ComponentState.SELECTED ? SELECTION_COLOR : COLOR);
@@ -16,6 +16,7 @@ import org.diylc.common.Orientation;
import org.diylc.components.AbstractTransparentComponent; import org.diylc.components.AbstractTransparentComponent;
import org.diylc.core.ComponentState; import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project; import org.diylc.core.Project;
import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.EditableProperty;
@@ -44,13 +45,16 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
private Size pinSpacing = new Size(0.1d, SizeUnit.in); private Size pinSpacing = new Size(0.1d, SizeUnit.in);
private Size rowSpacing = new Size(0.3d, SizeUnit.in); private Size rowSpacing = new Size(0.3d, SizeUnit.in);
private Point[] controlPoints = new Point[] { new Point(0, 0) }; private Point[] controlPoints = new Point[] { new Point(0, 0) };
// new Point(0, pinSpacing.convertToPixels()), // new Point(0, pinSpacing.convertToPixels()),
// new Point(0, 2 * pinSpacing.convertToPixels()), // new Point(0, 2 * pinSpacing.convertToPixels()),
// new Point(0, 3 * pinSpacing.convertToPixels()), // new Point(0, 3 * pinSpacing.convertToPixels()),
// new Point(3 * pinSpacing.convertToPixels(), 0), // new Point(3 * pinSpacing.convertToPixels(), 0),
// new Point(3 * pinSpacing.convertToPixels(), pinSpacing.convertToPixels()), // new Point(3 * pinSpacing.convertToPixels(),
// new Point(3 * pinSpacing.convertToPixels(), 2 * pinSpacing.convertToPixels()), // pinSpacing.convertToPixels()),
// new Point(3 * pinSpacing.convertToPixels(), 3 * pinSpacing.convertToPixels()) }; // new Point(3 * pinSpacing.convertToPixels(), 2 *
// pinSpacing.convertToPixels()),
// new Point(3 * pinSpacing.convertToPixels(), 3 *
// pinSpacing.convertToPixels()) };
private Shape body; private Shape body;
public DIL_IC() { public DIL_IC() {
@@ -212,7 +216,8 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
} }
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project) { public void draw(Graphics2D g2d, ComponentState componentState, Project project,
IDrawingObserver drawingObserver) {
int pinSize = PIN_SIZE.convertToPixels() / 2 * 2; int pinSize = PIN_SIZE.convertToPixels() / 2 * 2;
for (Point point : controlPoints) { for (Point point : controlPoints) {
g2d.setColor(PIN_COLOR); g2d.setColor(PIN_COLOR);