1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.bin; |
22 |
|
|
23 |
|
import java.awt.HeadlessException; |
24 |
|
import java.util.Locale; |
25 |
|
|
26 |
|
import jalview.util.ErrorLog; |
27 |
|
|
|
|
| 61.4% |
Uncovered Elements: 44 (114) |
Complexity: 33 |
Complexity Density: 0.46 |
|
28 |
|
public class HiDPISetting |
29 |
|
{ |
30 |
|
private static final int hidpiThreshold = 160; |
31 |
|
|
32 |
|
private static final int hidpiMultiThreshold = 240; |
33 |
|
|
34 |
|
private static final int bigScreenThreshold = 1400; |
35 |
|
|
36 |
|
public static final String scalePropertyName = "sun.java2d.uiScale"; |
37 |
|
|
38 |
|
private static final boolean isLinux; |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
public static final String setHiDPIPropertyName = "setHiDPI"; |
45 |
|
|
46 |
|
public static final String setHiDPIScalePropertyName = "setHiDPIScale"; |
47 |
|
|
48 |
|
private static boolean setHiDPI = false; |
49 |
|
|
50 |
|
private static int setHiDPIScale = 0; |
51 |
|
|
52 |
|
public static int dpi = 0; |
53 |
|
|
54 |
|
public static int mindimension = 0; |
55 |
|
|
56 |
|
public static int width = 0; |
57 |
|
|
58 |
|
public static int scale = 0; |
59 |
|
|
60 |
|
public final static int MAX_SCALE = 8; |
61 |
|
|
62 |
|
private static boolean doneInit = false; |
63 |
|
|
64 |
|
private static boolean allowScalePropertyArg = false; |
65 |
|
|
66 |
|
private static ScreenInfo screenInfo = new ScreenInfo(); |
67 |
|
|
|
|
| 62.5% |
Uncovered Elements: 3 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
68 |
1 |
static... |
69 |
|
{ |
70 |
1 |
String system = System.getProperty("os.name") == null ? null |
71 |
|
: System.getProperty("os.name").toLowerCase(Locale.ROOT); |
72 |
1 |
if (system != null) |
73 |
|
{ |
74 |
1 |
isLinux = system.indexOf("linux") > -1; |
75 |
|
|
76 |
|
|
77 |
|
} |
78 |
|
else |
79 |
|
{ |
80 |
0 |
isLinux = false; |
81 |
|
|
82 |
|
} |
83 |
|
} |
84 |
|
|
|
|
| 48.7% |
Uncovered Elements: 39 (76) |
Complexity: 22 |
Complexity Density: 0.44 |
|
85 |
6 |
private static void init()... |
86 |
|
{ |
87 |
6 |
if (doneInit) |
88 |
|
{ |
89 |
0 |
return; |
90 |
|
} |
91 |
|
|
92 |
|
|
93 |
6 |
String setHiDPIProperty = System.getProperty(setHiDPIPropertyName); |
94 |
6 |
boolean setHiDPIPropertyBool = Boolean.parseBoolean(setHiDPIProperty); |
95 |
|
|
96 |
|
|
97 |
6 |
if (setHiDPIProperty != null && !setHiDPIPropertyBool) |
98 |
|
{ |
99 |
0 |
clear(); |
100 |
0 |
doneInit = true; |
101 |
0 |
return; |
102 |
|
} |
103 |
|
|
104 |
6 |
setHiDPI = setHiDPIProperty != null && setHiDPIPropertyBool; |
105 |
|
|
106 |
6 |
String setHiDPIScaleProperty = System |
107 |
|
.getProperty(setHiDPIScalePropertyName); |
108 |
6 |
if (setHiDPIScaleProperty != null) |
109 |
|
{ |
110 |
0 |
try |
111 |
|
{ |
112 |
0 |
setHiDPIScale = Integer.parseInt(setHiDPIScaleProperty); |
113 |
|
|
114 |
|
|
115 |
0 |
if (setHiDPIProperty == null) |
116 |
|
{ |
117 |
0 |
setHiDPI = true; |
118 |
|
} |
119 |
|
} catch (NumberFormatException e) |
120 |
|
{ |
121 |
0 |
ErrorLog.errPrintln(setHiDPIScalePropertyName + " property give (" |
122 |
|
+ setHiDPIScaleProperty + ") but not parseable as integer"); |
123 |
|
} |
124 |
|
} |
125 |
6 |
if (setHiDPI && setHiDPIScale > 0) |
126 |
|
{ |
127 |
0 |
setHiDPIScale(setHiDPIScale); |
128 |
0 |
return; |
129 |
|
} |
130 |
|
|
131 |
|
|
132 |
|
|
133 |
6 |
String existingProperty = System.getProperty(scalePropertyName); |
134 |
6 |
if (existingProperty != null) |
135 |
|
{ |
136 |
0 |
try |
137 |
|
{ |
138 |
0 |
int existingPropertyVal = Integer.parseInt(existingProperty); |
139 |
0 |
ErrorLog.outPrintln("Existing " + scalePropertyName + " is " |
140 |
|
+ existingPropertyVal); |
141 |
0 |
if (existingPropertyVal > 1) |
142 |
|
{ |
143 |
0 |
setHiDPIScale(existingPropertyVal); |
144 |
0 |
return; |
145 |
|
} |
146 |
|
} catch (NumberFormatException e) |
147 |
|
{ |
148 |
0 |
ErrorLog.outPrintln( |
149 |
|
"Could not convert property " + scalePropertyName |
150 |
|
+ " vale '" + existingProperty + "' to number"); |
151 |
|
} |
152 |
|
} |
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
6 |
screenInfo = getScreenInfo(); |
159 |
6 |
try |
160 |
|
{ |
161 |
6 |
dpi = screenInfo.getScreenResolution(); |
162 |
|
} catch (HeadlessException e) |
163 |
|
{ |
164 |
0 |
if (isLinux) |
165 |
|
{ |
166 |
0 |
ErrorLog.errPrintln( |
167 |
|
"Cannot get screen resolution: " + e.getMessage()); |
168 |
|
} |
169 |
|
} |
170 |
|
|
171 |
|
|
172 |
6 |
try |
173 |
|
{ |
174 |
6 |
int height = screenInfo.getScreenHeight(); |
175 |
6 |
int width = screenInfo.getScreenWidth(); |
176 |
|
|
177 |
6 |
mindimension = Math.min(height, width); |
178 |
|
} catch (HeadlessException e) |
179 |
|
{ |
180 |
0 |
if (isLinux) |
181 |
|
{ |
182 |
0 |
ErrorLog.errPrintln("Cannot get screen size height and width:" |
183 |
|
+ e.getMessage()); |
184 |
|
} |
185 |
|
} |
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
|
194 |
6 |
int dpiScale = (dpi - hidpiThreshold > 0) |
195 |
|
? 2 + ((dpi - hidpiThreshold) / hidpiMultiThreshold) |
196 |
|
: 1; |
197 |
|
|
198 |
6 |
int dimensionScale = 1 + (mindimension / bigScreenThreshold); |
199 |
|
|
200 |
|
|
201 |
6 |
if (dpiScale > MAX_SCALE) |
202 |
|
{ |
203 |
0 |
dpiScale = 1; |
204 |
|
} |
205 |
6 |
if (dimensionScale > MAX_SCALE) |
206 |
|
{ |
207 |
0 |
dimensionScale = 1; |
208 |
|
} |
209 |
|
|
210 |
|
|
211 |
|
|
212 |
6 |
int autoScale = Math.max(dpiScale, dimensionScale); |
213 |
|
|
214 |
|
|
215 |
|
|
216 |
6 |
if ((autoScale > 1 && isLinux) || setHiDPI) |
217 |
|
{ |
218 |
3 |
setHiDPIScale(autoScale); |
219 |
3 |
return; |
220 |
|
} |
221 |
|
|
222 |
|
|
223 |
3 |
doneInit = true; |
224 |
|
} |
225 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
226 |
3 |
public static void setHiDPIScale(int s)... |
227 |
|
{ |
228 |
3 |
scale = s; |
229 |
3 |
allowScalePropertyArg = true; |
230 |
3 |
doneInit = true; |
231 |
|
} |
232 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
233 |
7 |
public static String getScalePropertyArg(int s)... |
234 |
|
{ |
235 |
7 |
return "-D" + scalePropertyName + "=" + String.valueOf(s); |
236 |
|
} |
237 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
238 |
6 |
public static String getScalePropertyArg()... |
239 |
|
{ |
240 |
6 |
init(); |
241 |
|
|
242 |
6 |
return allowScalePropertyArg ? getScalePropertyArg(scale) : null; |
243 |
|
} |
244 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
245 |
6 |
public static void clear()... |
246 |
|
{ |
247 |
6 |
setHiDPI = false; |
248 |
6 |
setHiDPIScale = 0; |
249 |
6 |
dpi = 0; |
250 |
6 |
mindimension = 0; |
251 |
6 |
width = 0; |
252 |
6 |
scale = 0; |
253 |
6 |
doneInit = false; |
254 |
6 |
allowScalePropertyArg = false; |
255 |
|
} |
256 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
257 |
6 |
public static void setScreenInfo(ScreenInfo si)... |
258 |
|
{ |
259 |
6 |
screenInfo = si; |
260 |
|
} |
261 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
262 |
12 |
public static ScreenInfo getScreenInfo()... |
263 |
|
{ |
264 |
12 |
if (screenInfo == null) |
265 |
|
{ |
266 |
0 |
screenInfo = new ScreenInfo(); |
267 |
|
} |
268 |
12 |
return screenInfo; |
269 |
|
} |
270 |
|
} |