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 groovy.lang.Binding;
71 import groovy.util.GroovyScriptEngine;
74 * Main class for Jalview Application <br>
76 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
79 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
80 * jalview.bin.Jalview jalview.bin.Jalview
82 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
83 * embellish '*' to e.g. '*.jar')
92 Platform.getURLCommandArguments();
95 // singleton instance of this class
97 private static Jalview instance;
99 private Desktop desktop;
101 public static AlignFrame currentAlignFrame;
105 if (!Platform.isJS())
112 // grab all the rights we can for the JVM
113 Policy.setPolicy(new Policy()
116 public PermissionCollection getPermissions(CodeSource codesource)
118 Permissions perms = new Permissions();
119 perms.add(new AllPermission());
124 public void refresh()
132 * keep track of feature fetching tasks.
140 * TODO: generalise to track all jalview events to orchestrate batch
144 private int queued = 0;
146 private int running = 0;
148 public FeatureFetcher()
153 public void addFetcher(final AlignFrame af,
154 final Vector<String> dasSources)
156 final long id = System.currentTimeMillis();
158 final FeatureFetcher us = this;
159 new Thread(new Runnable()
171 af.setProgressBar(MessageManager
172 .getString("status.das_features_being_retrived"), id);
173 af.featureSettings_actionPerformed(null);
174 af.setProgressBar(null, id);
183 public synchronized boolean allFinished()
185 return queued == 0 && running == 0;
190 public static Jalview getInstance()
196 * main class for Jalview application
199 * open <em>filename</em>
201 public static void main(String[] args)
203 // setLogging(); // BH - for event debugging in JavaScript
204 instance = new Jalview();
205 instance.doMain(args);
208 private static void logClass(String name)
210 // BH - for event debugging in JavaScript
211 ConsoleHandler consoleHandler = new ConsoleHandler();
212 consoleHandler.setLevel(Level.ALL);
213 Logger logger = Logger.getLogger(name);
214 logger.setLevel(Level.ALL);
215 logger.addHandler(consoleHandler);
218 @SuppressWarnings("unused")
219 private static void setLogging()
227 System.out.println("not in js");
230 // BH - for event debugging in JavaScript (Java mode only)
231 if (!Platform.isJS())
238 Logger.getLogger("").setLevel(Level.ALL);
239 logClass("java.awt.EventDispatchThread");
240 logClass("java.awt.EventQueue");
241 logClass("java.awt.Component");
242 logClass("java.awt.focus.Component");
243 logClass("java.awt.focus.DefaultKeyboardFocusManager");
254 void doMain(String[] args)
257 if (!Platform.isJS())
259 System.setSecurityManager(null);
263 .println("Java version: " + System.getProperty("java.version"));
264 System.out.println(System.getProperty("os.arch") + " "
265 + System.getProperty("os.name") + " "
266 + System.getProperty("os.version"));
268 ArgsParser aparser = new ArgsParser(args);
269 boolean headless = false;
271 String usrPropsFile = aparser.getValue("props");
272 Cache.loadProperties(usrPropsFile); // must do this before
273 if (usrPropsFile != null)
276 "CMD [-props " + usrPropsFile + "] executed successfully!");
279 if (!Platform.isJS())
286 if (aparser.contains("help") || aparser.contains("h"))
291 if (aparser.contains("nodisplay") || aparser.contains("nogui")
292 || aparser.contains("headless"))
294 System.setProperty("java.awt.headless", "true");
299 final String jabawsUrl = aparser.getValue("jabaws");
300 if (jabawsUrl != null)
304 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
306 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
307 } catch (MalformedURLException e)
310 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
315 String defs = aparser.getValue("setprop");
318 int p = defs.indexOf('=');
321 System.err.println("Ignoring invalid setprop argument : " + defs);
325 System.out.println("Executing setprop argument: " + defs);
328 Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
331 defs = aparser.getValue("setprop");
333 if (System.getProperty("java.awt.headless") != null
334 && System.getProperty("java.awt.headless").equals("true"))
338 System.setProperty("http.agent",
339 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
343 } catch (NoClassDefFoundError error)
345 error.printStackTrace();
346 System.out.println("\nEssential logging libraries not found."
347 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
355 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
356 } catch (Exception ex)
358 System.err.println("Unexpected Look and Feel Exception");
359 ex.printStackTrace();
361 if (Platform.isAMacAndNotJS())
364 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
366 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
368 System.setProperty("apple.laf.useScreenMenuBar", "true");
369 if (lookAndFeel != null)
373 UIManager.setLookAndFeel(lookAndFeel);
374 } catch (Throwable e)
377 "Failed to set QuaQua look and feel: " + e.toString());
380 if (lookAndFeel == null || !(lookAndFeel.getClass()
381 .isAssignableFrom(UIManager.getLookAndFeel().getClass()))
382 || !UIManager.getLookAndFeel().getClass().toString()
383 .toLowerCase().contains("quaqua"))
388 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
389 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
390 } catch (Throwable e)
393 "Failed to reset look and feel: " + e.toString());
399 * configure 'full' SO model if preferences say to,
400 * else use the default (SO Lite)
402 if (Cache.getDefault("USE_FULL_SO", false))
404 SequenceOntologyFactory.setInstance(new SequenceOntology());
409 desktop = new Desktop()
413 // protected void processEvent(AWTEvent e) {
414 // System.out.println("Jalview.java " + e);
415 // super.processEvent(e);
419 desktop.setInBatchMode(true); // indicate we are starting up
420 desktop.setVisible(true);
422 if (!Platform.isJS())
429 desktop.startServiceDiscovery();
430 if (!aparser.contains("nousagestats"))
432 startUsageStats(desktop);
436 System.err.println("CMD [-nousagestats] executed successfully!");
439 if (!aparser.contains("noquestionnaire"))
441 String url = aparser.getValue("questionnaire");
444 // Start the desktop questionnaire prompter with the specified
446 Cache.log.debug("Starting questionnaire url at " + url);
447 desktop.checkForQuestionnaire(url);
448 System.out.println("CMD questionnaire[-" + url
449 + "] executed successfully!");
453 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
455 // Start the desktop questionnaire prompter with the specified
458 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
460 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
462 "Starting questionnaire with default url: " + defurl);
463 desktop.checkForQuestionnaire(defurl);
470 .println("CMD [-noquestionnaire] executed successfully!");
473 if (!aparser.contains("nonews"))
475 desktop.checkForNews();
478 BioJsHTMLOutput.updateBioJS();
482 String file = null, data = null;
483 FileFormatI format = null;
484 DataSourceType protocol = null;
485 FileLoader fileLoader = new FileLoader(!headless);
487 String groovyscript = null; // script to execute after all loading is
488 // completed one way or another
489 // extract groovy argument and execute if necessary
490 groovyscript = aparser.getValue("groovy", true);
491 file = aparser.getValue("open", true);
493 if (file == null && desktop == null)
495 System.out.println("No files to open!");
498 String vamsasImport = aparser.getValue("vdoc");
499 String vamsasSession = aparser.getValue("vsess");
500 if (vamsasImport != null || vamsasSession != null)
502 if (desktop == null || headless)
505 "Headless vamsas sessions not yet supported. Sorry.");
508 // if we have a file, start a new session and import it.
509 boolean inSession = false;
510 if (vamsasImport != null)
514 DataSourceType viprotocol = AppletFormatAdapter
515 .checkProtocol(vamsasImport);
516 if (viprotocol == DataSourceType.FILE)
518 inSession = desktop.vamsasImport(new File(vamsasImport));
520 else if (viprotocol == DataSourceType.URL)
522 inSession = desktop.vamsasImport(new URL(vamsasImport));
525 } catch (Exception e)
527 System.err.println("Exeption when importing " + vamsasImport
528 + " as a vamsas document.");
533 System.err.println("Failed to import " + vamsasImport
534 + " as a vamsas document.");
538 System.out.println("Imported Successfully into new session "
539 + desktop.getVamsasApplication().getCurrentSession());
542 if (vamsasSession != null)
544 if (vamsasImport != null)
546 // close the newly imported session and import the Jalview specific
547 // remnants into the new session later on.
548 desktop.vamsasStop_actionPerformed(null);
550 // now join the new session
553 if (desktop.joinVamsasSession(vamsasSession))
556 "Successfully joined vamsas session " + vamsasSession);
560 System.err.println("WARNING: Failed to join vamsas session "
563 } catch (Exception e)
566 "ERROR: Failed to join vamsas session " + vamsasSession);
569 if (vamsasImport != null)
571 // the Jalview specific remnants can now be imported into the new
572 // session at the user's leisure.
574 "Skipping Push for import of data into existing vamsas session."); // TODO:
579 // desktop.getVamsasApplication().push_update();
584 // Finally, deal with the remaining input data.
589 desktop.setProgressBar(
591 .getString("status.processing_commandline_args"),
592 progress = System.currentTimeMillis());
594 System.out.println("CMD [-open " + file + "] executed successfully!");
596 if (!Platform.isJS())
598 * ignore in JavaScript -- can't just file existence - could load it?
603 if (!file.startsWith("http://") && !file.startsWith("https://"))
604 // BH 2019 added https check for Java
606 if (!(new File(file)).exists())
608 System.out.println("Can't find " + file);
617 protocol = AppletFormatAdapter.checkProtocol(file);
621 format = new IdentifyFile().identify(file, protocol);
622 } catch (FileFormatException e1)
627 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
631 System.out.println("error");
635 setCurrentAlignFrame(af);
636 data = aparser.getValue("colour", true);
639 data.replaceAll("%20", " ");
641 ColourSchemeI cs = ColourSchemeProperty
642 .getColourScheme(af.getViewport(),
643 af.getViewport().getAlignment(), data);
648 "CMD [-color " + data + "] executed successfully!");
653 // Must maintain ability to use the groups flag
654 data = aparser.getValue("groups", true);
657 af.parseFeaturesFile(data,
658 AppletFormatAdapter.checkProtocol(data));
659 // System.out.println("Added " + data);
661 "CMD groups[-" + data + "] executed successfully!");
663 data = aparser.getValue("features", true);
666 af.parseFeaturesFile(data,
667 AppletFormatAdapter.checkProtocol(data));
668 // System.out.println("Added " + data);
670 "CMD [-features " + data + "] executed successfully!");
673 data = aparser.getValue("annotations", true);
676 af.loadJalviewDataFile(data, null, null, null);
677 // System.out.println("Added " + data);
679 "CMD [-annotations " + data + "] executed successfully!");
681 // set or clear the sortbytree flag.
682 if (aparser.contains("sortbytree"))
684 af.getViewport().setSortByTree(true);
685 if (af.getViewport().getSortByTree())
687 System.out.println("CMD [-sortbytree] executed successfully!");
690 if (aparser.contains("no-annotation"))
692 af.getViewport().setShowAnnotation(false);
693 if (!af.getViewport().isShowAnnotation())
695 System.out.println("CMD no-annotation executed successfully!");
698 if (aparser.contains("nosortbytree"))
700 af.getViewport().setSortByTree(false);
701 if (!af.getViewport().getSortByTree())
704 .println("CMD [-nosortbytree] executed successfully!");
707 data = aparser.getValue("tree", true);
713 "CMD [-tree " + data + "] executed successfully!");
714 NewickFile nf = new NewickFile(data,
715 AppletFormatAdapter.checkProtocol(data));
717 .setCurrentTree(af.showNewickTree(nf, data).getTree());
718 } catch (IOException ex)
720 System.err.println("Couldn't add tree " + data);
721 ex.printStackTrace(System.err);
724 // TODO - load PDB structure(s) to alignment JAL-629
725 // (associate with identical sequence in alignment, or a specified
727 if (groovyscript != null)
729 // Execute the groovy script after we've done all the rendering stuff
730 // and before any images or figures are generated.
731 System.out.println("Executing script " + groovyscript);
732 executeGroovyScript(groovyscript, af);
733 System.out.println("CMD groovy[" + groovyscript
734 + "] executed successfully!");
737 String imageName = "unnamed.png";
738 while (aparser.getSize() > 1)
740 String outputFormat = aparser.nextValue();
741 file = aparser.nextValue();
743 if (outputFormat.equalsIgnoreCase("png"))
745 af.createPNG(new File(file));
746 imageName = (new File(file)).getName();
747 System.out.println("Creating PNG image: " + file);
750 else if (outputFormat.equalsIgnoreCase("svg"))
752 File imageFile = new File(file);
753 imageName = imageFile.getName();
754 af.createSVG(imageFile);
755 System.out.println("Creating SVG image: " + file);
758 else if (outputFormat.equalsIgnoreCase("html"))
760 File imageFile = new File(file);
761 imageName = imageFile.getName();
762 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
763 htmlSVG.exportHTML(file);
765 System.out.println("Creating HTML image: " + file);
768 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
772 System.err.println("The output html file must not be null");
777 BioJsHTMLOutput.refreshVersionInfo(
778 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
779 } catch (URISyntaxException e)
783 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
784 bjs.exportHTML(file);
786 .println("Creating BioJS MSA Viwer HTML file: " + file);
789 else if (outputFormat.equalsIgnoreCase("imgMap"))
791 af.createImageMap(new File(file), imageName);
792 System.out.println("Creating image map: " + file);
795 else if (outputFormat.equalsIgnoreCase("eps"))
797 File outputFile = new File(file);
799 "Creating EPS file: " + outputFile.getAbsolutePath());
800 af.createEPS(outputFile);
804 af.saveAlignment(file, format);
805 if (af.isSaveAlignmentSuccessful())
807 System.out.println("Written alignment in " + format
808 + " format to " + file);
812 System.out.println("Error writing file " + file + " in "
813 + format + " format!!");
818 while (aparser.getSize() > 0)
820 System.out.println("Unknown arg: " + aparser.nextValue());
824 AlignFrame startUpAlframe = null;
825 // We'll only open the default file if the desktop is visible.
827 // ////////////////////
829 if (!Platform.isJS() && !headless && file == null
830 && vamsasImport == null
831 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
838 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
839 jalview.bin.Cache.getDefault("www.jalview.org",
840 "http://www.jalview.org")
841 + "/examples/exampleFile_2_7.jar");
843 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
845 // hardwire upgrade of the startup file
846 file.replace("_2_3.jar", "_2_7.jar");
847 // and remove the stale setting
848 jalview.bin.Cache.removeProperty("STARTUP_FILE");
851 protocol = DataSourceType.FILE;
853 if (file.indexOf("http:") > -1)
855 protocol = DataSourceType.URL;
858 if (file.endsWith(".jar"))
860 format = FileFormat.Jalview;
866 format = new IdentifyFile().identify(file, protocol);
867 } catch (FileFormatException e)
873 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
875 // extract groovy arguments before anything else.
878 // Once all other stuff is done, execute any groovy scripts (in order)
879 if (groovyscript != null)
881 if (Cache.groovyJarsPresent())
883 System.out.println("Executing script " + groovyscript);
884 executeGroovyScript(groovyscript, startUpAlframe);
889 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
893 // and finally, turn off batch mode indicator - if the desktop still exists
898 desktop.setProgressBar(null, progress);
900 desktop.setInBatchMode(false);
904 private static void showUsage()
907 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
908 + "-nodisplay\tRun Jalview without User Interface.\n"
909 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
910 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
911 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
912 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
913 + "-features FILE\tUse the given file to mark features on the alignment.\n"
914 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
915 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
916 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
917 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
918 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
919 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
920 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
921 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
922 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
923 + "-png FILE\tCreate PNG image FILE from alignment.\n"
924 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
925 + "-html FILE\tCreate HTML file from alignment.\n"
926 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
927 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
928 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
929 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
930 + "-noquestionnaire\tTurn off questionnaire check.\n"
931 + "-nonews\tTurn off check for Jalview news.\n"
932 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
933 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
935 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
936 // after all other properties files have been read\n\t
937 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
938 // passed in correctly)"
939 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
940 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
942 // "-vdoc vamsas-document\tImport vamsas document into new
943 // session or join existing session with same URN\n"
944 // + "-vses vamsas-session\tJoin session with given URN\n"
945 + "-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"
946 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
949 private static void startUsageStats(final Desktop desktop)
952 * start a User Config prompt asking if we can log usage statistics.
954 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
955 "USAGESTATS", "Jalview Usage Statistics",
956 "Do you want to help make Jalview better by enabling "
957 + "the collection of usage statistics with Google Analytics ?"
958 + "\n\n(you can enable or disable usage tracking in the preferences)",
965 "Initialising googletracker for usage stats.");
966 Cache.initGoogleTracker();
967 Cache.log.debug("Tracking enabled.");
974 Cache.log.debug("Not enabling Google Tracking.");
977 desktop.addDialogThread(prompter);
981 * Locate the given string as a file and pass it to the groovy interpreter.
983 * @param groovyscript
984 * the script to execute
985 * @param jalviewContext
986 * the Jalview Desktop object passed in to the groovy binding as the
989 private void executeGroovyScript(String groovyscript, AlignFrame af)
992 * for scripts contained in files
999 if (groovyscript.trim().equals("STDIN"))
1001 // read from stdin into a tempfile and execute it
1004 tfile = File.createTempFile("jalview", "groovy");
1005 PrintWriter outfile = new PrintWriter(
1006 new OutputStreamWriter(new FileOutputStream(tfile)));
1007 BufferedReader br = new BufferedReader(
1008 new InputStreamReader(System.in));
1010 while ((line = br.readLine()) != null)
1012 outfile.write(line + "\n");
1018 } catch (Exception ex)
1020 System.err.println("Failed to read from STDIN into tempfile "
1021 + ((tfile == null) ? "(tempfile wasn't created)"
1022 : tfile.toString()));
1023 ex.printStackTrace();
1028 sfile = tfile.toURI().toURL();
1029 } catch (Exception x)
1032 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1034 x.printStackTrace();
1042 sfile = new URI(groovyscript).toURL();
1043 } catch (Exception x)
1045 tfile = new File(groovyscript);
1046 if (!tfile.exists())
1048 System.err.println("File '" + groovyscript + "' does not exist.");
1051 if (!tfile.canRead())
1053 System.err.println("File '" + groovyscript + "' cannot be read.");
1056 if (tfile.length() < 1)
1058 System.err.println("File '" + groovyscript + "' is empty.");
1063 sfile = tfile.getAbsoluteFile().toURI().toURL();
1064 } catch (Exception ex)
1066 System.err.println("Failed to create a file URL for "
1067 + tfile.getAbsoluteFile());
1074 Map<String, Object> vbinding = new HashMap<>();
1075 vbinding.put("Jalview", this);
1078 vbinding.put("currentAlFrame", af);
1080 Binding gbinding = new Binding(vbinding);
1081 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1082 gse.run(sfile.toString(), gbinding);
1083 if ("STDIN".equals(groovyscript))
1085 // delete temp file that we made -
1086 // only if it was successfully executed
1089 } catch (Exception e)
1091 System.err.println("Exception Whilst trying to execute file " + sfile
1092 + " as a groovy script.");
1093 e.printStackTrace(System.err);
1098 public static boolean isHeadlessMode()
1100 String isheadless = System.getProperty("java.awt.headless");
1101 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1108 public AlignFrame[] getAlignFrames()
1110 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1111 : Desktop.getAlignFrames();
1116 * Quit method delegates to Desktop.quit - unless running in headless mode
1117 * when it just ends the JVM
1121 if (desktop != null)
1131 public static AlignFrame getCurrentAlignFrame()
1133 return Jalview.currentAlignFrame;
1136 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1138 Jalview.currentAlignFrame = currentAlignFrame;