]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkNodeUtils.java
Elimination of compiler warnings.
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / nodes / DistrictNetworkNodeUtils.java
1 package org.simantics.district.network.ui.nodes;
2
3 import java.awt.geom.AffineTransform;
4 import java.awt.geom.Point2D;
5 import java.awt.geom.Rectangle2D;
6
7 import org.simantics.district.network.ModelledCRS;
8 import org.simantics.maps.MapScalingTransform;
9
10 public class DistrictNetworkNodeUtils {
11
12     public static Rectangle2D calculateDrawnGeometry(Point2D p, Rectangle2D margin, Rectangle2D result, double scaleRecip) {
13         if (result == null)
14             result = new Rectangle2D.Double();
15         double mw = margin.getWidth();
16         double mh = margin.getHeight();
17         result.setFrame(p.getX() - (mw / 2 * scaleRecip), p.getY() - (mh / 2 * scaleRecip), mw * scaleRecip, mh * scaleRecip);
18         return result;
19     }
20
21     public static Point2D calculatePoint2D(Point2D point, Point2D result) {
22         double x = ModelledCRS.longitudeToX(point.getX());
23         double y = ModelledCRS.latitudeToY(-point.getY()); // Inverse because Simantics Diagram is inverted
24         if (result == null)
25             result = new Point2D.Double(x, y);
26         else
27             result.setLocation(x, y);
28         return result;
29     }
30
31     public static AffineTransform getTransformToRectangle(Rectangle2D toDraw, AffineTransform transform) {
32         if (transform == null)
33             transform = new AffineTransform();
34
35         transform.setTransform(toDraw.getWidth(), 0.0, 0.0, toDraw.getHeight(), toDraw.getCenterX(), toDraw.getCenterY());
36         return transform;
37     }
38
39     public static double calculateScaleRecip(AffineTransform tr) {
40         int zoomLevel = MapScalingTransform.zoomLevel(tr);
41         double t = 1.0 / Math.sqrt(zoomLevel);
42         return t;
43     }
44 }