Polygon Ground Fill component

This commit is contained in:
bancika
2012-08-23 15:12:10 +00:00
parent 00a05f6f15
commit 58ac3d8148
7 changed files with 246 additions and 65 deletions
@@ -13,10 +13,11 @@ public class BlankBoard extends AbstractBoard {
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
int factor = 32 / width;
g2d.setColor(BOARD_COLOR);
g2d.fillRect(2, 2, width - 4, height - 4);
g2d.fillRect(2 / factor, 2 / factor, width - 4 / factor, height - 4 / factor);
g2d.setColor(BORDER_COLOR);
g2d.drawRect(2, 2, width - 4, height - 4);
g2d.drawRect(2 / factor, 2 / factor, width - 4 / factor, height - 4 / factor);
}
@Override
@@ -100,17 +100,18 @@ public class EyeletBoard extends AbstractBoard {
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
int factor = 32 / width;
g2d.setColor(BOARD_COLOR);
g2d.fillRect(2, 2, width - 4, height - 4);
g2d.fillRect(2 / factor, 2 / factor, width - 4 / factor, height - 4 / factor);
g2d.setColor(BORDER_COLOR);
g2d.drawRect(2, 2, width - 4, height - 4);
g2d.drawRect(2 / factor, 2 / factor, width - 4 / factor, height - 4 / factor);
g2d.setColor(EYELET_COLOR);
g2d.fillOval(width / 4, width / 4, width / 2, width / 2);
g2d.setColor(EYELET_COLOR.darker());
g2d.drawOval(width / 4, width / 4, width / 2, width / 2);
g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(width / 2 - 2, width / 2 - 2, 5, 5);
g2d.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, width / 2 - 2, 5, 5);
g2d.drawOval(width / 2 - 2 / factor, width / 2 - 2 / factor, getClosestOdd(5.0 / factor), getClosestOdd(5.0 / factor));
}
}
@@ -37,18 +37,20 @@ public class MarshallPerfBoard 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)
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());
@@ -60,11 +62,11 @@ 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);
@@ -82,29 +84,40 @@ public class MarshallPerfBoard extends AbstractBoard {
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
int factor = 32 / width;
g2d.setColor(BOARD_COLOR);
g2d.fillRect(2, 2, width - 4, height - 4);
g2d.fillRect(2 / factor, 2 / factor, width - 4 / factor, height - 4
/ factor);
g2d.setColor(BORDER_COLOR);
g2d.drawRect(2, 2, width - 4, height - 4);
g2d.drawRect(2 / factor, 2 / factor, width - 4 / factor, height - 4
/ factor);
g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(width / 3 - 2, width / 3 - 2, 5, 5);
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, width / 3 - 2, 5, 5);
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, width / 3 - 2, 5, 5);
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, width / 3 - 2, 5, 5);
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, 2 * width / 3 - 2, 5, 5);
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, 2 * width / 3 - 2, 5, 5);
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, 2 * width / 3 - 2, 5, 5);
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, 2 * width / 3 - 2, 5, 5);
g2d.drawOval(2 * width / 3 - 2 / factor, 2 * width / 3 - 2 / factor,
getClosestOdd(5.0 / factor), getClosestOdd(5.0 / factor));
}
}
@@ -33,18 +33,20 @@ public class PerfBoard extends AbstractBoard {
protected Color padColor = COPPER_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 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());
@@ -57,15 +59,17 @@ 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);
@@ -92,17 +96,22 @@ public class PerfBoard extends AbstractBoard {
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
int factor = 32 / width;
g2d.setColor(BOARD_COLOR);
g2d.fillRect(2, 2, width - 4, height - 4);
g2d.fillRect(2 / factor, 2 / factor, width - 4 / factor, height - 4
/ factor);
g2d.setColor(BORDER_COLOR);
g2d.drawRect(2, 2, width - 4, height - 4);
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, width / 2 - 2, 5, 5);
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, width / 2 - 2, 5, 5);
g2d.drawOval(width / 2 - 2 / factor, width / 2 - 2 / factor,
getClosestOdd(5.0 / factor), getClosestOdd(5.0 / factor));
}
}
@@ -36,10 +36,12 @@ public class VeroBoard extends AbstractBoard {
protected OrientationHV orientation = OrientationHV.HORIZONTAL;
@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)
if (checkPointsClipped(clip)
&& !clip.contains(firstPoint.x, secondPoint.y)
&& !clip.contains(secondPoint.x, firstPoint.y)) {
return;
}
@@ -47,8 +49,8 @@ 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());
@@ -60,17 +62,19 @@ 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 {
@@ -78,17 +82,19 @@ 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);
}
}
}
@@ -126,19 +132,26 @@ public class VeroBoard extends AbstractBoard {
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
int factor = 32 / width;
g2d.setColor(BOARD_COLOR);
g2d.fillRect(2, 2, width - 4, height - 4);
g2d.fillRect(2 / factor, 2 / factor, width - 4 / factor, height - 4
/ factor);
g2d.setColor(BORDER_COLOR);
g2d.drawRect(2, 2, width - 4, height - 4);
g2d.drawRect(2 / factor, 2 / factor, width - 4 / factor, height - 4
/ factor);
g2d.setColor(STRIP_COLOR);
g2d.fillRect(4, width / 4, width - 8, width / 2);
g2d.fillRect(4 / factor, width / 4, width - 8 / factor, width / 2);
g2d.setColor(STRIP_COLOR.darker());
g2d.drawRect(4, width / 4, width - 8, width / 2);
g2d.drawRect(4 / factor, width / 4, width - 8 / factor, width / 2);
g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(width / 3 - 2, width / 2 - 2, 5, 5);
g2d.fillOval(2 * width / 3 - 2, width / 2 - 2, 5, 5);
g2d.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, width / 2 - 2, 5, 5);
g2d.drawOval(2 * width / 3 - 2, width / 2 - 2, 5, 5);
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));
}
}
@@ -0,0 +1,144 @@
package org.diylc.components.connectivity;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.util.Arrays;
import org.diylc.common.ObjectCache;
import org.diylc.components.AbstractComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.BomPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
@ComponentDescriptor(name = "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;
public static Color COLOR = Color.black;
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()),
new Point((int) DEFAULT_WIDTH.convertToPixels(), 0) };
protected Color color = COLOR;
protected PointCount pointCount = PointCount._4;
@Override
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;
g2d.setColor(fillColor);
int[] xPoints = new int[controlPoints.length];
int[] yPoints = new int[controlPoints.length];
for (int i = 0; i < controlPoints.length; i++) {
xPoints[i] = controlPoints[i].x;
yPoints[i] = controlPoints[i].y;
}
g2d.fillPolygon(xPoints, yPoints, controlPoints.length);
// Do not track any changes that follow because the whole board has been
// tracked so far.
drawingObserver.stopTracking();
}
@EditableProperty(name = "Color")
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
@Override
public int getControlPointCount() {
return controlPoints.length;
}
@Override
public Point getControlPoint(int index) {
return controlPoints[index];
}
@Override
public boolean isControlPointSticky(int index) {
return false;
}
@Override
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
return VisibilityPolicy.WHEN_SELECTED;
}
@Override
public void setControlPoint(Point point, int index) {
controlPoints[index].setLocation(point);
}
@EditableProperty(name = "Edges")
public PointCount getPointCount() {
return pointCount;
}
public void setPointCount(PointCount pointCount) {
if (this.pointCount == pointCount)
return;
int oldPointCount = Integer.parseInt(this.pointCount.toString());
int newPointCount = Integer.parseInt(pointCount.toString());
this.controlPoints = Arrays.copyOf(this.controlPoints, newPointCount);
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 - 1].y + this.controlPoints[newPointCount - 1].y) / 2);
}
}
this.pointCount = pointCount;
}
@Deprecated
@Override
public Void getValue() {
return null;
}
@Deprecated
@Override
public void setValue(Void value) {
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
int factor = 32 / width;
g2d.setColor(COLOR);
int[] x = {2 / factor, width - 2 / factor, width - 4 / factor, 3 / factor};
int[] y = {4 / factor, 2 / factor, height - 5 / factor, height - 2 / factor};
g2d.fillPolygon(x, y, 4);
}
public enum PointCount {
_3, _4, _5, _6, _7, _8;
public String toString() {
return name().substring(1);
};
}
}