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.io.BufferedReader;
25 import java.io.FileOutputStream;
26 import java.io.IOException;
27 import java.io.InputStreamReader;
28 import java.io.OutputStreamWriter;
29 import java.io.PrintWriter;
30 import java.net.MalformedURLException;
32 import java.net.URISyntaxException;
34 import java.security.AllPermission;
35 import java.security.CodeSource;
36 import java.security.PermissionCollection;
37 import java.security.Permissions;
38 import java.security.Policy;
39 import java.util.HashMap;
41 import java.util.Vector;
43 import javax.swing.UIManager;
44 import javax.swing.UIManager.LookAndFeelInfo;
46 import com.threerings.getdown.util.LaunchUtil;
48 import groovy.lang.Binding;
49 import groovy.util.GroovyScriptEngine;
50 import jalview.ext.so.SequenceOntology;
51 import jalview.gui.AlignFrame;
52 import jalview.gui.Desktop;
53 import jalview.gui.PromptUserConfig;
54 import jalview.io.AppletFormatAdapter;
55 import jalview.io.BioJsHTMLOutput;
56 import jalview.io.DataSourceType;
57 import jalview.io.FileFormat;
58 import jalview.io.FileFormatException;
59 import jalview.io.FileFormatI;
60 import jalview.io.FileLoader;
61 import jalview.io.HtmlSvgOutput;
62 import jalview.io.IdentifyFile;
63 import jalview.io.NewickFile;
64 import jalview.io.gff.SequenceOntologyFactory;
65 import jalview.schemes.ColourSchemeI;
66 import jalview.schemes.ColourSchemeProperty;
67 import jalview.util.MessageManager;
68 import jalview.util.Platform;
69 import jalview.ws.jws2.Jws2Discoverer;
72 * Main class for Jalview Application <br>
74 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
77 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
78 * jalview.bin.Jalview jalview.bin.Jalview
80 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
81 * embellish '*' to e.g. '*.jar')
89 * singleton instance of this class
91 private static Jalview instance;
93 private Desktop desktop;
95 public static AlignFrame currentAlignFrame;
99 // grab all the rights we can the JVM
100 Policy.setPolicy(new Policy()
103 public PermissionCollection getPermissions(CodeSource codesource)
105 Permissions perms = new Permissions();
106 perms.add(new AllPermission());
111 public void refresh()
118 * keep track of feature fetching tasks.
126 * TODO: generalise to track all jalview events to orchestrate batch processing
130 private int queued = 0;
132 private int running = 0;
134 public FeatureFetcher()
139 public void addFetcher(final AlignFrame af,
140 final Vector<String> dasSources)
142 final long id = System.currentTimeMillis();
144 final FeatureFetcher us = this;
145 new Thread(new Runnable()
157 af.setProgressBar(MessageManager
158 .getString("status.das_features_being_retrived"), id);
159 af.featureSettings_actionPerformed(null);
160 af.setProgressBar(null, id);
169 public synchronized boolean allFinished()
171 return queued == 0 && running == 0;
176 public static Jalview getInstance()
182 * main class for Jalview application
185 * open <em>filename</em>
187 public static void main(String[] args)
189 instance = new Jalview();
190 instance.doMain(args);
196 void doMain(String[] args)
198 System.setSecurityManager(null);
200 .println("Java version: " + System.getProperty("java.version"));
201 System.out.println("Java Home: " + System.getProperty("java.home"));
202 System.out.println(System.getProperty("os.arch") + " "
203 + System.getProperty("os.name") + " "
204 + System.getProperty("os.version"));
205 String val = System.getProperty("sys.install4jVersion");
208 System.out.println("Install4j version: " + val);
210 val = System.getProperty("installer_template_version");
213 System.out.println("Install4j template version: " + val);
215 val = System.getProperty("launcher_version");
218 System.out.println("Launcher version: " + val);
221 // report Jalview version
222 Cache.loadBuildProperties(true);
224 ArgsParser aparser = new ArgsParser(args);
225 boolean headless = false;
227 if (aparser.contains("help") || aparser.contains("h"))
232 if (aparser.contains("nodisplay") || aparser.contains("nogui")
233 || aparser.contains("headless"))
235 System.setProperty("java.awt.headless", "true");
238 String usrPropsFile = aparser.getValue("props");
239 Cache.loadProperties(usrPropsFile); // must do this before
240 if (usrPropsFile != null)
243 "CMD [-props " + usrPropsFile + "] executed successfully!");
248 final String jabawsUrl = aparser.getValue("jabaws");
249 if (jabawsUrl != null)
253 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
255 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
256 } catch (MalformedURLException e)
259 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
263 String defs = aparser.getValue("setprop");
266 int p = defs.indexOf('=');
269 System.err.println("Ignoring invalid setprop argument : " + defs);
273 System.out.println("Executing setprop argument: " + defs);
274 // DISABLED FOR SECURITY REASONS
275 // TODO: add a property to allow properties to be overriden by cli args
276 // Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
278 defs = aparser.getValue("setprop");
280 if (System.getProperty("java.awt.headless") != null
281 && System.getProperty("java.awt.headless").equals("true"))
285 System.setProperty("http.agent",
286 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
290 } catch (NoClassDefFoundError error)
292 error.printStackTrace();
293 System.out.println("\nEssential logging libraries not found."
294 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
300 // property laf = "crossplatform", "system", "gtk", "metal", "nimbus" or
302 // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
304 String lafProp = System.getProperty("laf");
305 String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
311 else if (lafSetting != null)
315 boolean lafSet = false;
318 case "crossplatform":
319 lafSet = setCrossPlatformLookAndFeel();
322 Cache.log.error("Could not set requested laf=" + laf);
326 lafSet = setSystemLookAndFeel();
329 Cache.log.error("Could not set requested laf=" + laf);
333 lafSet = setGtkLookAndFeel();
335 Cache.log.error("Could not set requested laf=" + laf);
339 lafSet = setMetalLookAndFeel();
341 Cache.log.error("Could not set requested laf=" + laf);
345 lafSet = setNimbusLookAndFeel();
347 Cache.log.error("Could not set requested laf=" + laf);
351 lafSet = setQuaquaLookAndFeel();
353 Cache.log.error("Could not set requested laf=" + laf);
357 lafSet = setVaquaLookAndFeel();
359 Cache.log.error("Could not set requested laf=" + laf);
363 lafSet = setMacLookAndFeel();
366 Cache.log.error("Could not set requested laf=" + laf);
372 Cache.log.error("Requested laf=" + laf + " not implemented");
376 setSystemLookAndFeel();
377 if (Platform.isLinux())
379 setMetalLookAndFeel();
381 if (Platform.isAMac())
388 * configure 'full' SO model if preferences say to, else use the default (SO
391 if (Cache.getDefault("USE_FULL_SO", true))
393 SequenceOntologyFactory.setInstance(new SequenceOntology());
398 desktop = new Desktop();
399 desktop.setInBatchMode(true); // indicate we are starting up
403 JalviewTaskbar.setTaskbar(this);
404 } catch (Exception e)
406 Cache.log.info("Cannot set Taskbar");
407 Cache.log.error(e.getMessage());
408 // e.printStackTrace();
409 } catch (Throwable t)
411 Cache.log.info("Cannot set Taskbar");
412 Cache.log.error(t.getMessage());
413 // t.printStackTrace();
416 desktop.setVisible(true);
417 desktop.startServiceDiscovery();
418 if (!aparser.contains("nousagestats"))
420 startUsageStats(desktop);
424 System.err.println("CMD [-nousagestats] executed successfully!");
427 if (!aparser.contains("noquestionnaire"))
429 String url = aparser.getValue("questionnaire");
432 // Start the desktop questionnaire prompter with the specified
434 Cache.log.debug("Starting questionnaire url at " + url);
435 desktop.checkForQuestionnaire(url);
437 "CMD questionnaire[-" + url + "] executed successfully!");
441 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
443 // Start the desktop questionnaire prompter with the specified
446 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
448 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
450 "Starting questionnaire with default url: " + defurl);
451 desktop.checkForQuestionnaire(defurl);
457 System.err.println("CMD [-noquestionnaire] executed successfully!");
460 if (!aparser.contains("nonews"))
462 desktop.checkForNews();
465 BioJsHTMLOutput.updateBioJS();
468 // Move any new getdown-launcher-new.jar into place over old
469 // getdown-launcher.jar
470 String appdirString = System.getProperty("getdownappdir");
471 if (appdirString != null && appdirString.length() > 0)
473 final File appdir = new File(appdirString);
479 LaunchUtil.upgradeGetdown(
480 new File(appdir, "getdown-launcher-old.jar"),
481 new File(appdir, "getdown-launcher.jar"),
482 new File(appdir, "getdown-launcher-new.jar"));
487 String file = null, data = null;
488 FileFormatI format = null;
489 DataSourceType protocol = null;
490 FileLoader fileLoader = new FileLoader(!headless);
492 String groovyscript = null; // script to execute after all loading is
493 // completed one way or another
494 // extract groovy argument and execute if necessary
495 groovyscript = aparser.getValue("groovy", true);
496 file = aparser.getValue("open", true);
498 if (file == null && desktop == null)
500 System.out.println("No files to open!");
504 // Finally, deal with the remaining input data.
509 desktop.setProgressBar(
511 .getString("status.processing_commandline_args"),
512 progress = System.currentTimeMillis());
514 System.out.println("CMD [-open " + file + "] executed successfully!");
516 if (!file.startsWith("http://"))
518 if (!(new File(file)).exists())
520 System.out.println("Can't find " + file);
528 protocol = AppletFormatAdapter.checkProtocol(file);
532 format = new IdentifyFile().identify(file, protocol);
533 } catch (FileFormatException e1)
538 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
542 System.out.println("error");
546 setCurrentAlignFrame(af);
547 data = aparser.getValue("colour", true);
550 data.replaceAll("%20", " ");
552 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
553 af.getViewport(), af.getViewport().getAlignment(), data);
558 "CMD [-color " + data + "] executed successfully!");
563 // Must maintain ability to use the groups flag
564 data = aparser.getValue("groups", true);
567 af.parseFeaturesFile(data,
568 AppletFormatAdapter.checkProtocol(data));
569 // System.out.println("Added " + data);
571 "CMD groups[-" + data + "] executed successfully!");
573 data = aparser.getValue("features", true);
576 af.parseFeaturesFile(data,
577 AppletFormatAdapter.checkProtocol(data));
578 // System.out.println("Added " + data);
580 "CMD [-features " + data + "] executed successfully!");
583 data = aparser.getValue("annotations", true);
586 af.loadJalviewDataFile(data, null, null, null);
587 // System.out.println("Added " + data);
589 "CMD [-annotations " + data + "] executed successfully!");
591 // set or clear the sortbytree flag.
592 if (aparser.contains("sortbytree"))
594 af.getViewport().setSortByTree(true);
595 if (af.getViewport().getSortByTree())
597 System.out.println("CMD [-sortbytree] executed successfully!");
600 if (aparser.contains("no-annotation"))
602 af.getViewport().setShowAnnotation(false);
603 if (!af.getViewport().isShowAnnotation())
605 System.out.println("CMD no-annotation executed successfully!");
608 if (aparser.contains("nosortbytree"))
610 af.getViewport().setSortByTree(false);
611 if (!af.getViewport().getSortByTree())
614 .println("CMD [-nosortbytree] executed successfully!");
617 data = aparser.getValue("tree", true);
623 "CMD [-tree " + data + "] executed successfully!");
624 NewickFile nf = new NewickFile(data,
625 AppletFormatAdapter.checkProtocol(data));
627 .setCurrentTree(af.showNewickTree(nf, data).getTree());
628 } catch (IOException ex)
630 System.err.println("Couldn't add tree " + data);
631 ex.printStackTrace(System.err);
634 // TODO - load PDB structure(s) to alignment JAL-629
635 // (associate with identical sequence in alignment, or a specified
637 if (groovyscript != null)
639 // Execute the groovy script after we've done all the rendering stuff
640 // and before any images or figures are generated.
641 System.out.println("Executing script " + groovyscript);
642 executeGroovyScript(groovyscript, af);
643 System.out.println("CMD groovy[" + groovyscript
644 + "] executed successfully!");
647 String imageName = "unnamed.png";
648 while (aparser.getSize() > 1)
650 String outputFormat = aparser.nextValue();
651 file = aparser.nextValue();
653 if (outputFormat.equalsIgnoreCase("png"))
655 af.createPNG(new File(file));
656 imageName = (new File(file)).getName();
657 System.out.println("Creating PNG image: " + file);
660 else if (outputFormat.equalsIgnoreCase("svg"))
662 File imageFile = new File(file);
663 imageName = imageFile.getName();
664 af.createSVG(imageFile);
665 System.out.println("Creating SVG image: " + file);
668 else if (outputFormat.equalsIgnoreCase("html"))
670 File imageFile = new File(file);
671 imageName = imageFile.getName();
672 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
673 htmlSVG.exportHTML(file);
675 System.out.println("Creating HTML image: " + file);
678 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
682 System.err.println("The output html file must not be null");
687 BioJsHTMLOutput.refreshVersionInfo(
688 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
689 } catch (URISyntaxException e)
693 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
694 bjs.exportHTML(file);
696 .println("Creating BioJS MSA Viwer HTML file: " + file);
699 else if (outputFormat.equalsIgnoreCase("imgMap"))
701 af.createImageMap(new File(file), imageName);
702 System.out.println("Creating image map: " + file);
705 else if (outputFormat.equalsIgnoreCase("eps"))
707 File outputFile = new File(file);
709 "Creating EPS file: " + outputFile.getAbsolutePath());
710 af.createEPS(outputFile);
714 if (af.saveAlignment(file, format))
716 System.out.println("Written alignment in " + format
717 + " format to " + file);
721 System.out.println("Error writing file " + file + " in "
722 + format + " format!!");
727 while (aparser.getSize() > 0)
729 System.out.println("Unknown arg: " + aparser.nextValue());
733 AlignFrame startUpAlframe = null;
734 // We'll only open the default file if the desktop is visible.
736 // ////////////////////
738 if (!headless && file == null
739 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
741 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
742 jalview.bin.Cache.getDefault("www.jalview.org",
743 "http://www.jalview.org")
744 + "/examples/exampleFile_2_7.jar");
746 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
748 // hardwire upgrade of the startup file
749 file.replace("_2_3.jar", "_2_7.jar");
750 // and remove the stale setting
751 jalview.bin.Cache.removeProperty("STARTUP_FILE");
754 protocol = DataSourceType.FILE;
756 if (file.indexOf("http:") > -1)
758 protocol = DataSourceType.URL;
761 if (file.endsWith(".jar"))
763 format = FileFormat.Jalview;
769 format = new IdentifyFile().identify(file, protocol);
770 } catch (FileFormatException e)
776 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
778 // extract groovy arguments before anything else.
781 // Once all other stuff is done, execute any groovy scripts (in order)
782 if (groovyscript != null)
784 if (Cache.groovyJarsPresent())
786 System.out.println("Executing script " + groovyscript);
787 executeGroovyScript(groovyscript, startUpAlframe);
792 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
796 // and finally, turn off batch mode indicator - if the desktop still exists
801 desktop.setProgressBar(null, progress);
803 desktop.setInBatchMode(false);
807 private static boolean setCrossPlatformLookAndFeel()
812 UIManager.setLookAndFeel(
813 UIManager.getCrossPlatformLookAndFeelClassName());
815 } catch (Exception ex)
817 System.err.println("Unexpected Look and Feel Exception");
818 ex.printStackTrace();
823 private static boolean setSystemLookAndFeel()
828 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
830 } catch (Exception ex)
832 System.err.println("Unexpected Look and Feel Exception");
833 ex.printStackTrace();
838 private static boolean setSpecificLookAndFeel(String name,
839 String className, boolean nameStartsWith)
844 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
846 if (info.getName() != null && nameStartsWith
847 ? info.getName().toLowerCase()
848 .startsWith(name.toLowerCase())
849 : info.getName().toLowerCase().equals(name.toLowerCase()))
851 className = info.getClassName();
855 UIManager.setLookAndFeel(className);
857 } catch (Exception ex)
859 System.err.println("Unexpected Look and Feel Exception");
860 ex.printStackTrace();
865 private static boolean setGtkLookAndFeel()
867 return setSpecificLookAndFeel("gtk",
868 "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true);
871 private static boolean setMetalLookAndFeel()
873 return setSpecificLookAndFeel("metal",
874 "javax.swing.plaf.metal.MetalLookAndFeel", false);
877 private static boolean setNimbusLookAndFeel()
879 return setSpecificLookAndFeel("nimbus",
880 "javax.swing.plaf.nimbus.NimbusLookAndFeel", false);
883 private static boolean setQuaquaLookAndFeel()
885 return setSpecificLookAndFeel("quaqua",
886 ch.randelshofer.quaqua.QuaquaManager.getLookAndFeel().getClass()
891 private static boolean setVaquaLookAndFeel()
893 return setSpecificLookAndFeel("vaqua",
894 "org.violetlib.aqua.AquaLookAndFeel", false);
897 private static boolean setMacLookAndFeel()
900 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
902 System.setProperty("apple.laf.useScreenMenuBar", "true");
903 set = setQuaquaLookAndFeel();
904 if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
905 .toLowerCase().contains("quaqua"))
907 set = setVaquaLookAndFeel();
912 private static void showUsage()
915 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
916 + "-nodisplay\tRun Jalview without User Interface.\n"
917 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
918 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
919 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
920 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
921 + "-features FILE\tUse the given file to mark features on the alignment.\n"
922 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
923 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
924 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
925 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
926 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
927 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
928 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
929 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
930 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
931 + "-png FILE\tCreate PNG image FILE from alignment.\n"
932 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
933 + "-html FILE\tCreate HTML file from alignment.\n"
934 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
935 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
936 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
937 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
938 + "-noquestionnaire\tTurn off questionnaire check.\n"
939 + "-nonews\tTurn off check for Jalview news.\n"
940 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
941 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
943 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
944 // after all other properties files have been read\n\t
945 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
946 // passed in correctly)"
947 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
948 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
949 + "-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"
950 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
953 private static void startUsageStats(final Desktop desktop)
956 * start a User Config prompt asking if we can log usage statistics.
958 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
959 "USAGESTATS", "Jalview Usage Statistics",
960 "Do you want to help make Jalview better by enabling "
961 + "the collection of usage statistics with Google Analytics ?"
962 + "\n\n(you can enable or disable usage tracking in the preferences)",
969 "Initialising googletracker for usage stats.");
970 Cache.initGoogleTracker();
971 Cache.log.debug("Tracking enabled.");
978 Cache.log.debug("Not enabling Google Tracking.");
981 desktop.addDialogThread(prompter);
985 * Locate the given string as a file and pass it to the groovy interpreter.
987 * @param groovyscript
988 * the script to execute
989 * @param jalviewContext
990 * the Jalview Desktop object passed in to the groovy binding as the
993 private void executeGroovyScript(String groovyscript, AlignFrame af)
996 * for scripts contained in files
1003 if (groovyscript.trim().equals("STDIN"))
1005 // read from stdin into a tempfile and execute it
1008 tfile = File.createTempFile("jalview", "groovy");
1009 PrintWriter outfile = new PrintWriter(
1010 new OutputStreamWriter(new FileOutputStream(tfile)));
1011 BufferedReader br = new BufferedReader(
1012 new InputStreamReader(System.in));
1014 while ((line = br.readLine()) != null)
1016 outfile.write(line + "\n");
1022 } catch (Exception ex)
1024 System.err.println("Failed to read from STDIN into tempfile "
1025 + ((tfile == null) ? "(tempfile wasn't created)"
1026 : tfile.toString()));
1027 ex.printStackTrace();
1032 sfile = tfile.toURI().toURL();
1033 } catch (Exception x)
1036 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1038 x.printStackTrace();
1046 sfile = new URI(groovyscript).toURL();
1047 } catch (Exception x)
1049 tfile = new File(groovyscript);
1050 if (!tfile.exists())
1052 System.err.println("File '" + groovyscript + "' does not exist.");
1055 if (!tfile.canRead())
1057 System.err.println("File '" + groovyscript + "' cannot be read.");
1060 if (tfile.length() < 1)
1062 System.err.println("File '" + groovyscript + "' is empty.");
1067 sfile = tfile.getAbsoluteFile().toURI().toURL();
1068 } catch (Exception ex)
1070 System.err.println("Failed to create a file URL for "
1071 + tfile.getAbsoluteFile());
1078 Map<String, java.lang.Object> vbinding = new HashMap<>();
1079 vbinding.put("Jalview", this);
1082 vbinding.put("currentAlFrame", af);
1084 Binding gbinding = new Binding(vbinding);
1085 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1086 gse.run(sfile.toString(), gbinding);
1087 if ("STDIN".equals(groovyscript))
1089 // delete temp file that we made -
1090 // only if it was successfully executed
1093 } catch (Exception e)
1095 System.err.println("Exception Whilst trying to execute file " + sfile
1096 + " as a groovy script.");
1097 e.printStackTrace(System.err);
1102 public static boolean isHeadlessMode()
1104 String isheadless = System.getProperty("java.awt.headless");
1105 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1112 public AlignFrame[] getAlignFrames()
1114 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1115 : Desktop.getAlignFrames();
1120 * Quit method delegates to Desktop.quit - unless running in headless mode
1121 * when it just ends the JVM
1125 if (desktop != null)
1135 public static AlignFrame getCurrentAlignFrame()
1137 return Jalview.currentAlignFrame;
1140 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1142 Jalview.currentAlignFrame = currentAlignFrame;