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 public class PolarHorizontalTransform extends PolarTransform
33 {
34 private static final int MAXIMUM_HEIGHT = 90;
35 private static final int MINIMUM_HEIGHT = 35;
36 private static final int MAXIMUM_HEIGHT_2 = MAXIMUM_HEIGHT / 2;
37 private static final int MAXIMUM_HEIGHT_6 = MAXIMUM_HEIGHT / 6;
38 private static final double RELATIVE_X_OFFSET = 0.05;
39 private static final double RELATIVE_Y_OFFSET = 0.1;
40 private static final double RELATIVE_SCALE_SIZE_COMPARED_TO_HEIGHT = 0.3;
41
42
43
44
45 public void setParameters(int w, int h, int marginX, int marginY,
46 int tickOffset)
47 {
48 super.setParameters(w, h, marginX, marginY, tickOffset);
49
50 height = h;
51
52 double widthDouble = w * (1 - RELATIVE_X_OFFSET);
53 double heightDouble = (h - MAXIMUM_HEIGHT_2) * (1 - RELATIVE_Y_OFFSET);
54
55 height = (int)(heightDouble * RELATIVE_SCALE_SIZE_COMPARED_TO_HEIGHT);
56 height = Math.min(height, MAXIMUM_HEIGHT);
57 height = Math.max(height, MINIMUM_HEIGHT);
58
59
60 double RDouble = (0.5 * heightDouble * (1
61 + Math.pow(widthDouble / (2 * heightDouble), 2)));
62
63 R = RDouble;
64 r = R - height;
65
66 int offset = (int)(RELATIVE_Y_OFFSET * heightDouble / 2
67 + MAXIMUM_HEIGHT_6);
68
69 centre = new Point2D.Double(w / 2, R + offset);
70
71 double phi = Math.asin(widthDouble / (2 * RDouble)) * 180 / Math.PI;
72
73 alpha = (90.0 + phi);
74 span = (2.0 * phi);
75
76 setLabelPosition((int)centre.getX(), (int)(h * 0.75));
77
78 this.tickOffset = (tickOffset * 180.0 / Math.PI) / r;
79
80 ArcSegment segment = new ArcSegment(centre, r, R, alpha, span);
81 addSegment(segment);
82 }
83 }
84
85