Skip to content

Commit c6c4654

Browse files
committed
Transform the field DPIUtil.autoScaleMethodSetting to a constant
The field was already being used as a constant since it was being initialized in a static block. Also adapt the initialization of the field autoScaleMethod to use the constant.
1 parent b8dd804 commit c6c4654

File tree

1 file changed

+18
-11
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal

1 file changed

+18
-11
lines changed

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*******************************************************************************/
1616
package org.eclipse.swt.internal;
1717

18+
import java.util.*;
1819
import java.util.function.*;
1920

2021
import org.eclipse.swt.*;
@@ -42,9 +43,20 @@ public class DPIUtil {
4243
private static int deviceZoom = 100;
4344
private static int nativeDeviceZoom = 100;
4445

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;
4860

4961
private static String autoScaleValue;
5062
private static final boolean USE_CAIRO_AUTOSCALE = SWT.getPlatform().equals("gtk");
@@ -100,13 +112,8 @@ private static enum AutoScaleMethod { AUTO, NEAREST, SMOOTH }
100112
autoScaleValue = System.getProperty (SWT_AUTOSCALE);
101113

102114
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;
110117
}
111118

112119
/**
@@ -615,7 +622,7 @@ public static void setDeviceZoom (int nativeDeviceZoom) {
615622

616623
// in GTK, preserve the current method when switching to a 100% monitor
617624
boolean preserveScalingMethod = SWT.getPlatform().equals("gtk") && deviceZoom == 100;
618-
if (!preserveScalingMethod && autoScaleMethodSetting == AutoScaleMethod.AUTO) {
625+
if (!preserveScalingMethod && AUTO_SCALE_METHOD_SETTING == AutoScaleMethod.AUTO) {
619626
if (sholdUseSmoothScaling()) {
620627
autoScaleMethod = AutoScaleMethod.SMOOTH;
621628
} else {

0 commit comments

Comments
 (0)