From 95b877de26524b944ea89e16e2956553004600f8 Mon Sep 17 00:00:00 2001 From: lempinen Date: Thu, 29 Jul 2010 13:43:57 +0000 Subject: [PATCH] Moved some hover stuff to the common elements git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16872 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/ui/elements2/AuxiliaryFactory.java | 3 +- .../sysdyn/ui/elements2/CloudFactory.java | 17 ++- .../sysdyn/ui/elements2/HoverHandler.java | 20 --- .../elements2/HoverTextElementNoBounds.java | 140 ++---------------- .../sysdyn/ui/elements2/HoverTextNode.java | 8 +- .../sysdyn/ui/elements2/InputFactory.java | 3 +- .../sysdyn/ui/elements2/ModuleFactory.java | 5 +- .../sysdyn/ui/elements2/StockFactory.java | 5 +- .../ui/elements2/SysdynElementFactory.java | 2 +- .../ui/elements2/SysdynElementHints.java | 1 - .../ui/elements2/SysdynElementUtils.java | 14 +- .../sysdyn/ui/elements2/ValveFactory.java | 15 +- 12 files changed, 49 insertions(+), 184 deletions(-) delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverHandler.java diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/AuxiliaryFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/AuxiliaryFactory.java index 8c353038..50473289 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/AuxiliaryFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/AuxiliaryFactory.java @@ -19,6 +19,7 @@ import org.simantics.db.Resource; import org.simantics.g2d.element.ElementClass; import org.simantics.g2d.element.handler.impl.BoundsOutline; import org.simantics.g2d.element.handler.impl.DefaultTransform; +import org.simantics.g2d.element.handler.impl.HoverImpl; import org.simantics.g2d.element.handler.impl.ObjectTerminal; import org.simantics.g2d.element.handler.impl.OutlinePick; import org.simantics.g2d.element.handler.impl.SimpleElementLayers; @@ -53,7 +54,7 @@ public class AuxiliaryFactory extends SysdynElementFactory { StaticSymbolImageInitializer.INSTANCE, HoverTextElementHandler.INSTANCE, BoundsOutline.INSTANCE, - HoverHandler.INSTANCE, + HoverImpl.INSTANCE, new WholeElementTerminals(terminals) ).setId(AuxiliaryFactory.class.getSimpleName()); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/CloudFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/CloudFactory.java index 034b02af..504b790d 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/CloudFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/CloudFactory.java @@ -29,6 +29,7 @@ import org.simantics.g2d.element.handler.InternalSize; import org.simantics.g2d.element.handler.SceneGraph; import org.simantics.g2d.element.handler.impl.BoundsOutline; import org.simantics.g2d.element.handler.impl.DefaultTransform; +import org.simantics.g2d.element.handler.impl.HoverImpl; import org.simantics.g2d.element.handler.impl.ObjectTerminal; import org.simantics.g2d.element.handler.impl.OutlinePick; import org.simantics.g2d.element.handler.impl.SimpleElementLayers; @@ -92,7 +93,7 @@ public class CloudFactory extends SysdynElementFactory { new StaticSymbolImpl(DEFAULT_IMAGE), StaticSymbolImageInitializer.INSTANCE, CloudSceneGraph.INSTANCE, - HoverHandler.INSTANCE, + HoverImpl.INSTANCE, BoundsOutline.INSTANCE, new WholeElementTerminals(terminals) ).setId(CloudFactory.class.getSimpleName()); @@ -105,6 +106,8 @@ public class CloudFactory extends SysdynElementFactory { public static final CloudSceneGraph INSTANCE = new CloudSceneGraph(); private static final Key NODE = new SceneGraphNodeKey(ShapeNode.class, "VALVE_NODE"); + + private IHintListener hoverHintListener; @Override public void init(IElement e, G2DParentNode parent) { @@ -115,7 +118,7 @@ public class CloudFactory extends SysdynElementFactory { node.setColor(Color.BLACK); node.setShape(getCloudShape()); - e.addHintListener(new IHintListener() { + hoverHintListener = new IHintListener() { @Override public void hintRemoved(IHintObservable sender, Key key, Object oldValue) { @@ -126,13 +129,15 @@ public class CloudFactory extends SysdynElementFactory { public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) { IElement e = (IElement)sender; HoverShapeNode shape = (HoverShapeNode) e.getHint(NODE); - shape.setHover(SysdynElementUtils.isHovering(e)); + shape.setHover(ElementUtils.isHovering(e)); } - }); + }; + e.addHintListener(hoverHintListener); } @Override public void cleanup(IElement e) { + e.removeHintListener(hoverHintListener); ElementUtils.removePossibleNode(e, NODE); } @@ -147,10 +152,10 @@ public class CloudFactory extends SysdynElementFactory { @Override public boolean handleMouseEvent(IElement e, ICanvasContext ctx, MouseEvent me) { if (me instanceof MouseEnterEvent) { - SysdynElementUtils.setHover(e, true); + ElementUtils.setHover(e, true); return false; } else if (me instanceof MouseExitEvent) { - SysdynElementUtils.setHover(e, false); + ElementUtils.setHover(e, false); return false; } return false; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverHandler.java deleted file mode 100644 index 8673fab2..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverHandler.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.simantics.sysdyn.ui.elements2; - -import org.simantics.g2d.element.IElement; -import org.simantics.g2d.element.handler.ElementHandler; - -public class HoverHandler implements ElementHandler { - - private static final long serialVersionUID = -6392685799523448598L; - - public static final HoverHandler INSTANCE = new HoverHandler(); - - public boolean isHovering(IElement e) { - return e.getHint(SysdynElementHints.KEY_HOVER); - } - - - public void setHover(IElement e, boolean hover) { - e.setHint(SysdynElementHints.KEY_HOVER, hover); - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextElementNoBounds.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextElementNoBounds.java index f27813ad..35b93769 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextElementNoBounds.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextElementNoBounds.java @@ -13,29 +13,22 @@ package org.simantics.sysdyn.ui.elements2; import java.awt.Color; import java.awt.Font; -import java.awt.geom.Point2D; import org.simantics.diagram.elements.ITextListener; -import org.simantics.diagram.elements.TextEditActivation; +import org.simantics.diagram.elements.TextElementNoBounds; import org.simantics.diagram.elements.TextNode; -import org.simantics.g2d.canvas.ICanvasContext; import org.simantics.g2d.diagram.DiagramUtils; 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.SceneGraphNodeKey; -import org.simantics.g2d.element.handler.HandleMouseEvent; -import org.simantics.g2d.element.handler.SceneGraph; -import org.simantics.g2d.event.MouseEvent; -import org.simantics.g2d.event.MouseEvent.MouseEnterEvent; -import org.simantics.g2d.event.MouseEvent.MouseExitEvent; -import org.simantics.g2d.participant.MouseUtil.MouseClickEvent; import org.simantics.g2d.utils.Alignment; import org.simantics.scenegraph.g2d.G2DParentNode; import org.simantics.utils.datastructures.Callback; -import org.simantics.utils.datastructures.hints.IHintContext.Key; import org.simantics.utils.datastructures.hints.IHintListener; import org.simantics.utils.datastructures.hints.IHintObservable; +import org.simantics.utils.datastructures.hints.IHintContext.Key; /** * ElementHandler for text elements @@ -43,7 +36,7 @@ import org.simantics.utils.datastructures.hints.IHintObservable; * * @author Marko Luukkainen */ -public class HoverTextElementNoBounds implements SceneGraph, HandleMouseEvent { +public class HoverTextElementNoBounds extends TextElementNoBounds { private static final long serialVersionUID = -148784588840819612L; @@ -52,38 +45,20 @@ public class HoverTextElementNoBounds implements SceneGraph, HandleMouseEvent { public static final Key SG_NODE = new SceneGraphNodeKey(TextNode.class, "TEXT_SG_NODE"); - private final double originX; - private final double originY; - private final Alignment horizontalAlignment; - private final double borderWidth; - private final boolean editable; - private final double paddingX; - private final double paddingY; - private IHintListener hoverHintListener ; - public HoverTextElementNoBounds() { - this(0, 0, Alignment.LEADING, 0); + super(0, 0, Alignment.LEADING, 0); } public HoverTextElementNoBounds(double originX, double originY, Alignment horizontalAlignment) { - this(originX, originY, horizontalAlignment, 0); + super(originX, originY, horizontalAlignment, 0); } public HoverTextElementNoBounds(double originX, double originY, Alignment horizontalAlignment, double borderWidth) { - this(originX, originY, horizontalAlignment, borderWidth, 2.0, 2.0, true); + super(originX, originY, horizontalAlignment, borderWidth); } public HoverTextElementNoBounds(double originX, double originY, Alignment horizontalAlignment, double borderWidth, double paddingX, double paddingY, boolean editable) { - if (horizontalAlignment == null) - throw new NullPointerException("null horizontal alignment"); - - this.originX = originX; - this.originY = originY; - this.horizontalAlignment = horizontalAlignment; - this.borderWidth = borderWidth; - this.editable = editable; - this.paddingX = paddingX; - this.paddingY = paddingY; + super(originX, originY, horizontalAlignment, borderWidth, paddingX, paddingY, editable); } @Override @@ -130,10 +105,11 @@ public class HoverTextElementNoBounds implements SceneGraph, HandleMouseEvent { node.setBackgroundColor(fillColor); node.setBorderColor(borderColor); node.setHorizontalAlignment((byte) horizontalAlignment.ordinal()); - node.setBorderWidth((float) borderWidth * 0.235); - node.setEditable(editable); node.setPadding(paddingX, paddingY); - hoverHintListener = new IHintListener() { + node.setBorderWidth((float) borderWidth); + node.setEditable(editable); + + this.hoverHintListener = new IHintListener() { @Override public void hintRemoved(IHintObservable sender, Key key, Object oldValue) { @@ -141,99 +117,13 @@ public class HoverTextElementNoBounds implements SceneGraph, HandleMouseEvent { @Override public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) { - if(key == SysdynElementHints.KEY_HOVER) { + if(key == ElementHints.KEY_HOVER) { IElement e = (IElement)sender; - HoverTextNode name = (HoverTextNode) e.getHint(SG_NODE); - name.setHover(SysdynElementUtils.isHovering(e)); + TextNode name = (TextNode) e.getHint(SG_NODE); + name.setHover(ElementUtils.isHovering(e)); } } }; - e.addHintListener(hoverHintListener); } - - @Override - public void cleanup(IElement e) { - ElementUtils.removePossibleNode(e, SG_NODE); - e.removeHintListener(hoverHintListener); - } - - // FIXME: hazardous with TextElementHandler.INSTANCE - TextEditActivation editActivation = null; - - @Override - public boolean handleMouseEvent(IElement e, ICanvasContext ctx, MouseEvent me) { - if (me instanceof MouseEnterEvent) { - SysdynElementUtils.setHover(e, true); - } else if (me instanceof MouseExitEvent) { - SysdynElementUtils.setHover(e, false); - } else if (me instanceof MouseClickEvent) { - MouseClickEvent mce = (MouseClickEvent)me; - if ((mce.button & MouseClickEvent.LEFT_BUTTON) > 0) { - TextNode node = (TextNode) e.getHint(SG_NODE); - if (node == null) - return false; - if (node.isEditMode()) { - Point2D p = new Point2D.Double(); - ElementUtils.controlToCanvasCoordinate(ctx, me.controlPosition, p); - if (!ElementUtils.getElementBoundsOnDiagram(e).contains(p)) { - endEdit(node); - } - } else if (!node.isEditable()) { - return false; - } else if (mce.clickCount > 1) { - editActivation = new TextEditActivation(mce.mouseId, e, ctx); - node.setEditMode(true); - node.repaint(); - } - } - } - - return false; - } - - private void endEdit(TextNode node) { - if (editActivation != null) { - editActivation.release(); - editActivation = null; - - node.setEditMode(false); - node.repaint(); - } - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - long temp; - temp = Double.doubleToLongBits(borderWidth); - result = prime * result + (int) (temp ^ (temp >>> 32)); - result = prime * result + horizontalAlignment.hashCode(); - temp = Double.doubleToLongBits(originX); - result = prime * result + (int) (temp ^ (temp >>> 32)); - temp = Double.doubleToLongBits(originY); - result = prime * result + (int) (temp ^ (temp >>> 32)); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - HoverTextElementNoBounds other = (HoverTextElementNoBounds) obj; - if (Double.doubleToLongBits(borderWidth) != Double.doubleToLongBits(other.borderWidth)) - return false; - if (horizontalAlignment != other.horizontalAlignment) - return false; - if (Double.doubleToLongBits(originX) != Double.doubleToLongBits(other.originX)) - return false; - if (Double.doubleToLongBits(originY) != Double.doubleToLongBits(other.originY)) - return false; - return true; - } } \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextNode.java index b4fa4a61..d6f1e37d 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextNode.java @@ -13,13 +13,7 @@ import org.simantics.scenegraph.utils.NodeUtil; public class HoverTextNode extends TextNode { private static final long serialVersionUID = 3539499125943249895L; - - transient public boolean hover = false; - - public void setHover(boolean hover) { - this.hover = hover; - repaint(); - } + @Override public void render(Graphics2D g) { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java index 366ab5b8..2b4cea2e 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java @@ -24,6 +24,7 @@ import org.simantics.g2d.element.SceneGraphNodeKey; import org.simantics.g2d.element.handler.InternalSize; import org.simantics.g2d.element.handler.impl.BoundsOutline; import org.simantics.g2d.element.handler.impl.DefaultTransform; +import org.simantics.g2d.element.handler.impl.HoverImpl; import org.simantics.g2d.element.handler.impl.ObjectTerminal; import org.simantics.g2d.element.handler.impl.OutlinePick; import org.simantics.g2d.element.handler.impl.SimpleElementLayers; @@ -76,7 +77,7 @@ public class InputFactory extends SysdynElementFactory { Input.INSTANCE, new InputSceneGraph(0, 0, Alignment.LEADING), BoundsOutline.INSTANCE, - HoverHandler.INSTANCE, + HoverImpl.INSTANCE, new WholeElementTerminals(terminals) ).setId(InputFactory.class.getSimpleName()); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ModuleFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ModuleFactory.java index c0d76dbb..b36ad234 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ModuleFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ModuleFactory.java @@ -19,6 +19,7 @@ import org.simantics.db.Resource; import org.simantics.g2d.element.ElementClass; import org.simantics.g2d.element.handler.impl.BoundsOutline; import org.simantics.g2d.element.handler.impl.DefaultTransform; +import org.simantics.g2d.element.handler.impl.HoverImpl; import org.simantics.g2d.element.handler.impl.ObjectTerminal; import org.simantics.g2d.element.handler.impl.OutlinePick; import org.simantics.g2d.element.handler.impl.SimpleElementLayers; @@ -49,9 +50,9 @@ public class ModuleFactory extends SysdynElementFactory { new StaticObjectAdapter(elementType), new StaticSymbolImpl(DEFAULT_IMAGE), StaticSymbolImageInitializer.INSTANCE, - new HoverTextElementHandler(0, 0, Alignment.LEADING, 1f), + new HoverTextElementHandler(0, 0, Alignment.LEADING, 0.2f), BoundsOutline.INSTANCE, - HoverHandler.INSTANCE, + HoverImpl.INSTANCE, new WholeElementTerminals(terminals) ).setId(ModuleFactory.class.getSimpleName()); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/StockFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/StockFactory.java index f94a2d84..a4ed759d 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/StockFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/StockFactory.java @@ -19,6 +19,7 @@ import org.simantics.db.Resource; import org.simantics.g2d.element.ElementClass; import org.simantics.g2d.element.handler.impl.BoundsOutline; import org.simantics.g2d.element.handler.impl.DefaultTransform; +import org.simantics.g2d.element.handler.impl.HoverImpl; import org.simantics.g2d.element.handler.impl.ObjectTerminal; import org.simantics.g2d.element.handler.impl.OutlinePick; import org.simantics.g2d.element.handler.impl.SimpleElementLayers; @@ -49,9 +50,9 @@ public class StockFactory extends SysdynElementFactory { new StaticObjectAdapter(elementType), new StaticSymbolImpl(DEFAULT_IMAGE), StaticSymbolImageInitializer.INSTANCE, - new HoverTextElementHandler(0, 0, Alignment.LEADING, 2f), + new HoverTextElementHandler(0, 0, Alignment.LEADING, 1f), BoundsOutline.INSTANCE, - HoverHandler.INSTANCE, + HoverImpl.INSTANCE, new WholeElementTerminals(terminals) ).setId(StockFactory.class.getSimpleName()); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementFactory.java index 9b739a50..50352b4e 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementFactory.java @@ -94,7 +94,7 @@ public abstract class SysdynElementFactory extends SyncElementFactory { // This synchronizes only text and transformation (not font and color) e.setHint(SynchronizationHints.HINT_SYNCHRONIZER, SYNCHRONIZER); - SysdynElementUtils.setHover(e, false); + ElementUtils.setHover(e, false); } @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementHints.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementHints.java index 5c187767..ef69bf4d 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementHints.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementHints.java @@ -7,5 +7,4 @@ public class SysdynElementHints { public static final Key KEY_INPUT_REFERENCE = new KeyOf(String.class, "INPUT_REFERENCE"); - public static final Key KEY_HOVER = new KeyOf(Boolean.class, "HOVER"); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementUtils.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementUtils.java index a77038b3..dd82a3c9 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementUtils.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementUtils.java @@ -1,9 +1,8 @@ package org.simantics.sysdyn.ui.elements2; -import org.simantics.g2d.element.ElementUtils; import org.simantics.g2d.element.IElement; -public class SysdynElementUtils extends ElementUtils { +public class SysdynElementUtils { public static void setInputReference(IElement e, String inputReference) @@ -18,15 +17,4 @@ public class SysdynElementUtils extends ElementUtils { return i.getInputReference(e); } - public static void setHover(IElement e, boolean hover) - { - HoverHandler hh = e.getElementClass().getSingleItem(HoverHandler.class); - hh.setHover(e, hover); - } - - public static boolean isHovering(IElement e) - { - HoverHandler hh = e.getElementClass().getSingleItem(HoverHandler.class); - return hh.isHovering(e); - } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ValveFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ValveFactory.java index 545dfc74..f6b8c28d 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ValveFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ValveFactory.java @@ -26,6 +26,7 @@ import org.simantics.g2d.element.handler.HandleMouseEvent; import org.simantics.g2d.element.handler.InternalSize; import org.simantics.g2d.element.handler.impl.BoundsOutline; import org.simantics.g2d.element.handler.impl.DefaultTransform; +import org.simantics.g2d.element.handler.impl.HoverImpl; import org.simantics.g2d.element.handler.impl.ObjectTerminal; import org.simantics.g2d.element.handler.impl.OutlinePick; import org.simantics.g2d.element.handler.impl.SimpleElementLayers; @@ -70,7 +71,7 @@ public class ValveFactory extends SysdynElementFactory { new StaticObjectAdapter(elementType), new StaticSymbolImpl(VALVE_STATIC_IMAGE), StaticSymbolImageInitializer.INSTANCE, - HoverHandler.INSTANCE, + HoverImpl.INSTANCE, ValveSceneGraph.INSTANCE, BoundsOutline.INSTANCE, new WholeElementTerminals(terminals) @@ -105,6 +106,8 @@ public class ValveFactory extends SysdynElementFactory { public static final ValveSceneGraph INSTANCE = new ValveSceneGraph(); private static final Key NODE = new SceneGraphNodeKey(ShapeNode.class, "VALVE_NODE"); + + private IHintListener hoverHintListener; public ValveSceneGraph() { super(0, VALVE_SIZE + 3.0, Alignment.CENTER); @@ -119,9 +122,9 @@ public class ValveFactory extends SysdynElementFactory { node.setScaleStroke(true); node.setColor(Color.BLACK); node.setShape(createShape(VALVE_SIZE, Boolean.TRUE.equals(e.getHint(KEY_ROTATED)))); - node.setHover(SysdynElementUtils.isHovering(e)); + node.setHover(ElementUtils.isHovering(e)); - e.addHintListener(new IHintListener() { + hoverHintListener = new IHintListener() { @Override public void hintRemoved(IHintObservable sender, Key key, Object oldValue) { @@ -133,15 +136,17 @@ public class ValveFactory extends SysdynElementFactory { IElement e = (IElement)sender; // TextNode name = (TextNode) e.getHint(SG_NODE); HoverShapeNode shape = (HoverShapeNode) e.getHint(NODE); - boolean hover = SysdynElementUtils.isHovering(e); + boolean hover = ElementUtils.isHovering(e); shape.setHover(hover); // name.setHover(hover); } - }); + }; + e.addHintListener(hoverHintListener); } @Override public void cleanup(IElement e) { + e.removeHintListener(hoverHintListener); ElementUtils.removePossibleNode(e, NODE); } -- 2.47.1