editable colors for boards

This commit is contained in:
bancika
2011-01-10 23:47:39 +00:00
parent ce63511188
commit cb72d596a3
3 changed files with 34 additions and 139 deletions
@@ -20,27 +20,18 @@ public class PerfBoard extends AbstractBoard {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public static Color COPPER_COLOR = Color.decode("#B87333"); public static Color PAD_COLOR = Color.decode("#B87333");
private static Size SPACING = new Size(0.1d, SizeUnit.in); public static Size SPACING = new Size(0.1d, SizeUnit.in);
private static Size PAD_SIZE = new Size(0.08d, SizeUnit.in); public static Size PAD_SIZE = new Size(0.08d, SizeUnit.in);
private static Size HOLE_SIZE = new Size(0.7d, SizeUnit.mm); public static Size HOLE_SIZE = new Size(0.7d, SizeUnit.mm);
// private Area copperArea; // private Area copperArea;
private Size spacing = SPACING; protected Size spacing = SPACING;
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) {
// long t = System.nanoTime();
// Area copperArea = getCopperArea();
// System.err.println("Calc: " + (System.nanoTime() - t));
// t = System.nanoTime();
// super.draw(g2d, componentState, project);
// g2d.setColor(COPPER_COLOR);
// g2d.fill(copperArea);
// System.err.println(" Draw: " + (System.nanoTime() - t));
// long t = System.nanoTime();
super.draw(g2d, componentState, project); super.draw(g2d, componentState, project);
if (componentState != ComponentState.DRAGGING) { if (componentState != ComponentState.DRAGGING) {
@@ -59,7 +50,7 @@ public class PerfBoard extends AbstractBoard {
p.y += spacing; p.y += spacing;
while (p.x < controlPoints[1].x - spacing) { while (p.x < controlPoints[1].x - spacing) {
p.x += spacing; p.x += spacing;
g2d.setColor(COPPER_COLOR); 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(Constants.CANVAS_COLOR); g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(p.x - holeDiameter / 2, p.y - holeDiameter / 2, holeDiameter, g2d.fillOval(p.x - holeDiameter / 2, p.y - holeDiameter / 2, holeDiameter,
@@ -68,59 +59,16 @@ public class PerfBoard extends AbstractBoard {
} }
g2d.setComposite(oldComposite); g2d.setComposite(oldComposite);
} }
// System.err.println("OldDraw: " + (System.nanoTime() - t));
} }
// @Override @EditableProperty(name = "Pad")
// public void setControlPoint(Point point, int index) { public Color getPadColor() {
// // Reset copper area if a control point is changed. return padColor;
// if (!point.equals(getControlPoint(index))) { }
// copperArea = null;
// } public void setPadColor(Color padColor) {
// super.setControlPoint(point, index); this.padColor = padColor;
// } }
//
// public Area getCopperArea() {
// if (copperArea == null) {
// copperArea = new Area();
//
// int holeRadius = HOLE_SIZE.convertToPixels() / 2;
// int radius = PAD_SIZE.convertToPixels() / 2;
// int spacing = SPACING.convertToPixels();
//
// // Create a pad.
// Area pad = new Area(new Ellipse2D.Double(-radius, -radius, radius * 2,
// radius * 2));
// pad.subtract(new Area(new Ellipse2D.Double(-holeRadius, -holeRadius,
// holeRadius * 2,
// holeRadius * 2)));
//
// // Create a row duplicating the pad.
// Area row = new Area();
// int columnCount = (controlPoints[1].x - controlPoints[0].x) / spacing -
// 1;
// int rowCount = (controlPoints[1].y - controlPoints[0].y) / spacing - 1;
//
// AffineTransform xTransform =
// AffineTransform.getTranslateInstance(spacing, 0);
// for (int i = 0; i < columnCount; i++) {
// pad.transform(xTransform);
// row.add(pad);
// }
//
// // Create the whole matrix duplicating the row.
// AffineTransform yTransform = AffineTransform.getTranslateInstance(0,
// spacing);
// for (int i = 0; i < rowCount; i++) {
// row.transform(yTransform);
// copperArea.add(row);
// }
//
// copperArea.transform(AffineTransform.getTranslateInstance(controlPoints[0].x,
// controlPoints[0].y));
// }
// return copperArea;
// }
@EditableProperty @EditableProperty
public Size getSpacing() { public Size getSpacing() {
@@ -137,7 +85,7 @@ public class PerfBoard extends AbstractBoard {
g2d.fillRect(2, 2, width - 4, height - 4); g2d.fillRect(2, 2, width - 4, height - 4);
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.drawRect(2, 2, width - 4, height - 4); g2d.drawRect(2, 2, width - 4, height - 4);
g2d.setColor(COPPER_COLOR); g2d.setColor(PAD_COLOR);
g2d.fillOval(width / 4, width / 4, width / 2, width / 2); g2d.fillOval(width / 4, width / 4, width / 2, width / 2);
g2d.setColor(Constants.CANVAS_COLOR); g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(width / 2 - 1, width / 2 - 1, 2, 2); g2d.fillOval(width / 2 - 1, width / 2 - 1, 2, 2);
@@ -21,28 +21,18 @@ public class VeroBoard extends AbstractBoard {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public static Color BOARD_COLOR = Color.decode("#BCED91"); public static Color BOARD_COLOR = Color.decode("#BCED91");
public static Color COPPER_COLOR = Color.decode("#B87333"); public static Color PAD_COLOR = Color.decode("#B87333");
public static Color BORDER_COLOR = BOARD_COLOR.darker(); public static Color BORDER_COLOR = BOARD_COLOR.darker();
private static Size SPACING = new Size(0.1d, SizeUnit.in); public static Size SPACING = new Size(0.1d, SizeUnit.in);
private static Size STRIP_SIZE = new Size(0.085d, SizeUnit.in); public static Size STRIP_SIZE = new Size(0.085d, SizeUnit.in);
private static Size HOLE_SIZE = new Size(0.7d, SizeUnit.mm); public static Size HOLE_SIZE = new Size(0.7d, SizeUnit.mm);
// private Area copperArea; protected Size spacing = SPACING;
private Size spacing = SPACING; 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) {
// long t = System.nanoTime();
// Area copperArea = getCopperArea();
// System.err.println("Calc: " + (System.nanoTime() - t));
// t = System.nanoTime();
// super.draw(g2d, componentState, project);
// g2d.setColor(COPPER_COLOR);
// g2d.fill(copperArea);
// System.err.println(" Draw: " + (System.nanoTime() - t));
// long t = System.nanoTime();
super.draw(g2d, componentState, project); super.draw(g2d, componentState, project);
if (componentState != ComponentState.DRAGGING) { if (componentState != ComponentState.DRAGGING) {
@@ -59,7 +49,7 @@ public class VeroBoard extends AbstractBoard {
while (p.y < controlPoints[1].y - spacing) { while (p.y < controlPoints[1].y - spacing) {
p.x = controlPoints[0].x; p.x = controlPoints[0].x;
p.y += spacing; p.y += spacing;
g2d.setColor(COPPER_COLOR); g2d.setColor(padColor);
g2d.fillRect(p.x + SPACING.convertToPixels() / 2, p.y - stripSize / 2, g2d.fillRect(p.x + SPACING.convertToPixels() / 2, p.y - stripSize / 2,
controlPoints[1].x - spacing - p.x, stripSize); controlPoints[1].x - spacing - p.x, stripSize);
while (p.x < controlPoints[1].x - spacing) { while (p.x < controlPoints[1].x - spacing) {
@@ -72,59 +62,16 @@ public class VeroBoard extends AbstractBoard {
} }
g2d.setComposite(oldComposite); g2d.setComposite(oldComposite);
} }
// System.err.println("OldDraw: " + (System.nanoTime() - t));
} }
// @Override @EditableProperty(name = "Pad")
// public void setControlPoint(Point point, int index) { public Color getPadColor() {
// // Reset copper area if a control point is changed. return padColor;
// if (!point.equals(getControlPoint(index))) { }
// copperArea = null;
// } public void setPadColor(Color padColor) {
// super.setControlPoint(point, index); this.padColor = padColor;
// } }
//
// public Area getCopperArea() {
// if (copperArea == null) {
// copperArea = new Area();
//
// int holeRadius = HOLE_SIZE.convertToPixels() / 2;
// int radius = PAD_SIZE.convertToPixels() / 2;
// int spacing = SPACING.convertToPixels();
//
// // Create a pad.
// Area pad = new Area(new Ellipse2D.Double(-radius, -radius, radius * 2,
// radius * 2));
// pad.subtract(new Area(new Ellipse2D.Double(-holeRadius, -holeRadius,
// holeRadius * 2,
// holeRadius * 2)));
//
// // Create a row duplicating the pad.
// Area row = new Area();
// int columnCount = (controlPoints[1].x - controlPoints[0].x) / spacing -
// 1;
// int rowCount = (controlPoints[1].y - controlPoints[0].y) / spacing - 1;
//
// AffineTransform xTransform =
// AffineTransform.getTranslateInstance(spacing, 0);
// for (int i = 0; i < columnCount; i++) {
// pad.transform(xTransform);
// row.add(pad);
// }
//
// // Create the whole matrix duplicating the row.
// AffineTransform yTransform = AffineTransform.getTranslateInstance(0,
// spacing);
// for (int i = 0; i < rowCount; i++) {
// row.transform(yTransform);
// copperArea.add(row);
// }
//
// copperArea.transform(AffineTransform.getTranslateInstance(controlPoints[0].x,
// controlPoints[0].y));
// }
// return copperArea;
// }
@EditableProperty @EditableProperty
public Size getSpacing() { public Size getSpacing() {
@@ -141,7 +88,7 @@ public class VeroBoard extends AbstractBoard {
g2d.fillRect(2, 2, width - 4, height - 4); g2d.fillRect(2, 2, width - 4, height - 4);
g2d.setColor(BORDER_COLOR); g2d.setColor(BORDER_COLOR);
g2d.drawRect(2, 2, width - 4, height - 4); g2d.drawRect(2, 2, width - 4, height - 4);
g2d.setColor(COPPER_COLOR); g2d.setColor(PAD_COLOR);
g2d.fillRect(4, width / 4, width - 8, width / 2); g2d.fillRect(4, width / 4, width - 8, width / 2);
g2d.setColor(Constants.CANVAS_COLOR); g2d.setColor(Constants.CANVAS_COLOR);
g2d.fillOval(width / 3 - 1, width / 2 - 1, 3, 3); g2d.fillOval(width / 3 - 1, width / 2 - 1, 3, 3);