private static final boolean isWindows;
- public static final String forceHiDPISettingPropertyName = "forceHiDPISetting";
+ public static final String setHiDPIPropertyName = "setHiDPI";
- public static final String forceHiDPISettingScalePropertyName = "forceHiDPISettingScale";
+ public static final String setHiDPIScalePropertyName = "setHiDPIScale";
- private static final boolean forceHiDPISetting;
+ private static boolean setHiDPI = false;
- private static final int forceHiDPISettingScale;
+ private static int setHiDPIScale = 0;
public static int dpi = 0;
- public static int height = 0;
+ public static int maxdimension = 0;
+
+ public static int width = 0;
public static int scale = 0;
.indexOf("linux") > -1;
isWindows = System.getProperty("os.name").toLowerCase()
.indexOf("windows") > -1;
+ }
- String forceHiDPISettingProperty = System
- .getProperty(forceHiDPISettingPropertyName);
- forceHiDPISetting = forceHiDPISettingProperty != null
- && forceHiDPISettingProperty.equalsIgnoreCase("true");
+ private static void init()
+ {
+ if (doneInit)
+ {
+ return;
+ }
- int tryForceHiDPISettingScale = 0;
- String forceHiDPISettingScaleProperty = System
- .getProperty(forceHiDPISettingScalePropertyName);
- if (forceHiDPISettingScaleProperty != null)
+ String setHiDPIProperty = System.getProperty(setHiDPIPropertyName);
+ setHiDPI = setHiDPIProperty != null
+ && setHiDPIProperty.equalsIgnoreCase("true");
+
+ String setHiDPIScaleProperty = System
+ .getProperty(setHiDPIScalePropertyName);
+ if (setHiDPIScaleProperty != null)
{
try
{
- tryForceHiDPISettingScale = Integer
- .parseInt(forceHiDPISettingScaleProperty);
+ setHiDPIScale = Integer.parseInt(setHiDPIScaleProperty);
} catch (NumberFormatException e)
{
- System.err.println(forceHiDPISettingScalePropertyName
- + " property give (" + forceHiDPISettingScaleProperty
- + ") but not parseable as integer");
+ System.err.println(setHiDPIScalePropertyName + " property give ("
+ + setHiDPIScaleProperty + ") but not parseable as integer");
}
}
- forceHiDPISettingScale = tryForceHiDPISettingScale;
- }
-
- private void init()
- {
- if (doneInit)
- {
- return;
- }
// try and get screen resolution
try
System.err.println("Cannot get screen resolution");
}
- // try and get screen size height
+ // try and get screen size height and width
try
{
- height = Toolkit.getDefaultToolkit().getScreenSize().height;
+ int height = Toolkit.getDefaultToolkit().getScreenSize().height;
+ int width = Toolkit.getDefaultToolkit().getScreenSize().width;
+ // using maxdimension in case of portrait screens
+ maxdimension = Math.max(height, width);
} catch (Throwable t)
{
- System.err.println("Cannot get screen size height");
+ System.err.println("Cannot get screen size height and width");
}
- if (forceHiDPISetting && forceHiDPISettingScale > 0)
+ if (setHiDPI && setHiDPIScale > 0)
{
- scale = forceHiDPISettingScale;
+ scale = setHiDPIScale;
}
else
{
- // attempt at a formula for scaling based on screen dpi and height. scale
+ // attempt at a formula for scaling based on screen dpi and maxdimension.
+ // scale
// will be an integer >=1
- scale = Math.min(dpi / hidpiThreshold, height / tallScreenThreshold)
- + 1;
+ if (dpi > 0 && maxdimension > 0)
+ {
+ scale = Math.min(dpi / hidpiThreshold,
+ maxdimension / tallScreenThreshold) + 1;
+ }
+ else if (dpi == 0 && maxdimension > tallScreenThreshold)
+ {
+ // dpi couldn't be found but the screen has a large vertical pixel count
+ scale = maxdimension / tallScreenThreshold + 1;
+ }
+ /* do nothing if maxdimension == 0 -- might be just a small HD screen (e.g. Gemini PDA)
+ else if (maxdimension == 0 && dpi > hidpiThreshold)
+ {
+ }
+ */
}
- allowScalePropertyArg = (scale > 1 && isLinux) || forceHiDPISetting;
+ // only make a change if scale is changed and other conditions (OS is linux)
+ // apply, or if setHiDPI has been specified
+ allowScalePropertyArg = (scale > 1 && isLinux) || setHiDPI;
if (allowScalePropertyArg)
{
- System.out.println("boolean forceHiDPISetting=" + forceHiDPISetting);
+ System.out.println("boolean setHiDPI=" + setHiDPI);
System.out.println("DPI detected as " + dpi
+ ". Scaling factor set to " + scale + ".");
}
doneInit = true;
}
- public static synchronized String getScalePropertyArg()
+ public static void setHiDPIScale(int s)
+ {
+ scale = s;
+ allowScalePropertyArg = true;
+ doneInit = true;
+ }
+
+ public static String getScalePropertyArg()
{
+ init();
// HiDPI setting. Just looking at Linux to start with. Test with Windows.
return allowScalePropertyArg ? "-D" + scalePropertyName + "=" + scale
: null;
private static final boolean isWindows;
- public static final String forceHiDPISettingPropertyName = "forceHiDPISetting";
+ public static final String setHiDPIPropertyName = "setHiDPI";
- public static final String forceHiDPISettingScalePropertyName = "forceHiDPISettingScale";
+ public static final String setHiDPIScalePropertyName = "setHiDPIScale";
- private static final boolean forceHiDPISetting;
+ private static boolean setHiDPI = false;
- private static final int forceHiDPISettingScale;
+ private static int setHiDPIScale = 0;
public static int dpi = 0;
- public static int height = 0;
+ public static int maxdimension = 0;
+
+ public static int width = 0;
public static int scale = 0;
.indexOf("linux") > -1;
isWindows = System.getProperty("os.name").toLowerCase()
.indexOf("windows") > -1;
+ }
- String forceHiDPISettingProperty = System
- .getProperty(forceHiDPISettingPropertyName);
- forceHiDPISetting = forceHiDPISettingProperty != null
- && forceHiDPISettingProperty.equalsIgnoreCase("true");
+ private static void init()
+ {
+ if (doneInit)
+ {
+ return;
+ }
- int tryForceHiDPISettingScale = 0;
- String forceHiDPISettingScaleProperty = System
- .getProperty(forceHiDPISettingScalePropertyName);
- if (forceHiDPISettingScaleProperty != null)
+ String setHiDPIProperty = System.getProperty(setHiDPIPropertyName);
+ setHiDPI = setHiDPIProperty != null
+ && setHiDPIProperty.equalsIgnoreCase("true");
+
+ String setHiDPIScaleProperty = System
+ .getProperty(setHiDPIScalePropertyName);
+ if (setHiDPIScaleProperty != null)
{
try
{
- tryForceHiDPISettingScale = Integer
- .parseInt(forceHiDPISettingScaleProperty);
+ setHiDPIScale = Integer.parseInt(setHiDPIScaleProperty);
} catch (NumberFormatException e)
{
- System.err.println(forceHiDPISettingScalePropertyName
- + " property give (" + forceHiDPISettingScaleProperty
- + ") but not parseable as integer");
+ System.err.println(setHiDPIScalePropertyName + " property give ("
+ + setHiDPIScaleProperty + ") but not parseable as integer");
}
}
- forceHiDPISettingScale = tryForceHiDPISettingScale;
- }
-
- private void init()
- {
- if (doneInit)
- {
- return;
- }
// try and get screen resolution
try
System.err.println("Cannot get screen resolution");
}
- // try and get screen size height
+ // try and get screen size height and width
try
{
- height = Toolkit.getDefaultToolkit().getScreenSize().height;
+ int height = Toolkit.getDefaultToolkit().getScreenSize().height;
+ int width = Toolkit.getDefaultToolkit().getScreenSize().width;
+ // using maxdimension in case of portrait screens
+ maxdimension = Math.max(height, width);
} catch (Throwable t)
{
- System.err.println("Cannot get screen size height");
+ System.err.println("Cannot get screen size height and width");
}
- if (forceHiDPISetting && forceHiDPISettingScale > 0)
+ if (setHiDPI && setHiDPIScale > 0)
{
- scale = forceHiDPISettingScale;
+ scale = setHiDPIScale;
}
else
{
- // attempt at a formula for scaling based on screen dpi and height. scale
+ // attempt at a formula for scaling based on screen dpi and maxdimension.
+ // scale
// will be an integer >=1
- scale = Math.min(dpi / hidpiThreshold, height / tallScreenThreshold)
- + 1;
+ if (dpi > 0 && maxdimension > 0)
+ {
+ scale = Math.min(dpi / hidpiThreshold,
+ maxdimension / tallScreenThreshold) + 1;
+ }
+ else if (dpi == 0 && maxdimension > tallScreenThreshold)
+ {
+ // dpi couldn't be found but the screen has a large vertical pixel count
+ scale = maxdimension / tallScreenThreshold + 1;
+ }
+ /* do nothing if maxdimension == 0 -- might be just a small HD screen (e.g. Gemini PDA)
+ else if (maxdimension == 0 && dpi > hidpiThreshold)
+ {
+ }
+ */
}
- allowScalePropertyArg = (scale > 1 && isLinux) || forceHiDPISetting;
+ // only make a change if scale is changed and other conditions (OS is linux)
+ // apply, or if setHiDPI has been specified
+ allowScalePropertyArg = (scale > 1 && isLinux) || setHiDPI;
if (allowScalePropertyArg)
{
- System.out.println("boolean forceHiDPISetting=" + forceHiDPISetting);
+ System.out.println("boolean setHiDPI=" + setHiDPI);
System.out.println("DPI detected as " + dpi
+ ". Scaling factor set to " + scale + ".");
}
doneInit = true;
}
- public static synchronized String getScalePropertyArg()
+ public static void setHiDPIScale(int s)
+ {
+ scale = s;
+ allowScalePropertyArg = true;
+ doneInit = true;
+ }
+
+ public static String getScalePropertyArg()
{
+ init();
// HiDPI setting. Just looking at Linux to start with. Test with Windows.
return allowScalePropertyArg ? "-D" + scalePropertyName + "=" + scale
: null;