1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.cosylab.gui.components.gauger;
21
22 import java.awt.Graphics;
23 import java.awt.geom.Point2D;
24
25
26
27
28
29
30
31
32
33 public abstract class PolarTransform extends ScaleTransform
34 {
35 protected Point2D centre;
36 protected double R;
37 protected double r;
38 protected double alpha;
39 protected double span;
40 protected int height;
41 protected double tickOffset;
42
43
44
45
46 public void setParameters(int w, int h, int marginX, int marginY,
47 int tickOffset)
48 {
49 setPolar(true);
50 }
51
52
53
54
55 public void mapUVtoXY(Point2D scaleSpace, Point2D cartesianSpace)
56 {
57 double phi = alpha
58 - (tickOffset + scaleSpace.getX() * (span - 2.0 * tickOffset));
59
60 PolarPoint.polarToCartesian(cartesianSpace,
61 r + scaleSpace.getY() * height, phi);
62
63 cartesianSpace.setLocation(cartesianSpace.getX() + centre.getX(),
64 cartesianSpace.getY() + centre.getY());
65 }
66
67
68
69
70 public void mapXYtoUV(Point2D cartesianSpace, Point2D scaleScape)
71 {
72
73 }
74
75
76
77
78 public double scaleWidth(double v)
79 {
80 return Math.abs(((r + v * height) * Math.PI * (span - 2 * tickOffset) / 180.0));
81 }
82
83
84
85
86 public double scaleHeight(double u)
87 {
88 return height;
89 }
90
91
92
93
94
95 public int measureTick(Graphics g, double x, String text)
96 {
97 return g.getFontMetrics().stringWidth(text);
98 }
99 }
100
101