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.HashMap;
43 import java.util.Locale;
45 import java.util.Properties;
46 import java.util.Vector;
47 import java.util.logging.ConsoleHandler;
48 import java.util.logging.Level;
49 import java.util.logging.Logger;
51 import javax.swing.JDialog;
52 import javax.swing.JFrame;
53 import javax.swing.JOptionPane;
54 import javax.swing.SwingUtilities;
55 import javax.swing.UIManager;
56 import javax.swing.UIManager.LookAndFeelInfo;
57 import javax.swing.UnsupportedLookAndFeelException;
59 import com.formdev.flatlaf.FlatLightLaf;
60 import com.formdev.flatlaf.themes.FlatMacLightLaf;
61 import com.formdev.flatlaf.util.SystemInfo;
62 import com.threerings.getdown.util.LaunchUtil;
64 //import edu.stanford.ejalbert.launching.IBrowserLaunching;
65 import groovy.lang.Binding;
66 import groovy.util.GroovyScriptEngine;
67 import jalview.bin.ArgParser.Arg;
68 import jalview.bin.ArgParser.BootstrapArgs;
69 import jalview.ext.so.SequenceOntology;
70 import jalview.gui.AlignFrame;
71 import jalview.gui.Desktop;
72 import jalview.gui.PromptUserConfig;
73 import jalview.gui.QuitHandler;
74 import jalview.gui.QuitHandler.QResponse;
75 import jalview.io.AppletFormatAdapter;
76 import jalview.io.BioJsHTMLOutput;
77 import jalview.io.DataSourceType;
78 import jalview.io.FileFormat;
79 import jalview.io.FileFormatException;
80 import jalview.io.FileFormatI;
81 import jalview.io.FileFormats;
82 import jalview.io.FileLoader;
83 import jalview.io.HtmlSvgOutput;
84 import jalview.io.IdentifyFile;
85 import jalview.io.NewickFile;
86 import jalview.io.gff.SequenceOntologyFactory;
87 import jalview.schemes.ColourSchemeI;
88 import jalview.schemes.ColourSchemeProperty;
89 import jalview.util.ChannelProperties;
90 import jalview.util.HttpUtils;
91 import jalview.util.LaunchUtils;
92 import jalview.util.MessageManager;
93 import jalview.util.Platform;
94 import jalview.ws.jws2.Jws2Discoverer;
97 * Main class for Jalview Application <br>
99 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
100 * jalview.bin.Jalview
102 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
103 * jalview.bin.Jalview jalview.bin.Jalview
105 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
106 * embellish '*' to e.g. '*.jar')
109 * @version $Revision$
115 Platform.getURLCommandArguments();
116 Platform.addJ2SDirectDatabaseCall("https://www.jalview.org");
117 Platform.addJ2SDirectDatabaseCall("http://www.jalview.org");
118 Platform.addJ2SDirectDatabaseCall("http://www.compbio.dundee.ac.uk");
119 Platform.addJ2SDirectDatabaseCall("https://www.compbio.dundee.ac.uk");
123 * singleton instance of this class
125 private static Jalview instance;
127 private Desktop desktop;
129 protected Commands cmds;
131 public static AlignFrame currentAlignFrame;
135 if (!Platform.isJS())
142 // grab all the rights we can for the JVM
143 Policy.setPolicy(new Policy()
146 public PermissionCollection getPermissions(CodeSource codesource)
148 Permissions perms = new Permissions();
149 perms.add(new AllPermission());
154 public void refresh()
162 * keep track of feature fetching tasks.
170 * TODO: generalise to track all jalview events to orchestrate batch processing
174 private int queued = 0;
176 private int running = 0;
178 public FeatureFetcher()
183 public void addFetcher(final AlignFrame af,
184 final Vector<String> dasSources)
186 final long id = System.currentTimeMillis();
188 final FeatureFetcher us = this;
189 new Thread(new Runnable()
201 af.setProgressBar(MessageManager
202 .getString("status.das_features_being_retrived"), id);
203 af.featureSettings_actionPerformed(null);
204 af.setProgressBar(null, id);
213 public synchronized boolean allFinished()
215 return queued == 0 && running == 0;
220 public static Jalview getInstance()
226 * main class for Jalview application
229 * open <em>filename</em>
231 public static void main(String[] args)
233 // setLogging(); // BH - for event debugging in JavaScript
234 instance = new Jalview();
235 instance.doMain(args);
238 private static void logClass(String name)
240 // BH - for event debugging in JavaScript
241 ConsoleHandler consoleHandler = new ConsoleHandler();
242 consoleHandler.setLevel(Level.ALL);
243 Logger logger = Logger.getLogger(name);
244 logger.setLevel(Level.ALL);
245 logger.addHandler(consoleHandler);
248 @SuppressWarnings("unused")
249 private static void setLogging()
257 System.out.println("not in js");
260 // BH - for event debugging in JavaScript (Java mode only)
261 if (!Platform.isJS())
268 Logger.getLogger("").setLevel(Level.ALL);
269 logClass("java.awt.EventDispatchThread");
270 logClass("java.awt.EventQueue");
271 logClass("java.awt.Component");
272 logClass("java.awt.focus.Component");
273 logClass("java.awt.focus.DefaultKeyboardFocusManager");
281 void doMain(String[] args)
284 if (!Platform.isJS())
286 System.setSecurityManager(null);
289 // get args needed before proper ArgParser
290 BootstrapArgs bootstrapArgs = BootstrapArgs.getBootstrapArgs(args);
292 if (!Platform.isJS())
294 // are we being --quiet ?
295 if (bootstrapArgs.contains(Arg.QUIET))
297 OutputStream devNull = new OutputStream()
300 public void write(int b)
305 System.setOut(new PrintStream(devNull));
306 // redirecting stderr not working
307 if (bootstrapArgs.getList(Arg.QUIET).size() > 1)
309 System.setErr(new PrintStream(devNull));
315 .println("Java version: " + System.getProperty("java.version"));
316 System.out.println("Java Home: " + System.getProperty("java.home"));
317 System.out.println(System.getProperty("os.arch") + " "
318 + System.getProperty("os.name") + " "
319 + System.getProperty("os.version"));
321 String val = System.getProperty("sys.install4jVersion");
324 System.out.println("Install4j version: " + val);
326 val = System.getProperty("installer_template_version");
329 System.out.println("Install4j template version: " + val);
331 val = System.getProperty("launcher_version");
334 System.out.println("Launcher version: " + val);
337 if (Platform.isLinux() && LaunchUtils.getJavaVersion() < 11)
339 System.setProperty("flatlaf.uiScale", "1");
342 // get bootstrap properties (mainly for the logger level)
343 Properties bootstrapProperties = Cache
344 .bootstrapProperties(bootstrapArgs.get(Arg.PROPS));
346 // report Jalview version
347 Cache.loadBuildProperties(true);
350 ArgsParser aparser = new ArgsParser(args);
353 boolean headless = false;
355 boolean headlessArg = false;
359 String logLevel = bootstrapArgs.contains(Arg.DEBUG) ? "DEBUG" : null;
360 if (logLevel == null && !(bootstrapProperties == null))
362 logLevel = bootstrapProperties.getProperty(Cache.JALVIEWLOGLEVEL);
364 Console.initLogger(logLevel);
365 } catch (NoClassDefFoundError error)
367 error.printStackTrace();
368 System.out.println("\nEssential logging libraries not found."
369 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
373 // register SIGTERM listener
374 Runtime.getRuntime().addShutdownHook(new Thread()
378 Console.debug("Running shutdown hook");
379 if (QuitHandler.gotQuitResponse() == QResponse.CANCEL_QUIT)
381 // Got to here by a SIGTERM signal.
382 // Note we will not actually cancel the quit from here -- it's too
383 // late -- but we can wait for saving files.
384 Console.debug("Checking for saving files");
385 QuitHandler.getQuitResponse(false);
389 Console.debug("Nothing more to do");
391 Console.debug("Exiting, bye!");
392 // shutdownHook cannot be cancelled, JVM will now halt
396 String usrPropsFile = bootstrapArgs.contains(Arg.PROPS)
397 ? bootstrapArgs.get(Arg.PROPS)
398 : aparser.getValue("props");
399 Cache.loadProperties(usrPropsFile);
400 if (usrPropsFile != null)
403 "CMD [-props " + usrPropsFile + "] executed successfully!");
408 // --argfile=... -- OVERRIDES ALL NON-BOOTSTRAP ARGS
409 if (bootstrapArgs.contains(Arg.ARGFILE))
411 argparser = ArgParser
412 .parseArgFiles(bootstrapArgs.getList(Arg.ARGFILE));
416 argparser = new ArgParser(args);
419 if (!Platform.isJS())
426 if (aparser.contains("help") || aparser.contains("h")
427 || argparser.getBool(Arg.HELP))
433 if (bootstrapArgs.contains(Arg.HEADLESS))
435 System.setProperty("java.awt.headless", "true");
437 headlessArg = argparser.getBool(Arg.HEADLESS);
439 if (aparser.contains("nodisplay") || aparser.contains("nogui")
440 || aparser.contains("headless"))
442 System.setProperty("java.awt.headless", "true");
448 // allow https handshakes to download intermediate certs if necessary
449 System.setProperty("com.sun.security.enableAIAcaIssuers", "true");
451 final String jabawsUrl = aparser.getValue("jabaws");
452 if (jabawsUrl != null)
456 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
458 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
459 } catch (MalformedURLException e)
462 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
467 String defs = aparser.getValue("setprop");
470 int p = defs.indexOf('=');
473 System.err.println("Ignoring invalid setprop argument : " + defs);
477 System.out.println("Executing setprop argument: " + defs);
480 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
482 // DISABLED FOR SECURITY REASONS
483 // TODO: add a property to allow properties to be overriden by cli args
484 // Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
486 defs = aparser.getValue("setprop");
488 if (System.getProperty("java.awt.headless") != null
489 && System.getProperty("java.awt.headless").equals("true"))
493 System.setProperty("http.agent",
494 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
498 Console.initLogger();
501 NoClassDefFoundError error)
503 error.printStackTrace();
504 System.out.println("\nEssential logging libraries not found."
505 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
510 if (!(headless || headlessArg))
514 * configure 'full' SO model if preferences say to, else use the default (full SO)
515 * - as JS currently doesn't have OBO parsing, it must use 'Lite' version
517 boolean soDefault = !Platform.isJS();
518 if (Cache.getDefault("USE_FULL_SO", soDefault))
520 SequenceOntologyFactory.setInstance(new SequenceOntology());
523 if (!(headless || headlessArg))
525 Desktop.nosplash = aparser.contains("nosplash");
526 desktop = new Desktop();
527 desktop.setInBatchMode(true); // indicate we are starting up
531 JalviewTaskbar.setTaskbar(this);
532 } catch (Exception e)
534 Console.info("Cannot set Taskbar");
535 Console.error(e.getMessage());
536 // e.printStackTrace();
537 } catch (Throwable t)
539 Console.info("Cannot set Taskbar");
540 Console.error(t.getMessage());
541 // t.printStackTrace();
544 // set Proxy settings before all the internet calls
545 Cache.setProxyPropertiesFromPreferences();
547 desktop.setVisible(true);
549 if (!Platform.isJS())
558 * Check to see that the JVM version being run is suitable for the Java
559 * version this Jalview was compiled for. Popup a warning if not.
561 if (!LaunchUtils.checkJavaVersion())
563 Console.warn("The Java version being used (Java "
564 + LaunchUtils.getJavaVersion()
565 + ") may lead to problems. This installation of Jalview should be used with Java "
566 + LaunchUtils.getJavaCompileVersion() + ".");
569 .getBooleanUserPreference("IGNORE_JVM_WARNING_POPUP"))
572 MessageManager.getString("label.continue") };
573 JOptionPane.showOptionDialog(null,
574 MessageManager.formatMessage(
575 "warning.wrong_jvm_version_message",
576 LaunchUtils.getJavaVersion(),
577 LaunchUtils.getJavaCompileVersion()),
579 .getString("warning.wrong_jvm_version_title"),
580 JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
581 null, options, options[0]);
585 if (!aparser.contains("nowebservicediscovery"))
587 desktop.startServiceDiscovery();
589 if (!aparser.contains("nousagestats"))
591 startUsageStats(desktop);
595 System.err.println("CMD [-nousagestats] executed successfully!");
598 if (!aparser.contains("noquestionnaire"))
600 String url = aparser.getValue("questionnaire");
603 // Start the desktop questionnaire prompter with the specified
605 Console.debug("Starting questionnaire url at " + url);
606 desktop.checkForQuestionnaire(url);
607 System.out.println("CMD questionnaire[-" + url
608 + "] executed successfully!");
612 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
614 // Start the desktop questionnaire prompter with the specified
617 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
619 String defurl = "https://www.jalview.org/cgi-bin/questionnaire.pl";
621 "Starting questionnaire with default url: " + defurl);
622 desktop.checkForQuestionnaire(defurl);
629 .println("CMD [-noquestionnaire] executed successfully!");
632 if (!aparser.contains("nonews")
633 || Cache.getProperty("NONEWS") == null)
635 desktop.checkForNews();
638 if (!aparser.contains("nohtmltemplates")
639 || Cache.getProperty("NOHTMLTEMPLATES") == null)
641 BioJsHTMLOutput.updateBioJS();
645 // Run Commands from cli
646 cmds = new Commands(argparser, headlessArg);
647 boolean commandsSuccess = cmds.argsWereParsed();
650 Console.info("Successfully completed commands");
653 System.out.println("#### EXITING");
659 Console.warn("Error when running commands");
664 // Check if JVM and compile version might cause problems and log if it
666 if (headless && !Platform.isJS() && !LaunchUtils.checkJavaVersion())
668 Console.warn("The Java version being used (Java "
669 + LaunchUtils.getJavaVersion()
670 + ") may lead to problems. This installation of Jalview should be used with Java "
671 + LaunchUtils.getJavaCompileVersion() + ".");
674 // Move any new getdown-launcher-new.jar into place over old
675 // getdown-launcher.jar
676 String appdirString = System.getProperty("getdownappdir");
677 if (appdirString != null && appdirString.length() > 0)
679 final File appdir = new File(appdirString);
685 LaunchUtil.upgradeGetdown(
686 new File(appdir, "getdown-launcher-old.jar"),
687 new File(appdir, "getdown-launcher.jar"),
688 new File(appdir, "getdown-launcher-new.jar"));
693 String file = null, data = null;
695 FileFormatI format = null;
697 DataSourceType protocol = null;
699 FileLoader fileLoader = new FileLoader(!headless);
701 String groovyscript = null; // script to execute after all loading is
702 // completed one way or another
703 // extract groovy argument and execute if necessary
704 groovyscript = aparser.getValue("groovy", true);
705 file = aparser.getValue("open", true);
707 if (file == null && desktop == null)
709 System.out.println("No files to open!");
714 // Finally, deal with the remaining input data.
719 desktop.setProgressBar(
721 .getString("status.processing_commandline_args"),
722 progress = System.currentTimeMillis());
724 System.out.println("CMD [-open " + file + "] executed successfully!");
726 if (!Platform.isJS())
728 * ignore in JavaScript -- can't just file existence - could load it?
733 if (!HttpUtils.startsWithHttpOrHttps(file))
735 if (!(new File(file)).exists())
737 System.out.println("Can't find " + file);
746 protocol = AppletFormatAdapter.checkProtocol(file);
750 format = new IdentifyFile().identify(file, protocol);
751 } catch (FileFormatException e1)
756 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
760 System.out.println("error");
764 setCurrentAlignFrame(af);
765 data = aparser.getValue("colour", true);
768 data.replaceAll("%20", " ");
770 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
771 af.getViewport(), af.getViewport().getAlignment(), data);
776 "CMD [-colour " + data + "] executed successfully!");
781 // Must maintain ability to use the groups flag
782 data = aparser.getValue("groups", true);
785 af.parseFeaturesFile(data,
786 AppletFormatAdapter.checkProtocol(data));
787 // System.out.println("Added " + data);
789 "CMD groups[-" + data + "] executed successfully!");
791 data = aparser.getValue("features", true);
794 af.parseFeaturesFile(data,
795 AppletFormatAdapter.checkProtocol(data));
796 // System.out.println("Added " + data);
798 "CMD [-features " + data + "] executed successfully!");
801 data = aparser.getValue("annotations", true);
804 af.loadJalviewDataFile(data, null, null, null);
805 // System.out.println("Added " + data);
807 "CMD [-annotations " + data + "] executed successfully!");
809 // set or clear the sortbytree flag.
810 if (aparser.contains("sortbytree"))
812 af.getViewport().setSortByTree(true);
813 if (af.getViewport().getSortByTree())
815 System.out.println("CMD [-sortbytree] executed successfully!");
818 if (aparser.contains("no-annotation"))
820 af.getViewport().setShowAnnotation(false);
821 if (!af.getViewport().isShowAnnotation())
823 System.out.println("CMD no-annotation executed successfully!");
826 if (aparser.contains("nosortbytree"))
828 af.getViewport().setSortByTree(false);
829 if (!af.getViewport().getSortByTree())
832 .println("CMD [-nosortbytree] executed successfully!");
835 data = aparser.getValue("tree", true);
841 "CMD [-tree " + data + "] executed successfully!");
842 NewickFile nf = new NewickFile(data,
843 AppletFormatAdapter.checkProtocol(data));
845 .setCurrentTree(af.showNewickTree(nf, data).getTree());
846 } catch (IOException ex)
848 System.err.println("Couldn't add tree " + data);
849 ex.printStackTrace(System.err);
852 // TODO - load PDB structure(s) to alignment JAL-629
853 // (associate with identical sequence in alignment, or a specified
855 if (groovyscript != null)
857 // Execute the groovy script after we've done all the rendering stuff
858 // and before any images or figures are generated.
859 System.out.println("Executing script " + groovyscript);
860 executeGroovyScript(groovyscript, af);
861 System.out.println("CMD groovy[" + groovyscript
862 + "] executed successfully!");
865 String imageName = "unnamed.png";
866 while (aparser.getSize() > 1)
868 String outputFormat = aparser.nextValue();
869 file = aparser.nextValue();
871 if (outputFormat.equalsIgnoreCase("png"))
873 af.createPNG(new File(file));
874 imageName = (new File(file)).getName();
875 System.out.println("Creating PNG image: " + file);
878 else if (outputFormat.equalsIgnoreCase("svg"))
880 File imageFile = new File(file);
881 imageName = imageFile.getName();
882 af.createSVG(imageFile);
883 System.out.println("Creating SVG image: " + file);
886 else if (outputFormat.equalsIgnoreCase("html"))
888 File imageFile = new File(file);
889 imageName = imageFile.getName();
890 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
891 htmlSVG.exportHTML(file);
893 System.out.println("Creating HTML image: " + file);
896 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
900 System.err.println("The output html file must not be null");
905 BioJsHTMLOutput.refreshVersionInfo(
906 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
907 } catch (URISyntaxException e)
911 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
912 bjs.exportHTML(file);
914 .println("Creating BioJS MSA Viwer HTML file: " + file);
917 else if (outputFormat.equalsIgnoreCase("imgMap"))
919 af.createImageMap(new File(file), imageName);
920 System.out.println("Creating image map: " + file);
923 else if (outputFormat.equalsIgnoreCase("eps"))
925 File outputFile = new File(file);
927 "Creating EPS file: " + outputFile.getAbsolutePath());
928 af.createEPS(outputFile);
931 FileFormatI outFormat = null;
934 outFormat = FileFormats.getInstance().forName(outputFormat);
935 } catch (Exception formatP)
937 System.out.println("Couldn't parse " + outFormat
938 + " as a valid Jalview format string.");
940 if (outFormat != null)
942 if (!outFormat.isWritable())
945 "This version of Jalview does not support alignment export as "
950 af.saveAlignment(file, outFormat);
951 if (af.isSaveAlignmentSuccessful())
953 System.out.println("Written alignment in "
954 + outFormat.getName() + " format to " + file);
958 System.out.println("Error writing file " + file + " in "
959 + outFormat.getName() + " format!!");
966 while (aparser.getSize() > 0)
968 System.out.println("Unknown arg: " + aparser.nextValue());
973 AlignFrame startUpAlframe = null;
974 // We'll only open the default file if the desktop is visible.
976 // ////////////////////
978 if (!Platform.isJS() && !headless && file == null
979 && Cache.getDefault("SHOW_STARTUP_FILE", true)
980 && !cmds.commandArgsProvided())
981 // don't open the startup file if command line args have been processed
982 // (&& !Commands.commandArgsProvided())
989 file = Cache.getDefault("STARTUP_FILE",
990 Cache.getDefault("www.jalview.org", "https://www.jalview.org")
991 + "/examples/exampleFile_2_7.jvp");
992 if (file.equals("http://www.jalview.org/examples/exampleFile_2_3.jar")
994 "http://www.jalview.org/examples/exampleFile_2_7.jar"))
996 file.replace("http:", "https:");
997 // hardwire upgrade of the startup file
998 file.replace("_2_3", "_2_7");
999 file.replace("2_7.jar", "2_7.jvp");
1000 // and remove the stale setting
1001 Cache.removeProperty("STARTUP_FILE");
1004 protocol = AppletFormatAdapter.checkProtocol(file);
1006 if (file.endsWith(".jar"))
1008 format = FileFormat.Jalview;
1014 format = new IdentifyFile().identify(file, protocol);
1015 } catch (FileFormatException e)
1021 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
1023 // don't ask to save when quitting if only the startup file has been
1025 Console.debug("Resetting up-to-date flag for startup file");
1026 startUpAlframe.getViewport().setSavedUpToDate(true);
1027 // extract groovy arguments before anything else.
1030 // Once all other stuff is done, execute any groovy scripts (in order)
1031 if (groovyscript != null)
1033 if (Cache.groovyJarsPresent())
1035 System.out.println("Executing script " + groovyscript);
1036 executeGroovyScript(groovyscript, startUpAlframe);
1041 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
1045 // and finally, turn off batch mode indicator - if the desktop still exists
1046 if (desktop != null)
1050 desktop.setProgressBar(null, progress);
1052 desktop.setInBatchMode(false);
1056 private static void setLookAndFeel()
1058 // property laf = "crossplatform", "system", "gtk", "metal", "nimbus",
1060 // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
1061 // try Quaqua/Vaqua.
1062 String lafProp = System.getProperty("laf");
1063 String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
1064 String laf = "none";
1065 if (lafProp != null)
1069 else if (lafSetting != null)
1073 boolean lafSet = false;
1076 case "crossplatform":
1077 lafSet = setCrossPlatformLookAndFeel();
1080 Console.error("Could not set requested laf=" + laf);
1084 lafSet = setSystemLookAndFeel();
1087 Console.error("Could not set requested laf=" + laf);
1091 lafSet = setGtkLookAndFeel();
1094 Console.error("Could not set requested laf=" + laf);
1098 lafSet = setMetalLookAndFeel();
1101 Console.error("Could not set requested laf=" + laf);
1105 lafSet = setNimbusLookAndFeel();
1108 Console.error("Could not set requested laf=" + laf);
1112 lafSet = setFlatLookAndFeel();
1115 Console.error("Could not set requested laf=" + laf);
1119 lafSet = setMacLookAndFeel();
1122 Console.error("Could not set requested laf=" + laf);
1128 Console.error("Requested laf=" + laf + " not implemented");
1132 setSystemLookAndFeel();
1133 if (Platform.isLinux())
1135 setLinuxLookAndFeel();
1137 if (Platform.isMac())
1139 setMacLookAndFeel();
1144 private static boolean setCrossPlatformLookAndFeel()
1146 boolean set = false;
1149 UIManager.setLookAndFeel(
1150 UIManager.getCrossPlatformLookAndFeelClassName());
1152 } catch (Exception ex)
1154 Console.error("Unexpected Look and Feel Exception");
1155 Console.error(ex.getMessage());
1156 Console.debug(Cache.getStackTraceString(ex));
1161 private static boolean setSystemLookAndFeel()
1163 boolean set = false;
1166 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
1168 } catch (Exception ex)
1170 Console.error("Unexpected Look and Feel Exception");
1171 Console.error(ex.getMessage());
1172 Console.debug(Cache.getStackTraceString(ex));
1177 private static boolean setSpecificLookAndFeel(String name,
1178 String className, boolean nameStartsWith)
1180 boolean set = false;
1183 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
1185 if (info.getName() != null && nameStartsWith
1186 ? info.getName().toLowerCase(Locale.ROOT)
1187 .startsWith(name.toLowerCase(Locale.ROOT))
1188 : info.getName().toLowerCase(Locale.ROOT)
1189 .equals(name.toLowerCase(Locale.ROOT)))
1191 className = info.getClassName();
1195 UIManager.setLookAndFeel(className);
1197 } catch (Exception ex)
1199 Console.error("Unexpected Look and Feel Exception");
1200 Console.error(ex.getMessage());
1201 Console.debug(Cache.getStackTraceString(ex));
1206 private static boolean setGtkLookAndFeel()
1208 return setSpecificLookAndFeel("gtk",
1209 "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true);
1212 private static boolean setMetalLookAndFeel()
1214 return setSpecificLookAndFeel("metal",
1215 "javax.swing.plaf.metal.MetalLookAndFeel", false);
1218 private static boolean setNimbusLookAndFeel()
1220 return setSpecificLookAndFeel("nimbus",
1221 "javax.swing.plaf.nimbus.NimbusLookAndFeel", false);
1224 private static boolean setFlatLookAndFeel()
1226 boolean set = false;
1227 if (SystemInfo.isMacOS)
1231 UIManager.setLookAndFeel(
1232 "com.formdev.flatlaf.themes.FlatMacLightLaf");
1234 Console.debug("Using FlatMacLightLaf");
1235 } catch (ClassNotFoundException | InstantiationException
1236 | IllegalAccessException | UnsupportedLookAndFeelException e)
1238 Console.debug("Exception loading FlatLightLaf", e);
1240 System.setProperty("apple.laf.useScreenMenuBar", "true");
1241 System.setProperty("apple.awt.application.name",
1242 ChannelProperties.getProperty("app_name"));
1243 System.setProperty("apple.awt.application.appearance", "system");
1244 if (SystemInfo.isMacFullWindowContentSupported
1245 && Desktop.desktop != null)
1247 Console.debug("Setting transparent title bar");
1248 Desktop.desktop.getRootPane()
1249 .putClientProperty("apple.awt.fullWindowContent", true);
1250 Desktop.desktop.getRootPane()
1251 .putClientProperty("apple.awt.transparentTitleBar", true);
1252 Desktop.desktop.getRootPane()
1253 .putClientProperty("apple.awt.fullscreenable", true);
1255 SwingUtilities.invokeLater(() -> {
1256 FlatMacLightLaf.setup();
1258 Console.debug("Using FlatMacLightLaf");
1265 UIManager.setLookAndFeel("com.formdev.flatlaf.FlatLightLaf");
1267 Console.debug("Using FlatLightLaf");
1268 } catch (ClassNotFoundException | InstantiationException
1269 | IllegalAccessException | UnsupportedLookAndFeelException e)
1271 Console.debug("Exception loading FlatLightLaf", e);
1273 // Windows specific properties here
1274 SwingUtilities.invokeLater(() -> {
1275 FlatLightLaf.setup();
1277 Console.debug("Using FlatLightLaf");
1280 else if (SystemInfo.isLinux)
1284 UIManager.setLookAndFeel("com.formdev.flatlaf.FlatLightLaf");
1286 Console.debug("Using FlatLightLaf");
1287 } catch (ClassNotFoundException | InstantiationException
1288 | IllegalAccessException | UnsupportedLookAndFeelException e)
1290 Console.debug("Exception loading FlatLightLaf", e);
1292 // enable custom window decorations
1293 JFrame.setDefaultLookAndFeelDecorated(true);
1294 JDialog.setDefaultLookAndFeelDecorated(true);
1295 SwingUtilities.invokeLater(() -> {
1296 FlatLightLaf.setup();
1298 Console.debug("Using FlatLightLaf");
1306 UIManager.setLookAndFeel("com.formdev.flatlaf.FlatLightLaf");
1308 Console.debug("Using FlatLightLaf");
1309 } catch (ClassNotFoundException | InstantiationException
1310 | IllegalAccessException | UnsupportedLookAndFeelException e)
1312 Console.debug("Exception loading FlatLightLaf", e);
1318 UIManager.put("TabbedPane.tabType", "card");
1319 UIManager.put("TabbedPane.showTabSeparators", true);
1320 UIManager.put("TabbedPane.showContentSeparator", true);
1321 UIManager.put("TabbedPane.tabSeparatorsFullHeight", true);
1322 UIManager.put("TabbedPane.tabsOverlapBorder", true);
1323 UIManager.put("TabbedPane.hasFullBorder", true);
1324 UIManager.put("TabbedPane.tabLayoutPolicy", "scroll");
1325 UIManager.put("TabbedPane.scrollButtonsPolicy", "asNeeded");
1326 UIManager.put("TabbedPane.smoothScrolling", true);
1327 UIManager.put("TabbedPane.tabWidthMode", "compact");
1328 UIManager.put("TabbedPane.selectedBackground", Color.white);
1331 Desktop.setLiveDragMode(Cache.getDefault("FLAT_LIVE_DRAG_MODE", true));
1335 private static boolean setMacLookAndFeel()
1337 boolean set = false;
1338 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
1339 ChannelProperties.getProperty("app_name"));
1340 System.setProperty("apple.laf.useScreenMenuBar", "true");
1342 * broken native LAFs on (ARM?) macbooks
1343 set = setQuaquaLookAndFeel();
1344 if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
1345 .toLowerCase(Locale.ROOT).contains("quaqua"))
1347 set = setVaquaLookAndFeel();
1350 set = setFlatLookAndFeel();
1354 private static boolean setLinuxLookAndFeel()
1356 boolean set = false;
1358 * THIS IS A TEST FOR THE BUILD SERVER!
1360 set = setMetalLookAndFeel();
1361 //set = setFlatLookAndFeel();
1364 set = setMetalLookAndFeel();
1365 // avoid GtkLookAndFeel -- not good results especially on HiDPI
1367 set = setNimbusLookAndFeel();
1371 private static void showUsage()
1374 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1375 + "-nodisplay\tRun Jalview without User Interface.\n"
1376 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1377 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1378 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1379 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1380 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1381 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1382 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1383 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1384 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1385 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1386 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1387 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1388 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1389 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1390 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1391 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1392 + "-html FILE\tCreate HTML file from alignment.\n"
1393 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1394 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1395 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1396 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1397 + "-noquestionnaire\tTurn off questionnaire check.\n"
1398 + "-nonews\tTurn off check for Jalview news.\n"
1399 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1400 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1402 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1403 // after all other properties files have been read\n\t
1404 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1405 // passed in correctly)"
1406 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1407 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1408 + "-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"
1409 + "-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"
1410 + "-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"
1411 + "\n~Read documentation in Application or visit https://www.jalview.org for description of Features and Annotations file~\n\n");
1414 private static void startUsageStats(final Desktop desktop)
1417 * start a User Config prompt asking if we can log usage statistics.
1419 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
1420 "USAGESTATS", "Jalview Usage Statistics",
1421 "Do you want to help make Jalview better by enabling "
1422 + "the collection of usage statistics with Google Analytics ?"
1423 + "\n\n(you can enable or disable usage tracking in the preferences)",
1430 "Initialising googletracker for usage stats.");
1431 Cache.initGoogleTracker();
1432 Console.debug("Tracking enabled.");
1439 Console.debug("Not enabling Google Tracking.");
1442 desktop.addDialogThread(prompter);
1446 * Locate the given string as a file and pass it to the groovy interpreter.
1448 * @param groovyscript
1449 * the script to execute
1450 * @param jalviewContext
1451 * the Jalview Desktop object passed in to the groovy binding as the
1454 private void executeGroovyScript(String groovyscript, AlignFrame af)
1457 * for scripts contained in files
1464 if (groovyscript.trim().equals("STDIN"))
1466 // read from stdin into a tempfile and execute it
1469 tfile = File.createTempFile("jalview", "groovy");
1470 PrintWriter outfile = new PrintWriter(
1471 new OutputStreamWriter(new FileOutputStream(tfile)));
1472 BufferedReader br = new BufferedReader(
1473 new InputStreamReader(System.in));
1475 while ((line = br.readLine()) != null)
1477 outfile.write(line + "\n");
1483 } catch (Exception ex)
1485 System.err.println("Failed to read from STDIN into tempfile "
1486 + ((tfile == null) ? "(tempfile wasn't created)"
1487 : tfile.toString()));
1488 ex.printStackTrace();
1493 sfile = tfile.toURI().toURL();
1494 } catch (Exception x)
1497 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1499 x.printStackTrace();
1507 sfile = new URI(groovyscript).toURL();
1508 } catch (Exception x)
1510 tfile = new File(groovyscript);
1511 if (!tfile.exists())
1513 System.err.println("File '" + groovyscript + "' does not exist.");
1516 if (!tfile.canRead())
1518 System.err.println("File '" + groovyscript + "' cannot be read.");
1521 if (tfile.length() < 1)
1523 System.err.println("File '" + groovyscript + "' is empty.");
1528 sfile = tfile.getAbsoluteFile().toURI().toURL();
1529 } catch (Exception ex)
1531 System.err.println("Failed to create a file URL for "
1532 + tfile.getAbsoluteFile());
1539 Map<String, java.lang.Object> vbinding = new HashMap<>();
1540 vbinding.put("Jalview", this);
1543 vbinding.put("currentAlFrame", af);
1545 Binding gbinding = new Binding(vbinding);
1546 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1547 gse.run(sfile.toString(), gbinding);
1548 if ("STDIN".equals(groovyscript))
1550 // delete temp file that we made -
1551 // only if it was successfully executed
1554 } catch (Exception e)
1556 System.err.println("Exception Whilst trying to execute file " + sfile
1557 + " as a groovy script.");
1558 e.printStackTrace(System.err);
1563 public static boolean isHeadlessMode()
1565 String isheadless = System.getProperty("java.awt.headless");
1566 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1573 public AlignFrame[] getAlignFrames()
1575 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1576 : Desktop.getAlignFrames();
1581 * jalview.bin.Jalview.quit() will just run the non-GUI shutdownHook and exit
1585 // System.exit will run the shutdownHook first
1586 System.out.println("Quitting now. Bye!");
1590 public static AlignFrame getCurrentAlignFrame()
1592 return Jalview.currentAlignFrame;
1595 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1597 Jalview.currentAlignFrame = currentAlignFrame;
1600 protected Commands getCommands()