X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fbin%2FJalview.java;h=b1ea60bed10ab2144f2c4808af369e3c20d6235a;hb=7664ccad29d55ad2355d72feeac23d8bdd49a2a7;hp=64e3d813088432b4e08d018a2f5bc31b2e2f343b;hpb=0ddc96bc043a4fe9ba9b2947a770ae1d3969079c;p=jalview.git diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 64e3d81..b1ea60b 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; @@ -68,6 +67,7 @@ import jalview.io.NewickFile; import jalview.io.gff.SequenceOntologyFactory; import jalview.schemes.ColourSchemeI; import jalview.schemes.ColourSchemeProperty; +import jalview.util.HttpUtils; import jalview.util.MessageManager; import jalview.util.Platform; import jalview.ws.jws2.Jws2Discoverer; @@ -94,8 +94,9 @@ public class Jalview Platform.getURLCommandArguments(); } - // singleton instance of this class - + /* + * singleton instance of this class + */ private static Jalview instance; private Desktop desktop; @@ -286,6 +287,17 @@ public class Jalview ArgsParser aparser = new ArgsParser(args); boolean headless = false; + if (aparser.contains("help") || aparser.contains("h")) + { + showUsage(); + System.exit(0); + } + if (aparser.contains("nodisplay") || aparser.contains("nogui") + || aparser.contains("headless")) + { + System.setProperty("java.awt.headless", "true"); + headless = true; + } String usrPropsFile = aparser.getValue("props"); Cache.loadProperties(usrPropsFile); // must do this before if (usrPropsFile != null) @@ -328,8 +340,8 @@ public class Jalview "Invalid jabaws parameter: " + jabawsUrl + " ignored"); } } - } + String defs = aparser.getValue("setprop"); while (defs != null) { @@ -345,6 +357,9 @@ public class Jalview { Cache.setProperty(defs.substring(0, p), defs.substring(p + 1)); } + // DISABLED FOR SECURITY REASONS + // TODO: add a property to allow properties to be overriden by cli args + // Cache.setProperty(defs.substring(0,p), defs.substring(p+1)); } defs = aparser.getValue("setprop"); } @@ -368,75 +383,7 @@ public class Jalview desktop = null; - // 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) { - laf = lafProp; - } else if (lafSetting != null) { - laf = lafSetting; - } - boolean lafSet = false; - switch (laf) - { - case "crossplatform": - lafSet = setCrossPlatformLookAndFeel(); - if (!lafSet) - { - System.err.println("Could not set requested laf=" + laf); - } - break; - case "system": - lafSet = setSystemLookAndFeel(); - if (!lafSet) - { - 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 "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() && ! Platform.isJS()) { - setMetalLookAndFeel(); - } - if (Platform.isAMacAndNotJS()) - { - setMacLookAndFeel(); - } - } + setLookAndFeel(); /* * configure 'full' SO model if preferences say to, else use the default (full SO) @@ -456,11 +403,21 @@ public class Jalview try { JalviewTaskbar.setTaskbar(this); + } catch (Exception e) + { + Cache.log.info("Cannot set Taskbar"); + Cache.log.error(e.getMessage()); + // e.printStackTrace(); } catch (Throwable t) { - System.out.println("Error setting Taskbar: " + t.getMessage()); + Cache.log.info("Cannot set Taskbar"); + Cache.log.error(t.getMessage()); + // t.printStackTrace(); } + // set Proxy settings before all the internet calls + Cache.setProxyPropertiesFromPreferences(); + desktop.setVisible(true); if (!Platform.isJS()) @@ -578,8 +535,7 @@ public class Jalview * @j2sIgnore */ { - if (!file.startsWith("http://") && !file.startsWith("https://")) - // BH 2019 added https check for Java + if (!HttpUtils.startsWithHttpOrHttps(file)) { if (!(new File(file)).exists()) { @@ -876,6 +832,101 @@ public class Jalview } } + private static void setLookAndFeel() + { + // property laf = "crossplatform", "system", "gtk", "metal", "nimbus" 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) + { + laf = lafProp; + } + else if (lafSetting != null) + { + laf = lafSetting; + } + boolean lafSet = false; + switch (laf) + { + case "crossplatform": + lafSet = setCrossPlatformLookAndFeel(); + if (!lafSet) + { + Cache.log.error("Could not set requested laf=" + laf); + } + break; + case "system": + lafSet = setSystemLookAndFeel(); + if (!lafSet) + { + Cache.log.error("Could not set requested laf=" + laf); + } + break; + case "gtk": + lafSet = setGtkLookAndFeel(); + if (!lafSet) + { + Cache.log.error("Could not set requested laf=" + laf); + } + break; + case "metal": + lafSet = setMetalLookAndFeel(); + if (!lafSet) + { + Cache.log.error("Could not set requested laf=" + laf); + } + break; + case "nimbus": + lafSet = setNimbusLookAndFeel(); + if (!lafSet) + { + Cache.log.error("Could not set requested laf=" + laf); + } + break; + case "quaqua": + lafSet = setQuaquaLookAndFeel(); + if (!lafSet) + { + Cache.log.error("Could not set requested laf=" + laf); + } + break; + case "vaqua": + lafSet = setVaquaLookAndFeel(); + if (!lafSet) + { + Cache.log.error("Could not set requested laf=" + laf); + } + break; + case "mac": + lafSet = setMacLookAndFeel(); + if (!lafSet) + { + Cache.log.error("Could not set requested laf=" + laf); + } + break; + case "none": + break; + default: + Cache.log.error("Requested laf=" + laf + " not implemented"); + } + if (!lafSet) + { + setSystemLookAndFeel(); + if (Platform.isLinux()) + { + setMetalLookAndFeel(); + } + if (Platform.isMac()) + { + setMacLookAndFeel(); + } + } + } + private static boolean setCrossPlatformLookAndFeel() { boolean set = false; @@ -886,8 +937,9 @@ public class Jalview set = true; } catch (Exception ex) { - System.err.println("Unexpected Look and Feel Exception"); - ex.printStackTrace(); + Cache.log.error("Unexpected Look and Feel Exception"); + Cache.log.error(ex.getMessage()); + Cache.log.debug(Cache.getStackTraceString(ex)); } return set; } @@ -901,115 +953,84 @@ public class Jalview set = true; } catch (Exception ex) { - System.err.println("Unexpected Look and Feel Exception"); - ex.printStackTrace(); + Cache.log.error("Unexpected Look and Feel Exception"); + Cache.log.error(ex.getMessage()); + Cache.log.debug(Cache.getStackTraceString(ex)); } 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) { - System.err.println("Unexpected Look and Feel Exception"); - ex.printStackTrace(); + Cache.log.error("Unexpected Look and Feel Exception"); + Cache.log.error(ex.getMessage()); + Cache.log.debug(Cache.getStackTraceString(ex)); } 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; }