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.util.Locale;
25 import java.awt.GraphicsEnvironment;
26 import java.awt.Color;
28 import java.io.BufferedReader;
30 import java.io.FileOutputStream;
31 import java.io.IOException;
32 import java.io.InputStreamReader;
33 import java.io.OutputStreamWriter;
34 import java.io.PrintWriter;
35 import java.net.MalformedURLException;
37 import java.net.URISyntaxException;
39 import java.security.AllPermission;
40 import java.security.CodeSource;
41 import java.security.PermissionCollection;
42 import java.security.Permissions;
43 import java.security.Policy;
44 import java.util.HashMap;
45 import java.util.Locale;
47 import java.util.Vector;
48 import java.util.logging.ConsoleHandler;
49 import java.util.logging.Level;
50 import java.util.logging.Logger;
52 import javax.swing.JOptionPane;
53 import javax.swing.SwingUtilities;
54 import javax.swing.UIManager;
55 import javax.swing.UIManager.LookAndFeelInfo;
57 import com.formdev.flatlaf.FlatLightLaf;
58 import com.formdev.flatlaf.util.SystemInfo;
59 import com.threerings.getdown.util.LaunchUtil;
61 //import edu.stanford.ejalbert.launching.IBrowserLaunching;
62 import groovy.lang.Binding;
63 import groovy.util.GroovyScriptEngine;
64 import jalview.api.AlignCalcWorkerI;
65 import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
66 import jalview.ext.so.SequenceOntology;
67 import jalview.gui.AlignFrame;
68 import jalview.gui.AlignViewport;
69 import jalview.gui.Desktop;
70 import jalview.gui.Preferences;
71 import jalview.gui.PromptUserConfig;
72 import jalview.io.AppletFormatAdapter;
73 import jalview.io.BioJsHTMLOutput;
74 import jalview.io.DataSourceType;
75 import jalview.io.FileFormat;
76 import jalview.io.FileFormatException;
77 import jalview.io.FileFormatI;
78 import jalview.io.FileFormats;
79 import jalview.io.FileLoader;
80 import jalview.io.HtmlSvgOutput;
81 import jalview.io.IdentifyFile;
82 import jalview.io.NewickFile;
83 import jalview.io.gff.SequenceOntologyFactory;
84 import jalview.schemes.ColourSchemeI;
85 import jalview.schemes.ColourSchemeProperty;
86 import jalview.util.ChannelProperties;
87 import jalview.util.HttpUtils;
88 import jalview.util.LaunchUtils;
89 import jalview.util.MessageManager;
90 import jalview.util.Platform;
91 import jalview.ws.jws2.Jws2Discoverer;
94 * Main class for Jalview Application <br>
96 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
99 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
100 * jalview.bin.Jalview jalview.bin.Jalview
102 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
103 * embellish '*' to e.g. '*.jar')
106 * @version $Revision$
108 public class Jalview implements ApplicationSingletonI
110 // for testing those nasty messages you cannot ever find.
113 // System.setOut(new PrintStream(new ByteArrayOutputStream())
116 // public void println(Object o)
120 // System.err.println(o);
126 public static Jalview getInstance()
128 return ApplicationSingletonProvider.getInstance(Jalview.class);
133 Platform.getURLCommandArguments();
134 Platform.addJ2SDirectDatabaseCall("https://www.jalview.org");
135 Platform.addJ2SDirectDatabaseCall("http://www.jalview.org");
136 Platform.addJ2SDirectDatabaseCall("http://www.compbio.dundee.ac.uk");
137 Platform.addJ2SDirectDatabaseCall("https://www.compbio.dundee.ac.uk");
141 private boolean headless;
143 private Desktop desktop;
145 public AlignFrame currentAlignFrame;
147 public String appletResourcePath;
149 public String j2sAppletID;
151 private boolean noCalculation, noMenuBar, noStatus;
153 private boolean noAnnotation;
155 public boolean getStartCalculations()
157 return !noCalculation;
160 public boolean getAllowMenuBar()
165 public boolean getShowStatus()
170 public boolean getShowAnnotation()
172 return !noAnnotation;
179 Platform.getURLCommandArguments();
187 // grab all the rights we can for the JVM
188 Policy.setPolicy(new Policy()
191 public PermissionCollection getPermissions(CodeSource codesource)
193 Permissions perms = new Permissions();
194 perms.add(new AllPermission());
199 public void refresh()
207 * keep track of feature fetching tasks.
215 * TODO: generalise to track all jalview events to orchestrate batch processing
219 private int queued = 0;
221 private int running = 0;
223 public FeatureFetcher()
228 public void addFetcher(final AlignFrame af,
229 final Vector<String> dasSources)
231 final long id = System.currentTimeMillis();
233 final FeatureFetcher us = this;
234 new Thread(new Runnable()
246 af.setProgressBar(MessageManager
247 .getString("status.das_features_being_retrived"), id);
248 af.featureSettings_actionPerformed(null);
249 af.setProgressBar(null, id);
258 public synchronized boolean allFinished()
260 return queued == 0 && running == 0;
265 private final static boolean doPlatformLogging = false;
268 * main class for Jalview application
271 * open <em>filename</em>
273 public static void main(String[] args)
275 if (doPlatformLogging)
277 Platform.startJavaLogging();
280 getInstance().doMain(args);
290 void doMain(String[] args)
293 boolean isJS = Platform.isJS();
296 System.setSecurityManager(null);
300 * @j2sNative J2S.db._DirectDatabaseCalls["compbio.dundee.ac.uk"]=null;
301 * @j2sNative J2S.db._DirectDatabaseCalls["jalview.org"]=null;
305 .println("Java version: " + System.getProperty("java.version"));
306 System.out.println("Java Home: " + System.getProperty("java.home"));
307 System.out.println(System.getProperty("os.arch") + " "
308 + System.getProperty("os.name") + " "
309 + System.getProperty("os.version"));
310 String val = System.getProperty("sys.install4jVersion");
313 System.out.println("Install4j version: " + val);
315 val = System.getProperty("installer_template_version");
318 System.out.println("Install4j template version: " + val);
320 val = System.getProperty("launcher_version");
323 System.out.println("Launcher version: " + val);
326 // report Jalview version
327 Cache.getInstance().loadBuildProperties(true);
329 ArgsParser aparser = new ArgsParser(args);
332 String usrPropsFile = aparser.getValue("props");
333 Cache.loadProperties(usrPropsFile); // must do this before
334 boolean allowServices = true;
338 j2sAppletID = Platform.getAppID(null);
339 Preferences.setAppletDefaults();
340 Cache.loadProperties(usrPropsFile); // again, because we
341 // might be changing defaults here?
342 appletResourcePath = (String) aparser.getAppletValue("resourcepath",
353 if (usrPropsFile != null)
356 "CMD [-props " + usrPropsFile + "] executed successfully!");
358 if (aparser.contains("help") || aparser.contains("h"))
363 // BH note: Only -nodisplay is official; others are deprecated?
364 if (aparser.contains("nodisplay") || aparser.contains("nogui")
365 || aparser.contains("headless")
366 || GraphicsEnvironment.isHeadless())
369 // BH Definitely not a good idea in JavaScript;
370 // probably should not be here for Java, either.
371 System.setProperty("java.awt.headless", "true");
377 // allow https handshakes to download intermediate certs if necessary
378 System.setProperty("com.sun.security.enableAIAcaIssuers", "true");
379 final String jabawsUrl = aparser.getValue(ArgsParser.JABAWS);
380 allowServices = !("none".equals(jabawsUrl));
381 if (allowServices && jabawsUrl != null)
385 Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl);
387 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
388 } catch (MalformedURLException e)
391 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
396 String defs = aparser.getValue(ArgsParser.SETPROP);
399 int p = defs.indexOf('=');
402 System.err.println("Ignoring invalid setprop argument : " + defs);
406 System.out.println("Executing setprop argument: " + defs);
409 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
412 defs = aparser.getValue("setprop");
414 if (System.getProperty("java.awt.headless") != null
415 && System.getProperty("java.awt.headless").equals("true"))
419 System.setProperty("http.agent",
420 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
423 Console.initLogger();
424 } catch (NoClassDefFoundError error)
426 error.printStackTrace();
427 System.out.println("\nEssential logging libraries not found."
428 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
437 * configure 'full' SO model if preferences say to, else use the default (full SO)
438 * - as JS currently doesn't have OBO parsing, it must use 'Lite' version
440 boolean soDefault = !isJS;
441 if (Cache.getDefault("USE_FULL_SO", soDefault))
443 SequenceOntologyFactory.setSequenceOntology(new SequenceOntology());
448 Desktop.nosplash = aparser.contains("nosplash");
449 desktop = Desktop.getInstance();
450 desktop.setInBatchMode(true); // indicate we are starting up
454 JalviewTaskbar.setTaskbar(this);
455 } catch (Exception e)
457 Console.info("Cannot set Taskbar");
458 Console.error(e.getMessage());
459 // e.printStackTrace();
460 } catch (Throwable t)
462 Console.info("Cannot set Taskbar");
463 Console.error(t.getMessage());
464 // t.printStackTrace();
467 // set Proxy settings before all the internet calls
468 Cache.setProxyPropertiesFromPreferences();
470 desktop.setVisible(true);
474 Cache.setProperty("SHOW_JWS2_SERVICES", "false");
476 if (allowServices && !aparser.contains("nowebservicediscovery"))
478 desktop.startServiceDiscovery();
489 * Check to see that the JVM version being run is suitable for the Java
490 * version this Jalview was compiled for. Popup a warning if not.
492 if (!LaunchUtils.checkJavaVersion())
494 Console.warn("The Java version being used (Java "
495 + LaunchUtils.getJavaVersion()
496 + ") may lead to problems. This installation of Jalview should be used with Java "
497 + LaunchUtils.getJavaCompileVersion() + ".");
500 .getBooleanUserPreference("IGNORE_JVM_WARNING_POPUP"))
503 MessageManager.getString("label.continue") };
504 JOptionPane.showOptionDialog(null,
505 MessageManager.formatMessage(
506 "warning.wrong_jvm_version_message",
507 LaunchUtils.getJavaVersion(),
508 LaunchUtils.getJavaCompileVersion()),
510 .getString("warning.wrong_jvm_version_title"),
511 JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
512 null, options, options[0]);
515 if (!aparser.contains("nousagestats"))
517 startUsageStats(desktop);
521 System.err.println("CMD [-nousagestats] executed successfully!");
524 if (!aparser.contains("noquestionnaire"))
526 String url = aparser.getValue("questionnaire");
529 // Start the desktop questionnaire prompter with the specified
531 Console.debug("Starting questionnaire url at " + url);
532 desktop.checkForQuestionnaire(url);
533 System.out.println("CMD questionnaire[-" + url
534 + "] executed successfully!");
538 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
540 // Start the desktop questionnaire prompter with the specified
543 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
545 String defurl = "https://www.jalview.org/cgi-bin/questionnaire.pl";
547 "Starting questionnaire with default url: " + defurl);
548 desktop.checkForQuestionnaire(defurl);
555 .println("CMD [-noquestionnaire] executed successfully!");
558 if (!aparser.contains("nonews")
559 || Cache.getProperty("NONEWS") == null)
561 desktop.checkForNews();
564 if (!aparser.contains("nohtmltemplates")
565 || Cache.getProperty("NOHTMLTEMPLATES") == null)
567 BioJsHTMLOutput.updateBioJS();
572 // Check if JVM and compile version might cause problems and log if it
574 if (headless && !Platform.isJS() && !LaunchUtils.checkJavaVersion())
576 Console.warn("The Java version being used (Java "
577 + LaunchUtils.getJavaVersion()
578 + ") may lead to problems. This installation of Jalview should be used with Java "
579 + LaunchUtils.getJavaCompileVersion() + ".");
581 parseArguments(aparser, true);
585 * Parse all command-line String[] arguments as well as all JavaScript-derived
586 * parameters from Info.
588 * We allow for this method to be run from JavaScript. Basically allowing
594 public void parseArguments(ArgsParser aparser, boolean isStartup)
597 String groovyscript = null; // script to execute after all loading is
598 boolean isJS = Platform.isJS();
602 // Move any new getdown-launcher-new.jar into place over old
603 // getdown-launcher.jar
604 String appdirString = System.getProperty("getdownappdir");
605 if (appdirString != null && appdirString.length() > 0)
607 final File appdir = new File(appdirString);
613 LaunchUtil.upgradeGetdown(
614 new File(appdir, "getdown-launcher-old.jar"),
615 new File(appdir, "getdown-launcher.jar"),
616 new File(appdir, "getdown-launcher-new.jar"));
621 // completed one way or another
622 // extract groovy argument and execute if necessary
623 groovyscript = aparser.getValue("groovy", true);
626 String file = aparser.getValue("open", true);
628 if (!isJS && file == null && desktop == null)
630 System.out.println("No files to open!");
633 setDisplayParameters(aparser);
635 // time to open a file.
637 DataSourceType protocol = null;
638 FileLoader fileLoader = new FileLoader(!headless);
639 FileFormatI format = null;
640 // Finally, deal with the remaining input data.
641 AlignFrame af = null;
643 JalviewJSApp jsApp = (isJS ? new JalviewJSApp(this, aparser) : null);
649 // JalviewJS allows sequence1 sequence2 ....
652 else if (!headless && Cache.getDefault("SHOW_STARTUP_FILE", true))
659 file = Cache.getDefault("STARTUP_FILE",
660 Cache.getDefault("www.jalview.org", "https://www.jalview.org")
661 + "/examples/exampleFile_2_7.jvp");
662 if (file.equals("http://www.jalview.org/examples/exampleFile_2_3.jar")
664 "http://www.jalview.org/examples/exampleFile_2_7.jar"))
666 file.replace("http:", "https:");
667 // hardwire upgrade of the startup file
668 file.replace("_2_3", "_2_7");
669 file.replace("2_7.jar", "2_7.jvp");
670 // and remove the stale setting
671 Cache.removeProperty("STARTUP_FILE");
674 protocol = AppletFormatAdapter.checkProtocol(file);
676 if (file.endsWith(".jar"))
678 format = FileFormat.Jalview;
684 format = new IdentifyFile().identify(file, protocol);
685 } catch (FileFormatException e)
691 af = fileLoader.LoadFileWaitTillLoaded(file, protocol, format);
698 desktop.setProgressBar(
700 .getString("status.processing_commandline_args"),
701 progress = System.currentTimeMillis());
703 System.out.println("CMD [-open " + file + "] executed successfully!");
705 if (!Platform.isJS())
707 * ignore in JavaScript -- can't just file existence - could load it?
712 if (!HttpUtils.startsWithHttpOrHttps(file))
714 if (!(new File(file)).exists())
716 System.out.println("Can't find " + file);
725 // JS Only argument to provide a format parameter to specify what format to use
726 String fileFormat = (isJS
727 ? (String) aparser.getAppletValue("format", null, true)
729 protocol = AppletFormatAdapter.checkProtocol(file);
733 format = (fileFormat != null
734 ? FileFormats.getInstance().forName(fileFormat)
738 format = new IdentifyFile().identify(file, protocol);
740 } catch (FileFormatException e1)
745 af = new FileLoader(!headless).LoadFileWaitTillLoaded(file, protocol,
749 System.out.println("jalview error - AlignFrame was not created");
754 // JalviewLite interface for JavaScript allows second file open
755 String file2 = aparser.getValue(ArgsParser.OPEN2, true);
758 protocol = AppletFormatAdapter.checkProtocol(file2);
761 format = new IdentifyFile().identify(file2, protocol);
762 } catch (FileFormatException e1)
766 AlignFrame af2 = new FileLoader(!headless)
767 .LoadFileWaitTillLoaded(file2, protocol, format);
770 System.out.println("error");
774 AlignViewport.openLinkedAlignmentAs(af,
775 af.getViewport().getAlignment(),
776 af2.getViewport().getAlignment(), "",
777 AlignViewport.SPLIT_FRAME);
779 "CMD [-open2 " + file2 + "] executed successfully!");
782 // af is loaded - so set it as current frame
783 setCurrentAlignFrame(af);
785 setFrameDependentProperties(aparser, af);
789 jsApp.initFromParams(af);
798 if (groovyscript != null)
800 // Execute the groovy script after we've done all the rendering
802 // and before any images or figures are generated.
803 System.out.println("Executing script " + groovyscript);
804 executeGroovyScript(groovyscript, af);
805 System.out.println("CMD groovy[" + groovyscript
806 + "] executed successfully!");
810 if (!isJS || !isStartup) {
811 createOutputFiles(aparser, format);
816 af.getViewport().getCalcManager().shutdown();
819 // extract groovy arguments before anything else.
820 // Once all other stuff is done, execute any groovy scripts (in order)
821 if (!isJS && groovyscript != null)
823 if (Cache.groovyJarsPresent())
825 // TODO: DECIDE IF THIS SECOND PASS AT GROOVY EXECUTION IS STILL REQUIRED !!
826 System.out.println("Executing script " + groovyscript);
827 executeGroovyScript(groovyscript, af);
828 System.out.println("CMD groovy[" + groovyscript
829 + "] executed successfully!");
835 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
840 // and finally, turn off batch mode indicator - if the desktop still exists
845 desktop.setProgressBar(null, progress);
847 desktop.setInBatchMode(false);
851 jsApp.callInitCallback();
856 * Set general display parameters irrespective of file loading or headlessness.
860 private void setDisplayParameters(ArgsParser aparser)
862 if (aparser.contains(ArgsParser.NOMENUBAR))
865 System.out.println("CMD [nomenu] executed successfully!");
868 if (aparser.contains(ArgsParser.NOSTATUS))
871 System.out.println("CMD [nostatus] executed successfully!");
874 if (aparser.contains(ArgsParser.NOANNOTATION)
875 || aparser.contains(ArgsParser.NOANNOTATION2))
878 System.out.println("CMD no-annotation executed successfully!");
880 if (aparser.contains(ArgsParser.NOCALCULATION))
882 noCalculation = true;
883 System.out.println("CMD [nocalculation] executed successfully!");
887 private void setFrameDependentProperties(ArgsParser aparser,
890 String data = aparser.getValue(ArgsParser.COLOUR, true);
893 data.replaceAll("%20", " ");
895 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
896 af.getViewport(), af.getViewport().getAlignment(), data);
901 "CMD [-color " + data + "] executed successfully!");
906 // Must maintain ability to use the groups flag
907 data = aparser.getValue(ArgsParser.GROUPS, true);
910 af.parseFeaturesFile(data,
911 AppletFormatAdapter.checkProtocol(data));
912 // System.out.println("Added " + data);
914 "CMD groups[-" + data + "] executed successfully!");
916 data = aparser.getValue(ArgsParser.FEATURES, true);
919 af.parseFeaturesFile(data,
920 AppletFormatAdapter.checkProtocol(data));
921 // System.out.println("Added " + data);
923 "CMD [-features " + data + "] executed successfully!");
925 data = aparser.getValue(ArgsParser.ANNOTATIONS, true);
928 af.loadJalviewDataFile(data, null, null, null);
929 // System.out.println("Added " + data);
931 "CMD [-annotations " + data + "] executed successfully!");
934 // JavaScript feature
936 if (aparser.contains(ArgsParser.SHOWOVERVIEW))
938 af.overviewMenuItem_actionPerformed(null);
939 System.out.println("CMD [showoverview] executed successfully!");
942 // set or clear the sortbytree flag.
943 if (aparser.contains(ArgsParser.SORTBYTREE))
945 af.getViewport().setSortByTree(true);
946 if (af.getViewport().getSortByTree())
948 System.out.println("CMD [-sortbytree] executed successfully!");
952 boolean doUpdateAnnotation = false;
954 * we do this earlier in JalviewJS because of a complication with
957 * For now, just fixing this in JalviewJS.
966 af.getViewport().setShowAnnotation(false);
967 if (!af.getViewport().isShowAnnotation())
969 doUpdateAnnotation = true;
975 if (aparser.contains(ArgsParser.NOSORTBYTREE))
977 af.getViewport().setSortByTree(false);
978 if (!af.getViewport().getSortByTree())
980 doUpdateAnnotation = true;
982 .println("CMD [-nosortbytree] executed successfully!");
985 if (doUpdateAnnotation)
987 af.setMenusForViewport();
988 af.alignPanel.updateLayout();
991 data = aparser.getValue(ArgsParser.TREE, true);
996 NewickFile nf = new NewickFile(data,
997 AppletFormatAdapter.checkProtocol(data));
999 .setCurrentTree(af.showNewickTree(nf, data).getTree());
1001 "CMD [-tree " + data + "] executed successfully!");
1002 } catch (IOException ex)
1004 System.err.println("Couldn't add tree " + data);
1005 ex.printStackTrace(System.err);
1008 // TODO - load PDB structure(s) to alignment JAL-629
1009 // (associate with identical sequence in alignment, or a specified
1015 * Writes an output file for each format (if any) specified in the
1016 * command-line arguments. Supported formats are currently
1025 * A format parameter should be followed by a parameter specifying the output
1026 * file name. {@code imgMap} parameters should follow those for the
1027 * corresponding alignment image output.
1032 private void createOutputFiles(ArgsParser aparser, FileFormatI format)
1034 // logic essentially the same as 2.11.2/2.11.3 but uses a switch instead
1035 AlignFrame af = currentAlignFrame;
1036 while (aparser.getSize() >= 2)
1038 String outputFormat = aparser.nextValue();
1041 switch (outputFormat.toLowerCase(Locale.ROOT))
1044 imageFile = new File(aparser.nextValue());
1045 af.createPNG(imageFile);
1047 "Creating PNG image: " + imageFile.getAbsolutePath());
1050 imageFile = new File(aparser.nextValue());
1051 af.createSVG(imageFile);
1053 "Creating SVG image: " + imageFile.getAbsolutePath());
1056 imageFile = new File(aparser.nextValue());
1058 "Creating EPS file: " + imageFile.getAbsolutePath());
1059 af.createEPS(imageFile);
1062 fname = new File(aparser.nextValue()).getAbsolutePath();
1065 BioJsHTMLOutput.refreshVersionInfo(
1066 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
1067 } catch (URISyntaxException e)
1069 e.printStackTrace();
1071 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
1072 bjs.exportHTML(fname);
1073 System.out.println("Creating BioJS MSA Viwer HTML file: " + fname);
1076 fname = new File(aparser.nextValue()).getAbsolutePath();
1077 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
1078 htmlSVG.exportHTML(fname);
1079 System.out.println("Creating HTML image: " + fname);
1082 imageFile = new File(aparser.nextValue());
1083 af.alignPanel.makePNGImageMap(imageFile, "unnamed.png");
1085 "Creating image map: " + imageFile.getAbsolutePath());
1088 // fall through - try to parse as an alignment data export format
1089 FileFormatI outFormat = null;
1092 outFormat = FileFormats.getInstance().forName(outputFormat);
1093 } catch (Exception formatP)
1096 if (outFormat == null)
1098 System.out.println("Couldn't parse " + outputFormat
1099 + " as a valid Jalview format string.");
1102 if (!outFormat.isWritable())
1105 "This version of Jalview does not support alignment export as "
1109 // record file as it was passed to Jalview so it is recognisable to the CLI
1112 fname = new File(file = aparser.nextValue()).getAbsolutePath();
1113 // JBPNote - yuck - really wish we did have a bean returned from this which gave
1114 // success/fail like before !
1115 af.saveAlignment(fname, outFormat);
1116 if (!af.isSaveAlignmentSuccessful())
1118 System.out.println("Written alignment in " + outputFormat
1119 + " format to " + file);
1124 System.out.println("Error writing file " + file + " in "
1125 + outputFormat + " format!!");
1129 // ??? Should report - 'ignoring' extra args here...
1130 while (aparser.getSize() > 0)
1132 System.out.println("Ignoring extra argument: " + aparser.nextValue());
1136 private static void setLookAndFeel()
1138 // property laf = "crossplatform", "system", "gtk", "metal", "nimbus",
1140 // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
1141 // try Quaqua/Vaqua.
1142 String lafProp = System.getProperty("laf");
1143 String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
1144 String laf = "none";
1145 if (lafProp != null)
1149 else if (lafSetting != null)
1153 boolean lafSet = false;
1156 case "crossplatform":
1157 lafSet = setCrossPlatformLookAndFeel();
1160 Console.error("Could not set requested laf=" + laf);
1164 lafSet = setSystemLookAndFeel();
1167 Console.error("Could not set requested laf=" + laf);
1171 lafSet = setGtkLookAndFeel();
1174 Console.error("Could not set requested laf=" + laf);
1178 lafSet = setMetalLookAndFeel();
1181 Console.error("Could not set requested laf=" + laf);
1185 lafSet = setNimbusLookAndFeel();
1188 Console.error("Could not set requested laf=" + laf);
1192 lafSet = setFlatLookAndFeel();
1195 Console.error("Could not set requested laf=" + laf);
1199 lafSet = setQuaquaLookAndFeel();
1202 Console.error("Could not set requested laf=" + laf);
1206 lafSet = setVaquaLookAndFeel();
1209 Console.error("Could not set requested laf=" + laf);
1213 lafSet = setMacLookAndFeel();
1216 Console.error("Could not set requested laf=" + laf);
1222 Console.error("Requested laf=" + laf + " not implemented");
1226 setSystemLookAndFeel();
1227 if (Platform.isLinux())
1229 setMetalLookAndFeel();
1231 if (Platform.isMac())
1233 setMacLookAndFeel();
1238 private static boolean setCrossPlatformLookAndFeel()
1240 boolean set = false;
1243 UIManager.setLookAndFeel(
1244 UIManager.getCrossPlatformLookAndFeelClassName());
1246 } catch (Exception ex)
1248 Console.error("Unexpected Look and Feel Exception");
1249 Console.error(ex.getMessage());
1250 Console.debug(Cache.getStackTraceString(ex));
1255 private static boolean setSystemLookAndFeel()
1257 boolean set = false;
1260 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
1262 } catch (Exception ex)
1264 Console.error("Unexpected Look and Feel Exception");
1265 Console.error(ex.getMessage());
1266 Console.debug(Cache.getStackTraceString(ex));
1271 private static boolean setSpecificLookAndFeel(String name,
1272 String className, boolean nameStartsWith)
1274 boolean set = false;
1277 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
1279 if (info.getName() != null && nameStartsWith
1280 ? info.getName().toLowerCase(Locale.ROOT)
1281 .startsWith(name.toLowerCase(Locale.ROOT))
1282 : info.getName().toLowerCase(Locale.ROOT)
1283 .equals(name.toLowerCase(Locale.ROOT)))
1285 className = info.getClassName();
1289 UIManager.setLookAndFeel(className);
1291 } catch (Exception ex)
1293 Console.error("Unexpected Look and Feel Exception");
1294 Console.error(ex.getMessage());
1295 Console.debug(Cache.getStackTraceString(ex));
1300 private static boolean setGtkLookAndFeel()
1302 return setSpecificLookAndFeel("gtk",
1303 "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true);
1306 private static boolean setMetalLookAndFeel()
1308 return setSpecificLookAndFeel("metal",
1309 "javax.swing.plaf.metal.MetalLookAndFeel", false);
1312 private static boolean setNimbusLookAndFeel()
1314 return setSpecificLookAndFeel("nimbus",
1315 "javax.swing.plaf.nimbus.NimbusLookAndFeel", false);
1318 private static boolean setFlatLookAndFeel()
1320 boolean set = setSpecificLookAndFeel("flatlaf light",
1321 "com.formdev.flatlaf.FlatLightLaf", false);
1324 if (Platform.isMac())
1326 System.setProperty("apple.laf.useScreenMenuBar", "true");
1327 System.setProperty("apple.awt.application.name",
1328 ChannelProperties.getProperty("app_name"));
1329 System.setProperty("apple.awt.application.appearance", "system");
1330 if (SystemInfo.isMacFullWindowContentSupported
1331 && Desktop.getInstance() != null)
1333 Desktop.getInstance().getRootPane()
1334 .putClientProperty("apple.awt.fullWindowContent", true);
1335 Desktop.getInstance().getRootPane()
1336 .putClientProperty("apple.awt.transparentTitleBar", true);
1339 SwingUtilities.invokeLater(() -> {
1340 FlatLightLaf.setup();
1344 UIManager.put("TabbedPane.showTabSeparators", true);
1345 UIManager.put("TabbedPane.tabSeparatorsFullHeight", true);
1346 UIManager.put("TabbedPane.tabsOverlapBorder", true);
1347 // UIManager.put("TabbedPane.hasFullBorder", true);
1348 UIManager.put("TabbedPane.tabLayoutPolicy", "scroll");
1349 UIManager.put("TabbedPane.scrollButtonsPolicy", "asNeeded");
1350 UIManager.put("TabbedPane.smoothScrolling", true);
1351 UIManager.put("TabbedPane.tabWidthMode", "compact");
1352 UIManager.put("TabbedPane.selectedBackground", Color.white);
1356 private static boolean setQuaquaLookAndFeel()
1358 return setSpecificLookAndFeel("quaqua",
1359 ch.randelshofer.quaqua.QuaquaManager.getLookAndFeel().getClass()
1364 private static boolean setVaquaLookAndFeel()
1366 return setSpecificLookAndFeel("vaqua",
1367 "org.violetlib.aqua.AquaLookAndFeel", false);
1370 private static boolean setMacLookAndFeel()
1372 boolean set = false;
1373 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
1374 ChannelProperties.getProperty("app_name"));
1375 System.setProperty("apple.laf.useScreenMenuBar", "true");
1377 * broken native LAFs on (ARM?) macbooks
1378 set = setQuaquaLookAndFeel();
1379 if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
1380 .toLowerCase(Locale.ROOT).contains("quaqua"))
1382 set = setVaquaLookAndFeel();
1385 set = setFlatLookAndFeel();
1389 private static void showUsage()
1392 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1393 + "-nodisplay\tRun Jalview without User Interface.\n"
1394 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1395 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1396 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1397 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1398 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1399 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1400 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1401 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1402 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1403 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1404 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1405 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1406 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1407 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1408 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1409 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1410 + "-html FILE\tCreate HTML file from alignment.\n"
1411 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1412 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1413 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1414 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1415 + "-noquestionnaire\tTurn off questionnaire check.\n"
1416 + "-nonews\tTurn off check for Jalview news.\n"
1417 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1418 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1420 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1421 // after all other properties files have been read\n\t
1422 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1423 // passed in correctly)"
1424 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1425 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1426 + "-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"
1427 + "-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"
1428 + "-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"
1429 + "\n~Read documentation in Application or visit https://www.jalview.org for description of Features and Annotations file~\n\n");
1432 private static void startUsageStats(final Desktop desktop)
1435 * start a User Config prompt asking if we can log usage statistics.
1437 PromptUserConfig prompter = new PromptUserConfig(Desktop.getDesktopPane(),
1438 "USAGESTATS", "Jalview Usage Statistics",
1439 "Do you want to help make Jalview better by enabling "
1440 + "the collection of usage statistics with Google Analytics ?"
1441 + "\n\n(you can enable or disable usage tracking in the preferences)",
1448 "Initialising googletracker for usage stats.");
1449 Cache.initGoogleTracker();
1450 Console.debug("Tracking enabled.");
1457 Console.debug("Not enabling Google Tracking.");
1460 desktop.addDialogThread(prompter);
1464 * Locate the given string as a file and pass it to the groovy interpreter.
1466 * @param groovyscript
1467 * the script to execute
1468 * @param jalviewContext
1469 * the Jalview Desktop object passed in to the groovy binding as the
1472 private void executeGroovyScript(String groovyscript, AlignFrame af)
1475 * for scripts contained in files
1482 if (groovyscript.trim().equals("STDIN"))
1484 // read from stdin into a tempfile and execute it
1487 tfile = File.createTempFile("jalview", "groovy");
1488 PrintWriter outfile = new PrintWriter(
1489 new OutputStreamWriter(new FileOutputStream(tfile)));
1490 BufferedReader br = new BufferedReader(
1491 new InputStreamReader(System.in));
1493 while ((line = br.readLine()) != null)
1495 outfile.write(line + "\n");
1501 } catch (Exception ex)
1503 System.err.println("Failed to read from STDIN into tempfile "
1504 + ((tfile == null) ? "(tempfile wasn't created)"
1505 : tfile.toString()));
1506 ex.printStackTrace();
1511 sfile = tfile.toURI().toURL();
1512 } catch (Exception x)
1515 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1517 x.printStackTrace();
1525 sfile = new URI(groovyscript).toURL();
1526 } catch (Exception x)
1528 tfile = new File(groovyscript);
1529 if (!tfile.exists())
1531 System.err.println("File '" + groovyscript + "' does not exist.");
1534 if (!tfile.canRead())
1536 System.err.println("File '" + groovyscript + "' cannot be read.");
1539 if (tfile.length() < 1)
1541 System.err.println("File '" + groovyscript + "' is empty.");
1546 sfile = tfile.getAbsoluteFile().toURI().toURL();
1547 } catch (Exception ex)
1549 System.err.println("Failed to create a file URL for "
1550 + tfile.getAbsoluteFile());
1557 Map<String, java.lang.Object> vbinding = new HashMap<>();
1558 vbinding.put("Jalview", this);
1561 vbinding.put("currentAlFrame", af);
1563 Binding gbinding = new Binding(vbinding);
1564 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1565 gse.run(sfile.toString(), gbinding);
1566 if ("STDIN".equals(groovyscript))
1568 // delete temp file that we made -
1569 // only if it was successfully executed
1572 } catch (Exception e)
1574 System.err.println("Exception Whilst trying to execute file " + sfile
1575 + " as a groovy script.");
1576 e.printStackTrace(System.err);
1581 public static boolean isHeadlessMode()
1583 String isheadless = System.getProperty("java.awt.headless");
1584 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1591 public AlignFrame[] getAlignFrames()
1593 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1594 : Desktop.getAlignFrames();
1599 * Quit method delegates to Desktop.quit - unless running in headless mode when
1600 * it just ends the JVM
1604 if (desktop != null)
1614 public static AlignFrame getCurrentAlignFrame()
1616 return Jalview.getInstance().currentAlignFrame;
1619 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1621 Jalview.getInstance().currentAlignFrame = currentAlignFrame;
1624 public void notifyWorker(AlignCalcWorkerI worker, String status)
1626 // System.out.println("Jalview worker " + worker.getClass().getSimpleName()
1631 private static boolean isInteractive = true;
1633 public static boolean isInteractive()
1635 return isInteractive;
1638 public static void setInteractive(boolean tf)