From: Ben Soares Date: Wed, 22 Apr 2020 19:18:27 +0000 (+0100) Subject: JAL-3608 Added CrossPlatform LaF and made configurable with the 'laf' system property... X-Git-Tag: Develop-2_11_2_0-d20201215~24^2~16^2^2~9 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=608e9777754f555b4941a80db4f8a14edb66b18b;p=jalview.git JAL-3608 Added CrossPlatform LaF and made configurable with the 'laf' system property. Also set laf for tests --- diff --git a/build.gradle b/build.gradle index 985cc87..453ad5d 100644 --- a/build.gradle +++ b/build.gradle @@ -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 diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index cdd8cc1..afe4055 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -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(