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.Arg.Opt;
71 import jalview.bin.argparser.ArgParser;
72 import jalview.bin.argparser.BootstrapArgs;
73 import jalview.ext.so.SequenceOntology;
74 import jalview.gui.AlignFrame;
75 import jalview.gui.Desktop;
76 import jalview.gui.PromptUserConfig;
77 import jalview.gui.QuitHandler;
78 import jalview.gui.QuitHandler.QResponse;
79 import jalview.io.AppletFormatAdapter;
80 import jalview.io.BioJsHTMLOutput;
81 import jalview.io.DataSourceType;
82 import jalview.io.FileFormat;
83 import jalview.io.FileFormatException;
84 import jalview.io.FileFormatI;
85 import jalview.io.FileFormats;
86 import jalview.io.FileLoader;
87 import jalview.io.HtmlSvgOutput;
88 import jalview.io.IdentifyFile;
89 import jalview.io.NewickFile;
90 import jalview.io.gff.SequenceOntologyFactory;
91 import jalview.schemes.ColourSchemeI;
92 import jalview.schemes.ColourSchemeProperty;
93 import jalview.util.ChannelProperties;
94 import jalview.util.HttpUtils;
95 import jalview.util.LaunchUtils;
96 import jalview.util.MessageManager;
97 import jalview.util.Platform;
98 import jalview.ws.jws2.Jws2Discoverer;
101 * Main class for Jalview Application <br>
103 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
104 * jalview.bin.Jalview
106 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
107 * jalview.bin.Jalview jalview.bin.Jalview
109 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
110 * embellish '*' to e.g. '*.jar')
113 * @version $Revision$
119 Platform.getURLCommandArguments();
120 Platform.addJ2SDirectDatabaseCall("https://www.jalview.org");
121 Platform.addJ2SDirectDatabaseCall("http://www.jalview.org");
122 Platform.addJ2SDirectDatabaseCall("http://www.compbio.dundee.ac.uk");
123 Platform.addJ2SDirectDatabaseCall("https://www.compbio.dundee.ac.uk");
127 * singleton instance of this class
129 private static Jalview instance;
131 private Desktop desktop;
133 protected Commands cmds;
135 public static AlignFrame currentAlignFrame;
137 public ArgParser argparser = null;
139 public BootstrapArgs bootstrapArgs = null;
141 private boolean QUIET = false;
143 public static boolean quiet()
145 return Jalview.getInstance() != null && Jalview.getInstance().QUIET;
150 if (!Platform.isJS())
157 // grab all the rights we can for the JVM
158 Policy.setPolicy(new Policy()
161 public PermissionCollection getPermissions(CodeSource codesource)
163 Permissions perms = new Permissions();
164 perms.add(new AllPermission());
169 public void refresh()
177 * keep track of feature fetching tasks.
185 * TODO: generalise to track all jalview events to orchestrate batch processing
189 private int queued = 0;
191 private int running = 0;
193 public FeatureFetcher()
198 public void addFetcher(final AlignFrame af,
199 final Vector<String> dasSources)
201 final long id = System.currentTimeMillis();
203 final FeatureFetcher us = this;
204 new Thread(new Runnable()
216 af.setProgressBar(MessageManager
217 .getString("status.das_features_being_retrived"), id);
218 af.featureSettings_actionPerformed(null);
219 af.setProgressBar(null, id);
228 public synchronized boolean allFinished()
230 return queued == 0 && running == 0;
235 public static Jalview getInstance()
241 * main class for Jalview application
244 * open <em>filename</em>
246 public static void main(String[] args)
248 // setLogging(); // BH - for event debugging in JavaScript
249 instance = new Jalview();
250 instance.doMain(args);
253 private static void logClass(String name)
255 // BH - for event debugging in JavaScript
256 ConsoleHandler consoleHandler = new ConsoleHandler();
257 consoleHandler.setLevel(Level.ALL);
258 Logger logger = Logger.getLogger(name);
259 logger.setLevel(Level.ALL);
260 logger.addHandler(consoleHandler);
263 @SuppressWarnings("unused")
264 private static void setLogging()
272 System.out.println("not in js");
275 // BH - for event debugging in JavaScript (Java mode only)
276 if (!Platform.isJS())
283 Logger.getLogger("").setLevel(Level.ALL);
284 logClass("java.awt.EventDispatchThread");
285 logClass("java.awt.EventQueue");
286 logClass("java.awt.Component");
287 logClass("java.awt.focus.Component");
288 logClass("java.awt.focus.DefaultKeyboardFocusManager");
296 void doMain(String[] args)
298 if (!Platform.isJS())
300 System.setSecurityManager(null);
304 args = new String[] {};
306 // get args needed before proper ArgParser
307 bootstrapArgs = BootstrapArgs.getBootstrapArgs(args);
309 if (!Platform.isJS())
311 // are we being --quiet ?
312 if (bootstrapArgs.contains(Arg.QUIET))
315 OutputStream devNull = new OutputStream()
319 public void write(int b)
324 System.setOut(new PrintStream(devNull));
325 // redirecting stderr not working
326 if (bootstrapArgs.getList(Arg.QUIET).size() > 1)
328 System.setErr(new PrintStream(devNull));
332 if (bootstrapArgs.contains(Arg.HELP))
338 // Move any new getdown-launcher-new.jar into place over old
339 // getdown-launcher.jar
340 String appdirString = System.getProperty("getdownappdir");
341 if (appdirString != null && appdirString.length() > 0)
343 final File appdir = new File(appdirString);
349 LaunchUtil.upgradeGetdown(
350 new File(appdir, "getdown-launcher-old.jar"),
351 new File(appdir, "getdown-launcher.jar"),
352 new File(appdir, "getdown-launcher-new.jar"));
360 "Java version: " + System.getProperty("java.version"));
361 System.out.println("Java Home: " + System.getProperty("java.home"));
362 System.out.println(System.getProperty("os.arch") + " "
363 + System.getProperty("os.name") + " "
364 + System.getProperty("os.version"));
366 String val = System.getProperty("sys.install4jVersion");
369 System.out.println("Install4j version: " + val);
371 val = System.getProperty("installer_template_version");
374 System.out.println("Install4j template version: " + val);
376 val = System.getProperty("launcher_version");
379 System.out.println("Launcher version: " + val);
383 if (Platform.isLinux() && LaunchUtils.getJavaVersion() < 11)
385 System.setProperty("flatlaf.uiScale", "1");
388 // get bootstrap properties (mainly for the logger level)
389 Properties bootstrapProperties = Cache
390 .bootstrapProperties(bootstrapArgs.get(Arg.PROPS));
392 // report Jalview version
393 Cache.loadBuildProperties(true);
396 ArgsParser aparser = new ArgsParser(args);
399 boolean headless = false;
401 boolean headlessArg = false;
405 String logLevel = null;
406 if (bootstrapArgs.contains(Arg.TRACE))
410 else if (bootstrapArgs.contains(Arg.DEBUG))
414 if (logLevel == null && !(bootstrapProperties == null))
416 logLevel = bootstrapProperties.getProperty(Cache.JALVIEWLOGLEVEL);
418 Console.initLogger(logLevel);
419 } catch (NoClassDefFoundError error)
421 error.printStackTrace();
422 String message = "\nEssential logging libraries not found."
423 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview";
424 Jalview.exit(message, 0);
427 // register SIGTERM listener
428 Runtime.getRuntime().addShutdownHook(new Thread()
432 Console.debug("Running shutdown hook");
433 if (QuitHandler.gotQuitResponse() == QResponse.CANCEL_QUIT)
435 // Got to here by a SIGTERM signal.
436 // Note we will not actually cancel the quit from here -- it's too
437 // late -- but we can wait for saving files.
438 Console.debug("Checking for saving files");
439 QuitHandler.getQuitResponse(false);
443 Console.debug("Nothing more to do");
445 Console.debug("Exiting, bye!");
446 // shutdownHook cannot be cancelled, JVM will now halt
450 String usrPropsFile = bootstrapArgs.contains(Arg.PROPS)
451 ? bootstrapArgs.get(Arg.PROPS)
452 : aparser.getValue("props");
453 // if usrPropsFile == null, loadProperties will use the Channel
455 Cache.loadProperties(usrPropsFile);
456 if (usrPropsFile != null)
459 "CMD [-props " + usrPropsFile + "] executed successfully!");
460 testoutput(bootstrapArgs, Arg.PROPS,
461 "test/jalview/bin/testProps.jvprops", usrPropsFile);
464 // --argfile=... -- OVERRIDES ALL NON-BOOTSTRAP ARGS
465 if (bootstrapArgs.contains(Arg.ARGFILE))
467 argparser = ArgParser.parseArgFiles(
468 bootstrapArgs.getList(Arg.ARGFILE),
469 bootstrapArgs.getBoolean(Arg.INITSUBSTITUTIONS),
474 argparser = new ArgParser(args,
475 bootstrapArgs.getBoolean(Arg.INITSUBSTITUTIONS),
479 if (!Platform.isJS())
486 if (bootstrapArgs.contains(Arg.HELP))
488 System.out.println(Arg.usage());
489 Jalview.exit(null, 0);
491 if (aparser.contains("help") || aparser.contains("h"))
494 * Now using new usage statement.
497 System.out.println(Arg.usage());
498 Jalview.exit(null, 0);
501 if (bootstrapArgs.contains(Arg.HEADLESS))
503 System.setProperty("java.awt.headless", "true");
505 headlessArg = bootstrapArgs.getBoolean(Arg.HEADLESS);
507 if (aparser.contains("nodisplay") || aparser.contains("nogui")
508 || aparser.contains("headless"))
510 System.setProperty("java.awt.headless", "true");
516 // allow https handshakes to download intermediate certs if necessary
517 System.setProperty("com.sun.security.enableAIAcaIssuers", "true");
519 String jabawsUrl = bootstrapArgs.get(Arg.JABAWS);
520 if (jabawsUrl == null)
521 jabawsUrl = aparser.getValue("jabaws");
522 if (jabawsUrl != null)
526 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
528 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
529 testoutput(bootstrapArgs, Arg.JABAWS,
530 "http://www.compbio.dundee.ac.uk/jabaws", jabawsUrl);
531 } catch (MalformedURLException e)
534 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
539 List<String> setprops = new ArrayList<>();
540 if (bootstrapArgs.contains(Arg.SETPROP))
542 setprops = bootstrapArgs.getList(Arg.SETPROP);
546 String sp = aparser.getValue("setprop");
550 sp = aparser.getValue("setprop");
553 for (String setprop : setprops)
555 int p = setprop.indexOf('=');
559 .println("Ignoring invalid setprop argument : " + setprop);
563 System.out.println("Executing setprop argument: " + setprop);
566 Cache.setProperty(setprop.substring(0, p),
567 setprop.substring(p + 1));
569 // DISABLED FOR SECURITY REASONS
570 // TODO: add a property to allow properties to be overriden by cli args
571 // Cache.setProperty(setprop.substring(0,p), setprop.substring(p+1));
574 if (System.getProperty("java.awt.headless") != null
575 && System.getProperty("java.awt.headless").equals("true"))
579 System.setProperty("http.agent",
580 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
584 Console.initLogger();
587 NoClassDefFoundError error)
589 error.printStackTrace();
590 String message = "\nEssential logging libraries not found."
591 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview";
592 Jalview.exit(message, 0);
596 if (!(headless || headlessArg))
600 * configure 'full' SO model if preferences say to, else use the default (full SO)
601 * - as JS currently doesn't have OBO parsing, it must use 'Lite' version
603 boolean soDefault = !Platform.isJS();
604 if (Cache.getDefault("USE_FULL_SO", soDefault))
606 SequenceOntologyFactory.setInstance(new SequenceOntology());
609 if (!(headless || headlessArg))
611 Desktop.nosplash = "false".equals(bootstrapArgs.get(Arg.SPLASH))
612 || aparser.contains("nosplash")
613 || Cache.getDefault("SPLASH", "true").equals("false");
614 desktop = new Desktop();
615 desktop.setInBatchMode(true); // indicate we are starting up
619 JalviewTaskbar.setTaskbar(this);
620 } catch (Exception e)
622 Console.info("Cannot set Taskbar");
623 Console.error(e.getMessage());
624 // e.printStackTrace();
625 } catch (Throwable t)
627 Console.info("Cannot set Taskbar");
628 Console.error(t.getMessage());
629 // t.printStackTrace();
632 // set Proxy settings before all the internet calls
633 Cache.setProxyPropertiesFromPreferences();
635 desktop.setVisible(true);
637 if (!Platform.isJS())
646 * Check to see that the JVM version being run is suitable for the Java
647 * version this Jalview was compiled for. Popup a warning if not.
649 if (!LaunchUtils.checkJavaVersion())
651 Console.warn("The Java version being used (Java "
652 + LaunchUtils.getJavaVersion()
653 + ") may lead to problems. This installation of Jalview should be used with Java "
654 + LaunchUtils.getJavaCompileVersion() + ".");
657 .getBooleanUserPreference("IGNORE_JVM_WARNING_POPUP"))
660 MessageManager.getString("label.continue") };
661 JOptionPane.showOptionDialog(null,
662 MessageManager.formatMessage(
663 "warning.wrong_jvm_version_message",
664 LaunchUtils.getJavaVersion(),
665 LaunchUtils.getJavaCompileVersion()),
667 .getString("warning.wrong_jvm_version_title"),
668 JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
669 null, options, options[0]);
673 boolean webservicediscovery = bootstrapArgs
674 .getBoolean(Arg.WEBSERVICEDISCOVERY);
675 if (aparser.contains("nowebservicediscovery"))
676 webservicediscovery = false;
677 if (webservicediscovery)
679 desktop.startServiceDiscovery();
683 testoutput(argparser, Arg.WEBSERVICEDISCOVERY);
686 boolean usagestats = bootstrapArgs.getBoolean(Arg.USAGESTATS);
687 if (aparser.contains("nousagestats"))
691 startUsageStats(desktop);
692 testoutput(argparser, Arg.USAGESTATS);
696 System.out.println("CMD [-nousagestats] executed successfully!");
697 testoutput(argparser, Arg.USAGESTATS);
700 boolean questionnaire = bootstrapArgs.getBoolean(Arg.QUESTIONNAIRE);
701 if (aparser.contains("noquestionnaire"))
702 questionnaire = false;
705 String url = aparser.getValue("questionnaire");
708 // Start the desktop questionnaire prompter with the specified
710 Console.debug("Starting questionnaire url at " + url);
711 desktop.checkForQuestionnaire(url);
712 System.out.println("CMD questionnaire[-" + url
713 + "] executed successfully!");
717 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
719 // Start the desktop questionnaire prompter with the specified
722 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
724 String defurl = "https://www.jalview.org/cgi-bin/questionnaire.pl";
726 "Starting questionnaire with default url: " + defurl);
727 desktop.checkForQuestionnaire(defurl);
734 .println("CMD [-noquestionnaire] executed successfully!");
735 testoutput(argparser, Arg.QUESTIONNAIRE);
738 if ((!aparser.contains("nonews")
739 && Cache.getProperty("NONEWS") == null
740 && !"false".equals(bootstrapArgs.get(Arg.NEWS)))
741 || "true".equals(bootstrapArgs.get(Arg.NEWS)))
743 desktop.checkForNews();
746 if (!aparser.contains("nohtmltemplates")
747 && Cache.getProperty("NOHTMLTEMPLATES") == null)
749 BioJsHTMLOutput.updateBioJS();
753 // Run Commands from cli
754 cmds = new Commands(argparser, headlessArg);
755 boolean commandsSuccess = cmds.argsWereParsed();
760 Jalview.exit("Successfully completed commands in headless mode", 0);
762 Console.info("Successfully completed commands");
768 Jalview.exit("Error when running Commands in headless mode", 1);
770 Console.warn("Error when running commands");
773 // Check if JVM and compile version might cause problems and log if it
775 if (headless && !Platform.isJS() && !LaunchUtils.checkJavaVersion())
777 Console.warn("The Java version being used (Java "
778 + LaunchUtils.getJavaVersion()
779 + ") may lead to problems. This installation of Jalview should be used with Java "
780 + LaunchUtils.getJavaCompileVersion() + ".");
783 String file = null, data = null;
785 FileFormatI format = null;
787 DataSourceType protocol = null;
789 FileLoader fileLoader = new FileLoader(!headless);
791 String groovyscript = null; // script to execute after all loading is
792 // completed one way or another
793 // extract groovy argument and execute if necessary
794 groovyscript = aparser.getValue("groovy", true);
795 file = aparser.getValue("open", true);
797 if (file == null && desktop == null && !commandsSuccess)
799 Jalview.exit("No files to open!", 1);
803 // Finally, deal with the remaining input data.
808 desktop.setProgressBar(
810 .getString("status.processing_commandline_args"),
811 progress = System.currentTimeMillis());
813 System.out.println("CMD [-open " + file + "] executed successfully!");
815 if (!Platform.isJS())
817 * ignore in JavaScript -- can't just file existence - could load it?
822 if (!HttpUtils.startsWithHttpOrHttps(file))
824 if (!(new File(file)).exists())
829 "Can't find file '" + file + "' in headless mode", 1);
831 Console.warn("Can't find file'" + file + "'");
836 protocol = AppletFormatAdapter.checkProtocol(file);
840 format = new IdentifyFile().identify(file, protocol);
841 } catch (FileFormatException e1)
846 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
850 System.out.println("error");
854 setCurrentAlignFrame(af);
855 data = aparser.getValue("colour", true);
858 data.replaceAll("%20", " ");
860 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
861 af.getViewport(), af.getViewport().getAlignment(), data);
866 "CMD [-colour " + data + "] executed successfully!");
871 // Must maintain ability to use the groups flag
872 data = aparser.getValue("groups", true);
875 af.parseFeaturesFile(data,
876 AppletFormatAdapter.checkProtocol(data));
877 // System.out.println("Added " + data);
879 "CMD groups[-" + data + "] executed successfully!");
881 data = aparser.getValue("features", true);
884 af.parseFeaturesFile(data,
885 AppletFormatAdapter.checkProtocol(data));
886 // System.out.println("Added " + data);
888 "CMD [-features " + data + "] executed successfully!");
891 data = aparser.getValue("annotations", true);
894 af.loadJalviewDataFile(data, null, null, null);
895 // System.out.println("Added " + data);
897 "CMD [-annotations " + data + "] executed successfully!");
899 // set or clear the sortbytree flag.
900 if (aparser.contains("sortbytree"))
902 af.getViewport().setSortByTree(true);
903 if (af.getViewport().getSortByTree())
905 System.out.println("CMD [-sortbytree] executed successfully!");
908 if (aparser.contains("no-annotation"))
910 af.getViewport().setShowAnnotation(false);
911 if (!af.getViewport().isShowAnnotation())
913 System.out.println("CMD no-annotation executed successfully!");
916 if (aparser.contains("nosortbytree"))
918 af.getViewport().setSortByTree(false);
919 if (!af.getViewport().getSortByTree())
922 .println("CMD [-nosortbytree] executed successfully!");
925 data = aparser.getValue("tree", true);
931 "CMD [-tree " + data + "] executed successfully!");
932 NewickFile nf = new NewickFile(data,
933 AppletFormatAdapter.checkProtocol(data));
935 .setCurrentTree(af.showNewickTree(nf, data).getTree());
936 } catch (IOException ex)
938 System.err.println("Couldn't add tree " + data);
939 ex.printStackTrace(System.err);
942 // TODO - load PDB structure(s) to alignment JAL-629
943 // (associate with identical sequence in alignment, or a specified
945 if (groovyscript != null)
947 // Execute the groovy script after we've done all the rendering stuff
948 // and before any images or figures are generated.
949 System.out.println("Executing script " + groovyscript);
950 executeGroovyScript(groovyscript, af);
951 System.out.println("CMD groovy[" + groovyscript
952 + "] executed successfully!");
955 String imageName = "unnamed.png";
956 while (aparser.getSize() > 1)
958 String outputFormat = aparser.nextValue();
959 file = aparser.nextValue();
961 if (outputFormat.equalsIgnoreCase("png"))
963 af.createPNG(new File(file));
964 imageName = (new File(file)).getName();
965 System.out.println("Creating PNG image: " + file);
968 else if (outputFormat.equalsIgnoreCase("svg"))
970 File imageFile = new File(file);
971 imageName = imageFile.getName();
972 af.createSVG(imageFile);
973 System.out.println("Creating SVG image: " + file);
976 else if (outputFormat.equalsIgnoreCase("html"))
978 File imageFile = new File(file);
979 imageName = imageFile.getName();
980 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
981 htmlSVG.exportHTML(file);
983 System.out.println("Creating HTML image: " + file);
986 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
990 System.err.println("The output html file must not be null");
995 BioJsHTMLOutput.refreshVersionInfo(
996 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
997 } catch (URISyntaxException e)
1001 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
1002 bjs.exportHTML(file);
1004 .println("Creating BioJS MSA Viwer HTML file: " + file);
1007 else if (outputFormat.equalsIgnoreCase("imgMap"))
1009 af.createImageMap(new File(file), imageName);
1010 System.out.println("Creating image map: " + file);
1013 else if (outputFormat.equalsIgnoreCase("eps"))
1015 File outputFile = new File(file);
1017 "Creating EPS file: " + outputFile.getAbsolutePath());
1018 af.createEPS(outputFile);
1021 FileFormatI outFormat = null;
1024 outFormat = FileFormats.getInstance().forName(outputFormat);
1025 } catch (Exception formatP)
1027 System.out.println("Couldn't parse " + outFormat
1028 + " as a valid Jalview format string.");
1030 if (outFormat != null)
1032 if (!outFormat.isWritable())
1035 "This version of Jalview does not support alignment export as "
1040 af.saveAlignment(file, outFormat);
1041 if (af.isSaveAlignmentSuccessful())
1043 System.out.println("Written alignment in "
1044 + outFormat.getName() + " format to " + file);
1048 System.out.println("Error writing file " + file + " in "
1049 + outFormat.getName() + " format!!");
1056 while (aparser.getSize() > 0)
1058 System.out.println("Unknown arg: " + aparser.nextValue());
1063 AlignFrame startUpAlframe = null;
1064 // We'll only open the default file if the desktop is visible.
1066 // ////////////////////
1068 if (!Platform.isJS() && !headless && file == null
1069 && Cache.getDefault("SHOW_STARTUP_FILE", true)
1070 && !cmds.commandArgsProvided())
1071 // don't open the startup file if command line args have been processed
1072 // (&& !Commands.commandArgsProvided())
1079 file = Cache.getDefault("STARTUP_FILE",
1080 Cache.getDefault("www.jalview.org", "https://www.jalview.org")
1081 + "/examples/exampleFile_2_7.jvp");
1082 if (file.equals("http://www.jalview.org/examples/exampleFile_2_3.jar")
1084 "http://www.jalview.org/examples/exampleFile_2_7.jar"))
1086 file.replace("http:", "https:");
1087 // hardwire upgrade of the startup file
1088 file.replace("_2_3", "_2_7");
1089 file.replace("2_7.jar", "2_7.jvp");
1090 // and remove the stale setting
1091 Cache.removeProperty("STARTUP_FILE");
1094 protocol = AppletFormatAdapter.checkProtocol(file);
1096 if (file.endsWith(".jar"))
1098 format = FileFormat.Jalview;
1104 format = new IdentifyFile().identify(file, protocol);
1105 } catch (FileFormatException e)
1111 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
1113 // don't ask to save when quitting if only the startup file has been
1115 Console.debug("Resetting up-to-date flag for startup file");
1116 startUpAlframe.getViewport().setSavedUpToDate(true);
1117 // extract groovy arguments before anything else.
1120 // Once all other stuff is done, execute any groovy scripts (in order)
1121 if (groovyscript != null)
1123 if (Cache.groovyJarsPresent())
1125 System.out.println("Executing script " + groovyscript);
1126 executeGroovyScript(groovyscript, startUpAlframe);
1131 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
1135 // and finally, turn off batch mode indicator - if the desktop still exists
1136 if (desktop != null)
1140 desktop.setProgressBar(null, progress);
1142 desktop.setInBatchMode(false);
1146 private static void setLookAndFeel()
1148 // property laf = "crossplatform", "system", "gtk", "metal", "nimbus",
1150 // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
1151 // try Quaqua/Vaqua.
1152 String lafProp = System.getProperty("laf");
1153 String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
1154 String laf = "none";
1155 if (lafProp != null)
1159 else if (lafSetting != null)
1163 boolean lafSet = false;
1166 case "crossplatform":
1167 lafSet = setCrossPlatformLookAndFeel();
1170 Console.error("Could not set requested laf=" + laf);
1174 lafSet = setSystemLookAndFeel();
1177 Console.error("Could not set requested laf=" + laf);
1181 lafSet = setGtkLookAndFeel();
1184 Console.error("Could not set requested laf=" + laf);
1188 lafSet = setMetalLookAndFeel();
1191 Console.error("Could not set requested laf=" + laf);
1195 lafSet = setNimbusLookAndFeel();
1198 Console.error("Could not set requested laf=" + laf);
1202 lafSet = setFlatLookAndFeel();
1205 Console.error("Could not set requested laf=" + laf);
1209 lafSet = setMacLookAndFeel();
1212 Console.error("Could not set requested laf=" + laf);
1218 Console.error("Requested laf=" + laf + " not implemented");
1222 setSystemLookAndFeel();
1223 if (Platform.isLinux())
1225 setLinuxLookAndFeel();
1227 if (Platform.isMac())
1229 setMacLookAndFeel();
1234 private static boolean setCrossPlatformLookAndFeel()
1236 boolean set = false;
1239 UIManager.setLookAndFeel(
1240 UIManager.getCrossPlatformLookAndFeelClassName());
1242 } catch (Exception ex)
1244 Console.error("Unexpected Look and Feel Exception");
1245 Console.error(ex.getMessage());
1246 Console.debug(Cache.getStackTraceString(ex));
1251 private static boolean setSystemLookAndFeel()
1253 boolean set = false;
1256 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
1258 } catch (Exception ex)
1260 Console.error("Unexpected Look and Feel Exception");
1261 Console.error(ex.getMessage());
1262 Console.debug(Cache.getStackTraceString(ex));
1267 private static boolean setSpecificLookAndFeel(String name,
1268 String className, boolean nameStartsWith)
1270 boolean set = false;
1273 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
1275 if (info.getName() != null && nameStartsWith
1276 ? info.getName().toLowerCase(Locale.ROOT)
1277 .startsWith(name.toLowerCase(Locale.ROOT))
1278 : info.getName().toLowerCase(Locale.ROOT)
1279 .equals(name.toLowerCase(Locale.ROOT)))
1281 className = info.getClassName();
1285 UIManager.setLookAndFeel(className);
1287 } catch (Exception ex)
1289 Console.error("Unexpected Look and Feel Exception");
1290 Console.error(ex.getMessage());
1291 Console.debug(Cache.getStackTraceString(ex));
1296 private static boolean setGtkLookAndFeel()
1298 return setSpecificLookAndFeel("gtk",
1299 "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true);
1302 private static boolean setMetalLookAndFeel()
1304 return setSpecificLookAndFeel("metal",
1305 "javax.swing.plaf.metal.MetalLookAndFeel", false);
1308 private static boolean setNimbusLookAndFeel()
1310 return setSpecificLookAndFeel("nimbus",
1311 "javax.swing.plaf.nimbus.NimbusLookAndFeel", false);
1314 private static boolean setFlatLookAndFeel()
1316 boolean set = false;
1317 if (SystemInfo.isMacOS)
1321 UIManager.setLookAndFeel(
1322 "com.formdev.flatlaf.themes.FlatMacLightLaf");
1324 Console.debug("Using FlatMacLightLaf");
1325 } catch (ClassNotFoundException | InstantiationException
1326 | IllegalAccessException | UnsupportedLookAndFeelException e)
1328 Console.debug("Exception loading FlatLightLaf", e);
1330 System.setProperty("apple.laf.useScreenMenuBar", "true");
1331 System.setProperty("apple.awt.application.name",
1332 ChannelProperties.getProperty("app_name"));
1333 System.setProperty("apple.awt.application.appearance", "system");
1334 if (SystemInfo.isMacFullWindowContentSupported
1335 && Desktop.desktop != null)
1337 Console.debug("Setting transparent title bar");
1338 Desktop.desktop.getRootPane()
1339 .putClientProperty("apple.awt.fullWindowContent", true);
1340 Desktop.desktop.getRootPane()
1341 .putClientProperty("apple.awt.transparentTitleBar", true);
1342 Desktop.desktop.getRootPane()
1343 .putClientProperty("apple.awt.fullscreenable", true);
1345 SwingUtilities.invokeLater(() -> {
1346 FlatMacLightLaf.setup();
1348 Console.debug("Using FlatMacLightLaf");
1355 UIManager.setLookAndFeel("com.formdev.flatlaf.FlatLightLaf");
1357 Console.debug("Using FlatLightLaf");
1358 } catch (ClassNotFoundException | InstantiationException
1359 | IllegalAccessException | UnsupportedLookAndFeelException e)
1361 Console.debug("Exception loading FlatLightLaf", e);
1363 // Windows specific properties here
1364 SwingUtilities.invokeLater(() -> {
1365 FlatLightLaf.setup();
1367 Console.debug("Using FlatLightLaf");
1370 else if (SystemInfo.isLinux)
1374 UIManager.setLookAndFeel("com.formdev.flatlaf.FlatLightLaf");
1376 Console.debug("Using FlatLightLaf");
1377 } catch (ClassNotFoundException | InstantiationException
1378 | IllegalAccessException | UnsupportedLookAndFeelException e)
1380 Console.debug("Exception loading FlatLightLaf", e);
1382 // enable custom window decorations
1383 JFrame.setDefaultLookAndFeelDecorated(true);
1384 JDialog.setDefaultLookAndFeelDecorated(true);
1385 SwingUtilities.invokeLater(() -> {
1386 FlatLightLaf.setup();
1388 Console.debug("Using FlatLightLaf");
1396 UIManager.setLookAndFeel("com.formdev.flatlaf.FlatLightLaf");
1398 Console.debug("Using FlatLightLaf");
1399 } catch (ClassNotFoundException | InstantiationException
1400 | IllegalAccessException | UnsupportedLookAndFeelException e)
1402 Console.debug("Exception loading FlatLightLaf", e);
1408 UIManager.put("TabbedPane.tabType", "card");
1409 UIManager.put("TabbedPane.showTabSeparators", true);
1410 UIManager.put("TabbedPane.showContentSeparator", true);
1411 UIManager.put("TabbedPane.tabSeparatorsFullHeight", true);
1412 UIManager.put("TabbedPane.tabsOverlapBorder", true);
1413 UIManager.put("TabbedPane.hasFullBorder", true);
1414 UIManager.put("TabbedPane.tabLayoutPolicy", "scroll");
1415 UIManager.put("TabbedPane.scrollButtonsPolicy", "asNeeded");
1416 UIManager.put("TabbedPane.smoothScrolling", true);
1417 UIManager.put("TabbedPane.tabWidthMode", "compact");
1418 UIManager.put("TabbedPane.selectedBackground", Color.white);
1421 Desktop.setLiveDragMode(Cache.getDefault("FLAT_LIVE_DRAG_MODE", true));
1425 private static boolean setMacLookAndFeel()
1427 boolean set = false;
1428 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
1429 ChannelProperties.getProperty("app_name"));
1430 System.setProperty("apple.laf.useScreenMenuBar", "true");
1432 * broken native LAFs on (ARM?) macbooks
1433 set = setQuaquaLookAndFeel();
1434 if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
1435 .toLowerCase(Locale.ROOT).contains("quaqua"))
1437 set = setVaquaLookAndFeel();
1440 set = setFlatLookAndFeel();
1444 private static boolean setLinuxLookAndFeel()
1446 boolean set = false;
1447 set = setFlatLookAndFeel();
1449 set = setMetalLookAndFeel();
1450 // avoid GtkLookAndFeel -- not good results especially on HiDPI
1452 set = setNimbusLookAndFeel();
1456 private static void showUsage()
1459 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1460 + "-nodisplay\tRun Jalview without User Interface.\n"
1461 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1462 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1463 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1464 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1465 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1466 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1467 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1468 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1469 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1470 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1471 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1472 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1473 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1474 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1475 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1476 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1477 + "-html FILE\tCreate HTML file from alignment.\n"
1478 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1479 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1480 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1481 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1482 + "-noquestionnaire\tTurn off questionnaire check.\n"
1483 + "-nonews\tTurn off check for Jalview news.\n"
1484 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1485 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1487 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1488 // after all other properties files have been read\n\t
1489 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1490 // passed in correctly)"
1491 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1492 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1493 + "-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"
1494 + "-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"
1495 + "-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"
1496 + "\n~Read documentation in Application or visit https://www.jalview.org for description of Features and Annotations file~\n\n");
1499 private static void startUsageStats(final Desktop desktop)
1502 * start a User Config prompt asking if we can log usage statistics.
1504 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
1505 "USAGESTATS", "Jalview Usage Statistics",
1506 "Do you want to help make Jalview better by enabling "
1507 + "the collection of usage statistics with Google Analytics ?"
1508 + "\n\n(you can enable or disable usage tracking in the preferences)",
1515 "Initialising googletracker for usage stats.");
1516 Cache.initGoogleTracker();
1517 Console.debug("Tracking enabled.");
1524 Console.debug("Not enabling Google Tracking.");
1527 desktop.addDialogThread(prompter);
1531 * Locate the given string as a file and pass it to the groovy interpreter.
1533 * @param groovyscript
1534 * the script to execute
1535 * @param jalviewContext
1536 * the Jalview Desktop object passed in to the groovy binding as the
1539 protected void executeGroovyScript(String groovyscript, AlignFrame af)
1542 * for scripts contained in files
1549 if (groovyscript.trim().equals("STDIN"))
1551 // read from stdin into a tempfile and execute it
1554 tfile = File.createTempFile("jalview", "groovy");
1555 PrintWriter outfile = new PrintWriter(
1556 new OutputStreamWriter(new FileOutputStream(tfile)));
1557 BufferedReader br = new BufferedReader(
1558 new InputStreamReader(System.in));
1560 while ((line = br.readLine()) != null)
1562 outfile.write(line + "\n");
1568 } catch (Exception ex)
1570 System.err.println("Failed to read from STDIN into tempfile "
1571 + ((tfile == null) ? "(tempfile wasn't created)"
1572 : tfile.toString()));
1573 ex.printStackTrace();
1578 sfile = tfile.toURI().toURL();
1579 } catch (Exception x)
1582 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1584 x.printStackTrace();
1592 sfile = new URI(groovyscript).toURL();
1593 } catch (Exception x)
1595 tfile = new File(groovyscript);
1596 if (!tfile.exists())
1598 System.err.println("File '" + groovyscript + "' does not exist.");
1601 if (!tfile.canRead())
1603 System.err.println("File '" + groovyscript + "' cannot be read.");
1606 if (tfile.length() < 1)
1608 System.err.println("File '" + groovyscript + "' is empty.");
1613 sfile = tfile.getAbsoluteFile().toURI().toURL();
1614 } catch (Exception ex)
1616 System.err.println("Failed to create a file URL for "
1617 + tfile.getAbsoluteFile());
1624 Map<String, java.lang.Object> vbinding = new HashMap<>();
1625 vbinding.put("Jalview", this);
1628 vbinding.put("currentAlFrame", af);
1630 Binding gbinding = new Binding(vbinding);
1631 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1632 gse.run(sfile.toString(), gbinding);
1633 if ("STDIN".equals(groovyscript))
1635 // delete temp file that we made -
1636 // only if it was successfully executed
1639 } catch (Exception e)
1641 System.err.println("Exception Whilst trying to execute file " + sfile
1642 + " as a groovy script.");
1643 e.printStackTrace(System.err);
1648 public static boolean isHeadlessMode()
1650 String isheadless = System.getProperty("java.awt.headless");
1651 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1658 public AlignFrame[] getAlignFrames()
1660 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1661 : Desktop.getAlignFrames();
1666 * jalview.bin.Jalview.quit() will just run the non-GUI shutdownHook and exit
1670 // System.exit will run the shutdownHook first
1671 Jalview.exit("Quitting now. Bye!", 0);
1674 public static AlignFrame getCurrentAlignFrame()
1676 return Jalview.currentAlignFrame;
1679 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1681 Jalview.currentAlignFrame = currentAlignFrame;
1684 protected Commands getCommands()
1689 public static void exit(String message, int exitcode)
1691 Console.debug("Using Jalview.exit");
1692 if (message != null)
1694 Console.info(message);
1696 Console.error(message);
1698 System.exit(exitcode);
1702 * testoutput for string values
1704 protected static void testoutput(ArgParser ap, Arg a, String s1,
1707 BootstrapArgs bsa = ap.getBootstrapArgs();
1708 if (!bsa.getBoolean(Arg.TESTOUTPUT))
1710 if (!((s1 == null && s2 == null) || (s1 != null && s1.equals(s2))))
1712 Console.debug("testoutput with unmatching values '" + s1 + "' and '"
1713 + s2 + "' for arg " + a.argString());
1716 boolean isset = a.hasOption(Opt.BOOTSTRAP) ? bsa.contains(a)
1720 Console.warn("Arg '" + a.getName() + "' not set at all");
1723 testoutput(true, a, s1, s2);
1726 protected static void testoutput(BootstrapArgs bsa, Arg a, String s1,
1729 if (!bsa.getBoolean(Arg.TESTOUTPUT))
1731 if (!((s1 == null && s2 == null) || (s1 != null && s1.equals(s2))))
1733 Console.debug("testoutput with unmatching values '" + s1 + "' and '"
1734 + s2 + "' for arg " + a.argString());
1737 if (!a.hasOption(Opt.BOOTSTRAP))
1739 Console.error("Non-bootstrap Arg '" + a.getName()
1740 + "' given to testoutput(BootstrapArgs bsa, Arg a, String s1, String s2) with only BootstrapArgs");
1742 if (!bsa.contains(a))
1744 Console.warn("Arg '" + a.getName() + "' not set at all");
1747 testoutput(true, a, s1, s2);
1750 private static void testoutput(boolean yes, Arg a, String s1, String s2)
1752 if (yes && ((s1 == null && s2 == null)
1753 || (s1 != null && s1.equals(s2))))
1755 System.out.println("[TESTOUTPUT] arg " + a.argString() + "='" + s1
1761 * testoutput for boolean values
1763 protected static void testoutput(ArgParser ap, Arg a)
1767 BootstrapArgs bsa = ap.getBootstrapArgs();
1770 if (!bsa.getBoolean(Arg.TESTOUTPUT))
1772 boolean val = a.hasOption(Opt.BOOTSTRAP) ? bsa.getBoolean(a)
1774 boolean isset = a.hasOption(Opt.BOOTSTRAP) ? bsa.contains(a)
1778 Console.warn("Arg '" + a.getName() + "' not set at all");
1784 protected static void testoutput(BootstrapArgs bsa, Arg a)
1786 if (!bsa.getBoolean(Arg.TESTOUTPUT))
1788 if (!a.hasOption(Opt.BOOTSTRAP))
1790 Console.warn("Non-bootstrap Arg '" + a.getName()
1791 + "' given to testoutput(BootstrapArgs bsa, Arg a) with only BootstrapArgs");
1794 if (!bsa.contains(a))
1796 Console.warn("Arg '" + a.getName() + "' not set at all");
1799 testoutput(bsa.getBoolean(a), a);
1802 private static void testoutput(boolean yes, Arg a)
1804 System.out.println("[TESTOUTPUT] arg "
1805 + (yes ? a.argString() : a.negateArgString()) + " was set");