]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextNode.java
Option to edit TextNode's text externally
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / elements / TextNode.java
index 9d39bbfdedccc4287b9eca1049d133c07c910da5..2991d234c462bdb09e150e7d81892e7c18013f2c 100644 (file)
@@ -51,7 +51,8 @@ import org.simantics.scenegraph.LoaderNode;
 import org.simantics.scenegraph.ScenegraphUtils;
 import org.simantics.scenegraph.g2d.G2DNode;
 import org.simantics.scenegraph.g2d.G2DPDFRenderingHints;
-import org.simantics.scenegraph.g2d.G2DPDFRenderingHints.TextRenderingMode;
+import org.simantics.scenegraph.g2d.G2DRenderingHints;
+import org.simantics.scenegraph.g2d.G2DRenderingHints.TextRenderingMode;
 import org.simantics.scenegraph.g2d.events.Event;
 import org.simantics.scenegraph.g2d.events.EventTypes;
 import org.simantics.scenegraph.g2d.events.KeyEvent.KeyPressedEvent;
@@ -61,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;
@@ -711,7 +711,7 @@ public class TextNode extends G2DNode implements IDynamicSelectionPainterNode, L
 
         // PDF 
         PdfWriter writer = (PdfWriter) g.getRenderingHint(G2DPDFRenderingHints.KEY_PDF_WRITER);
-        TextRenderingMode renderingMode = (TextRenderingMode) g.getRenderingHint(G2DPDFRenderingHints.KEY_TEXT_RENDERING_MODE);
+        TextRenderingMode renderingMode = (TextRenderingMode) g.getRenderingHint(G2DRenderingHints.KEY_TEXT_RENDERING_MODE);
         boolean renderAsText = writer != null || renderingMode == TextRenderingMode.AS_TEXT;
         /// PDF
 
@@ -857,6 +857,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
@@ -1805,7 +1817,6 @@ public class TextNode extends G2DNode implements IDynamicSelectionPainterNode, L
     protected boolean mouseDragged(MouseDragBegin e) {
         if (isHovering()
                 && (isControlDown(e) || isShiftDown(e))
-                && e.context instanceof NodeEventHandler
                 && (dataRVI != null || text != null))
         {
             List<Transferable> trs = new ArrayList<>(2);