|
15 | 15 | *******************************************************************************/
|
16 | 16 | package org.eclipse.swt.internal;
|
17 | 17 |
|
| 18 | +import java.util.*; |
18 | 19 | import java.util.function.*;
|
19 | 20 |
|
20 | 21 | import org.eclipse.swt.*;
|
@@ -42,9 +43,20 @@ public class DPIUtil {
|
42 | 43 | private static int deviceZoom = 100;
|
43 | 44 | private static int nativeDeviceZoom = 100;
|
44 | 45 |
|
45 |
| - private static enum AutoScaleMethod { AUTO, NEAREST, SMOOTH } |
46 |
| - private static AutoScaleMethod autoScaleMethodSetting = AutoScaleMethod.AUTO; |
47 |
| - private static AutoScaleMethod autoScaleMethod = AutoScaleMethod.NEAREST; |
| 46 | + private static enum AutoScaleMethod { AUTO, NEAREST, SMOOTH; |
| 47 | + |
| 48 | + public static Optional<AutoScaleMethod> forString(String s) { |
| 49 | + for (AutoScaleMethod v : values()) { |
| 50 | + if (v.name().equalsIgnoreCase(s)) { |
| 51 | + return Optional.of(v); |
| 52 | + } |
| 53 | + } |
| 54 | + return Optional.empty(); |
| 55 | + } |
| 56 | + |
| 57 | + } |
| 58 | + private static final AutoScaleMethod AUTO_SCALE_METHOD_SETTING; |
| 59 | + private static AutoScaleMethod autoScaleMethod; |
48 | 60 |
|
49 | 61 | private static String autoScaleValue;
|
50 | 62 | private static final boolean USE_CAIRO_AUTOSCALE = SWT.getPlatform().equals("gtk");
|
@@ -100,13 +112,8 @@ private static enum AutoScaleMethod { AUTO, NEAREST, SMOOTH }
|
100 | 112 | autoScaleValue = System.getProperty (SWT_AUTOSCALE);
|
101 | 113 |
|
102 | 114 | String value = System.getProperty (SWT_AUTOSCALE_METHOD);
|
103 |
| - if (value != null) { |
104 |
| - if (AutoScaleMethod.NEAREST.name().equalsIgnoreCase(value)) { |
105 |
| - autoScaleMethod = autoScaleMethodSetting = AutoScaleMethod.NEAREST; |
106 |
| - } else if (AutoScaleMethod.SMOOTH.name().equalsIgnoreCase(value)) { |
107 |
| - autoScaleMethod = autoScaleMethodSetting = AutoScaleMethod.SMOOTH; |
108 |
| - } |
109 |
| - } |
| 115 | + AUTO_SCALE_METHOD_SETTING = AutoScaleMethod.forString(value).orElse(AutoScaleMethod.AUTO); |
| 116 | + autoScaleMethod = AUTO_SCALE_METHOD_SETTING != AutoScaleMethod.AUTO ? AUTO_SCALE_METHOD_SETTING : AutoScaleMethod.NEAREST; |
110 | 117 | }
|
111 | 118 |
|
112 | 119 | /**
|
@@ -615,7 +622,7 @@ public static void setDeviceZoom (int nativeDeviceZoom) {
|
615 | 622 |
|
616 | 623 | // in GTK, preserve the current method when switching to a 100% monitor
|
617 | 624 | boolean preserveScalingMethod = SWT.getPlatform().equals("gtk") && deviceZoom == 100;
|
618 |
| - if (!preserveScalingMethod && autoScaleMethodSetting == AutoScaleMethod.AUTO) { |
| 625 | + if (!preserveScalingMethod && AUTO_SCALE_METHOD_SETTING == AutoScaleMethod.AUTO) { |
619 | 626 | if (sholdUseSmoothScaling()) {
|
620 | 627 | autoScaleMethod = AutoScaleMethod.SMOOTH;
|
621 | 628 | } else {
|
|
0 commit comments