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 desktop.setVisible(true);
334 desktop.startServiceDiscovery();
335 if (!aparser.contains("nousagestats"))
337 startUsageStats(desktop);
341 System.err.println("CMD [-nousagestats] executed successfully!");
344 if (!aparser.contains("noquestionnaire"))
346 String url = aparser.getValue("questionnaire");
349 // Start the desktop questionnaire prompter with the specified
351 Cache.log.debug("Starting questionnaire url at " + url);
352 desktop.checkForQuestionnaire(url);
354 "CMD questionnaire[-" + url + "] executed successfully!");
358 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
360 // Start the desktop questionnaire prompter with the specified
363 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
365 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
367 "Starting questionnaire with default url: " + defurl);
368 desktop.checkForQuestionnaire(defurl);
374 System.err.println("CMD [-noquestionnaire] executed successfully!");
377 if (!aparser.contains("nonews"))
379 desktop.checkForNews();
382 BioJsHTMLOutput.updateBioJS();
385 // Move any new getdown-launcher-new.jar into place over old
386 // getdown-launcher.jar
387 String appdirString = System.getProperty("getdownappdir");
388 if (appdirString != null && appdirString.length() > 0)
390 final File appdir = new File(appdirString);
396 LaunchUtil.upgradeGetdown(
397 new File(appdir, "getdown-launcher-old.jar"),
398 new File(appdir, "getdown-launcher.jar"),
399 new File(appdir, "getdown-launcher-new.jar"));
404 String file = null, data = null;
405 FileFormatI format = null;
406 DataSourceType protocol = null;
407 FileLoader fileLoader = new FileLoader(!headless);
409 String groovyscript = null; // script to execute after all loading is
410 // completed one way or another
411 // extract groovy argument and execute if necessary
412 groovyscript = aparser.getValue("groovy", true);
413 file = aparser.getValue("open", true);
415 if (file == null && desktop == null)
417 System.out.println("No files to open!");
421 // Finally, deal with the remaining input data.
426 desktop.setProgressBar(
428 .getString("status.processing_commandline_args"),
429 progress = System.currentTimeMillis());
431 System.out.println("CMD [-open " + file + "] executed successfully!");
433 if (!HttpUtils.startsWithHttpOrHttps(file))
435 if (!(new File(file)).exists())
437 System.out.println("Can't find " + file);
445 protocol = AppletFormatAdapter.checkProtocol(file);
449 format = new IdentifyFile().identify(file, protocol);
450 } catch (FileFormatException e1)
455 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
459 System.out.println("error");
463 setCurrentAlignFrame(af);
464 data = aparser.getValue("colour", true);
467 data.replaceAll("%20", " ");
469 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
470 af.getViewport(), af.getViewport().getAlignment(), data);
475 "CMD [-color " + data + "] executed successfully!");
480 // Must maintain ability to use the groups flag
481 data = aparser.getValue("groups", true);
484 af.parseFeaturesFile(data,
485 AppletFormatAdapter.checkProtocol(data));
486 // System.out.println("Added " + data);
488 "CMD groups[-" + data + "] executed successfully!");
490 data = aparser.getValue("features", true);
493 af.parseFeaturesFile(data,
494 AppletFormatAdapter.checkProtocol(data));
495 // System.out.println("Added " + data);
497 "CMD [-features " + data + "] executed successfully!");
500 data = aparser.getValue("annotations", true);
503 af.loadJalviewDataFile(data, null, null, null);
504 // System.out.println("Added " + data);
506 "CMD [-annotations " + data + "] executed successfully!");
508 // set or clear the sortbytree flag.
509 if (aparser.contains("sortbytree"))
511 af.getViewport().setSortByTree(true);
512 if (af.getViewport().getSortByTree())
514 System.out.println("CMD [-sortbytree] executed successfully!");
517 if (aparser.contains("no-annotation"))
519 af.getViewport().setShowAnnotation(false);
520 if (!af.getViewport().isShowAnnotation())
522 System.out.println("CMD no-annotation executed successfully!");
525 if (aparser.contains("nosortbytree"))
527 af.getViewport().setSortByTree(false);
528 if (!af.getViewport().getSortByTree())
531 .println("CMD [-nosortbytree] executed successfully!");
534 data = aparser.getValue("tree", true);
540 "CMD [-tree " + data + "] executed successfully!");
541 NewickFile nf = new NewickFile(data,
542 AppletFormatAdapter.checkProtocol(data));
544 .setCurrentTree(af.showNewickTree(nf, data).getTree());
545 } catch (IOException ex)
547 System.err.println("Couldn't add tree " + data);
548 ex.printStackTrace(System.err);
551 // TODO - load PDB structure(s) to alignment JAL-629
552 // (associate with identical sequence in alignment, or a specified
554 if (groovyscript != null)
556 // Execute the groovy script after we've done all the rendering stuff
557 // and before any images or figures are generated.
558 System.out.println("Executing script " + groovyscript);
559 executeGroovyScript(groovyscript, af);
560 System.out.println("CMD groovy[" + groovyscript
561 + "] executed successfully!");
564 String imageName = "unnamed.png";
565 while (aparser.getSize() > 1)
567 String outputFormat = aparser.nextValue();
568 file = aparser.nextValue();
570 if (outputFormat.equalsIgnoreCase("png"))
572 af.createPNG(new File(file));
573 imageName = (new File(file)).getName();
574 System.out.println("Creating PNG image: " + file);
577 else if (outputFormat.equalsIgnoreCase("svg"))
579 File imageFile = new File(file);
580 imageName = imageFile.getName();
581 af.createSVG(imageFile);
582 System.out.println("Creating SVG image: " + file);
585 else if (outputFormat.equalsIgnoreCase("html"))
587 File imageFile = new File(file);
588 imageName = imageFile.getName();
589 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
590 htmlSVG.exportHTML(file);
592 System.out.println("Creating HTML image: " + file);
595 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
599 System.err.println("The output html file must not be null");
604 BioJsHTMLOutput.refreshVersionInfo(
605 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
606 } catch (URISyntaxException e)
610 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
611 bjs.exportHTML(file);
613 .println("Creating BioJS MSA Viwer HTML file: " + file);
616 else if (outputFormat.equalsIgnoreCase("imgMap"))
618 af.createImageMap(new File(file), imageName);
619 System.out.println("Creating image map: " + file);
622 else if (outputFormat.equalsIgnoreCase("eps"))
624 File outputFile = new File(file);
626 "Creating EPS file: " + outputFile.getAbsolutePath());
627 af.createEPS(outputFile);
631 if (af.saveAlignment(file, format))
633 System.out.println("Written alignment in " + format
634 + " format to " + file);
638 System.out.println("Error writing file " + file + " in "
639 + format + " format!!");
644 while (aparser.getSize() > 0)
646 System.out.println("Unknown arg: " + aparser.nextValue());
650 AlignFrame startUpAlframe = null;
651 // We'll only open the default file if the desktop is visible.
653 // ////////////////////
655 if (!headless && file == null
656 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
658 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
659 jalview.bin.Cache.getDefault("www.jalview.org",
660 "http://www.jalview.org")
661 + "/examples/exampleFile_2_7.jar");
663 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
665 // hardwire upgrade of the startup file
666 file.replace("_2_3.jar", "_2_7.jar");
667 // and remove the stale setting
668 jalview.bin.Cache.removeProperty("STARTUP_FILE");
671 protocol = DataSourceType.FILE;
673 if (file.indexOf("http:") > -1)
675 protocol = DataSourceType.URL;
678 if (file.endsWith(".jar"))
680 format = FileFormat.Jalview;
686 format = new IdentifyFile().identify(file, protocol);
687 } catch (FileFormatException e)
693 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
695 // extract groovy arguments before anything else.
698 // Once all other stuff is done, execute any groovy scripts (in order)
699 if (groovyscript != null)
701 if (Cache.groovyJarsPresent())
703 System.out.println("Executing script " + groovyscript);
704 executeGroovyScript(groovyscript, startUpAlframe);
709 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
713 // and finally, turn off batch mode indicator - if the desktop still exists
718 desktop.setProgressBar(null, progress);
720 desktop.setInBatchMode(false);
724 private static void setLookAndFeel()
726 // property laf = "crossplatform", "system", "gtk", "metal", "nimbus" or
728 // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
730 String lafProp = System.getProperty("laf");
731 String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
737 else if (lafSetting != null)
741 boolean lafSet = false;
744 case "crossplatform":
745 lafSet = setCrossPlatformLookAndFeel();
748 Cache.log.error("Could not set requested laf=" + laf);
752 lafSet = setSystemLookAndFeel();
755 Cache.log.error("Could not set requested laf=" + laf);
759 lafSet = setGtkLookAndFeel();
762 Cache.log.error("Could not set requested laf=" + laf);
766 lafSet = setMetalLookAndFeel();
769 Cache.log.error("Could not set requested laf=" + laf);
773 lafSet = setNimbusLookAndFeel();
776 Cache.log.error("Could not set requested laf=" + laf);
780 lafSet = setQuaquaLookAndFeel();
783 Cache.log.error("Could not set requested laf=" + laf);
787 lafSet = setVaquaLookAndFeel();
790 Cache.log.error("Could not set requested laf=" + laf);
794 lafSet = setMacLookAndFeel();
797 Cache.log.error("Could not set requested laf=" + laf);
803 Cache.log.error("Requested laf=" + laf + " not implemented");
807 setSystemLookAndFeel();
808 if (Platform.isLinux())
810 setMetalLookAndFeel();
812 if (Platform.isAMac())
819 private static boolean setCrossPlatformLookAndFeel()
824 UIManager.setLookAndFeel(
825 UIManager.getCrossPlatformLookAndFeelClassName());
827 } catch (Exception ex)
829 Cache.log.error("Unexpected Look and Feel Exception");
830 Cache.log.error(ex.getMessage());
831 Cache.log.debug(Cache.getStackTraceString(ex));
836 private static boolean setSystemLookAndFeel()
841 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
843 } catch (Exception ex)
845 Cache.log.error("Unexpected Look and Feel Exception");
846 Cache.log.error(ex.getMessage());
847 Cache.log.debug(Cache.getStackTraceString(ex));
852 private static boolean setSpecificLookAndFeel(String name,
853 String className, boolean nameStartsWith)
858 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
860 if (info.getName() != null && nameStartsWith
861 ? info.getName().toLowerCase()
862 .startsWith(name.toLowerCase())
863 : info.getName().toLowerCase().equals(name.toLowerCase()))
865 className = info.getClassName();
869 UIManager.setLookAndFeel(className);
871 } catch (Exception ex)
873 Cache.log.error("Unexpected Look and Feel Exception");
874 Cache.log.error(ex.getMessage());
875 Cache.log.debug(Cache.getStackTraceString(ex));
880 private static boolean setGtkLookAndFeel()
882 return setSpecificLookAndFeel("gtk",
883 "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true);
886 private static boolean setMetalLookAndFeel()
888 return setSpecificLookAndFeel("metal",
889 "javax.swing.plaf.metal.MetalLookAndFeel", false);
892 private static boolean setNimbusLookAndFeel()
894 return setSpecificLookAndFeel("nimbus",
895 "javax.swing.plaf.nimbus.NimbusLookAndFeel", false);
898 private static boolean setQuaquaLookAndFeel()
900 return setSpecificLookAndFeel("quaqua",
901 ch.randelshofer.quaqua.QuaquaManager.getLookAndFeel().getClass()
906 private static boolean setVaquaLookAndFeel()
908 return setSpecificLookAndFeel("vaqua",
909 "org.violetlib.aqua.AquaLookAndFeel", false);
912 private static boolean setMacLookAndFeel()
915 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
917 System.setProperty("apple.laf.useScreenMenuBar", "true");
918 set = setQuaquaLookAndFeel();
919 if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
920 .toLowerCase().contains("quaqua"))
922 set = setVaquaLookAndFeel();
927 private static void showUsage()
930 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
931 + "-nodisplay\tRun Jalview without User Interface.\n"
932 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
933 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
934 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
935 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
936 + "-features FILE\tUse the given file to mark features on the alignment.\n"
937 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
938 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
939 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
940 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
941 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
942 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
943 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
944 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
945 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
946 + "-png FILE\tCreate PNG image FILE from alignment.\n"
947 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
948 + "-html FILE\tCreate HTML file from alignment.\n"
949 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
950 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
951 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
952 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
953 + "-noquestionnaire\tTurn off questionnaire check.\n"
954 + "-nonews\tTurn off check for Jalview news.\n"
955 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
956 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
958 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
959 // after all other properties files have been read\n\t
960 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
961 // passed in correctly)"
962 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
963 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
964 + "-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"
965 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
968 private static void startUsageStats(final Desktop desktop)
971 * start a User Config prompt asking if we can log usage statistics.
973 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
974 "USAGESTATS", "Jalview Usage Statistics",
975 "Do you want to help make Jalview better by enabling "
976 + "the collection of usage statistics with Google Analytics ?"
977 + "\n\n(you can enable or disable usage tracking in the preferences)",
984 "Initialising googletracker for usage stats.");
985 Cache.initGoogleTracker();
986 Cache.log.debug("Tracking enabled.");
993 Cache.log.debug("Not enabling Google Tracking.");
996 desktop.addDialogThread(prompter);
1000 * Locate the given string as a file and pass it to the groovy interpreter.
1002 * @param groovyscript
1003 * the script to execute
1004 * @param jalviewContext
1005 * the Jalview Desktop object passed in to the groovy binding as the
1008 private void executeGroovyScript(String groovyscript, AlignFrame af)
1011 * for scripts contained in files
1018 if (groovyscript.trim().equals("STDIN"))
1020 // read from stdin into a tempfile and execute it
1023 tfile = File.createTempFile("jalview", "groovy");
1024 PrintWriter outfile = new PrintWriter(
1025 new OutputStreamWriter(new FileOutputStream(tfile)));
1026 BufferedReader br = new BufferedReader(
1027 new InputStreamReader(System.in));
1029 while ((line = br.readLine()) != null)
1031 outfile.write(line + "\n");
1037 } catch (Exception ex)
1039 System.err.println("Failed to read from STDIN into tempfile "
1040 + ((tfile == null) ? "(tempfile wasn't created)"
1041 : tfile.toString()));
1042 ex.printStackTrace();
1047 sfile = tfile.toURI().toURL();
1048 } catch (Exception x)
1051 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1053 x.printStackTrace();
1061 sfile = new URI(groovyscript).toURL();
1062 } catch (Exception x)
1064 tfile = new File(groovyscript);
1065 if (!tfile.exists())
1067 System.err.println("File '" + groovyscript + "' does not exist.");
1070 if (!tfile.canRead())
1072 System.err.println("File '" + groovyscript + "' cannot be read.");
1075 if (tfile.length() < 1)
1077 System.err.println("File '" + groovyscript + "' is empty.");
1082 sfile = tfile.getAbsoluteFile().toURI().toURL();
1083 } catch (Exception ex)
1085 System.err.println("Failed to create a file URL for "
1086 + tfile.getAbsoluteFile());
1093 Map<String, java.lang.Object> vbinding = new HashMap<>();
1094 vbinding.put("Jalview", this);
1097 vbinding.put("currentAlFrame", af);
1099 Binding gbinding = new Binding(vbinding);
1100 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1101 gse.run(sfile.toString(), gbinding);
1102 if ("STDIN".equals(groovyscript))
1104 // delete temp file that we made -
1105 // only if it was successfully executed
1108 } catch (Exception e)
1110 System.err.println("Exception Whilst trying to execute file " + sfile
1111 + " as a groovy script.");
1112 e.printStackTrace(System.err);
1117 public static boolean isHeadlessMode()
1119 String isheadless = System.getProperty("java.awt.headless");
1120 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1127 public AlignFrame[] getAlignFrames()
1129 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1130 : Desktop.getAlignFrames();
1135 * Quit method delegates to Desktop.quit - unless running in headless mode
1136 * when it just ends the JVM
1140 if (desktop != null)
1150 public static AlignFrame getCurrentAlignFrame()
1152 return Jalview.currentAlignFrame;
1155 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1157 Jalview.currentAlignFrame = currentAlignFrame;