allow choosing name/value

This commit is contained in:
bancika
2011-01-16 09:50:00 +00:00
parent 6f6d802829
commit 2660841ceb
2 changed files with 26 additions and 2 deletions
@@ -0,0 +1,11 @@
package org.diylc.common;
public enum Display {
NAME, VALUE;
@Override
public String toString() {
return name().substring(0, 1) + name().substring(1).toLowerCase();
}
}
@@ -9,7 +9,9 @@ import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;
import org.diylc.common.Display;
import org.diylc.core.ComponentState;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
@@ -42,6 +44,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
new Point(DEFAULT_SIZE.convertToPixels() / 2, 0) };
protected Color bodyColor = getDefaultBodyColor();
protected Color borderColor = getDefaultBorderColor();
protected Display display = Display.NAME;
protected AbstractLeadedComponent() {
super();
@@ -102,8 +105,9 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED
: LABEL_COLOR);
FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
java.awt.geom.Rectangle2D textRect = fontMetrics.getStringBounds(getName(), g2d);
g2d.drawString(getName(), (int) (shapeRect.width - textRect.getWidth()) / 2,
String label = display == Display.NAME ? getName() : getValue().toString();
Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d);
g2d.drawString(label, (int) (shapeRect.width - textRect.getWidth()) / 2,
(int) (shapeRect.height - textRect.getHeight()) / 2 + fontMetrics.getAscent());
}
@@ -200,4 +204,13 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
public void setHeight(Size height) {
this.height = height;
}
@EditableProperty
public Display getDisplay() {
return display;
}
public void setDisplay(Display display) {
this.display = display;
}
}