From a489ea23cdc41d8bae686aef89b4bb13b1c2c6cf Mon Sep 17 00:00:00 2001 From: lempinen Date: Thu, 9 Sep 2010 07:10:45 +0000 Subject: [PATCH] No more errors when a cloud is removed git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@17850 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/ui/elements2/CloudFactory.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) 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 d71c5796..083adef6 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 @@ -22,6 +22,7 @@ import java.util.Collection; import org.simantics.db.Resource; import org.simantics.g2d.canvas.ICanvasContext; import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.ElementHints; import org.simantics.g2d.element.ElementUtils; import org.simantics.g2d.element.IElement; import org.simantics.g2d.element.SceneGraphNodeKey; @@ -80,9 +81,8 @@ public class CloudFactory extends SysdynElementFactory { } return path; } - - @Override - protected ElementClass compileElementClass(Resource elementType, Collection terminals) { + + public static ElementClass createElementClass(Resource elementType, Collection terminals) { return ElementClass.compile( SimpleElementLayers.INSTANCE, OutlinePick.INSTANCE, @@ -100,20 +100,25 @@ public class CloudFactory extends SysdynElementFactory { ).setId(CloudFactory.class.getSimpleName()); } + @Override + protected ElementClass compileElementClass(Resource elementType, Collection terminals) { + return createElementClass(elementType, terminals); + } + public static class CloudSceneGraph implements SceneGraph, InternalSize, HandleMouseEvent { private static final long serialVersionUID = 5544256245734478634L; public static final CloudSceneGraph INSTANCE = new CloudSceneGraph(); - private static final Key NODE = new SceneGraphNodeKey(ShapeNode.class, "VALVE_NODE"); + private static final Key NODE = new SceneGraphNodeKey(ShapeNode.class, "CLOUD_NODE"); private IHintListener hoverHintListener; @Override public void init(IElement e, G2DParentNode parent) { AffineTransform at = ElementUtils.getTransform(e); - HoverShapeNode node = ElementUtils.getOrCreateNode(e, parent, NODE, "valve", HoverShapeNode.class); + HoverShapeNode node = ElementUtils.getOrCreateNode(e, parent, NODE, "cloud", HoverShapeNode.class); node.setStroke(STROKE); node.setScaleStroke(true); @@ -137,6 +142,9 @@ 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); + if(shape == null) { + return; + } shape.setHover(ElementUtils.isHovering(e)); } }; @@ -160,10 +168,10 @@ public class CloudFactory extends SysdynElementFactory { @Override public boolean handleMouseEvent(IElement e, ICanvasContext ctx, MouseEvent me) { if (me instanceof MouseEnterEvent) { - ElementUtils.setHover(e, true); + e.setHint(ElementHints.KEY_HOVER, true); return false; } else if (me instanceof MouseExitEvent) { - ElementUtils.setHover(e, false); + e.setHint(ElementHints.KEY_HOVER, false); return false; } return false; -- 2.47.1