diff --git a/diylc/diylc-library/src/org/diylc/components/boards/AbstractBoard.java b/diylc/diylc-library/src/org/diylc/components/boards/AbstractBoard.java index 8c961aaf..f18aebd2 100644 --- a/diylc/diylc-library/src/org/diylc/components/boards/AbstractBoard.java +++ b/diylc/diylc-library/src/org/diylc/components/boards/AbstractBoard.java @@ -60,7 +60,9 @@ public abstract class AbstractBoard extends AbstractTransparentComponent protected Color borderColor = BORDER_COLOR; protected Color coordinateColor = COORDINATE_COLOR; protected Boolean drawCoordinates = null; - protected CoordinateType coordinateType = CoordinateType.XY; + protected CoordinateType xType = CoordinateType.Numbers; + protected CoordinateDisplay coordinateDisplay = CoordinateDisplay.One_Side; + protected CoordinateType yType = CoordinateType.Letters; @Override public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project, @@ -83,29 +85,39 @@ public abstract class AbstractBoard extends AbstractTransparentComponent g2d.drawRect(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y); } - protected void drawCoordinates(Graphics2D g2d, int spacing, Project project) { - CoordinateType ct = getCoordinateType(); - if (ct == CoordinateType.None) - return; - Point p = new Point(firstPoint); + protected void drawCoordinates(Graphics2D g2d, int spacing, Project project) { g2d.setColor(coordinateColor); g2d.setFont(project.getFont().deriveFont(COORDINATE_FONT_SIZE)); - - int t = 1; - while (p.y < secondPoint.y - spacing) { - p.y += spacing; - super.drawCenteredText(g2d, ct == CoordinateType.XY ? getCoordinateLabel(t) : Integer.toString(t), p.x + (ct == CoordinateType.YX && t >= 10 ? 0 : 2), p.y, HorizontalAlignment.LEFT, - VerticalAlignment.CENTER); - t++; + + if (getCoordinateDisplay() != CoordinateDisplay.None) { + Point p = new Point(firstPoint); + int t = 1; + while (p.y < secondPoint.y - spacing) { + p.y += spacing; + int offset = (getyType() == CoordinateType.Numbers && t >= 10) || (getyType() == CoordinateType.Letters && t >= 27) ? 0 : 2; + drawCenteredText(g2d, getyType() == CoordinateType.Letters ? getCoordinateLabel(t) : Integer.toString(t), p.x + offset, p.y, HorizontalAlignment.LEFT, + VerticalAlignment.CENTER); + if (getCoordinateDisplay() == CoordinateDisplay.Both_Sides) { + drawCenteredText(g2d, getyType() == CoordinateType.Letters ? getCoordinateLabel(t) : Integer.toString(t), secondPoint.x - offset, p.y, HorizontalAlignment.RIGHT, + VerticalAlignment.CENTER); + } + t++; + } } - - p = new Point(firstPoint); - t = 1; - while (p.x < secondPoint.x - spacing) { - p.x += spacing; - super.drawCenteredText(g2d, ct == CoordinateType.XY ? Integer.toString(t) : getCoordinateLabel(t), p.x, p.y - 2, HorizontalAlignment.CENTER, - VerticalAlignment.TOP); - t++; + + if (getCoordinateDisplay() != CoordinateDisplay.None) { + Point p = new Point(firstPoint); + int t = 1; + while (p.x < secondPoint.x - spacing) { + p.x += spacing; + drawCenteredText(g2d, getxType() == CoordinateType.Letters ? getCoordinateLabel(t) : Integer.toString(t), p.x, p.y - 2, HorizontalAlignment.CENTER, + VerticalAlignment.TOP); + if (getCoordinateDisplay() == CoordinateDisplay.Both_Sides) { + drawCenteredText(g2d, getxType() == CoordinateType.Letters ? getCoordinateLabel(t) : Integer.toString(t), p.x, (int) (secondPoint.y - COORDINATE_FONT_SIZE), HorizontalAlignment.CENTER, + VerticalAlignment.BOTTOM); + } + t++; + } } } @@ -152,15 +164,37 @@ public abstract class AbstractBoard extends AbstractTransparentComponent this.borderColor = borderColor; } - @EditableProperty(name ="Coordinates") - public CoordinateType getCoordinateType() { - if (coordinateType == null) - coordinateType = drawCoordinates == null || drawCoordinates ? CoordinateType.XY : CoordinateType.None; - return coordinateType; + @EditableProperty(name = "X") + public CoordinateType getxType() { + if (xType == null) + xType = CoordinateType.Numbers; + return xType; } - - public void setCoordinateType(CoordinateType coordinateType) { - this.coordinateType = coordinateType; + + public void setxType(CoordinateType xType) { + this.xType = xType; + } + + @EditableProperty(name = "Coordinates") + public CoordinateDisplay getCoordinateDisplay() { + if (coordinateDisplay == null) + coordinateDisplay = CoordinateDisplay.One_Side; + return coordinateDisplay; + } + + public void setCoordinateDisplay(CoordinateDisplay coordinateDisplay) { + this.coordinateDisplay = coordinateDisplay; + } + + @EditableProperty(name = "Y") + public CoordinateType getyType() { + if (yType == null) + yType = CoordinateType.Letters; + return yType; + } + + public void setyType(CoordinateType yType) { + this.yType = yType; } @Override @@ -204,17 +238,15 @@ public abstract class AbstractBoard extends AbstractTransparentComponent } public static enum CoordinateType { - None("None"), XY("X-numbers Y-letters"), YX("X-letters Y-numbers"); - - private String label; - - private CoordinateType(String label) { - this.label = label; - } + Letters, Numbers + } + + public static enum CoordinateDisplay { + None, One_Side, Both_Sides; @Override public String toString() { - return label; - } + return super.toString().replace('_', ' '); + }; } } diff --git a/diylc/diylc-library/src/org/diylc/components/boards/BlankBoard.java b/diylc/diylc-library/src/org/diylc/components/boards/BlankBoard.java index 71713b60..796ce6e1 100644 --- a/diylc/diylc-library/src/org/diylc/components/boards/BlankBoard.java +++ b/diylc/diylc-library/src/org/diylc/components/boards/BlankBoard.java @@ -21,21 +21,21 @@ */ package org.diylc.components.boards; -import java.awt.AlphaComposite; +import java.awt.AlphaComposite; import java.awt.Color; -import java.awt.Composite; -import java.awt.Graphics2D; -import java.awt.Shape; +import java.awt.Composite; +import java.awt.Graphics2D; +import java.awt.Shape; -import org.diylc.common.ObjectCache; -import org.diylc.common.SimpleComponentTransformer; -import org.diylc.core.ComponentState; -import org.diylc.core.IDIYComponent; -import org.diylc.core.IDrawingObserver; -import org.diylc.core.Project; -import org.diylc.core.annotations.BomPolicy; -import org.diylc.core.annotations.ComponentDescriptor; -import org.diylc.core.annotations.EditableProperty; +import org.diylc.common.ObjectCache; +import org.diylc.common.SimpleComponentTransformer; +import org.diylc.core.ComponentState; +import org.diylc.core.IDIYComponent; +import org.diylc.core.IDrawingObserver; +import org.diylc.core.Project; +import org.diylc.core.annotations.BomPolicy; +import org.diylc.core.annotations.ComponentDescriptor; +import org.diylc.core.annotations.EditableProperty; @ComponentDescriptor(name = "Blank Board", category = "Boards", author = "Branislav Stojkovic", zOrder = IDIYComponent.BOARD, instanceNamePrefix = "Board", description = "Blank circuit board", @@ -86,14 +86,26 @@ public class BlankBoard extends AbstractBoard { g2d.drawRect(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y); else g2d.drawOval(firstPoint.x, firstPoint.y, secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y); - } - - @Override - public CoordinateType getCoordinateType() { - // Override to prevent editing. - return super.getCoordinateType(); } + @Override + public CoordinateType getxType() { + // Override to prevent editing. + return super.getxType(); + } + + @Override + public CoordinateDisplay getCoordinateDisplay() { + // Override to prevent editing. + return super.getCoordinateDisplay(); + } + + @Override + public CoordinateType getyType() { + // Override to prevent editing. + return super.getyType(); + } + @Override public Color getCoordinateColor() { // Override to prevent editing.