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 jalview.ext.so.SequenceOntology;
24 import jalview.gui.AlignFrame;
25 import jalview.gui.Desktop;
26 import jalview.gui.PromptUserConfig;
27 import jalview.io.AppletFormatAdapter;
28 import jalview.io.BioJsHTMLOutput;
29 import jalview.io.DataSourceType;
30 import jalview.io.FileFormat;
31 import jalview.io.FileFormatException;
32 import jalview.io.FileFormatI;
33 import jalview.io.FileLoader;
34 import jalview.io.HtmlSvgOutput;
35 import jalview.io.IdentifyFile;
36 import jalview.io.NewickFile;
37 import jalview.io.gff.SequenceOntologyFactory;
38 import jalview.schemes.ColourSchemeI;
39 import jalview.schemes.ColourSchemeProperty;
40 import jalview.util.MessageManager;
41 import jalview.util.Platform;
42 import jalview.ws.jws2.Jws2Discoverer;
44 import java.io.BufferedReader;
46 import java.io.FileOutputStream;
47 import java.io.IOException;
48 import java.io.InputStreamReader;
49 import java.io.OutputStreamWriter;
50 import java.io.PrintWriter;
51 import java.net.MalformedURLException;
53 import java.net.URISyntaxException;
55 import java.security.AllPermission;
56 import java.security.CodeSource;
57 import java.security.PermissionCollection;
58 import java.security.Permissions;
59 import java.security.Policy;
60 import java.util.HashMap;
62 import java.util.Vector;
63 import java.util.logging.ConsoleHandler;
64 import java.util.logging.Level;
65 import java.util.logging.Logger;
67 import javax.swing.LookAndFeel;
68 import javax.swing.UIManager;
70 import com.threerings.getdown.util.LaunchUtil;
72 import groovy.lang.Binding;
73 import groovy.util.GroovyScriptEngine;
76 * Main class for Jalview Application <br>
78 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
81 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
82 * jalview.bin.Jalview jalview.bin.Jalview
84 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
85 * embellish '*' to e.g. '*.jar')
94 Platform.getURLCommandArguments();
97 // singleton instance of this class
99 private static Jalview instance;
101 private Desktop desktop;
103 public static AlignFrame currentAlignFrame;
107 if (!Platform.isJS())
114 // grab all the rights we can for the JVM
115 Policy.setPolicy(new Policy()
118 public PermissionCollection getPermissions(CodeSource codesource)
120 Permissions perms = new Permissions();
121 perms.add(new AllPermission());
126 public void refresh()
134 * keep track of feature fetching tasks.
142 * TODO: generalise to track all jalview events to orchestrate batch
146 private int queued = 0;
148 private int running = 0;
150 public FeatureFetcher()
155 public void addFetcher(final AlignFrame af,
156 final Vector<String> dasSources)
158 final long id = System.currentTimeMillis();
160 final FeatureFetcher us = this;
161 new Thread(new Runnable()
173 af.setProgressBar(MessageManager
174 .getString("status.das_features_being_retrived"), id);
175 af.featureSettings_actionPerformed(null);
176 af.setProgressBar(null, id);
185 public synchronized boolean allFinished()
187 return queued == 0 && running == 0;
192 public static Jalview getInstance()
198 * main class for Jalview application
201 * open <em>filename</em>
203 public static void main(String[] args)
205 // setLogging(); // BH - for event debugging in JavaScript
206 instance = new Jalview();
207 instance.doMain(args);
210 private static void logClass(String name)
212 // BH - for event debugging in JavaScript
213 ConsoleHandler consoleHandler = new ConsoleHandler();
214 consoleHandler.setLevel(Level.ALL);
215 Logger logger = Logger.getLogger(name);
216 logger.setLevel(Level.ALL);
217 logger.addHandler(consoleHandler);
220 @SuppressWarnings("unused")
221 private static void setLogging()
229 System.out.println("not in js");
232 // BH - for event debugging in JavaScript (Java mode only)
233 if (!Platform.isJS())
240 Logger.getLogger("").setLevel(Level.ALL);
241 logClass("java.awt.EventDispatchThread");
242 logClass("java.awt.EventQueue");
243 logClass("java.awt.Component");
244 logClass("java.awt.focus.Component");
245 logClass("java.awt.focus.DefaultKeyboardFocusManager");
256 void doMain(String[] args)
259 if (!Platform.isJS())
261 System.setSecurityManager(null);
265 .println("Java version: " + System.getProperty("java.version"));
266 System.out.println(System.getProperty("os.arch") + " "
267 + System.getProperty("os.name") + " "
268 + System.getProperty("os.version"));
270 String appdirString = System.getProperty("getdownappdir");
271 if (appdirString != null && appdirString.length() > 0)
273 final File appdir = new File(appdirString);
279 LaunchUtil.upgradeGetdown(
280 new File(appdir, "getdown-launcher-old.jar"),
281 new File(appdir, "getdown-launcher.jar"),
282 new File(appdir, "getdown-launcher-new.jar"));
287 ArgsParser aparser = new ArgsParser(args);
288 boolean headless = false;
290 String usrPropsFile = aparser.getValue("props");
291 Cache.loadProperties(usrPropsFile); // must do this before
292 if (usrPropsFile != null)
295 "CMD [-props " + usrPropsFile + "] executed successfully!");
298 if (!Platform.isJS())
305 if (aparser.contains("help") || aparser.contains("h"))
310 if (aparser.contains("nodisplay") || aparser.contains("nogui")
311 || aparser.contains("headless"))
313 System.setProperty("java.awt.headless", "true");
318 final String jabawsUrl = aparser.getValue("jabaws");
319 if (jabawsUrl != null)
323 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
325 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
326 } catch (MalformedURLException e)
329 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
334 String defs = aparser.getValue("setprop");
337 int p = defs.indexOf('=');
340 System.err.println("Ignoring invalid setprop argument : " + defs);
344 System.out.println("Executing setprop argument: " + defs);
347 Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
350 defs = aparser.getValue("setprop");
352 if (System.getProperty("java.awt.headless") != null
353 && System.getProperty("java.awt.headless").equals("true"))
357 System.setProperty("http.agent",
358 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
362 } catch (NoClassDefFoundError error)
364 error.printStackTrace();
365 System.out.println("\nEssential logging libraries not found."
366 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
374 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
375 } catch (Exception ex)
377 System.err.println("Unexpected Look and Feel Exception");
378 ex.printStackTrace();
380 if (Platform.isAMacAndNotJS())
383 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
385 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
387 System.setProperty("apple.laf.useScreenMenuBar", "true");
388 if (lookAndFeel != null)
392 UIManager.setLookAndFeel(lookAndFeel);
393 } catch (Throwable e)
396 "Failed to set QuaQua look and feel: " + e.toString());
399 if (lookAndFeel == null || !(lookAndFeel.getClass()
400 .isAssignableFrom(UIManager.getLookAndFeel().getClass()))
401 || !UIManager.getLookAndFeel().getClass().toString()
402 .toLowerCase().contains("quaqua"))
407 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
408 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
409 } catch (Throwable e)
412 "Failed to reset look and feel: " + e.toString());
418 * configure 'full' SO model if preferences say to,
419 * else use the default (SO Lite)
421 if (Cache.getDefault("USE_FULL_SO", false))
423 SequenceOntologyFactory.setInstance(new SequenceOntology());
428 desktop = new Desktop()
432 // protected void processEvent(AWTEvent e) {
433 // System.out.println("Jalview.java " + e);
434 // super.processEvent(e);
438 desktop.setInBatchMode(true); // indicate we are starting up
442 if (! Platform.isJS())
449 JalviewTaskbar.setTaskbar(this);
451 } catch (Exception e)
453 System.out.println("Cannot set Taskbar");
454 // e.printStackTrace();
455 } catch (Throwable t)
457 System.out.println("Cannot set Taskbar");
458 // t.printStackTrace();
461 desktop.setVisible(true);
463 if (!Platform.isJS())
470 desktop.startServiceDiscovery();
471 if (!aparser.contains("nousagestats"))
473 startUsageStats(desktop);
477 System.err.println("CMD [-nousagestats] executed successfully!");
480 if (!aparser.contains("noquestionnaire"))
482 String url = aparser.getValue("questionnaire");
485 // Start the desktop questionnaire prompter with the specified
487 Cache.log.debug("Starting questionnaire url at " + url);
488 desktop.checkForQuestionnaire(url);
489 System.out.println("CMD questionnaire[-" + url
490 + "] executed successfully!");
494 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
496 // Start the desktop questionnaire prompter with the specified
499 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
501 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
503 "Starting questionnaire with default url: " + defurl);
504 desktop.checkForQuestionnaire(defurl);
511 .println("CMD [-noquestionnaire] executed successfully!");
514 if (!aparser.contains("nonews"))
516 desktop.checkForNews();
519 BioJsHTMLOutput.updateBioJS();
523 String file = null, data = null;
524 FileFormatI format = null;
525 DataSourceType protocol = null;
526 FileLoader fileLoader = new FileLoader(!headless);
528 String groovyscript = null; // script to execute after all loading is
529 // completed one way or another
530 // extract groovy argument and execute if necessary
531 groovyscript = aparser.getValue("groovy", true);
532 file = aparser.getValue("open", true);
534 if (file == null && desktop == null)
536 System.out.println("No files to open!");
539 String vamsasImport = aparser.getValue("vdoc");
540 String vamsasSession = aparser.getValue("vsess");
541 if (vamsasImport != null || vamsasSession != null)
543 if (desktop == null || headless)
546 "Headless vamsas sessions not yet supported. Sorry.");
549 // if we have a file, start a new session and import it.
550 boolean inSession = false;
551 if (vamsasImport != null)
555 DataSourceType viprotocol = AppletFormatAdapter
556 .checkProtocol(vamsasImport);
557 if (viprotocol == DataSourceType.FILE)
559 inSession = desktop.vamsasImport(new File(vamsasImport));
561 else if (viprotocol == DataSourceType.URL)
563 inSession = desktop.vamsasImport(new URL(vamsasImport));
566 } catch (Exception e)
568 System.err.println("Exeption when importing " + vamsasImport
569 + " as a vamsas document.");
574 System.err.println("Failed to import " + vamsasImport
575 + " as a vamsas document.");
579 System.out.println("Imported Successfully into new session "
580 + desktop.getVamsasApplication().getCurrentSession());
583 if (vamsasSession != null)
585 if (vamsasImport != null)
587 // close the newly imported session and import the Jalview specific
588 // remnants into the new session later on.
589 desktop.vamsasStop_actionPerformed(null);
591 // now join the new session
594 if (desktop.joinVamsasSession(vamsasSession))
597 "Successfully joined vamsas session " + vamsasSession);
601 System.err.println("WARNING: Failed to join vamsas session "
604 } catch (Exception e)
607 "ERROR: Failed to join vamsas session " + vamsasSession);
610 if (vamsasImport != null)
612 // the Jalview specific remnants can now be imported into the new
613 // session at the user's leisure.
615 "Skipping Push for import of data into existing vamsas session."); // TODO:
620 // desktop.getVamsasApplication().push_update();
625 // Finally, deal with the remaining input data.
630 desktop.setProgressBar(
632 .getString("status.processing_commandline_args"),
633 progress = System.currentTimeMillis());
635 System.out.println("CMD [-open " + file + "] executed successfully!");
637 if (!Platform.isJS())
639 * ignore in JavaScript -- can't just file existence - could load it?
644 if (!file.startsWith("http://") && !file.startsWith("https://"))
645 // BH 2019 added https check for Java
647 if (!(new File(file)).exists())
649 System.out.println("Can't find " + file);
658 protocol = AppletFormatAdapter.checkProtocol(file);
662 format = new IdentifyFile().identify(file, protocol);
663 } catch (FileFormatException e1)
668 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
672 System.out.println("error");
676 setCurrentAlignFrame(af);
677 data = aparser.getValue("colour", true);
680 data.replaceAll("%20", " ");
682 ColourSchemeI cs = ColourSchemeProperty
683 .getColourScheme(af.getViewport(),
684 af.getViewport().getAlignment(), data);
689 "CMD [-color " + data + "] executed successfully!");
694 // Must maintain ability to use the groups flag
695 data = aparser.getValue("groups", true);
698 af.parseFeaturesFile(data,
699 AppletFormatAdapter.checkProtocol(data));
700 // System.out.println("Added " + data);
702 "CMD groups[-" + data + "] executed successfully!");
704 data = aparser.getValue("features", true);
707 af.parseFeaturesFile(data,
708 AppletFormatAdapter.checkProtocol(data));
709 // System.out.println("Added " + data);
711 "CMD [-features " + data + "] executed successfully!");
714 data = aparser.getValue("annotations", true);
717 af.loadJalviewDataFile(data, null, null, null);
718 // System.out.println("Added " + data);
720 "CMD [-annotations " + data + "] executed successfully!");
722 // set or clear the sortbytree flag.
723 if (aparser.contains("sortbytree"))
725 af.getViewport().setSortByTree(true);
726 if (af.getViewport().getSortByTree())
728 System.out.println("CMD [-sortbytree] executed successfully!");
731 if (aparser.contains("no-annotation"))
733 af.getViewport().setShowAnnotation(false);
734 if (!af.getViewport().isShowAnnotation())
736 System.out.println("CMD no-annotation executed successfully!");
739 if (aparser.contains("nosortbytree"))
741 af.getViewport().setSortByTree(false);
742 if (!af.getViewport().getSortByTree())
745 .println("CMD [-nosortbytree] executed successfully!");
748 data = aparser.getValue("tree", true);
754 "CMD [-tree " + data + "] executed successfully!");
755 NewickFile nf = new NewickFile(data,
756 AppletFormatAdapter.checkProtocol(data));
758 .setCurrentTree(af.showNewickTree(nf, data).getTree());
759 } catch (IOException ex)
761 System.err.println("Couldn't add tree " + data);
762 ex.printStackTrace(System.err);
765 // TODO - load PDB structure(s) to alignment JAL-629
766 // (associate with identical sequence in alignment, or a specified
768 if (groovyscript != null)
770 // Execute the groovy script after we've done all the rendering stuff
771 // and before any images or figures are generated.
772 System.out.println("Executing script " + groovyscript);
773 executeGroovyScript(groovyscript, af);
774 System.out.println("CMD groovy[" + groovyscript
775 + "] executed successfully!");
778 String imageName = "unnamed.png";
779 while (aparser.getSize() > 1)
781 String outputFormat = aparser.nextValue();
782 file = aparser.nextValue();
784 if (outputFormat.equalsIgnoreCase("png"))
786 af.createPNG(new File(file));
787 imageName = (new File(file)).getName();
788 System.out.println("Creating PNG image: " + file);
791 else if (outputFormat.equalsIgnoreCase("svg"))
793 File imageFile = new File(file);
794 imageName = imageFile.getName();
795 af.createSVG(imageFile);
796 System.out.println("Creating SVG image: " + file);
799 else if (outputFormat.equalsIgnoreCase("html"))
801 File imageFile = new File(file);
802 imageName = imageFile.getName();
803 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
804 htmlSVG.exportHTML(file);
806 System.out.println("Creating HTML image: " + file);
809 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
813 System.err.println("The output html file must not be null");
818 BioJsHTMLOutput.refreshVersionInfo(
819 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
820 } catch (URISyntaxException e)
824 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
825 bjs.exportHTML(file);
827 .println("Creating BioJS MSA Viwer HTML file: " + file);
830 else if (outputFormat.equalsIgnoreCase("imgMap"))
832 af.createImageMap(new File(file), imageName);
833 System.out.println("Creating image map: " + file);
836 else if (outputFormat.equalsIgnoreCase("eps"))
838 File outputFile = new File(file);
840 "Creating EPS file: " + outputFile.getAbsolutePath());
841 af.createEPS(outputFile);
845 af.saveAlignment(file, format);
846 if (af.isSaveAlignmentSuccessful())
848 System.out.println("Written alignment in " + format
849 + " format to " + file);
853 System.out.println("Error writing file " + file + " in "
854 + format + " format!!");
859 while (aparser.getSize() > 0)
861 System.out.println("Unknown arg: " + aparser.nextValue());
865 AlignFrame startUpAlframe = null;
866 // We'll only open the default file if the desktop is visible.
868 // ////////////////////
870 if (!Platform.isJS() && !headless && file == null
871 && vamsasImport == null
872 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
879 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
880 jalview.bin.Cache.getDefault("www.jalview.org",
881 "http://www.jalview.org")
882 + "/examples/exampleFile_2_7.jar");
884 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
886 // hardwire upgrade of the startup file
887 file.replace("_2_3.jar", "_2_7.jar");
888 // and remove the stale setting
889 jalview.bin.Cache.removeProperty("STARTUP_FILE");
892 protocol = DataSourceType.FILE;
894 if (file.indexOf("http:") > -1)
896 protocol = DataSourceType.URL;
899 if (file.endsWith(".jar"))
901 format = FileFormat.Jalview;
907 format = new IdentifyFile().identify(file, protocol);
908 } catch (FileFormatException e)
914 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
916 // extract groovy arguments before anything else.
919 // Once all other stuff is done, execute any groovy scripts (in order)
920 if (groovyscript != null)
922 if (Cache.groovyJarsPresent())
924 System.out.println("Executing script " + groovyscript);
925 executeGroovyScript(groovyscript, startUpAlframe);
930 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
934 // and finally, turn off batch mode indicator - if the desktop still exists
939 desktop.setProgressBar(null, progress);
941 desktop.setInBatchMode(false);
945 private static void showUsage()
948 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
949 + "-nodisplay\tRun Jalview without User Interface.\n"
950 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
951 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
952 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
953 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
954 + "-features FILE\tUse the given file to mark features on the alignment.\n"
955 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
956 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
957 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
958 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
959 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
960 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
961 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
962 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
963 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
964 + "-png FILE\tCreate PNG image FILE from alignment.\n"
965 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
966 + "-html FILE\tCreate HTML file from alignment.\n"
967 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
968 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
969 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
970 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
971 + "-noquestionnaire\tTurn off questionnaire check.\n"
972 + "-nonews\tTurn off check for Jalview news.\n"
973 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
974 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
976 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
977 // after all other properties files have been read\n\t
978 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
979 // passed in correctly)"
980 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
981 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
983 // "-vdoc vamsas-document\tImport vamsas document into new
984 // session or join existing session with same URN\n"
985 // + "-vses vamsas-session\tJoin session with given URN\n"
986 + "-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"
987 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
990 private static void startUsageStats(final Desktop desktop)
993 * start a User Config prompt asking if we can log usage statistics.
995 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
996 "USAGESTATS", "Jalview Usage Statistics",
997 "Do you want to help make Jalview better by enabling "
998 + "the collection of usage statistics with Google Analytics ?"
999 + "\n\n(you can enable or disable usage tracking in the preferences)",
1006 "Initialising googletracker for usage stats.");
1007 Cache.initGoogleTracker();
1008 Cache.log.debug("Tracking enabled.");
1015 Cache.log.debug("Not enabling Google Tracking.");
1018 desktop.addDialogThread(prompter);
1022 * Locate the given string as a file and pass it to the groovy interpreter.
1024 * @param groovyscript
1025 * the script to execute
1026 * @param jalviewContext
1027 * the Jalview Desktop object passed in to the groovy binding as the
1030 private void executeGroovyScript(String groovyscript, AlignFrame af)
1033 * for scripts contained in files
1040 if (groovyscript.trim().equals("STDIN"))
1042 // read from stdin into a tempfile and execute it
1045 tfile = File.createTempFile("jalview", "groovy");
1046 PrintWriter outfile = new PrintWriter(
1047 new OutputStreamWriter(new FileOutputStream(tfile)));
1048 BufferedReader br = new BufferedReader(
1049 new InputStreamReader(System.in));
1051 while ((line = br.readLine()) != null)
1053 outfile.write(line + "\n");
1059 } catch (Exception ex)
1061 System.err.println("Failed to read from STDIN into tempfile "
1062 + ((tfile == null) ? "(tempfile wasn't created)"
1063 : tfile.toString()));
1064 ex.printStackTrace();
1069 sfile = tfile.toURI().toURL();
1070 } catch (Exception x)
1073 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1075 x.printStackTrace();
1083 sfile = new URI(groovyscript).toURL();
1084 } catch (Exception x)
1086 tfile = new File(groovyscript);
1087 if (!tfile.exists())
1089 System.err.println("File '" + groovyscript + "' does not exist.");
1092 if (!tfile.canRead())
1094 System.err.println("File '" + groovyscript + "' cannot be read.");
1097 if (tfile.length() < 1)
1099 System.err.println("File '" + groovyscript + "' is empty.");
1104 sfile = tfile.getAbsoluteFile().toURI().toURL();
1105 } catch (Exception ex)
1107 System.err.println("Failed to create a file URL for "
1108 + tfile.getAbsoluteFile());
1115 Map<String, java.lang.Object> vbinding = new HashMap<>();
1116 vbinding.put("Jalview", this);
1119 vbinding.put("currentAlFrame", af);
1121 Binding gbinding = new Binding(vbinding);
1122 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1123 gse.run(sfile.toString(), gbinding);
1124 if ("STDIN".equals(groovyscript))
1126 // delete temp file that we made -
1127 // only if it was successfully executed
1130 } catch (Exception e)
1132 System.err.println("Exception Whilst trying to execute file " + sfile
1133 + " as a groovy script.");
1134 e.printStackTrace(System.err);
1139 public static boolean isHeadlessMode()
1141 String isheadless = System.getProperty("java.awt.headless");
1142 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1149 public AlignFrame[] getAlignFrames()
1151 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1152 : Desktop.getAlignFrames();
1157 * Quit method delegates to Desktop.quit - unless running in headless mode
1158 * when it just ends the JVM
1162 if (desktop != null)
1172 public static AlignFrame getCurrentAlignFrame()
1174 return Jalview.currentAlignFrame;
1177 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1179 Jalview.currentAlignFrame = currentAlignFrame;