Merge branch 'develop' into features/r2_11_2_alphafold/JAL-629
[jalview.git] / src / jalview / bin / Jalview.java
index 071d700..402235b 100755 (executable)
@@ -61,6 +61,7 @@ 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;
@@ -324,13 +325,30 @@ public class Jalview
       System.out.println("Launcher version: " + val);
     }
 
+    if (Platform.isLinux() && LaunchUtils.getJavaVersion() < 11)
+    {
+      System.setProperty("flatlaf.uiScale", "1");
+    }
+
     // report Jalview version
     Cache.loadBuildProperties(true);
 
+    // old ArgsParser
     ArgsParser aparser = new ArgsParser(args);
 
     boolean headless = false;
 
+    try
+    {
+      Console.initLogger();
+    } 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
@@ -340,6 +358,31 @@ public class Jalview
               "CMD [-props " + usrPropsFile + "] executed successfully!");
     }
 
+    // set log level from cache properties
+    Console.setLogLevel(Cache.getDefault(Cache.JALVIEWLOGLEVEL, "INFO"));
+
+    // new ArgParser
+    ArgParser argparser = new ArgParser(args); // do this after
+                                               // Console.initLogger, but TODO
+                                               // want --props before then
+                                               // CATCH22
+
+    if (argparser.isSet(Arg.HEADLESS))
+      headless = argparser.getBool(Arg.HEADLESS);
+    boolean commandsSuccess = Commands.processArgs(argparser, headless);
+    if (commandsSuccess)
+    {
+      Console.info("Successfully completed commands");
+      if (headless)
+        System.exit(0);
+    }
+    else
+    {
+      Console.warn("Error when running commands");
+      if (headless)
+        System.exit(1);
+    }
+
     if (!Platform.isJS())
     /**
      * Java only
@@ -347,13 +390,18 @@ public class Jalview
      * @j2sIgnore
      */
     {
+      if (argparser.isSet(Arg.HEADLESS))
+      {
+        headless = argparser.getBool(Arg.HEADLESS);
+      }
+
       if (aparser.contains("help") || aparser.contains("h"))
       {
         showUsage();
         System.exit(0);
       }
-      if (aparser.contains("nodisplay") || aparser.contains("nogui")
-              || aparser.contains("headless"))
+      if (headless || aparser.contains("nodisplay")
+              || aparser.contains("nogui") || aparser.contains("headless"))
       {
         System.setProperty("java.awt.headless", "true");
         headless = true;
@@ -880,8 +928,6 @@ public class Jalview
      * @j2sIgnore
      */
     {
-      boolean defaultStartupFile = Cache.getDefault("STARTUP_FILE",
-              null) == null;
       file = Cache.getDefault("STARTUP_FILE",
               Cache.getDefault("www.jalview.org", "https://www.jalview.org")
                       + "/examples/exampleFile_2_7.jvp");
@@ -895,7 +941,6 @@ public class Jalview
         file.replace("2_7.jar", "2_7.jvp");
         // and remove the stale setting
         Cache.removeProperty("STARTUP_FILE");
-        defaultStartupFile = true;
       }
 
       protocol = AppletFormatAdapter.checkProtocol(file);
@@ -917,11 +962,10 @@ public class Jalview
 
       startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
               format);
-      if (defaultStartupFile)
-      {
-        Console.debug("Resetting up-to-date flag for startup file");
-        startUpAlframe.getViewport().setSavedUpToDate(true);
-      }
+      // 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.
     }
 
@@ -1126,7 +1170,8 @@ public class Jalview
     {
       try
       {
-        UIManager.setLookAndFeel("com.formdev.flatlaf.FlatMacLightLaf");
+        UIManager.setLookAndFeel(
+                "com.formdev.flatlaf.themes.FlatMacLightLaf");
         set = true;
         Console.debug("Using FlatMacLightLaf");
       } catch (ClassNotFoundException | InstantiationException
@@ -1155,7 +1200,7 @@ public class Jalview
       Console.debug("Using FlatMacLightLaf");
       set = true;
     }
-    else if (SystemInfo.isWindows)
+    if (!set)
     {
       try
       {