1 package org.simantics.district.network.ui.nodes;
3 import java.awt.BasicStroke;
5 import java.awt.Graphics2D;
6 import java.awt.Stroke;
7 import java.awt.geom.Point2D;
8 import java.awt.geom.Rectangle2D;
9 import java.util.Collection;
10 import java.util.Collections;
12 import org.simantics.scenegraph.g2d.G2DNode;
13 import org.simantics.scenegraph.utils.GeometryUtils;
15 public class ElevationServerNode extends G2DNode {
17 private static final long serialVersionUID = 3832908017166017921L;
19 private static final Stroke DASHED_STROKE = new BasicStroke(2.0f,
20 BasicStroke.CAP_ROUND,
21 BasicStroke.JOIN_ROUND,
22 4.0f, new float[]{4.0f}, 0.0f);
24 private static final Color BLUE_ALPHA = new Color(0, 0, 255, 100);
26 public static final String ID = "elevationServerNode";
28 private Collection<Rectangle2D> rectangles;
31 public void render(Graphics2D g2d) {
33 Color old = g2d.getColor();
34 Stroke oldStroke = g2d.getStroke();
36 g2d.setColor(BLUE_ALPHA);
37 BasicStroke stroke = GeometryUtils.scaleStroke(DASHED_STROKE, (float) (1.0 / GeometryUtils.getScale(g2d.getTransform())));
38 g2d.setStroke(stroke);
40 double scale = getTransform().getScaleY();
42 for (Rectangle2D rect : getRectangles()) {
44 Point2D point = new Point2D.Double(rect.getY(), rect.getX());
45 Point2D result = DistrictNetworkNodeUtils.calculatePoint2D(point, null);
47 Point2D point2 = new Point2D.Double(rect.getY() + rect.getHeight(), rect.getX() + rect.getWidth());
48 Point2D result2 = DistrictNetworkNodeUtils.calculatePoint2D(point2, null);
50 double x = result.getX() * scale;
51 double y = result.getY() * scale;
52 double width = result2.getX() * scale - result.getX() * scale;
53 double height = result2.getY() * scale - result.getY() * scale;
55 Rectangle2D translated = new Rectangle2D.Double(x, y, width, Math.abs(height));
59 g2d.setStroke(oldStroke);
64 public Rectangle2D getBoundsInLocal() {
65 Rectangle2D bounds = new Rectangle2D.Double();
66 for (Rectangle2D rect : getRectangles()) {
72 public void setRectangles(Collection<Rectangle2D> rectangles) {
73 this.rectangles = rectangles;
76 public Collection<Rectangle2D> getRectangles() {
77 if (rectangles == null)
78 return Collections.emptyList();