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;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
17 public class DistrictNetworkVertexNode extends G2DNode {
19 private static final Logger LOGGER = LoggerFactory.getLogger(DistrictNetworkVertexNode.class);
21 private static final long serialVersionUID = -2641639101400236719L;
22 private DistrictNetworkVertex vertex;
24 private static final double left = -0.5;
25 private static final double top = -0.5;
26 private static final double width = 1;
27 private static final double height = 1;
29 private static final Rectangle2D NORMAL = new Rectangle2D.Double(left, top, width, height);
30 private static final Rectangle2D HOVERED = new Rectangle2D.Double(left * 2, top * 2, width * 2, height * 2);
32 private Stroke stroke = new BasicStroke(2);
33 private boolean scaleStroke = true;
34 private boolean hover;
42 public void render(Graphics2D g2d) {
43 AffineTransform ot = null;
44 AffineTransform t = getTransform();
45 if (t != null && !t.isIdentity()) {
46 ot = g2d.getTransform();
47 g2d.transform(getTransform());
50 Object aaHint = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
51 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
53 Color oldColor = g2d.getColor();
54 Stroke oldStroke = g2d.getStroke();
56 g2d.setColor(Color.RED);
58 double scaleRecip = 1;
60 double scale = GeometryUtils.getScale(g2d.getTransform());
62 //System.out.println("scale: " + scale);
63 scaleRecip = 1.0 / scale;
65 scaleRecip = 8.0 * scaleRecip;
69 toDraw = new Rectangle2D.Double(HOVERED.getX() * scaleRecip, HOVERED.getY() * scaleRecip, HOVERED.getWidth() * scaleRecip, HOVERED.getHeight() * scaleRecip);
71 toDraw = new Rectangle2D.Double(NORMAL.getX() * scaleRecip, NORMAL.getY() * scaleRecip, NORMAL.getWidth() * scaleRecip, NORMAL.getHeight() * scaleRecip);
77 g2d.setColor(oldColor);
78 g2d.setStroke(oldStroke);
80 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aaHint);
87 public Rectangle2D getBoundsInLocal() {
91 public void setVertex(DistrictNetworkVertex vertex) {
95 public boolean hover(boolean hover) {
96 // if (hover && LOGGER.isDebugEnabled())
97 // LOGGER.debug("Hovering " + this);
98 boolean changed = false;
99 if (this.hover != hover) {