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");
303 * configure 'full' SO model if preferences say to, else use the default (SO
306 if (Cache.getDefault("USE_FULL_SO", true))
308 SequenceOntologyFactory.setInstance(new SequenceOntology());
313 desktop = new Desktop();
314 desktop.setInBatchMode(true); // indicate we are starting up
318 JalviewTaskbar.setTaskbar(this);
319 } catch (Exception e)
321 Cache.log.info("Cannot set Taskbar");
322 Cache.log.error(e.getMessage());
323 // e.printStackTrace();
324 } catch (Throwable t)
326 Cache.log.info("Cannot set Taskbar");
327 Cache.log.error(t.getMessage());
328 // t.printStackTrace();
331 desktop.setVisible(true);
332 desktop.startServiceDiscovery();
333 if (!aparser.contains("nousagestats"))
335 startUsageStats(desktop);
339 System.err.println("CMD [-nousagestats] executed successfully!");
342 if (!aparser.contains("noquestionnaire"))
344 String url = aparser.getValue("questionnaire");
347 // Start the desktop questionnaire prompter with the specified
349 Cache.log.debug("Starting questionnaire url at " + url);
350 desktop.checkForQuestionnaire(url);
352 "CMD questionnaire[-" + url + "] executed successfully!");
356 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
358 // Start the desktop questionnaire prompter with the specified
361 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
363 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
365 "Starting questionnaire with default url: " + defurl);
366 desktop.checkForQuestionnaire(defurl);
372 System.err.println("CMD [-noquestionnaire] executed successfully!");
375 if (!aparser.contains("nonews"))
377 desktop.checkForNews();
380 BioJsHTMLOutput.updateBioJS();
383 // Move any new getdown-launcher-new.jar into place over old
384 // getdown-launcher.jar
385 String appdirString = System.getProperty("getdownappdir");
386 if (appdirString != null && appdirString.length() > 0)
388 final File appdir = new File(appdirString);
394 LaunchUtil.upgradeGetdown(
395 new File(appdir, "getdown-launcher-old.jar"),
396 new File(appdir, "getdown-launcher.jar"),
397 new File(appdir, "getdown-launcher-new.jar"));
402 String file = null, data = null;
403 FileFormatI format = null;
404 DataSourceType protocol = null;
405 FileLoader fileLoader = new FileLoader(!headless);
407 String groovyscript = null; // script to execute after all loading is
408 // completed one way or another
409 // extract groovy argument and execute if necessary
410 groovyscript = aparser.getValue("groovy", true);
411 file = aparser.getValue("open", true);
413 if (file == null && desktop == null)
415 System.out.println("No files to open!");
419 // Finally, deal with the remaining input data.
424 desktop.setProgressBar(
426 .getString("status.processing_commandline_args"),
427 progress = System.currentTimeMillis());
429 System.out.println("CMD [-open " + file + "] executed successfully!");
431 if (!file.startsWith("http://"))
433 if (!(new File(file)).exists())
435 System.out.println("Can't find " + file);
443 protocol = AppletFormatAdapter.checkProtocol(file);
447 format = new IdentifyFile().identify(file, protocol);
448 } catch (FileFormatException e1)
453 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
457 System.out.println("error");
461 setCurrentAlignFrame(af);
462 data = aparser.getValue("colour", true);
465 data.replaceAll("%20", " ");
467 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
468 af.getViewport(), af.getViewport().getAlignment(), data);
473 "CMD [-color " + data + "] executed successfully!");
478 // Must maintain ability to use the groups flag
479 data = aparser.getValue("groups", true);
482 af.parseFeaturesFile(data,
483 AppletFormatAdapter.checkProtocol(data));
484 // System.out.println("Added " + data);
486 "CMD groups[-" + data + "] executed successfully!");
488 data = aparser.getValue("features", true);
491 af.parseFeaturesFile(data,
492 AppletFormatAdapter.checkProtocol(data));
493 // System.out.println("Added " + data);
495 "CMD [-features " + data + "] executed successfully!");
498 data = aparser.getValue("annotations", true);
501 af.loadJalviewDataFile(data, null, null, null);
502 // System.out.println("Added " + data);
504 "CMD [-annotations " + data + "] executed successfully!");
506 // set or clear the sortbytree flag.
507 if (aparser.contains("sortbytree"))
509 af.getViewport().setSortByTree(true);
510 if (af.getViewport().getSortByTree())
512 System.out.println("CMD [-sortbytree] executed successfully!");
515 if (aparser.contains("no-annotation"))
517 af.getViewport().setShowAnnotation(false);
518 if (!af.getViewport().isShowAnnotation())
520 System.out.println("CMD no-annotation executed successfully!");
523 if (aparser.contains("nosortbytree"))
525 af.getViewport().setSortByTree(false);
526 if (!af.getViewport().getSortByTree())
529 .println("CMD [-nosortbytree] executed successfully!");
532 data = aparser.getValue("tree", true);
538 "CMD [-tree " + data + "] executed successfully!");
539 NewickFile nf = new NewickFile(data,
540 AppletFormatAdapter.checkProtocol(data));
542 .setCurrentTree(af.showNewickTree(nf, data).getTree());
543 } catch (IOException ex)
545 System.err.println("Couldn't add tree " + data);
546 ex.printStackTrace(System.err);
549 // TODO - load PDB structure(s) to alignment JAL-629
550 // (associate with identical sequence in alignment, or a specified
552 if (groovyscript != null)
554 // Execute the groovy script after we've done all the rendering stuff
555 // and before any images or figures are generated.
556 System.out.println("Executing script " + groovyscript);
557 executeGroovyScript(groovyscript, af);
558 System.out.println("CMD groovy[" + groovyscript
559 + "] executed successfully!");
562 String imageName = "unnamed.png";
563 while (aparser.getSize() > 1)
565 String outputFormat = aparser.nextValue();
566 file = aparser.nextValue();
568 if (outputFormat.equalsIgnoreCase("png"))
570 af.createPNG(new File(file));
571 imageName = (new File(file)).getName();
572 System.out.println("Creating PNG image: " + file);
575 else if (outputFormat.equalsIgnoreCase("svg"))
577 File imageFile = new File(file);
578 imageName = imageFile.getName();
579 af.createSVG(imageFile);
580 System.out.println("Creating SVG image: " + file);
583 else if (outputFormat.equalsIgnoreCase("html"))
585 File imageFile = new File(file);
586 imageName = imageFile.getName();
587 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
588 htmlSVG.exportHTML(file);
590 System.out.println("Creating HTML image: " + file);
593 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
597 System.err.println("The output html file must not be null");
602 BioJsHTMLOutput.refreshVersionInfo(
603 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
604 } catch (URISyntaxException e)
608 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
609 bjs.exportHTML(file);
611 .println("Creating BioJS MSA Viwer HTML file: " + file);
614 else if (outputFormat.equalsIgnoreCase("imgMap"))
616 af.createImageMap(new File(file), imageName);
617 System.out.println("Creating image map: " + file);
620 else if (outputFormat.equalsIgnoreCase("eps"))
622 File outputFile = new File(file);
624 "Creating EPS file: " + outputFile.getAbsolutePath());
625 af.createEPS(outputFile);
629 if (af.saveAlignment(file, format))
631 System.out.println("Written alignment in " + format
632 + " format to " + file);
636 System.out.println("Error writing file " + file + " in "
637 + format + " format!!");
642 while (aparser.getSize() > 0)
644 System.out.println("Unknown arg: " + aparser.nextValue());
648 AlignFrame startUpAlframe = null;
649 // We'll only open the default file if the desktop is visible.
651 // ////////////////////
653 if (!headless && file == null
654 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
656 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
657 jalview.bin.Cache.getDefault("www.jalview.org",
658 "http://www.jalview.org")
659 + "/examples/exampleFile_2_7.jar");
661 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
663 // hardwire upgrade of the startup file
664 file.replace("_2_3.jar", "_2_7.jar");
665 // and remove the stale setting
666 jalview.bin.Cache.removeProperty("STARTUP_FILE");
669 protocol = DataSourceType.FILE;
671 if (file.indexOf("http:") > -1)
673 protocol = DataSourceType.URL;
676 if (file.endsWith(".jar"))
678 format = FileFormat.Jalview;
684 format = new IdentifyFile().identify(file, protocol);
685 } catch (FileFormatException e)
691 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
693 // extract groovy arguments before anything else.
696 // Once all other stuff is done, execute any groovy scripts (in order)
697 if (groovyscript != null)
699 if (Cache.groovyJarsPresent())
701 System.out.println("Executing script " + groovyscript);
702 executeGroovyScript(groovyscript, startUpAlframe);
707 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
711 // and finally, turn off batch mode indicator - if the desktop still exists
716 desktop.setProgressBar(null, progress);
718 desktop.setInBatchMode(false);
722 private static void setLookAndFeel()
724 // property laf = "crossplatform", "system", "gtk", "metal", "nimbus" or
726 // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
728 String lafProp = System.getProperty("laf");
729 String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
735 else if (lafSetting != null)
739 boolean lafSet = false;
742 case "crossplatform":
743 lafSet = setCrossPlatformLookAndFeel();
746 Cache.log.error("Could not set requested laf=" + laf);
750 lafSet = setSystemLookAndFeel();
753 Cache.log.error("Could not set requested laf=" + laf);
757 lafSet = setGtkLookAndFeel();
760 Cache.log.error("Could not set requested laf=" + laf);
764 lafSet = setMetalLookAndFeel();
767 Cache.log.error("Could not set requested laf=" + laf);
771 lafSet = setNimbusLookAndFeel();
774 Cache.log.error("Could not set requested laf=" + laf);
778 lafSet = setQuaquaLookAndFeel();
781 Cache.log.error("Could not set requested laf=" + laf);
785 lafSet = setVaquaLookAndFeel();
788 Cache.log.error("Could not set requested laf=" + laf);
792 lafSet = setMacLookAndFeel();
795 Cache.log.error("Could not set requested laf=" + laf);
801 Cache.log.error("Requested laf=" + laf + " not implemented");
805 setSystemLookAndFeel();
806 if (Platform.isLinux())
808 setMetalLookAndFeel();
810 if (Platform.isAMac())
817 private static boolean setCrossPlatformLookAndFeel()
822 UIManager.setLookAndFeel(
823 UIManager.getCrossPlatformLookAndFeelClassName());
825 } catch (Exception ex)
827 Cache.log.error("Unexpected Look and Feel Exception");
828 Cache.log.error(ex.getMessage());
829 Cache.log.debug(Cache.getStackTraceString(ex));
834 private static boolean setSystemLookAndFeel()
839 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
841 } catch (Exception ex)
843 Cache.log.error("Unexpected Look and Feel Exception");
844 Cache.log.error(ex.getMessage());
845 Cache.log.debug(Cache.getStackTraceString(ex));
850 private static boolean setSpecificLookAndFeel(String name,
851 String className, boolean nameStartsWith)
856 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
858 if (info.getName() != null && nameStartsWith
859 ? info.getName().toLowerCase()
860 .startsWith(name.toLowerCase())
861 : info.getName().toLowerCase().equals(name.toLowerCase()))
863 className = info.getClassName();
867 UIManager.setLookAndFeel(className);
869 } catch (Exception ex)
871 Cache.log.error("Unexpected Look and Feel Exception");
872 Cache.log.error(ex.getMessage());
873 Cache.log.debug(Cache.getStackTraceString(ex));
878 private static boolean setGtkLookAndFeel()
880 return setSpecificLookAndFeel("gtk",
881 "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true);
884 private static boolean setMetalLookAndFeel()
886 return setSpecificLookAndFeel("metal",
887 "javax.swing.plaf.metal.MetalLookAndFeel", false);
890 private static boolean setNimbusLookAndFeel()
892 return setSpecificLookAndFeel("nimbus",
893 "javax.swing.plaf.nimbus.NimbusLookAndFeel", false);
896 private static boolean setQuaquaLookAndFeel()
898 return setSpecificLookAndFeel("quaqua",
899 ch.randelshofer.quaqua.QuaquaManager.getLookAndFeel().getClass()
904 private static boolean setVaquaLookAndFeel()
906 return setSpecificLookAndFeel("vaqua",
907 "org.violetlib.aqua.AquaLookAndFeel", false);
910 private static boolean setMacLookAndFeel()
913 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
915 System.setProperty("apple.laf.useScreenMenuBar", "true");
916 set = setQuaquaLookAndFeel();
917 if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
918 .toLowerCase().contains("quaqua"))
920 set = setVaquaLookAndFeel();
925 private static void showUsage()
928 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
929 + "-nodisplay\tRun Jalview without User Interface.\n"
930 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
931 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
932 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
933 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
934 + "-features FILE\tUse the given file to mark features on the alignment.\n"
935 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
936 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
937 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
938 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
939 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
940 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
941 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
942 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
943 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
944 + "-png FILE\tCreate PNG image FILE from alignment.\n"
945 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
946 + "-html FILE\tCreate HTML file from alignment.\n"
947 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
948 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
949 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
950 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
951 + "-noquestionnaire\tTurn off questionnaire check.\n"
952 + "-nonews\tTurn off check for Jalview news.\n"
953 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
954 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
956 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
957 // after all other properties files have been read\n\t
958 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
959 // passed in correctly)"
960 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
961 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
962 + "-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"
963 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
966 private static void startUsageStats(final Desktop desktop)
969 * start a User Config prompt asking if we can log usage statistics.
971 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
972 "USAGESTATS", "Jalview Usage Statistics",
973 "Do you want to help make Jalview better by enabling "
974 + "the collection of usage statistics with Google Analytics ?"
975 + "\n\n(you can enable or disable usage tracking in the preferences)",
982 "Initialising googletracker for usage stats.");
983 Cache.initGoogleTracker();
984 Cache.log.debug("Tracking enabled.");
991 Cache.log.debug("Not enabling Google Tracking.");
994 desktop.addDialogThread(prompter);
998 * Locate the given string as a file and pass it to the groovy interpreter.
1000 * @param groovyscript
1001 * the script to execute
1002 * @param jalviewContext
1003 * the Jalview Desktop object passed in to the groovy binding as the
1006 private void executeGroovyScript(String groovyscript, AlignFrame af)
1009 * for scripts contained in files
1016 if (groovyscript.trim().equals("STDIN"))
1018 // read from stdin into a tempfile and execute it
1021 tfile = File.createTempFile("jalview", "groovy");
1022 PrintWriter outfile = new PrintWriter(
1023 new OutputStreamWriter(new FileOutputStream(tfile)));
1024 BufferedReader br = new BufferedReader(
1025 new InputStreamReader(System.in));
1027 while ((line = br.readLine()) != null)
1029 outfile.write(line + "\n");
1035 } catch (Exception ex)
1037 System.err.println("Failed to read from STDIN into tempfile "
1038 + ((tfile == null) ? "(tempfile wasn't created)"
1039 : tfile.toString()));
1040 ex.printStackTrace();
1045 sfile = tfile.toURI().toURL();
1046 } catch (Exception x)
1049 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1051 x.printStackTrace();
1059 sfile = new URI(groovyscript).toURL();
1060 } catch (Exception x)
1062 tfile = new File(groovyscript);
1063 if (!tfile.exists())
1065 System.err.println("File '" + groovyscript + "' does not exist.");
1068 if (!tfile.canRead())
1070 System.err.println("File '" + groovyscript + "' cannot be read.");
1073 if (tfile.length() < 1)
1075 System.err.println("File '" + groovyscript + "' is empty.");
1080 sfile = tfile.getAbsoluteFile().toURI().toURL();
1081 } catch (Exception ex)
1083 System.err.println("Failed to create a file URL for "
1084 + tfile.getAbsoluteFile());
1091 Map<String, java.lang.Object> vbinding = new HashMap<>();
1092 vbinding.put("Jalview", this);
1095 vbinding.put("currentAlFrame", af);
1097 Binding gbinding = new Binding(vbinding);
1098 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1099 gse.run(sfile.toString(), gbinding);
1100 if ("STDIN".equals(groovyscript))
1102 // delete temp file that we made -
1103 // only if it was successfully executed
1106 } catch (Exception e)
1108 System.err.println("Exception Whilst trying to execute file " + sfile
1109 + " as a groovy script.");
1110 e.printStackTrace(System.err);
1115 public static boolean isHeadlessMode()
1117 String isheadless = System.getProperty("java.awt.headless");
1118 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1125 public AlignFrame[] getAlignFrames()
1127 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1128 : Desktop.getAlignFrames();
1133 * Quit method delegates to Desktop.quit - unless running in headless mode
1134 * when it just ends the JVM
1138 if (desktop != null)
1148 public static AlignFrame getCurrentAlignFrame()
1150 return Jalview.currentAlignFrame;
1153 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1155 Jalview.currentAlignFrame = currentAlignFrame;