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.Color;
24 import java.io.BufferedReader;
26 import java.io.FileOutputStream;
27 import java.io.IOException;
28 import java.io.InputStreamReader;
29 import java.io.OutputStream;
30 import java.io.OutputStreamWriter;
31 import java.io.PrintStream;
32 import java.io.PrintWriter;
33 import java.net.MalformedURLException;
35 import java.net.URISyntaxException;
37 import java.security.AllPermission;
38 import java.security.CodeSource;
39 import java.security.PermissionCollection;
40 import java.security.Permissions;
41 import java.security.Policy;
42 import java.util.ArrayList;
43 import java.util.HashMap;
44 import java.util.List;
45 import java.util.Locale;
47 import java.util.Properties;
48 import java.util.Vector;
49 import java.util.logging.ConsoleHandler;
50 import java.util.logging.Level;
51 import java.util.logging.Logger;
53 import javax.swing.JDialog;
54 import javax.swing.JFrame;
55 import javax.swing.JOptionPane;
56 import javax.swing.SwingUtilities;
57 import javax.swing.UIManager;
58 import javax.swing.UIManager.LookAndFeelInfo;
59 import javax.swing.UnsupportedLookAndFeelException;
61 import com.formdev.flatlaf.FlatLightLaf;
62 import com.formdev.flatlaf.themes.FlatMacLightLaf;
63 import com.formdev.flatlaf.util.SystemInfo;
64 import com.threerings.getdown.util.LaunchUtil;
66 //import edu.stanford.ejalbert.launching.IBrowserLaunching;
67 import groovy.lang.Binding;
68 import groovy.util.GroovyScriptEngine;
69 import jalview.bin.argparser.Arg;
70 import jalview.bin.argparser.ArgParser;
71 import jalview.bin.argparser.BootstrapArgs;
72 import jalview.ext.so.SequenceOntology;
73 import jalview.gui.AlignFrame;
74 import jalview.gui.Desktop;
75 import jalview.gui.PromptUserConfig;
76 import jalview.gui.QuitHandler;
77 import jalview.gui.QuitHandler.QResponse;
78 import jalview.io.AppletFormatAdapter;
79 import jalview.io.BioJsHTMLOutput;
80 import jalview.io.DataSourceType;
81 import jalview.io.FileFormat;
82 import jalview.io.FileFormatException;
83 import jalview.io.FileFormatI;
84 import jalview.io.FileFormats;
85 import jalview.io.FileLoader;
86 import jalview.io.HtmlSvgOutput;
87 import jalview.io.IdentifyFile;
88 import jalview.io.NewickFile;
89 import jalview.io.gff.SequenceOntologyFactory;
90 import jalview.schemes.ColourSchemeI;
91 import jalview.schemes.ColourSchemeProperty;
92 import jalview.util.ChannelProperties;
93 import jalview.util.HttpUtils;
94 import jalview.util.LaunchUtils;
95 import jalview.util.MessageManager;
96 import jalview.util.Platform;
97 import jalview.ws.jws2.Jws2Discoverer;
100 * Main class for Jalview Application <br>
102 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
103 * jalview.bin.Jalview
105 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
106 * jalview.bin.Jalview jalview.bin.Jalview
108 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
109 * embellish '*' to e.g. '*.jar')
112 * @version $Revision$
118 Platform.getURLCommandArguments();
119 Platform.addJ2SDirectDatabaseCall("https://www.jalview.org");
120 Platform.addJ2SDirectDatabaseCall("http://www.jalview.org");
121 Platform.addJ2SDirectDatabaseCall("http://www.compbio.dundee.ac.uk");
122 Platform.addJ2SDirectDatabaseCall("https://www.compbio.dundee.ac.uk");
126 * singleton instance of this class
128 private static Jalview instance;
130 private Desktop desktop;
132 protected Commands cmds;
134 public static AlignFrame currentAlignFrame;
138 if (!Platform.isJS())
145 // grab all the rights we can for the JVM
146 Policy.setPolicy(new Policy()
149 public PermissionCollection getPermissions(CodeSource codesource)
151 Permissions perms = new Permissions();
152 perms.add(new AllPermission());
157 public void refresh()
165 * keep track of feature fetching tasks.
173 * TODO: generalise to track all jalview events to orchestrate batch processing
177 private int queued = 0;
179 private int running = 0;
181 public FeatureFetcher()
186 public void addFetcher(final AlignFrame af,
187 final Vector<String> dasSources)
189 final long id = System.currentTimeMillis();
191 final FeatureFetcher us = this;
192 new Thread(new Runnable()
204 af.setProgressBar(MessageManager
205 .getString("status.das_features_being_retrived"), id);
206 af.featureSettings_actionPerformed(null);
207 af.setProgressBar(null, id);
216 public synchronized boolean allFinished()
218 return queued == 0 && running == 0;
223 public static Jalview getInstance()
229 * main class for Jalview application
232 * open <em>filename</em>
234 public static void main(String[] args)
236 // setLogging(); // BH - for event debugging in JavaScript
237 instance = new Jalview();
238 instance.doMain(args);
241 private static void logClass(String name)
243 // BH - for event debugging in JavaScript
244 ConsoleHandler consoleHandler = new ConsoleHandler();
245 consoleHandler.setLevel(Level.ALL);
246 Logger logger = Logger.getLogger(name);
247 logger.setLevel(Level.ALL);
248 logger.addHandler(consoleHandler);
251 @SuppressWarnings("unused")
252 private static void setLogging()
260 System.out.println("not in js");
263 // BH - for event debugging in JavaScript (Java mode only)
264 if (!Platform.isJS())
271 Logger.getLogger("").setLevel(Level.ALL);
272 logClass("java.awt.EventDispatchThread");
273 logClass("java.awt.EventQueue");
274 logClass("java.awt.Component");
275 logClass("java.awt.focus.Component");
276 logClass("java.awt.focus.DefaultKeyboardFocusManager");
284 void doMain(String[] args)
286 if (!Platform.isJS())
288 System.setSecurityManager(null);
292 args = new String[] {};
294 // Move any new getdown-launcher-new.jar into place over old
295 // getdown-launcher.jar
296 String appdirString = System.getProperty("getdownappdir");
297 if (appdirString != null && appdirString.length() > 0)
299 final File appdir = new File(appdirString);
305 LaunchUtil.upgradeGetdown(
306 new File(appdir, "getdown-launcher-old.jar"),
307 new File(appdir, "getdown-launcher.jar"),
308 new File(appdir, "getdown-launcher-new.jar"));
313 // get args needed before proper ArgParser
314 BootstrapArgs bootstrapArgs = BootstrapArgs.getBootstrapArgs(args);
316 if (!Platform.isJS())
318 // are we being --quiet ?
319 if (bootstrapArgs.contains(Arg.QUIET))
321 OutputStream devNull = new OutputStream()
324 public void write(int b)
329 System.setOut(new PrintStream(devNull));
330 // redirecting stderr not working
331 if (bootstrapArgs.getList(Arg.QUIET).size() > 1)
333 System.setErr(new PrintStream(devNull));
339 .println("Java version: " + System.getProperty("java.version"));
340 System.out.println("Java Home: " + System.getProperty("java.home"));
341 System.out.println(System.getProperty("os.arch") + " "
342 + System.getProperty("os.name") + " "
343 + System.getProperty("os.version"));
345 String val = System.getProperty("sys.install4jVersion");
348 System.out.println("Install4j version: " + val);
350 val = System.getProperty("installer_template_version");
353 System.out.println("Install4j template version: " + val);
355 val = System.getProperty("launcher_version");
358 System.out.println("Launcher version: " + val);
361 if (Platform.isLinux() && LaunchUtils.getJavaVersion() < 11)
363 System.setProperty("flatlaf.uiScale", "1");
366 // get bootstrap properties (mainly for the logger level)
367 Properties bootstrapProperties = Cache
368 .bootstrapProperties(bootstrapArgs.get(Arg.PROPS));
370 // report Jalview version
371 Cache.loadBuildProperties(true);
374 ArgsParser aparser = new ArgsParser(args);
377 boolean headless = false;
379 boolean headlessArg = false;
383 String logLevel = bootstrapArgs.contains(Arg.DEBUG) ? "DEBUG" : null;
384 if (logLevel == null && !(bootstrapProperties == null))
386 logLevel = bootstrapProperties.getProperty(Cache.JALVIEWLOGLEVEL);
388 Console.initLogger(logLevel);
389 } catch (NoClassDefFoundError error)
391 error.printStackTrace();
392 String message = "\nEssential logging libraries not found."
393 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview";
394 Jalview.exit(message, 0);
397 // register SIGTERM listener
398 Runtime.getRuntime().addShutdownHook(new Thread()
402 Console.debug("Running shutdown hook");
403 if (QuitHandler.gotQuitResponse() == QResponse.CANCEL_QUIT)
405 // Got to here by a SIGTERM signal.
406 // Note we will not actually cancel the quit from here -- it's too
407 // late -- but we can wait for saving files.
408 Console.debug("Checking for saving files");
409 QuitHandler.getQuitResponse(false);
413 Console.debug("Nothing more to do");
415 Console.debug("Exiting, bye!");
416 // shutdownHook cannot be cancelled, JVM will now halt
420 String usrPropsFile = bootstrapArgs.contains(Arg.PROPS)
421 ? bootstrapArgs.get(Arg.PROPS)
422 : aparser.getValue("props");
423 // if usrPropsFile == null, loadProperties will use the Channel
425 Cache.loadProperties(usrPropsFile);
426 if (usrPropsFile != null)
429 "CMD [-props " + usrPropsFile + "] executed successfully!");
434 // --argfile=... -- OVERRIDES ALL NON-BOOTSTRAP ARGS
435 if (bootstrapArgs.contains(Arg.ARGFILE))
437 argparser = ArgParser.parseArgFiles(
438 bootstrapArgs.getList(Arg.ARGFILE),
439 bootstrapArgs.getBoolean(Arg.INITSUBSTITUTIONS));
443 argparser = new ArgParser(args,
444 bootstrapArgs.getBoolean(Arg.INITSUBSTITUTIONS));
447 if (!Platform.isJS())
454 if (bootstrapArgs.contains(Arg.HELP))
456 System.out.println(Arg.usage());
457 Jalview.exit(null, 0);
459 if (aparser.contains("help") || aparser.contains("h"))
462 Jalview.exit(null, 0);
465 if (bootstrapArgs.contains(Arg.HEADLESS))
467 System.setProperty("java.awt.headless", "true");
469 headlessArg = argparser.getBool(Arg.HEADLESS);
471 if (aparser.contains("nodisplay") || aparser.contains("nogui")
472 || aparser.contains("headless"))
474 System.setProperty("java.awt.headless", "true");
480 // allow https handshakes to download intermediate certs if necessary
481 System.setProperty("com.sun.security.enableAIAcaIssuers", "true");
483 final String jabawsUrl = aparser.getValue("jabaws");
484 if (jabawsUrl != null)
488 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
490 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
491 } catch (MalformedURLException e)
494 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
499 List<String> setprops = new ArrayList<>();
500 if (bootstrapArgs.contains(Arg.SETPROP))
502 setprops = bootstrapArgs.getList(Arg.SETPROP);
506 String sp = aparser.getValue("setprop");
510 sp = aparser.getValue("setprop");
513 for (String setprop : setprops)
515 int p = setprop.indexOf('=');
519 .println("Ignoring invalid setprop argument : " + setprop);
523 System.out.println("Executing setprop argument: " + setprop);
526 Cache.setProperty(setprop.substring(0, p),
527 setprop.substring(p + 1));
529 // DISABLED FOR SECURITY REASONS
530 // TODO: add a property to allow properties to be overriden by cli args
531 // Cache.setProperty(setprop.substring(0,p), setprop.substring(p+1));
534 if (System.getProperty("java.awt.headless") != null
535 && System.getProperty("java.awt.headless").equals("true"))
539 System.setProperty("http.agent",
540 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
544 Console.initLogger();
547 NoClassDefFoundError error)
549 error.printStackTrace();
550 String message = "\nEssential logging libraries not found."
551 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview";
552 Jalview.exit(message, 0);
556 if (!(headless || headlessArg))
560 * configure 'full' SO model if preferences say to, else use the default (full SO)
561 * - as JS currently doesn't have OBO parsing, it must use 'Lite' version
563 boolean soDefault = !Platform.isJS();
564 if (Cache.getDefault("USE_FULL_SO", soDefault))
566 SequenceOntologyFactory.setInstance(new SequenceOntology());
569 if (!(headless || headlessArg))
571 Desktop.nosplash = "false".equals(bootstrapArgs.get(Arg.SPLASH))
572 || aparser.contains("nosplash")
573 || Cache.getDefault("SPLASH", "true").equals("false");
574 desktop = new Desktop();
575 desktop.setInBatchMode(true); // indicate we are starting up
579 JalviewTaskbar.setTaskbar(this);
580 } catch (Exception e)
582 Console.info("Cannot set Taskbar");
583 Console.error(e.getMessage());
584 // e.printStackTrace();
585 } catch (Throwable t)
587 Console.info("Cannot set Taskbar");
588 Console.error(t.getMessage());
589 // t.printStackTrace();
592 // set Proxy settings before all the internet calls
593 Cache.setProxyPropertiesFromPreferences();
595 desktop.setVisible(true);
597 if (!Platform.isJS())
606 * Check to see that the JVM version being run is suitable for the Java
607 * version this Jalview was compiled for. Popup a warning if not.
609 if (!LaunchUtils.checkJavaVersion())
611 Console.warn("The Java version being used (Java "
612 + LaunchUtils.getJavaVersion()
613 + ") may lead to problems. This installation of Jalview should be used with Java "
614 + LaunchUtils.getJavaCompileVersion() + ".");
617 .getBooleanUserPreference("IGNORE_JVM_WARNING_POPUP"))
620 MessageManager.getString("label.continue") };
621 JOptionPane.showOptionDialog(null,
622 MessageManager.formatMessage(
623 "warning.wrong_jvm_version_message",
624 LaunchUtils.getJavaVersion(),
625 LaunchUtils.getJavaCompileVersion()),
627 .getString("warning.wrong_jvm_version_title"),
628 JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
629 null, options, options[0]);
633 if (!aparser.contains("nowebservicediscovery"))
635 desktop.startServiceDiscovery();
637 if (!aparser.contains("nousagestats"))
639 startUsageStats(desktop);
643 System.err.println("CMD [-nousagestats] executed successfully!");
646 if (!aparser.contains("noquestionnaire"))
648 String url = aparser.getValue("questionnaire");
651 // Start the desktop questionnaire prompter with the specified
653 Console.debug("Starting questionnaire url at " + url);
654 desktop.checkForQuestionnaire(url);
655 System.out.println("CMD questionnaire[-" + url
656 + "] executed successfully!");
660 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
662 // Start the desktop questionnaire prompter with the specified
665 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
667 String defurl = "https://www.jalview.org/cgi-bin/questionnaire.pl";
669 "Starting questionnaire with default url: " + defurl);
670 desktop.checkForQuestionnaire(defurl);
677 .println("CMD [-noquestionnaire] executed successfully!");
680 if ((!aparser.contains("nonews")
681 && Cache.getProperty("NONEWS") == null
682 && !"false".equals(bootstrapArgs.get(Arg.NEWS)))
683 || "true".equals(bootstrapArgs.get(Arg.NEWS)))
685 desktop.checkForNews();
688 if (!aparser.contains("nohtmltemplates")
689 && Cache.getProperty("NOHTMLTEMPLATES") == null)
691 BioJsHTMLOutput.updateBioJS();
695 // Run Commands from cli
696 cmds = new Commands(argparser, headlessArg);
697 boolean commandsSuccess = cmds.argsWereParsed();
702 Jalview.exit("Successfully completed commands in headless mode", 0);
704 Console.info("Successfully completed commands");
710 Jalview.exit("Error when running Commands in headless mode", 1);
712 Console.warn("Error when running commands");
715 // Check if JVM and compile version might cause problems and log if it
717 if (headless && !Platform.isJS() && !LaunchUtils.checkJavaVersion())
719 Console.warn("The Java version being used (Java "
720 + LaunchUtils.getJavaVersion()
721 + ") may lead to problems. This installation of Jalview should be used with Java "
722 + LaunchUtils.getJavaCompileVersion() + ".");
725 String file = null, data = null;
727 FileFormatI format = null;
729 DataSourceType protocol = null;
731 FileLoader fileLoader = new FileLoader(!headless);
733 String groovyscript = null; // script to execute after all loading is
734 // completed one way or another
735 // extract groovy argument and execute if necessary
736 groovyscript = aparser.getValue("groovy", true);
737 file = aparser.getValue("open", true);
739 if (file == null && desktop == null && !commandsSuccess)
741 Jalview.exit("No files to open!", 1);
745 // Finally, deal with the remaining input data.
750 desktop.setProgressBar(
752 .getString("status.processing_commandline_args"),
753 progress = System.currentTimeMillis());
755 System.out.println("CMD [-open " + file + "] executed successfully!");
757 if (!Platform.isJS())
759 * ignore in JavaScript -- can't just file existence - could load it?
764 if (!HttpUtils.startsWithHttpOrHttps(file))
766 if (!(new File(file)).exists())
771 "Can't find file '" + file + "' in headless mode", 1);
773 Console.warn("Can't find file'" + file + "'");
778 protocol = AppletFormatAdapter.checkProtocol(file);
782 format = new IdentifyFile().identify(file, protocol);
783 } catch (FileFormatException e1)
788 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
792 System.out.println("error");
796 setCurrentAlignFrame(af);
797 data = aparser.getValue("colour", true);
800 data.replaceAll("%20", " ");
802 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
803 af.getViewport(), af.getViewport().getAlignment(), data);
808 "CMD [-colour " + data + "] executed successfully!");
813 // Must maintain ability to use the groups flag
814 data = aparser.getValue("groups", true);
817 af.parseFeaturesFile(data,
818 AppletFormatAdapter.checkProtocol(data));
819 // System.out.println("Added " + data);
821 "CMD groups[-" + data + "] executed successfully!");
823 data = aparser.getValue("features", true);
826 af.parseFeaturesFile(data,
827 AppletFormatAdapter.checkProtocol(data));
828 // System.out.println("Added " + data);
830 "CMD [-features " + data + "] executed successfully!");
833 data = aparser.getValue("annotations", true);
836 af.loadJalviewDataFile(data, null, null, null);
837 // System.out.println("Added " + data);
839 "CMD [-annotations " + data + "] executed successfully!");
841 // set or clear the sortbytree flag.
842 if (aparser.contains("sortbytree"))
844 af.getViewport().setSortByTree(true);
845 if (af.getViewport().getSortByTree())
847 System.out.println("CMD [-sortbytree] executed successfully!");
850 if (aparser.contains("no-annotation"))
852 af.getViewport().setShowAnnotation(false);
853 if (!af.getViewport().isShowAnnotation())
855 System.out.println("CMD no-annotation executed successfully!");
858 if (aparser.contains("nosortbytree"))
860 af.getViewport().setSortByTree(false);
861 if (!af.getViewport().getSortByTree())
864 .println("CMD [-nosortbytree] executed successfully!");
867 data = aparser.getValue("tree", true);
873 "CMD [-tree " + data + "] executed successfully!");
874 NewickFile nf = new NewickFile(data,
875 AppletFormatAdapter.checkProtocol(data));
877 .setCurrentTree(af.showNewickTree(nf, data).getTree());
878 } catch (IOException ex)
880 System.err.println("Couldn't add tree " + data);
881 ex.printStackTrace(System.err);
884 // TODO - load PDB structure(s) to alignment JAL-629
885 // (associate with identical sequence in alignment, or a specified
887 if (groovyscript != null)
889 // Execute the groovy script after we've done all the rendering stuff
890 // and before any images or figures are generated.
891 System.out.println("Executing script " + groovyscript);
892 executeGroovyScript(groovyscript, af);
893 System.out.println("CMD groovy[" + groovyscript
894 + "] executed successfully!");
897 String imageName = "unnamed.png";
898 while (aparser.getSize() > 1)
900 String outputFormat = aparser.nextValue();
901 file = aparser.nextValue();
903 if (outputFormat.equalsIgnoreCase("png"))
905 af.createPNG(new File(file));
906 imageName = (new File(file)).getName();
907 System.out.println("Creating PNG image: " + file);
910 else if (outputFormat.equalsIgnoreCase("svg"))
912 File imageFile = new File(file);
913 imageName = imageFile.getName();
914 af.createSVG(imageFile);
915 System.out.println("Creating SVG image: " + file);
918 else if (outputFormat.equalsIgnoreCase("html"))
920 File imageFile = new File(file);
921 imageName = imageFile.getName();
922 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
923 htmlSVG.exportHTML(file);
925 System.out.println("Creating HTML image: " + file);
928 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
932 System.err.println("The output html file must not be null");
937 BioJsHTMLOutput.refreshVersionInfo(
938 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
939 } catch (URISyntaxException e)
943 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
944 bjs.exportHTML(file);
946 .println("Creating BioJS MSA Viwer HTML file: " + file);
949 else if (outputFormat.equalsIgnoreCase("imgMap"))
951 af.createImageMap(new File(file), imageName);
952 System.out.println("Creating image map: " + file);
955 else if (outputFormat.equalsIgnoreCase("eps"))
957 File outputFile = new File(file);
959 "Creating EPS file: " + outputFile.getAbsolutePath());
960 af.createEPS(outputFile);
963 FileFormatI outFormat = null;
966 outFormat = FileFormats.getInstance().forName(outputFormat);
967 } catch (Exception formatP)
969 System.out.println("Couldn't parse " + outFormat
970 + " as a valid Jalview format string.");
972 if (outFormat != null)
974 if (!outFormat.isWritable())
977 "This version of Jalview does not support alignment export as "
982 af.saveAlignment(file, outFormat);
983 if (af.isSaveAlignmentSuccessful())
985 System.out.println("Written alignment in "
986 + outFormat.getName() + " format to " + file);
990 System.out.println("Error writing file " + file + " in "
991 + outFormat.getName() + " format!!");
998 while (aparser.getSize() > 0)
1000 System.out.println("Unknown arg: " + aparser.nextValue());
1005 AlignFrame startUpAlframe = null;
1006 // We'll only open the default file if the desktop is visible.
1008 // ////////////////////
1010 if (!Platform.isJS() && !headless && file == null
1011 && Cache.getDefault("SHOW_STARTUP_FILE", true)
1012 && !cmds.commandArgsProvided())
1013 // don't open the startup file if command line args have been processed
1014 // (&& !Commands.commandArgsProvided())
1021 file = Cache.getDefault("STARTUP_FILE",
1022 Cache.getDefault("www.jalview.org", "https://www.jalview.org")
1023 + "/examples/exampleFile_2_7.jvp");
1024 if (file.equals("http://www.jalview.org/examples/exampleFile_2_3.jar")
1026 "http://www.jalview.org/examples/exampleFile_2_7.jar"))
1028 file.replace("http:", "https:");
1029 // hardwire upgrade of the startup file
1030 file.replace("_2_3", "_2_7");
1031 file.replace("2_7.jar", "2_7.jvp");
1032 // and remove the stale setting
1033 Cache.removeProperty("STARTUP_FILE");
1036 protocol = AppletFormatAdapter.checkProtocol(file);
1038 if (file.endsWith(".jar"))
1040 format = FileFormat.Jalview;
1046 format = new IdentifyFile().identify(file, protocol);
1047 } catch (FileFormatException e)
1053 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
1055 // don't ask to save when quitting if only the startup file has been
1057 Console.debug("Resetting up-to-date flag for startup file");
1058 startUpAlframe.getViewport().setSavedUpToDate(true);
1059 // extract groovy arguments before anything else.
1062 // Once all other stuff is done, execute any groovy scripts (in order)
1063 if (groovyscript != null)
1065 if (Cache.groovyJarsPresent())
1067 System.out.println("Executing script " + groovyscript);
1068 executeGroovyScript(groovyscript, startUpAlframe);
1073 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
1077 // and finally, turn off batch mode indicator - if the desktop still exists
1078 if (desktop != null)
1082 desktop.setProgressBar(null, progress);
1084 desktop.setInBatchMode(false);
1088 private static void setLookAndFeel()
1090 // property laf = "crossplatform", "system", "gtk", "metal", "nimbus",
1092 // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
1093 // try Quaqua/Vaqua.
1094 String lafProp = System.getProperty("laf");
1095 String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
1096 String laf = "none";
1097 if (lafProp != null)
1101 else if (lafSetting != null)
1105 boolean lafSet = false;
1108 case "crossplatform":
1109 lafSet = setCrossPlatformLookAndFeel();
1112 Console.error("Could not set requested laf=" + laf);
1116 lafSet = setSystemLookAndFeel();
1119 Console.error("Could not set requested laf=" + laf);
1123 lafSet = setGtkLookAndFeel();
1126 Console.error("Could not set requested laf=" + laf);
1130 lafSet = setMetalLookAndFeel();
1133 Console.error("Could not set requested laf=" + laf);
1137 lafSet = setNimbusLookAndFeel();
1140 Console.error("Could not set requested laf=" + laf);
1144 lafSet = setFlatLookAndFeel();
1147 Console.error("Could not set requested laf=" + laf);
1151 lafSet = setMacLookAndFeel();
1154 Console.error("Could not set requested laf=" + laf);
1160 Console.error("Requested laf=" + laf + " not implemented");
1164 setSystemLookAndFeel();
1165 if (Platform.isLinux())
1167 setLinuxLookAndFeel();
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 Console.error("Unexpected Look and Feel Exception");
1187 Console.error(ex.getMessage());
1188 Console.debug(Cache.getStackTraceString(ex));
1193 private static boolean setSystemLookAndFeel()
1195 boolean set = false;
1198 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
1200 } catch (Exception ex)
1202 Console.error("Unexpected Look and Feel Exception");
1203 Console.error(ex.getMessage());
1204 Console.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)
1221 .equals(name.toLowerCase(Locale.ROOT)))
1223 className = info.getClassName();
1227 UIManager.setLookAndFeel(className);
1229 } catch (Exception ex)
1231 Console.error("Unexpected Look and Feel Exception");
1232 Console.error(ex.getMessage());
1233 Console.debug(Cache.getStackTraceString(ex));
1238 private static boolean setGtkLookAndFeel()
1240 return setSpecificLookAndFeel("gtk",
1241 "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true);
1244 private static boolean setMetalLookAndFeel()
1246 return setSpecificLookAndFeel("metal",
1247 "javax.swing.plaf.metal.MetalLookAndFeel", false);
1250 private static boolean setNimbusLookAndFeel()
1252 return setSpecificLookAndFeel("nimbus",
1253 "javax.swing.plaf.nimbus.NimbusLookAndFeel", false);
1256 private static boolean setFlatLookAndFeel()
1258 boolean set = false;
1259 if (SystemInfo.isMacOS)
1263 UIManager.setLookAndFeel(
1264 "com.formdev.flatlaf.themes.FlatMacLightLaf");
1266 Console.debug("Using FlatMacLightLaf");
1267 } catch (ClassNotFoundException | InstantiationException
1268 | IllegalAccessException | UnsupportedLookAndFeelException e)
1270 Console.debug("Exception loading FlatLightLaf", e);
1272 System.setProperty("apple.laf.useScreenMenuBar", "true");
1273 System.setProperty("apple.awt.application.name",
1274 ChannelProperties.getProperty("app_name"));
1275 System.setProperty("apple.awt.application.appearance", "system");
1276 if (SystemInfo.isMacFullWindowContentSupported
1277 && Desktop.desktop != null)
1279 Console.debug("Setting transparent title bar");
1280 Desktop.desktop.getRootPane()
1281 .putClientProperty("apple.awt.fullWindowContent", true);
1282 Desktop.desktop.getRootPane()
1283 .putClientProperty("apple.awt.transparentTitleBar", true);
1284 Desktop.desktop.getRootPane()
1285 .putClientProperty("apple.awt.fullscreenable", true);
1287 SwingUtilities.invokeLater(() -> {
1288 FlatMacLightLaf.setup();
1290 Console.debug("Using FlatMacLightLaf");
1297 UIManager.setLookAndFeel("com.formdev.flatlaf.FlatLightLaf");
1299 Console.debug("Using FlatLightLaf");
1300 } catch (ClassNotFoundException | InstantiationException
1301 | IllegalAccessException | UnsupportedLookAndFeelException e)
1303 Console.debug("Exception loading FlatLightLaf", e);
1305 // Windows specific properties here
1306 SwingUtilities.invokeLater(() -> {
1307 FlatLightLaf.setup();
1309 Console.debug("Using FlatLightLaf");
1312 else if (SystemInfo.isLinux)
1316 UIManager.setLookAndFeel("com.formdev.flatlaf.FlatLightLaf");
1318 Console.debug("Using FlatLightLaf");
1319 } catch (ClassNotFoundException | InstantiationException
1320 | IllegalAccessException | UnsupportedLookAndFeelException e)
1322 Console.debug("Exception loading FlatLightLaf", e);
1324 // enable custom window decorations
1325 JFrame.setDefaultLookAndFeelDecorated(true);
1326 JDialog.setDefaultLookAndFeelDecorated(true);
1327 SwingUtilities.invokeLater(() -> {
1328 FlatLightLaf.setup();
1330 Console.debug("Using FlatLightLaf");
1338 UIManager.setLookAndFeel("com.formdev.flatlaf.FlatLightLaf");
1340 Console.debug("Using FlatLightLaf");
1341 } catch (ClassNotFoundException | InstantiationException
1342 | IllegalAccessException | UnsupportedLookAndFeelException e)
1344 Console.debug("Exception loading FlatLightLaf", e);
1350 UIManager.put("TabbedPane.tabType", "card");
1351 UIManager.put("TabbedPane.showTabSeparators", true);
1352 UIManager.put("TabbedPane.showContentSeparator", true);
1353 UIManager.put("TabbedPane.tabSeparatorsFullHeight", true);
1354 UIManager.put("TabbedPane.tabsOverlapBorder", true);
1355 UIManager.put("TabbedPane.hasFullBorder", true);
1356 UIManager.put("TabbedPane.tabLayoutPolicy", "scroll");
1357 UIManager.put("TabbedPane.scrollButtonsPolicy", "asNeeded");
1358 UIManager.put("TabbedPane.smoothScrolling", true);
1359 UIManager.put("TabbedPane.tabWidthMode", "compact");
1360 UIManager.put("TabbedPane.selectedBackground", Color.white);
1363 Desktop.setLiveDragMode(Cache.getDefault("FLAT_LIVE_DRAG_MODE", true));
1367 private static boolean setMacLookAndFeel()
1369 boolean set = false;
1370 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
1371 ChannelProperties.getProperty("app_name"));
1372 System.setProperty("apple.laf.useScreenMenuBar", "true");
1374 * broken native LAFs on (ARM?) macbooks
1375 set = setQuaquaLookAndFeel();
1376 if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
1377 .toLowerCase(Locale.ROOT).contains("quaqua"))
1379 set = setVaquaLookAndFeel();
1382 set = setFlatLookAndFeel();
1386 private static boolean setLinuxLookAndFeel()
1388 boolean set = false;
1389 set = setFlatLookAndFeel();
1391 set = setMetalLookAndFeel();
1392 // avoid GtkLookAndFeel -- not good results especially on HiDPI
1394 set = setNimbusLookAndFeel();
1398 private static void showUsage()
1401 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1402 + "-nodisplay\tRun Jalview without User Interface.\n"
1403 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1404 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1405 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1406 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1407 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1408 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1409 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1410 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1411 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1412 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1413 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1414 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1415 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1416 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1417 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1418 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1419 + "-html FILE\tCreate HTML file from alignment.\n"
1420 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1421 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1422 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1423 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1424 + "-noquestionnaire\tTurn off questionnaire check.\n"
1425 + "-nonews\tTurn off check for Jalview news.\n"
1426 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1427 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1429 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1430 // after all other properties files have been read\n\t
1431 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1432 // passed in correctly)"
1433 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1434 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1435 + "-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"
1436 + "-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"
1437 + "-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"
1438 + "\n~Read documentation in Application or visit https://www.jalview.org for description of Features and Annotations file~\n\n");
1441 private static void startUsageStats(final Desktop desktop)
1444 * start a User Config prompt asking if we can log usage statistics.
1446 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
1447 "USAGESTATS", "Jalview Usage Statistics",
1448 "Do you want to help make Jalview better by enabling "
1449 + "the collection of usage statistics with Google Analytics ?"
1450 + "\n\n(you can enable or disable usage tracking in the preferences)",
1457 "Initialising googletracker for usage stats.");
1458 Cache.initGoogleTracker();
1459 Console.debug("Tracking enabled.");
1466 Console.debug("Not enabling Google Tracking.");
1469 desktop.addDialogThread(prompter);
1473 * Locate the given string as a file and pass it to the groovy interpreter.
1475 * @param groovyscript
1476 * the script to execute
1477 * @param jalviewContext
1478 * the Jalview Desktop object passed in to the groovy binding as the
1481 private void executeGroovyScript(String groovyscript, AlignFrame af)
1484 * for scripts contained in files
1491 if (groovyscript.trim().equals("STDIN"))
1493 // read from stdin into a tempfile and execute it
1496 tfile = File.createTempFile("jalview", "groovy");
1497 PrintWriter outfile = new PrintWriter(
1498 new OutputStreamWriter(new FileOutputStream(tfile)));
1499 BufferedReader br = new BufferedReader(
1500 new InputStreamReader(System.in));
1502 while ((line = br.readLine()) != null)
1504 outfile.write(line + "\n");
1510 } catch (Exception ex)
1512 System.err.println("Failed to read from STDIN into tempfile "
1513 + ((tfile == null) ? "(tempfile wasn't created)"
1514 : tfile.toString()));
1515 ex.printStackTrace();
1520 sfile = tfile.toURI().toURL();
1521 } catch (Exception x)
1524 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1526 x.printStackTrace();
1534 sfile = new URI(groovyscript).toURL();
1535 } catch (Exception x)
1537 tfile = new File(groovyscript);
1538 if (!tfile.exists())
1540 System.err.println("File '" + groovyscript + "' does not exist.");
1543 if (!tfile.canRead())
1545 System.err.println("File '" + groovyscript + "' cannot be read.");
1548 if (tfile.length() < 1)
1550 System.err.println("File '" + groovyscript + "' is empty.");
1555 sfile = tfile.getAbsoluteFile().toURI().toURL();
1556 } catch (Exception ex)
1558 System.err.println("Failed to create a file URL for "
1559 + tfile.getAbsoluteFile());
1566 Map<String, java.lang.Object> vbinding = new HashMap<>();
1567 vbinding.put("Jalview", this);
1570 vbinding.put("currentAlFrame", af);
1572 Binding gbinding = new Binding(vbinding);
1573 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1574 gse.run(sfile.toString(), gbinding);
1575 if ("STDIN".equals(groovyscript))
1577 // delete temp file that we made -
1578 // only if it was successfully executed
1581 } catch (Exception e)
1583 System.err.println("Exception Whilst trying to execute file " + sfile
1584 + " as a groovy script.");
1585 e.printStackTrace(System.err);
1590 public static boolean isHeadlessMode()
1592 String isheadless = System.getProperty("java.awt.headless");
1593 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1600 public AlignFrame[] getAlignFrames()
1602 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1603 : Desktop.getAlignFrames();
1608 * jalview.bin.Jalview.quit() will just run the non-GUI shutdownHook and exit
1612 // System.exit will run the shutdownHook first
1613 Jalview.exit("Quitting now. Bye!", 0);
1616 public static AlignFrame getCurrentAlignFrame()
1618 return Jalview.currentAlignFrame;
1621 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1623 Jalview.currentAlignFrame = currentAlignFrame;
1626 protected Commands getCommands()
1631 public static void exit(String message, int exitcode)
1633 Console.debug("Using Jalview.exit");
1634 if (message != null)
1636 Console.info(message);
1638 Console.error(message);
1640 System.exit(exitcode);