JAL-3660 Fix for specified output format when using command line arg to convert a...
[jalview.git] / src / jalview / bin / Jalview.java
index cfcc2f7..08cbcb2 100755 (executable)
@@ -43,8 +43,8 @@ import java.util.logging.ConsoleHandler;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import javax.swing.LookAndFeel;
 import javax.swing.UIManager;
+import javax.swing.UIManager.LookAndFeelInfo;
 
 import com.threerings.getdown.util.LaunchUtil;
 
@@ -60,6 +60,7 @@ import jalview.io.DataSourceType;
 import jalview.io.FileFormat;
 import jalview.io.FileFormatException;
 import jalview.io.FileFormatI;
+import jalview.io.FileFormats;
 import jalview.io.FileLoader;
 import jalview.io.HtmlSvgOutput;
 import jalview.io.IdentifyFile;
@@ -367,10 +368,20 @@ public class Jalview
 
     desktop = null;
 
-    // property laf = "crossplatform", "system", "gtk" or "mac"
+    // property laf = "crossplatform", "system", "gtk", "metal" or "mac"
     // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
     // try Quaqua/Vaqua.
-    String laf = System.getProperty("laf", "none");
+    String lafProp = System.getProperty("laf");
+    String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
+    String laf = "none";
+    if (lafProp != null)
+    {
+      laf = lafProp;
+    }
+    else if (lafSetting != null)
+    {
+      laf = lafSetting;
+    }
     boolean lafSet = false;
     switch (laf)
     {
@@ -390,9 +401,33 @@ public class Jalview
       break;
     case "gtk":
       lafSet = setGtkLookAndFeel();
-      {
-        System.err.println("Could not set requested laf=" + laf);
-      }
+    {
+      System.err.println("Could not set requested laf=" + laf);
+    }
+      break;
+    case "metal":
+      lafSet = setMetalLookAndFeel();
+    {
+      System.err.println("Could not set requested laf=" + laf);
+    }
+      break;
+    case "nimbus":
+      lafSet = setNimbusLookAndFeel();
+    {
+      System.err.println("Could not set requested laf=" + laf);
+    }
+      break;
+    case "quaqua":
+      lafSet = setQuaquaLookAndFeel();
+    {
+      System.err.println("Could not set requested laf=" + laf);
+    }
+      break;
+    case "vaqua":
+      lafSet = setVaquaLookAndFeel();
+    {
+      System.err.println("Could not set requested laf=" + laf);
+    }
       break;
     case "mac":
       lafSet = setMacLookAndFeel();
@@ -409,6 +444,10 @@ public class Jalview
     if (!lafSet)
     {
       setSystemLookAndFeel();
+      if (Platform.isLinux() && !Platform.isJS())
+      {
+        setMetalLookAndFeel();
+      }
       if (Platform.isAMacAndNotJS())
       {
         setMacLookAndFeel();
@@ -427,6 +466,7 @@ public class Jalview
 
     if (!headless)
     {
+
       desktop = new Desktop();
       desktop.setInBatchMode(true); // indicate we are starting up
 
@@ -754,17 +794,37 @@ public class Jalview
             af.createEPS(outputFile);
             continue;
           }
-
-          af.saveAlignment(file, format);
-          if (af.isSaveAlignmentSuccessful())
+          FileFormatI outFormat = null;
+          try
           {
-            System.out.println("Written alignment in " + format
-                    + " format to " + file);
+            outFormat = FileFormats.getInstance().forName(outputFormat);
+          } catch (Exception formatP)
+          {
+            System.out.println("Couldn't parse " + outFormat
+                    + " as a valid Jalview format string.");
           }
-          else
+          if (outFormat != null)
           {
-            System.out.println("Error writing file " + file + " in "
-                    + format + " format!!");
+            if (!outFormat.isWritable())
+            {
+              System.out.println(
+                      "This version of Jalview does not support alignment export as "
+                              + outputFormat);
+            }
+            else
+            {
+              af.saveAlignment(file, outFormat);
+              if (af.isSaveAlignmentSuccessful())
+              {
+                System.out.println("Written alignment in "
+                        + outFormat.getName() + " format to " + file);
+              }
+              else
+              {
+                System.out.println("Error writing file " + file + " in "
+                        + outFormat.getName() + " format!!");
+              }
+            }
           }
 
         }
@@ -855,11 +915,22 @@ public class Jalview
 
   private static boolean setCrossPlatformLookAndFeel()
   {
+    return setGenericLookAndFeel(false);
+  }
+
+  private static boolean setSystemLookAndFeel()
+  {
+    return setGenericLookAndFeel(true);
+  }
+
+  private static boolean setGenericLookAndFeel(boolean system)
+  {
     boolean set = false;
     try
     {
       UIManager.setLookAndFeel(
-              UIManager.getCrossPlatformLookAndFeelClassName());
+              system ? UIManager.getSystemLookAndFeelClassName()
+                      : UIManager.getCrossPlatformLookAndFeelClassName());
       set = true;
     } catch (Exception ex)
     {
@@ -869,12 +940,24 @@ public class Jalview
     return set;
   }
 
-  private static boolean setSystemLookAndFeel()
+  private static boolean setSpecificLookAndFeel(String name,
+          String className, boolean nameStartsWith)
   {
     boolean set = false;
     try
     {
-      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+      for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
+      {
+        if (info.getName() != null && nameStartsWith
+                ? info.getName().toLowerCase()
+                        .startsWith(name.toLowerCase())
+                : info.getName().toLowerCase().equals(name.toLowerCase()))
+        {
+          className = info.getClassName();
+          break;
+        }
+      }
+      UIManager.setLookAndFeel(className);
       set = true;
     } catch (Exception ex)
     {
@@ -886,57 +969,47 @@ public class Jalview
 
   private static boolean setGtkLookAndFeel()
   {
-    boolean set = false;
-    String laf = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
-    try
-    {
-      UIManager.setLookAndFeel(laf);
-      set = true;
-    } catch (Exception ex)
-    {
-      System.err.println("Unexpected Look and Feel Exception");
-      ex.printStackTrace();
-    }
-    return set;
+    return setSpecificLookAndFeel("gtk",
+            "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true);
+  }
+
+  private static boolean setMetalLookAndFeel()
+  {
+    return setSpecificLookAndFeel("metal",
+            "javax.swing.plaf.metal.MetalLookAndFeel", false);
+  }
+
+  private static boolean setNimbusLookAndFeel()
+  {
+    return setSpecificLookAndFeel("nimbus",
+            "javax.swing.plaf.nimbus.NimbusLookAndFeel", false);
+  }
+
+  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;
-    LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
-            .getLookAndFeel();
     System.setProperty("com.apple.mrj.application.apple.menu.about.name",
             "Jalview");
     System.setProperty("apple.laf.useScreenMenuBar", "true");
-    if (lookAndFeel != null)
-    {
-      try
-      {
-        UIManager.setLookAndFeel(lookAndFeel);
-        set = true;
-      } catch (Throwable e)
-      {
-        System.err.println(
-                "Failed to set QuaQua look and feel: " + e.toString());
-      }
-    }
-    if (lookAndFeel == null
-            || !(lookAndFeel.getClass().isAssignableFrom(
-                    UIManager.getLookAndFeel().getClass()))
-            || !UIManager.getLookAndFeel().getClass().toString()
-                    .toLowerCase().contains("quaqua"))
+    set = setQuaquaLookAndFeel();
+    if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
+            .toLowerCase().contains("quaqua"))
     {
-      try
-      {
-        System.err.println(
-                "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
-        UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
-        set = true;
-      } catch (Throwable e)
-      {
-        System.err
-                .println("Failed to reset look and feel: " + e.toString());
-      }
+      set = setVaquaLookAndFeel();
     }
     return set;
   }
@@ -979,6 +1052,8 @@ public class Jalview
                     + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
                     + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
                     + "-groovy FILE\tExecute groovy script in FILE, after all other arguments have been processed (if FILE is the text 'STDIN' then the file will be read from STDIN)\n"
+                    + "-jvmmempc=PERCENT\tOnly available with standalone executable jar or jalview.bin.Launcher. Limit maximum heap size (memory) to PERCENT% of total physical memory detected. This defaults to 90 if total physical memory can be detected. See https://www.jalview.org/help/html/memory.html for more details.\n"
+                    + "-jvmmemmax=MAXMEMORY\tOnly available with standalone executable jar or jalview.bin.Launcher. Limit maximum heap size (memory) to MAXMEMORY. MAXMEMORY can be specified in bytes, kilobytes(k), megabytes(m), gigabytes(g) or if you're lucky enough, terabytes(t). This defaults to 32g if total physical memory can be detected, or to 8g if total physical memory cannot be detected. See https://www.jalview.org/help/html/memory.html for more details.\n"
                     + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
   }