JAL-3608 Added java builtin NimbusLookAndFeel option 'nimbus'
[jalview.git] / src / jalview / bin / Jalview.java
index 5c026fd..992ca01 100755 (executable)
@@ -45,6 +45,7 @@ import java.util.logging.Logger;
 
 import javax.swing.LookAndFeel;
 import javax.swing.UIManager;
+import javax.swing.UIManager.LookAndFeelInfo;
 
 import com.threerings.getdown.util.LaunchUtil;
 
@@ -367,7 +368,7 @@ public class Jalview
 
     desktop = null;
 
-    // property laf = "crossplatform", "system" 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");
@@ -388,6 +389,24 @@ public class Jalview
         System.err.println("Could not set requested laf=" + laf);
       }
       break;
+    case "gtk":
+      lafSet = setGtkLookAndFeel();
+      {
+        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 "mac":
       lafSet = setMacLookAndFeel();
       if (!lafSet)
@@ -403,6 +422,9 @@ public class Jalview
     if (!lafSet)
     {
       setSystemLookAndFeel();
+      if (Platform.isLinux() && ! Platform.isJS()) {
+        setMetalLookAndFeel();
+      }
       if (Platform.isAMacAndNotJS())
       {
         setMacLookAndFeel();
@@ -878,6 +900,72 @@ public class Jalview
     return set;
   }
 
+  private static boolean setGtkLookAndFeel()
+  {
+    boolean set = false;
+    String laf = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
+    try
+    {
+      for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
+        if (info.getName() != null && info.getName().startsWith("Gtk")) {
+          laf = info.getClassName();
+          break;
+        }
+      }
+      UIManager.setLookAndFeel(laf);
+      set = true;
+    } catch (Exception ex)
+    {
+      System.err.println("Unexpected Look and Feel Exception");
+      ex.printStackTrace();
+    }
+    return set;
+  }
+
+  private static boolean setMetalLookAndFeel()
+  {
+    boolean set = false;
+    String laf = "javax.swing.plaf.metal.MetalLookAndFeel";
+    try
+    {
+      for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
+        if (info.getName() != null && info.getName().equals("Metal")) {
+          laf = info.getClassName();
+          break;
+        }
+      }
+      UIManager.setLookAndFeel(laf);
+      set = true;
+    } catch (Exception ex)
+    {
+      System.err.println("Unexpected Look and Feel Exception");
+      ex.printStackTrace();
+    }
+    return set;
+  }
+
+  private static boolean setNimbusLookAndFeel()
+  {
+    boolean set = false;
+    String laf = "javax.swing.plaf.nimbus.NimbusLookAndFeel";
+    try
+    {
+      for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
+        if (info.getName() != null && info.getName().equals("Nimbus")) {
+          laf = info.getClassName();
+          break;
+        }
+      }
+      UIManager.setLookAndFeel(laf);
+      set = true;
+    } catch (Exception ex)
+    {
+      System.err.println("Unexpected Look and Feel Exception");
+      ex.printStackTrace();
+    }
+    return set;
+  }
+
   private static boolean setMacLookAndFeel()
   {
     boolean set = false;