ability to center label

This commit is contained in:
bancika
2011-01-24 20:12:51 +00:00
parent 8927b2c326
commit efeaf92ccb
4 changed files with 30 additions and 13 deletions
@@ -1,15 +1,15 @@
<map>
<entry>
<string>lastPath</string>
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop\oldFiles</string>
<string>metric</string>
<boolean>true</boolean>
</entry>
<entry>
<string>zoom</string>
<double>1.0</double>
</entry>
<entry>
<string>metric</string>
<boolean>true</boolean>
<string>lastPath</string>
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop\oldFiles</string>
</entry>
<entry>
<string>default.org.diylc.components.misc.Label:Color</string>
@@ -206,15 +206,16 @@ public class ProjectFileManager {
IDIYComponent<?> component = null;
if (nodeName.equalsIgnoreCase("text")) {
LOG.debug("Recognized " + nodeName);
Label pad = new Label();
pad.setName(nameAttr);
Label label = new Label();
label.setName(nameAttr);
if (color != null) {
pad.setColor(color);
label.setColor(color);
}
pad.setText(valueAttr);
pad.setControlPoint(convertV1CoordinatesToV3Point(referencePoint, x1Attr,
label.setText(valueAttr);
label.setCenter(false);
label.setControlPoint(convertV1CoordinatesToV3Point(referencePoint, x1Attr,
y1Attr), 0);
component = pad;
component = label;
} else if (nodeName.equalsIgnoreCase("pad")) {
LOG.debug("Recognized " + nodeName);
SolderPad pad = new SolderPad();
@@ -27,6 +27,7 @@ public class Label extends AbstractComponent<Void> {
private String text = DEFAULT_TEXT;
private Font font = LABEL_FONT;
private Color color = LABEL_COLOR;
private boolean center = true;
@Override
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
@@ -39,9 +40,16 @@ public class Label extends AbstractComponent<Void> {
int textHeight = (int) rect.getHeight();
int textWidth = (int) rect.getWidth();
// Center text horizontally and vertically
int x = point.x - textWidth / 2;
int y = point.y - textHeight / 2 + fontMetrics.getAscent();
int x;
int y;
if (center) {
// Center text horizontally and vertically
x = point.x - textWidth / 2;
y = point.y - textHeight / 2 + fontMetrics.getAscent();
} else {
x = point.x;
y = point.y - textHeight;
}
g2d.drawString(text, x, y);
}
@@ -107,6 +115,14 @@ public class Label extends AbstractComponent<Void> {
this.color = color;
}
public boolean getCenter() {
return center;
}
public void setCenter(boolean center) {
this.center = center;
}
@Override
public String getName() {
return super.getName();