public static final Key KEY_INPUT_VALIDATOR = new KeyOf(Object.class, "INPUT_VALIDATOR");
public static final Key KEY_RVI = new KeyOf(RVI.class, "RVI");
+ public static final Key KEY_PREFIX_TEXT = new KeyOf(String.class, "PREFIX_TEXT");
+ public static final Key KEY_SUFFIX_TEXT = new KeyOf(String.class, "SUFFIX_TEXT");
+
/**
* If this hint is defined, the monitor will force its x-axis to match this
* angle. If this hint doesn't exist, the monitor will not force x-axis
public static final Key KEY_SG_NODE = new SceneGraphNodeKey(TextNode.class, "MONITOR_SG_NODE");
public static final Key KEY_SG_NODE2 = new SceneGraphNodeKey(ShapeNode.class, "MONITOR_SG_NODE2");
+ public static final Key KEY_SG_PREFIX_NODE = new SceneGraphNodeKey(ShapeNode.class, "MONITOR_PREFIX_NODE");
+ public static final Key KEY_SG_SUFFIX_NODE = new SceneGraphNodeKey(ShapeNode.class, "MONITOR_SUFFIX_NODE");
final static BasicStroke STROKE = new BasicStroke(1.0f);
node.setTextListener(new ITextListener() {
@Override
- public void textChanged() {}
+ public void textChanged() {
+ updatePrefixAndSuffixPositions(e);
+ }
@Override
- public void textEditingStarted() {}
+ public void textEditingStarted() {
+ updatePrefixAndSuffixPositions(e);
+ }
@Override
- public void textEditingCancelled() {}
+ public void textEditingCancelled() {
+ updatePrefixAndSuffixPositions(e);
+ }
boolean isEndingEdit = false;
@Override
public void textEditingEnded() {
+ updatePrefixAndSuffixPositions(e);
TextNode node = e.getHint(KEY_SG_NODE);
if (node == null)
return;
shape.remove();
}
+ String prefixText = e.getHint(KEY_PREFIX_TEXT);
+ if (prefixText != null) {
+ TextNode prefixNode = e.getHint(KEY_SG_PREFIX_NODE);
+ if (prefixNode == null || prefixNode.getParent() != parent) {
+ nodeId = ElementUtils.generateNodeId(e) + "-prefix";
+ node = parent.addNode(nodeId, TextNode.class);
+ e.setHint(KEY_SG_PREFIX_NODE, node);
+ Font font = ElementUtils.getTextFont(e);
+ Color color = ElementUtils.getTextColor(e);
+ node.setEditable(false);
+ node.setShowSelection(false);
+ node.setHorizontalAlignment((byte) 1);
+ node.init(prefixText, font, color, 0, 0, 1.0);
+ }
+ } else {
+ TextNode prefixNode = e.getHint(KEY_SG_PREFIX_NODE);
+ if (prefixNode != null)
+ prefixNode.remove();
+ }
+
+ String suffixText = e.getHint(KEY_SUFFIX_TEXT);
+ if (suffixText != null) {
+ TextNode suffixNode = e.getHint(KEY_SG_SUFFIX_NODE);
+ if (suffixNode == null || suffixNode.getParent() != parent) {
+ nodeId = ElementUtils.generateNodeId(e) + "-suffix";
+ node = parent.addNode(nodeId, TextNode.class);
+ e.setHint(KEY_SG_SUFFIX_NODE, node);
+ Font font = ElementUtils.getTextFont(e);
+ Color color = ElementUtils.getTextColor(e);
+ node.setEditable(false);
+ node.setShowSelection(false);
+ node.setHorizontalAlignment((byte) 0);
+ node.init(suffixText, font, color, 0, 0, 1.0);
+ }
+ } else {
+ TextNode suffixNode = e.getHint(KEY_SG_SUFFIX_NODE);
+ if (suffixNode != null)
+ suffixNode.remove();
+ }
+
update(e);
}
at2.translate(bounds.getMinX(), bounds.getCenterY());
shape.setTransform(at2);
}
+
+ updatePrefixAndSuffixPositions(e);
+ }
+ }
+
+ public void updatePrefixAndSuffixPositions(IElement e) {
+ TextNode node = e.getHint(KEY_SG_NODE);
+ if (node != null) {
+ TextNode prefix = e.getHint(KEY_SG_PREFIX_NODE);
+ TextNode suffix = e.getHint(KEY_SG_SUFFIX_NODE);
+ if (prefix != null || suffix != null) {
+ AffineTransform at = ElementUtils.getTransform(e);
+ Alignment vAlign = getVerticalAlignment(e);
+ if (prefix != null) {
+ AffineTransform at2 = new AffineTransform(at);
+ Rectangle2D bounds = node.getBoundsInLocal();
+ at2.translate(bounds.getMinX(), 0);
+ prefix.setTransform(at2);
+ prefix.setVerticalAlignment((byte) vAlign.ordinal());
+ }
+
+ if (suffix != null) {
+ AffineTransform at2 = new AffineTransform(at);
+ Rectangle2D bounds = node.getBoundsInLocal();
+ at2.translate(bounds.getMaxX(), 0);
+ suffix.setTransform(at2);
+ suffix.setVerticalAlignment((byte) vAlign.ordinal());
+ }
+ }
}
}
size.setRect(bounds);
}
}
+ TextNode prefixNode = (TextNode) e.getHint(KEY_SG_PREFIX_NODE);
+ if (prefixNode != null) {
+ Rectangle2D bounds = prefixNode.getBoundsInLocal();
+ if (size == null)
+ size = new Rectangle2D.Double(0, 0, 0, 0);
+ size.add(bounds);
+ }
+ TextNode suffixNode = (TextNode) e.getHint(KEY_SG_SUFFIX_NODE);
+ if (suffixNode != null) {
+ Rectangle2D bounds = suffixNode.getBoundsInLocal();
+ if (size == null)
+ size = new Rectangle2D.Double(0, 0, 0, 0);
+ size.add(bounds);
+ }
return size;
}
@Override
public Shape getElementShape(IElement e) {
- Shape shape = new Rectangle2D.Double(0, 0, 0, 0);
-
- TextNode node = (TextNode)e.getHint(KEY_SG_NODE);
- if(node != null && node.getBoundsInLocal() != null) {
- shape = node.getBoundsInLocal();
+ Rectangle2D bounds = getBounds(e, null);
+ if (bounds != null) {
+ return bounds;
+ } else {
+ return new Rectangle2D.Double(0, 0, 0, 0);
}
-
- return shape;
}
}