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.HttpUtils;
68 import jalview.util.MessageManager;
69 import jalview.util.Platform;
70 import jalview.ws.jws2.Jws2Discoverer;
73 * Main class for Jalview Application <br>
75 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
78 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
79 * jalview.bin.Jalview jalview.bin.Jalview
81 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
82 * embellish '*' to e.g. '*.jar')
90 * singleton instance of this class
92 private static Jalview instance;
94 private Desktop desktop;
96 public static AlignFrame currentAlignFrame;
100 // grab all the rights we can the JVM
101 Policy.setPolicy(new Policy()
104 public PermissionCollection getPermissions(CodeSource codesource)
106 Permissions perms = new Permissions();
107 perms.add(new AllPermission());
112 public void refresh()
119 * keep track of feature fetching tasks.
127 * TODO: generalise to track all jalview events to orchestrate batch processing
131 private int queued = 0;
133 private int running = 0;
135 public FeatureFetcher()
140 public void addFetcher(final AlignFrame af,
141 final Vector<String> dasSources)
143 final long id = System.currentTimeMillis();
145 final FeatureFetcher us = this;
146 new Thread(new Runnable()
158 af.setProgressBar(MessageManager
159 .getString("status.das_features_being_retrived"), id);
160 af.featureSettings_actionPerformed(null);
161 af.setProgressBar(null, id);
170 public synchronized boolean allFinished()
172 return queued == 0 && running == 0;
177 public static Jalview getInstance()
183 * main class for Jalview application
186 * open <em>filename</em>
188 public static void main(String[] args)
190 instance = new Jalview();
191 instance.doMain(args);
197 void doMain(String[] args)
199 System.setSecurityManager(null);
201 .println("Java version: " + System.getProperty("java.version"));
202 System.out.println("Java Home: " + System.getProperty("java.home"));
203 System.out.println(System.getProperty("os.arch") + " "
204 + System.getProperty("os.name") + " "
205 + System.getProperty("os.version"));
206 String val = System.getProperty("sys.install4jVersion");
209 System.out.println("Install4j version: " + val);
211 val = System.getProperty("installer_template_version");
214 System.out.println("Install4j template version: " + val);
216 val = System.getProperty("launcher_version");
219 System.out.println("Launcher version: " + val);
222 // report Jalview version
223 Cache.loadBuildProperties(true);
225 ArgsParser aparser = new ArgsParser(args);
226 boolean headless = false;
228 if (aparser.contains("help") || aparser.contains("h"))
233 if (aparser.contains("nodisplay") || aparser.contains("nogui")
234 || aparser.contains("headless"))
236 System.setProperty("java.awt.headless", "true");
239 String usrPropsFile = aparser.getValue("props");
240 Cache.loadProperties(usrPropsFile); // must do this before
241 if (usrPropsFile != null)
244 "CMD [-props " + usrPropsFile + "] executed successfully!");
249 final String jabawsUrl = aparser.getValue("jabaws");
250 if (jabawsUrl != null)
254 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
256 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
257 } catch (MalformedURLException e)
260 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
264 String defs = aparser.getValue("setprop");
267 int p = defs.indexOf('=');
270 System.err.println("Ignoring invalid setprop argument : " + defs);
274 System.out.println("Executing setprop argument: " + defs);
275 // DISABLED FOR SECURITY REASONS
276 // TODO: add a property to allow properties to be overriden by cli args
277 // Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
279 defs = aparser.getValue("setprop");
281 if (System.getProperty("java.awt.headless") != null
282 && System.getProperty("java.awt.headless").equals("true"))
286 System.setProperty("http.agent",
287 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
291 } catch (NoClassDefFoundError error)
293 error.printStackTrace();
294 System.out.println("\nEssential logging libraries not found."
295 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
304 * configure 'full' SO model if preferences say to, else use the default (SO
307 if (Cache.getDefault("USE_FULL_SO", true))
309 SequenceOntologyFactory.setInstance(new SequenceOntology());
315 desktop = new Desktop();
316 desktop.setInBatchMode(true); // indicate we are starting up
320 JalviewTaskbar.setTaskbar(this);
321 } catch (Exception e)
323 Cache.log.info("Cannot set Taskbar");
324 Cache.log.error(e.getMessage());
325 // e.printStackTrace();
326 } catch (Throwable t)
328 Cache.log.info("Cannot set Taskbar");
329 Cache.log.error(t.getMessage());
330 // t.printStackTrace();
333 // set Proxy settings before all the internet calls
334 Cache.setProxyPropertiesFromPreferences();
336 desktop.setVisible(true);
337 desktop.startServiceDiscovery();
338 if (!aparser.contains("nousagestats"))
340 startUsageStats(desktop);
344 System.err.println("CMD [-nousagestats] executed successfully!");
347 if (!aparser.contains("noquestionnaire"))
349 String url = aparser.getValue("questionnaire");
352 // Start the desktop questionnaire prompter with the specified
354 Cache.log.debug("Starting questionnaire url at " + url);
355 desktop.checkForQuestionnaire(url);
357 "CMD questionnaire[-" + url + "] executed successfully!");
361 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
363 // Start the desktop questionnaire prompter with the specified
366 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
368 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
370 "Starting questionnaire with default url: " + defurl);
371 desktop.checkForQuestionnaire(defurl);
377 System.err.println("CMD [-noquestionnaire] executed successfully!");
380 if (!aparser.contains("nonews"))
382 desktop.checkForNews();
385 BioJsHTMLOutput.updateBioJS();
388 // Move any new getdown-launcher-new.jar into place over old
389 // getdown-launcher.jar
390 String appdirString = System.getProperty("getdownappdir");
391 if (appdirString != null && appdirString.length() > 0)
393 final File appdir = new File(appdirString);
399 LaunchUtil.upgradeGetdown(
400 new File(appdir, "getdown-launcher-old.jar"),
401 new File(appdir, "getdown-launcher.jar"),
402 new File(appdir, "getdown-launcher-new.jar"));
407 String file = null, data = null;
408 FileFormatI format = null;
409 DataSourceType protocol = null;
410 FileLoader fileLoader = new FileLoader(!headless);
412 String groovyscript = null; // script to execute after all loading is
413 // completed one way or another
414 // extract groovy argument and execute if necessary
415 groovyscript = aparser.getValue("groovy", true);
416 file = aparser.getValue("open", true);
418 if (file == null && desktop == null)
420 System.out.println("No files to open!");
424 // Finally, deal with the remaining input data.
429 desktop.setProgressBar(
431 .getString("status.processing_commandline_args"),
432 progress = System.currentTimeMillis());
434 System.out.println("CMD [-open " + file + "] executed successfully!");
436 if (!HttpUtils.startsWithHttpOrHttps(file))
438 if (!(new File(file)).exists())
440 System.out.println("Can't find " + file);
448 protocol = AppletFormatAdapter.checkProtocol(file);
452 format = new IdentifyFile().identify(file, protocol);
453 } catch (FileFormatException e1)
458 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
462 System.out.println("error");
466 setCurrentAlignFrame(af);
467 data = aparser.getValue("colour", true);
470 data.replaceAll("%20", " ");
472 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
473 af.getViewport(), af.getViewport().getAlignment(), data);
478 "CMD [-color " + data + "] executed successfully!");
483 // Must maintain ability to use the groups flag
484 data = aparser.getValue("groups", true);
487 af.parseFeaturesFile(data,
488 AppletFormatAdapter.checkProtocol(data));
489 // System.out.println("Added " + data);
491 "CMD groups[-" + data + "] executed successfully!");
493 data = aparser.getValue("features", true);
496 af.parseFeaturesFile(data,
497 AppletFormatAdapter.checkProtocol(data));
498 // System.out.println("Added " + data);
500 "CMD [-features " + data + "] executed successfully!");
503 data = aparser.getValue("annotations", true);
506 af.loadJalviewDataFile(data, null, null, null);
507 // System.out.println("Added " + data);
509 "CMD [-annotations " + data + "] executed successfully!");
511 // set or clear the sortbytree flag.
512 if (aparser.contains("sortbytree"))
514 af.getViewport().setSortByTree(true);
515 if (af.getViewport().getSortByTree())
517 System.out.println("CMD [-sortbytree] executed successfully!");
520 if (aparser.contains("no-annotation"))
522 af.getViewport().setShowAnnotation(false);
523 if (!af.getViewport().isShowAnnotation())
525 System.out.println("CMD no-annotation executed successfully!");
528 if (aparser.contains("nosortbytree"))
530 af.getViewport().setSortByTree(false);
531 if (!af.getViewport().getSortByTree())
534 .println("CMD [-nosortbytree] executed successfully!");
537 data = aparser.getValue("tree", true);
543 "CMD [-tree " + data + "] executed successfully!");
544 NewickFile nf = new NewickFile(data,
545 AppletFormatAdapter.checkProtocol(data));
547 .setCurrentTree(af.showNewickTree(nf, data).getTree());
548 } catch (IOException ex)
550 System.err.println("Couldn't add tree " + data);
551 ex.printStackTrace(System.err);
554 // TODO - load PDB structure(s) to alignment JAL-629
555 // (associate with identical sequence in alignment, or a specified
557 if (groovyscript != null)
559 // Execute the groovy script after we've done all the rendering stuff
560 // and before any images or figures are generated.
561 System.out.println("Executing script " + groovyscript);
562 executeGroovyScript(groovyscript, af);
563 System.out.println("CMD groovy[" + groovyscript
564 + "] executed successfully!");
567 String imageName = "unnamed.png";
568 while (aparser.getSize() > 1)
570 String outputFormat = aparser.nextValue();
571 file = aparser.nextValue();
573 if (outputFormat.equalsIgnoreCase("png"))
575 af.createPNG(new File(file));
576 imageName = (new File(file)).getName();
577 System.out.println("Creating PNG image: " + file);
580 else if (outputFormat.equalsIgnoreCase("svg"))
582 File imageFile = new File(file);
583 imageName = imageFile.getName();
584 af.createSVG(imageFile);
585 System.out.println("Creating SVG image: " + file);
588 else if (outputFormat.equalsIgnoreCase("html"))
590 File imageFile = new File(file);
591 imageName = imageFile.getName();
592 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
593 htmlSVG.exportHTML(file);
595 System.out.println("Creating HTML image: " + file);
598 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
602 System.err.println("The output html file must not be null");
607 BioJsHTMLOutput.refreshVersionInfo(
608 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
609 } catch (URISyntaxException e)
613 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
614 bjs.exportHTML(file);
616 .println("Creating BioJS MSA Viwer HTML file: " + file);
619 else if (outputFormat.equalsIgnoreCase("imgMap"))
621 af.createImageMap(new File(file), imageName);
622 System.out.println("Creating image map: " + file);
625 else if (outputFormat.equalsIgnoreCase("eps"))
627 File outputFile = new File(file);
629 "Creating EPS file: " + outputFile.getAbsolutePath());
630 af.createEPS(outputFile);
634 if (af.saveAlignment(file, format))
636 System.out.println("Written alignment in " + format
637 + " format to " + file);
641 System.out.println("Error writing file " + file + " in "
642 + format + " format!!");
647 while (aparser.getSize() > 0)
649 System.out.println("Unknown arg: " + aparser.nextValue());
653 AlignFrame startUpAlframe = null;
654 // We'll only open the default file if the desktop is visible.
656 // ////////////////////
658 if (!headless && file == null
659 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
661 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
662 jalview.bin.Cache.getDefault("www.jalview.org",
663 "http://www.jalview.org")
664 + "/examples/exampleFile_2_7.jar");
666 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
668 // hardwire upgrade of the startup file
669 file.replace("_2_3.jar", "_2_7.jar");
670 // and remove the stale setting
671 jalview.bin.Cache.removeProperty("STARTUP_FILE");
674 protocol = DataSourceType.FILE;
676 if (file.indexOf("http:") > -1)
678 protocol = DataSourceType.URL;
681 if (file.endsWith(".jar"))
683 format = FileFormat.Jalview;
689 format = new IdentifyFile().identify(file, protocol);
690 } catch (FileFormatException e)
696 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
698 // extract groovy arguments before anything else.
701 // Once all other stuff is done, execute any groovy scripts (in order)
702 if (groovyscript != null)
704 if (Cache.groovyJarsPresent())
706 System.out.println("Executing script " + groovyscript);
707 executeGroovyScript(groovyscript, startUpAlframe);
712 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
716 // and finally, turn off batch mode indicator - if the desktop still exists
721 desktop.setProgressBar(null, progress);
723 desktop.setInBatchMode(false);
727 private static void setLookAndFeel()
729 // property laf = "crossplatform", "system", "gtk", "metal", "nimbus" or
731 // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
733 String lafProp = System.getProperty("laf");
734 String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
740 else if (lafSetting != null)
744 boolean lafSet = false;
747 case "crossplatform":
748 lafSet = setCrossPlatformLookAndFeel();
751 Cache.log.error("Could not set requested laf=" + laf);
755 lafSet = setSystemLookAndFeel();
758 Cache.log.error("Could not set requested laf=" + laf);
762 lafSet = setGtkLookAndFeel();
765 Cache.log.error("Could not set requested laf=" + laf);
769 lafSet = setMetalLookAndFeel();
772 Cache.log.error("Could not set requested laf=" + laf);
776 lafSet = setNimbusLookAndFeel();
779 Cache.log.error("Could not set requested laf=" + laf);
783 lafSet = setQuaquaLookAndFeel();
786 Cache.log.error("Could not set requested laf=" + laf);
790 lafSet = setVaquaLookAndFeel();
793 Cache.log.error("Could not set requested laf=" + laf);
797 lafSet = setMacLookAndFeel();
800 Cache.log.error("Could not set requested laf=" + laf);
806 Cache.log.error("Requested laf=" + laf + " not implemented");
810 setSystemLookAndFeel();
811 if (Platform.isLinux())
813 setMetalLookAndFeel();
815 if (Platform.isAMac())
822 private static boolean setCrossPlatformLookAndFeel()
827 UIManager.setLookAndFeel(
828 UIManager.getCrossPlatformLookAndFeelClassName());
830 } catch (Exception ex)
832 Cache.log.error("Unexpected Look and Feel Exception");
833 Cache.log.error(ex.getMessage());
834 Cache.log.debug(Cache.getStackTraceString(ex));
839 private static boolean setSystemLookAndFeel()
844 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
846 } catch (Exception ex)
848 Cache.log.error("Unexpected Look and Feel Exception");
849 Cache.log.error(ex.getMessage());
850 Cache.log.debug(Cache.getStackTraceString(ex));
855 private static boolean setSpecificLookAndFeel(String name,
856 String className, boolean nameStartsWith)
861 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
863 if (info.getName() != null && nameStartsWith
864 ? info.getName().toLowerCase()
865 .startsWith(name.toLowerCase())
866 : info.getName().toLowerCase().equals(name.toLowerCase()))
868 className = info.getClassName();
872 UIManager.setLookAndFeel(className);
874 } catch (Exception ex)
876 Cache.log.error("Unexpected Look and Feel Exception");
877 Cache.log.error(ex.getMessage());
878 Cache.log.debug(Cache.getStackTraceString(ex));
883 private static boolean setGtkLookAndFeel()
885 return setSpecificLookAndFeel("gtk",
886 "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true);
889 private static boolean setMetalLookAndFeel()
891 return setSpecificLookAndFeel("metal",
892 "javax.swing.plaf.metal.MetalLookAndFeel", false);
895 private static boolean setNimbusLookAndFeel()
897 return setSpecificLookAndFeel("nimbus",
898 "javax.swing.plaf.nimbus.NimbusLookAndFeel", false);
901 private static boolean setQuaquaLookAndFeel()
903 return setSpecificLookAndFeel("quaqua",
904 ch.randelshofer.quaqua.QuaquaManager.getLookAndFeel().getClass()
909 private static boolean setVaquaLookAndFeel()
911 return setSpecificLookAndFeel("vaqua",
912 "org.violetlib.aqua.AquaLookAndFeel", false);
915 private static boolean setMacLookAndFeel()
918 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
920 System.setProperty("apple.laf.useScreenMenuBar", "true");
921 set = setQuaquaLookAndFeel();
922 if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
923 .toLowerCase().contains("quaqua"))
925 set = setVaquaLookAndFeel();
930 private static void showUsage()
933 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
934 + "-nodisplay\tRun Jalview without User Interface.\n"
935 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
936 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
937 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
938 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
939 + "-features FILE\tUse the given file to mark features on the alignment.\n"
940 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
941 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
942 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
943 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
944 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
945 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
946 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
947 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
948 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
949 + "-png FILE\tCreate PNG image FILE from alignment.\n"
950 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
951 + "-html FILE\tCreate HTML file from alignment.\n"
952 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
953 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
954 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
955 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
956 + "-noquestionnaire\tTurn off questionnaire check.\n"
957 + "-nonews\tTurn off check for Jalview news.\n"
958 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
959 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
961 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
962 // after all other properties files have been read\n\t
963 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
964 // passed in correctly)"
965 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
966 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
967 + "-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"
968 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
971 private static void startUsageStats(final Desktop desktop)
974 * start a User Config prompt asking if we can log usage statistics.
976 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
977 "USAGESTATS", "Jalview Usage Statistics",
978 "Do you want to help make Jalview better by enabling "
979 + "the collection of usage statistics with Google Analytics ?"
980 + "\n\n(you can enable or disable usage tracking in the preferences)",
987 "Initialising googletracker for usage stats.");
988 Cache.initGoogleTracker();
989 Cache.log.debug("Tracking enabled.");
996 Cache.log.debug("Not enabling Google Tracking.");
999 desktop.addDialogThread(prompter);
1003 * Locate the given string as a file and pass it to the groovy interpreter.
1005 * @param groovyscript
1006 * the script to execute
1007 * @param jalviewContext
1008 * the Jalview Desktop object passed in to the groovy binding as the
1011 private void executeGroovyScript(String groovyscript, AlignFrame af)
1014 * for scripts contained in files
1021 if (groovyscript.trim().equals("STDIN"))
1023 // read from stdin into a tempfile and execute it
1026 tfile = File.createTempFile("jalview", "groovy");
1027 PrintWriter outfile = new PrintWriter(
1028 new OutputStreamWriter(new FileOutputStream(tfile)));
1029 BufferedReader br = new BufferedReader(
1030 new InputStreamReader(System.in));
1032 while ((line = br.readLine()) != null)
1034 outfile.write(line + "\n");
1040 } catch (Exception ex)
1042 System.err.println("Failed to read from STDIN into tempfile "
1043 + ((tfile == null) ? "(tempfile wasn't created)"
1044 : tfile.toString()));
1045 ex.printStackTrace();
1050 sfile = tfile.toURI().toURL();
1051 } catch (Exception x)
1054 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1056 x.printStackTrace();
1064 sfile = new URI(groovyscript).toURL();
1065 } catch (Exception x)
1067 tfile = new File(groovyscript);
1068 if (!tfile.exists())
1070 System.err.println("File '" + groovyscript + "' does not exist.");
1073 if (!tfile.canRead())
1075 System.err.println("File '" + groovyscript + "' cannot be read.");
1078 if (tfile.length() < 1)
1080 System.err.println("File '" + groovyscript + "' is empty.");
1085 sfile = tfile.getAbsoluteFile().toURI().toURL();
1086 } catch (Exception ex)
1088 System.err.println("Failed to create a file URL for "
1089 + tfile.getAbsoluteFile());
1096 Map<String, java.lang.Object> vbinding = new HashMap<>();
1097 vbinding.put("Jalview", this);
1100 vbinding.put("currentAlFrame", af);
1102 Binding gbinding = new Binding(vbinding);
1103 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1104 gse.run(sfile.toString(), gbinding);
1105 if ("STDIN".equals(groovyscript))
1107 // delete temp file that we made -
1108 // only if it was successfully executed
1111 } catch (Exception e)
1113 System.err.println("Exception Whilst trying to execute file " + sfile
1114 + " as a groovy script.");
1115 e.printStackTrace(System.err);
1120 public static boolean isHeadlessMode()
1122 String isheadless = System.getProperty("java.awt.headless");
1123 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1130 public AlignFrame[] getAlignFrames()
1132 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1133 : Desktop.getAlignFrames();
1138 * Quit method delegates to Desktop.quit - unless running in headless mode
1139 * when it just ends the JVM
1143 if (desktop != null)
1153 public static AlignFrame getCurrentAlignFrame()
1155 return Jalview.currentAlignFrame;
1158 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1160 Jalview.currentAlignFrame = currentAlignFrame;