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.Point2D;
10 import java.awt.geom.Rectangle2D;
12 import org.simantics.district.network.ModelledCRS;
13 import org.simantics.district.network.ui.adapters.DistrictNetworkVertex;
14 import org.simantics.scenegraph.g2d.G2DNode;
15 import org.simantics.scenegraph.utils.GeometryUtils;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 public class DistrictNetworkVertexNode extends G2DNode {
21 private static final Logger LOGGER = LoggerFactory.getLogger(DistrictNetworkVertexNode.class);
23 private static final long serialVersionUID = -2641639101400236719L;
24 private DistrictNetworkVertex vertex;
26 private static final double left = -0.5;
27 private static final double top = -0.5;
28 private static final double width = 1;
29 private static final double height = 1;
31 private static final Rectangle2D NORMAL = new Rectangle2D.Double(left, top, width, height);
32 private static final Rectangle2D HOVERED = new Rectangle2D.Double(left * 3, top * 3, width * 3, height * 3);
34 private Stroke stroke = new BasicStroke(2);
35 private boolean scaleStroke = true;
36 private boolean hover;
46 public void render(Graphics2D g2d) {
47 AffineTransform ot = null;
48 AffineTransform t = getTransform();
49 if (t != null && !t.isIdentity()) {
50 ot = g2d.getTransform();
51 g2d.transform(getTransform());
54 Object aaHint = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
55 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
57 Color oldColor = g2d.getColor();
58 Stroke oldStroke = g2d.getStroke();
62 double scaleRecip = 1;
64 double scale = GeometryUtils.getScale(g2d.getTransform());
66 //System.out.println("scale: " + scale);
67 scaleRecip = 1.0 / scale;
69 scaleRecip = 8.0 * scaleRecip;
73 toDraw = new Rectangle2D.Double(HOVERED.getX() * scaleRecip, HOVERED.getY() * scaleRecip, HOVERED.getWidth() * scaleRecip, HOVERED.getHeight() * scaleRecip);
75 toDraw = new Rectangle2D.Double(NORMAL.getX() * scaleRecip, NORMAL.getY() * scaleRecip, NORMAL.getWidth() * scaleRecip, NORMAL.getHeight() * scaleRecip);
81 g2d.setColor(oldColor);
82 g2d.setStroke(oldStroke);
84 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aaHint);
91 public Rectangle2D getBoundsInLocal() {
97 public void setVertex(DistrictNetworkVertex vertex) {
101 public boolean hover(boolean hover) {
102 // if (hover && LOGGER.isDebugEnabled())
103 // LOGGER.debug("Hovering " + this);
104 boolean changed = false;
105 if (this.hover != hover) {
112 public void setColor(Color color) {
116 public Color getColor() {