import java.util.Collection;\r
\r
import org.simantics.db.Resource;\r
-import org.simantics.diagram.elements.TextElementHandler;\r
import org.simantics.g2d.element.ElementClass;\r
import org.simantics.g2d.element.handler.impl.BoundsOutline;\r
import org.simantics.g2d.element.handler.impl.DefaultTransform;\r
new StaticObjectAdapter(elementType),\r
new StaticSymbolImpl(AUX_STATIC_IMAGE),\r
StaticSymbolImageInitializer.INSTANCE,\r
- TextElementHandler.INSTANCE,\r
+ HoverTextElementHandler.INSTANCE,\r
BoundsOutline.INSTANCE,\r
+ HoverHandler.INSTANCE,\r
new WholeElementTerminals(terminals)\r
).setId(AuxiliaryFactory.class.getSimpleName());\r
}\r
import java.util.Collection;\r
\r
import org.simantics.db.Resource;\r
+import org.simantics.g2d.canvas.ICanvasContext;\r
import org.simantics.g2d.element.ElementClass;\r
import org.simantics.g2d.element.ElementUtils;\r
import org.simantics.g2d.element.IElement;\r
import org.simantics.g2d.element.SceneGraphNodeKey;\r
+import org.simantics.g2d.element.handler.HandleMouseEvent;\r
import org.simantics.g2d.element.handler.InternalSize;\r
import org.simantics.g2d.element.handler.SceneGraph;\r
import org.simantics.g2d.element.handler.impl.BoundsOutline;\r
import org.simantics.g2d.element.handler.impl.TextColorImpl;\r
import org.simantics.g2d.element.handler.impl.TextFontImpl;\r
import org.simantics.g2d.element.handler.impl.TextImpl;\r
+import org.simantics.g2d.event.MouseEvent;\r
+import org.simantics.g2d.event.MouseEvent.MouseEnterEvent;\r
+import org.simantics.g2d.event.MouseEvent.MouseExitEvent;\r
import org.simantics.g2d.image.Image;\r
import org.simantics.g2d.image.impl.ShapeImage;\r
import org.simantics.scenegraph.g2d.G2DParentNode;\r
import org.simantics.scenegraph.g2d.nodes.ShapeNode;\r
+import org.simantics.utils.datastructures.hints.IHintListener;\r
+import org.simantics.utils.datastructures.hints.IHintObservable;\r
import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
\r
public class CloudFactory extends SysdynElementFactory {\r
new StaticSymbolImpl(DEFAULT_IMAGE),\r
StaticSymbolImageInitializer.INSTANCE,\r
CloudSceneGraph.INSTANCE,\r
+ HoverHandler.INSTANCE,\r
BoundsOutline.INSTANCE,\r
new WholeElementTerminals(terminals)\r
).setId(CloudFactory.class.getSimpleName());\r
}\r
\r
-\r
- public static class CloudSceneGraph implements SceneGraph, InternalSize {\r
+ public static class CloudSceneGraph implements SceneGraph, InternalSize, HandleMouseEvent {\r
\r
private static final long serialVersionUID = 5544256245734478634L;\r
\r
\r
@Override\r
public void init(IElement e, G2DParentNode parent) {\r
- ShapeNode node = ElementUtils.getOrCreateNode(e, parent, NODE, "valve", ShapeNode.class);\r
+ HoverShapeNode node = ElementUtils.getOrCreateNode(e, parent, NODE, "valve", HoverShapeNode.class);\r
\r
node.setStroke(STROKE);\r
node.setScaleStroke(true);\r
node.setColor(Color.BLACK);\r
node.setShape(getCloudShape());\r
+ \r
+ e.addHintListener(new IHintListener() {\r
+ \r
+ @Override\r
+ public void hintRemoved(IHintObservable sender, Key key, Object oldValue) {\r
+ \r
+ }\r
+ \r
+ @Override\r
+ public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) {\r
+ IElement e = (IElement)sender;\r
+ HoverShapeNode shape = (HoverShapeNode) e.getHint(NODE);\r
+ shape.setHover(SysdynElementUtils.isHovering(e));\r
+ }\r
+ });\r
}\r
\r
@Override\r
return size;\r
}\r
\r
+ @Override\r
+ public boolean handleMouseEvent(IElement e, ICanvasContext ctx, MouseEvent me) {\r
+ if (me instanceof MouseEnterEvent) {\r
+ SysdynElementUtils.setHover(e, true);\r
+ return false;\r
+ } else if (me instanceof MouseExitEvent) {\r
+ SysdynElementUtils.setHover(e, false);\r
+ return false;\r
+ }\r
+ return false;\r
+ }\r
+\r
}\r
\r
}\r
--- /dev/null
+package org.simantics.sysdyn.ui.elements2;\r
+\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.handler.ElementHandler;\r
+\r
+public class HoverHandler implements ElementHandler {\r
+ \r
+ private static final long serialVersionUID = -6392685799523448598L;\r
+ \r
+ public static final HoverHandler INSTANCE = new HoverHandler();\r
+ \r
+ public boolean isHovering(IElement e) {\r
+ return e.getHint(SysdynElementHints.KEY_HOVER);\r
+ }\r
+\r
+ \r
+ public void setHover(IElement e, boolean hover) {\r
+ e.setHint(SysdynElementHints.KEY_HOVER, hover);\r
+ }\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.elements2;\r
+\r
+import java.awt.BasicStroke;\r
+import java.awt.Color;\r
+import java.awt.Graphics2D;\r
+import java.awt.Shape;\r
+import java.awt.Stroke;\r
+import org.simantics.scenegraph.g2d.nodes.ShapeNode;\r
+\r
+public class HoverShapeNode extends ShapeNode {\r
+\r
+ private static final long serialVersionUID = -4580969977763722602L;\r
+\r
+ transient public boolean hover = false;\r
+ \r
+ @Override\r
+ protected void renderShape(Graphics2D g2d, Shape s) {\r
+ boolean fill = Boolean.TRUE.equals(dynamicFill) ? true : this.fill;\r
+ if (fill)\r
+ g2d.fill(s);\r
+ \r
+ if(hover) {\r
+ BasicStroke oldStroke = (BasicStroke)g2d.getStroke();\r
+ Color oldColor = g2d.getColor();\r
+ g2d.setColor(Color.LIGHT_GRAY);\r
+ float lineWidth = oldStroke.getLineWidth() * 6;\r
+ g2d.setStroke(new BasicStroke(lineWidth < 1.0f ? lineWidth : 1.0f));\r
+ g2d.draw(s);\r
+ g2d.setColor(oldColor);\r
+ g2d.setStroke(oldStroke);\r
+ }\r
+\r
+ Stroke stroke = dynamicStroke != null ? dynamicStroke : this.stroke;\r
+ if (stroke != null)\r
+ g2d.draw(s);\r
+ \r
+ }\r
+ \r
+ public void setHover(boolean hover) {\r
+ this.hover = hover;\r
+ repaint();\r
+ }\r
+\r
+\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.elements2;\r
+\r
+import java.awt.geom.Rectangle2D;\r
+\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.handler.InternalSize;\r
+import org.simantics.g2d.utils.Alignment;\r
+\r
+public class HoverTextElementHandler extends HoverTextElementNoBounds implements InternalSize {\r
+\r
+ private static final long serialVersionUID = 8800738238681432901L;\r
+ \r
+ public static final HoverTextElementHandler INSTANCE = new HoverTextElementHandler();\r
+\r
+ public HoverTextElementHandler() {\r
+ super();\r
+ }\r
+\r
+ public HoverTextElementHandler(double originX, double originY, Alignment horizontalAlignment) {\r
+ super(originX, originY, horizontalAlignment);\r
+ }\r
+\r
+ public HoverTextElementHandler(double originX, double originY, Alignment horizontalAlignment, double borderWidth) {\r
+ super(originX, originY, horizontalAlignment, borderWidth);\r
+ }\r
+\r
+ public HoverTextElementHandler(double originX, double originY, Alignment horizontalAlignment, double borderWidth,\r
+ boolean editable) {\r
+ super(originX, originY, horizontalAlignment, borderWidth, editable);\r
+ }\r
+\r
+ @Override\r
+ public Rectangle2D getBounds(IElement e, Rectangle2D size) {\r
+ HoverTextNode node = (HoverTextNode) e.getHint(SG_NODE);\r
+ if (size == null)\r
+ size = new Rectangle2D.Double();\r
+ if (node != null)\r
+ size.setRect(node.getBoundsInLocal());\r
+ else\r
+ size.setFrame(0, 0, 0, 0);\r
+ return size;\r
+ }\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.elements2;\r
+\r
+import java.awt.Color;\r
+import java.awt.Font;\r
+import java.awt.geom.Point2D;\r
+import java.util.Collection;\r
+\r
+import org.simantics.diagram.elements.ITextListener;\r
+import org.simantics.diagram.elements.TextNode;\r
+import org.simantics.diagram.participant.ContextUtil;\r
+import org.simantics.g2d.canvas.ICanvasContext;\r
+import org.simantics.g2d.canvas.IMouseCaptureHandle;\r
+import org.simantics.g2d.diagram.DiagramUtils;\r
+import org.simantics.g2d.diagram.IDiagram;\r
+import org.simantics.g2d.diagram.participant.ElementInteractor;\r
+import org.simantics.g2d.element.ElementUtils;\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.SceneGraphNodeKey;\r
+import org.simantics.g2d.element.handler.HandleMouseEvent;\r
+import org.simantics.g2d.element.handler.SceneGraph;\r
+import org.simantics.g2d.event.MouseEvent;\r
+import org.simantics.g2d.event.MouseEvent.MouseEnterEvent;\r
+import org.simantics.g2d.event.MouseEvent.MouseExitEvent;\r
+import org.simantics.g2d.participant.MouseUtil.MouseClickEvent;\r
+import org.simantics.g2d.utils.Alignment;\r
+import org.simantics.scenegraph.g2d.G2DParentNode;\r
+import org.simantics.utils.datastructures.Callback;\r
+import org.simantics.utils.datastructures.hints.IHintListener;\r
+import org.simantics.utils.datastructures.hints.IHintObservable;\r
+import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
+\r
+/**\r
+ * ElementHandler for text elements\r
+ * In-line editing supported.\r
+ * \r
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
+ */\r
+public class HoverTextElementNoBounds implements SceneGraph, HandleMouseEvent {\r
+\r
+ private static final long serialVersionUID = -148784588840819612L;\r
+\r
+\r
+ public static final HoverTextElementNoBounds INSTANCE = new HoverTextElementNoBounds();\r
+\r
+ public static final Key SG_NODE = new SceneGraphNodeKey(TextNode.class, "TEXT_SG_NODE");\r
+\r
+ private final double originX;\r
+ private final double originY;\r
+ private final Alignment horizontalAlignment;\r
+ private final double borderWidth;\r
+ private final boolean editable;\r
+\r
+ public HoverTextElementNoBounds() {\r
+ this(0, 0, Alignment.LEADING, 0);\r
+ }\r
+\r
+ public HoverTextElementNoBounds(double originX, double originY, Alignment horizontalAlignment) {\r
+ this(originX, originY, horizontalAlignment, 0);\r
+ }\r
+\r
+ public HoverTextElementNoBounds(double originX, double originY, Alignment horizontalAlignment, double borderWidth) {\r
+ this(originX, originY, horizontalAlignment, borderWidth, true);\r
+ }\r
+\r
+ public HoverTextElementNoBounds(double originX, double originY, Alignment horizontalAlignment, double borderWidth, boolean editable) {\r
+ if (horizontalAlignment == null)\r
+ throw new NullPointerException("null horizontal alignment");\r
+\r
+ this.originX = originX;\r
+ this.originY = originY;\r
+ this.horizontalAlignment = horizontalAlignment;\r
+ this.borderWidth = borderWidth;\r
+ this.editable = editable;\r
+ }\r
+\r
+ @Override\r
+ public void init(final IElement e, G2DParentNode parent) {\r
+ HoverTextNode node = ElementUtils.getOrCreateNode(e, parent, SG_NODE, "text", HoverTextNode.class, new Callback<HoverTextNode>() {\r
+ @Override\r
+ public void run(HoverTextNode node) {\r
+ node.setTextListener(new ITextListener() {\r
+ @Override\r
+ public void textChanged() {}\r
+\r
+ @Override\r
+ public void textEditingStarted() {}\r
+\r
+ @Override\r
+ public void textEditingCancelled() {\r
+ TextNode node = (TextNode) e.getHint(SG_NODE);\r
+ if (node != null)\r
+ endEdit(node);\r
+ }\r
+\r
+ @Override\r
+ public void textEditingEnded() {\r
+ TextNode node = (TextNode) e.getHint(SG_NODE);\r
+ if (node == null)\r
+ return;\r
+ //System.out.println("Node text changed: " + node.getText());\r
+ ElementUtils.setText(e, node.getText());\r
+ IDiagram diagram = ElementUtils.getDiagram(e);\r
+ DiagramUtils.synchronizeHintsToBackend(diagram, e);\r
+ endEdit(node);\r
+ }\r
+ });\r
+ }\r
+ });\r
+\r
+ //Font font = new Font("Tahoma", 0, 12);\r
+ Font font = ElementUtils.getTextFont(e);\r
+ Color color = ElementUtils.getTextColor(e);\r
+ Color fillColor = ElementUtils.getFillColor(e);\r
+ Color borderColor = ElementUtils.getBorderColor(e, Color.BLACK);\r
+ String text = ElementUtils.getText(e);\r
+ node.init(text, font, color, originX, originY, 0.235);\r
+ node.setBackgroundColor(fillColor);\r
+ node.setBorderColor(borderColor);\r
+ node.setHorizontalAlignment((byte) horizontalAlignment.ordinal());\r
+ node.setBorderWidth((float) borderWidth);\r
+ node.setEditable(editable);\r
+ \r
+ e.addHintListener(new IHintListener() {\r
+ \r
+ @Override\r
+ public void hintRemoved(IHintObservable sender, Key key, Object oldValue) {\r
+ \r
+ }\r
+ \r
+ @Override\r
+ public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) {\r
+ IElement e = (IElement)sender;\r
+ HoverTextNode name = (HoverTextNode) e.getHint(SG_NODE);\r
+ name.setHover(SysdynElementUtils.isHovering(e));\r
+ }\r
+ });\r
+ }\r
+\r
+ @Override\r
+ public void cleanup(IElement e) {\r
+ ElementUtils.removePossibleNode(e, SG_NODE);\r
+ }\r
+\r
+ // FIXME: hazardous with TextElementHandler.INSTANCE\r
+ TextEditActivation editActivation = null;\r
+\r
+ @Override\r
+ public boolean handleMouseEvent(IElement e, ICanvasContext ctx, MouseEvent me) {\r
+ if (me instanceof MouseEnterEvent) {\r
+ SysdynElementUtils.setHover(e, true);\r
+ } else if (me instanceof MouseExitEvent) {\r
+ SysdynElementUtils.setHover(e, false);\r
+ } else if (me instanceof MouseClickEvent) {\r
+ MouseClickEvent mce = (MouseClickEvent)me;\r
+ if ((mce.button & MouseClickEvent.LEFT_BUTTON) > 0) {\r
+ TextNode node = (TextNode) e.getHint(SG_NODE);\r
+ if (node == null)\r
+ return false;\r
+ if (node.isEditMode()) {\r
+ Point2D p = new Point2D.Double();\r
+ ElementUtils.controlToCanvasCoordinate(ctx, me.controlPosition, p);\r
+ if (!ElementUtils.getElementBoundsOnDiagram(e).contains(p)) {\r
+ endEdit(node);\r
+ }\r
+ } else if (!node.isEditable()) {\r
+ return false;\r
+ } else if (mce.clickCount > 1) {\r
+ editActivation = new TextEditActivation(mce.mouseId, e, ctx);\r
+ node.setEditMode(true);\r
+ node.repaint();\r
+ }\r
+ }\r
+ }\r
+\r
+ return false;\r
+ }\r
+\r
+ private void endEdit(TextNode node) {\r
+ if (editActivation != null) {\r
+ editActivation.release();\r
+ editActivation = null;\r
+\r
+ node.setEditMode(false);\r
+ node.repaint();\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public int hashCode() {\r
+ final int prime = 31;\r
+ int result = 1;\r
+ long temp;\r
+ temp = Double.doubleToLongBits(borderWidth);\r
+ result = prime * result + (int) (temp ^ (temp >>> 32));\r
+ result = prime * result + horizontalAlignment.hashCode();\r
+ temp = Double.doubleToLongBits(originX);\r
+ result = prime * result + (int) (temp ^ (temp >>> 32));\r
+ temp = Double.doubleToLongBits(originY);\r
+ result = prime * result + (int) (temp ^ (temp >>> 32));\r
+ return result;\r
+ }\r
+\r
+ @Override\r
+ public boolean equals(Object obj) {\r
+ if (this == obj)\r
+ return true;\r
+ if (obj == null)\r
+ return false;\r
+ if (getClass() != obj.getClass())\r
+ return false;\r
+ HoverTextElementNoBounds other = (HoverTextElementNoBounds) obj;\r
+ if (Double.doubleToLongBits(borderWidth) != Double.doubleToLongBits(other.borderWidth))\r
+ return false;\r
+ if (horizontalAlignment != other.horizontalAlignment)\r
+ return false;\r
+ if (Double.doubleToLongBits(originX) != Double.doubleToLongBits(other.originX))\r
+ return false;\r
+ if (Double.doubleToLongBits(originY) != Double.doubleToLongBits(other.originY))\r
+ return false;\r
+ return true;\r
+ }\r
+ \r
+ \r
+ \r
+ \r
+ \r
+ \r
+ \r
+ class TextEditActivation {\r
+\r
+ ICanvasContext ctx;\r
+ IMouseCaptureHandle capture;\r
+ ContextUtil ctxUtil;\r
+ Collection<String> originalContexts;\r
+\r
+ public TextEditActivation(int mouseId, IElement e, ICanvasContext ctx) {\r
+ ElementInteractor ei = ctx.getSingleItem(ElementInteractor.class);\r
+ this.ctxUtil = ctx.getSingleItem(ContextUtil.class);\r
+\r
+ // Capture mouse events (otherwise we would not get mouse events when the cursor is outside the text widget)\r
+ this.capture = ei.captureMouse(e, mouseId);\r
+\r
+ // activate in-line editing context\r
+ this.originalContexts = ctxUtil.getActivatedContextIds();\r
+ ctxUtil.deactivateAll();\r
+ ctxUtil.activate("org.simantics.modeling.ui.diagramming.inlineEdit");\r
+ }\r
+\r
+ public void release() {\r
+ capture.release();\r
+ capture = null;\r
+\r
+ // de-activate in-line editing context\r
+ ctxUtil.deactivateAll();\r
+ ctxUtil.activate(originalContexts);\r
+ }\r
+\r
+ }\r
+\r
+}
\ No newline at end of file
--- /dev/null
+package org.simantics.sysdyn.ui.elements2;\r
+\r
+import java.awt.BasicStroke;\r
+import java.awt.Color;\r
+import java.awt.Graphics2D;\r
+import java.awt.geom.Rectangle2D;\r
+\r
+import org.simantics.diagram.elements.TextNode;\r
+import org.simantics.scenegraph.utils.NodeUtil;\r
+\r
+public class HoverTextNode extends TextNode {\r
+\r
+ private static final long serialVersionUID = 3539499125943249895L;\r
+\r
+ transient public boolean hover = false;\r
+\r
+ public void setHover(boolean hover) {\r
+ this.hover = hover;\r
+ repaint();\r
+ }\r
+\r
+ @Override\r
+ public void render(Graphics2D g) {\r
+ Rectangle2D r = getBoundsInLocal();\r
+ \r
+ boolean selected = NodeUtil.isSelected(this, 1);\r
+ if (!selected && hover){\r
+ \r
+ BasicStroke oldStroke = (BasicStroke)g.getStroke();\r
+ Color oldColor = g.getColor();\r
+ g.setColor(Color.LIGHT_GRAY);\r
+ g.setStroke(new BasicStroke((float)(2.0f * scale)));\r
+ g.translate(x, y);\r
+ g.draw(r);\r
+ g.translate(-x, -y);\r
+ g.setColor(oldColor);\r
+ g.setStroke(oldStroke);\r
+ }\r
+ \r
+ super.render(g);\r
+ \r
+\r
+ }\r
+}\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.diagram.elements.TextElementNoBounds;\r
import org.simantics.diagram.elements.TextNode;\r
import org.simantics.diagram.stubs.DiagramResource;\r
import org.simantics.diagram.ui.DiagramModelHints;\r
Input.INSTANCE,\r
new InputSceneGraph(0, 0, Alignment.CENTER),\r
BoundsOutline.INSTANCE,\r
+ HoverHandler.INSTANCE,\r
new WholeElementTerminals(terminals)\r
).setId(InputFactory.class.getSimpleName());\r
}\r
}\r
\r
\r
- public static class InputSceneGraph extends TextElementNoBounds implements InternalSize {\r
+ public static class InputSceneGraph extends HoverTextElementNoBounds implements InternalSize {\r
\r
private static final long serialVersionUID = -3713275157729126409L;\r
public static final Key INPUT_SG_NODE = new SceneGraphNodeKey(TextNode.class, "INPUT_SG_NODE");\r
size.setFrame(0, 0, 0, 0);\r
return size;\r
}\r
+ \r
}\r
}\r
import java.util.Collection;\r
\r
import org.simantics.db.Resource;\r
-import org.simantics.diagram.elements.TextElementHandler;\r
import org.simantics.g2d.element.ElementClass;\r
import org.simantics.g2d.element.handler.impl.BoundsOutline;\r
import org.simantics.g2d.element.handler.impl.DefaultTransform;\r
new StaticObjectAdapter(elementType),\r
new StaticSymbolImpl(DEFAULT_IMAGE),\r
StaticSymbolImageInitializer.INSTANCE,\r
- TextElementHandler.INSTANCE,\r
+ HoverTextElementHandler.INSTANCE,\r
BorderSceneGraph.INSTANCE,\r
BoundsOutline.INSTANCE,\r
+ HoverHandler.INSTANCE,\r
new WholeElementTerminals(terminals)\r
).setId(ModuleFactory.class.getSimpleName());\r
}\r
import java.util.Collection;\r
\r
import org.simantics.db.Resource;\r
-import org.simantics.diagram.elements.TextElementHandler;\r
import org.simantics.g2d.element.ElementClass;\r
import org.simantics.g2d.element.handler.impl.BoundsOutline;\r
import org.simantics.g2d.element.handler.impl.DefaultTransform;\r
new StaticObjectAdapter(elementType),\r
new StaticSymbolImpl(DEFAULT_IMAGE),\r
StaticSymbolImageInitializer.INSTANCE,\r
- TextElementHandler.INSTANCE,\r
+ HoverTextElementHandler.INSTANCE,\r
BorderSceneGraph.INSTANCE,\r
BoundsOutline.INSTANCE,\r
+ HoverHandler.INSTANCE,\r
new WholeElementTerminals(terminals)\r
).setId(StockFactory.class.getSimpleName());\r
}\r
\r
// This synchronizes only text and transformation (not font and color)\r
e.setHint(SynchronizationHints.HINT_SYNCHRONIZER, SYNCHRONIZER);\r
+ \r
+ SysdynElementUtils.setHover(e, false);\r
}\r
\r
@Override\r
public class SysdynElementHints {\r
\r
public static final Key KEY_INPUT_REFERENCE = new KeyOf(String.class, "INPUT_REFERENCE");\r
+ \r
+ public static final Key KEY_HOVER = new KeyOf(Boolean.class, "HOVER");\r
}\r
Input i = e.getElementClass().getSingleItem(Input.class);\r
return i.getInputReference(e);\r
}\r
+ \r
+ public static void setHover(IElement e, boolean hover)\r
+ {\r
+ HoverHandler hh = e.getElementClass().getSingleItem(HoverHandler.class);\r
+ hh.setHover(e, hover);\r
+ }\r
+\r
+ public static boolean isHovering(IElement e)\r
+ {\r
+ HoverHandler hh = e.getElementClass().getSingleItem(HoverHandler.class);\r
+ return hh.isHovering(e);\r
+ } \r
}\r
import java.awt.Color;\r
import java.awt.geom.Path2D;\r
import java.awt.geom.Rectangle2D;\r
-import java.awt.geom.Rectangle2D.Double;\r
import java.util.Collection;\r
\r
import org.simantics.db.Resource;\r
-import org.simantics.diagram.elements.TextElementNoBounds;\r
import org.simantics.g2d.element.ElementClass;\r
import org.simantics.g2d.element.ElementUtils;\r
import org.simantics.g2d.element.IElement;\r
import org.simantics.g2d.element.SceneGraphNodeKey;\r
-import org.simantics.g2d.element.handler.ElementHandler;\r
+import org.simantics.g2d.element.handler.HandleMouseEvent;\r
import org.simantics.g2d.element.handler.InternalSize;\r
-import org.simantics.g2d.element.handler.SceneGraph;\r
import org.simantics.g2d.element.handler.impl.BoundsOutline;\r
import org.simantics.g2d.element.handler.impl.DefaultTransform;\r
import org.simantics.g2d.element.handler.impl.ObjectTerminal;\r
import org.simantics.g2d.utils.Alignment;\r
import org.simantics.scenegraph.g2d.G2DParentNode;\r
import org.simantics.scenegraph.g2d.nodes.ShapeNode;\r
+import org.simantics.utils.datastructures.hints.IHintListener;\r
+import org.simantics.utils.datastructures.hints.IHintObservable;\r
import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
\r
\r
public static final double VALVE_SIZE = 2.5;\r
\r
- private static final ElementHandler TEXT_NODE = new TextElementNoBounds(0, VALVE_SIZE + 2, Alignment.CENTER);\r
-\r
private static final BasicStroke STROKE = new BasicStroke(1f);\r
private static final Image VALVE_STATIC_IMAGE = new ShapeImage(createShape(VALVE_SIZE, false), null, STROKE, true);\r
\r
new StaticObjectAdapter(elementType),\r
new StaticSymbolImpl(VALVE_STATIC_IMAGE),\r
StaticSymbolImageInitializer.INSTANCE,\r
- TEXT_NODE,\r
+ HoverHandler.INSTANCE,\r
ValveSceneGraph.INSTANCE,\r
BoundsOutline.INSTANCE,\r
new WholeElementTerminals(terminals)\r
).setId(ValveFactory.class.getSimpleName());\r
}\r
-\r
+ \r
/**\r
* @param valveSize\r
* @param rotated <code>true</code> for vertical valve, <code>false</code>\r
return path;\r
}\r
\r
- public static class ValveSceneGraph implements SceneGraph, InternalSize {\r
+ public static class ValveSceneGraph extends HoverTextElementNoBounds implements InternalSize, HandleMouseEvent {\r
\r
private static final long serialVersionUID = 5544256245734478634L;\r
\r
\r
private static final Key NODE = new SceneGraphNodeKey(ShapeNode.class, "VALVE_NODE");\r
\r
+ public ValveSceneGraph() {\r
+ super(0, VALVE_SIZE + 2, Alignment.CENTER);\r
+ }\r
@Override\r
public void init(IElement e, G2DParentNode parent) {\r
- ShapeNode node = ElementUtils.getOrCreateNode(e, parent, NODE, "valve", ShapeNode.class);\r
+ super.init(e, parent);\r
+ final HoverShapeNode node = ElementUtils.getOrCreateNode(e, parent, NODE, "valve", HoverShapeNode.class);\r
\r
// Calculate borders from text node bounds.\r
node.setStroke(STROKE);\r
node.setScaleStroke(true);\r
node.setColor(Color.BLACK);\r
node.setShape(createShape(VALVE_SIZE, Boolean.TRUE.equals(e.getHint(KEY_ROTATED))));\r
+ node.setHover(SysdynElementUtils.isHovering(e));\r
+\r
+ e.addHintListener(new IHintListener() {\r
+ \r
+ @Override\r
+ public void hintRemoved(IHintObservable sender, Key key, Object oldValue) {\r
+ \r
+ }\r
+ \r
+ @Override\r
+ public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) {\r
+ IElement e = (IElement)sender;\r
+// TextNode name = (TextNode) e.getHint(SG_NODE);\r
+ HoverShapeNode shape = (HoverShapeNode) e.getHint(NODE);\r
+ boolean hover = SysdynElementUtils.isHovering(e);\r
+ shape.setHover(hover);\r
+// name.setHover(hover);\r
+ }\r
+ });\r
}\r
\r
@Override\r