1 package org.simantics.district.network.ui.nodes;
\r
3 import java.awt.BasicStroke;
\r
4 import java.awt.Color;
\r
5 import java.awt.Graphics2D;
\r
6 import java.awt.RenderingHints;
\r
7 import java.awt.Shape;
\r
8 import java.awt.Stroke;
\r
9 import java.awt.geom.AffineTransform;
\r
10 import java.awt.geom.Path2D;
\r
11 import java.awt.geom.Rectangle2D;
\r
13 import org.simantics.district.network.ui.DistrictNetworkEdge;
\r
14 import org.simantics.scenegraph.g2d.G2DNode;
\r
15 import org.simantics.scenegraph.utils.NodeUtil;
\r
17 public class DistrictNetworkEdgeNode extends G2DNode {
\r
19 private static final long serialVersionUID = 8049769475036519806L;
\r
21 private static final Stroke SELECTION_STROKE = new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
\r
22 private static final Color SELECTION_COLOR = new Color(255, 0, 255, 96);
\r
24 private DistrictNetworkEdge edge;
\r
25 private Rectangle2D bounds;
\r
28 public void render(Graphics2D g2d) {
\r
30 AffineTransform ot = null;
\r
31 AffineTransform t = getTransform();
\r
32 if (t != null && !t.isIdentity()) {
\r
33 ot = g2d.getTransform();
\r
34 g2d.transform(getTransform());
\r
37 Object aaHint = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
\r
38 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
\r
40 Color oldColor = g2d.getColor();
\r
41 boolean selected = isSelected();
\r
43 Path2D selectionPath = edge.getPath();
\r
44 Shape selectionShape = SELECTION_STROKE.createStrokedShape(selectionPath);
\r
45 g2d.setColor(SELECTION_COLOR);
\r
46 g2d.fill(selectionShape);
\r
49 g2d.setColor(Color.BLUE);
\r
51 g2d.draw(edge.getPath());
\r
54 g2d.setColor(oldColor);
\r
55 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aaHint);
\r
58 g2d.setTransform(ot);
\r
61 private boolean isSelected() {
\r
62 return NodeUtil.isSelected(this, 1);
\r
66 public Rectangle2D getBoundsInLocal() {
\r
70 private void updateBounds() {
\r
71 Rectangle2D oldBounds = bounds;
\r
72 if (oldBounds == null)
\r
73 oldBounds = new Rectangle2D.Double();
\r
74 bounds = calculateBounds(oldBounds);
\r
77 private Rectangle2D calculateBounds(Rectangle2D rect) {
\r
78 return edge.getBounds(rect);
\r
81 public void setDNEdge(DistrictNetworkEdge edge) {
\r