]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
When the diagram loses focus and a text element is being edited, the element edition...
authormiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 27 Sep 2012 09:31:57 +0000 (09:31 +0000)
committermiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 27 Sep 2012 09:31:57 +0000 (09:31 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@25883 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramViewer.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/HoverTextNode.java

index 3fb13edf09571be7e23280b2bf4b4c03681d3b63..a3ea5059dffe6b8f89681a96fbd59691dc3e1f64 100644 (file)
@@ -65,12 +65,6 @@ import org.simantics.utils.threads.ThreadUtils;
  */\r
 public class DiagramViewer extends org.simantics.modeling.ui.diagramEditor.DiagramViewer {\r
 \r
-       /*@Override\r
-       public void setFocus() {\r
-       System.out.println("diagram setFocus()");\r
-               super.setFocus();\r
-       }*/\r
-       \r
        protected String getPopupId() {\r
                return "#SysdynDiagramPopup";\r
        }\r
index a0c3941c0bc23596fcdf7f61771b6b631a920eb5..eef60ea7ce6f6f99e47c9441fb312d262d141c43 100644 (file)
@@ -19,6 +19,8 @@ import java.awt.geom.Rectangle2D;
 \r
 import org.simantics.diagram.elements.TextNode;\r
 import org.simantics.scenegraph.ISelectionPainterNode;\r
+import org.simantics.scenegraph.g2d.events.EventTypes;\r
+import org.simantics.scenegraph.g2d.events.FocusEvent;\r
 import org.simantics.scenegraph.utils.NodeUtil;\r
 \r
 public class HoverTextNode extends TextNode implements ISelectionPainterNode {\r
@@ -60,4 +62,25 @@ public class HoverTextNode extends TextNode implements ISelectionPainterNode {
         g.setTransform(ot);\r
     }\r
 \r
+    @Override\r
+    public void init() {\r
+        super.init();\r
+        addEventHandler(this);\r
+    }\r
+    \r
+    @Override\r
+    public int getEventMask(){\r
+               return EventTypes.FocusLostMask | super.getEventMask();\r
+       }\r
+    \r
+    @Override\r
+    protected boolean handleFocusEvent(FocusEvent e) {\r
+       int eventType = EventTypes.toType(e);\r
+       if (eventType == EventTypes.FocusLost){\r
+               //If focus of the element (and the diagram) is lost, save the name of the node\r
+               fireTextEditingEnded();\r
+       }\r
+       return false;\r
+    }\r
+    \r
 }\r