From b8f511234b7826b56150685978384fdfdae85076 Mon Sep 17 00:00:00 2001 From: miettinen Date: Thu, 27 Sep 2012 09:31:57 +0000 Subject: [PATCH] When the diagram loses focus and a text element is being edited, the element edition is ended, and thus a possible label change saved (refs #3643). git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@25883 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/ui/editor/DiagramViewer.java | 6 ----- .../sysdyn/ui/elements/HoverTextNode.java | 23 +++++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramViewer.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramViewer.java index 3fb13edf..a3ea5059 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramViewer.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramViewer.java @@ -65,12 +65,6 @@ import org.simantics.utils.threads.ThreadUtils; */ public class DiagramViewer extends org.simantics.modeling.ui.diagramEditor.DiagramViewer { - /*@Override - public void setFocus() { - System.out.println("diagram setFocus()"); - super.setFocus(); - }*/ - protected String getPopupId() { return "#SysdynDiagramPopup"; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/HoverTextNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/HoverTextNode.java index a0c3941c..eef60ea7 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/HoverTextNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/HoverTextNode.java @@ -19,6 +19,8 @@ import java.awt.geom.Rectangle2D; import org.simantics.diagram.elements.TextNode; import org.simantics.scenegraph.ISelectionPainterNode; +import org.simantics.scenegraph.g2d.events.EventTypes; +import org.simantics.scenegraph.g2d.events.FocusEvent; import org.simantics.scenegraph.utils.NodeUtil; public class HoverTextNode extends TextNode implements ISelectionPainterNode { @@ -60,4 +62,25 @@ public class HoverTextNode extends TextNode implements ISelectionPainterNode { g.setTransform(ot); } + @Override + public void init() { + super.init(); + addEventHandler(this); + } + + @Override + public int getEventMask(){ + return EventTypes.FocusLostMask | super.getEventMask(); + } + + @Override + protected boolean handleFocusEvent(FocusEvent e) { + int eventType = EventTypes.toType(e); + if (eventType == EventTypes.FocusLost){ + //If focus of the element (and the diagram) is lost, save the name of the node + fireTextEditingEnded(); + } + return false; + } + } -- 2.47.1