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");
301 // property laf = "crossplatform", "system", "gtk", "metal" or "mac"
302 // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
304 String lafProp = System.getProperty("laf");
305 String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
311 else if (lafSetting != null)
315 boolean lafSet = false;
318 case "crossplatform":
319 lafSet = setCrossPlatformLookAndFeel();
322 System.err.println("Could not set requested laf=" + laf);
326 lafSet = setSystemLookAndFeel();
329 System.err.println("Could not set requested laf=" + laf);
333 lafSet = setGtkLookAndFeel();
335 System.err.println("Could not set requested laf=" + laf);
339 lafSet = setMetalLookAndFeel();
341 System.err.println("Could not set requested laf=" + laf);
345 lafSet = setNimbusLookAndFeel();
347 System.err.println("Could not set requested laf=" + laf);
351 lafSet = setQuaquaLookAndFeel();
353 System.err.println("Could not set requested laf=" + laf);
357 lafSet = setVaquaLookAndFeel();
359 System.err.println("Could not set requested laf=" + laf);
363 lafSet = setMacLookAndFeel();
366 System.err.println("Could not set requested laf=" + laf);
372 System.err.println("Requested laf=" + laf + " not implemented");
376 setSystemLookAndFeel();
377 if (Platform.isLinux())
379 setMetalLookAndFeel();
381 if (Platform.isAMac())
388 * configure 'full' SO model if preferences say to, else use the default (SO
391 if (Cache.getDefault("USE_FULL_SO", true))
393 SequenceOntologyFactory.setInstance(new SequenceOntology());
399 desktop = new Desktop();
400 desktop.setInBatchMode(true); // indicate we are starting up
404 JalviewTaskbar.setTaskbar(this);
405 } catch (Exception e)
407 System.out.println("Cannot set Taskbar");
408 // e.printStackTrace();
409 } catch (Throwable t)
411 System.out.println("Cannot set Taskbar");
412 // t.printStackTrace();
415 desktop.setVisible(true);
416 desktop.startServiceDiscovery();
417 if (!aparser.contains("nousagestats"))
419 startUsageStats(desktop);
423 System.err.println("CMD [-nousagestats] executed successfully!");
426 if (!aparser.contains("noquestionnaire"))
428 String url = aparser.getValue("questionnaire");
431 // Start the desktop questionnaire prompter with the specified
433 Cache.log.debug("Starting questionnaire url at " + url);
434 desktop.checkForQuestionnaire(url);
436 "CMD questionnaire[-" + url + "] executed successfully!");
440 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
442 // Start the desktop questionnaire prompter with the specified
445 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
447 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
449 "Starting questionnaire with default url: " + defurl);
450 desktop.checkForQuestionnaire(defurl);
456 System.err.println("CMD [-noquestionnaire] executed successfully!");
459 if (!aparser.contains("nonews"))
461 desktop.checkForNews();
464 BioJsHTMLOutput.updateBioJS();
467 // Move any new getdown-launcher-new.jar into place over old
468 // getdown-launcher.jar
469 String appdirString = System.getProperty("getdownappdir");
470 if (appdirString != null && appdirString.length() > 0)
472 final File appdir = new File(appdirString);
478 LaunchUtil.upgradeGetdown(
479 new File(appdir, "getdown-launcher-old.jar"),
480 new File(appdir, "getdown-launcher.jar"),
481 new File(appdir, "getdown-launcher-new.jar"));
486 String file = null, data = null;
487 FileFormatI format = null;
488 DataSourceType protocol = null;
489 FileLoader fileLoader = new FileLoader(!headless);
491 String groovyscript = null; // script to execute after all loading is
492 // completed one way or another
493 // extract groovy argument and execute if necessary
494 groovyscript = aparser.getValue("groovy", true);
495 file = aparser.getValue("open", true);
497 if (file == null && desktop == null)
499 System.out.println("No files to open!");
503 // Finally, deal with the remaining input data.
508 desktop.setProgressBar(
510 .getString("status.processing_commandline_args"),
511 progress = System.currentTimeMillis());
513 System.out.println("CMD [-open " + file + "] executed successfully!");
515 if (!HttpUtils.startsWithHttpOrHttps(file))
517 if (!(new File(file)).exists())
519 System.out.println("Can't find " + file);
527 protocol = AppletFormatAdapter.checkProtocol(file);
531 format = new IdentifyFile().identify(file, protocol);
532 } catch (FileFormatException e1)
537 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
541 System.out.println("error");
545 setCurrentAlignFrame(af);
546 data = aparser.getValue("colour", true);
549 data.replaceAll("%20", " ");
551 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
552 af.getViewport(), af.getViewport().getAlignment(), data);
557 "CMD [-color " + data + "] executed successfully!");
562 // Must maintain ability to use the groups flag
563 data = aparser.getValue("groups", true);
566 af.parseFeaturesFile(data,
567 AppletFormatAdapter.checkProtocol(data));
568 // System.out.println("Added " + data);
570 "CMD groups[-" + data + "] executed successfully!");
572 data = aparser.getValue("features", true);
575 af.parseFeaturesFile(data,
576 AppletFormatAdapter.checkProtocol(data));
577 // System.out.println("Added " + data);
579 "CMD [-features " + data + "] executed successfully!");
582 data = aparser.getValue("annotations", true);
585 af.loadJalviewDataFile(data, null, null, null);
586 // System.out.println("Added " + data);
588 "CMD [-annotations " + data + "] executed successfully!");
590 // set or clear the sortbytree flag.
591 if (aparser.contains("sortbytree"))
593 af.getViewport().setSortByTree(true);
594 if (af.getViewport().getSortByTree())
596 System.out.println("CMD [-sortbytree] executed successfully!");
599 if (aparser.contains("no-annotation"))
601 af.getViewport().setShowAnnotation(false);
602 if (!af.getViewport().isShowAnnotation())
604 System.out.println("CMD no-annotation executed successfully!");
607 if (aparser.contains("nosortbytree"))
609 af.getViewport().setSortByTree(false);
610 if (!af.getViewport().getSortByTree())
613 .println("CMD [-nosortbytree] executed successfully!");
616 data = aparser.getValue("tree", true);
622 "CMD [-tree " + data + "] executed successfully!");
623 NewickFile nf = new NewickFile(data,
624 AppletFormatAdapter.checkProtocol(data));
626 .setCurrentTree(af.showNewickTree(nf, data).getTree());
627 } catch (IOException ex)
629 System.err.println("Couldn't add tree " + data);
630 ex.printStackTrace(System.err);
633 // TODO - load PDB structure(s) to alignment JAL-629
634 // (associate with identical sequence in alignment, or a specified
636 if (groovyscript != null)
638 // Execute the groovy script after we've done all the rendering stuff
639 // and before any images or figures are generated.
640 System.out.println("Executing script " + groovyscript);
641 executeGroovyScript(groovyscript, af);
642 System.out.println("CMD groovy[" + groovyscript
643 + "] executed successfully!");
646 String imageName = "unnamed.png";
647 while (aparser.getSize() > 1)
649 String outputFormat = aparser.nextValue();
650 file = aparser.nextValue();
652 if (outputFormat.equalsIgnoreCase("png"))
654 af.createPNG(new File(file));
655 imageName = (new File(file)).getName();
656 System.out.println("Creating PNG image: " + file);
659 else if (outputFormat.equalsIgnoreCase("svg"))
661 File imageFile = new File(file);
662 imageName = imageFile.getName();
663 af.createSVG(imageFile);
664 System.out.println("Creating SVG image: " + file);
667 else if (outputFormat.equalsIgnoreCase("html"))
669 File imageFile = new File(file);
670 imageName = imageFile.getName();
671 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
672 htmlSVG.exportHTML(file);
674 System.out.println("Creating HTML image: " + file);
677 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
681 System.err.println("The output html file must not be null");
686 BioJsHTMLOutput.refreshVersionInfo(
687 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
688 } catch (URISyntaxException e)
692 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
693 bjs.exportHTML(file);
695 .println("Creating BioJS MSA Viwer HTML file: " + file);
698 else if (outputFormat.equalsIgnoreCase("imgMap"))
700 af.createImageMap(new File(file), imageName);
701 System.out.println("Creating image map: " + file);
704 else if (outputFormat.equalsIgnoreCase("eps"))
706 File outputFile = new File(file);
708 "Creating EPS file: " + outputFile.getAbsolutePath());
709 af.createEPS(outputFile);
713 if (af.saveAlignment(file, format))
715 System.out.println("Written alignment in " + format
716 + " format to " + file);
720 System.out.println("Error writing file " + file + " in "
721 + format + " format!!");
726 while (aparser.getSize() > 0)
728 System.out.println("Unknown arg: " + aparser.nextValue());
732 AlignFrame startUpAlframe = null;
733 // We'll only open the default file if the desktop is visible.
735 // ////////////////////
737 if (!headless && file == null
738 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
740 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
741 jalview.bin.Cache.getDefault("www.jalview.org",
742 "http://www.jalview.org")
743 + "/examples/exampleFile_2_7.jar");
745 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
747 // hardwire upgrade of the startup file
748 file.replace("_2_3.jar", "_2_7.jar");
749 // and remove the stale setting
750 jalview.bin.Cache.removeProperty("STARTUP_FILE");
753 protocol = DataSourceType.FILE;
755 if (file.indexOf("http:") > -1)
757 protocol = DataSourceType.URL;
760 if (file.endsWith(".jar"))
762 format = FileFormat.Jalview;
768 format = new IdentifyFile().identify(file, protocol);
769 } catch (FileFormatException e)
775 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
777 // extract groovy arguments before anything else.
780 // Once all other stuff is done, execute any groovy scripts (in order)
781 if (groovyscript != null)
783 if (Cache.groovyJarsPresent())
785 System.out.println("Executing script " + groovyscript);
786 executeGroovyScript(groovyscript, startUpAlframe);
791 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
795 // and finally, turn off batch mode indicator - if the desktop still exists
800 desktop.setProgressBar(null, progress);
802 desktop.setInBatchMode(false);
806 private static boolean setCrossPlatformLookAndFeel()
811 UIManager.setLookAndFeel(
812 UIManager.getCrossPlatformLookAndFeelClassName());
814 } catch (Exception ex)
816 System.err.println("Unexpected Look and Feel Exception");
817 ex.printStackTrace();
822 private static boolean setSystemLookAndFeel()
827 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
829 } catch (Exception ex)
831 System.err.println("Unexpected Look and Feel Exception");
832 ex.printStackTrace();
837 private static boolean setSpecificLookAndFeel(String name,
838 String className, boolean nameStartsWith)
843 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
845 if (info.getName() != null && nameStartsWith
846 ? info.getName().toLowerCase()
847 .startsWith(name.toLowerCase())
848 : info.getName().toLowerCase().equals(name.toLowerCase()))
850 className = info.getClassName();
854 UIManager.setLookAndFeel(className);
856 } catch (Exception ex)
858 System.err.println("Unexpected Look and Feel Exception");
859 ex.printStackTrace();
864 private static boolean setGtkLookAndFeel()
866 return setSpecificLookAndFeel("gtk",
867 "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true);
870 private static boolean setMetalLookAndFeel()
872 return setSpecificLookAndFeel("metal",
873 "javax.swing.plaf.metal.MetalLookAndFeel", false);
876 private static boolean setNimbusLookAndFeel()
878 return setSpecificLookAndFeel("nimbus",
879 "javax.swing.plaf.nimbus.NimbusLookAndFeel", false);
882 private static boolean setQuaquaLookAndFeel()
884 return setSpecificLookAndFeel("quaqua",
885 ch.randelshofer.quaqua.QuaquaManager.getLookAndFeel().getClass()
890 private static boolean setVaquaLookAndFeel()
892 return setSpecificLookAndFeel("vaqua",
893 "org.violetlib.aqua.AquaLookAndFeel", false);
896 private static boolean setMacLookAndFeel()
899 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
901 System.setProperty("apple.laf.useScreenMenuBar", "true");
902 set = setQuaquaLookAndFeel();
903 if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
904 .toLowerCase().contains("quaqua"))
906 set = setVaquaLookAndFeel();
911 private static void showUsage()
914 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
915 + "-nodisplay\tRun Jalview without User Interface.\n"
916 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
917 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
918 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
919 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
920 + "-features FILE\tUse the given file to mark features on the alignment.\n"
921 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
922 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
923 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
924 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
925 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
926 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
927 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
928 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
929 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
930 + "-png FILE\tCreate PNG image FILE from alignment.\n"
931 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
932 + "-html FILE\tCreate HTML file from alignment.\n"
933 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
934 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
935 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
936 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
937 + "-noquestionnaire\tTurn off questionnaire check.\n"
938 + "-nonews\tTurn off check for Jalview news.\n"
939 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
940 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
942 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
943 // after all other properties files have been read\n\t
944 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
945 // passed in correctly)"
946 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
947 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
948 + "-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"
949 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
952 private static void startUsageStats(final Desktop desktop)
955 * start a User Config prompt asking if we can log usage statistics.
957 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
958 "USAGESTATS", "Jalview Usage Statistics",
959 "Do you want to help make Jalview better by enabling "
960 + "the collection of usage statistics with Google Analytics ?"
961 + "\n\n(you can enable or disable usage tracking in the preferences)",
968 "Initialising googletracker for usage stats.");
969 Cache.initGoogleTracker();
970 Cache.log.debug("Tracking enabled.");
977 Cache.log.debug("Not enabling Google Tracking.");
980 desktop.addDialogThread(prompter);
984 * Locate the given string as a file and pass it to the groovy interpreter.
986 * @param groovyscript
987 * the script to execute
988 * @param jalviewContext
989 * the Jalview Desktop object passed in to the groovy binding as the
992 private void executeGroovyScript(String groovyscript, AlignFrame af)
995 * for scripts contained in files
1002 if (groovyscript.trim().equals("STDIN"))
1004 // read from stdin into a tempfile and execute it
1007 tfile = File.createTempFile("jalview", "groovy");
1008 PrintWriter outfile = new PrintWriter(
1009 new OutputStreamWriter(new FileOutputStream(tfile)));
1010 BufferedReader br = new BufferedReader(
1011 new InputStreamReader(System.in));
1013 while ((line = br.readLine()) != null)
1015 outfile.write(line + "\n");
1021 } catch (Exception ex)
1023 System.err.println("Failed to read from STDIN into tempfile "
1024 + ((tfile == null) ? "(tempfile wasn't created)"
1025 : tfile.toString()));
1026 ex.printStackTrace();
1031 sfile = tfile.toURI().toURL();
1032 } catch (Exception x)
1035 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1037 x.printStackTrace();
1045 sfile = new URI(groovyscript).toURL();
1046 } catch (Exception x)
1048 tfile = new File(groovyscript);
1049 if (!tfile.exists())
1051 System.err.println("File '" + groovyscript + "' does not exist.");
1054 if (!tfile.canRead())
1056 System.err.println("File '" + groovyscript + "' cannot be read.");
1059 if (tfile.length() < 1)
1061 System.err.println("File '" + groovyscript + "' is empty.");
1066 sfile = tfile.getAbsoluteFile().toURI().toURL();
1067 } catch (Exception ex)
1069 System.err.println("Failed to create a file URL for "
1070 + tfile.getAbsoluteFile());
1077 Map<String, java.lang.Object> vbinding = new HashMap<>();
1078 vbinding.put("Jalview", this);
1081 vbinding.put("currentAlFrame", af);
1083 Binding gbinding = new Binding(vbinding);
1084 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1085 gse.run(sfile.toString(), gbinding);
1086 if ("STDIN".equals(groovyscript))
1088 // delete temp file that we made -
1089 // only if it was successfully executed
1092 } catch (Exception e)
1094 System.err.println("Exception Whilst trying to execute file " + sfile
1095 + " as a groovy script.");
1096 e.printStackTrace(System.err);
1101 public static boolean isHeadlessMode()
1103 String isheadless = System.getProperty("java.awt.headless");
1104 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1111 public AlignFrame[] getAlignFrames()
1113 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1114 : Desktop.getAlignFrames();
1119 * Quit method delegates to Desktop.quit - unless running in headless mode
1120 * when it just ends the JVM
1124 if (desktop != null)
1134 public static AlignFrame getCurrentAlignFrame()
1136 return Jalview.currentAlignFrame;
1139 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1141 Jalview.currentAlignFrame = currentAlignFrame;