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 processing
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: "
266 + System.getProperty("java.version"));
267 System.out.println("Java Home: " + System.getProperty("java.home"));
268 System.out.println(System.getProperty("os.arch") + " "
269 + System.getProperty("os.name") + " "
270 + System.getProperty("os.version"));
271 String val = System.getProperty("sys.install4jVersion");
273 System.out.println("Install4j version: " + val);
275 val = System.getProperty("installer_template_version");
277 System.out.println("Install4j template version: " + val);
279 val = System.getProperty("launcher_version");
281 System.out.println("Launcher version: " + val);
284 // report Jalview version
285 Cache.loadBuildProperties(true);
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");
372 // property laf = "crossplatform", "system" or "mac"
373 // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac, try Quaqua/Vaqua.
374 String laf = System.getProperty("laf","none");
375 boolean lafSet = false;
377 case "crossplatform":
378 lafSet = setCrossPlatformLookAndFeel();
381 System.err.println("Could not set requested laf="+laf);
385 lafSet = setSystemLookAndFeel();
388 System.err.println("Could not set requested laf="+laf);
392 lafSet = setMacLookAndFeel();
395 System.err.println("Could not set requested laf="+laf);
401 System.err.println("Requested laf="+laf+" not implemented");
405 setSystemLookAndFeel();
406 if (Platform.isAMacAndNotJS())
413 * configure 'full' SO model if preferences say to, else use the default (full SO)
414 * - as JS currently doesn't have OBO parsing, it must use 'Lite' version
416 boolean soDefault = !Platform.isJS();
417 if (Cache.getDefault("USE_FULL_SO", soDefault))
419 SequenceOntologyFactory.setInstance(new SequenceOntology());
424 desktop = new Desktop();
425 desktop.setInBatchMode(true); // indicate we are starting up
429 JalviewTaskbar.setTaskbar(this);
430 } catch (Throwable t)
432 System.out.println("Error setting Taskbar: " + t.getMessage());
435 desktop.setVisible(true);
437 if (!Platform.isJS())
444 desktop.startServiceDiscovery();
445 if (!aparser.contains("nousagestats"))
447 startUsageStats(desktop);
451 System.err.println("CMD [-nousagestats] executed successfully!");
454 if (!aparser.contains("noquestionnaire"))
456 String url = aparser.getValue("questionnaire");
459 // Start the desktop questionnaire prompter with the specified
461 Cache.log.debug("Starting questionnaire url at " + url);
462 desktop.checkForQuestionnaire(url);
463 System.out.println("CMD questionnaire[-" + url
464 + "] executed successfully!");
468 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
470 // Start the desktop questionnaire prompter with the specified
473 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
475 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
477 "Starting questionnaire with default url: " + defurl);
478 desktop.checkForQuestionnaire(defurl);
485 .println("CMD [-noquestionnaire] executed successfully!");
488 if (!aparser.contains("nonews"))
490 desktop.checkForNews();
493 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 (!file.startsWith("http://") && !file.startsWith("https://"))
553 // BH 2019 added https check for Java
555 if (!(new File(file)).exists())
557 System.out.println("Can't find " + file);
566 protocol = AppletFormatAdapter.checkProtocol(file);
570 format = new IdentifyFile().identify(file, protocol);
571 } catch (FileFormatException e1)
576 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
580 System.out.println("error");
584 setCurrentAlignFrame(af);
585 data = aparser.getValue("colour", true);
588 data.replaceAll("%20", " ");
590 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
591 af.getViewport(), af.getViewport().getAlignment(), data);
596 "CMD [-color " + data + "] executed successfully!");
601 // Must maintain ability to use the groups flag
602 data = aparser.getValue("groups", true);
605 af.parseFeaturesFile(data,
606 AppletFormatAdapter.checkProtocol(data));
607 // System.out.println("Added " + data);
609 "CMD groups[-" + data + "] executed successfully!");
611 data = aparser.getValue("features", true);
614 af.parseFeaturesFile(data,
615 AppletFormatAdapter.checkProtocol(data));
616 // System.out.println("Added " + data);
618 "CMD [-features " + data + "] executed successfully!");
621 data = aparser.getValue("annotations", true);
624 af.loadJalviewDataFile(data, null, null, null);
625 // System.out.println("Added " + data);
627 "CMD [-annotations " + data + "] executed successfully!");
629 // set or clear the sortbytree flag.
630 if (aparser.contains("sortbytree"))
632 af.getViewport().setSortByTree(true);
633 if (af.getViewport().getSortByTree())
635 System.out.println("CMD [-sortbytree] executed successfully!");
638 if (aparser.contains("no-annotation"))
640 af.getViewport().setShowAnnotation(false);
641 if (!af.getViewport().isShowAnnotation())
643 System.out.println("CMD no-annotation executed successfully!");
646 if (aparser.contains("nosortbytree"))
648 af.getViewport().setSortByTree(false);
649 if (!af.getViewport().getSortByTree())
652 .println("CMD [-nosortbytree] executed successfully!");
655 data = aparser.getValue("tree", true);
661 "CMD [-tree " + data + "] executed successfully!");
662 NewickFile nf = new NewickFile(data,
663 AppletFormatAdapter.checkProtocol(data));
665 .setCurrentTree(af.showNewickTree(nf, data).getTree());
666 } catch (IOException ex)
668 System.err.println("Couldn't add tree " + data);
669 ex.printStackTrace(System.err);
672 // TODO - load PDB structure(s) to alignment JAL-629
673 // (associate with identical sequence in alignment, or a specified
675 if (groovyscript != null)
677 // Execute the groovy script after we've done all the rendering stuff
678 // and before any images or figures are generated.
679 System.out.println("Executing script " + groovyscript);
680 executeGroovyScript(groovyscript, af);
681 System.out.println("CMD groovy[" + groovyscript
682 + "] executed successfully!");
685 String imageName = "unnamed.png";
686 while (aparser.getSize() > 1)
688 String outputFormat = aparser.nextValue();
689 file = aparser.nextValue();
691 if (outputFormat.equalsIgnoreCase("png"))
693 af.createPNG(new File(file));
694 imageName = (new File(file)).getName();
695 System.out.println("Creating PNG image: " + file);
698 else if (outputFormat.equalsIgnoreCase("svg"))
700 File imageFile = new File(file);
701 imageName = imageFile.getName();
702 af.createSVG(imageFile);
703 System.out.println("Creating SVG image: " + file);
706 else if (outputFormat.equalsIgnoreCase("html"))
708 File imageFile = new File(file);
709 imageName = imageFile.getName();
710 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
711 htmlSVG.exportHTML(file);
713 System.out.println("Creating HTML image: " + file);
716 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
720 System.err.println("The output html file must not be null");
725 BioJsHTMLOutput.refreshVersionInfo(
726 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
727 } catch (URISyntaxException e)
731 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
732 bjs.exportHTML(file);
734 .println("Creating BioJS MSA Viwer HTML file: " + file);
737 else if (outputFormat.equalsIgnoreCase("imgMap"))
739 af.createImageMap(new File(file), imageName);
740 System.out.println("Creating image map: " + file);
743 else if (outputFormat.equalsIgnoreCase("eps"))
745 File outputFile = new File(file);
747 "Creating EPS file: " + outputFile.getAbsolutePath());
748 af.createEPS(outputFile);
752 af.saveAlignment(file, format);
753 if (af.isSaveAlignmentSuccessful())
755 System.out.println("Written alignment in " + format
756 + " format to " + file);
760 System.out.println("Error writing file " + file + " in "
761 + format + " format!!");
766 while (aparser.getSize() > 0)
768 System.out.println("Unknown arg: " + aparser.nextValue());
772 AlignFrame startUpAlframe = null;
773 // We'll only open the default file if the desktop is visible.
775 // ////////////////////
777 if (!Platform.isJS() && !headless && file == null
778 && Cache.getDefault("SHOW_STARTUP_FILE", true))
785 file = Cache.getDefault("STARTUP_FILE",
786 Cache.getDefault("www.jalview.org",
787 "http://www.jalview.org")
788 + "/examples/exampleFile_2_7.jar");
790 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
792 // hardwire upgrade of the startup file
793 file.replace("_2_3.jar", "_2_7.jar");
794 // and remove the stale setting
795 Cache.removeProperty("STARTUP_FILE");
798 protocol = DataSourceType.FILE;
800 if (file.indexOf("http:") > -1)
802 protocol = DataSourceType.URL;
805 if (file.endsWith(".jar"))
807 format = FileFormat.Jalview;
813 format = new IdentifyFile().identify(file, protocol);
814 } catch (FileFormatException e)
820 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
822 // extract groovy arguments before anything else.
825 // Once all other stuff is done, execute any groovy scripts (in order)
826 if (groovyscript != null)
828 if (Cache.groovyJarsPresent())
830 System.out.println("Executing script " + groovyscript);
831 executeGroovyScript(groovyscript, startUpAlframe);
836 "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 private static boolean setCrossPlatformLookAndFeel() {
855 UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
857 } catch (Exception ex)
859 System.err.println("Unexpected Look and Feel Exception");
860 ex.printStackTrace();
865 private static boolean setSystemLookAndFeel() {
869 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
871 } catch (Exception ex)
873 System.err.println("Unexpected Look and Feel Exception");
874 ex.printStackTrace();
879 private static boolean setMacLookAndFeel() {
881 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
883 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
885 System.setProperty("apple.laf.useScreenMenuBar", "true");
886 if (lookAndFeel != null)
890 UIManager.setLookAndFeel(lookAndFeel);
892 } catch (Throwable e)
895 "Failed to set QuaQua look and feel: " + e.toString());
898 if (lookAndFeel == null
899 || !(lookAndFeel.getClass().isAssignableFrom(
900 UIManager.getLookAndFeel().getClass()))
901 || !UIManager.getLookAndFeel().getClass().toString()
902 .toLowerCase().contains("quaqua"))
907 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
908 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
910 } catch (Throwable e)
913 "Failed to reset look and feel: " + e.toString());
919 private static void showUsage()
922 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
923 + "-nodisplay\tRun Jalview without User Interface.\n"
924 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
925 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
926 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
927 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
928 + "-features FILE\tUse the given file to mark features on the alignment.\n"
929 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
930 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
931 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
932 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
933 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
934 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
935 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
936 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
937 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
938 + "-png FILE\tCreate PNG image FILE from alignment.\n"
939 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
940 + "-html FILE\tCreate HTML file from alignment.\n"
941 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
942 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
943 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
944 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
945 + "-noquestionnaire\tTurn off questionnaire check.\n"
946 + "-nonews\tTurn off check for Jalview news.\n"
947 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
948 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
950 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
951 // after all other properties files have been read\n\t
952 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
953 // passed in correctly)"
954 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
955 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
956 + "-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"
957 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
960 private static void startUsageStats(final Desktop desktop)
963 * start a User Config prompt asking if we can log usage statistics.
965 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
966 "USAGESTATS", "Jalview Usage Statistics",
967 "Do you want to help make Jalview better by enabling "
968 + "the collection of usage statistics with Google Analytics ?"
969 + "\n\n(you can enable or disable usage tracking in the preferences)",
976 "Initialising googletracker for usage stats.");
977 Cache.initGoogleTracker();
978 Cache.log.debug("Tracking enabled.");
985 Cache.log.debug("Not enabling Google Tracking.");
988 desktop.addDialogThread(prompter);
992 * Locate the given string as a file and pass it to the groovy interpreter.
994 * @param groovyscript
995 * the script to execute
996 * @param jalviewContext
997 * the Jalview Desktop object passed in to the groovy
998 * binding as the 'Jalview' object.
1000 private void executeGroovyScript(String groovyscript, AlignFrame af)
1003 * for scripts contained in files
1010 if (groovyscript.trim().equals("STDIN"))
1012 // read from stdin into a tempfile and execute it
1015 tfile = File.createTempFile("jalview", "groovy");
1016 PrintWriter outfile = new PrintWriter(
1017 new OutputStreamWriter(new FileOutputStream(tfile)));
1018 BufferedReader br = new BufferedReader(
1019 new InputStreamReader(System.in));
1021 while ((line = br.readLine()) != null)
1023 outfile.write(line + "\n");
1029 } catch (Exception ex)
1031 System.err.println("Failed to read from STDIN into tempfile "
1032 + ((tfile == null) ? "(tempfile wasn't created)"
1033 : tfile.toString()));
1034 ex.printStackTrace();
1039 sfile = tfile.toURI().toURL();
1040 } catch (Exception x)
1043 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1045 x.printStackTrace();
1053 sfile = new URI(groovyscript).toURL();
1054 } catch (Exception x)
1056 tfile = new File(groovyscript);
1057 if (!tfile.exists())
1059 System.err.println("File '" + groovyscript + "' does not exist.");
1062 if (!tfile.canRead())
1064 System.err.println("File '" + groovyscript + "' cannot be read.");
1067 if (tfile.length() < 1)
1069 System.err.println("File '" + groovyscript + "' is empty.");
1074 sfile = tfile.getAbsoluteFile().toURI().toURL();
1075 } catch (Exception ex)
1077 System.err.println("Failed to create a file URL for "
1078 + tfile.getAbsoluteFile());
1085 Map<String, java.lang.Object> vbinding = new HashMap<>();
1086 vbinding.put("Jalview", this);
1089 vbinding.put("currentAlFrame", af);
1091 Binding gbinding = new Binding(vbinding);
1092 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1093 gse.run(sfile.toString(), gbinding);
1094 if ("STDIN".equals(groovyscript))
1096 // delete temp file that we made -
1097 // only if it was successfully executed
1100 } catch (Exception e)
1102 System.err.println("Exception Whilst trying to execute file " + sfile
1103 + " as a groovy script.");
1104 e.printStackTrace(System.err);
1109 public static boolean isHeadlessMode()
1111 String isheadless = System.getProperty("java.awt.headless");
1112 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1119 public AlignFrame[] getAlignFrames()
1121 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1122 : Desktop.getAlignFrames();
1127 * Quit method delegates to Desktop.quit - unless running in headless mode when
1128 * it just ends the JVM
1132 if (desktop != null)
1142 public static AlignFrame getCurrentAlignFrame()
1144 return Jalview.currentAlignFrame;
1147 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1149 Jalview.currentAlignFrame = currentAlignFrame;