X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fbin%2FJalview.java;h=04cf2a35709d6b8435e16b68d7db2aa7c8cdb5f6;hb=156ab6ab1046c02dc327c2ac986afa336f0bbf3b;hp=b87a14d0f22a748e1a674f437baf917ad178f369;hpb=952d6b6fecfb976c0c113f013ed2b8980af3d190;p=jalview.git diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index b87a14d..04cf2a3 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -40,23 +40,29 @@ import java.security.Policy; import java.util.HashMap; import java.util.Locale; import java.util.Map; +import java.util.Properties; import java.util.Vector; import java.util.logging.ConsoleHandler; import java.util.logging.Level; import java.util.logging.Logger; +import javax.swing.JDialog; +import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.UIManager.LookAndFeelInfo; +import javax.swing.UnsupportedLookAndFeelException; import com.formdev.flatlaf.FlatLightLaf; +import com.formdev.flatlaf.themes.FlatMacLightLaf; import com.formdev.flatlaf.util.SystemInfo; import com.threerings.getdown.util.LaunchUtil; //import edu.stanford.ejalbert.launching.IBrowserLaunching; import groovy.lang.Binding; import groovy.util.GroovyScriptEngine; +import jalview.bin.ArgParser.Arg; import jalview.ext.so.SequenceOntology; import jalview.gui.AlignFrame; import jalview.gui.Desktop; @@ -273,30 +279,12 @@ public class Jalview if (!Platform.isJS()) { System.setSecurityManager(null); - - Runtime.getRuntime().addShutdownHook(new Thread() - { - public void run() - { - Console.debug("Running shutdown hook"); - if (QuitHandler.gotQuitResponse() == QResponse.CANCEL_QUIT) - { - // Got to here by a SIGTERM signal. - // Note we will not actually cancel the quit from here -- it's too - // late -- but we can wait for saving files. - Console.debug("Checking for saving files"); - QuitHandler.getQuitResponse(false); - } - else - { - Console.debug("Nothing more to do"); - } - Console.debug("Exiting, bye!"); - // shutdownHook cannot be cancelled, JVM will now halt - } - }); } + // get args needed before proper ArgParser + Map bootstrapArgs = ArgParser + .bootstrapArgs(args); + System.out .println("Java version: " + System.getProperty("java.version")); System.out.println("Java Home: " + System.getProperty("java.home")); @@ -320,22 +308,79 @@ public class Jalview System.out.println("Launcher version: " + val); } + if (Platform.isLinux() && LaunchUtils.getJavaVersion() < 11) + { + System.setProperty("flatlaf.uiScale", "1"); + } + + // get bootstrap properties (mainly for the logger level) + Properties bootstrapProperties = Cache + .bootstrapProperties(bootstrapArgs.get(Arg.PROPS)); + // report Jalview version Cache.loadBuildProperties(true); + // old ArgsParser ArgsParser aparser = new ArgsParser(args); + // old boolean headless = false; + // new + boolean headlessArg = false; + + try + { + String logLevel = bootstrapArgs.containsKey(Arg.DEBUG) ? "DEBUG" + : null; + if (logLevel == null && !(bootstrapProperties == null)) + { + logLevel = bootstrapProperties.getProperty(Cache.JALVIEWLOGLEVEL); + } + Console.initLogger(logLevel); + } catch (NoClassDefFoundError error) + { + error.printStackTrace(); + System.out.println("\nEssential logging libraries not found." + + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview"); + System.exit(0); + } - String usrPropsFile = aparser.getValue("props"); - Cache.loadProperties(usrPropsFile); // must do this - // before + // register SIGTERM listener + Runtime.getRuntime().addShutdownHook(new Thread() + { + public void run() + { + Console.debug("Running shutdown hook"); + if (QuitHandler.gotQuitResponse() == QResponse.CANCEL_QUIT) + { + // Got to here by a SIGTERM signal. + // Note we will not actually cancel the quit from here -- it's too + // late -- but we can wait for saving files. + Console.debug("Checking for saving files"); + QuitHandler.getQuitResponse(false); + } + else + { + Console.debug("Nothing more to do"); + } + Console.debug("Exiting, bye!"); + // shutdownHook cannot be cancelled, JVM will now halt + } + }); + + String usrPropsFile = bootstrapArgs.containsKey(Arg.PROPS) + ? bootstrapArgs.get(Arg.PROPS) + : aparser.getValue("props"); + Cache.loadProperties(usrPropsFile); if (usrPropsFile != null) { System.out.println( "CMD [-props " + usrPropsFile + "] executed successfully!"); } + // new ArgParser + ArgParser argparser = new ArgParser(args); + if (!Platform.isJS()) /** * Java only @@ -343,15 +388,24 @@ public class Jalview * @j2sIgnore */ { - if (aparser.contains("help") || aparser.contains("h")) + if (aparser.contains("help") || aparser.contains("h") + || argparser.getBool(Arg.HELP)) { showUsage(); System.exit(0); } + + if (argparser.isSet(Arg.HEADLESS)) + { + System.setProperty("java.awt.headless", "true"); + // new + headlessArg = argparser.getBool(Arg.HEADLESS); + } if (aparser.contains("nodisplay") || aparser.contains("nogui") || aparser.contains("headless")) { System.setProperty("java.awt.headless", "true"); + // old headless = true; } // anything else! @@ -416,10 +470,10 @@ public class Jalview + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview"); System.exit(0); } - desktop = null; - setLookAndFeel(); + if (!(headless || headlessArg)) + setLookAndFeel(); /* * configure 'full' SO model if preferences say to, else use the default (full SO) @@ -431,7 +485,7 @@ public class Jalview SequenceOntologyFactory.setInstance(new SequenceOntology()); } - if (!headless) + if (!(headless || headlessArg)) { Desktop.nosplash = aparser.contains("nosplash"); desktop = new Desktop(); @@ -553,6 +607,20 @@ public class Jalview } } } + // Run Commands from cli + boolean commandsSuccess = Commands.processArgs(argparser, headless); + if (commandsSuccess) + { + Console.info("Successfully completed commands"); + if (headlessArg) + System.exit(0); + } + else + { + Console.warn("Error when running commands"); + if (headlessArg) + System.exit(1); + } // Check if JVM and compile version might cause problems and log if it // might. @@ -666,7 +734,7 @@ public class Jalview if (cs != null) { System.out.println( - "CMD [-color " + data + "] executed successfully!"); + "CMD [-colour " + data + "] executed successfully!"); } af.changeColour(cs); } @@ -910,6 +978,10 @@ public class Jalview startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol, format); + // don't ask to save when quitting if only the startup file has been + // opened + Console.debug("Resetting up-to-date flag for startup file"); + startUpAlframe.getViewport().setSavedUpToDate(true); // extract groovy arguments before anything else. } @@ -1001,20 +1073,6 @@ public class Jalview Console.error("Could not set requested laf=" + laf); } break; - case "quaqua": - lafSet = setQuaquaLookAndFeel(); - if (!lafSet) - { - Console.error("Could not set requested laf=" + laf); - } - break; - case "vaqua": - lafSet = setVaquaLookAndFeel(); - if (!lafSet) - { - Console.error("Could not set requested laf=" + laf); - } - break; case "mac": lafSet = setMacLookAndFeel(); if (!lafSet) @@ -1032,7 +1090,7 @@ public class Jalview setSystemLookAndFeel(); if (Platform.isLinux()) { - setMetalLookAndFeel(); + setLinuxLookAndFeel(); } if (Platform.isMac()) { @@ -1123,34 +1181,104 @@ public class Jalview private static boolean setFlatLookAndFeel() { - boolean set = setSpecificLookAndFeel("flatlaf light", - "com.formdev.flatlaf.FlatLightLaf", false); - if (set) + boolean set = false; + if (SystemInfo.isMacOS) { - if (Platform.isMac()) + try { - System.setProperty("apple.laf.useScreenMenuBar", "true"); - System.setProperty("apple.awt.application.name", - ChannelProperties.getProperty("app_name")); - System.setProperty("apple.awt.application.appearance", "system"); - if (SystemInfo.isMacFullWindowContentSupported - && Desktop.desktop != null) - { - Desktop.desktop.getRootPane() - .putClientProperty("apple.awt.fullWindowContent", true); - Desktop.desktop.getRootPane() - .putClientProperty("apple.awt.transparentTitleBar", true); - } + UIManager.setLookAndFeel( + "com.formdev.flatlaf.themes.FlatMacLightLaf"); + set = true; + Console.debug("Using FlatMacLightLaf"); + } catch (ClassNotFoundException | InstantiationException + | IllegalAccessException | UnsupportedLookAndFeelException e) + { + Console.debug("Exception loading FlatLightLaf", e); + } + System.setProperty("apple.laf.useScreenMenuBar", "true"); + System.setProperty("apple.awt.application.name", + ChannelProperties.getProperty("app_name")); + System.setProperty("apple.awt.application.appearance", "system"); + if (SystemInfo.isMacFullWindowContentSupported + && Desktop.desktop != null) + { + Console.debug("Setting transparent title bar"); + Desktop.desktop.getRootPane() + .putClientProperty("apple.awt.fullWindowContent", true); + Desktop.desktop.getRootPane() + .putClientProperty("apple.awt.transparentTitleBar", true); + Desktop.desktop.getRootPane() + .putClientProperty("apple.awt.fullscreenable", true); + } + SwingUtilities.invokeLater(() -> { + FlatMacLightLaf.setup(); + }); + Console.debug("Using FlatMacLightLaf"); + set = true; + } + if (!set) + { + try + { + UIManager.setLookAndFeel("com.formdev.flatlaf.FlatLightLaf"); + set = true; + Console.debug("Using FlatLightLaf"); + } catch (ClassNotFoundException | InstantiationException + | IllegalAccessException | UnsupportedLookAndFeelException e) + { + Console.debug("Exception loading FlatLightLaf", e); + } + // Windows specific properties here + SwingUtilities.invokeLater(() -> { + FlatLightLaf.setup(); + }); + Console.debug("Using FlatLightLaf"); + set = true; + } + else if (SystemInfo.isLinux) + { + try + { + UIManager.setLookAndFeel("com.formdev.flatlaf.FlatLightLaf"); + set = true; + Console.debug("Using FlatLightLaf"); + } catch (ClassNotFoundException | InstantiationException + | IllegalAccessException | UnsupportedLookAndFeelException e) + { + Console.debug("Exception loading FlatLightLaf", e); + } + // enable custom window decorations + JFrame.setDefaultLookAndFeelDecorated(true); + JDialog.setDefaultLookAndFeelDecorated(true); + SwingUtilities.invokeLater(() -> { + FlatLightLaf.setup(); + }); + Console.debug("Using FlatLightLaf"); + set = true; + } - SwingUtilities.invokeLater(() -> { - FlatLightLaf.setup(); - }); + if (!set) + { + try + { + UIManager.setLookAndFeel("com.formdev.flatlaf.FlatLightLaf"); + set = true; + Console.debug("Using FlatLightLaf"); + } catch (ClassNotFoundException | InstantiationException + | IllegalAccessException | UnsupportedLookAndFeelException e) + { + Console.debug("Exception loading FlatLightLaf", e); } + } + if (set) + { + UIManager.put("TabbedPane.tabType", "card"); UIManager.put("TabbedPane.showTabSeparators", true); + UIManager.put("TabbedPane.showContentSeparator", true); UIManager.put("TabbedPane.tabSeparatorsFullHeight", true); UIManager.put("TabbedPane.tabsOverlapBorder", true); - // UIManager.put("TabbedPane.hasFullBorder", true); + UIManager.put("TabbedPane.hasFullBorder", true); UIManager.put("TabbedPane.tabLayoutPolicy", "scroll"); UIManager.put("TabbedPane.scrollButtonsPolicy", "asNeeded"); UIManager.put("TabbedPane.smoothScrolling", true); @@ -1162,20 +1290,6 @@ public class Jalview return set; } - private static boolean setQuaquaLookAndFeel() - { - return setSpecificLookAndFeel("quaqua", - ch.randelshofer.quaqua.QuaquaManager.getLookAndFeel().getClass() - .getName(), - false); - } - - private static boolean setVaquaLookAndFeel() - { - return setSpecificLookAndFeel("vaqua", - "org.violetlib.aqua.AquaLookAndFeel", false); - } - private static boolean setMacLookAndFeel() { boolean set = false; @@ -1195,6 +1309,18 @@ public class Jalview return set; } + private static boolean setLinuxLookAndFeel() + { + boolean set = false; + set = setFlatLookAndFeel(); + if (!set) + set = setMetalLookAndFeel(); + // avoid GtkLookAndFeel -- not good results especially on HiDPI + if (!set) + set = setNimbusLookAndFeel(); + return set; + } + private static void showUsage() { System.out.println(