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());
397 desktop = new Desktop();
398 desktop.setInBatchMode(true); // indicate we are starting up
402 JalviewTaskbar.setTaskbar(this);
403 } catch (Exception e)
405 System.out.println("Cannot set Taskbar");
406 // e.printStackTrace();
407 } catch (Throwable t)
409 System.out.println("Cannot set Taskbar");
410 // t.printStackTrace();
413 desktop.setVisible(true);
414 desktop.startServiceDiscovery();
415 if (!aparser.contains("nousagestats"))
417 startUsageStats(desktop);
421 System.err.println("CMD [-nousagestats] executed successfully!");
424 if (!aparser.contains("noquestionnaire"))
426 String url = aparser.getValue("questionnaire");
429 // Start the desktop questionnaire prompter with the specified
431 Cache.log.debug("Starting questionnaire url at " + url);
432 desktop.checkForQuestionnaire(url);
434 "CMD questionnaire[-" + url + "] executed successfully!");
438 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
440 // Start the desktop questionnaire prompter with the specified
443 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
445 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
447 "Starting questionnaire with default url: " + defurl);
448 desktop.checkForQuestionnaire(defurl);
454 System.err.println("CMD [-noquestionnaire] executed successfully!");
457 if (!aparser.contains("nonews"))
459 desktop.checkForNews();
462 BioJsHTMLOutput.updateBioJS();
465 // Move any new getdown-launcher-new.jar into place over old
466 // getdown-launcher.jar
467 String appdirString = System.getProperty("getdownappdir");
468 if (appdirString != null && appdirString.length() > 0)
470 final File appdir = new File(appdirString);
476 LaunchUtil.upgradeGetdown(
477 new File(appdir, "getdown-launcher-old.jar"),
478 new File(appdir, "getdown-launcher.jar"),
479 new File(appdir, "getdown-launcher-new.jar"));
484 String file = null, data = null;
485 FileFormatI format = null;
486 DataSourceType protocol = null;
487 FileLoader fileLoader = new FileLoader(!headless);
489 String groovyscript = null; // script to execute after all loading is
490 // completed one way or another
491 // extract groovy argument and execute if necessary
492 groovyscript = aparser.getValue("groovy", true);
493 file = aparser.getValue("open", true);
495 if (file == null && desktop == null)
497 System.out.println("No files to open!");
501 // Finally, deal with the remaining input data.
506 desktop.setProgressBar(
508 .getString("status.processing_commandline_args"),
509 progress = System.currentTimeMillis());
511 System.out.println("CMD [-open " + file + "] executed successfully!");
513 if (!file.startsWith("http://"))
515 if (!(new File(file)).exists())
517 System.out.println("Can't find " + file);
525 protocol = AppletFormatAdapter.checkProtocol(file);
529 format = new IdentifyFile().identify(file, protocol);
530 } catch (FileFormatException e1)
535 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
539 System.out.println("error");
543 setCurrentAlignFrame(af);
544 data = aparser.getValue("colour", true);
547 data.replaceAll("%20", " ");
549 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
550 af.getViewport(), af.getViewport().getAlignment(), data);
555 "CMD [-color " + data + "] executed successfully!");
560 // Must maintain ability to use the groups flag
561 data = aparser.getValue("groups", true);
564 af.parseFeaturesFile(data,
565 AppletFormatAdapter.checkProtocol(data));
566 // System.out.println("Added " + data);
568 "CMD groups[-" + data + "] executed successfully!");
570 data = aparser.getValue("features", true);
573 af.parseFeaturesFile(data,
574 AppletFormatAdapter.checkProtocol(data));
575 // System.out.println("Added " + data);
577 "CMD [-features " + data + "] executed successfully!");
580 data = aparser.getValue("annotations", true);
583 af.loadJalviewDataFile(data, null, null, null);
584 // System.out.println("Added " + data);
586 "CMD [-annotations " + data + "] executed successfully!");
588 // set or clear the sortbytree flag.
589 if (aparser.contains("sortbytree"))
591 af.getViewport().setSortByTree(true);
592 if (af.getViewport().getSortByTree())
594 System.out.println("CMD [-sortbytree] executed successfully!");
597 if (aparser.contains("no-annotation"))
599 af.getViewport().setShowAnnotation(false);
600 if (!af.getViewport().isShowAnnotation())
602 System.out.println("CMD no-annotation executed successfully!");
605 if (aparser.contains("nosortbytree"))
607 af.getViewport().setSortByTree(false);
608 if (!af.getViewport().getSortByTree())
611 .println("CMD [-nosortbytree] executed successfully!");
614 data = aparser.getValue("tree", true);
620 "CMD [-tree " + data + "] executed successfully!");
621 NewickFile nf = new NewickFile(data,
622 AppletFormatAdapter.checkProtocol(data));
624 .setCurrentTree(af.showNewickTree(nf, data).getTree());
625 } catch (IOException ex)
627 System.err.println("Couldn't add tree " + data);
628 ex.printStackTrace(System.err);
631 // TODO - load PDB structure(s) to alignment JAL-629
632 // (associate with identical sequence in alignment, or a specified
634 if (groovyscript != null)
636 // Execute the groovy script after we've done all the rendering stuff
637 // and before any images or figures are generated.
638 System.out.println("Executing script " + groovyscript);
639 executeGroovyScript(groovyscript, af);
640 System.out.println("CMD groovy[" + groovyscript
641 + "] executed successfully!");
644 String imageName = "unnamed.png";
645 while (aparser.getSize() > 1)
647 String outputFormat = aparser.nextValue();
648 file = aparser.nextValue();
650 if (outputFormat.equalsIgnoreCase("png"))
652 af.createPNG(new File(file));
653 imageName = (new File(file)).getName();
654 System.out.println("Creating PNG image: " + file);
657 else if (outputFormat.equalsIgnoreCase("svg"))
659 File imageFile = new File(file);
660 imageName = imageFile.getName();
661 af.createSVG(imageFile);
662 System.out.println("Creating SVG image: " + file);
665 else if (outputFormat.equalsIgnoreCase("html"))
667 File imageFile = new File(file);
668 imageName = imageFile.getName();
669 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
670 htmlSVG.exportHTML(file);
672 System.out.println("Creating HTML image: " + file);
675 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
679 System.err.println("The output html file must not be null");
684 BioJsHTMLOutput.refreshVersionInfo(
685 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
686 } catch (URISyntaxException e)
690 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
691 bjs.exportHTML(file);
693 .println("Creating BioJS MSA Viwer HTML file: " + file);
696 else if (outputFormat.equalsIgnoreCase("imgMap"))
698 af.createImageMap(new File(file), imageName);
699 System.out.println("Creating image map: " + file);
702 else if (outputFormat.equalsIgnoreCase("eps"))
704 File outputFile = new File(file);
706 "Creating EPS file: " + outputFile.getAbsolutePath());
707 af.createEPS(outputFile);
711 if (af.saveAlignment(file, format))
713 System.out.println("Written alignment in " + format
714 + " format to " + file);
718 System.out.println("Error writing file " + file + " in "
719 + format + " format!!");
724 while (aparser.getSize() > 0)
726 System.out.println("Unknown arg: " + aparser.nextValue());
730 AlignFrame startUpAlframe = null;
731 // We'll only open the default file if the desktop is visible.
733 // ////////////////////
735 if (!headless && file == null
736 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
738 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
739 jalview.bin.Cache.getDefault("www.jalview.org",
740 "http://www.jalview.org")
741 + "/examples/exampleFile_2_7.jar");
743 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
745 // hardwire upgrade of the startup file
746 file.replace("_2_3.jar", "_2_7.jar");
747 // and remove the stale setting
748 jalview.bin.Cache.removeProperty("STARTUP_FILE");
751 protocol = DataSourceType.FILE;
753 if (file.indexOf("http:") > -1)
755 protocol = DataSourceType.URL;
758 if (file.endsWith(".jar"))
760 format = FileFormat.Jalview;
766 format = new IdentifyFile().identify(file, protocol);
767 } catch (FileFormatException e)
773 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
775 // extract groovy arguments before anything else.
778 // Once all other stuff is done, execute any groovy scripts (in order)
779 if (groovyscript != null)
781 if (Cache.groovyJarsPresent())
783 System.out.println("Executing script " + groovyscript);
784 executeGroovyScript(groovyscript, startUpAlframe);
789 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
793 // and finally, turn off batch mode indicator - if the desktop still exists
798 desktop.setProgressBar(null, progress);
800 desktop.setInBatchMode(false);
804 private static boolean setCrossPlatformLookAndFeel()
809 UIManager.setLookAndFeel(
810 UIManager.getCrossPlatformLookAndFeelClassName());
812 } catch (Exception ex)
814 System.err.println("Unexpected Look and Feel Exception");
815 ex.printStackTrace();
820 private static boolean setSystemLookAndFeel()
825 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
827 } catch (Exception ex)
829 System.err.println("Unexpected Look and Feel Exception");
830 ex.printStackTrace();
835 private static boolean setSpecificLookAndFeel(String name,
836 String className, boolean nameStartsWith)
841 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
843 if (info.getName() != null && nameStartsWith
844 ? info.getName().toLowerCase()
845 .startsWith(name.toLowerCase())
846 : info.getName().toLowerCase().equals(name.toLowerCase()))
848 className = info.getClassName();
852 UIManager.setLookAndFeel(className);
854 } catch (Exception ex)
856 System.err.println("Unexpected Look and Feel Exception");
857 ex.printStackTrace();
862 private static boolean setGtkLookAndFeel()
864 return setSpecificLookAndFeel("gtk",
865 "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true);
868 private static boolean setMetalLookAndFeel()
870 return setSpecificLookAndFeel("metal",
871 "javax.swing.plaf.metal.MetalLookAndFeel", false);
874 private static boolean setNimbusLookAndFeel()
876 return setSpecificLookAndFeel("nimbus",
877 "javax.swing.plaf.nimbus.NimbusLookAndFeel", false);
880 private static boolean setQuaquaLookAndFeel()
882 return setSpecificLookAndFeel("quaqua",
883 ch.randelshofer.quaqua.QuaquaManager.getLookAndFeel().getClass()
888 private static boolean setVaquaLookAndFeel()
890 return setSpecificLookAndFeel("vaqua",
891 "org.violetlib.aqua.AquaLookAndFeel", false);
894 private static boolean setMacLookAndFeel()
897 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
899 System.setProperty("apple.laf.useScreenMenuBar", "true");
900 set = setQuaquaLookAndFeel();
901 if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
902 .toLowerCase().contains("quaqua"))
904 set = setVaquaLookAndFeel();
909 private static void showUsage()
912 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
913 + "-nodisplay\tRun Jalview without User Interface.\n"
914 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
915 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
916 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
917 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
918 + "-features FILE\tUse the given file to mark features on the alignment.\n"
919 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
920 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
921 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
922 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
923 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
924 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
925 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
926 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
927 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
928 + "-png FILE\tCreate PNG image FILE from alignment.\n"
929 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
930 + "-html FILE\tCreate HTML file from alignment.\n"
931 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
932 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
933 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
934 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
935 + "-noquestionnaire\tTurn off questionnaire check.\n"
936 + "-nonews\tTurn off check for Jalview news.\n"
937 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
938 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
940 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
941 // after all other properties files have been read\n\t
942 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
943 // passed in correctly)"
944 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
945 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
946 + "-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"
947 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
950 private static void startUsageStats(final Desktop desktop)
953 * start a User Config prompt asking if we can log usage statistics.
955 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
956 "USAGESTATS", "Jalview Usage Statistics",
957 "Do you want to help make Jalview better by enabling "
958 + "the collection of usage statistics with Google Analytics ?"
959 + "\n\n(you can enable or disable usage tracking in the preferences)",
966 "Initialising googletracker for usage stats.");
967 Cache.initGoogleTracker();
968 Cache.log.debug("Tracking enabled.");
975 Cache.log.debug("Not enabling Google Tracking.");
978 desktop.addDialogThread(prompter);
982 * Locate the given string as a file and pass it to the groovy interpreter.
984 * @param groovyscript
985 * the script to execute
986 * @param jalviewContext
987 * the Jalview Desktop object passed in to the groovy binding as the
990 private void executeGroovyScript(String groovyscript, AlignFrame af)
993 * for scripts contained in files
1000 if (groovyscript.trim().equals("STDIN"))
1002 // read from stdin into a tempfile and execute it
1005 tfile = File.createTempFile("jalview", "groovy");
1006 PrintWriter outfile = new PrintWriter(
1007 new OutputStreamWriter(new FileOutputStream(tfile)));
1008 BufferedReader br = new BufferedReader(
1009 new InputStreamReader(System.in));
1011 while ((line = br.readLine()) != null)
1013 outfile.write(line + "\n");
1019 } catch (Exception ex)
1021 System.err.println("Failed to read from STDIN into tempfile "
1022 + ((tfile == null) ? "(tempfile wasn't created)"
1023 : tfile.toString()));
1024 ex.printStackTrace();
1029 sfile = tfile.toURI().toURL();
1030 } catch (Exception x)
1033 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1035 x.printStackTrace();
1043 sfile = new URI(groovyscript).toURL();
1044 } catch (Exception x)
1046 tfile = new File(groovyscript);
1047 if (!tfile.exists())
1049 System.err.println("File '" + groovyscript + "' does not exist.");
1052 if (!tfile.canRead())
1054 System.err.println("File '" + groovyscript + "' cannot be read.");
1057 if (tfile.length() < 1)
1059 System.err.println("File '" + groovyscript + "' is empty.");
1064 sfile = tfile.getAbsoluteFile().toURI().toURL();
1065 } catch (Exception ex)
1067 System.err.println("Failed to create a file URL for "
1068 + tfile.getAbsoluteFile());
1075 Map<String, java.lang.Object> vbinding = new HashMap<>();
1076 vbinding.put("Jalview", this);
1079 vbinding.put("currentAlFrame", af);
1081 Binding gbinding = new Binding(vbinding);
1082 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1083 gse.run(sfile.toString(), gbinding);
1084 if ("STDIN".equals(groovyscript))
1086 // delete temp file that we made -
1087 // only if it was successfully executed
1090 } catch (Exception e)
1092 System.err.println("Exception Whilst trying to execute file " + sfile
1093 + " as a groovy script.");
1094 e.printStackTrace(System.err);
1099 public static boolean isHeadlessMode()
1101 String isheadless = System.getProperty("java.awt.headless");
1102 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1109 public AlignFrame[] getAlignFrames()
1111 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1112 : Desktop.getAlignFrames();
1117 * Quit method delegates to Desktop.quit - unless running in headless mode
1118 * when it just ends the JVM
1122 if (desktop != null)
1132 public static AlignFrame getCurrentAlignFrame()
1134 return Jalview.currentAlignFrame;
1137 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1139 Jalview.currentAlignFrame = currentAlignFrame;