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.geom.Point2D;
23
24
25
26
27
28
29
30
31
32
33 public class PolarVerticalTransform extends PolarTransform
34 {
35 private static final int MAXIMUM_HEIGHT = 90;
36 private static final int MINIMUM_HEIGHT = 35;
37 private static final double RELATIVE_X_OFFSET = 0.1;
38 private static final double RELATIVE_Y_OFFSET = 0.05;
39 private static final double RELATIVE_SCALE_SIZE_COMPARED_TO_WIDTH = 0.3;
40
41
42
43
44 public void setParameters(int w, int h, int marginX, int marginY,
45 int tickOffset)
46 {
47 super.setParameters(w, h, marginX, marginY, tickOffset);
48
49 double heightDouble = h * (1 - RELATIVE_Y_OFFSET);
50 double widthDouble = (w - MAXIMUM_HEIGHT / 2) * (1 - RELATIVE_X_OFFSET);
51
52 height = (int)(widthDouble * RELATIVE_SCALE_SIZE_COMPARED_TO_WIDTH);
53 height = Math.min(height, MAXIMUM_HEIGHT);
54 height = Math.max(height, MINIMUM_HEIGHT);
55
56 double RDouble = 0.5 * widthDouble * (1
57 + Math.pow(0.5 * heightDouble / widthDouble, 2));
58
59 double phi = (Math.asin(0.5 * heightDouble / RDouble) * 180 / Math.PI);
60
61 R = RDouble;
62 r = R - height;
63
64 double cw = R
65 + (RELATIVE_X_OFFSET * widthDouble / 2 + MAXIMUM_HEIGHT / 6);
66
67 centre = new Point2D.Double((w - cw), h / 2);
68 alpha = phi;
69 span = 2 * phi;
70
71 this.tickOffset = ((tickOffset * 180.0 / Math.PI) / r);
72
73 setLabelPosition((int)(3 * w / 8), (int)centre.getY());
74
75 ArcSegment segment = new ArcSegment(centre, r, R, alpha, span);
76 addSegment(segment);
77 }
78 }
79
80