+
+ // Try and auto guess a good scale based on reported DPI (not trustworthy)
+ // and screen resolution (more trustworthy)
+
+ // get screen dpi
+ screenInfo = getScreenInfo();
+ try
+ {
+ dpi = screenInfo.getScreenResolution();
+ } catch (HeadlessException e)
+ {
+ if (isLinux)
+ {
+ jalview.bin.Console.errPrintln(
+ "Cannot get screen resolution: " + e.getMessage());
+ }
+ }
+
+ // try and get screen size height and width
+ try
+ {
+ int height = screenInfo.getScreenHeight();
+ int width = screenInfo.getScreenWidth();
+ // using mindimension in case of portrait screens
+ mindimension = Math.min(height, width);
+ } catch (HeadlessException e)
+ {
+ if (isLinux)
+ {
+ jalview.bin.Console
+ .errPrintln("Cannot get screen size height and width:"
+ + e.getMessage());
+ }
+ }
+
+ // attempt at a formula for scaling based on screen dpi and mindimension.
+ // scale will be an integer >=1. This formula is based on some testing and
+ // guesswork!
+
+ // scale based on reported dpi. if dpi>hidpiThreshold then scale=2+multiples
+ // of hidpiMultiThreshold (else scale=1)
+ // (e.g. dpi of 110 scales 1. dpi of 120 scales 2. dpi of 360 scales 3)
+ int dpiScale = (dpi - hidpiThreshold > 0)
+ ? 2 + ((dpi - hidpiThreshold) / hidpiMultiThreshold)
+ : 1;
+
+ int dimensionScale = 1 + (mindimension / bigScreenThreshold);
+
+ // reject outrageous values -- dpiScale in particular could be mistaken
+ if (dpiScale > MAX_SCALE)
+ {
+ dpiScale = 1;
+ }
+ if (dimensionScale > MAX_SCALE)
+ {
+ dimensionScale = 1;
+ }
+
+ // choose larger of dimensionScale or dpiScale (most likely dimensionScale
+ // as dpiScale often misreported)
+ int autoScale = Math.max(dpiScale, dimensionScale);
+
+ // only make an automatic change if scale is changed and other conditions
+ // (OS is linux) apply, or if setHiDPI has been specified
+ if ((autoScale > 1 && isLinux) || setHiDPI)
+ {
+ setHiDPIScale(autoScale);
+ return;
+ }
+
+ // looks like we're not doing any scaling
+ doneInit = true;
+ }
+
+ public static void setHiDPIScale(int s)
+ {
+ scale = s;
+ allowScalePropertyArg = true;
+ doneInit = true;
+ }
+
+ public static String getScalePropertyArg(int s)
+ {
+ return "-D" + scalePropertyName + "=" + String.valueOf(s);
+ }
+
+ public static String getScalePropertyArg()
+ {
+ init();
+ // HiDPI setting. Just looking at Linux to start with. Test with Windows.
+ return allowScalePropertyArg ? getScalePropertyArg(scale) : null;
+ }
+
+ public static void clear()
+ {
+ setHiDPI = false;
+ setHiDPIScale = 0;
+ dpi = 0;
+ mindimension = 0;
+ width = 0;
+ scale = 0;
+ doneInit = false;
+ allowScalePropertyArg = false;
+ }
+
+ public static void setScreenInfo(ScreenInfo si)
+ {
+ screenInfo = si;
+ }
+
+ public static ScreenInfo getScreenInfo()
+ {
+ if (screenInfo == null)