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" or "mac"
301 // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
303 String lafProp = System.getProperty("laf");
304 String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
310 else if (lafSetting != null)
314 boolean lafSet = false;
317 case "crossplatform":
318 lafSet = setCrossPlatformLookAndFeel();
321 System.err.println("Could not set requested laf=" + laf);
325 lafSet = setSystemLookAndFeel();
328 System.err.println("Could not set requested laf=" + laf);
332 lafSet = setGtkLookAndFeel();
334 System.err.println("Could not set requested laf=" + laf);
338 lafSet = setMetalLookAndFeel();
340 System.err.println("Could not set requested laf=" + laf);
344 lafSet = setNimbusLookAndFeel();
346 System.err.println("Could not set requested laf=" + laf);
350 lafSet = setQuaquaLookAndFeel();
352 System.err.println("Could not set requested laf=" + laf);
356 lafSet = setVaquaLookAndFeel();
358 System.err.println("Could not set requested laf=" + laf);
362 lafSet = setMacLookAndFeel();
365 System.err.println("Could not set requested laf=" + laf);
371 System.err.println("Requested laf=" + laf + " not implemented");
375 setSystemLookAndFeel();
376 if (Platform.isLinux()) {
377 setMetalLookAndFeel();
379 if (Platform.isAMac())
386 * configure 'full' SO model if preferences say to, else use the default (SO
389 if (Cache.getDefault("USE_FULL_SO", true))
391 SequenceOntologyFactory.setInstance(new SequenceOntology());
396 desktop = new Desktop();
397 desktop.setInBatchMode(true); // indicate we are starting up
401 JalviewTaskbar.setTaskbar(this);
402 } catch (Exception e)
404 System.out.println("Cannot set Taskbar");
405 // e.printStackTrace();
406 } catch (Throwable t)
408 System.out.println("Cannot set Taskbar");
409 // t.printStackTrace();
412 desktop.setVisible(true);
413 desktop.startServiceDiscovery();
414 if (!aparser.contains("nousagestats"))
416 startUsageStats(desktop);
420 System.err.println("CMD [-nousagestats] executed successfully!");
423 if (!aparser.contains("noquestionnaire"))
425 String url = aparser.getValue("questionnaire");
428 // Start the desktop questionnaire prompter with the specified
430 Cache.log.debug("Starting questionnaire url at " + url);
431 desktop.checkForQuestionnaire(url);
433 "CMD questionnaire[-" + url + "] executed successfully!");
437 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
439 // Start the desktop questionnaire prompter with the specified
442 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
444 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
446 "Starting questionnaire with default url: " + defurl);
447 desktop.checkForQuestionnaire(defurl);
453 System.err.println("CMD [-noquestionnaire] executed successfully!");
456 if (!aparser.contains("nonews"))
458 desktop.checkForNews();
461 BioJsHTMLOutput.updateBioJS();
464 // Move any new getdown-launcher-new.jar into place over old
465 // getdown-launcher.jar
466 String appdirString = System.getProperty("getdownappdir");
467 if (appdirString != null && appdirString.length() > 0)
469 final File appdir = new File(appdirString);
475 LaunchUtil.upgradeGetdown(
476 new File(appdir, "getdown-launcher-old.jar"),
477 new File(appdir, "getdown-launcher.jar"),
478 new File(appdir, "getdown-launcher-new.jar"));
483 String file = null, data = null;
484 FileFormatI format = null;
485 DataSourceType protocol = null;
486 FileLoader fileLoader = new FileLoader(!headless);
488 String groovyscript = null; // script to execute after all loading is
489 // completed one way or another
490 // extract groovy argument and execute if necessary
491 groovyscript = aparser.getValue("groovy", true);
492 file = aparser.getValue("open", true);
494 if (file == null && desktop == null)
496 System.out.println("No files to open!");
500 // Finally, deal with the remaining input data.
505 desktop.setProgressBar(
507 .getString("status.processing_commandline_args"),
508 progress = System.currentTimeMillis());
510 System.out.println("CMD [-open " + file + "] executed successfully!");
512 if (!file.startsWith("http://"))
514 if (!(new File(file)).exists())
516 System.out.println("Can't find " + file);
524 protocol = AppletFormatAdapter.checkProtocol(file);
528 format = new IdentifyFile().identify(file, protocol);
529 } catch (FileFormatException e1)
534 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
538 System.out.println("error");
542 setCurrentAlignFrame(af);
543 data = aparser.getValue("colour", true);
546 data.replaceAll("%20", " ");
548 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
549 af.getViewport(), af.getViewport().getAlignment(), data);
554 "CMD [-color " + data + "] executed successfully!");
559 // Must maintain ability to use the groups flag
560 data = aparser.getValue("groups", true);
563 af.parseFeaturesFile(data,
564 AppletFormatAdapter.checkProtocol(data));
565 // System.out.println("Added " + data);
567 "CMD groups[-" + data + "] executed successfully!");
569 data = aparser.getValue("features", true);
572 af.parseFeaturesFile(data,
573 AppletFormatAdapter.checkProtocol(data));
574 // System.out.println("Added " + data);
576 "CMD [-features " + data + "] executed successfully!");
579 data = aparser.getValue("annotations", true);
582 af.loadJalviewDataFile(data, null, null, null);
583 // System.out.println("Added " + data);
585 "CMD [-annotations " + data + "] executed successfully!");
587 // set or clear the sortbytree flag.
588 if (aparser.contains("sortbytree"))
590 af.getViewport().setSortByTree(true);
591 if (af.getViewport().getSortByTree())
593 System.out.println("CMD [-sortbytree] executed successfully!");
596 if (aparser.contains("no-annotation"))
598 af.getViewport().setShowAnnotation(false);
599 if (!af.getViewport().isShowAnnotation())
601 System.out.println("CMD no-annotation executed successfully!");
604 if (aparser.contains("nosortbytree"))
606 af.getViewport().setSortByTree(false);
607 if (!af.getViewport().getSortByTree())
610 .println("CMD [-nosortbytree] executed successfully!");
613 data = aparser.getValue("tree", true);
619 "CMD [-tree " + data + "] executed successfully!");
620 NewickFile nf = new NewickFile(data,
621 AppletFormatAdapter.checkProtocol(data));
623 .setCurrentTree(af.showNewickTree(nf, data).getTree());
624 } catch (IOException ex)
626 System.err.println("Couldn't add tree " + data);
627 ex.printStackTrace(System.err);
630 // TODO - load PDB structure(s) to alignment JAL-629
631 // (associate with identical sequence in alignment, or a specified
633 if (groovyscript != null)
635 // Execute the groovy script after we've done all the rendering stuff
636 // and before any images or figures are generated.
637 System.out.println("Executing script " + groovyscript);
638 executeGroovyScript(groovyscript, af);
639 System.out.println("CMD groovy[" + groovyscript
640 + "] executed successfully!");
643 String imageName = "unnamed.png";
644 while (aparser.getSize() > 1)
646 String outputFormat = aparser.nextValue();
647 file = aparser.nextValue();
649 if (outputFormat.equalsIgnoreCase("png"))
651 af.createPNG(new File(file));
652 imageName = (new File(file)).getName();
653 System.out.println("Creating PNG image: " + file);
656 else if (outputFormat.equalsIgnoreCase("svg"))
658 File imageFile = new File(file);
659 imageName = imageFile.getName();
660 af.createSVG(imageFile);
661 System.out.println("Creating SVG image: " + file);
664 else if (outputFormat.equalsIgnoreCase("html"))
666 File imageFile = new File(file);
667 imageName = imageFile.getName();
668 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
669 htmlSVG.exportHTML(file);
671 System.out.println("Creating HTML image: " + file);
674 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
678 System.err.println("The output html file must not be null");
683 BioJsHTMLOutput.refreshVersionInfo(
684 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
685 } catch (URISyntaxException e)
689 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
690 bjs.exportHTML(file);
692 .println("Creating BioJS MSA Viwer HTML file: " + file);
695 else if (outputFormat.equalsIgnoreCase("imgMap"))
697 af.createImageMap(new File(file), imageName);
698 System.out.println("Creating image map: " + file);
701 else if (outputFormat.equalsIgnoreCase("eps"))
703 File outputFile = new File(file);
705 "Creating EPS file: " + outputFile.getAbsolutePath());
706 af.createEPS(outputFile);
710 if (af.saveAlignment(file, format))
712 System.out.println("Written alignment in " + format
713 + " format to " + file);
717 System.out.println("Error writing file " + file + " in "
718 + format + " format!!");
723 while (aparser.getSize() > 0)
725 System.out.println("Unknown arg: " + aparser.nextValue());
729 AlignFrame startUpAlframe = null;
730 // We'll only open the default file if the desktop is visible.
732 // ////////////////////
734 if (!headless && file == null
735 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
737 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
738 jalview.bin.Cache.getDefault("www.jalview.org",
739 "http://www.jalview.org")
740 + "/examples/exampleFile_2_7.jar");
742 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
744 // hardwire upgrade of the startup file
745 file.replace("_2_3.jar", "_2_7.jar");
746 // and remove the stale setting
747 jalview.bin.Cache.removeProperty("STARTUP_FILE");
750 protocol = DataSourceType.FILE;
752 if (file.indexOf("http:") > -1)
754 protocol = DataSourceType.URL;
757 if (file.endsWith(".jar"))
759 format = FileFormat.Jalview;
765 format = new IdentifyFile().identify(file, protocol);
766 } catch (FileFormatException e)
772 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
774 // extract groovy arguments before anything else.
777 // Once all other stuff is done, execute any groovy scripts (in order)
778 if (groovyscript != null)
780 if (Cache.groovyJarsPresent())
782 System.out.println("Executing script " + groovyscript);
783 executeGroovyScript(groovyscript, startUpAlframe);
788 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
792 // and finally, turn off batch mode indicator - if the desktop still exists
797 desktop.setProgressBar(null, progress);
799 desktop.setInBatchMode(false);
803 private static boolean setCrossPlatformLookAndFeel()
808 UIManager.setLookAndFeel(
809 UIManager.getCrossPlatformLookAndFeelClassName());
811 } catch (Exception ex)
813 System.err.println("Unexpected Look and Feel Exception");
814 ex.printStackTrace();
819 private static boolean setSystemLookAndFeel()
824 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
826 } catch (Exception ex)
828 System.err.println("Unexpected Look and Feel Exception");
829 ex.printStackTrace();
834 private static boolean setSpecificLookAndFeel(String name,
835 String className, boolean nameStartsWith)
840 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
842 if (info.getName() != null && nameStartsWith
843 ? info.getName().toLowerCase()
844 .startsWith(name.toLowerCase())
845 : info.getName().toLowerCase().equals(name.toLowerCase()))
847 className = info.getClassName();
851 UIManager.setLookAndFeel(className);
853 } catch (Exception ex)
855 System.err.println("Unexpected Look and Feel Exception");
856 ex.printStackTrace();
861 private static boolean setGtkLookAndFeel()
863 return setSpecificLookAndFeel("gtk",
864 "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true);
867 private static boolean setMetalLookAndFeel()
869 return setSpecificLookAndFeel("metal",
870 "javax.swing.plaf.metal.MetalLookAndFeel", false);
873 private static boolean setNimbusLookAndFeel()
875 return setSpecificLookAndFeel("nimbus",
876 "javax.swing.plaf.nimbus.NimbusLookAndFeel", false);
879 private static boolean setQuaquaLookAndFeel()
881 return setSpecificLookAndFeel("quaqua",
882 ch.randelshofer.quaqua.QuaquaManager.getLookAndFeel().getClass()
887 private static boolean setVaquaLookAndFeel()
889 return setSpecificLookAndFeel("vaqua",
890 "org.violetlib.aqua.AquaLookAndFeel", false);
893 private static boolean setMacLookAndFeel()
896 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
898 System.setProperty("apple.laf.useScreenMenuBar", "true");
899 set = setQuaquaLookAndFeel();
900 if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
901 .toLowerCase().contains("quaqua"))
903 set = setVaquaLookAndFeel();
908 private static void showUsage()
911 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
912 + "-nodisplay\tRun Jalview without User Interface.\n"
913 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
914 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
915 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
916 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
917 + "-features FILE\tUse the given file to mark features on the alignment.\n"
918 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
919 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
920 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
921 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
922 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
923 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
924 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
925 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
926 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
927 + "-png FILE\tCreate PNG image FILE from alignment.\n"
928 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
929 + "-html FILE\tCreate HTML file from alignment.\n"
930 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
931 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
932 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
933 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
934 + "-noquestionnaire\tTurn off questionnaire check.\n"
935 + "-nonews\tTurn off check for Jalview news.\n"
936 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
937 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
939 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
940 // after all other properties files have been read\n\t
941 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
942 // passed in correctly)"
943 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
944 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
945 + "-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"
946 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
949 private static void startUsageStats(final Desktop desktop)
952 * start a User Config prompt asking if we can log usage statistics.
954 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
955 "USAGESTATS", "Jalview Usage Statistics",
956 "Do you want to help make Jalview better by enabling "
957 + "the collection of usage statistics with Google Analytics ?"
958 + "\n\n(you can enable or disable usage tracking in the preferences)",
965 "Initialising googletracker for usage stats.");
966 Cache.initGoogleTracker();
967 Cache.log.debug("Tracking enabled.");
974 Cache.log.debug("Not enabling Google Tracking.");
977 desktop.addDialogThread(prompter);
981 * Locate the given string as a file and pass it to the groovy interpreter.
983 * @param groovyscript
984 * the script to execute
985 * @param jalviewContext
986 * the Jalview Desktop object passed in to the groovy binding as the
989 private void executeGroovyScript(String groovyscript, AlignFrame af)
992 * for scripts contained in files
999 if (groovyscript.trim().equals("STDIN"))
1001 // read from stdin into a tempfile and execute it
1004 tfile = File.createTempFile("jalview", "groovy");
1005 PrintWriter outfile = new PrintWriter(
1006 new OutputStreamWriter(new FileOutputStream(tfile)));
1007 BufferedReader br = new BufferedReader(
1008 new InputStreamReader(System.in));
1010 while ((line = br.readLine()) != null)
1012 outfile.write(line + "\n");
1018 } catch (Exception ex)
1020 System.err.println("Failed to read from STDIN into tempfile "
1021 + ((tfile == null) ? "(tempfile wasn't created)"
1022 : tfile.toString()));
1023 ex.printStackTrace();
1028 sfile = tfile.toURI().toURL();
1029 } catch (Exception x)
1032 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1034 x.printStackTrace();
1042 sfile = new URI(groovyscript).toURL();
1043 } catch (Exception x)
1045 tfile = new File(groovyscript);
1046 if (!tfile.exists())
1048 System.err.println("File '" + groovyscript + "' does not exist.");
1051 if (!tfile.canRead())
1053 System.err.println("File '" + groovyscript + "' cannot be read.");
1056 if (tfile.length() < 1)
1058 System.err.println("File '" + groovyscript + "' is empty.");
1063 sfile = tfile.getAbsoluteFile().toURI().toURL();
1064 } catch (Exception ex)
1066 System.err.println("Failed to create a file URL for "
1067 + tfile.getAbsoluteFile());
1074 Map<String, java.lang.Object> vbinding = new HashMap<>();
1075 vbinding.put("Jalview", this);
1078 vbinding.put("currentAlFrame", af);
1080 Binding gbinding = new Binding(vbinding);
1081 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1082 gse.run(sfile.toString(), gbinding);
1083 if ("STDIN".equals(groovyscript))
1085 // delete temp file that we made -
1086 // only if it was successfully executed
1089 } catch (Exception e)
1091 System.err.println("Exception Whilst trying to execute file " + sfile
1092 + " as a groovy script.");
1093 e.printStackTrace(System.err);
1098 public static boolean isHeadlessMode()
1100 String isheadless = System.getProperty("java.awt.headless");
1101 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1108 public AlignFrame[] getAlignFrames()
1110 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1111 : Desktop.getAlignFrames();
1116 * Quit method delegates to Desktop.quit - unless running in headless mode
1117 * when it just ends the JVM
1121 if (desktop != null)
1131 public static AlignFrame getCurrentAlignFrame()
1133 return Jalview.currentAlignFrame;
1136 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1138 Jalview.currentAlignFrame = currentAlignFrame;