]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextNode.java
Merge "Counting of pending nodes does not work if null text is saved as """
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / elements / TextNode.java
index 43653cbd0930abc7da98159406c44a71122ed235..bf1bf563b32c9f9e89c2c2355902d2a5b5f1ef02 100644 (file)
@@ -62,7 +62,6 @@ import org.simantics.scenegraph.g2d.events.MouseEvent.MouseClickEvent;
 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDoubleClickedEvent;
 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDragBegin;
 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent;
-import org.simantics.scenegraph.g2d.events.NodeEventHandler;
 import org.simantics.scenegraph.g2d.events.command.CommandEvent;
 import org.simantics.scenegraph.g2d.events.command.Commands;
 import org.simantics.scenegraph.utils.GeometryUtils;
@@ -404,13 +403,14 @@ public class TextNode extends G2DNode implements IDynamicSelectionPainterNode, L
         if (hasState(STATE_EDITING))
             return;
 
-        this.text = new String(text != null ? text : "");
+        this.text = text;
         this.font = font;
         this.color = color;
         this.scale = scale;
         this.scaleRecip = 1.0 / scale;
         this.caret = 0;
         this.selectionTail = 0;
+        
 
         resetCaches();
     }
@@ -470,8 +470,8 @@ public class TextNode extends G2DNode implements IDynamicSelectionPainterNode, L
         // no value => value
         if(this.text == null && text != null) NodeUtil.decreasePending(this);
 
-        this.text = text != null ? text : "";
-        caret = Math.min(caret, this.text.length());
+        this.text = text;
+        caret = text != null ? Math.min(caret, text.length()) : 0;
         selectionTail = caret;
 
         resetCaches();
@@ -858,6 +858,18 @@ public class TextNode extends G2DNode implements IDynamicSelectionPainterNode, L
     protected void renderSelectedHover(Graphics2D g, boolean isSelected, boolean isHovering) {
     }
 
+    public String editText(String text) {
+
+        String error = validator != null ? validator.apply(text) : null;
+        if (error == null) {
+            this.text = text;
+            if (textListener != null) {
+                textListener.textEditingEnded();
+            }
+        }
+        return error;
+    }
+
     /**
      * Replaces the current selection with the content or inserts
      * the content at caret. After the insertion the caret
@@ -1426,6 +1438,9 @@ public class TextNode extends G2DNode implements IDynamicSelectionPainterNode, L
             y += line.layout.getDescent() + line.layout.getLeading() + line.layout.getAscent();
 
             Rectangle2D bbox = line.layout.getLogicalHighlightShape(0, lineText.length()).getBounds2D();
+            // HighlightShape is not large enough, if font is italic.
+            Rectangle2D bbox2 = line.layout.getBounds();
+            bbox.add(bbox2);
             bbox.setFrame(bbox.getX(), bbox.getY() + line.drawPosY, bbox.getWidth(), bbox.getHeight());
             line.bbox = bbox;
         }