JAL-3608 Added CrossPlatform LaF and made configurable with the 'laf' system property...
authorBen Soares <bsoares@dundee.ac.uk>
Wed, 22 Apr 2020 19:18:27 +0000 (20:18 +0100)
committerBen Soares <bsoares@dundee.ac.uk>
Wed, 22 Apr 2020 19:18:27 +0000 (20:18 +0100)
build.gradle
src/jalview/bin/Jalview.java

index 985cc87..453ad5d 100644 (file)
@@ -1030,6 +1030,11 @@ test {
 
   workingDir = jalviewDir
   //systemProperties 'clover.jar' System.properties.clover.jar
+  def testLaf = project.findProperty("test_laf")
+  if (testLaf != null) {
+    println("Setting Test LaF to '${testLaf}'")
+    systemProperty "laf", testLaf
+  }
   sourceCompatibility = compile_source_compatibility
   targetCompatibility = compile_target_compatibility
   jvmArgs += additional_compiler_args
index cdd8cc1..afe4055 100755 (executable)
@@ -369,49 +369,43 @@ public class Jalview
 
     desktop = null;
 
-    try
-    {
-      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
-    } catch (Exception ex)
-    {
-      System.err.println("Unexpected Look and Feel Exception");
-      ex.printStackTrace();
-    }
-    if (Platform.isAMacAndNotJS())
-    {
-
-      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)
+    // property laf = "crossplatform", "system" 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");
+    boolean lafSet = false;
+    switch(laf) {
+    case "crossplatform":
+      lafSet = setCrossPlatformLookAndFeel();
+      if (!lafSet)
       {
-        try
-        {
-          UIManager.setLookAndFeel(lookAndFeel);
-        } catch (Throwable e)
-        {
-          System.err.println(
-                  "Failed to set QuaQua look and feel: " + e.toString());
-        }
+        System.err.println("Could not set requested laf="+laf);
       }
-      if (lookAndFeel == null
-              || !(lookAndFeel.getClass().isAssignableFrom(
-                      UIManager.getLookAndFeel().getClass()))
-              || !UIManager.getLookAndFeel().getClass().toString()
-                      .toLowerCase().contains("quaqua"))
+      break;
+    case "system":
+      lafSet = setSystemLookAndFeel();
+      if (!lafSet)
       {
-        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");
-        } catch (Throwable e)
-        {
-          System.err.println(
-                  "Failed to reset look and feel: " + e.toString());
-        }
+        System.err.println("Could not set requested laf="+laf);
+      }
+      break;
+    case "mac":
+      lafSet = setMacLookAndFeel();
+      if (!lafSet)
+      {
+        System.err.println("Could not set requested laf="+laf);
+      }
+      break;
+    case "none":
+      break;
+    default:
+      System.err.println("Requested laf="+laf+" not implemented");
+    }
+    if (! lafSet)
+    {
+      setSystemLookAndFeel();
+      if (Platform.isAMacAndNotJS())
+      {
+        setMacLookAndFeel();
       }
     }
 
@@ -854,6 +848,74 @@ public class Jalview
     }
   }
 
+  private static boolean setCrossPlatformLookAndFeel() {
+         boolean set = false;
+         try
+         {
+                 UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
+                 set = true;
+         } catch (Exception ex)
+         {
+                 System.err.println("Unexpected Look and Feel Exception");
+                 ex.printStackTrace();
+         }
+         return set;
+  }
+
+  private static boolean setSystemLookAndFeel() {
+         boolean set = false;
+         try
+         {
+                 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+                 set = true;
+         } catch (Exception ex)
+         {
+                 System.err.println("Unexpected Look and Feel Exception");
+                 ex.printStackTrace();
+         }
+         return set;
+  }
+  
+  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"))
+         {
+                 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());
+                 }
+         }
+         return set;
+  }
+  
   private static void showUsage()
   {
     System.out.println(