From b8bd6b51acc64e31899db005518b7d7953dc26ec Mon Sep 17 00:00:00 2001 From: lehtonen Date: Tue, 21 Dec 2010 15:00:53 +0000 Subject: [PATCH] Removed AA-setting from FlowNode/DependencyNode to keep interaction performance tolerable. git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@19189 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../elements2/connections/DependencyNode.java | 255 +++++++++--------- .../ui/elements2/connections/FlowNode.java | 85 +++--- 2 files changed, 169 insertions(+), 171 deletions(-) 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 66a5f1ca..03fdf329 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 @@ -14,7 +14,6 @@ package org.simantics.sysdyn.ui.elements2.connections; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; -import java.awt.RenderingHints; import java.awt.Stroke; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; @@ -43,18 +42,18 @@ public class DependencyNode extends G2DNode implements ISelectionPainterNode, Mo private Rectangle2D endBounds; private double angle = 0.1; private transient Pair shapes = new Pair(new Arc2D.Double(), new Path2D.Double()); - + transient public boolean hover = false; - - private transient PropertyChangeListener fieldListener = null; - + + private transient PropertyChangeListener fieldListener = null; + @Override public void init() { super.init(); NodeUtil.getEventDelegator(this).addMouseListener(this); NodeUtil.getEventDelegator(this).addMouseMotionListener(this); } - + @Override public void cleanup() { NodeUtil.getEventDelegator(this).removeMouseListener(this); @@ -62,174 +61,174 @@ public class DependencyNode extends G2DNode implements ISelectionPainterNode, Mo super.cleanup(); } - public void setFieldListener(PropertyChangeListener listener) { - this.fieldListener = listener; - } - - @ServerSide - public void commitProperty(String field, Object value) { + 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)); + fieldListener.propertyChange(new PropertyChangeEvent(this, field, null, value)); } - } + } - @PropertySetter("color") + @PropertySetter("color") @SyncField("color") public void setColor(Color color) { - this.color = color; + this.color = color; } - - @PropertySetter("stroke") + + @PropertySetter("stroke") @SyncField("stroke") public void setStroke(Stroke stroke) { - this.stroke = stroke; + this.stroke = stroke; } - - @PropertySetter("beginBounds") + + @PropertySetter("beginBounds") @SyncField("beginBounds") public void setBeginBounds(Rectangle2D beginBounds) { - this.beginBounds = beginBounds; + this.beginBounds = beginBounds; } - - @PropertySetter("endBounds") + + @PropertySetter("endBounds") @SyncField("endBounds") public void setEndBounds(Rectangle2D endBounds) { - this.endBounds = endBounds; + this.endBounds = endBounds; } - - @PropertySetter("angle") + + @PropertySetter("angle") @SyncField("angle") public void setAngle(Double angle) { - this.angle = angle.doubleValue(); + this.angle = angle.doubleValue(); } - + public Color getColor() { - return color; + return color; } - + public Stroke getStroke() { - return stroke; + return stroke; } - + public Rectangle2D getBeginBounds() { - return beginBounds; + return beginBounds; } - + public Rectangle2D getEndBounds() { - return endBounds; + return endBounds; } - + public double getAngle() { - return angle; + return angle; } - + @Override public void render(Graphics2D g) { - if(beginBounds == null || endBounds == null) return; - - // NICENESS - g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - + if(beginBounds == null || endBounds == null) return; + + // Removed to let the global control handle rendering quality issues. + //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + Dependencies.createArrowShape(shapes, beginBounds, endBounds, angle); - - boolean selected = NodeUtil.isSelected(this, 2); - if(selected) { + + boolean selected = NodeUtil.isSelected(this, 2); + if(selected) { g.setColor(Color.PINK); g.setStroke(STROKE); - g.draw(shapes.first); - g.fill(shapes.second); + g.draw(shapes.first); + g.fill(shapes.second); if(color != null) g.setColor(color); g.setStroke(stroke); - g.draw(shapes.first); - g.fill(shapes.second); - } else if (hover){ + g.draw(shapes.first); + g.fill(shapes.second); + } else if (hover){ g.setColor(Color.LIGHT_GRAY); g.setStroke(STROKE); - g.draw(shapes.first); - g.fill(shapes.second); + g.draw(shapes.first); + g.fill(shapes.second); if(color != null) g.setColor(color); g.setStroke(stroke); - g.draw(shapes.first); - g.fill(shapes.second); - } else { + g.draw(shapes.first); + g.fill(shapes.second); + } else { if(color != null) g.setColor(color); if(stroke != null) g.setStroke(stroke); - g.draw(shapes.first); - g.fill(shapes.second); - } + g.draw(shapes.first); + g.fill(shapes.second); + } } - - boolean pressHit = false; - private boolean hitTest(MouseEvent event, double tolerance) { - if(event instanceof ISGMouseEvent) { - if(beginBounds == null || endBounds == null) return false; + boolean pressHit = false; - return Arcs.hitTest(beginBounds, endBounds, angle, ((ISGMouseEvent)event).getDoubleX(), ((ISGMouseEvent)event).getDoubleY(), tolerance); - } else { - return false; - } - } + private boolean hitTest(MouseEvent event, double tolerance) { + if(event instanceof ISGMouseEvent) { + if(beginBounds == null || endBounds == null) return false; - @Override + return Arcs.hitTest(beginBounds, endBounds, angle, ((ISGMouseEvent)event).getDoubleX(), ((ISGMouseEvent)event).getDoubleY(), tolerance); + } else { + return false; + } + } + + @Override public Rectangle2D getBoundsInLocal() { - return null; - } - - @Override - public void mouseDragged(MouseEvent e) { - if(pressHit && e instanceof ISGMouseEvent) { - setAngle(Arcs.angleOfArc( - beginBounds.getCenterX(), beginBounds.getCenterY(), - ((ISGMouseEvent)e).getDoubleX(), ((ISGMouseEvent)e).getDoubleY(), - endBounds.getCenterX(), endBounds.getCenterY())); - } - } - - @Override - public void mouseMoved(MouseEvent e) { - boolean hit = hitTest(e, 3.0); - if(hit != hover) { - hover = hit; - repaint(); - } - } - - @Override - public void mouseClicked(MouseEvent e) { - // TODO Auto-generated method stub - - } - - @Override - public void mousePressed(MouseEvent e) { - boolean hit = hitTest(e, 3.0); - pressHit = hit; - if(hit) { - commitProperty("angle", angle); - } - - } - - @Override - public void mouseReleased(MouseEvent e) { - boolean hit = hitTest(e, 3.0); - if(hit) { - commitProperty("angle", angle); - } - } - - @Override - public void mouseEntered(MouseEvent e) { - // TODO Auto-generated method stub - - } - - @Override - public void mouseExited(MouseEvent e) { - // TODO Auto-generated method stub - - } + return null; + } + + @Override + public void mouseDragged(MouseEvent e) { + if(pressHit && e instanceof ISGMouseEvent) { + setAngle(Arcs.angleOfArc( + beginBounds.getCenterX(), beginBounds.getCenterY(), + ((ISGMouseEvent)e).getDoubleX(), ((ISGMouseEvent)e).getDoubleY(), + endBounds.getCenterX(), endBounds.getCenterY())); + } + } + + @Override + public void mouseMoved(MouseEvent e) { + boolean hit = hitTest(e, 3.0); + if(hit != hover) { + hover = hit; + repaint(); + } + } + + @Override + public void mouseClicked(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mousePressed(MouseEvent e) { + boolean hit = hitTest(e, 3.0); + pressHit = hit; + if(hit) { + commitProperty("angle", angle); + } + + } + + @Override + public void mouseReleased(MouseEvent e) { + boolean hit = hitTest(e, 3.0); + if(hit) { + commitProperty("angle", angle); + } + } + + @Override + public void mouseEntered(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseExited(MouseEvent e) { + // TODO Auto-generated method stub + + } } 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 70891941..3c5a08f4 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 @@ -14,7 +14,6 @@ package org.simantics.sysdyn.ui.elements2.connections; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; -import java.awt.RenderingHints; import java.awt.Stroke; import java.awt.geom.Path2D; import java.awt.geom.Rectangle2D; @@ -25,7 +24,7 @@ import org.simantics.scenegraph.utils.NodeUtil; public class FlowNode extends G2DNode implements ISelectionPainterNode { - private static final long serialVersionUID = 328942356917631237L; + private static final long serialVersionUID = 328942356917631237L; private static final BasicStroke STROKE = new BasicStroke(1.0f); @@ -36,61 +35,61 @@ public class FlowNode extends G2DNode implements ISelectionPainterNode { private Boolean toValve; private transient Path2D lines; private transient Path2D arrow; - - @PropertySetter("color") + + @PropertySetter("color") @SyncField("color") public void setColor(Color color) { - this.color = color; + this.color = color; } - - @PropertySetter("stroke") + + @PropertySetter("stroke") @SyncField("stroke") public void setStroke(Stroke stroke) { - this.stroke = stroke; + this.stroke = stroke; } - - @PropertySetter("beginBounds") + + @PropertySetter("beginBounds") @SyncField("beginBounds") public void setBeginBounds(Rectangle2D beginBounds) { - this.beginBounds = beginBounds; + this.beginBounds = beginBounds; } - - @PropertySetter("endBounds") + + @PropertySetter("endBounds") @SyncField("endBounds") public void setEndBounds(Rectangle2D endBounds) { - this.endBounds = endBounds; + this.endBounds = endBounds; } - - @PropertySetter("toValve") + + @PropertySetter("toValve") @SyncField("toValve") public void setToValve(Boolean toValve) { - this.toValve = toValve; + this.toValve = toValve; } - + public Color getColor() { - return color; + return color; } - + public Stroke getStroke() { - return stroke; + return stroke; } - + public Rectangle2D getBeginBounds() { - return beginBounds; + return beginBounds; } - + public Rectangle2D getEndBounds() { - return endBounds; + return endBounds; } - + public Boolean getBoolean() { - return toValve; + return toValve; } - + @Override public void render(Graphics2D g) { - // NICENESS - g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + // Removed to let the global control handle rendering quality issues. + //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); /* * There are two cases, first is from Stock|Cloud to Valve and second is from Valve to Stock|Cloud @@ -99,35 +98,35 @@ public class FlowNode extends G2DNode implements ISelectionPainterNode { */ // System.out.println("FlowNode.render toValve = " + toValve); - + if(toValve) { lines = Flows.createLines(lines, false, endBounds, beginBounds); } else { lines = Flows.createLines(lines, true, beginBounds, endBounds); arrow = Flows.createArrow(arrow, beginBounds, endBounds); } - - boolean selected = NodeUtil.isSelected(this, 2); - if(selected) { + + boolean selected = NodeUtil.isSelected(this, 2); + if(selected) { g.setColor(Color.PINK); g.setStroke(STROKE); g.draw(lines); if(color != null) g.setColor(color); g.setStroke(stroke); g.draw(lines); - if(arrow != null) g.fill(arrow); - } else { + if(arrow != null) g.fill(arrow); + } else { if(color != null) g.setColor(color); if(stroke != null) g.setStroke(stroke); g.draw(lines); - if(arrow != null) g.fill(arrow); - } - - + if(arrow != null) g.fill(arrow); + } + + } - - @Override + + @Override public Rectangle2D getBoundsInLocal() { - return null; + return null; } } -- 2.47.1