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
+import org.simantics.g2d.element.handler.impl.HoverImpl;\r
import org.simantics.g2d.element.handler.impl.ObjectTerminal;\r
import org.simantics.g2d.element.handler.impl.OutlinePick;\r
import org.simantics.g2d.element.handler.impl.SimpleElementLayers;\r
StaticSymbolImageInitializer.INSTANCE,\r
HoverTextElementHandler.INSTANCE,\r
BoundsOutline.INSTANCE,\r
- HoverHandler.INSTANCE,\r
+ HoverImpl.INSTANCE,\r
new WholeElementTerminals(terminals)\r
).setId(AuxiliaryFactory.class.getSimpleName());\r
}\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.HoverImpl;\r
import org.simantics.g2d.element.handler.impl.ObjectTerminal;\r
import org.simantics.g2d.element.handler.impl.OutlinePick;\r
import org.simantics.g2d.element.handler.impl.SimpleElementLayers;\r
new StaticSymbolImpl(DEFAULT_IMAGE),\r
StaticSymbolImageInitializer.INSTANCE,\r
CloudSceneGraph.INSTANCE,\r
- HoverHandler.INSTANCE,\r
+ HoverImpl.INSTANCE,\r
BoundsOutline.INSTANCE,\r
new WholeElementTerminals(terminals)\r
).setId(CloudFactory.class.getSimpleName());\r
public static final CloudSceneGraph INSTANCE = new CloudSceneGraph();\r
\r
private static final Key NODE = new SceneGraphNodeKey(ShapeNode.class, "VALVE_NODE");\r
+ \r
+ private IHintListener hoverHintListener;\r
\r
@Override\r
public void init(IElement e, G2DParentNode parent) {\r
node.setColor(Color.BLACK);\r
node.setShape(getCloudShape());\r
\r
- e.addHintListener(new IHintListener() {\r
+ hoverHintListener = new IHintListener() {\r
\r
@Override\r
public void hintRemoved(IHintObservable sender, Key key, Object oldValue) {\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
+ shape.setHover(ElementUtils.isHovering(e));\r
}\r
- });\r
+ };\r
+ e.addHintListener(hoverHintListener);\r
}\r
\r
@Override\r
public void cleanup(IElement e) {\r
+ e.removeHintListener(hoverHintListener);\r
ElementUtils.removePossibleNode(e, NODE);\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
+ ElementUtils.setHover(e, true);\r
return false;\r
} else if (me instanceof MouseExitEvent) {\r
- SysdynElementUtils.setHover(e, false);\r
+ ElementUtils.setHover(e, false);\r
return false;\r
}\r
return false;\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
\r
import java.awt.Color;\r
import java.awt.Font;\r
-import java.awt.geom.Point2D;\r
\r
import org.simantics.diagram.elements.ITextListener;\r
-import org.simantics.diagram.elements.TextEditActivation;\r
+import org.simantics.diagram.elements.TextElementNoBounds;\r
import org.simantics.diagram.elements.TextNode;\r
-import org.simantics.g2d.canvas.ICanvasContext;\r
import org.simantics.g2d.diagram.DiagramUtils;\r
import org.simantics.g2d.diagram.IDiagram;\r
+import org.simantics.g2d.element.ElementHints;\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.IHintContext.Key;\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
* \r
* @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
*/\r
-public class HoverTextElementNoBounds implements SceneGraph, HandleMouseEvent {\r
+public class HoverTextElementNoBounds extends TextElementNoBounds {\r
\r
private static final long serialVersionUID = -148784588840819612L;\r
\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
- private final double paddingX;\r
- private final double paddingY;\r
- private IHintListener hoverHintListener ;\r
-\r
public HoverTextElementNoBounds() {\r
- this(0, 0, Alignment.LEADING, 0);\r
+ super(0, 0, Alignment.LEADING, 0);\r
}\r
\r
public HoverTextElementNoBounds(double originX, double originY, Alignment horizontalAlignment) {\r
- this(originX, originY, horizontalAlignment, 0);\r
+ super(originX, originY, horizontalAlignment, 0);\r
}\r
\r
public HoverTextElementNoBounds(double originX, double originY, Alignment horizontalAlignment, double borderWidth) {\r
- this(originX, originY, horizontalAlignment, borderWidth, 2.0, 2.0, true);\r
+ super(originX, originY, horizontalAlignment, borderWidth);\r
}\r
\r
public HoverTextElementNoBounds(double originX, double originY, Alignment horizontalAlignment, double borderWidth, double paddingX, double paddingY, 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
- this.paddingX = paddingX;\r
- this.paddingY = paddingY;\r
+ super(originX, originY, horizontalAlignment, borderWidth, paddingX, paddingY, editable);\r
}\r
\r
@Override\r
node.setBackgroundColor(fillColor);\r
node.setBorderColor(borderColor);\r
node.setHorizontalAlignment((byte) horizontalAlignment.ordinal());\r
- node.setBorderWidth((float) borderWidth * 0.235);\r
- node.setEditable(editable);\r
node.setPadding(paddingX, paddingY);\r
- hoverHintListener = new IHintListener() {\r
+ node.setBorderWidth((float) borderWidth);\r
+ node.setEditable(editable);\r
+ \r
+ this.hoverHintListener = new IHintListener() {\r
@Override\r
public void hintRemoved(IHintObservable sender, Key key, Object oldValue) {\r
\r
\r
@Override\r
public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) {\r
- if(key == SysdynElementHints.KEY_HOVER) {\r
+ if(key == ElementHints.KEY_HOVER) {\r
IElement e = (IElement)sender;\r
- HoverTextNode name = (HoverTextNode) e.getHint(SG_NODE);\r
- name.setHover(SysdynElementUtils.isHovering(e));\r
+ TextNode name = (TextNode) e.getHint(SG_NODE);\r
+ name.setHover(ElementUtils.isHovering(e));\r
}\r
}\r
};\r
- \r
e.addHintListener(hoverHintListener);\r
}\r
-\r
- @Override\r
- public void cleanup(IElement e) {\r
- ElementUtils.removePossibleNode(e, SG_NODE);\r
- e.removeHintListener(hoverHintListener);\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
}
\ No newline at end of file
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
import org.simantics.g2d.element.handler.InternalSize;\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.HoverImpl;\r
import org.simantics.g2d.element.handler.impl.ObjectTerminal;\r
import org.simantics.g2d.element.handler.impl.OutlinePick;\r
import org.simantics.g2d.element.handler.impl.SimpleElementLayers;\r
Input.INSTANCE,\r
new InputSceneGraph(0, 0, Alignment.LEADING),\r
BoundsOutline.INSTANCE,\r
- HoverHandler.INSTANCE,\r
+ HoverImpl.INSTANCE,\r
new WholeElementTerminals(terminals)\r
).setId(InputFactory.class.getSimpleName());\r
}\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
+import org.simantics.g2d.element.handler.impl.HoverImpl;\r
import org.simantics.g2d.element.handler.impl.ObjectTerminal;\r
import org.simantics.g2d.element.handler.impl.OutlinePick;\r
import org.simantics.g2d.element.handler.impl.SimpleElementLayers;\r
new StaticObjectAdapter(elementType),\r
new StaticSymbolImpl(DEFAULT_IMAGE),\r
StaticSymbolImageInitializer.INSTANCE,\r
- new HoverTextElementHandler(0, 0, Alignment.LEADING, 1f),\r
+ new HoverTextElementHandler(0, 0, Alignment.LEADING, 0.2f),\r
BoundsOutline.INSTANCE,\r
- HoverHandler.INSTANCE,\r
+ HoverImpl.INSTANCE,\r
new WholeElementTerminals(terminals)\r
).setId(ModuleFactory.class.getSimpleName());\r
}\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
+import org.simantics.g2d.element.handler.impl.HoverImpl;\r
import org.simantics.g2d.element.handler.impl.ObjectTerminal;\r
import org.simantics.g2d.element.handler.impl.OutlinePick;\r
import org.simantics.g2d.element.handler.impl.SimpleElementLayers;\r
new StaticObjectAdapter(elementType),\r
new StaticSymbolImpl(DEFAULT_IMAGE),\r
StaticSymbolImageInitializer.INSTANCE,\r
- new HoverTextElementHandler(0, 0, Alignment.LEADING, 2f),\r
+ new HoverTextElementHandler(0, 0, Alignment.LEADING, 1f),\r
BoundsOutline.INSTANCE,\r
- HoverHandler.INSTANCE,\r
+ HoverImpl.INSTANCE,\r
new WholeElementTerminals(terminals)\r
).setId(StockFactory.class.getSimpleName());\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
+ ElementUtils.setHover(e, false);\r
}\r
\r
@Override\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
package org.simantics.sysdyn.ui.elements2;\r
\r
-import org.simantics.g2d.element.ElementUtils;\r
import org.simantics.g2d.element.IElement;\r
\r
-public class SysdynElementUtils extends ElementUtils {\r
+public class SysdynElementUtils {\r
\r
\r
public static void setInputReference(IElement e, String inputReference)\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 org.simantics.g2d.element.handler.InternalSize;\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.HoverImpl;\r
import org.simantics.g2d.element.handler.impl.ObjectTerminal;\r
import org.simantics.g2d.element.handler.impl.OutlinePick;\r
import org.simantics.g2d.element.handler.impl.SimpleElementLayers;\r
new StaticObjectAdapter(elementType),\r
new StaticSymbolImpl(VALVE_STATIC_IMAGE),\r
StaticSymbolImageInitializer.INSTANCE,\r
- HoverHandler.INSTANCE,\r
+ HoverImpl.INSTANCE,\r
ValveSceneGraph.INSTANCE,\r
BoundsOutline.INSTANCE,\r
new WholeElementTerminals(terminals)\r
public static final ValveSceneGraph INSTANCE = new ValveSceneGraph();\r
\r
private static final Key NODE = new SceneGraphNodeKey(ShapeNode.class, "VALVE_NODE");\r
+ \r
+ private IHintListener hoverHintListener;\r
\r
public ValveSceneGraph() {\r
super(0, VALVE_SIZE + 3.0, Alignment.CENTER);\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
+ node.setHover(ElementUtils.isHovering(e));\r
\r
- e.addHintListener(new IHintListener() {\r
+ hoverHintListener = new IHintListener() {\r
\r
@Override\r
public void hintRemoved(IHintObservable sender, Key key, Object oldValue) {\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
+ boolean hover = ElementUtils.isHovering(e);\r
shape.setHover(hover);\r
// name.setHover(hover);\r
}\r
- });\r
+ };\r
+ e.addHintListener(hoverHintListener);\r
}\r
\r
@Override\r
public void cleanup(IElement e) {\r
+ e.removeHintListener(hoverHintListener);\r
ElementUtils.removePossibleNode(e, NODE);\r
}\r
\r