import org.simantics.g2d.elementclass.connection.EdgeClass.EdgeHandler;\r
import org.simantics.g2d.elementclass.connection.EdgeClass.FixedTransform;\r
import org.simantics.scenegraph.g2d.G2DParentNode;\r
+import org.simantics.scenegraph.utils.NodeUtil;\r
import org.simantics.utils.datastructures.Callback;\r
import org.simantics.utils.datastructures.Pair;\r
import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
return false;\r
}\r
\r
- return Arcs.hitTest(node.beginBounds, node.endBounds, node.angle, pickRect.getCenterX(), pickRect.getCenterY(), 3.0);\r
+ return Arcs.hitTest(node.getBeginBounds(), node.getEndBounds(), node.getAngle(), pickRect.getCenterX(), pickRect.getCenterY(), 3.0);\r
\r
}\r
\r
\r
if(beginTerminalShape == null || endTerminalShape == null) return;\r
\r
- node.setProperty("beginBounds", beginTerminalShape.getBounds2D());\r
- node.setProperty("endBounds", endTerminalShape.getBounds2D());\r
- node.setProperty("stroke", stroke);\r
- node.setProperty("color", c);\r
- node.setProperty("angle", 0.1);\r
+ node.setBeginBounds(beginTerminalShape.getBounds2D());\r
+ node.setEndBounds(endTerminalShape.getBounds2D());\r
+ node.setStroke(stroke);\r
+ node.setColor(c);\r
+ node.setAngle(0.1);\r
\r
Map<String, Pair<Resource, Object>> properties = e.getHint(DiagramHints.PROPERTIES);\r
if(properties != null) {\r
for(Map.Entry<String, Pair<Resource, Object>> entry : properties.entrySet()) {\r
- node.setProperty(entry.getKey(), entry.getValue().second);\r
+ NodeUtil.setPropertyIfSupported(entry.getKey(), entry.getValue().second, node); \r
+// node.setProperty(entry.getKey(), entry.getValue().second);\r
// System.out.println("setProperty " + entry.getKey() + " => " + entry.getValue().second);\r
}\r
}\r
\r
- Pair<Shape, Shape> shapes = Dependencies.createArrowShape(beginTerminalShape.getBounds2D(), endTerminalShape.getBounds2D(), node.angle);\r
+ Pair<Shape, Shape> shapes = Dependencies.createArrowShape(beginTerminalShape.getBounds2D(), endTerminalShape.getBounds2D(), node.getAngle());\r
EdgeHandler eh = e.getElementClass().getAtMostOneItemOfClass(EdgeHandler.class);\r
Path2D path = new Path2D.Double(shapes.first);\r
eh.setPath(e, path);\r
package org.simantics.sysdyn.ui.elements2.connections;\r
\r
+import java.awt.AWTEvent;\r
import java.awt.BasicStroke;\r
import java.awt.Color;\r
import java.awt.Graphics2D;\r
import java.awt.RenderingHints;\r
import java.awt.Shape;\r
import java.awt.Stroke;\r
+import java.awt.event.MouseEvent;\r
import java.awt.geom.Rectangle2D;\r
+import java.beans.PropertyChangeEvent;\r
+import java.beans.PropertyChangeListener;\r
\r
import org.simantics.scenegraph.ISelectionPainterNode;\r
+import org.simantics.scenegraph.g2d.G2DNode;\r
import org.simantics.scenegraph.g2d.events.SGMouseEvent;\r
import org.simantics.scenegraph.utils.NodeUtil;\r
-import org.simantics.sysdyn.ui.elements2.GraphPropertyNode;\r
import org.simantics.utils.datastructures.Pair;\r
\r
-public class DependencyNode extends GraphPropertyNode implements ISelectionPainterNode {\r
+public class DependencyNode extends G2DNode implements ISelectionPainterNode {\r
\r
private static final long serialVersionUID = 1294351381209071074L;\r
\r
- public Color color;\r
- public Stroke stroke;\r
- public Rectangle2D beginBounds;\r
- public Rectangle2D endBounds;\r
- public double angle = 0.1;\r
+ private Color color;\r
+ private Stroke stroke;\r
+ private Rectangle2D beginBounds;\r
+ private Rectangle2D endBounds;\r
+ private double angle = 0.1;\r
\r
transient public boolean hover = false;\r
\r
+ private transient PropertyChangeListener fieldListener = null;\r
+ \r
+ public void setFieldListener(PropertyChangeListener listener) {\r
+ this.fieldListener = listener;\r
+ }\r
+ \r
+ @ServerSide\r
+ public void commitProperty(String field, Object value) {\r
+ if(fieldListener != null) {\r
+ fieldListener.propertyChange(new PropertyChangeEvent(this, field, null, value));\r
+ }\r
+ }\r
+\r
+ @PropertySetter("color")\r
+ @SyncField("color")\r
+ public void setColor(Color color) {\r
+ this.color = color;\r
+ }\r
+ \r
+ @PropertySetter("stroke")\r
+ @SyncField("stroke")\r
+ public void setStroke(Stroke stroke) {\r
+ this.stroke = stroke;\r
+ }\r
+ \r
+ @PropertySetter("beginBounds")\r
+ @SyncField("beginBounds")\r
+ public void setBeginBounds(Rectangle2D beginBounds) {\r
+ this.beginBounds = beginBounds;\r
+ }\r
+ \r
+ @PropertySetter("endBounds")\r
+ @SyncField("endBounds")\r
+ public void setEndBounds(Rectangle2D endBounds) {\r
+ this.endBounds = endBounds;\r
+ }\r
+ \r
+ @PropertySetter("angle")\r
+ @SyncField("angle")\r
+ public void setAngle(Double angle) {\r
+ this.angle = angle.doubleValue();\r
+ }\r
+ \r
+ public Color getColor() {\r
+ return color;\r
+ }\r
+ \r
+ public Stroke getStroke() {\r
+ return stroke;\r
+ }\r
+ \r
+ public Rectangle2D getBeginBounds() {\r
+ return beginBounds;\r
+ }\r
+ \r
+ public Rectangle2D getEndBounds() {\r
+ return endBounds;\r
+ }\r
+ \r
+ public double getAngle() {\r
+ return angle;\r
+ }\r
+ \r
@Override\r
public void render(Graphics2D g) {\r
-\r
+ if(beginBounds == null || endBounds == null) return;\r
+ \r
// NICENESS\r
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);\r
-\r
-// System.out.println("dep " + angle + " " + beginBounds + " " + endBounds);\r
\r
Pair<Shape, Shape> shapes = Dependencies.createArrowShape(beginBounds, endBounds, angle);\r
\r
}\r
\r
}\r
+ \r
+ boolean pressHit = false;\r
+\r
+ @Override\r
+ public void handleEvent(AWTEvent event) {\r
+ if(event instanceof SGMouseEvent) {\r
+ SGMouseEvent e = (SGMouseEvent)event;\r
+ boolean hit = hitTest(e.getDoubleX(), e.getDoubleY(), 3.0);\r
+ if(e.getID() == MouseEvent.MOUSE_DRAGGED) {\r
+ mouseDragged((SGMouseEvent)event, pressHit, hit);\r
+ }\r
+ if(e.getID() == MouseEvent.MOUSE_PRESSED) {\r
+ pressHit = hit;\r
+ mouseReleased((SGMouseEvent)event, hit);\r
+ }\r
+ if(e.getID() == MouseEvent.MOUSE_RELEASED)\r
+ mouseReleased((SGMouseEvent)event, hit);\r
+ if(e.getID() == MouseEvent.MOUSE_MOVED)\r
+ mouseMoved((SGMouseEvent)event, hit);\r
+ }\r
+ }\r
\r
- @Override\r
public boolean hitTest(double x, double y, double tolerance) {\r
+ if(beginBounds == null || endBounds == null) return false;\r
+\r
return Arcs.hitTest(beginBounds, endBounds, angle, x, y, tolerance);\r
}\r
\r
- @Override\r
public void mouseDragged(SGMouseEvent event, boolean pressHit, boolean currentHit) {\r
\r
if(!pressHit) return;\r
\r
- angle = Arcs.angleOfArc(\r
+ setAngle(Arcs.angleOfArc(\r
beginBounds.getCenterX(), beginBounds.getCenterY(), \r
event.getDoubleX(), event.getDoubleY(), \r
- endBounds.getCenterX(), endBounds.getCenterY());\r
- \r
+ endBounds.getCenterX(), endBounds.getCenterY()));\r
}\r
- \r
- @Override\r
+\r
public void mouseReleased(SGMouseEvent event, boolean hit) {\r
- if(hit) commitProperty("angle", angle);\r
+ if(hit) {\r
+ commitProperty("angle", angle);\r
+ }\r
}\r
- \r
- @Override\r
+\r
public void mouseMoved(SGMouseEvent event, boolean hit) {\r
if(hit != hover) {\r
hover = hit;\r
}\r
}\r
\r
+ @Override\r
+ public Rectangle2D getBoundsInLocal() {\r
+ return null;\r
+ }\r
+\r
}\r
import org.simantics.g2d.elementclass.connection.EdgeClass.EdgeHandler;\r
import org.simantics.g2d.elementclass.connection.EdgeClass.FixedTransform;\r
import org.simantics.scenegraph.g2d.G2DParentNode;\r
+import org.simantics.scenegraph.utils.NodeUtil;\r
import org.simantics.sysdyn.ui.elements2.ValveFactory.ValveSceneGraph;\r
import org.simantics.utils.datastructures.Callback;\r
import org.simantics.utils.datastructures.Pair;\r
\r
final IDiagram diagram = ElementUtils.peekDiagram(e);\r
\r
- node.setFieldListener(new PropertyChangeListener() {\r
-\r
- @Override\r
- public void propertyChange(final PropertyChangeEvent event) {\r
- \r
- DiagramUtils.mutateDiagram(diagram, new Callback<DiagramMutator>() {\r
- \r
- @Override\r
- public void run(DiagramMutator mutator) {\r
-\r
- String field = event.getPropertyName();\r
- Map<String, Pair<Resource, Object>> properties = e.getHint(DiagramHints.PROPERTIES);\r
- Pair<Resource, Object> property = properties.get(field);\r
- \r
- mutator.modifyProperty(e, property.first, event.getNewValue());\r
- \r
- }\r
- \r
- });\r
- \r
- }\r
- \r
- });\r
+ // Flownode does not change any property, hence listener is not needed\r
+// node.setFieldListener(new PropertyChangeListener() {\r
+//\r
+// @Override\r
+// public void propertyChange(final PropertyChangeEvent event) {\r
+// \r
+// DiagramUtils.mutateDiagram(diagram, new Callback<DiagramMutator>() {\r
+// \r
+// @Override\r
+// public void run(DiagramMutator mutator) {\r
+//\r
+// String field = event.getPropertyName();\r
+// Map<String, Pair<Resource, Object>> properties = e.getHint(DiagramHints.PROPERTIES);\r
+// Pair<Resource, Object> property = properties.get(field);\r
+// \r
+// mutator.modifyProperty(e, property.first, event.getNewValue());\r
+// \r
+// }\r
+// \r
+// });\r
+// \r
+// }\r
+// \r
+// });\r
\r
Stroke stroke = new BasicStroke(0.1f);\r
Color c = ElementUtils.getFillColor(e, Color.BLACK);\r
\r
if(beginTerminalShape == null || endTerminalShape == null) return;\r
\r
- node.setProperty("beginBounds", beginTerminalShape.getBounds2D());\r
- node.setProperty("endBounds", endTerminalShape.getBounds2D());\r
- node.setProperty("stroke", stroke);\r
- node.setProperty("color", c);\r
- node.setProperty("toValve", toValve);\r
+ node.setBeginBounds(beginTerminalShape.getBounds2D());\r
+ node.setEndBounds(endTerminalShape.getBounds2D());\r
+ node.setStroke(stroke);\r
+ node.setColor(c);\r
+ node.setToValve(toValve);\r
// System.out.println("set toValve = " + toValve);\r
- node.toValve = toValve;\r
\r
Map<String, Pair<Resource, Object>> properties = e.getHint(DiagramHints.PROPERTIES);\r
if(properties != null) {\r
for(Map.Entry<String, Pair<Resource, Object>> entry : properties.entrySet()) {\r
- node.setProperty(entry.getKey(), entry.getValue().second);\r
+ NodeUtil.setPropertyIfSupported(entry.getKey(), entry.getValue().second, node); \r
+// node.setProperty(entry.getKey(), entry.getValue().second);\r
}\r
}\r
\r
import java.awt.geom.Rectangle2D;\r
\r
import org.simantics.scenegraph.ISelectionPainterNode;\r
+import org.simantics.scenegraph.INode.PropertySetter;\r
+import org.simantics.scenegraph.g2d.G2DNode;\r
import org.simantics.scenegraph.utils.NodeUtil;\r
-import org.simantics.sysdyn.ui.elements2.GraphPropertyNode;\r
import org.simantics.utils.datastructures.Pair;\r
\r
-public class FlowNode extends GraphPropertyNode implements ISelectionPainterNode {\r
+public class FlowNode extends G2DNode implements ISelectionPainterNode {\r
\r
private static final long serialVersionUID = 328942356917631237L;\r
\r
- public Color color;\r
- public Stroke stroke;\r
- public Rectangle2D beginBounds;\r
- public Rectangle2D endBounds;\r
- public Boolean toValve;\r
+ private Color color;\r
+ private Stroke stroke;\r
+ private Rectangle2D beginBounds;\r
+ private Rectangle2D endBounds;\r
+ private Boolean toValve;\r
\r
+ @PropertySetter("color")\r
+ @SyncField("color")\r
+ public void setColor(Color color) {\r
+ this.color = color;\r
+ }\r
+ \r
+ @PropertySetter("stroke")\r
+ @SyncField("stroke")\r
+ public void setStroke(Stroke stroke) {\r
+ this.stroke = stroke;\r
+ }\r
+ \r
+ @PropertySetter("beginBounds")\r
+ @SyncField("beginBounds")\r
+ public void setBeginBounds(Rectangle2D beginBounds) {\r
+ this.beginBounds = beginBounds;\r
+ }\r
+ \r
+ @PropertySetter("endBounds")\r
+ @SyncField("endBounds")\r
+ public void setEndBounds(Rectangle2D endBounds) {\r
+ this.endBounds = endBounds;\r
+ }\r
+ \r
+ @PropertySetter("toValve")\r
+ @SyncField("toValve")\r
+ public void setToValve(Boolean toValve) {\r
+ this.toValve = toValve;\r
+ }\r
+ \r
+ public Color getColor() {\r
+ return color;\r
+ }\r
+ \r
+ public Stroke getStroke() {\r
+ return stroke;\r
+ }\r
+ \r
+ public Rectangle2D getBeginBounds() {\r
+ return beginBounds;\r
+ }\r
+ \r
+ public Rectangle2D getEndBounds() {\r
+ return endBounds;\r
+ }\r
+ \r
+ public Boolean getBoolean() {\r
+ return toValve;\r
+ }\r
+ \r
@Override\r
public void render(Graphics2D g) {\r
\r
\r
\r
}\r
-\r
+ \r
+ @Override\r
+ public Rectangle2D getBoundsInLocal() {\r
+ return null;\r
+ }\r
}\r