public static final Key KEY_RULER_ENABLED = new KeyOf(Boolean.class, "RULER_ENABLED");
+ /**
+ * Size of ruler in normalized (non-zoomed or 100% zoom) coordinates, not screen pixel coordinates.
+ */
+ public static final Key KEY_RULER_SIZE = new KeyOf(Double.class, "RULER_SIZE");
+
/** Background color */
public static final Key KEY_RULER_BACKGROUND_COLOR = new KeyOf(Color.class, "RULER_BACKGROUND_COLOR");
@Override
public void addedToContext(ICanvasContext ctx) {
super.addedToContext(ctx);
+
+ if (!hasHint(KEY_RULER_SIZE))
+ setHint(KEY_RULER_SIZE, RULER_WIDTH);
+
getHintStack().addKeyHintListener(getThread(), KEY_RULER_ENABLED, hintListener);
+ getHintStack().addKeyHintListener(getThread(), KEY_RULER_SIZE, hintListener);
getHintStack().addKeyHintListener(getThread(), KEY_RULER_BACKGROUND_COLOR, hintListener);
getHintStack().addKeyHintListener(getThread(), KEY_RULER_TEXT_COLOR, hintListener);
getHintStack().addKeyHintListener(getThread(), GridPainter.KEY_GRID_SIZE, hintListener);
@Override
public void removedFromContext(ICanvasContext ctx) {
getHintStack().removeKeyHintListener(getThread(), KEY_RULER_ENABLED, hintListener);
+ getHintStack().removeKeyHintListener(getThread(), KEY_RULER_SIZE, hintListener);
getHintStack().removeKeyHintListener(getThread(), KEY_RULER_BACKGROUND_COLOR, hintListener);
getHintStack().removeKeyHintListener(getThread(), KEY_RULER_TEXT_COLOR, hintListener);
getHintStack().removeKeyHintListener(getThread(), GridPainter.KEY_GRID_SIZE, hintListener);
@SGInit
public void initSG(G2DParentNode parent) {
- node = parent.addNode("ruler", RulerNode.class);
+ node = parent.addNode("ruler", getNodeClass());
node.setZIndex(PAINT_PRIORITY);
updateNode();
}
+ protected Class<? extends RulerNode> getNodeClass() {
+ return RulerNode.class;
+ }
+
@SGCleanup
public void cleanupSG() {
node.remove();
}
- void updateNode() {
+ protected void updateNode() {
node.setEnabled(isPaintingEnabled());
node.setGridSize(getGridSize());
+ node.setRulerSize(getRulerSize());
}
private double getGridSize() {
return !Boolean.FALSE.equals(b);
}
+ private double getRulerSize() {
+ Double d = getHint(KEY_RULER_SIZE);
+ return d != null ? d : RULER_WIDTH;
+ }
+
public Color getRulerTextColor()
{
Color c = getHint(KEY_RULER_TEXT_COLOR);