1 package org.simantics.district.network.ui.nodes;
5 import java.awt.Graphics2D;
6 import java.awt.RenderingHints;
7 import java.awt.geom.AffineTransform;
8 import java.awt.geom.NoninvertibleTransformException;
9 import java.awt.geom.Point2D;
10 import java.awt.geom.Rectangle2D;
12 import org.simantics.district.network.DistrictNetworkUtil;
13 import org.simantics.district.network.ui.DistrictNetworkUIUtil;
14 import org.simantics.maps.MapScalingTransform;
15 import org.simantics.scenegraph.g2d.G2DNode;
16 import org.simantics.scenegraph.g2d.G2DParentNode;
17 import org.simantics.scenegraph.utils.DPIUtil;
19 public class DistrictNetworkStaticInfoNode extends G2DNode {
21 private static final Font FONT = new Font("Tahoma", Font.PLAIN, (int)(DPIUtil.upscale(9) * MapScalingTransform.getScaleY() + 0.5));
23 private static final long serialVersionUID = 1L;
25 private static final Point2D UNIT_X = new Point2D.Double(1.0, 0.0);
27 public static final String NODE_KEY = "DISTRICT_NETWORK_STATIC_INFO";
30 Point2D origin = new Point2D.Double();
31 Point2D direction = UNIT_X;
34 public void render(Graphics2D g) {
35 if (info == null || "".equals(info))
38 AffineTransform oldTransform = g.getTransform();
40 // There has to be a better way to calculate the zoom level in this context...
41 AffineTransform baseTransform;
43 baseTransform = ((G2DParentNode)getParent()).getTransform().createInverse();
44 } catch (NoninvertibleTransformException e) {
45 baseTransform = new AffineTransform();
48 baseTransform.preConcatenate(oldTransform);
49 int zoomLevel = MapScalingTransform.zoomLevel(baseTransform);
53 Font oldFont = g.getFont();
54 Color oldColor = g.getColor();
55 Object oldAA = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
56 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
60 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldAA);
61 g.setTransform(oldTransform);
66 private void doRender(Graphics2D g) {
67 g.translate(origin.getX(), origin.getY());
68 double scale = 1.5 / g.getTransform().getScaleX();
69 g.scale(scale, scale);
72 g.setColor(Color.BLACK);
74 g.transform(AffineTransform.getRotateInstance(direction.getX(), direction.getY()));
77 int width1 = g.getFontMetrics().stringWidth(info);
78 g.drawString(info, -width1/2, 0);
82 public Rectangle2D getBoundsInLocal() {
86 public void setLocation(Point2D origin, Point2D direction) {
88 this.direction = direction;
91 public void setInfo(String info) {