2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.awt.GraphicsEnvironment;
25 import java.io.BufferedReader;
27 import java.io.FileOutputStream;
28 import java.io.IOException;
29 import java.io.InputStreamReader;
30 import java.io.OutputStreamWriter;
31 import java.io.PrintWriter;
32 import java.net.MalformedURLException;
34 import java.net.URISyntaxException;
36 import java.security.AllPermission;
37 import java.security.CodeSource;
38 import java.security.PermissionCollection;
39 import java.security.Permissions;
40 import java.security.Policy;
41 import java.util.HashMap;
42 import java.util.Locale;
44 import java.util.Vector;
45 import java.util.logging.ConsoleHandler;
46 import java.util.logging.Level;
47 import java.util.logging.Logger;
49 import javax.swing.UIManager;
50 import javax.swing.UIManager.LookAndFeelInfo;
52 import com.threerings.getdown.util.LaunchUtil;
54 import groovy.lang.Binding;
55 import groovy.util.GroovyScriptEngine;
56 import jalview.api.AlignCalcWorkerI;
57 import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
58 import jalview.ext.so.SequenceOntology;
59 import jalview.gui.AlignFrame;
60 import jalview.gui.AlignViewport;
61 import jalview.gui.Desktop;
62 import jalview.gui.Preferences;
63 import jalview.gui.PromptUserConfig;
64 import jalview.io.AppletFormatAdapter;
65 import jalview.io.BioJsHTMLOutput;
66 import jalview.io.DataSourceType;
67 import jalview.io.FileFormat;
68 import jalview.io.FileFormatException;
69 import jalview.io.FileFormatI;
70 import jalview.io.FileFormats;
71 import jalview.io.FileLoader;
72 import jalview.io.HtmlSvgOutput;
73 import jalview.io.IdentifyFile;
74 import jalview.io.NewickFile;
75 import jalview.io.gff.SequenceOntologyFactory;
76 import jalview.schemes.ColourSchemeI;
77 import jalview.schemes.ColourSchemeProperty;
78 import jalview.util.ChannelProperties;
79 import jalview.util.HttpUtils;
80 import jalview.util.MessageManager;
81 import jalview.util.Platform;
82 import jalview.ws.jws2.Jws2Discoverer;
85 * Main class for Jalview Application <br>
87 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
90 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
91 * jalview.bin.Jalview jalview.bin.Jalview
93 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
94 * embellish '*' to e.g. '*.jar')
99 public class Jalview implements ApplicationSingletonI
101 // for testing those nasty messages you cannot ever find.
104 // System.setOut(new PrintStream(new ByteArrayOutputStream())
107 // public void println(Object o)
111 // System.err.println(o);
117 public static Jalview getInstance()
119 return (Jalview) ApplicationSingletonProvider
120 .getInstance(Jalview.class);
125 Platform.getURLCommandArguments();
129 private Desktop desktop;
131 public AlignFrame currentAlignFrame;
133 public String appletResourcePath;
135 public String j2sAppletID;
137 private boolean noCalculation, noMenuBar, noStatus;
139 private boolean noAnnotation;
141 public boolean getStartCalculations()
143 return !noCalculation;
146 public boolean getAllowMenuBar()
151 public boolean getShowStatus()
156 public boolean getShowAnnotation()
158 return !noAnnotation;
163 if (!Platform.isJS())
170 // grab all the rights we can for the JVM
171 Policy.setPolicy(new Policy()
174 public PermissionCollection getPermissions(CodeSource codesource)
176 Permissions perms = new Permissions();
177 perms.add(new AllPermission());
182 public void refresh()
190 * keep track of feature fetching tasks.
198 * TODO: generalise to track all jalview events to orchestrate batch processing
202 private int queued = 0;
204 private int running = 0;
206 public FeatureFetcher()
211 public void addFetcher(final AlignFrame af,
212 final Vector<String> dasSources)
214 final long id = System.currentTimeMillis();
216 final FeatureFetcher us = this;
217 new Thread(new Runnable()
229 af.setProgressBar(MessageManager
230 .getString("status.das_features_being_retrived"), id);
231 af.featureSettings_actionPerformed(null);
232 af.setProgressBar(null, id);
241 public synchronized boolean allFinished()
243 return queued == 0 && running == 0;
248 private final static boolean doPlatformLogging = false;
251 * main class for Jalview application
254 * open <em>filename</em>
256 public static void main(String[] args)
258 if (doPlatformLogging)
260 Platform.startJavaLogging();
263 getInstance().doMain(args);
273 void doMain(String[] args)
276 boolean isJS = Platform.isJS();
279 System.setSecurityManager(null);
283 * @j2sNative J2S.db._DirectDatabaseCalls["compbio.dundee.ac.uk"]=null;
284 * @j2sNative J2S.db._DirectDatabaseCalls["jalview.org"]=null;
288 .println("Java version: " + System.getProperty("java.version"));
289 System.out.println("Java Home: " + System.getProperty("java.home"));
290 System.out.println(System.getProperty("os.arch") + " "
291 + System.getProperty("os.name") + " "
292 + System.getProperty("os.version"));
293 String val = System.getProperty("sys.install4jVersion");
296 System.out.println("Install4j version: " + val);
298 val = System.getProperty("installer_template_version");
301 System.out.println("Install4j template version: " + val);
303 val = System.getProperty("launcher_version");
306 System.out.println("Launcher version: " + val);
309 // report Jalview version
310 Cache.getInstance().loadBuildProperties(true);
312 ArgsParser aparser = new ArgsParser(args);
313 boolean headless = false;
315 String usrPropsFile = aparser.getValue("props");
316 Cache.loadProperties(usrPropsFile); // must do this before
317 boolean allowServices = true;
321 j2sAppletID = Platform.getAppID(null);
322 Preferences.setAppletDefaults();
323 Cache.loadProperties(usrPropsFile); // again, because we
324 // might be changing defaults here?
325 appletResourcePath = (String) aparser.getAppletValue("resourcepath",
336 if (usrPropsFile != null)
339 "CMD [-props " + usrPropsFile + "] executed successfully!");
341 if (aparser.contains("help") || aparser.contains("h"))
346 // BH note: Only -nodisplay is official; others are deprecated?
347 if (aparser.contains("nodisplay") || aparser.contains("nogui")
348 || aparser.contains("headless")
349 || GraphicsEnvironment.isHeadless())
352 // BH Definitely not a good idea in JavaScript;
353 // probably should not be here for Java, either.
354 System.setProperty("java.awt.headless", "true");
360 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
361 allowServices = !("none".equals(jabawsUrl));
362 if (allowServices && jabawsUrl != null)
366 Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl);
368 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
369 } catch (MalformedURLException e)
372 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
377 String defs = aparser.getValue(ArgsParser.SETPROP);
380 int p = defs.indexOf('=');
383 System.err.println("Ignoring invalid setprop argument : " + defs);
387 System.out.println("Executing setprop argument: " + defs);
390 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
393 defs = aparser.getValue("setprop");
395 if (System.getProperty("java.awt.headless") != null
396 && System.getProperty("java.awt.headless").equals("true"))
400 System.setProperty("http.agent",
401 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
405 } catch (NoClassDefFoundError error)
407 error.printStackTrace();
408 System.out.println("\nEssential logging libraries not found."
409 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
418 * configure 'full' SO model if preferences say to, else use the default (full SO)
419 * - as JS currently doesn't have OBO parsing, it must use 'Lite' version
421 boolean soDefault = !isJS;
422 if (Cache.getDefault("USE_FULL_SO", soDefault))
424 SequenceOntologyFactory.setInstance(new SequenceOntology());
429 Desktop.nosplash = aparser.contains("nosplash");
430 desktop = Desktop.getInstance();
431 desktop.setInBatchMode(true); // indicate we are starting up
435 JalviewTaskbar.setTaskbar(this);
436 } catch (Exception e)
438 Cache.log.info("Cannot set Taskbar");
439 Cache.log.error(e.getMessage());
440 // e.printStackTrace();
441 } catch (Throwable t)
443 Cache.log.info("Cannot set Taskbar");
444 Cache.log.error(t.getMessage());
445 // t.printStackTrace();
447 // set Proxy settings before all the internet calls
448 Cache.setProxyPropertiesFromPreferences();
450 desktop.setVisible(true);
454 Cache.setProperty("SHOW_JWS2_SERVICES", "false");
456 if (allowServices && !aparser.contains("nowebservicediscovery"))
458 desktop.startServiceDiscovery();
468 if (!aparser.contains("nousagestats"))
470 startUsageStats(desktop);
474 System.err.println("CMD [-nousagestats] executed successfully!");
477 if (!aparser.contains("noquestionnaire"))
479 String url = aparser.getValue("questionnaire");
482 // Start the desktop questionnaire prompter with the specified
484 Cache.log.debug("Starting questionnaire url at " + url);
485 desktop.checkForQuestionnaire(url);
486 System.out.println("CMD questionnaire[-" + url
487 + "] executed successfully!");
491 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
493 // Start the desktop questionnaire prompter with the specified
496 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
498 String defurl = "https://www.jalview.org/cgi-bin/questionnaire.pl";
500 "Starting questionnaire with default url: " + defurl);
501 desktop.checkForQuestionnaire(defurl);
508 .println("CMD [-noquestionnaire] executed successfully!");
511 if (!aparser.contains("nonews"))
513 desktop.checkForNews();
516 BioJsHTMLOutput.updateBioJS();
519 parseArguments(aparser, true);
523 * Parse all command-line String[] arguments as well as all JavaScript-derived
524 * parameters from Info.
526 * We allow for this method to be run from JavaScript. Basically allowing
532 public void parseArguments(ArgsParser aparser, boolean isStartup)
535 String groovyscript = null; // script to execute after all loading is
536 boolean isJS = Platform.isJS();
540 // Move any new getdown-launcher-new.jar into place over old
541 // getdown-launcher.jar
542 String appdirString = System.getProperty("getdownappdir");
543 if (appdirString != null && appdirString.length() > 0)
545 final File appdir = new File(appdirString);
551 LaunchUtil.upgradeGetdown(
552 new File(appdir, "getdown-launcher-old.jar"),
553 new File(appdir, "getdown-launcher.jar"),
554 new File(appdir, "getdown-launcher-new.jar"));
559 // completed one way or another
560 // extract groovy argument and execute if necessary
561 groovyscript = aparser.getValue("groovy", true);
564 String file = aparser.getValue("open", true);
566 if (!isJS && file == null && desktop == null)
568 System.out.println("No files to open!");
571 setDisplayParameters(aparser);
573 // time to open a file.
575 DataSourceType protocol = null;
576 FileLoader fileLoader = new FileLoader(!headless);
577 FileFormatI format = null;
578 // Finally, deal with the remaining input data.
579 AlignFrame af = null;
581 JalviewJSApp jsApp = (isJS ? new JalviewJSApp(this, aparser) : null);
587 // JalviewJS allows sequence1 sequence2 ....
590 else if (!headless && Cache.getDefault("SHOW_STARTUP_FILE", true))
598 // We'll only open the default file if the desktop is visible.
600 // ////////////////////
602 file = Cache.getDefault("STARTUP_FILE",
603 Cache.getDefault("www.jalview.org",
604 "http://www.jalview.org")
605 + "/examples/exampleFile_2_7.jar");
607 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
609 // hardwire upgrade of the startup file
610 file.replace("_2_3.jar", "_2_7.jar");
611 // and remove the stale setting
612 Cache.removeProperty("STARTUP_FILE");
615 protocol = DataSourceType.FILE;
617 if (file.indexOf("http:") > -1)
619 protocol = DataSourceType.URL;
622 if (file.endsWith(".jar"))
624 format = FileFormat.Jalview;
630 format = new IdentifyFile().identify(file, protocol);
631 } catch (FileFormatException e)
636 af = fileLoader.LoadFileWaitTillLoaded(file, protocol, format);
643 desktop.setProgressBar(
645 .getString("status.processing_commandline_args"),
646 progress = System.currentTimeMillis());
648 System.out.println("CMD [-open " + file + "] executed successfully!");
650 if (!Platform.isJS())
652 * ignore in JavaScript -- can't just file existence - could load it?
657 if (!HttpUtils.startsWithHttpOrHttps(file))
659 if (!(new File(file)).exists())
661 System.out.println("Can't find " + file);
670 // JS Only argument to provide a format parameter to specify what format to use
671 String fileFormat = (isJS
672 ? (String) aparser.getAppletValue("format", null, true)
674 protocol = AppletFormatAdapter.checkProtocol(file);
678 format = (fileFormat != null
679 ? FileFormats.getInstance().forName(fileFormat)
683 format = new IdentifyFile().identify(file, protocol);
685 } catch (FileFormatException e1)
690 af = new FileLoader(!headless).LoadFileWaitTillLoaded(file, protocol,
694 System.out.println("jalview error - AlignFrame was not created");
699 // JalviewLite interface for JavaScript allows second file open
700 String file2 = aparser.getValue(ArgsParser.OPEN2, true);
703 protocol = AppletFormatAdapter.checkProtocol(file2);
706 format = new IdentifyFile().identify(file2, protocol);
707 } catch (FileFormatException e1)
711 AlignFrame af2 = new FileLoader(!headless)
712 .LoadFileWaitTillLoaded(file2, protocol, format);
715 System.out.println("error");
719 AlignViewport.openLinkedAlignmentAs(af,
720 af.getViewport().getAlignment(),
721 af2.getViewport().getAlignment(), "",
722 AlignViewport.SPLIT_FRAME);
724 "CMD [-open2 " + file2 + "] executed successfully!");
727 // af is loaded - so set it as current frame
728 setCurrentAlignFrame(af);
730 setFrameDependentProperties(aparser, af);
734 jsApp.initFromParams(af);
743 if (groovyscript != null)
745 // Execute the groovy script after we've done all the rendering
747 // and before any images or figures are generated.
748 System.out.println("Executing script " + groovyscript);
749 executeGroovyScript(groovyscript, af);
750 System.out.println("CMD groovy[" + groovyscript
751 + "] executed successfully!");
755 if (!isJS || !isStartup) {
756 createOutputFiles(aparser, format);
761 af.getViewport().getCalcManager().shutdown();
764 // extract groovy arguments before anything else.
765 // Once all other stuff is done, execute any groovy scripts (in order)
766 if (!isJS && groovyscript != null)
768 if (Cache.groovyJarsPresent())
770 // TODO: DECIDE IF THIS SECOND PASS AT GROOVY EXECUTION IS STILL REQUIRED !!
771 System.out.println("Executing script " + groovyscript);
772 executeGroovyScript(groovyscript, af);
773 System.out.println("CMD groovy[" + groovyscript
774 + "] executed successfully!");
780 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
785 // and finally, turn off batch mode indicator - if the desktop still exists
790 desktop.setProgressBar(null, progress);
792 desktop.setInBatchMode(false);
796 jsApp.callInitCallback();
801 * Set general display parameters irrespective of file loading or headlessness.
805 private void setDisplayParameters(ArgsParser aparser)
807 if (aparser.contains(ArgsParser.NOMENUBAR))
810 System.out.println("CMD [nomenu] executed successfully!");
813 if (aparser.contains(ArgsParser.NOSTATUS))
816 System.out.println("CMD [nostatus] executed successfully!");
819 if (aparser.contains(ArgsParser.NOANNOTATION)
820 || aparser.contains(ArgsParser.NOANNOTATION2))
823 System.out.println("CMD no-annotation executed successfully!");
825 if (aparser.contains(ArgsParser.NOCALCULATION))
827 noCalculation = true;
828 System.out.println("CMD [nocalculation] executed successfully!");
833 private void setFrameDependentProperties(ArgsParser aparser,
836 String data = aparser.getValue(ArgsParser.COLOUR, true);
839 data.replaceAll("%20", " ");
841 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
842 af.getViewport(), af.getViewport().getAlignment(), data);
847 "CMD [-color " + data + "] executed successfully!");
852 // Must maintain ability to use the groups flag
853 data = aparser.getValue(ArgsParser.GROUPS, true);
856 af.parseFeaturesFile(data,
857 AppletFormatAdapter.checkProtocol(data));
858 // System.out.println("Added " + data);
860 "CMD groups[-" + data + "] executed successfully!");
862 data = aparser.getValue(ArgsParser.FEATURES, true);
865 af.parseFeaturesFile(data,
866 AppletFormatAdapter.checkProtocol(data));
867 // System.out.println("Added " + data);
869 "CMD [-features " + data + "] executed successfully!");
871 data = aparser.getValue(ArgsParser.ANNOTATIONS, true);
874 af.loadJalviewDataFile(data, null, null, null);
875 // System.out.println("Added " + data);
877 "CMD [-annotations " + data + "] executed successfully!");
880 // JavaScript feature
882 if (aparser.contains(ArgsParser.SHOWOVERVIEW))
884 af.overviewMenuItem_actionPerformed(null);
885 System.out.println("CMD [showoverview] executed successfully!");
888 // set or clear the sortbytree flag.
889 if (aparser.contains(ArgsParser.SORTBYTREE))
891 af.getViewport().setSortByTree(true);
892 if (af.getViewport().getSortByTree())
894 System.out.println("CMD [-sortbytree] executed successfully!");
898 boolean doUpdateAnnotation = false;
900 * we do this earlier in JalviewJS because of a complication with
903 * For now, just fixing this in JalviewJS.
912 af.getViewport().setShowAnnotation(false);
913 if (!af.getViewport().isShowAnnotation())
915 doUpdateAnnotation = true;
920 if (aparser.contains(ArgsParser.NOSORTBYTREE))
922 af.getViewport().setSortByTree(false);
923 if (!af.getViewport().getSortByTree())
925 doUpdateAnnotation = true;
927 .println("CMD [-nosortbytree] executed successfully!");
930 if (doUpdateAnnotation)
932 af.setMenusForViewport();
933 af.alignPanel.updateLayout();
936 data = aparser.getValue(ArgsParser.TREE, true);
941 NewickFile nf = new NewickFile(data,
942 AppletFormatAdapter.checkProtocol(data));
944 .setCurrentTree(af.showNewickTree(nf, data).getTree());
946 "CMD [-tree " + data + "] executed successfully!");
947 } catch (IOException ex)
949 System.err.println("Couldn't add tree " + data);
950 ex.printStackTrace(System.err);
953 // TODO - load PDB structure(s) to alignment JAL-629
954 // (associate with identical sequence in alignment, or a specified
960 * Writes an output file for each format (if any) specified in the
961 * command-line arguments. Supported formats are currently
970 * A format parameter should be followed by a parameter specifying the output
971 * file name. {@code imgMap} parameters should follow those for the
972 * corresponding alignment image output.
977 private void createOutputFiles(ArgsParser aparser, FileFormatI format)
979 // logic essentially the same as 2.11.2/2.11.3 but uses a switch instead
980 AlignFrame af = currentAlignFrame;
981 while (aparser.getSize() >= 2)
983 String outputFormat = aparser.nextValue();
986 switch (outputFormat.toLowerCase(Locale.ROOT))
989 imageFile = new File(aparser.nextValue());
990 af.createPNG(imageFile);
992 "Creating PNG image: " + imageFile.getAbsolutePath());
995 imageFile = new File(aparser.nextValue());
996 af.createSVG(imageFile);
998 "Creating SVG image: " + imageFile.getAbsolutePath());
1001 imageFile = new File(aparser.nextValue());
1003 "Creating EPS file: " + imageFile.getAbsolutePath());
1004 af.createEPS(imageFile);
1007 fname = new File(aparser.nextValue()).getAbsolutePath();
1010 BioJsHTMLOutput.refreshVersionInfo(
1011 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
1012 } catch (URISyntaxException e)
1014 e.printStackTrace();
1016 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
1017 bjs.exportHTML(fname);
1018 System.out.println("Creating BioJS MSA Viwer HTML file: " + fname);
1021 fname = new File(aparser.nextValue()).getAbsolutePath();
1022 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
1023 htmlSVG.exportHTML(fname);
1024 System.out.println("Creating HTML image: " + fname);
1027 imageFile = new File(aparser.nextValue());
1028 af.alignPanel.makePNGImageMap(imageFile, "unnamed.png");
1030 "Creating image map: " + imageFile.getAbsolutePath());
1033 // fall through - try to parse as an alignment data export format
1034 FileFormatI outFormat = null;
1037 outFormat = FileFormats.getInstance().forName(outputFormat);
1038 } catch (Exception formatP)
1041 if (outFormat == null)
1043 System.out.println("Couldn't parse " + outputFormat
1044 + " as a valid Jalview format string.");
1047 if (!outFormat.isWritable())
1050 "This version of Jalview does not support alignment export as "
1054 // record file as it was passed to Jalview so it is recognisable to the CLI
1057 fname = new File(file = aparser.nextValue()).getAbsolutePath();
1058 // JBPNote - yuck - really wish we did have a bean returned from this which gave
1059 // success/fail like before !
1060 af.saveAlignment(fname, outFormat);
1061 if (!af.isSaveAlignmentSuccessful())
1063 System.out.println("Written alignment in " + outputFormat
1064 + " format to " + file);
1069 System.out.println("Error writing file " + file + " in "
1070 + outputFormat + " format!!");
1074 // ??? Should report - 'ignoring' extra args here...
1075 while (aparser.getSize() > 0)
1077 System.out.println("Ignoring extra argument: " + aparser.nextValue());
1081 private static void setLookAndFeel()
1083 // property laf = "crossplatform", "system", "gtk", "metal", "nimbus" or
1085 // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
1086 // try Quaqua/Vaqua.
1087 String lafProp = System.getProperty("laf");
1088 String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
1089 String laf = "none";
1090 if (lafProp != null)
1094 else if (lafSetting != null)
1098 boolean lafSet = false;
1101 case "crossplatform":
1102 lafSet = setCrossPlatformLookAndFeel();
1105 Cache.log.error("Could not set requested laf=" + laf);
1109 lafSet = setSystemLookAndFeel();
1112 Cache.log.error("Could not set requested laf=" + laf);
1116 lafSet = setGtkLookAndFeel();
1119 Cache.log.error("Could not set requested laf=" + laf);
1123 lafSet = setMetalLookAndFeel();
1126 Cache.log.error("Could not set requested laf=" + laf);
1130 lafSet = setNimbusLookAndFeel();
1133 Cache.log.error("Could not set requested laf=" + laf);
1137 lafSet = setQuaquaLookAndFeel();
1140 Cache.log.error("Could not set requested laf=" + laf);
1144 lafSet = setVaquaLookAndFeel();
1147 Cache.log.error("Could not set requested laf=" + laf);
1151 lafSet = setMacLookAndFeel();
1154 Cache.log.error("Could not set requested laf=" + laf);
1160 Cache.log.error("Requested laf=" + laf + " not implemented");
1164 setSystemLookAndFeel();
1165 if (Platform.isLinux())
1167 setMetalLookAndFeel();
1169 if (Platform.isMac())
1171 setMacLookAndFeel();
1176 private static boolean setCrossPlatformLookAndFeel()
1178 boolean set = false;
1181 UIManager.setLookAndFeel(
1182 UIManager.getCrossPlatformLookAndFeelClassName());
1184 } catch (Exception ex)
1186 Cache.log.error("Unexpected Look and Feel Exception");
1187 Cache.log.error(ex.getMessage());
1188 Cache.log.debug(Cache.getStackTraceString(ex));
1193 private static boolean setSystemLookAndFeel()
1195 boolean set = false;
1198 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
1200 } catch (Exception ex)
1202 Cache.log.error("Unexpected Look and Feel Exception");
1203 Cache.log.error(ex.getMessage());
1204 Cache.log.debug(Cache.getStackTraceString(ex));
1209 private static boolean setSpecificLookAndFeel(String name,
1210 String className, boolean nameStartsWith)
1212 boolean set = false;
1215 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
1217 if (info.getName() != null && nameStartsWith
1218 ? info.getName().toLowerCase(Locale.ROOT)
1219 .startsWith(name.toLowerCase(Locale.ROOT))
1220 : info.getName().toLowerCase(Locale.ROOT).equals(name.toLowerCase(Locale.ROOT)))
1222 className = info.getClassName();
1226 UIManager.setLookAndFeel(className);
1228 } catch (Exception ex)
1230 Cache.log.error("Unexpected Look and Feel Exception");
1231 Cache.log.error(ex.getMessage());
1232 Cache.log.debug(Cache.getStackTraceString(ex));
1237 private static boolean setGtkLookAndFeel()
1239 return setSpecificLookAndFeel("gtk",
1240 "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true);
1243 private static boolean setMetalLookAndFeel()
1245 return setSpecificLookAndFeel("metal",
1246 "javax.swing.plaf.metal.MetalLookAndFeel", false);
1249 private static boolean setNimbusLookAndFeel()
1251 return setSpecificLookAndFeel("nimbus",
1252 "javax.swing.plaf.nimbus.NimbusLookAndFeel", false);
1255 private static boolean setQuaquaLookAndFeel()
1257 return setSpecificLookAndFeel("quaqua",
1258 ch.randelshofer.quaqua.QuaquaManager.getLookAndFeel().getClass()
1263 private static boolean setVaquaLookAndFeel()
1265 return setSpecificLookAndFeel("vaqua",
1266 "org.violetlib.aqua.AquaLookAndFeel", false);
1269 private static boolean setMacLookAndFeel()
1271 boolean set = false;
1272 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
1273 ChannelProperties.getProperty("app_name"));
1274 System.setProperty("apple.laf.useScreenMenuBar", "true");
1275 set = setQuaquaLookAndFeel();
1276 if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
1277 .toLowerCase(Locale.ROOT).contains("quaqua"))
1279 set = setVaquaLookAndFeel();
1283 private static void showUsage()
1286 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1287 + "-nodisplay\tRun Jalview without User Interface.\n"
1288 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1289 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1290 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1291 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1292 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1293 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1294 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1295 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1296 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1297 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1298 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1299 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1300 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1301 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1302 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1303 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1304 + "-html FILE\tCreate HTML file from alignment.\n"
1305 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1306 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1307 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1308 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1309 + "-noquestionnaire\tTurn off questionnaire check.\n"
1310 + "-nonews\tTurn off check for Jalview news.\n"
1311 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1312 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1314 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1315 // after all other properties files have been read\n\t
1316 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1317 // passed in correctly)"
1318 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1319 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1320 + "-groovy FILE\tExecute groovy script in FILE, after all other arguments have been processed (if FILE is the text 'STDIN' then the file will be read from STDIN)\n"
1321 + "-jvmmempc=PERCENT\tOnly available with standalone executable jar or jalview.bin.Launcher. Limit maximum heap size (memory) to PERCENT% of total physical memory detected. This defaults to 90 if total physical memory can be detected. See https://www.jalview.org/help/html/memory.html for more details.\n"
1322 + "-jvmmemmax=MAXMEMORY\tOnly available with standalone executable jar or jalview.bin.Launcher. Limit maximum heap size (memory) to MAXMEMORY. MAXMEMORY can be specified in bytes, kilobytes(k), megabytes(m), gigabytes(g) or if you're lucky enough, terabytes(t). This defaults to 32g if total physical memory can be detected, or to 8g if total physical memory cannot be detected. See https://www.jalview.org/help/html/memory.html for more details.\n"
1323 + "\n~Read documentation in Application or visit https://www.jalview.org for description of Features and Annotations file~\n\n");
1326 private static void startUsageStats(final Desktop desktop)
1329 * start a User Config prompt asking if we can log usage statistics.
1331 PromptUserConfig prompter = new PromptUserConfig(Desktop.getDesktopPane(),
1332 "USAGESTATS", "Jalview Usage Statistics",
1333 "Do you want to help make Jalview better by enabling "
1334 + "the collection of usage statistics with Google Analytics ?"
1335 + "\n\n(you can enable or disable usage tracking in the preferences)",
1342 "Initialising googletracker for usage stats.");
1343 Cache.initGoogleTracker();
1344 Cache.log.debug("Tracking enabled.");
1351 Cache.log.debug("Not enabling Google Tracking.");
1354 desktop.addDialogThread(prompter);
1358 * Locate the given string as a file and pass it to the groovy interpreter.
1360 * @param groovyscript
1361 * the script to execute
1362 * @param jalviewContext
1363 * the Jalview Desktop object passed in to the groovy binding as the
1366 private void executeGroovyScript(String groovyscript, AlignFrame af)
1369 * for scripts contained in files
1376 if (groovyscript.trim().equals("STDIN"))
1378 // read from stdin into a tempfile and execute it
1381 tfile = File.createTempFile("jalview", "groovy");
1382 PrintWriter outfile = new PrintWriter(
1383 new OutputStreamWriter(new FileOutputStream(tfile)));
1384 BufferedReader br = new BufferedReader(
1385 new InputStreamReader(System.in));
1387 while ((line = br.readLine()) != null)
1389 outfile.write(line + "\n");
1395 } catch (Exception ex)
1397 System.err.println("Failed to read from STDIN into tempfile "
1398 + ((tfile == null) ? "(tempfile wasn't created)"
1399 : tfile.toString()));
1400 ex.printStackTrace();
1405 sfile = tfile.toURI().toURL();
1406 } catch (Exception x)
1409 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1411 x.printStackTrace();
1419 sfile = new URI(groovyscript).toURL();
1420 } catch (Exception x)
1422 tfile = new File(groovyscript);
1423 if (!tfile.exists())
1425 System.err.println("File '" + groovyscript + "' does not exist.");
1428 if (!tfile.canRead())
1430 System.err.println("File '" + groovyscript + "' cannot be read.");
1433 if (tfile.length() < 1)
1435 System.err.println("File '" + groovyscript + "' is empty.");
1440 sfile = tfile.getAbsoluteFile().toURI().toURL();
1441 } catch (Exception ex)
1443 System.err.println("Failed to create a file URL for "
1444 + tfile.getAbsoluteFile());
1451 Map<String, java.lang.Object> vbinding = new HashMap<>();
1452 vbinding.put("Jalview", this);
1455 vbinding.put("currentAlFrame", af);
1457 Binding gbinding = new Binding(vbinding);
1458 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1459 gse.run(sfile.toString(), gbinding);
1460 if ("STDIN".equals(groovyscript))
1462 // delete temp file that we made -
1463 // only if it was successfully executed
1466 } catch (Exception e)
1468 System.err.println("Exception Whilst trying to execute file " + sfile
1469 + " as a groovy script.");
1470 e.printStackTrace(System.err);
1475 public static boolean isHeadlessMode()
1477 String isheadless = System.getProperty("java.awt.headless");
1478 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1485 public AlignFrame[] getAlignFrames()
1487 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1488 : Desktop.getAlignFrames();
1493 * Quit method delegates to Desktop.quit - unless running in headless mode when
1494 * it just ends the JVM
1498 if (desktop != null)
1508 public static AlignFrame getCurrentAlignFrame()
1510 return Jalview.getInstance().currentAlignFrame;
1513 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1515 Jalview.getInstance().currentAlignFrame = currentAlignFrame;
1518 public void notifyWorker(AlignCalcWorkerI worker, String status)
1520 // System.out.println("Jalview worker " + worker.getClass().getSimpleName()
1525 private static boolean isInteractive = true;
1527 public static boolean isInteractive()
1529 return isInteractive;
1532 public static void setInteractive(boolean tf)