From: Ben Soares Date: Fri, 3 May 2019 19:28:56 +0000 (+0100) Subject: JAL-3247 Part way towards adding double-click opening in Jalview on .jvp file in... X-Git-Tag: Release_2_11_0~12^2^2~18 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=649af941146ec3b4e40bb0b7901ce7f8b382ebce;p=jalview.git JAL-3247 Part way towards adding double-click opening in Jalview on .jvp file in macOS --- diff --git a/build.gradle b/build.gradle index 92d2021..ac71cd3 100644 --- a/build.gradle +++ b/build.gradle @@ -722,7 +722,9 @@ task getdownWebsite() { } */ - getdownTextString += "code = " + file(getdownLauncher).getName() + "\n" + // getdown-launcher.jar should not be in main application class path so the main application can move it when updated. Listed as a resource so it gets updated. + //getdownTextString += "class = " + file(getdownLauncher).getName() + "\n" + getdownTextString += "resource = " + file(getdownLauncher).getName() + "\n" getdownTextString += "class = " + mainClass + "\n" def getdown_txt = file(project.ext.getdownWebsiteDir + "/getdown.txt") diff --git a/getdown/lib/getdown-launcher.jar b/getdown/lib/getdown-launcher.jar index e93b97b..8f52ad8 100644 Binary files a/getdown/lib/getdown-launcher.jar and b/getdown/lib/getdown-launcher.jar differ 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 6548fde..0c8cac5 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 @@ -27,6 +27,7 @@ import javax.swing.JFrame; import javax.swing.KeyStroke; import javax.swing.WindowConstants; +import com.install4j.api.launcher.StartupNotification; import com.samskivert.swing.util.SwingUtil; import com.threerings.getdown.data.EnvConfig; import com.threerings.getdown.data.SysProps; @@ -39,216 +40,241 @@ import static com.threerings.getdown.Log.log; */ public class GetdownApp { - /** - * The main entry point of the Getdown launcher application. - */ - public static void main (String[] argv) { - try { - start(argv); - } catch (Exception e) { - log.warning("main() failed.", e); - } + public static String startupFilesParameterString = ""; + /** + * The main entry point of the Getdown launcher application. + */ + public static void main (String[] argv) { + try { + start(argv); + } catch (Exception e) { + log.warning("main() failed.", e); } + } - /** - * Runs Getdown as an application, using the arguments supplie as {@code argv}. - * @return the {@code Getdown} instance that is running. {@link Getdown#start} will have been - * called on it. - * @throws Exception if anything goes wrong starting Getdown. - */ - public static Getdown start (String[] argv) throws Exception { - List notes = new ArrayList<>(); - EnvConfig envc = EnvConfig.create(argv, notes); - if (envc == null) { - if (!notes.isEmpty()) for (EnvConfig.Note n : notes) System.err.println(n.message); - else System.err.println("Usage: java -jar getdown.jar [app_dir] [app_id] [app args]"); - System.exit(-1); - } + /** + * Runs Getdown as an application, using the arguments supplie as {@code argv}. + * @return the {@code Getdown} instance that is running. {@link Getdown#start} will have been + * called on it. + * @throws Exception if anything goes wrong starting Getdown. + */ + public static Getdown start (String[] argv) throws Exception { + List notes = new ArrayList<>(); + EnvConfig envc = EnvConfig.create(argv, notes); + if (envc == null) { + if (!notes.isEmpty()) for (EnvConfig.Note n : notes) System.err.println(n.message); + else System.err.println("Usage: java -jar getdown.jar [app_dir] [app_id] [app args]"); + System.exit(-1); + } - // pipe our output into a file in the application directory - if (!SysProps.noLogRedir()) { - File logFile = new File(envc.appDir, "launcher.log"); - try { - PrintStream logOut = new PrintStream( - new BufferedOutputStream(new FileOutputStream(logFile)), true); - System.setOut(logOut); - System.setErr(logOut); - } catch (IOException ioe) { - log.warning("Unable to redirect output to '" + logFile + "': " + ioe); - } - } + // pipe our output into a file in the application directory + if (!SysProps.noLogRedir()) { + File logFile = new File(envc.appDir, "launcher.log"); + try { + PrintStream logOut = new PrintStream( + new BufferedOutputStream(new FileOutputStream(logFile)), true); + System.setOut(logOut); + System.setErr(logOut); + } catch (IOException ioe) { + log.warning("Unable to redirect output to '" + logFile + "': " + ioe); + } + } - // report any notes from reading our env config, and abort if necessary - boolean abort = false; - for (EnvConfig.Note note : notes) { - switch (note.level) { - case INFO: log.info(note.message); break; - case WARN: log.warning(note.message); break; - case ERROR: log.error(note.message); abort = true; break; - } - } - if (abort) System.exit(-1); - - // record a few things for posterity - log.info("------------------ VM Info ------------------"); - log.info("-- OS Name: " + System.getProperty("os.name")); - log.info("-- OS Arch: " + System.getProperty("os.arch")); - log.info("-- OS Vers: " + System.getProperty("os.version")); - log.info("-- Java Vers: " + System.getProperty("java.version")); - log.info("-- Java Home: " + System.getProperty("java.home")); - log.info("-- User Name: " + System.getProperty("user.name")); - log.info("-- User Home: " + System.getProperty("user.home")); - log.info("-- Cur dir: " + System.getProperty("user.dir")); - log.info("-- JVL: " + System.getProperty("jvl")); - log.info("---------------------------------------------"); - - Getdown app = new Getdown(envc) { - @Override - protected Container createContainer () { - // create our user interface, and display it - if (_frame == null) { - _frame = new JFrame(""); - _frame.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing (WindowEvent evt) { - handleWindowClose(); - } - }); - // handle close on ESC - String cancelId = "Cancel"; // $NON-NLS-1$ - _frame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelId); - _frame.getRootPane().getActionMap().put(cancelId, new AbstractAction() { - public void actionPerformed (ActionEvent e) { - handleWindowClose(); - } - }); - // 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); - _frame.setResizable(false); - } else { - _frame.getContentPane().removeAll(); + // report any notes from reading our env config, and abort if necessary + boolean abort = false; + for (EnvConfig.Note note : notes) { + switch (note.level) { + case INFO: log.info(note.message); break; + case WARN: log.warning(note.message); break; + case ERROR: log.error(note.message); abort = true; break; + } + } + if (abort) System.exit(-1); + + try + { + log.info("**** Registering i4j StartupNotification Listener"); + StartupNotification.registerStartupListener( + new StartupNotification.Listener() { + @Override + public void startupPerformed(String parameters) + { + log.info("**** adding startup parameters '"+parameters+"'"); + GetdownApp.setStartupFilesParameterString(parameters); } - _frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - return _frame.getContentPane(); - } + }); + } catch (Exception e) + { + e.printStackTrace(); + } + + Thread.sleep(500); + + // record a few things for posterity + log.info("------------------ VM Info ------------------"); + log.info("-- OS Name: " + System.getProperty("os.name")); + log.info("-- OS Arch: " + System.getProperty("os.arch")); + log.info("-- OS Vers: " + System.getProperty("os.version")); + log.info("-- Java Vers: " + System.getProperty("java.version")); + log.info("-- Java Home: " + System.getProperty("java.home")); + log.info("-- User Name: " + System.getProperty("user.name")); + log.info("-- User Home: " + System.getProperty("user.home")); + log.info("-- Cur dir: " + System.getProperty("user.dir")); + log.info("-- JVL: " + System.getProperty("jvl")); + log.info("-- startupFilesParameterString: " + startupFilesParameterString); + log.info("---------------------------------------------"); + Getdown app = new Getdown(envc) { + @Override + protected Container createContainer () { + // create our user interface, and display it + if (_frame == null) { + _frame = new JFrame(""); + _frame.addWindowListener(new WindowAdapter() { @Override - protected void configureContainer () { - if (_frame == null) return; + public void windowClosing (WindowEvent evt) { + handleWindowClose(); + } + }); + // handle close on ESC + String cancelId = "Cancel"; // $NON-NLS-1$ + _frame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( + KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelId); + _frame.getRootPane().getActionMap().put(cancelId, new AbstractAction() { + public void actionPerformed (ActionEvent e) { + handleWindowClose(); + } + }); + // 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); + _frame.setResizable(false); + } else { + _frame.getContentPane().removeAll(); + } + _frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); + return _frame.getContentPane(); + } - _frame.setTitle(_ifc.name); + @Override + protected void configureContainer () { + if (_frame == null) return; - try { - _frame.setBackground(new Color(_ifc.background, true)); - } catch (Exception e) { - log.warning("Failed to set background", "bg", _ifc.background, e); - } + _frame.setTitle(_ifc.name); - if (_ifc.iconImages != null) { - ArrayList icons = new ArrayList<>(); - for (String path : _ifc.iconImages) { - Image img = loadImage(path); - if (img == null) { - log.warning("Error loading icon image", "path", path); - } else { - icons.add(img); - } - } - if (icons.isEmpty()) { - log.warning("Failed to load any icons", "iconImages", _ifc.iconImages); - } else { - _frame.setIconImages(icons); - } - } - } + try { + _frame.setBackground(new Color(_ifc.background, true)); + } catch (Exception e) { + log.warning("Failed to set background", "bg", _ifc.background, e); + } - @Override - protected void showContainer () { - if (_frame != null) { - _frame.pack(); - SwingUtil.centerWindow(_frame); - _frame.setVisible(true); - } + if (_ifc.iconImages != null) { + ArrayList icons = new ArrayList<>(); + for (String path : _ifc.iconImages) { + Image img = loadImage(path); + if (img == null) { + log.warning("Error loading icon image", "path", path); + } else { + icons.add(img); } + } + if (icons.isEmpty()) { + log.warning("Failed to load any icons", "iconImages", _ifc.iconImages); + } else { + _frame.setIconImages(icons); + } + } + } - @Override - protected void disposeContainer () { - if (_frame != null) { - _frame.dispose(); - _frame = null; - } - } + @Override + protected void showContainer () { + if (_frame != null) { + _frame.pack(); + SwingUtil.centerWindow(_frame); + _frame.setVisible(true); + } + } - @Override - protected void showDocument (String url) { - if (!StringUtil.couldBeValidUrl(url)) { - // command injection would be possible if we allowed e.g. spaces and double quotes - log.warning("Invalid document URL.", "url", url); - return; - } - String[] cmdarray; - if (LaunchUtil.isWindows()) { - String osName = System.getProperty("os.name", ""); - if (osName.indexOf("9") != -1 || osName.indexOf("Me") != -1) { - cmdarray = new String[] { - "command.com", "/c", "start", "\"" + url + "\"" }; - } else { - cmdarray = new String[] { - "cmd.exe", "/c", "start", "\"\"", "\"" + url + "\"" }; - } - } else if (LaunchUtil.isMacOS()) { - cmdarray = new String[] { "open", url }; - } else { // Linux, Solaris, etc. - cmdarray = new String[] { "firefox", url }; - } - try { - Runtime.getRuntime().exec(cmdarray); - } catch (Exception e) { - log.warning("Failed to open browser.", "cmdarray", cmdarray, e); - } - } + @Override + protected void disposeContainer () { + if (_frame != null) { + _frame.dispose(); + _frame = null; + } + } - @Override - protected void exit (int exitCode) { - // if we're running the app in the same JVM, don't call System.exit, but do - // make double sure that the download window is closed. - if (invokeDirect()) { - disposeContainer(); - } else { - System.exit(exitCode); - } - } + @Override + protected void showDocument (String url) { + if (!StringUtil.couldBeValidUrl(url)) { + // command injection would be possible if we allowed e.g. spaces and double quotes + log.warning("Invalid document URL.", "url", url); + return; + } + String[] cmdarray; + if (LaunchUtil.isWindows()) { + String osName = System.getProperty("os.name", ""); + if (osName.indexOf("9") != -1 || osName.indexOf("Me") != -1) { + cmdarray = new String[] { + "command.com", "/c", "start", "\"" + url + "\"" }; + } else { + cmdarray = new String[] { + "cmd.exe", "/c", "start", "\"\"", "\"" + url + "\"" }; + } + } else if (LaunchUtil.isMacOS()) { + cmdarray = new String[] { "open", url }; + } else { // Linux, Solaris, etc. + cmdarray = new String[] { "firefox", url }; + } + try { + Runtime.getRuntime().exec(cmdarray); + } catch (Exception e) { + log.warning("Failed to open browser.", "cmdarray", cmdarray, e); + } + } - @Override - protected void fail (String message) { - super.fail(message); - // super.fail causes the UI to be created (if needed) on the next UI tick, so we - // want to wait until that happens before we attempt to redecorate the window - EventQueue.invokeLater(new Runnable() { - @Override - public void run() { - // if the frame was set to be undecorated, make window decoration available - // to allow the user to close the window - if (_frame != null && _frame.isUndecorated()) { - _frame.dispose(); - Color bg = _frame.getBackground(); - if (bg != null && bg.getAlpha() < 255) { - // decorated windows do not allow alpha backgrounds - _frame.setBackground( - new Color(bg.getRed(), bg.getGreen(), bg.getBlue())); - } - _frame.setUndecorated(false); - showContainer(); - } - } - }); + @Override + protected void exit (int exitCode) { + // if we're running the app in the same JVM, don't call System.exit, but do + // make double sure that the download window is closed. + if (invokeDirect()) { + disposeContainer(); + } else { + System.exit(exitCode); + } + } + + @Override + protected void fail (String message) { + super.fail(message); + // super.fail causes the UI to be created (if needed) on the next UI tick, so we + // want to wait until that happens before we attempt to redecorate the window + EventQueue.invokeLater(new Runnable() { + @Override + public void run() { + // if the frame was set to be undecorated, make window decoration available + // to allow the user to close the window + if (_frame != null && _frame.isUndecorated()) { + _frame.dispose(); + Color bg = _frame.getBackground(); + if (bg != null && bg.getAlpha() < 255) { + // decorated windows do not allow alpha backgrounds + _frame.setBackground( + new Color(bg.getRed(), bg.getGreen(), bg.getBlue())); + } + _frame.setUndecorated(false); + showContainer(); } + } + }); + } - protected JFrame _frame; - }; - app.start(); - return app; - } + protected JFrame _frame; + }; + app.start(); + return app; + } + + public static void setStartupFilesParameterString(String parameters) { + startupFilesParameterString = parameters; + } } diff --git a/getdown/src/getdown/pom.xml b/getdown/src/getdown/pom.xml index 66ebf0f..17cb8f6 100644 --- a/getdown/src/getdown/pom.xml +++ b/getdown/src/getdown/pom.xml @@ -47,6 +47,13 @@ ant + + + ej-technologies + https://maven.ej-technologies.com/repository + + + @@ -54,6 +61,12 @@ commons-compress 1.18 + + com.install4j + install4j-runtime + 7.0.11 + + diff --git a/j11lib/i4jruntime.jar b/j11lib/i4jruntime.jar new file mode 100644 index 0000000..4be2a73 Binary files /dev/null and b/j11lib/i4jruntime.jar differ diff --git a/j8lib/i4jruntime.jar b/j8lib/i4jruntime.jar new file mode 100644 index 0000000..4be2a73 Binary files /dev/null and b/j8lib/i4jruntime.jar differ diff --git a/utils/install4j/install4j_template.install4j b/utils/install4j/install4j_template.install4j index 861a81a..cf00519 100644 --- a/utils/install4j/install4j_template.install4j +++ b/utils/install4j/install4j_template.install4j @@ -7,7 +7,6 @@ -