3 import java.awt.Toolkit;
5 public class HiDPISetting
7 public static final int dpi;
9 public static final int scale;
11 private static final int hidpi = 110;
13 private static final String scalePropertyName = "sun.java2d.uiScale";
15 private static final boolean isAMac;
17 private static final boolean isLinux;
19 private static final boolean isWindows;
21 public static final String forceHiDPISettingPropertyName = "forceHiDPISetting";
23 private static final boolean forceHiDPISetting;
27 isAMac = System.getProperty("os.name").indexOf("Mac") > -1;
28 isLinux = System.getProperty("os.name").toLowerCase()
29 .indexOf("linux") > -1;
30 isWindows = System.getProperty("os.name").toLowerCase()
31 .indexOf("windows") > -1;
32 dpi = Toolkit.getDefaultToolkit().getScreenResolution();
33 scale = dpi / hidpi + 1;
34 String forceHiDPISettingProperty = System
35 .getProperty(forceHiDPISettingPropertyName);
36 forceHiDPISetting = forceHiDPISettingProperty != null
37 && forceHiDPISettingProperty.equalsIgnoreCase("true");
40 System.out.println("Property '" + forceHiDPISettingPropertyName + "'="
41 + forceHiDPISettingProperty);
42 System.out.println("boolean forceHiDPISetting=" + forceHiDPISetting);
43 System.out.println("DPI detected as " + dpi
44 + ". Scaling factor set to " + scale + ".");
48 private static synchronized boolean doCondition()
50 return (scale > 1 && isLinux) || forceHiDPISetting;
53 public static synchronized String getScalePropertyArg()
55 // HiDPI setting. Just looking at Linux to start with. Test with Windows.
58 return "-D" + scalePropertyName + "=" + scale;