]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/FlagNode.java
(refs #7180) Configurable font for FlagNode
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / org / simantics / scenegraph / g2d / nodes / FlagNode.java
index 4468996fb81d57e995bcc0c34162feb94e672cd8..598e130091391303febf5b14cbe039e4bda3ef2e 100644 (file)
@@ -49,7 +49,7 @@ public class FlagNode extends G2DNode {
     static transient final BasicStroke   STROKE           = new BasicStroke(0.25f, BasicStroke.CAP_BUTT,
                                                                   BasicStroke.JOIN_MITER);
 
-    final transient Font                 FONT             = Font.decode("Arial 12");
+    public final static Font             DEFAULT_FONT     = Font.decode("Arial 12");
 
     protected boolean visible;
 
@@ -66,6 +66,7 @@ public class FlagNode extends G2DNode {
     protected Rectangle2D textArea;
     protected byte hAlign;
     protected byte vAlign;
+    protected Font font = DEFAULT_FONT;
 
     private transient final Point2D      origin           = new Point2D.Double();
     private transient final Point2D      xa               = new Point2D.Double();
@@ -85,8 +86,8 @@ public class FlagNode extends G2DNode {
         return visible;
     }
 
-    @SyncField({"visible", "flagShape", "flagText", "stroke", "border", "fill", "textColor", "width", "height", "direction", "beakAngle", "textSize", "hAlign", "vAlign"})
-    public void init(Shape flagShape, String[] flagText, Stroke stroke, Color border, Color fill, Color textColor, float width, float height, double direction, float beakAngle, Rectangle2D textArea, int hAlign, int vAlign) {
+    @SyncField({"visible", "flagShape", "flagText", "stroke", "border", "fill", "textColor", "width", "height", "direction", "beakAngle", "textSize", "hAlign", "vAlign", "font"})
+    public void init(Shape flagShape, String[] flagText, Stroke stroke, Color border, Color fill, Color textColor, float width, float height, double direction, float beakAngle, Rectangle2D textArea, int hAlign, int vAlign, Font font) {
         this.visible = true;
         this.flagShape = flagShape;
         this.flagText = flagText;
@@ -101,6 +102,7 @@ public class FlagNode extends G2DNode {
         this.textArea = textArea;
         this.hAlign =  (byte) hAlign;
         this.vAlign = (byte) vAlign;
+        this.font = font;
 
         resetCaches();
     }
@@ -165,8 +167,7 @@ public class FlagNode extends G2DNode {
             }
 
             // Paint flag text
-            Font f = FONT;
-            g.setFont(f);
+            g.setFont(font);
             g.setColor(textColor);
 
             AffineTransform orig = g.getTransform();
@@ -240,7 +241,7 @@ public class FlagNode extends G2DNode {
                 System.out.println("transform: " + g.getTransform());
             }
 
-            FontMetrics fm = g.getFontMetrics(f);
+            FontMetrics fm = g.getFontMetrics(font);
             double fontHeight = fm.getHeight();
 
             if (textLayout == null || (float) scale != lastViewScale)
@@ -254,7 +255,7 @@ public class FlagNode extends G2DNode {
                 textHeight = 0;
                 for (int i = 0; i < flagText.length; ++i) {
                     String txt = flagText[i].isEmpty() ? " " : flagText[i]; 
-                    textLayout[i] = new TextLayout(txt, f, frc);
+                    textLayout[i] = new TextLayout(txt, font, frc);
                     rects[i] = textLayout[i].getBounds();
 
                     // If the bb height is not overridden with the font height