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
23
24
25
26
27
28
29 public class ScaleTransformFactory
30 {
31
32 public static final short AUTOMATIC_SHAPE = 0;
33
34
35 public static final short HORIZONTAL_LINEAR_SHAPE = 1;
36
37
38 public static final short HORIZONTAL_CIRCULAR_SHAPE = 2;
39
40
41 public static final short FULL_CIRCULAR_SHAPE = 3;
42
43
44 public static final short VERTICAL_CIRCULAR_SHAPE = 4;
45
46
47 public static final short VERTICAL_LINEAR_SHAPE = 5;
48
49
50 private static final double FROM_LINEAR_TO_HALF_CIRCULAR = 3.5;
51
52
53 private static final double FROM_HALF_CIRCULAR_TO_FULL_CIRCULAR = 1.7;
54
55
56 private static final double FROM_FULL_CIRCULAR_TO_HALF_CIRCULAR = 0.65;
57
58
59 private static final int HEIGHT_SMALLER_THAN_THIS_ALWAYS_LINEAR = 95;
60
61
62 private static final int WIDTH_SMALLER_THAN_THIS_ALWAYS_LINEAR = 120;
63
64
65
66
67
68
69
70
71
72
73 protected static int getOptimalRenderer(int w, int h)
74 {
75 double ratio = (1.0 * w) / h;
76 short shape;
77
78 if(ratio > FROM_LINEAR_TO_HALF_CIRCULAR) {
79 shape = HORIZONTAL_LINEAR_SHAPE;
80 } else if(ratio > FROM_HALF_CIRCULAR_TO_FULL_CIRCULAR) {
81 shape = HORIZONTAL_CIRCULAR_SHAPE;
82 } else if(ratio > FROM_FULL_CIRCULAR_TO_HALF_CIRCULAR) {
83 shape = FULL_CIRCULAR_SHAPE;
84 } else if(ratio > 1 / FROM_LINEAR_TO_HALF_CIRCULAR) {
85 shape = VERTICAL_CIRCULAR_SHAPE;
86 } else {
87 shape = VERTICAL_LINEAR_SHAPE;
88 }
89
90 if((w < 1.5 * WIDTH_SMALLER_THAN_THIS_ALWAYS_LINEAR)
91 && (h < 1.5 * HEIGHT_SMALLER_THAN_THIS_ALWAYS_LINEAR)) {
92 shape = HORIZONTAL_LINEAR_SHAPE;
93 }
94
95 if(w < WIDTH_SMALLER_THAN_THIS_ALWAYS_LINEAR) {
96 shape = VERTICAL_LINEAR_SHAPE;
97 }
98
99 if(h < HEIGHT_SMALLER_THAN_THIS_ALWAYS_LINEAR) {
100 shape = HORIZONTAL_LINEAR_SHAPE;
101 }
102
103 return shape;
104 }
105
106
107
108
109
110
111
112
113
114 public static ScaleTransform createTransform(int w, int h)
115 {
116 int newValue = getOptimalRenderer(w, h);
117
118 switch(newValue) {
119 case HORIZONTAL_LINEAR_SHAPE:
120 return new LinearHorizontalTransform();
121
122 case HORIZONTAL_CIRCULAR_SHAPE:
123 return new PolarHorizontalTransform();
124
125 case FULL_CIRCULAR_SHAPE:
126 return new PolarFullTransform();
127
128 case VERTICAL_CIRCULAR_SHAPE:
129 return new PolarVerticalTransform();
130
131 case VERTICAL_LINEAR_SHAPE:
132 return new LinearVerticalTransform();
133
134 default:
135 return new LinearVerticalTransform();
136 }
137 }
138 }
139
140