import java.util.logging.Level;
import java.util.logging.Logger;
-import javax.swing.LookAndFeel;
import javax.swing.UIManager;
+import javax.swing.UIManager.LookAndFeelInfo;
import com.threerings.getdown.util.LaunchUtil;
Platform.getURLCommandArguments();
}
- // singleton instance of this class
-
+ /*
+ * singleton instance of this class
+ */
private static Jalview instance;
private Desktop desktop;
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)
"Invalid jabaws parameter: " + jabawsUrl + " ignored");
}
}
-
}
+
String defs = aparser.getValue("setprop");
while (defs != null)
{
{
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");
}
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 laf = System.getProperty("laf", "none");
- 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 "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();
- }
- }
+ setLookAndFeel();
/*
* configure 'full' SO model if preferences say to, else use the default (full SO)
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();
}
desktop.setVisible(true);
}
}
+ 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;
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;
}
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
{
- UIManager.setLookAndFeel(laf);
+ 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();
+ 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
- {
- 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()
+ {
+ 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)
- {
- 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"))
+ set = setQuaquaLookAndFeel();
+ if ((!set) || !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;
}