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()
325 public void write(int b)
330 System.setOut(new PrintStream(devNull));
331 // redirecting stderr not working
332 if (bootstrapArgs.getList(Arg.QUIET).size() > 1)
334 System.setErr(new PrintStream(devNull));
340 .println("Java version: " + System.getProperty("java.version"));
341 System.out.println("Java Home: " + System.getProperty("java.home"));
342 System.out.println(System.getProperty("os.arch") + " "
343 + System.getProperty("os.name") + " "
344 + System.getProperty("os.version"));
346 String val = System.getProperty("sys.install4jVersion");
349 System.out.println("Install4j version: " + val);
351 val = System.getProperty("installer_template_version");
354 System.out.println("Install4j template version: " + val);
356 val = System.getProperty("launcher_version");
359 System.out.println("Launcher version: " + val);
362 if (Platform.isLinux() && LaunchUtils.getJavaVersion() < 11)
364 System.setProperty("flatlaf.uiScale", "1");
367 // get bootstrap properties (mainly for the logger level)
368 Properties bootstrapProperties = Cache
369 .bootstrapProperties(bootstrapArgs.get(Arg.PROPS));
371 // report Jalview version
372 Cache.loadBuildProperties(true);
375 ArgsParser aparser = new ArgsParser(args);
378 boolean headless = false;
380 boolean headlessArg = false;
384 String logLevel = null;
385 if (bootstrapArgs.contains(Arg.TRACE))
389 else if (bootstrapArgs.contains(Arg.DEBUG))
393 if (logLevel == null && !(bootstrapProperties == null))
395 logLevel = bootstrapProperties.getProperty(Cache.JALVIEWLOGLEVEL);
397 Console.initLogger(logLevel);
398 } catch (NoClassDefFoundError error)
400 error.printStackTrace();
401 String message = "\nEssential logging libraries not found."
402 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview";
403 Jalview.exit(message, 0);
406 // register SIGTERM listener
407 Runtime.getRuntime().addShutdownHook(new Thread()
411 Console.debug("Running shutdown hook");
412 if (QuitHandler.gotQuitResponse() == QResponse.CANCEL_QUIT)
414 // Got to here by a SIGTERM signal.
415 // Note we will not actually cancel the quit from here -- it's too
416 // late -- but we can wait for saving files.
417 Console.debug("Checking for saving files");
418 QuitHandler.getQuitResponse(false);
422 Console.debug("Nothing more to do");
424 Console.debug("Exiting, bye!");
425 // shutdownHook cannot be cancelled, JVM will now halt
429 String usrPropsFile = bootstrapArgs.contains(Arg.PROPS)
430 ? bootstrapArgs.get(Arg.PROPS)
431 : aparser.getValue("props");
432 // if usrPropsFile == null, loadProperties will use the Channel
434 Cache.loadProperties(usrPropsFile);
435 if (usrPropsFile != null)
438 "CMD [-props " + usrPropsFile + "] executed successfully!");
443 // --argfile=... -- OVERRIDES ALL NON-BOOTSTRAP ARGS
444 if (bootstrapArgs.contains(Arg.ARGFILE))
446 argparser = ArgParser.parseArgFiles(
447 bootstrapArgs.getList(Arg.ARGFILE),
448 bootstrapArgs.getBoolean(Arg.INITSUBSTITUTIONS));
452 argparser = new ArgParser(args,
453 bootstrapArgs.getBoolean(Arg.INITSUBSTITUTIONS));
456 if (!Platform.isJS())
463 if (bootstrapArgs.contains(Arg.HELP))
465 System.out.println(Arg.usage());
466 Jalview.exit(null, 0);
468 if (aparser.contains("help") || aparser.contains("h"))
471 Jalview.exit(null, 0);
474 if (bootstrapArgs.contains(Arg.HEADLESS))
476 System.setProperty("java.awt.headless", "true");
478 headlessArg = bootstrapArgs.getBoolean(Arg.HEADLESS);
480 if (aparser.contains("nodisplay") || aparser.contains("nogui")
481 || aparser.contains("headless"))
483 System.setProperty("java.awt.headless", "true");
489 // allow https handshakes to download intermediate certs if necessary
490 System.setProperty("com.sun.security.enableAIAcaIssuers", "true");
492 final String jabawsUrl = aparser.getValue("jabaws");
493 if (jabawsUrl != null)
497 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
499 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
500 } catch (MalformedURLException e)
503 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
508 List<String> setprops = new ArrayList<>();
509 if (bootstrapArgs.contains(Arg.SETPROP))
511 setprops = bootstrapArgs.getList(Arg.SETPROP);
515 String sp = aparser.getValue("setprop");
519 sp = aparser.getValue("setprop");
522 for (String setprop : setprops)
524 int p = setprop.indexOf('=');
528 .println("Ignoring invalid setprop argument : " + setprop);
532 System.out.println("Executing setprop argument: " + setprop);
535 Cache.setProperty(setprop.substring(0, p),
536 setprop.substring(p + 1));
538 // DISABLED FOR SECURITY REASONS
539 // TODO: add a property to allow properties to be overriden by cli args
540 // Cache.setProperty(setprop.substring(0,p), setprop.substring(p+1));
543 if (System.getProperty("java.awt.headless") != null
544 && System.getProperty("java.awt.headless").equals("true"))
548 System.setProperty("http.agent",
549 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
553 Console.initLogger();
556 NoClassDefFoundError error)
558 error.printStackTrace();
559 String message = "\nEssential logging libraries not found."
560 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview";
561 Jalview.exit(message, 0);
565 if (!(headless || headlessArg))
569 * configure 'full' SO model if preferences say to, else use the default (full SO)
570 * - as JS currently doesn't have OBO parsing, it must use 'Lite' version
572 boolean soDefault = !Platform.isJS();
573 if (Cache.getDefault("USE_FULL_SO", soDefault))
575 SequenceOntologyFactory.setInstance(new SequenceOntology());
578 if (!(headless || headlessArg))
580 Desktop.nosplash = "false".equals(bootstrapArgs.get(Arg.SPLASH))
581 || aparser.contains("nosplash")
582 || Cache.getDefault("SPLASH", "true").equals("false");
583 desktop = new Desktop();
584 desktop.setInBatchMode(true); // indicate we are starting up
588 JalviewTaskbar.setTaskbar(this);
589 } catch (Exception e)
591 Console.info("Cannot set Taskbar");
592 Console.error(e.getMessage());
593 // e.printStackTrace();
594 } catch (Throwable t)
596 Console.info("Cannot set Taskbar");
597 Console.error(t.getMessage());
598 // t.printStackTrace();
601 // set Proxy settings before all the internet calls
602 Cache.setProxyPropertiesFromPreferences();
604 desktop.setVisible(true);
606 if (!Platform.isJS())
615 * Check to see that the JVM version being run is suitable for the Java
616 * version this Jalview was compiled for. Popup a warning if not.
618 if (!LaunchUtils.checkJavaVersion())
620 Console.warn("The Java version being used (Java "
621 + LaunchUtils.getJavaVersion()
622 + ") may lead to problems. This installation of Jalview should be used with Java "
623 + LaunchUtils.getJavaCompileVersion() + ".");
626 .getBooleanUserPreference("IGNORE_JVM_WARNING_POPUP"))
629 MessageManager.getString("label.continue") };
630 JOptionPane.showOptionDialog(null,
631 MessageManager.formatMessage(
632 "warning.wrong_jvm_version_message",
633 LaunchUtils.getJavaVersion(),
634 LaunchUtils.getJavaCompileVersion()),
636 .getString("warning.wrong_jvm_version_title"),
637 JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
638 null, options, options[0]);
642 boolean doWebServiceDiscovery = !aparser
643 .contains("nowebservicediscovery");
644 if (bootstrapArgs.contains(Arg.WEBSERVICEDISCOVERY))
645 doWebServiceDiscovery = bootstrapArgs
646 .getBoolean(Arg.WEBSERVICEDISCOVERY);
647 if (doWebServiceDiscovery)
649 desktop.startServiceDiscovery();
651 if (!aparser.contains("nousagestats"))
653 startUsageStats(desktop);
657 System.err.println("CMD [-nousagestats] executed successfully!");
660 if (!aparser.contains("noquestionnaire"))
662 String url = aparser.getValue("questionnaire");
665 // Start the desktop questionnaire prompter with the specified
667 Console.debug("Starting questionnaire url at " + url);
668 desktop.checkForQuestionnaire(url);
669 System.out.println("CMD questionnaire[-" + url
670 + "] executed successfully!");
674 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
676 // Start the desktop questionnaire prompter with the specified
679 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
681 String defurl = "https://www.jalview.org/cgi-bin/questionnaire.pl";
683 "Starting questionnaire with default url: " + defurl);
684 desktop.checkForQuestionnaire(defurl);
691 .println("CMD [-noquestionnaire] executed successfully!");
694 if ((!aparser.contains("nonews")
695 && Cache.getProperty("NONEWS") == null
696 && !"false".equals(bootstrapArgs.get(Arg.NEWS)))
697 || "true".equals(bootstrapArgs.get(Arg.NEWS)))
699 desktop.checkForNews();
702 if (!aparser.contains("nohtmltemplates")
703 && Cache.getProperty("NOHTMLTEMPLATES") == null)
705 BioJsHTMLOutput.updateBioJS();
709 // Run Commands from cli
710 cmds = new Commands(argparser, headlessArg);
711 boolean commandsSuccess = cmds.argsWereParsed();
716 Jalview.exit("Successfully completed commands in headless mode", 0);
718 Console.info("Successfully completed commands");
724 Jalview.exit("Error when running Commands in headless mode", 1);
726 Console.warn("Error when running commands");
729 // Check if JVM and compile version might cause problems and log if it
731 if (headless && !Platform.isJS() && !LaunchUtils.checkJavaVersion())
733 Console.warn("The Java version being used (Java "
734 + LaunchUtils.getJavaVersion()
735 + ") may lead to problems. This installation of Jalview should be used with Java "
736 + LaunchUtils.getJavaCompileVersion() + ".");
739 String file = null, data = null;
741 FileFormatI format = null;
743 DataSourceType protocol = null;
745 FileLoader fileLoader = new FileLoader(!headless);
747 String groovyscript = null; // script to execute after all loading is
748 // completed one way or another
749 // extract groovy argument and execute if necessary
750 groovyscript = aparser.getValue("groovy", true);
751 file = aparser.getValue("open", true);
753 if (file == null && desktop == null && !commandsSuccess)
755 Jalview.exit("No files to open!", 1);
759 // Finally, deal with the remaining input data.
764 desktop.setProgressBar(
766 .getString("status.processing_commandline_args"),
767 progress = System.currentTimeMillis());
769 System.out.println("CMD [-open " + file + "] executed successfully!");
771 if (!Platform.isJS())
773 * ignore in JavaScript -- can't just file existence - could load it?
778 if (!HttpUtils.startsWithHttpOrHttps(file))
780 if (!(new File(file)).exists())
785 "Can't find file '" + file + "' in headless mode", 1);
787 Console.warn("Can't find file'" + file + "'");
792 protocol = AppletFormatAdapter.checkProtocol(file);
796 format = new IdentifyFile().identify(file, protocol);
797 } catch (FileFormatException e1)
802 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
806 System.out.println("error");
810 setCurrentAlignFrame(af);
811 data = aparser.getValue("colour", true);
814 data.replaceAll("%20", " ");
816 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
817 af.getViewport(), af.getViewport().getAlignment(), data);
822 "CMD [-colour " + data + "] executed successfully!");
827 // Must maintain ability to use the groups flag
828 data = aparser.getValue("groups", true);
831 af.parseFeaturesFile(data,
832 AppletFormatAdapter.checkProtocol(data));
833 // System.out.println("Added " + data);
835 "CMD groups[-" + data + "] executed successfully!");
837 data = aparser.getValue("features", true);
840 af.parseFeaturesFile(data,
841 AppletFormatAdapter.checkProtocol(data));
842 // System.out.println("Added " + data);
844 "CMD [-features " + data + "] executed successfully!");
847 data = aparser.getValue("annotations", true);
850 af.loadJalviewDataFile(data, null, null, null);
851 // System.out.println("Added " + data);
853 "CMD [-annotations " + data + "] executed successfully!");
855 // set or clear the sortbytree flag.
856 if (aparser.contains("sortbytree"))
858 af.getViewport().setSortByTree(true);
859 if (af.getViewport().getSortByTree())
861 System.out.println("CMD [-sortbytree] executed successfully!");
864 if (aparser.contains("no-annotation"))
866 af.getViewport().setShowAnnotation(false);
867 if (!af.getViewport().isShowAnnotation())
869 System.out.println("CMD no-annotation executed successfully!");
872 if (aparser.contains("nosortbytree"))
874 af.getViewport().setSortByTree(false);
875 if (!af.getViewport().getSortByTree())
878 .println("CMD [-nosortbytree] executed successfully!");
881 data = aparser.getValue("tree", true);
887 "CMD [-tree " + data + "] executed successfully!");
888 NewickFile nf = new NewickFile(data,
889 AppletFormatAdapter.checkProtocol(data));
891 .setCurrentTree(af.showNewickTree(nf, data).getTree());
892 } catch (IOException ex)
894 System.err.println("Couldn't add tree " + data);
895 ex.printStackTrace(System.err);
898 // TODO - load PDB structure(s) to alignment JAL-629
899 // (associate with identical sequence in alignment, or a specified
901 if (groovyscript != null)
903 // Execute the groovy script after we've done all the rendering stuff
904 // and before any images or figures are generated.
905 System.out.println("Executing script " + groovyscript);
906 executeGroovyScript(groovyscript, af);
907 System.out.println("CMD groovy[" + groovyscript
908 + "] executed successfully!");
911 String imageName = "unnamed.png";
912 while (aparser.getSize() > 1)
914 String outputFormat = aparser.nextValue();
915 file = aparser.nextValue();
917 if (outputFormat.equalsIgnoreCase("png"))
919 af.createPNG(new File(file));
920 imageName = (new File(file)).getName();
921 System.out.println("Creating PNG image: " + file);
924 else if (outputFormat.equalsIgnoreCase("svg"))
926 File imageFile = new File(file);
927 imageName = imageFile.getName();
928 af.createSVG(imageFile);
929 System.out.println("Creating SVG image: " + file);
932 else if (outputFormat.equalsIgnoreCase("html"))
934 File imageFile = new File(file);
935 imageName = imageFile.getName();
936 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
937 htmlSVG.exportHTML(file);
939 System.out.println("Creating HTML image: " + file);
942 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
946 System.err.println("The output html file must not be null");
951 BioJsHTMLOutput.refreshVersionInfo(
952 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
953 } catch (URISyntaxException e)
957 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
958 bjs.exportHTML(file);
960 .println("Creating BioJS MSA Viwer HTML file: " + file);
963 else if (outputFormat.equalsIgnoreCase("imgMap"))
965 af.createImageMap(new File(file), imageName);
966 System.out.println("Creating image map: " + file);
969 else if (outputFormat.equalsIgnoreCase("eps"))
971 File outputFile = new File(file);
973 "Creating EPS file: " + outputFile.getAbsolutePath());
974 af.createEPS(outputFile);
977 FileFormatI outFormat = null;
980 outFormat = FileFormats.getInstance().forName(outputFormat);
981 } catch (Exception formatP)
983 System.out.println("Couldn't parse " + outFormat
984 + " as a valid Jalview format string.");
986 if (outFormat != null)
988 if (!outFormat.isWritable())
991 "This version of Jalview does not support alignment export as "
996 af.saveAlignment(file, outFormat);
997 if (af.isSaveAlignmentSuccessful())
999 System.out.println("Written alignment in "
1000 + outFormat.getName() + " format to " + file);
1004 System.out.println("Error writing file " + file + " in "
1005 + outFormat.getName() + " format!!");
1012 while (aparser.getSize() > 0)
1014 System.out.println("Unknown arg: " + aparser.nextValue());
1019 AlignFrame startUpAlframe = null;
1020 // We'll only open the default file if the desktop is visible.
1022 // ////////////////////
1024 if (!Platform.isJS() && !headless && file == null
1025 && Cache.getDefault("SHOW_STARTUP_FILE", true)
1026 && !cmds.commandArgsProvided())
1027 // don't open the startup file if command line args have been processed
1028 // (&& !Commands.commandArgsProvided())
1035 file = Cache.getDefault("STARTUP_FILE",
1036 Cache.getDefault("www.jalview.org", "https://www.jalview.org")
1037 + "/examples/exampleFile_2_7.jvp");
1038 if (file.equals("http://www.jalview.org/examples/exampleFile_2_3.jar")
1040 "http://www.jalview.org/examples/exampleFile_2_7.jar"))
1042 file.replace("http:", "https:");
1043 // hardwire upgrade of the startup file
1044 file.replace("_2_3", "_2_7");
1045 file.replace("2_7.jar", "2_7.jvp");
1046 // and remove the stale setting
1047 Cache.removeProperty("STARTUP_FILE");
1050 protocol = AppletFormatAdapter.checkProtocol(file);
1052 if (file.endsWith(".jar"))
1054 format = FileFormat.Jalview;
1060 format = new IdentifyFile().identify(file, protocol);
1061 } catch (FileFormatException e)
1067 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
1069 // don't ask to save when quitting if only the startup file has been
1071 Console.debug("Resetting up-to-date flag for startup file");
1072 startUpAlframe.getViewport().setSavedUpToDate(true);
1073 // extract groovy arguments before anything else.
1076 // Once all other stuff is done, execute any groovy scripts (in order)
1077 if (groovyscript != null)
1079 if (Cache.groovyJarsPresent())
1081 System.out.println("Executing script " + groovyscript);
1082 executeGroovyScript(groovyscript, startUpAlframe);
1087 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
1091 // and finally, turn off batch mode indicator - if the desktop still exists
1092 if (desktop != null)
1096 desktop.setProgressBar(null, progress);
1098 desktop.setInBatchMode(false);
1102 private static void setLookAndFeel()
1104 // property laf = "crossplatform", "system", "gtk", "metal", "nimbus",
1106 // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
1107 // try Quaqua/Vaqua.
1108 String lafProp = System.getProperty("laf");
1109 String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
1110 String laf = "none";
1111 if (lafProp != null)
1115 else if (lafSetting != null)
1119 boolean lafSet = false;
1122 case "crossplatform":
1123 lafSet = setCrossPlatformLookAndFeel();
1126 Console.error("Could not set requested laf=" + laf);
1130 lafSet = setSystemLookAndFeel();
1133 Console.error("Could not set requested laf=" + laf);
1137 lafSet = setGtkLookAndFeel();
1140 Console.error("Could not set requested laf=" + laf);
1144 lafSet = setMetalLookAndFeel();
1147 Console.error("Could not set requested laf=" + laf);
1151 lafSet = setNimbusLookAndFeel();
1154 Console.error("Could not set requested laf=" + laf);
1158 lafSet = setFlatLookAndFeel();
1161 Console.error("Could not set requested laf=" + laf);
1165 lafSet = setMacLookAndFeel();
1168 Console.error("Could not set requested laf=" + laf);
1174 Console.error("Requested laf=" + laf + " not implemented");
1178 setSystemLookAndFeel();
1179 if (Platform.isLinux())
1181 setLinuxLookAndFeel();
1183 if (Platform.isMac())
1185 setMacLookAndFeel();
1190 private static boolean setCrossPlatformLookAndFeel()
1192 boolean set = false;
1195 UIManager.setLookAndFeel(
1196 UIManager.getCrossPlatformLookAndFeelClassName());
1198 } catch (Exception ex)
1200 Console.error("Unexpected Look and Feel Exception");
1201 Console.error(ex.getMessage());
1202 Console.debug(Cache.getStackTraceString(ex));
1207 private static boolean setSystemLookAndFeel()
1209 boolean set = false;
1212 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
1214 } catch (Exception ex)
1216 Console.error("Unexpected Look and Feel Exception");
1217 Console.error(ex.getMessage());
1218 Console.debug(Cache.getStackTraceString(ex));
1223 private static boolean setSpecificLookAndFeel(String name,
1224 String className, boolean nameStartsWith)
1226 boolean set = false;
1229 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
1231 if (info.getName() != null && nameStartsWith
1232 ? info.getName().toLowerCase(Locale.ROOT)
1233 .startsWith(name.toLowerCase(Locale.ROOT))
1234 : info.getName().toLowerCase(Locale.ROOT)
1235 .equals(name.toLowerCase(Locale.ROOT)))
1237 className = info.getClassName();
1241 UIManager.setLookAndFeel(className);
1243 } catch (Exception ex)
1245 Console.error("Unexpected Look and Feel Exception");
1246 Console.error(ex.getMessage());
1247 Console.debug(Cache.getStackTraceString(ex));
1252 private static boolean setGtkLookAndFeel()
1254 return setSpecificLookAndFeel("gtk",
1255 "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true);
1258 private static boolean setMetalLookAndFeel()
1260 return setSpecificLookAndFeel("metal",
1261 "javax.swing.plaf.metal.MetalLookAndFeel", false);
1264 private static boolean setNimbusLookAndFeel()
1266 return setSpecificLookAndFeel("nimbus",
1267 "javax.swing.plaf.nimbus.NimbusLookAndFeel", false);
1270 private static boolean setFlatLookAndFeel()
1272 boolean set = false;
1273 if (SystemInfo.isMacOS)
1277 UIManager.setLookAndFeel(
1278 "com.formdev.flatlaf.themes.FlatMacLightLaf");
1280 Console.debug("Using FlatMacLightLaf");
1281 } catch (ClassNotFoundException | InstantiationException
1282 | IllegalAccessException | UnsupportedLookAndFeelException e)
1284 Console.debug("Exception loading FlatLightLaf", e);
1286 System.setProperty("apple.laf.useScreenMenuBar", "true");
1287 System.setProperty("apple.awt.application.name",
1288 ChannelProperties.getProperty("app_name"));
1289 System.setProperty("apple.awt.application.appearance", "system");
1290 if (SystemInfo.isMacFullWindowContentSupported
1291 && Desktop.desktop != null)
1293 Console.debug("Setting transparent title bar");
1294 Desktop.desktop.getRootPane()
1295 .putClientProperty("apple.awt.fullWindowContent", true);
1296 Desktop.desktop.getRootPane()
1297 .putClientProperty("apple.awt.transparentTitleBar", true);
1298 Desktop.desktop.getRootPane()
1299 .putClientProperty("apple.awt.fullscreenable", true);
1301 SwingUtilities.invokeLater(() -> {
1302 FlatMacLightLaf.setup();
1304 Console.debug("Using FlatMacLightLaf");
1311 UIManager.setLookAndFeel("com.formdev.flatlaf.FlatLightLaf");
1313 Console.debug("Using FlatLightLaf");
1314 } catch (ClassNotFoundException | InstantiationException
1315 | IllegalAccessException | UnsupportedLookAndFeelException e)
1317 Console.debug("Exception loading FlatLightLaf", e);
1319 // Windows specific properties here
1320 SwingUtilities.invokeLater(() -> {
1321 FlatLightLaf.setup();
1323 Console.debug("Using FlatLightLaf");
1326 else if (SystemInfo.isLinux)
1330 UIManager.setLookAndFeel("com.formdev.flatlaf.FlatLightLaf");
1332 Console.debug("Using FlatLightLaf");
1333 } catch (ClassNotFoundException | InstantiationException
1334 | IllegalAccessException | UnsupportedLookAndFeelException e)
1336 Console.debug("Exception loading FlatLightLaf", e);
1338 // enable custom window decorations
1339 JFrame.setDefaultLookAndFeelDecorated(true);
1340 JDialog.setDefaultLookAndFeelDecorated(true);
1341 SwingUtilities.invokeLater(() -> {
1342 FlatLightLaf.setup();
1344 Console.debug("Using FlatLightLaf");
1352 UIManager.setLookAndFeel("com.formdev.flatlaf.FlatLightLaf");
1354 Console.debug("Using FlatLightLaf");
1355 } catch (ClassNotFoundException | InstantiationException
1356 | IllegalAccessException | UnsupportedLookAndFeelException e)
1358 Console.debug("Exception loading FlatLightLaf", e);
1364 UIManager.put("TabbedPane.tabType", "card");
1365 UIManager.put("TabbedPane.showTabSeparators", true);
1366 UIManager.put("TabbedPane.showContentSeparator", true);
1367 UIManager.put("TabbedPane.tabSeparatorsFullHeight", true);
1368 UIManager.put("TabbedPane.tabsOverlapBorder", true);
1369 UIManager.put("TabbedPane.hasFullBorder", true);
1370 UIManager.put("TabbedPane.tabLayoutPolicy", "scroll");
1371 UIManager.put("TabbedPane.scrollButtonsPolicy", "asNeeded");
1372 UIManager.put("TabbedPane.smoothScrolling", true);
1373 UIManager.put("TabbedPane.tabWidthMode", "compact");
1374 UIManager.put("TabbedPane.selectedBackground", Color.white);
1377 Desktop.setLiveDragMode(Cache.getDefault("FLAT_LIVE_DRAG_MODE", true));
1381 private static boolean setMacLookAndFeel()
1383 boolean set = false;
1384 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
1385 ChannelProperties.getProperty("app_name"));
1386 System.setProperty("apple.laf.useScreenMenuBar", "true");
1388 * broken native LAFs on (ARM?) macbooks
1389 set = setQuaquaLookAndFeel();
1390 if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
1391 .toLowerCase(Locale.ROOT).contains("quaqua"))
1393 set = setVaquaLookAndFeel();
1396 set = setFlatLookAndFeel();
1400 private static boolean setLinuxLookAndFeel()
1402 boolean set = false;
1403 set = setFlatLookAndFeel();
1405 set = setMetalLookAndFeel();
1406 // avoid GtkLookAndFeel -- not good results especially on HiDPI
1408 set = setNimbusLookAndFeel();
1412 private static void showUsage()
1415 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1416 + "-nodisplay\tRun Jalview without User Interface.\n"
1417 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1418 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1419 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1420 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1421 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1422 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1423 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1424 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1425 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1426 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1427 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1428 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1429 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1430 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1431 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1432 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1433 + "-html FILE\tCreate HTML file from alignment.\n"
1434 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1435 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1436 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1437 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1438 + "-noquestionnaire\tTurn off questionnaire check.\n"
1439 + "-nonews\tTurn off check for Jalview news.\n"
1440 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1441 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1443 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1444 // after all other properties files have been read\n\t
1445 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1446 // passed in correctly)"
1447 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1448 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1449 + "-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"
1450 + "-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"
1451 + "-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"
1452 + "\n~Read documentation in Application or visit https://www.jalview.org for description of Features and Annotations file~\n\n");
1455 private static void startUsageStats(final Desktop desktop)
1458 * start a User Config prompt asking if we can log usage statistics.
1460 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
1461 "USAGESTATS", "Jalview Usage Statistics",
1462 "Do you want to help make Jalview better by enabling "
1463 + "the collection of usage statistics with Google Analytics ?"
1464 + "\n\n(you can enable or disable usage tracking in the preferences)",
1471 "Initialising googletracker for usage stats.");
1472 Cache.initGoogleTracker();
1473 Console.debug("Tracking enabled.");
1480 Console.debug("Not enabling Google Tracking.");
1483 desktop.addDialogThread(prompter);
1487 * Locate the given string as a file and pass it to the groovy interpreter.
1489 * @param groovyscript
1490 * the script to execute
1491 * @param jalviewContext
1492 * the Jalview Desktop object passed in to the groovy binding as the
1495 private void executeGroovyScript(String groovyscript, AlignFrame af)
1498 * for scripts contained in files
1505 if (groovyscript.trim().equals("STDIN"))
1507 // read from stdin into a tempfile and execute it
1510 tfile = File.createTempFile("jalview", "groovy");
1511 PrintWriter outfile = new PrintWriter(
1512 new OutputStreamWriter(new FileOutputStream(tfile)));
1513 BufferedReader br = new BufferedReader(
1514 new InputStreamReader(System.in));
1516 while ((line = br.readLine()) != null)
1518 outfile.write(line + "\n");
1524 } catch (Exception ex)
1526 System.err.println("Failed to read from STDIN into tempfile "
1527 + ((tfile == null) ? "(tempfile wasn't created)"
1528 : tfile.toString()));
1529 ex.printStackTrace();
1534 sfile = tfile.toURI().toURL();
1535 } catch (Exception x)
1538 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1540 x.printStackTrace();
1548 sfile = new URI(groovyscript).toURL();
1549 } catch (Exception x)
1551 tfile = new File(groovyscript);
1552 if (!tfile.exists())
1554 System.err.println("File '" + groovyscript + "' does not exist.");
1557 if (!tfile.canRead())
1559 System.err.println("File '" + groovyscript + "' cannot be read.");
1562 if (tfile.length() < 1)
1564 System.err.println("File '" + groovyscript + "' is empty.");
1569 sfile = tfile.getAbsoluteFile().toURI().toURL();
1570 } catch (Exception ex)
1572 System.err.println("Failed to create a file URL for "
1573 + tfile.getAbsoluteFile());
1580 Map<String, java.lang.Object> vbinding = new HashMap<>();
1581 vbinding.put("Jalview", this);
1584 vbinding.put("currentAlFrame", af);
1586 Binding gbinding = new Binding(vbinding);
1587 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1588 gse.run(sfile.toString(), gbinding);
1589 if ("STDIN".equals(groovyscript))
1591 // delete temp file that we made -
1592 // only if it was successfully executed
1595 } catch (Exception e)
1597 System.err.println("Exception Whilst trying to execute file " + sfile
1598 + " as a groovy script.");
1599 e.printStackTrace(System.err);
1604 public static boolean isHeadlessMode()
1606 String isheadless = System.getProperty("java.awt.headless");
1607 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1614 public AlignFrame[] getAlignFrames()
1616 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1617 : Desktop.getAlignFrames();
1622 * jalview.bin.Jalview.quit() will just run the non-GUI shutdownHook and exit
1626 // System.exit will run the shutdownHook first
1627 Jalview.exit("Quitting now. Bye!", 0);
1630 public static AlignFrame getCurrentAlignFrame()
1632 return Jalview.currentAlignFrame;
1635 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1637 Jalview.currentAlignFrame = currentAlignFrame;
1640 protected Commands getCommands()
1645 public static void exit(String message, int exitcode)
1647 Console.debug("Using Jalview.exit");
1648 if (message != null)
1650 Console.info(message);
1652 Console.error(message);
1654 System.exit(exitcode);