X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fbin%2FJalview.java;h=021aad6071177493fdf7d7bb57836e5fa3101390;hb=6e2b4ee8fb9bdb978087ed19516bfd8d7f00f544;hp=a571ce91012f8c4ee40782a1479a95ce8a74aefb;hpb=fa750d6b432ef31a7407fdb8bf01c1edf687bcf4;p=jalview.git diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index a571ce9..021aad6 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -40,8 +40,8 @@ import java.util.HashMap; import java.util.Map; import java.util.Vector; -import javax.swing.LookAndFeel; import javax.swing.UIManager; +import javax.swing.UIManager.LookAndFeelInfo; import com.threerings.getdown.util.LaunchUtil; @@ -297,49 +297,88 @@ public class Jalview desktop = null; - try + // 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 lafProp = System.getProperty("laf"); + String lafSetting = Cache.getDefault("PREFERRED_LAF", null); + String laf = "none"; + if (lafProp != null) { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } catch (Exception ex) + laf = lafProp; + } + else if (lafSetting != null) { - System.err.println("Unexpected Look and Feel Exception"); - ex.printStackTrace(); + laf = lafSetting; } - if (Platform.isAMac()) + boolean lafSet = false; + switch (laf) { - - 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) + 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 "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 "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(); + 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.isLinux()) { + setMetalLookAndFeel(); + } + if (Platform.isAMac()) + { + setMacLookAndFeel(); } } @@ -762,6 +801,111 @@ 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 setSpecificLookAndFeel(String name, + String className, boolean nameStartsWith) + { + boolean set = false; + try + { + 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(className); + set = true; + } catch (Exception ex) + { + System.err.println("Unexpected Look and Feel Exception"); + ex.printStackTrace(); + } + return set; + } + + private static boolean setGtkLookAndFeel() + { + return setSpecificLookAndFeel("gtk", + "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true); + } + + private static boolean setMetalLookAndFeel() + { + return setSpecificLookAndFeel("metal", + "javax.swing.plaf.metal.MetalLookAndFeel", false); + } + + private static boolean setNimbusLookAndFeel() + { + 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; + System.setProperty("com.apple.mrj.application.apple.menu.about.name", + "Jalview"); + System.setProperty("apple.laf.useScreenMenuBar", "true"); + set = setQuaquaLookAndFeel(); + if ((!set) || !UIManager.getLookAndFeel().getClass().toString() + .toLowerCase().contains("quaqua")) + { + set = setVaquaLookAndFeel(); + } + return set; + } + private static void showUsage() { System.out.println(