From f62299104032b7577f8909d0de52c2b31a34aaa7 Mon Sep 17 00:00:00 2001 From: lehtonen Date: Tue, 27 Nov 2012 09:28:18 +0000 Subject: [PATCH] Removed unnecessary hover hint listener code from TextElementNoBounds completely. They were implemented incorrectly and caused problems in TextNode and should not be there at all. refs #3877 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26456 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../ui/elements/HoverTextElementNoBounds.java | 57 ++++++++++++------- .../ui/elements/MultilineTextElement.java | 23 +------- 2 files changed, 38 insertions(+), 42 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/HoverTextElementNoBounds.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/HoverTextElementNoBounds.java index a3295d47..c7f76857 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/HoverTextElementNoBounds.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/HoverTextElementNoBounds.java @@ -27,6 +27,7 @@ import org.simantics.g2d.diagram.IDiagram; import org.simantics.g2d.element.ElementHints; import org.simantics.g2d.element.ElementUtils; import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.LifeCycle; import org.simantics.g2d.utils.Alignment; import org.simantics.modeling.ModelingResources; import org.simantics.scenegraph.g2d.G2DParentNode; @@ -43,13 +44,28 @@ import org.simantics.utils.datastructures.hints.IHintObservable; * * @author Marko Luukkainen */ -public class HoverTextElementNoBounds extends TextElementNoBounds { +public class HoverTextElementNoBounds extends TextElementNoBounds implements LifeCycle { private static final long serialVersionUID = -148784588840819612L; public static final HoverTextElementNoBounds INSTANCE = new HoverTextElementNoBounds(); - private IHintListener hoverHintListener; + static class HoverHintListener implements IHintListener { + @Override + public void hintRemoved(IHintObservable sender, Key key, Object oldValue) { + } + @Override + public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) { + if (key == ElementHints.KEY_HOVER) { + IElement e = (IElement)sender; + TextNode name = (TextNode) e.getHint(SG_NODE); + if (name != null) + name.setHover(Boolean.TRUE.equals(e.getHint(ElementHints.KEY_HOVER))); + } + } + } + + protected static IHintListener hoverHintListener = new HoverHintListener(); public HoverTextElementNoBounds() { super(0, 0, Alignment.LEADING, 0); @@ -178,30 +194,29 @@ public class HoverTextElementNoBounds extends TextElementNoBounds { node.setEditable(editable); if(at != null) node.setTransform(at); + } - this.hoverHintListener = new IHintListener() { - @Override - public void hintRemoved(IHintObservable sender, Key key, Object oldValue) { + @Override + public void cleanup(IElement e) { + ElementUtils.removePossibleNode(e, SG_NODE); + } - } + @Override + public void onElementCreated(IElement e) { + } - @Override - public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) { - if(key == ElementHints.KEY_HOVER) { - IElement e = (IElement)sender; - TextNode name = (TextNode) e.getHint(SG_NODE); - if(name != null) - name.setHover(Boolean.TRUE.equals(e.getHint(ElementHints.KEY_HOVER))); - } - } - }; - e.addHintListener(hoverHintListener); + @Override + public void onElementDestroyed(IElement e) { } @Override - public void cleanup(IElement e) { - if(hoverHintListener != null) - e.removeHintListener(hoverHintListener); - ElementUtils.removePossibleNode(e, SG_NODE); + public void onElementActivated(IDiagram d, IElement e) { + e.addKeyHintListener(ElementHints.KEY_HOVER, hoverHintListener); } + + @Override + public void onElementDeactivated(IDiagram d, IElement e) { + e.removeKeyHintListener(ElementHints.KEY_HOVER, hoverHintListener); + } + } \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/MultilineTextElement.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/MultilineTextElement.java index fe2e31a2..f71c4206 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/MultilineTextElement.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/MultilineTextElement.java @@ -47,26 +47,8 @@ public class MultilineTextElement extends TextElementNoBounds { if(node == null) { node = parent.addNode(MultilineTextNode.class); e.setHint(SG_NODE, node); - - this.hoverHintListener = new IHintListener() { - @Override - public void hintRemoved(IHintObservable sender, Key key, Object oldValue) { - - } - - @Override - public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) { - if(key == ElementHints.KEY_HOVER) { - IElement e = (IElement)sender; - TextNode name = (TextNode) e.getHint(SG_NODE); - if (name != null) - name.setHover(Boolean.TRUE.equals(e.getHint(ElementHints.KEY_HOVER))); - } - } - }; - e.addHintListener(hoverHintListener); } - + Font font = ElementUtils.getTextFont(e); Color color = ElementUtils.getTextColor(e); Color fillColor = ElementUtils.getFillColor(e); @@ -86,7 +68,6 @@ public class MultilineTextElement extends TextElementNoBounds { node.setBounds(new Rectangle2D.Double(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight())); // Multiline text fields have fixed bounds if(at != null) node.setTransform(at); - } - + } -- 2.47.1