From 77773765645b11ceeac5137a3a9a0ac2ca0eb7ac Mon Sep 17 00:00:00 2001 From: jplaine Date: Tue, 12 Oct 2010 09:55:06 +0000 Subject: [PATCH] SceneGraph nodes changed to use setter methods and PropertySetter annotations instead of functionalities from GraphPropertyNode. git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@18384 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../connections/DependencyEdgeClass.java | 18 +-- .../elements2/connections/DependencyNode.java | 131 +++++++++++++++--- .../elements2/connections/FlowEdgeClass.java | 62 +++++---- .../ui/elements2/connections/FlowNode.java | 71 ++++++++-- 4 files changed, 216 insertions(+), 66 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyEdgeClass.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyEdgeClass.java index 140bd0df..e3d4dd29 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyEdgeClass.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyEdgeClass.java @@ -47,6 +47,7 @@ import org.simantics.g2d.element.handler.impl.SimpleElementLayers; import org.simantics.g2d.elementclass.connection.EdgeClass.EdgeHandler; import org.simantics.g2d.elementclass.connection.EdgeClass.FixedTransform; import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.scenegraph.utils.NodeUtil; import org.simantics.utils.datastructures.Callback; import org.simantics.utils.datastructures.Pair; import org.simantics.utils.datastructures.hints.IHintContext.Key; @@ -72,7 +73,7 @@ public class DependencyEdgeClass { return false; } - return Arcs.hitTest(node.beginBounds, node.endBounds, node.angle, pickRect.getCenterX(), pickRect.getCenterY(), 3.0); + return Arcs.hitTest(node.getBeginBounds(), node.getEndBounds(), node.getAngle(), pickRect.getCenterX(), pickRect.getCenterY(), 3.0); } @@ -162,21 +163,22 @@ public class DependencyEdgeClass { if(beginTerminalShape == null || endTerminalShape == null) return; - node.setProperty("beginBounds", beginTerminalShape.getBounds2D()); - node.setProperty("endBounds", endTerminalShape.getBounds2D()); - node.setProperty("stroke", stroke); - node.setProperty("color", c); - node.setProperty("angle", 0.1); + node.setBeginBounds(beginTerminalShape.getBounds2D()); + node.setEndBounds(endTerminalShape.getBounds2D()); + node.setStroke(stroke); + node.setColor(c); + node.setAngle(0.1); Map> properties = e.getHint(DiagramHints.PROPERTIES); if(properties != null) { for(Map.Entry> entry : properties.entrySet()) { - node.setProperty(entry.getKey(), entry.getValue().second); + NodeUtil.setPropertyIfSupported(entry.getKey(), entry.getValue().second, node); +// node.setProperty(entry.getKey(), entry.getValue().second); // System.out.println("setProperty " + entry.getKey() + " => " + entry.getValue().second); } } - Pair shapes = Dependencies.createArrowShape(beginTerminalShape.getBounds2D(), endTerminalShape.getBounds2D(), node.angle); + Pair shapes = Dependencies.createArrowShape(beginTerminalShape.getBounds2D(), endTerminalShape.getBounds2D(), node.getAngle()); EdgeHandler eh = e.getElementClass().getAtMostOneItemOfClass(EdgeHandler.class); Path2D path = new Path2D.Double(shapes.first); eh.setPath(e, path); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyNode.java index a2a24a90..8da1a055 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/DependencyNode.java @@ -1,38 +1,104 @@ package org.simantics.sysdyn.ui.elements2.connections; +import java.awt.AWTEvent; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.Shape; import java.awt.Stroke; +import java.awt.event.MouseEvent; import java.awt.geom.Rectangle2D; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import org.simantics.scenegraph.ISelectionPainterNode; +import org.simantics.scenegraph.g2d.G2DNode; import org.simantics.scenegraph.g2d.events.SGMouseEvent; import org.simantics.scenegraph.utils.NodeUtil; -import org.simantics.sysdyn.ui.elements2.GraphPropertyNode; import org.simantics.utils.datastructures.Pair; -public class DependencyNode extends GraphPropertyNode implements ISelectionPainterNode { +public class DependencyNode extends G2DNode implements ISelectionPainterNode { private static final long serialVersionUID = 1294351381209071074L; - public Color color; - public Stroke stroke; - public Rectangle2D beginBounds; - public Rectangle2D endBounds; - public double angle = 0.1; + private Color color; + private Stroke stroke; + private Rectangle2D beginBounds; + private Rectangle2D endBounds; + private double angle = 0.1; transient public boolean hover = false; + private transient PropertyChangeListener fieldListener = null; + + public void setFieldListener(PropertyChangeListener listener) { + this.fieldListener = listener; + } + + @ServerSide + public void commitProperty(String field, Object value) { + if(fieldListener != null) { + fieldListener.propertyChange(new PropertyChangeEvent(this, field, null, value)); + } + } + + @PropertySetter("color") + @SyncField("color") + public void setColor(Color color) { + this.color = color; + } + + @PropertySetter("stroke") + @SyncField("stroke") + public void setStroke(Stroke stroke) { + this.stroke = stroke; + } + + @PropertySetter("beginBounds") + @SyncField("beginBounds") + public void setBeginBounds(Rectangle2D beginBounds) { + this.beginBounds = beginBounds; + } + + @PropertySetter("endBounds") + @SyncField("endBounds") + public void setEndBounds(Rectangle2D endBounds) { + this.endBounds = endBounds; + } + + @PropertySetter("angle") + @SyncField("angle") + public void setAngle(Double angle) { + this.angle = angle.doubleValue(); + } + + public Color getColor() { + return color; + } + + public Stroke getStroke() { + return stroke; + } + + public Rectangle2D getBeginBounds() { + return beginBounds; + } + + public Rectangle2D getEndBounds() { + return endBounds; + } + + public double getAngle() { + return angle; + } + @Override public void render(Graphics2D g) { - + if(beginBounds == null || endBounds == null) return; + // NICENESS g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - -// System.out.println("dep " + angle + " " + beginBounds + " " + endBounds); Pair shapes = Dependencies.createArrowShape(beginBounds, endBounds, angle); @@ -63,30 +129,50 @@ public class DependencyNode extends GraphPropertyNode implements ISelectionPaint } } + + boolean pressHit = false; + + @Override + public void handleEvent(AWTEvent event) { + if(event instanceof SGMouseEvent) { + SGMouseEvent e = (SGMouseEvent)event; + boolean hit = hitTest(e.getDoubleX(), e.getDoubleY(), 3.0); + if(e.getID() == MouseEvent.MOUSE_DRAGGED) { + mouseDragged((SGMouseEvent)event, pressHit, hit); + } + if(e.getID() == MouseEvent.MOUSE_PRESSED) { + pressHit = hit; + mouseReleased((SGMouseEvent)event, hit); + } + if(e.getID() == MouseEvent.MOUSE_RELEASED) + mouseReleased((SGMouseEvent)event, hit); + if(e.getID() == MouseEvent.MOUSE_MOVED) + mouseMoved((SGMouseEvent)event, hit); + } + } - @Override public boolean hitTest(double x, double y, double tolerance) { + if(beginBounds == null || endBounds == null) return false; + return Arcs.hitTest(beginBounds, endBounds, angle, x, y, tolerance); } - @Override public void mouseDragged(SGMouseEvent event, boolean pressHit, boolean currentHit) { if(!pressHit) return; - angle = Arcs.angleOfArc( + setAngle(Arcs.angleOfArc( beginBounds.getCenterX(), beginBounds.getCenterY(), event.getDoubleX(), event.getDoubleY(), - endBounds.getCenterX(), endBounds.getCenterY()); - + endBounds.getCenterX(), endBounds.getCenterY())); } - - @Override + public void mouseReleased(SGMouseEvent event, boolean hit) { - if(hit) commitProperty("angle", angle); + if(hit) { + commitProperty("angle", angle); + } } - - @Override + public void mouseMoved(SGMouseEvent event, boolean hit) { if(hit != hover) { hover = hit; @@ -94,4 +180,9 @@ public class DependencyNode extends GraphPropertyNode implements ISelectionPaint } } + @Override + public Rectangle2D getBoundsInLocal() { + return null; + } + } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowEdgeClass.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowEdgeClass.java index 66874597..171a7e51 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowEdgeClass.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowEdgeClass.java @@ -43,6 +43,7 @@ import org.simantics.g2d.element.handler.impl.SimpleElementLayers; import org.simantics.g2d.elementclass.connection.EdgeClass.EdgeHandler; import org.simantics.g2d.elementclass.connection.EdgeClass.FixedTransform; import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.scenegraph.utils.NodeUtil; import org.simantics.sysdyn.ui.elements2.ValveFactory.ValveSceneGraph; import org.simantics.utils.datastructures.Callback; import org.simantics.utils.datastructures.Pair; @@ -95,29 +96,30 @@ public class FlowEdgeClass { final IDiagram diagram = ElementUtils.peekDiagram(e); - node.setFieldListener(new PropertyChangeListener() { - - @Override - public void propertyChange(final PropertyChangeEvent event) { - - DiagramUtils.mutateDiagram(diagram, new Callback() { - - @Override - public void run(DiagramMutator mutator) { - - String field = event.getPropertyName(); - Map> properties = e.getHint(DiagramHints.PROPERTIES); - Pair property = properties.get(field); - - mutator.modifyProperty(e, property.first, event.getNewValue()); - - } - - }); - - } - - }); + // Flownode does not change any property, hence listener is not needed +// node.setFieldListener(new PropertyChangeListener() { +// +// @Override +// public void propertyChange(final PropertyChangeEvent event) { +// +// DiagramUtils.mutateDiagram(diagram, new Callback() { +// +// @Override +// public void run(DiagramMutator mutator) { +// +// String field = event.getPropertyName(); +// Map> properties = e.getHint(DiagramHints.PROPERTIES); +// Pair property = properties.get(field); +// +// mutator.modifyProperty(e, property.first, event.getNewValue()); +// +// } +// +// }); +// +// } +// +// }); Stroke stroke = new BasicStroke(0.1f); Color c = ElementUtils.getFillColor(e, Color.BLACK); @@ -139,18 +141,18 @@ public class FlowEdgeClass { if(beginTerminalShape == null || endTerminalShape == null) return; - node.setProperty("beginBounds", beginTerminalShape.getBounds2D()); - node.setProperty("endBounds", endTerminalShape.getBounds2D()); - node.setProperty("stroke", stroke); - node.setProperty("color", c); - node.setProperty("toValve", toValve); + node.setBeginBounds(beginTerminalShape.getBounds2D()); + node.setEndBounds(endTerminalShape.getBounds2D()); + node.setStroke(stroke); + node.setColor(c); + node.setToValve(toValve); // System.out.println("set toValve = " + toValve); - node.toValve = toValve; Map> properties = e.getHint(DiagramHints.PROPERTIES); if(properties != null) { for(Map.Entry> entry : properties.entrySet()) { - node.setProperty(entry.getKey(), entry.getValue().second); + NodeUtil.setPropertyIfSupported(entry.getKey(), entry.getValue().second, node); +// node.setProperty(entry.getKey(), entry.getValue().second); } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowNode.java index 4b307b43..86befcba 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowNode.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/connections/FlowNode.java @@ -9,20 +9,71 @@ import java.awt.Stroke; import java.awt.geom.Rectangle2D; import org.simantics.scenegraph.ISelectionPainterNode; +import org.simantics.scenegraph.INode.PropertySetter; +import org.simantics.scenegraph.g2d.G2DNode; import org.simantics.scenegraph.utils.NodeUtil; -import org.simantics.sysdyn.ui.elements2.GraphPropertyNode; import org.simantics.utils.datastructures.Pair; -public class FlowNode extends GraphPropertyNode implements ISelectionPainterNode { +public class FlowNode extends G2DNode implements ISelectionPainterNode { private static final long serialVersionUID = 328942356917631237L; - public Color color; - public Stroke stroke; - public Rectangle2D beginBounds; - public Rectangle2D endBounds; - public Boolean toValve; + private Color color; + private Stroke stroke; + private Rectangle2D beginBounds; + private Rectangle2D endBounds; + private Boolean toValve; + @PropertySetter("color") + @SyncField("color") + public void setColor(Color color) { + this.color = color; + } + + @PropertySetter("stroke") + @SyncField("stroke") + public void setStroke(Stroke stroke) { + this.stroke = stroke; + } + + @PropertySetter("beginBounds") + @SyncField("beginBounds") + public void setBeginBounds(Rectangle2D beginBounds) { + this.beginBounds = beginBounds; + } + + @PropertySetter("endBounds") + @SyncField("endBounds") + public void setEndBounds(Rectangle2D endBounds) { + this.endBounds = endBounds; + } + + @PropertySetter("toValve") + @SyncField("toValve") + public void setToValve(Boolean toValve) { + this.toValve = toValve; + } + + public Color getColor() { + return color; + } + + public Stroke getStroke() { + return stroke; + } + + public Rectangle2D getBeginBounds() { + return beginBounds; + } + + public Rectangle2D getEndBounds() { + return endBounds; + } + + public Boolean getBoolean() { + return toValve; + } + @Override public void render(Graphics2D g) { @@ -72,5 +123,9 @@ public class FlowNode extends GraphPropertyNode implements ISelectionPainterNode } - + + @Override + public Rectangle2D getBoundsInLocal() { + return null; + } } -- 2.47.1