From: Ben Soares Date: Fri, 12 Nov 2021 14:31:52 +0000 (+0000) Subject: JAL-3911 HiDPISetting update. jalview.bin.* update. Attempt to detect SHIFT key ... X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;ds=sidebyside;h=cd49bbd5f0eb396c1622096df6c3e3a80efb3a52;p=jalview.git JAL-3911 HiDPISetting update. jalview.bin.* update. Attempt to detect SHIFT key -- Order of app config and window appearance wrong. must create a window to click instead. --- 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 2022750..35250f3 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 @@ -68,6 +68,9 @@ public class Application /** A special classname that means 'use -jar code.jar' instead of a classname. */ public static final String MANIFEST_CLASS = "manifest"; + /** Set this if SHIFT key is down -- reverts to the BACKUP_CONFIG_DIR ("install") */ + private static boolean shiftKeyPressed = false; + /** Used to communicate information about the UI displayed when updating the application. */ public static final class UpdateInterface { @@ -631,7 +634,10 @@ public class Application } catch (Exception e) { log.warning("Failure reading config file", "file", _config, e); } - if (config == null || config.getString("appbase") == null || config.getString("appbase").isEmpty()) { + +System.out.println("3 SHIFT key"+(getShiftKeyPressed()?"":" not")+" pressed"); + if (getShiftKeyPressed() || config == null || config.getString("appbase") == null || config.getString("appbase").isEmpty()) { +System.out.println("4 SHIFT key"+(getShiftKeyPressed()?"":" not")+" pressed"); try { Config backupConfig = Config.parseConfig(_backupConfig, opts); config = backupConfig; @@ -2059,7 +2065,36 @@ public class Application public String getAppbase() { return _appbase; } + + public static boolean getShiftKeyPressed() { + return shiftKeyPressed; + } + + public static void setShiftKeyPressed(boolean down) { + shiftKeyPressed |= down; + } + public boolean isInstallationAppbase() { + // if not on the installation appbase, give half a second for SHIFT key to be pressed + Config.ParseOpts opts = null; + Config config = null; + try { + Config backupConfig = Config.parseConfig(_backupConfig, opts); +System.out.println("1 SHIFT key"+(getShiftKeyPressed()?"":" not")+" pressed"); + Thread.sleep(2000); +System.out.println("2 SHIFT key"+(getShiftKeyPressed()?"":" not")+" pressed"); + return (true || (config != null && backupConfig != null && backupConfig.getString("appbase") != null && (!backupConfig.getString("appbase").equals(config.getString("appbase"))))); + + } catch (NullPointerException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return false; + } + protected final EnvConfig _envc; protected File _config; protected File _backupConfig; 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 index d6d440a..cda27cd 100644 --- a/getdown/src/getdown/core/src/main/java/jalview/bin/HiDPISetting.java +++ b/getdown/src/getdown/core/src/main/java/jalview/bin/HiDPISetting.java @@ -1,5 +1,7 @@ package jalview.bin; +import java.util.Locale; + import java.awt.HeadlessException; public class HiDPISetting @@ -34,6 +36,8 @@ public class HiDPISetting public static int scale = 0; + public final static int MAX_SCALE = 8; + private static boolean doneInit = false; private static boolean allowScalePropertyArg = false; @@ -43,7 +47,7 @@ public class HiDPISetting static { String system = System.getProperty("os.name") == null ? null - : System.getProperty("os.name").toLowerCase(); + : System.getProperty("os.name").toLowerCase(Locale.ROOT); if (system != null) { isLinux = system.indexOf("linux") > -1; @@ -66,8 +70,17 @@ public class HiDPISetting // get and use command line property values first String setHiDPIProperty = System.getProperty(setHiDPIPropertyName); - setHiDPI = setHiDPIProperty != null - && setHiDPIProperty.equalsIgnoreCase("true"); + boolean setHiDPIPropertyBool = Boolean.parseBoolean(setHiDPIProperty); + + // allow -DsetHiDPI=false to turn off HiDPI scaling + if (setHiDPIProperty != null && !setHiDPIPropertyBool) + { + clear(); + doneInit = true; + return; + } + + setHiDPI = setHiDPIProperty != null && setHiDPIPropertyBool; String setHiDPIScaleProperty = System .getProperty(setHiDPIScalePropertyName); @@ -76,6 +89,12 @@ public class HiDPISetting try { setHiDPIScale = Integer.parseInt(setHiDPIScaleProperty); + // if setHiDPIScale property is validly set and setHiDPI property wasn't + // attempted to be set we assume setHiDPIScale to be true + if (setHiDPIProperty == null) + { + setHiDPI = true; + } } catch (NumberFormatException e) { System.err.println(setHiDPIScalePropertyName + " property give (" @@ -149,6 +168,14 @@ public class HiDPISetting 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); @@ -184,6 +211,20 @@ public class HiDPISetting return allowScalePropertyArg ? getScalePropertyArg(scale) : null; } + public static void setScaleProperty(int s) + { + System.setProperty(scalePropertyName, String.valueOf(s)); + } + + public static void setScaleProperty() + { + init(); + if (allowScalePropertyArg) + { + setScaleProperty(scale); + } + } + public static void clear() { setHiDPI = false; 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 5d7f14c..52f0c9e 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 @@ -31,6 +31,8 @@ package jalview.bin; * @author bsoares * */ +import java.util.Locale; + public class MemorySetting { public static final String MAX_HEAPSIZE_PERCENT_PROPERTY_NAME = "jvmmempc"; @@ -101,7 +103,7 @@ public class MemorySetting if (jvmmemmax != null && jvmmemmax.length() > 0) { long multiplier = 1; - switch (jvmmemmax.toLowerCase().substring(jvmmemmax.length() - 1)) + switch (jvmmemmax.toLowerCase(Locale.ROOT).substring(jvmmemmax.length() - 1)) { case "t": multiplier = 1099511627776L; // 2^40 diff --git a/getdown/src/getdown/launcher/src/main/java/com/threerings/getdown/launcher/GetdownApp.java b/getdown/src/getdown/launcher/src/main/java/com/threerings/getdown/launcher/GetdownApp.java index fee1d3e..f328fad 100644 --- a/getdown/src/getdown/launcher/src/main/java/com/threerings/getdown/launcher/GetdownApp.java +++ b/getdown/src/getdown/launcher/src/main/java/com/threerings/getdown/launcher/GetdownApp.java @@ -9,6 +9,7 @@ import java.awt.Color; import java.awt.Container; import java.awt.Image; import java.awt.event.ActionEvent; +import java.awt.event.KeyListener; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; @@ -35,12 +36,18 @@ import com.threerings.getdown.util.LaunchUtil; import com.threerings.getdown.util.StringUtil; import static com.threerings.getdown.Log.log; import jalview.bin.StartupNotificationListener; +import jalview.bin.HiDPISetting; /** * The main application entry point for Getdown. */ public class GetdownApp { + // try and set HiDPISetting property immediately + static { + HiDPISetting.setScaleProperty(); + } + public static String startupFilesParameterString = ""; /** * The main entry point of the Getdown launcher application. @@ -126,6 +133,7 @@ public class GetdownApp Getdown app = new Getdown(envc) { @Override protected Container createContainer () { +System.out.println("0 Creating Container"); // create our user interface, and display it if (_frame == null) { _frame = new JFrame(""); @@ -157,6 +165,26 @@ public class GetdownApp handleWindowClose(); } }); + + // look for SHIFT key presses and set flag in Application + _frame.addKeyListener( + new KeyListener() { + @Override + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_SHIFT) { + Application.setShiftKeyPressed(true); + //_app. + } + } + @Override + public void keyReleased(KeyEvent e) { + } + @Override + public void keyTyped(KeyEvent e) { + } + } + ); + // this cannot be called in configureContainer as it is only allowed before the // frame has been displayed for the first time _frame.setUndecorated(_ifc.hideDecorations); diff --git a/getdown/src/getdown/mvn_cmd b/getdown/src/getdown/mvn_cmd index 65e5fb9..ba092a7 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.10_JVL + export VERSION=1.8.3-1.3.0_JVL fi if [ x${VERSION%_JVL} = x$VERSION ]; then diff --git a/src/jalview/bin/HiDPISetting.java b/src/jalview/bin/HiDPISetting.java index 6219179..cda27cd 100644 --- a/src/jalview/bin/HiDPISetting.java +++ b/src/jalview/bin/HiDPISetting.java @@ -211,6 +211,20 @@ public class HiDPISetting return allowScalePropertyArg ? getScalePropertyArg(scale) : null; } + public static void setScaleProperty(int s) + { + System.setProperty(scalePropertyName, String.valueOf(s)); + } + + public static void setScaleProperty() + { + init(); + if (allowScalePropertyArg) + { + setScaleProperty(scale); + } + } + public static void clear() { setHiDPI = false;