From: Ben Soares Date: Mon, 4 May 2020 14:28:38 +0000 (+0100) Subject: JAL-3608 streamlined LaF methods and allow specificying "vaqua", "quaqua" X-Git-Tag: Develop-2_11_2_0-d20201215~24^2~16^2^2~1 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;ds=sidebyside;h=dc13933d1655206660d32c4e55e150dcf672ba48;p=jalview.git JAL-3608 streamlined LaF methods and allow specificying "vaqua", "quaqua" --- diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 64e3d81..08c12d6 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -43,7 +43,6 @@ 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; @@ -374,10 +373,13 @@ public class Jalview 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; + if (lafProp != null) + { + laf = lafProp; + } + else if (lafSetting != null) + { + laf = lafSetting; } boolean lafSet = false; switch (laf) @@ -398,21 +400,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); - } + { + System.err.println("Could not set requested laf=" + laf); + } break; case "nimbus": lafSet = setNimbusLookAndFeel(); - { - System.err.println("Could not set requested laf=" + laf); - } + { + 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(); @@ -429,7 +443,8 @@ public class Jalview if (!lafSet) { setSystemLookAndFeel(); - if (Platform.isLinux() && ! Platform.isJS()) { + if (Platform.isLinux() && !Platform.isJS()) + { setMetalLookAndFeel(); } if (Platform.isAMacAndNotJS()) @@ -907,19 +922,24 @@ public class Jalview return set; } - private static boolean setGtkLookAndFeel() + private static boolean setSpecificLookAndFeel(String name, + String className, boolean nameStartsWith) { 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(); + 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(laf); + UIManager.setLookAndFeel(className); set = true; } catch (Exception ex) { @@ -929,87 +949,49 @@ public class Jalview return set; } + private static boolean setGtkLookAndFeel() + { + return setSpecificLookAndFeel("gtk", + "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true); + } + 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; + return setSpecificLookAndFeel("metal", + "javax.swing.plaf.metal.MetalLookAndFeel", false); } 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; + 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) + set = setQuaquaLookAndFeel(); + if ((!set) || !UIManager.getLookAndFeel().getClass().toString() + .toLowerCase().contains("quaqua")) { - 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()); - } + set = setVaquaLookAndFeel(); } return set; }