perfboards can show coordinates

This commit is contained in:
bancika
2012-02-10 03:17:42 +00:00
parent fe527eece2
commit 2dfec28dc9
16 changed files with 140 additions and 6 deletions
@@ -16,7 +16,7 @@
<target name="compile">
<mkdir dir="${classes.dir}" />
<echo>Compile with JDK ${java.runtime.version}</echo>
<javac encoding="8859_1" srcdir="${basedir}/${src.dir}" destdir="${classes.dir}" classpathref="class.path" />
<javac encoding="8859_1" srcdir="${basedir}/${src.dir}" destdir="${classes.dir}" classpathref="class.path" debug="true" />
</target>
<target name="resource.copy">
@@ -46,7 +46,7 @@
<target name="jar" depends="clean, lib.copy, resource.copy, compile">
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}" />
<copy todir="../DIYLC/library" overwrite="true">
<copy todir="../diylc-swing/library" overwrite="true">
<fileset dir="${jar.dir}" includes="${ant.project.name}.jar" />
</copy>
</target>
@@ -6,7 +6,9 @@ import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.Point;
import org.diylc.common.HorizontalAlignment;
import org.diylc.common.ObjectCache;
import org.diylc.common.VerticalAlignment;
import org.diylc.components.AbstractTransparentComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.IDrawingObserver;
@@ -22,6 +24,8 @@ public abstract class AbstractBoard extends AbstractTransparentComponent<String>
public static Color BOARD_COLOR = Color.decode("#F8EBB3");
public static Color BORDER_COLOR = BOARD_COLOR.darker();
public static Color COORDINATE_COLOR = Color.gray.brighter();
public static float COORDINATE_FONT_SIZE = 9f;
public static Size DEFAULT_WIDTH = new Size(1.5d, SizeUnit.in);
public static Size DEFAULT_HEIGHT = new Size(1.2d, SizeUnit.in);
@@ -34,10 +38,12 @@ public abstract class AbstractBoard extends AbstractTransparentComponent<String>
protected Color boardColor = BOARD_COLOR;
protected Color borderColor = BORDER_COLOR;
protected Color coordinateColor = COORDINATE_COLOR;
protected Boolean drawCoordinates = true;
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
IDrawingObserver drawingObserver) {
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
if (componentState != ComponentState.DRAGGING) {
Composite oldComposite = g2d.getComposite();
@@ -59,6 +65,44 @@ public abstract class AbstractBoard extends AbstractTransparentComponent<String>
drawingObserver.stopTracking();
}
protected void drawCoordinates(Graphics2D g2d, int spacing) {
if (!getDrawCoordinates())
return;
Point p = new Point(firstPoint);
g2d.setColor(coordinateColor);
g2d.setFont(LABEL_FONT.deriveFont(COORDINATE_FONT_SIZE));
int t = 1;
while (p.y < secondPoint.y - spacing) {
p.y += spacing;
super.drawCenteredText(g2d, getCoordinateLabel(t++), p.x + 2, p.y,
HorizontalAlignment.LEFT, VerticalAlignment.CENTER);
}
p = new Point(firstPoint);
t = 1;
while (p.x < secondPoint.x - spacing) {
p.x += spacing;
super.drawCenteredText(g2d, getCoordinateLabel(t++), p.x, p.y - 2,
HorizontalAlignment.CENTER, VerticalAlignment.TOP);
}
}
private String getCoordinateLabel(int coordinate) {
String result = "";
while (coordinate > 0) {
int digit = coordinate % 26;
coordinate /= 26;
if (digit == 0) {
result = 'Z' + result;
coordinate--;
} else {
result = (char) ((int) 'A' + digit - 1) + result;
}
}
return result;
}
@EditableProperty(name = "Color")
public Color getBoardColor() {
return boardColor;
@@ -68,6 +112,16 @@ public abstract class AbstractBoard extends AbstractTransparentComponent<String>
this.boardColor = boardColor;
}
@EditableProperty(name = "Coordinate Color")
public Color getCoordinateColor() {
// Null protection for older files
return coordinateColor == null ? COORDINATE_COLOR : coordinateColor;
}
public void setCoordinateColor(Color coordinateColor) {
this.coordinateColor = coordinateColor;
}
@EditableProperty(name = "Border")
public Color getBorderColor() {
return borderColor;
@@ -77,6 +131,16 @@ public abstract class AbstractBoard extends AbstractTransparentComponent<String>
this.borderColor = borderColor;
}
@EditableProperty(name = "Draw Coordinates")
public boolean getDrawCoordinates() {
// Null protection for older files
return drawCoordinates == null || drawCoordinates;
}
public void setDrawCoordinates(boolean drawCoordinates) {
this.drawCoordinates = drawCoordinates;
}
@Override
public int getControlPointCount() {
return controlPoints.length;
@@ -17,4 +17,10 @@ public class BlankBoard extends AbstractBoard {
g2d.setColor(BORDER_COLOR);
g2d.drawRect(2, 2, width - 4, height - 4);
}
@Override
public boolean getDrawCoordinates() {
// Override to prevent editing.
return super.getDrawCoordinates();
}
}
@@ -75,6 +75,7 @@ public class EyeletBoard extends AbstractBoard {
holeDiameter);
}
}
super.drawCoordinates(g2d, spacing);
}
}
@@ -66,6 +66,7 @@ public class MarshallPerfBoard extends AbstractBoard {
holeDiameter);
}
}
super.drawCoordinates(g2d, spacing);
}
}
@@ -67,6 +67,7 @@ public class PerfBoard extends AbstractBoard {
holeDiameter);
}
}
super.drawCoordinates(g2d, spacing);
}
}
@@ -92,6 +92,7 @@ public class VeroBoard extends AbstractBoard {
}
}
g2d.setComposite(oldComposite);
super.drawCoordinates(g2d, spacing);
}
}