1 package org.simantics.district.network.ui.nodes;
3 import java.awt.BasicStroke;
5 import java.awt.Graphics2D;
6 import java.awt.RenderingHints;
7 import java.awt.Stroke;
8 import java.awt.geom.AffineTransform;
9 import java.awt.geom.Rectangle2D;
11 import org.simantics.district.network.ui.adapters.DistrictNetworkVertex;
12 import org.simantics.scenegraph.g2d.G2DNode;
13 import org.simantics.scenegraph.utils.GeometryUtils;
15 public class DistrictNetworkVertexNode extends G2DNode {
17 private static final long serialVersionUID = -2641639101400236719L;
18 private DistrictNetworkVertex vertex;
20 private static final double scale = 1;
22 private double left = -0.5;
23 private double top = -0.5;
24 private double width = 1;
25 private double height = 1;
27 private Stroke stroke = new BasicStroke(2);
28 private boolean scaleStroke = true;
36 public void render(Graphics2D g2d) {
37 AffineTransform ot = null;
38 AffineTransform t = getTransform();
39 if (t != null && !t.isIdentity()) {
40 ot = g2d.getTransform();
41 g2d.transform(getTransform());
44 Object aaHint = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
45 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
47 Color oldColor = g2d.getColor();
48 Stroke oldStroke = g2d.getStroke();
50 g2d.setColor(Color.RED);
52 if (scaleStroke && stroke instanceof BasicStroke) {
53 BasicStroke bs = GeometryUtils.scaleStroke(stroke, (float) (1.0 / GeometryUtils.getScale(g2d.getTransform())));
56 g2d.setStroke(stroke);
61 Rectangle2D.Double rect = new Rectangle2D.Double(left / scale, top / scale, width / scale, height / scale);
65 g2d.setColor(oldColor);
66 g2d.setStroke(oldStroke);
68 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aaHint);
75 public Rectangle2D getBoundsInLocal() {
76 return new Rectangle2D.Double(left / scale, top / scale, width / scale, height / scale);
79 public void setVertex(DistrictNetworkVertex vertex) {