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.OutputStreamWriter;
30 import java.io.PrintWriter;
31 import java.net.MalformedURLException;
33 import java.net.URISyntaxException;
35 import java.security.AllPermission;
36 import java.security.CodeSource;
37 import java.security.PermissionCollection;
38 import java.security.Permissions;
39 import java.security.Policy;
40 import java.util.HashMap;
41 import java.util.Locale;
43 import java.util.Vector;
44 import java.util.logging.ConsoleHandler;
45 import java.util.logging.Level;
46 import java.util.logging.Logger;
48 import javax.swing.SwingUtilities;
49 import javax.swing.UIManager;
50 import javax.swing.UIManager.LookAndFeelInfo;
52 import com.formdev.flatlaf.FlatLightLaf;
53 import com.formdev.flatlaf.util.SystemInfo;
54 import com.threerings.getdown.util.LaunchUtil;
56 //import edu.stanford.ejalbert.launching.IBrowserLaunching;
57 import groovy.lang.Binding;
58 import groovy.util.GroovyScriptEngine;
59 import jalview.ext.so.SequenceOntology;
60 import jalview.gui.AlignFrame;
61 import jalview.gui.Desktop;
62 import jalview.gui.PromptUserConfig;
63 import jalview.io.AppletFormatAdapter;
64 import jalview.io.BioJsHTMLOutput;
65 import jalview.io.DataSourceType;
66 import jalview.io.FileFormat;
67 import jalview.io.FileFormatException;
68 import jalview.io.FileFormatI;
69 import jalview.io.FileFormats;
70 import jalview.io.FileLoader;
71 import jalview.io.HtmlSvgOutput;
72 import jalview.io.IdentifyFile;
73 import jalview.io.NewickFile;
74 import jalview.io.gff.SequenceOntologyFactory;
75 import jalview.schemes.ColourSchemeI;
76 import jalview.schemes.ColourSchemeProperty;
77 import jalview.util.ChannelProperties;
78 import jalview.util.HttpUtils;
79 import jalview.util.MessageManager;
80 import jalview.util.Platform;
81 import jalview.ws.jws2.Jws2Discoverer;
84 * Main class for Jalview Application <br>
86 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
89 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
90 * jalview.bin.Jalview jalview.bin.Jalview
92 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
93 * embellish '*' to e.g. '*.jar')
102 Platform.getURLCommandArguments();
103 Platform.addJ2SDirectDatabaseCall("https://www.jalview.org");
104 Platform.addJ2SDirectDatabaseCall("http://www.jalview.org");
105 Platform.addJ2SDirectDatabaseCall("http://www.compbio.dundee.ac.uk");
106 Platform.addJ2SDirectDatabaseCall("https://www.compbio.dundee.ac.uk");
110 * singleton instance of this class
112 private static Jalview instance;
114 private Desktop desktop;
116 public static AlignFrame currentAlignFrame;
120 if (!Platform.isJS())
127 // grab all the rights we can for the JVM
128 Policy.setPolicy(new Policy()
131 public PermissionCollection getPermissions(CodeSource codesource)
133 Permissions perms = new Permissions();
134 perms.add(new AllPermission());
139 public void refresh()
147 * keep track of feature fetching tasks.
155 * TODO: generalise to track all jalview events to orchestrate batch processing
159 private int queued = 0;
161 private int running = 0;
163 public FeatureFetcher()
168 public void addFetcher(final AlignFrame af,
169 final Vector<String> dasSources)
171 final long id = System.currentTimeMillis();
173 final FeatureFetcher us = this;
174 new Thread(new Runnable()
186 af.setProgressBar(MessageManager
187 .getString("status.das_features_being_retrived"), id);
188 af.featureSettings_actionPerformed(null);
189 af.setProgressBar(null, id);
198 public synchronized boolean allFinished()
200 return queued == 0 && running == 0;
205 public static Jalview getInstance()
211 * main class for Jalview application
214 * open <em>filename</em>
216 public static void main(String[] args)
218 // setLogging(); // BH - for event debugging in JavaScript
219 instance = new Jalview();
220 instance.doMain(args);
223 private static void logClass(String name)
225 // BH - for event debugging in JavaScript
226 ConsoleHandler consoleHandler = new ConsoleHandler();
227 consoleHandler.setLevel(Level.ALL);
228 Logger logger = Logger.getLogger(name);
229 logger.setLevel(Level.ALL);
230 logger.addHandler(consoleHandler);
233 @SuppressWarnings("unused")
234 private static void setLogging()
242 System.out.println("not in js");
245 // BH - for event debugging in JavaScript (Java mode only)
246 if (!Platform.isJS())
253 Logger.getLogger("").setLevel(Level.ALL);
254 logClass("java.awt.EventDispatchThread");
255 logClass("java.awt.EventQueue");
256 logClass("java.awt.Component");
257 logClass("java.awt.focus.Component");
258 logClass("java.awt.focus.DefaultKeyboardFocusManager");
266 void doMain(String[] args)
269 if (!Platform.isJS())
271 System.setSecurityManager(null);
275 .println("Java version: " + System.getProperty("java.version"));
276 System.out.println("Java Home: " + System.getProperty("java.home"));
277 System.out.println(System.getProperty("os.arch") + " "
278 + System.getProperty("os.name") + " "
279 + System.getProperty("os.version"));
280 String val = System.getProperty("sys.install4jVersion");
283 System.out.println("Install4j version: " + val);
285 val = System.getProperty("installer_template_version");
288 System.out.println("Install4j template version: " + val);
290 val = System.getProperty("launcher_version");
293 System.out.println("Launcher version: " + val);
296 // report Jalview version
297 Cache.loadBuildProperties(true);
299 ArgsParser aparser = new ArgsParser(args);
300 boolean headless = false;
302 String usrPropsFile = aparser.getValue("props");
303 Cache.loadProperties(usrPropsFile); // must do this before
304 if (usrPropsFile != null)
307 "CMD [-props " + usrPropsFile + "] executed successfully!");
310 if (!Platform.isJS())
317 if (aparser.contains("help") || aparser.contains("h"))
322 if (aparser.contains("nodisplay") || aparser.contains("nogui")
323 || aparser.contains("headless"))
325 System.setProperty("java.awt.headless", "true");
330 // allow https handshakes to download intermediate certs if necessary
331 System.setProperty("com.sun.security.enableAIAcaIssuers", "true");
333 final String jabawsUrl = aparser.getValue("jabaws");
334 if (jabawsUrl != null)
338 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
340 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
341 } catch (MalformedURLException e)
344 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
349 String defs = aparser.getValue("setprop");
352 int p = defs.indexOf('=');
355 System.err.println("Ignoring invalid setprop argument : " + defs);
359 System.out.println("Executing setprop argument: " + defs);
362 Cache.setProperty(defs.substring(0, p), defs.substring(p + 1));
364 // DISABLED FOR SECURITY REASONS
365 // TODO: add a property to allow properties to be overriden by cli args
366 // Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
368 defs = aparser.getValue("setprop");
370 if (System.getProperty("java.awt.headless") != null
371 && System.getProperty("java.awt.headless").equals("true"))
375 System.setProperty("http.agent",
376 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
380 Console.initLogger();
381 } catch (NoClassDefFoundError error)
383 error.printStackTrace();
384 System.out.println("\nEssential logging libraries not found."
385 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
394 * configure 'full' SO model if preferences say to, else use the default (full SO)
395 * - as JS currently doesn't have OBO parsing, it must use 'Lite' version
397 boolean soDefault = !Platform.isJS();
398 if (Cache.getDefault("USE_FULL_SO", soDefault))
400 SequenceOntologyFactory.setInstance(new SequenceOntology());
405 Desktop.nosplash = aparser.contains("nosplash");
406 desktop = new Desktop();
407 desktop.setInBatchMode(true); // indicate we are starting up
411 JalviewTaskbar.setTaskbar(this);
412 } catch (Exception e)
414 Console.info("Cannot set Taskbar");
415 Console.error(e.getMessage());
416 // e.printStackTrace();
417 } catch (Throwable t)
419 Console.info("Cannot set Taskbar");
420 Console.error(t.getMessage());
421 // t.printStackTrace();
424 // set Proxy settings before all the internet calls
425 Cache.setProxyPropertiesFromPreferences();
427 desktop.setVisible(true);
429 if (!Platform.isJS())
436 if (!aparser.contains("nowebservicediscovery"))
438 desktop.startServiceDiscovery();
440 if (!aparser.contains("nousagestats"))
442 startUsageStats(desktop);
446 System.err.println("CMD [-nousagestats] executed successfully!");
449 if (!aparser.contains("noquestionnaire"))
451 String url = aparser.getValue("questionnaire");
454 // Start the desktop questionnaire prompter with the specified
456 Console.debug("Starting questionnaire url at " + url);
457 desktop.checkForQuestionnaire(url);
458 System.out.println("CMD questionnaire[-" + url
459 + "] executed successfully!");
463 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
465 // Start the desktop questionnaire prompter with the specified
468 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
470 String defurl = "https://www.jalview.org/cgi-bin/questionnaire.pl";
472 "Starting questionnaire with default url: " + defurl);
473 desktop.checkForQuestionnaire(defurl);
480 .println("CMD [-noquestionnaire] executed successfully!");
483 if (!aparser.contains("nonews")
484 || Cache.getProperty("NONEWS") == null)
486 desktop.checkForNews();
489 if (!aparser.contains("nohtmltemplates")
490 || Cache.getProperty("NOHTMLTEMPLATES") == null)
492 BioJsHTMLOutput.updateBioJS();
497 // Move any new getdown-launcher-new.jar into place over old
498 // getdown-launcher.jar
499 String appdirString = System.getProperty("getdownappdir");
500 if (appdirString != null && appdirString.length() > 0)
502 final File appdir = new File(appdirString);
508 LaunchUtil.upgradeGetdown(
509 new File(appdir, "getdown-launcher-old.jar"),
510 new File(appdir, "getdown-launcher.jar"),
511 new File(appdir, "getdown-launcher-new.jar"));
516 String file = null, data = null;
517 FileFormatI format = null;
518 DataSourceType protocol = null;
519 FileLoader fileLoader = new FileLoader(!headless);
521 String groovyscript = null; // script to execute after all loading is
522 // completed one way or another
523 // extract groovy argument and execute if necessary
524 groovyscript = aparser.getValue("groovy", true);
525 file = aparser.getValue("open", true);
527 if (file == null && desktop == null)
529 System.out.println("No files to open!");
533 // Finally, deal with the remaining input data.
538 desktop.setProgressBar(
540 .getString("status.processing_commandline_args"),
541 progress = System.currentTimeMillis());
543 System.out.println("CMD [-open " + file + "] executed successfully!");
545 if (!Platform.isJS())
547 * ignore in JavaScript -- can't just file existence - could load it?
552 if (!HttpUtils.startsWithHttpOrHttps(file))
554 if (!(new File(file)).exists())
556 System.out.println("Can't find " + file);
565 protocol = AppletFormatAdapter.checkProtocol(file);
569 format = new IdentifyFile().identify(file, protocol);
570 } catch (FileFormatException e1)
575 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
579 System.out.println("error");
583 setCurrentAlignFrame(af);
584 data = aparser.getValue("colour", true);
587 data.replaceAll("%20", " ");
589 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
590 af.getViewport(), af.getViewport().getAlignment(), data);
595 "CMD [-color " + data + "] executed successfully!");
600 // Must maintain ability to use the groups flag
601 data = aparser.getValue("groups", true);
604 af.parseFeaturesFile(data,
605 AppletFormatAdapter.checkProtocol(data));
606 // System.out.println("Added " + data);
608 "CMD groups[-" + data + "] executed successfully!");
610 data = aparser.getValue("features", true);
613 af.parseFeaturesFile(data,
614 AppletFormatAdapter.checkProtocol(data));
615 // System.out.println("Added " + data);
617 "CMD [-features " + data + "] executed successfully!");
620 data = aparser.getValue("annotations", true);
623 af.loadJalviewDataFile(data, null, null, null);
624 // System.out.println("Added " + data);
626 "CMD [-annotations " + data + "] executed successfully!");
628 // set or clear the sortbytree flag.
629 if (aparser.contains("sortbytree"))
631 af.getViewport().setSortByTree(true);
632 if (af.getViewport().getSortByTree())
634 System.out.println("CMD [-sortbytree] executed successfully!");
637 if (aparser.contains("no-annotation"))
639 af.getViewport().setShowAnnotation(false);
640 if (!af.getViewport().isShowAnnotation())
642 System.out.println("CMD no-annotation executed successfully!");
645 if (aparser.contains("nosortbytree"))
647 af.getViewport().setSortByTree(false);
648 if (!af.getViewport().getSortByTree())
651 .println("CMD [-nosortbytree] executed successfully!");
654 data = aparser.getValue("tree", true);
660 "CMD [-tree " + data + "] executed successfully!");
661 NewickFile nf = new NewickFile(data,
662 AppletFormatAdapter.checkProtocol(data));
664 .setCurrentTree(af.showNewickTree(nf, data).getTree());
665 } catch (IOException ex)
667 System.err.println("Couldn't add tree " + data);
668 ex.printStackTrace(System.err);
671 // TODO - load PDB structure(s) to alignment JAL-629
672 // (associate with identical sequence in alignment, or a specified
674 if (groovyscript != null)
676 // Execute the groovy script after we've done all the rendering stuff
677 // and before any images or figures are generated.
678 System.out.println("Executing script " + groovyscript);
679 executeGroovyScript(groovyscript, af);
680 System.out.println("CMD groovy[" + groovyscript
681 + "] executed successfully!");
684 String imageName = "unnamed.png";
685 while (aparser.getSize() > 1)
687 String outputFormat = aparser.nextValue();
688 file = aparser.nextValue();
690 if (outputFormat.equalsIgnoreCase("png"))
692 af.createPNG(new File(file));
693 imageName = (new File(file)).getName();
694 System.out.println("Creating PNG image: " + file);
697 else if (outputFormat.equalsIgnoreCase("svg"))
699 File imageFile = new File(file);
700 imageName = imageFile.getName();
701 af.createSVG(imageFile);
702 System.out.println("Creating SVG image: " + file);
705 else if (outputFormat.equalsIgnoreCase("html"))
707 File imageFile = new File(file);
708 imageName = imageFile.getName();
709 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
710 htmlSVG.exportHTML(file);
712 System.out.println("Creating HTML image: " + file);
715 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
719 System.err.println("The output html file must not be null");
724 BioJsHTMLOutput.refreshVersionInfo(
725 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
726 } catch (URISyntaxException e)
730 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
731 bjs.exportHTML(file);
733 .println("Creating BioJS MSA Viwer HTML file: " + file);
736 else if (outputFormat.equalsIgnoreCase("imgMap"))
738 af.createImageMap(new File(file), imageName);
739 System.out.println("Creating image map: " + file);
742 else if (outputFormat.equalsIgnoreCase("eps"))
744 File outputFile = new File(file);
746 "Creating EPS file: " + outputFile.getAbsolutePath());
747 af.createEPS(outputFile);
750 FileFormatI outFormat = null;
753 outFormat = FileFormats.getInstance().forName(outputFormat);
754 } catch (Exception formatP)
756 System.out.println("Couldn't parse " + outFormat
757 + " as a valid Jalview format string.");
759 if (outFormat != null)
761 if (!outFormat.isWritable())
764 "This version of Jalview does not support alignment export as "
769 af.saveAlignment(file, outFormat);
770 if (af.isSaveAlignmentSuccessful())
772 System.out.println("Written alignment in "
773 + outFormat.getName() + " format to " + file);
777 System.out.println("Error writing file " + file + " in "
778 + outFormat.getName() + " format!!");
785 while (aparser.getSize() > 0)
787 System.out.println("Unknown arg: " + aparser.nextValue());
791 AlignFrame startUpAlframe = null;
792 // We'll only open the default file if the desktop is visible.
794 // ////////////////////
796 if (!Platform.isJS() && !headless && file == null
797 && Cache.getDefault("SHOW_STARTUP_FILE", true))
804 file = Cache.getDefault("STARTUP_FILE",
805 Cache.getDefault("www.jalview.org", "https://www.jalview.org")
806 + "/examples/exampleFile_2_7.jvp");
807 if (file.equals("http://www.jalview.org/examples/exampleFile_2_3.jar")
809 "http://www.jalview.org/examples/exampleFile_2_7.jar"))
811 file.replace("http:", "https:");
812 // hardwire upgrade of the startup file
813 file.replace("_2_3", "_2_7");
814 file.replace("2_7.jar", "2_7.jvp");
815 // and remove the stale setting
816 Cache.removeProperty("STARTUP_FILE");
819 protocol = AppletFormatAdapter.checkProtocol(file);
821 if (file.endsWith(".jar"))
823 format = FileFormat.Jalview;
829 format = new IdentifyFile().identify(file, protocol);
830 } catch (FileFormatException e)
836 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
838 // extract groovy arguments before anything else.
841 // Once all other stuff is done, execute any groovy scripts (in order)
842 if (groovyscript != null)
844 if (Cache.groovyJarsPresent())
846 System.out.println("Executing script " + groovyscript);
847 executeGroovyScript(groovyscript, startUpAlframe);
852 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
856 // and finally, turn off batch mode indicator - if the desktop still exists
861 desktop.setProgressBar(null, progress);
863 desktop.setInBatchMode(false);
867 private static void setLookAndFeel()
869 // property laf = "crossplatform", "system", "gtk", "metal", "nimbus",
871 // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
873 String lafProp = System.getProperty("laf");
874 String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
880 else if (lafSetting != null)
884 boolean lafSet = false;
887 case "crossplatform":
888 lafSet = setCrossPlatformLookAndFeel();
891 Console.error("Could not set requested laf=" + laf);
895 lafSet = setSystemLookAndFeel();
898 Console.error("Could not set requested laf=" + laf);
902 lafSet = setGtkLookAndFeel();
905 Console.error("Could not set requested laf=" + laf);
909 lafSet = setMetalLookAndFeel();
912 Console.error("Could not set requested laf=" + laf);
916 lafSet = setNimbusLookAndFeel();
919 Console.error("Could not set requested laf=" + laf);
923 lafSet = setFlatLookAndFeel();
926 Console.error("Could not set requested laf=" + laf);
930 lafSet = setQuaquaLookAndFeel();
933 Console.error("Could not set requested laf=" + laf);
937 lafSet = setVaquaLookAndFeel();
940 Console.error("Could not set requested laf=" + laf);
944 lafSet = setMacLookAndFeel();
947 Console.error("Could not set requested laf=" + laf);
953 Console.error("Requested laf=" + laf + " not implemented");
957 setSystemLookAndFeel();
958 if (Platform.isLinux())
960 setMetalLookAndFeel();
962 if (Platform.isMac())
969 private static boolean setCrossPlatformLookAndFeel()
974 UIManager.setLookAndFeel(
975 UIManager.getCrossPlatformLookAndFeelClassName());
977 } catch (Exception ex)
979 Console.error("Unexpected Look and Feel Exception");
980 Console.error(ex.getMessage());
981 Console.debug(Cache.getStackTraceString(ex));
986 private static boolean setSystemLookAndFeel()
991 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
993 } catch (Exception ex)
995 Console.error("Unexpected Look and Feel Exception");
996 Console.error(ex.getMessage());
997 Console.debug(Cache.getStackTraceString(ex));
1002 private static boolean setSpecificLookAndFeel(String name,
1003 String className, boolean nameStartsWith)
1005 boolean set = false;
1008 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
1010 if (info.getName() != null && nameStartsWith
1011 ? info.getName().toLowerCase(Locale.ROOT)
1012 .startsWith(name.toLowerCase(Locale.ROOT))
1013 : info.getName().toLowerCase(Locale.ROOT)
1014 .equals(name.toLowerCase(Locale.ROOT)))
1016 className = info.getClassName();
1020 UIManager.setLookAndFeel(className);
1022 } catch (Exception ex)
1024 Console.error("Unexpected Look and Feel Exception");
1025 Console.error(ex.getMessage());
1026 Console.debug(Cache.getStackTraceString(ex));
1031 private static boolean setGtkLookAndFeel()
1033 return setSpecificLookAndFeel("gtk",
1034 "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true);
1037 private static boolean setMetalLookAndFeel()
1039 return setSpecificLookAndFeel("metal",
1040 "javax.swing.plaf.metal.MetalLookAndFeel", false);
1043 private static boolean setNimbusLookAndFeel()
1045 return setSpecificLookAndFeel("nimbus",
1046 "javax.swing.plaf.nimbus.NimbusLookAndFeel", false);
1049 private static boolean setFlatLookAndFeel()
1051 boolean set = setSpecificLookAndFeel("flatlaf light",
1052 "com.formdev.flatlaf.FlatLightLaf", false);
1055 if (Platform.isMac())
1057 System.setProperty("apple.laf.useScreenMenuBar", "true");
1058 System.setProperty("apple.awt.application.name",
1059 ChannelProperties.getProperty("app_name"));
1060 System.setProperty("apple.awt.application.appearance", "system");
1061 if (SystemInfo.isMacFullWindowContentSupported
1062 && Desktop.desktop != null)
1064 Desktop.desktop.getRootPane()
1065 .putClientProperty("apple.awt.fullWindowContent", true);
1066 Desktop.desktop.getRootPane()
1067 .putClientProperty("apple.awt.transparentTitleBar", true);
1070 SwingUtilities.invokeLater(() -> {
1071 FlatLightLaf.setup();
1075 UIManager.put("TabbedPane.showTabSeparators", true);
1076 UIManager.put("TabbedPane.tabSeparatorsFullHeight", true);
1077 UIManager.put("TabbedPane.tabsOverlapBorder", true);
1078 // UIManager.put("TabbedPane.hasFullBorder", true);
1079 UIManager.put("TabbedPane.tabLayoutPolicy", "scroll");
1080 UIManager.put("TabbedPane.scrollButtonsPolicy", "asNeeded");
1081 UIManager.put("TabbedPane.smoothScrolling", true);
1082 UIManager.put("TabbedPane.tabWidthMode", "compact");
1083 UIManager.put("TabbedPane.selectedBackground", Color.white);
1088 private static boolean setQuaquaLookAndFeel()
1090 return setSpecificLookAndFeel("quaqua",
1091 ch.randelshofer.quaqua.QuaquaManager.getLookAndFeel().getClass()
1096 private static boolean setVaquaLookAndFeel()
1098 return setSpecificLookAndFeel("vaqua",
1099 "org.violetlib.aqua.AquaLookAndFeel", false);
1102 private static boolean setMacLookAndFeel()
1104 boolean set = false;
1105 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
1106 ChannelProperties.getProperty("app_name"));
1107 System.setProperty("apple.laf.useScreenMenuBar", "true");
1108 set = setQuaquaLookAndFeel();
1109 if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
1110 .toLowerCase(Locale.ROOT).contains("quaqua"))
1112 set = setVaquaLookAndFeel();
1117 private static void showUsage()
1120 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
1121 + "-nodisplay\tRun Jalview without User Interface.\n"
1122 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
1123 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
1124 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
1125 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
1126 + "-features FILE\tUse the given file to mark features on the alignment.\n"
1127 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
1128 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
1129 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
1130 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
1131 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
1132 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
1133 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
1134 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
1135 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
1136 + "-png FILE\tCreate PNG image FILE from alignment.\n"
1137 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
1138 + "-html FILE\tCreate HTML file from alignment.\n"
1139 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
1140 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
1141 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
1142 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
1143 + "-noquestionnaire\tTurn off questionnaire check.\n"
1144 + "-nonews\tTurn off check for Jalview news.\n"
1145 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
1146 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
1148 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
1149 // after all other properties files have been read\n\t
1150 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
1151 // passed in correctly)"
1152 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
1153 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
1154 + "-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"
1155 + "-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"
1156 + "-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"
1157 + "\n~Read documentation in Application or visit https://www.jalview.org for description of Features and Annotations file~\n\n");
1160 private static void startUsageStats(final Desktop desktop)
1163 * start a User Config prompt asking if we can log usage statistics.
1165 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
1166 "USAGESTATS", "Jalview Usage Statistics",
1167 "Do you want to help make Jalview better by enabling "
1168 + "the collection of usage statistics with Google Analytics ?"
1169 + "\n\n(you can enable or disable usage tracking in the preferences)",
1176 "Initialising googletracker for usage stats.");
1177 Cache.initGoogleTracker();
1178 Console.debug("Tracking enabled.");
1185 Console.debug("Not enabling Google Tracking.");
1188 desktop.addDialogThread(prompter);
1192 * Locate the given string as a file and pass it to the groovy interpreter.
1194 * @param groovyscript
1195 * the script to execute
1196 * @param jalviewContext
1197 * the Jalview Desktop object passed in to the groovy binding as the
1200 private void executeGroovyScript(String groovyscript, AlignFrame af)
1203 * for scripts contained in files
1210 if (groovyscript.trim().equals("STDIN"))
1212 // read from stdin into a tempfile and execute it
1215 tfile = File.createTempFile("jalview", "groovy");
1216 PrintWriter outfile = new PrintWriter(
1217 new OutputStreamWriter(new FileOutputStream(tfile)));
1218 BufferedReader br = new BufferedReader(
1219 new InputStreamReader(System.in));
1221 while ((line = br.readLine()) != null)
1223 outfile.write(line + "\n");
1229 } catch (Exception ex)
1231 System.err.println("Failed to read from STDIN into tempfile "
1232 + ((tfile == null) ? "(tempfile wasn't created)"
1233 : tfile.toString()));
1234 ex.printStackTrace();
1239 sfile = tfile.toURI().toURL();
1240 } catch (Exception x)
1243 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1245 x.printStackTrace();
1253 sfile = new URI(groovyscript).toURL();
1254 } catch (Exception x)
1256 tfile = new File(groovyscript);
1257 if (!tfile.exists())
1259 System.err.println("File '" + groovyscript + "' does not exist.");
1262 if (!tfile.canRead())
1264 System.err.println("File '" + groovyscript + "' cannot be read.");
1267 if (tfile.length() < 1)
1269 System.err.println("File '" + groovyscript + "' is empty.");
1274 sfile = tfile.getAbsoluteFile().toURI().toURL();
1275 } catch (Exception ex)
1277 System.err.println("Failed to create a file URL for "
1278 + tfile.getAbsoluteFile());
1285 Map<String, java.lang.Object> vbinding = new HashMap<>();
1286 vbinding.put("Jalview", this);
1289 vbinding.put("currentAlFrame", af);
1291 Binding gbinding = new Binding(vbinding);
1292 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1293 gse.run(sfile.toString(), gbinding);
1294 if ("STDIN".equals(groovyscript))
1296 // delete temp file that we made -
1297 // only if it was successfully executed
1300 } catch (Exception e)
1302 System.err.println("Exception Whilst trying to execute file " + sfile
1303 + " as a groovy script.");
1304 e.printStackTrace(System.err);
1309 public static boolean isHeadlessMode()
1311 String isheadless = System.getProperty("java.awt.headless");
1312 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1319 public AlignFrame[] getAlignFrames()
1321 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1322 : Desktop.getAlignFrames();
1327 * Quit method delegates to Desktop.quit - unless running in headless mode
1328 * when it just ends the JVM
1332 if (desktop != null)
1342 public static AlignFrame getCurrentAlignFrame()
1344 return Jalview.currentAlignFrame;
1347 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1349 Jalview.currentAlignFrame = currentAlignFrame;