From 608e9777754f555b4941a80db4f8a14edb66b18b Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Wed, 22 Apr 2020 20:18:27 +0100 Subject: [PATCH] JAL-3608 Added CrossPlatform LaF and made configurable with the 'laf' system property. Also set laf for tests --- build.gradle | 5 ++ src/jalview/bin/Jalview.java | 142 ++++++++++++++++++++++++++++++------------ 2 files changed, 107 insertions(+), 40 deletions(-) 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( -- 1.7.10.2