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 * 3, top * 3, width * 3, height * 3);
32 private Stroke stroke = new BasicStroke(2);
33 private boolean scaleStroke = true;
34 private boolean hover;
44 public void render(Graphics2D g2d) {
45 AffineTransform ot = null;
46 AffineTransform t = getTransform();
47 if (t != null && !t.isIdentity()) {
48 ot = g2d.getTransform();
49 g2d.transform(getTransform());
52 Object aaHint = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
53 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
55 Color oldColor = g2d.getColor();
56 Stroke oldStroke = g2d.getStroke();
60 double scaleRecip = 1;
62 double scale = GeometryUtils.getScale(g2d.getTransform());
64 //System.out.println("scale: " + scale);
65 scaleRecip = 1.0 / scale;
67 scaleRecip = 8.0 * scaleRecip;
71 toDraw = new Rectangle2D.Double(HOVERED.getX() * scaleRecip, HOVERED.getY() * scaleRecip, HOVERED.getWidth() * scaleRecip, HOVERED.getHeight() * scaleRecip);
73 toDraw = new Rectangle2D.Double(NORMAL.getX() * scaleRecip, NORMAL.getY() * scaleRecip, NORMAL.getWidth() * scaleRecip, NORMAL.getHeight() * scaleRecip);
79 g2d.setColor(oldColor);
80 g2d.setStroke(oldStroke);
82 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aaHint);
89 public Rectangle2D getBoundsInLocal() {
95 public void setVertex(DistrictNetworkVertex vertex) {
99 public boolean hover(boolean hover) {
100 // if (hover && LOGGER.isDebugEnabled())
101 // LOGGER.debug("Hovering " + this);
102 boolean changed = false;
103 if (this.hover != hover) {
110 public void setColor(Color color) {
114 public Color getColor() {