From: Ben Soares Date: Wed, 1 Jul 2020 13:55:55 +0000 (+0100) Subject: Merge branch 'task/JAL-3608_property_set_laf_and_tests_from_Release_2_11_1_Branch... X-Git-Tag: Release_2_11_1_1~22^2~17^2~1 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=6e2b4ee8fb9bdb978087ed19516bfd8d7f00f544;hp=6312cb6f6a715162cccd42b952c4801ee39715be;p=jalview.git Merge branch 'task/JAL-3608_property_set_laf_and_tests_from_Release_2_11_1_Branch' into merge/JAL-3609_and_JAL-3608 --- diff --git a/getdown/lib/FJVL_VERSION b/getdown/lib/FJVL_VERSION index e7a1de7..fdf3dcc 100644 --- a/getdown/lib/FJVL_VERSION +++ b/getdown/lib/FJVL_VERSION @@ -1 +1 @@ -1.8.3-1.2.4_FJVL +1.8.3-1.2.6_FJVL diff --git a/getdown/lib/JVL_VERSION b/getdown/lib/JVL_VERSION index 756f4bd..4492183 100644 --- a/getdown/lib/JVL_VERSION +++ b/getdown/lib/JVL_VERSION @@ -1 +1 @@ -1.8.3-1.2.4_JVL +1.8.3-1.2.6_JVL diff --git a/getdown/lib/getdown-core.jar b/getdown/lib/getdown-core.jar index 9c0f96e..6748a25 100644 Binary files a/getdown/lib/getdown-core.jar and b/getdown/lib/getdown-core.jar differ diff --git a/getdown/lib/getdown-launcher-local.jar b/getdown/lib/getdown-launcher-local.jar index cfa96f3..9a27f55 100644 Binary files a/getdown/lib/getdown-launcher-local.jar and b/getdown/lib/getdown-launcher-local.jar differ diff --git a/getdown/lib/getdown-launcher.jar b/getdown/lib/getdown-launcher.jar index 2f8baa7..e441bc6 100644 Binary files a/getdown/lib/getdown-launcher.jar and b/getdown/lib/getdown-launcher.jar differ diff --git a/getdown/src/getdown/ant/pom.xml b/getdown/src/getdown/ant/pom.xml index 8dcef42..65686d2 100644 --- a/getdown/src/getdown/ant/pom.xml +++ b/getdown/src/getdown/ant/pom.xml @@ -4,7 +4,7 @@ com.threerings.getdown getdown - 1.8.3-1.2.4_FJVL + 1.8.3-1.2.6_FJVL getdown-ant diff --git a/getdown/src/getdown/core/pom.xml b/getdown/src/getdown/core/pom.xml index 2d0e89a..6a9e169 100644 --- a/getdown/src/getdown/core/pom.xml +++ b/getdown/src/getdown/core/pom.xml @@ -4,7 +4,7 @@ com.threerings.getdown getdown - 1.8.3-1.2.4_FJVL + 1.8.3-1.2.6_FJVL getdown-core diff --git a/getdown/src/getdown/core/src/main/java/com/threerings/getdown/data/Application.java b/getdown/src/getdown/core/src/main/java/com/threerings/getdown/data/Application.java index fd53c79..b11a380 100644 --- a/getdown/src/getdown/core/src/main/java/com/threerings/getdown/data/Application.java +++ b/getdown/src/getdown/core/src/main/java/com/threerings/getdown/data/Application.java @@ -27,6 +27,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; +import jalview.bin.HiDPISetting; import jalview.bin.MemorySetting; //import com.install4j.api.launcher.Variables; @@ -1071,6 +1072,13 @@ public class Application args.add("-Dinstaller_template_version=" + System.getProperty("installer_template_version")); args.add("-Dlauncher_version=" + Build.version()); + // set HiDPI property if wanted + String scalePropertyArg = HiDPISetting.getScalePropertyArg(); + if (scalePropertyArg != null) + { + args.add(scalePropertyArg); + } + // set the native library path if we have native resources // @TODO optional getdown.txt parameter to set addCurrentLibraryPath to true or false? ClassPath javaLibPath = PathBuilder.buildLibsPath(this, true); diff --git a/getdown/src/getdown/core/src/main/java/jalview/bin/GetMemory.java b/getdown/src/getdown/core/src/main/java/jalview/bin/GetMemory.java index e89bffb..b01dfb8 100644 --- a/getdown/src/getdown/core/src/main/java/jalview/bin/GetMemory.java +++ b/getdown/src/getdown/core/src/main/java/jalview/bin/GetMemory.java @@ -1,3 +1,23 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.bin; import java.lang.management.ManagementFactory; diff --git a/getdown/src/getdown/core/src/main/java/jalview/bin/HiDPISetting.java b/getdown/src/getdown/core/src/main/java/jalview/bin/HiDPISetting.java new file mode 100644 index 0000000..497900f --- /dev/null +++ b/getdown/src/getdown/core/src/main/java/jalview/bin/HiDPISetting.java @@ -0,0 +1,180 @@ +package jalview.bin; + +import java.awt.HeadlessException; +import java.awt.Toolkit; + +public class HiDPISetting +{ + private static final int hidpiThreshold = 160; + + private static final int hidpiMultiThreshold = 240; + + private static final int bigScreenThreshold = 1400; + + private static final String scalePropertyName = "sun.java2d.uiScale"; + + private static final boolean isLinux; + + // private static final boolean isAMac; + + // private static final boolean isWindows; + + public static final String setHiDPIPropertyName = "setHiDPI"; + + public static final String setHiDPIScalePropertyName = "setHiDPIScale"; + + private static boolean setHiDPI = false; + + private static int setHiDPIScale = 0; + + public static int dpi = 0; + + public static int mindimension = 0; + + public static int width = 0; + + public static int scale = 0; + + private static boolean doneInit = false; + + private static boolean allowScalePropertyArg = false; + + static + { + String system = System.getProperty("os.name") == null ? null + : System.getProperty("os.name").toLowerCase(); + if (system != null) + { + isLinux = system.indexOf("linux") > -1; + // isAMac = system.indexOf("mac") > -1; + // isWindows = system.indexOf("windows") > -1; + } + else + { + isLinux = false; + // isAMac = isWindows = false; + } + } + + private static void init() + { + if (doneInit) + { + return; + } + + // get and use command line property values first + String setHiDPIProperty = System.getProperty(setHiDPIPropertyName); + setHiDPI = setHiDPIProperty != null + && setHiDPIProperty.equalsIgnoreCase("true"); + + String setHiDPIScaleProperty = System + .getProperty(setHiDPIScalePropertyName); + if (setHiDPIScaleProperty != null) + { + try + { + setHiDPIScale = Integer.parseInt(setHiDPIScaleProperty); + } catch (NumberFormatException e) + { + System.err.println(setHiDPIScalePropertyName + " property give (" + + setHiDPIScaleProperty + ") but not parseable as integer"); + } + } + if (setHiDPI && setHiDPIScale > 0) + { + setHiDPIScale(setHiDPIScale); + return; + } + + // check to see if the scale property has already been set by something else + // (e.g. the OS) + String existingProperty = System.getProperty(scalePropertyName); + if (existingProperty != null) + { + try + { + int existingPropertyVal = Integer.parseInt(existingProperty); + System.out.println("Existing " + scalePropertyName + " is " + + existingPropertyVal); + if (existingPropertyVal > 1) + { + setHiDPIScale(existingPropertyVal); + return; + } + } catch (NumberFormatException e) + { + System.out.println("Could not convert property " + scalePropertyName + + " vale '" + existingProperty + "' to number"); + } + } + + // Try and auto guess a good scale based on reported DPI (not trustworthy) + // and screen resolution (more trustworthy) + + // get screen dpi + try + { + dpi = Toolkit.getDefaultToolkit().getScreenResolution(); + } catch (HeadlessException e) + { + System.err.println("Cannot get screen resolution: " + e.getMessage()); + } + + // try and get screen size height and width + try + { + int height = Toolkit.getDefaultToolkit().getScreenSize().height; + int width = Toolkit.getDefaultToolkit().getScreenSize().width; + // using mindimension in case of portrait screens + mindimension = Math.min(height, width); + } catch (HeadlessException e) + { + System.err.println( + "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); + + // 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() + { + init(); + // HiDPI setting. Just looking at Linux to start with. Test with Windows. + return allowScalePropertyArg ? "-D" + scalePropertyName + "=" + scale + : null; + } +} diff --git a/getdown/src/getdown/core/src/main/java/jalview/bin/MemorySetting.java b/getdown/src/getdown/core/src/main/java/jalview/bin/MemorySetting.java index 7849ba2..159374a 100644 --- a/getdown/src/getdown/core/src/main/java/jalview/bin/MemorySetting.java +++ b/getdown/src/getdown/core/src/main/java/jalview/bin/MemorySetting.java @@ -1,3 +1,23 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.bin; /** diff --git a/getdown/src/getdown/launcher/pom.xml b/getdown/src/getdown/launcher/pom.xml index ad87541..0410815 100644 --- a/getdown/src/getdown/launcher/pom.xml +++ b/getdown/src/getdown/launcher/pom.xml @@ -4,7 +4,7 @@ com.threerings.getdown getdown - 1.8.3-1.2.4_FJVL + 1.8.3-1.2.6_FJVL getdown-launcher diff --git a/getdown/src/getdown/mvn_cmd b/getdown/src/getdown/mvn_cmd index 3f9b4a2..25faf6f 100755 --- a/getdown/src/getdown/mvn_cmd +++ b/getdown/src/getdown/mvn_cmd @@ -3,7 +3,7 @@ if [ x$JVLVERSION != x ]; then export VERSION=$JVLVERSION else - export VERSION=1.8.3-1.2.4_JVL + export VERSION=1.8.3-1.2.6_JVL fi if [ x${VERSION%_JVL} = x$VERSION ]; then diff --git a/getdown/src/getdown/pom.xml b/getdown/src/getdown/pom.xml index 2ca4aa1..0011325 100644 --- a/getdown/src/getdown/pom.xml +++ b/getdown/src/getdown/pom.xml @@ -10,7 +10,7 @@ com.threerings.getdown getdown pom - 1.8.3-1.2.4_FJVL + 1.8.3-1.2.6_FJVL getdown An application installer and updater. diff --git a/j11lib/getdown-core.jar b/j11lib/getdown-core.jar index 9c0f96e..6748a25 100644 Binary files a/j11lib/getdown-core.jar and b/j11lib/getdown-core.jar differ diff --git a/j8lib/getdown-core.jar b/j8lib/getdown-core.jar index 9c0f96e..6748a25 100644 Binary files a/j8lib/getdown-core.jar and b/j8lib/getdown-core.jar differ diff --git a/src/jalview/bin/HiDPISetting.java b/src/jalview/bin/HiDPISetting.java new file mode 100644 index 0000000..497900f --- /dev/null +++ b/src/jalview/bin/HiDPISetting.java @@ -0,0 +1,180 @@ +package jalview.bin; + +import java.awt.HeadlessException; +import java.awt.Toolkit; + +public class HiDPISetting +{ + private static final int hidpiThreshold = 160; + + private static final int hidpiMultiThreshold = 240; + + private static final int bigScreenThreshold = 1400; + + private static final String scalePropertyName = "sun.java2d.uiScale"; + + private static final boolean isLinux; + + // private static final boolean isAMac; + + // private static final boolean isWindows; + + public static final String setHiDPIPropertyName = "setHiDPI"; + + public static final String setHiDPIScalePropertyName = "setHiDPIScale"; + + private static boolean setHiDPI = false; + + private static int setHiDPIScale = 0; + + public static int dpi = 0; + + public static int mindimension = 0; + + public static int width = 0; + + public static int scale = 0; + + private static boolean doneInit = false; + + private static boolean allowScalePropertyArg = false; + + static + { + String system = System.getProperty("os.name") == null ? null + : System.getProperty("os.name").toLowerCase(); + if (system != null) + { + isLinux = system.indexOf("linux") > -1; + // isAMac = system.indexOf("mac") > -1; + // isWindows = system.indexOf("windows") > -1; + } + else + { + isLinux = false; + // isAMac = isWindows = false; + } + } + + private static void init() + { + if (doneInit) + { + return; + } + + // get and use command line property values first + String setHiDPIProperty = System.getProperty(setHiDPIPropertyName); + setHiDPI = setHiDPIProperty != null + && setHiDPIProperty.equalsIgnoreCase("true"); + + String setHiDPIScaleProperty = System + .getProperty(setHiDPIScalePropertyName); + if (setHiDPIScaleProperty != null) + { + try + { + setHiDPIScale = Integer.parseInt(setHiDPIScaleProperty); + } catch (NumberFormatException e) + { + System.err.println(setHiDPIScalePropertyName + " property give (" + + setHiDPIScaleProperty + ") but not parseable as integer"); + } + } + if (setHiDPI && setHiDPIScale > 0) + { + setHiDPIScale(setHiDPIScale); + return; + } + + // check to see if the scale property has already been set by something else + // (e.g. the OS) + String existingProperty = System.getProperty(scalePropertyName); + if (existingProperty != null) + { + try + { + int existingPropertyVal = Integer.parseInt(existingProperty); + System.out.println("Existing " + scalePropertyName + " is " + + existingPropertyVal); + if (existingPropertyVal > 1) + { + setHiDPIScale(existingPropertyVal); + return; + } + } catch (NumberFormatException e) + { + System.out.println("Could not convert property " + scalePropertyName + + " vale '" + existingProperty + "' to number"); + } + } + + // Try and auto guess a good scale based on reported DPI (not trustworthy) + // and screen resolution (more trustworthy) + + // get screen dpi + try + { + dpi = Toolkit.getDefaultToolkit().getScreenResolution(); + } catch (HeadlessException e) + { + System.err.println("Cannot get screen resolution: " + e.getMessage()); + } + + // try and get screen size height and width + try + { + int height = Toolkit.getDefaultToolkit().getScreenSize().height; + int width = Toolkit.getDefaultToolkit().getScreenSize().width; + // using mindimension in case of portrait screens + mindimension = Math.min(height, width); + } catch (HeadlessException e) + { + System.err.println( + "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); + + // 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() + { + init(); + // HiDPI setting. Just looking at Linux to start with. Test with Windows. + return allowScalePropertyArg ? "-D" + scalePropertyName + "=" + scale + : null; + } +} diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 5df9ace..021aad6 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -393,6 +393,7 @@ public class Jalview if (!headless) { + desktop = new Desktop(); desktop.setInBatchMode(true); // indicate we are starting up diff --git a/src/jalview/bin/Launcher.java b/src/jalview/bin/Launcher.java index fb1c5cd..fecacbe 100644 --- a/src/jalview/bin/Launcher.java +++ b/src/jalview/bin/Launcher.java @@ -49,8 +49,8 @@ public class Launcher /** * main method for jalview.bin.Launcher. This restarts the same JRE's JVM with - * the same arguments but with memory adjusted based on extracted -jvmmempc and - * -jvmmemmax application arguments. If on a Mac then extra dock:icon and + * the same arguments but with memory adjusted based on extracted -jvmmempc + * and -jvmmemmax application arguments. If on a Mac then extra dock:icon and * dock:name arguments are also set. * * @param args @@ -130,7 +130,7 @@ public class Launcher if (!memSet) { long maxMemLong = MemorySetting.getMemorySetting(jvmmemmax, jvmmempc); - + if (maxMemLong > 0) { memSetting = "-Xmx" + Long.toString(maxMemLong); @@ -153,6 +153,14 @@ public class Launcher } } + String scalePropertyArg = HiDPISetting.getScalePropertyArg(); + if (scalePropertyArg != null) + { + System.out.println("Running " + startClass + " with scale setting " + + scalePropertyArg); + command.add(scalePropertyArg); + } + command.add(startClass); command.addAll(arguments); @@ -160,7 +168,8 @@ public class Launcher // System.out.println("COMMAND: " + String.join(" ", builder.command())); System.out.println("Running " + startClass + " with " - + (memSetting == null ? "no memory setting" : memSetting)); + + (memSetting == null ? "no memory setting" + : ("memory setting " + memSetting))); if (Boolean.parseBoolean(System.getProperty("launcherstop"))) { @@ -176,7 +185,8 @@ public class Launcher if (e.getMessage().toLowerCase().contains("memory")) { System.out.println("Caught a memory exception: " + e.getMessage()); - // Probably the "Cannot allocate memory" error, try without the memory setting + // Probably the "Cannot allocate memory" error, try without the memory + // setting ArrayList commandNoMem = new ArrayList<>(); for (int i = 0; i < command.size(); i++) {