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 jalview.ext.so.SequenceOntology;
24 import jalview.gui.AlignFrame;
25 import jalview.gui.Desktop;
26 import jalview.gui.PromptUserConfig;
27 import jalview.io.AppletFormatAdapter;
28 import jalview.io.BioJsHTMLOutput;
29 import jalview.io.DataSourceType;
30 import jalview.io.FileFormat;
31 import jalview.io.FileFormatException;
32 import jalview.io.FileFormatI;
33 import jalview.io.FileLoader;
34 import jalview.io.HtmlSvgOutput;
35 import jalview.io.IdentifyFile;
36 import jalview.io.NewickFile;
37 import jalview.io.gff.SequenceOntologyFactory;
38 import jalview.schemes.ColourSchemeI;
39 import jalview.schemes.ColourSchemeProperty;
40 import jalview.util.MessageManager;
41 import jalview.util.Platform;
42 import jalview.ws.jws2.Jws2Discoverer;
44 import java.awt.event.ActionEvent;
45 import java.awt.event.ActionListener;
46 import java.io.BufferedReader;
48 import java.io.FileOutputStream;
49 import java.io.IOException;
50 import java.io.InputStreamReader;
51 import java.io.OutputStreamWriter;
52 import java.io.PrintWriter;
53 import java.net.MalformedURLException;
55 import java.net.URISyntaxException;
57 import java.security.AllPermission;
58 import java.security.CodeSource;
59 import java.security.PermissionCollection;
60 import java.security.Permissions;
61 import java.security.Policy;
62 import java.util.HashMap;
64 import java.util.Vector;
65 import java.util.logging.ConsoleHandler;
66 import java.util.logging.Level;
67 import java.util.logging.Logger;
69 import javax.swing.LookAndFeel;
70 import javax.swing.Timer;
71 import javax.swing.UIManager;
73 import groovy.lang.Binding;
74 import groovy.util.GroovyScriptEngine;
77 * Main class for Jalview Application <br>
79 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
82 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
83 * jalview.bin.Jalview jalview.bin.Jalview
85 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
86 * embellish '*' to e.g. '*.jar')
96 * // find first query parameter (if any) that doesn't start with j2s
97 * // and set as space-delimited arguments to Jalview main
98 * hr = decodeURI(document.location.href);
99 * pos = hr.indexOf("?");
102 * q = hr.substring(pos+1);
103 * args = q.split("&");
104 * for (i = 0 ; i < args.length; i++)
107 * if (!arg1.startsWith("j2s"))
109 * thisApplet.__Info.args = arg1.split(" ");
117 * singleton instance of this class
119 private static Jalview instance;
121 private Desktop desktop;
123 public static AlignFrame currentAlignFrame;
127 if (!Platform.isJS())
129 // grab all the rights we can for the JVM
130 Policy.setPolicy(new Policy()
133 public PermissionCollection getPermissions(CodeSource codesource)
135 Permissions perms = new Permissions();
136 perms.add(new AllPermission());
141 public void refresh()
149 * keep track of feature fetching tasks.
157 * TODO: generalise to track all jalview events to orchestrate batch
161 private int queued = 0;
163 private int running = 0;
165 public FeatureFetcher()
170 public void addFetcher(final AlignFrame af,
171 final Vector<String> dasSources)
173 final long id = System.currentTimeMillis();
175 final FeatureFetcher us = this;
176 new Thread(new Runnable()
188 af.setProgressBar(MessageManager
189 .getString("status.das_features_being_retrived"), id);
190 af.featureSettings_actionPerformed(null);
191 af.setProgressBar(null, id);
200 public synchronized boolean allFinished()
202 return queued == 0 && running == 0;
207 public static Jalview getInstance()
213 * main class for Jalview application
216 * open <em>filename</em>
218 public static void main(String[] args)
220 // setLogging(); // BH - for event debugging in JavaScript
221 instance = new Jalview();
222 instance.doMain(args);
225 private static void logClass(String name)
227 // BH - for event debugging in JavaScript
228 ConsoleHandler consoleHandler = new ConsoleHandler();
229 consoleHandler.setLevel(Level.ALL);
230 Logger logger = Logger.getLogger(name);
231 logger.setLevel(Level.ALL);
232 logger.addHandler(consoleHandler);
235 @SuppressWarnings("unused")
236 private static void setLogging()
238 // BH - for event debugging in JavaScript (Java mode only)
239 if (!(/** @j2sNative true ||*/false))
241 Logger.getLogger("").setLevel(Level.ALL);
242 logClass("java.awt.EventDispatchThread");
243 logClass("java.awt.EventQueue");
244 logClass("java.awt.Component");
245 logClass("java.awt.focus.Component");
246 logClass("java.awt.focus.DefaultKeyboardFocusManager");
257 void doMain(String[] args)
260 if (!Platform.isJS())
262 System.setSecurityManager(null);
266 .println("Java version: " + System.getProperty("java.version"));
267 System.out.println(System.getProperty("os.arch") + " "
268 + System.getProperty("os.name") + " "
269 + System.getProperty("os.version"));
271 ArgsParser aparser = new ArgsParser(args);
272 boolean headless = false;
274 String usrPropsFile = aparser.getValue("props");
275 Cache.loadProperties(usrPropsFile); // must do this before
276 if (usrPropsFile != null)
279 "CMD [-props " + usrPropsFile + "] executed successfully!");
283 * BH 2018 ignoring this section for JS
288 if (aparser.contains("help") || aparser.contains("h"))
293 if (aparser.contains("nodisplay") || aparser.contains("nogui")
294 || aparser.contains("headless"))
296 System.setProperty("java.awt.headless", "true");
301 final String jabawsUrl = aparser.getValue("jabaws");
302 if (jabawsUrl != null)
306 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
308 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
309 } catch (MalformedURLException e)
312 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
317 String defs = aparser.getValue("setprop");
320 int p = defs.indexOf('=');
323 System.err.println("Ignoring invalid setprop argument : " + defs);
327 System.out.println("Executing setprop argument: " + defs);
330 Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
333 defs = aparser.getValue("setprop");
335 if (System.getProperty("java.awt.headless") != null
336 && System.getProperty("java.awt.headless").equals("true"))
340 System.setProperty("http.agent",
341 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
345 } catch (NoClassDefFoundError error)
347 error.printStackTrace();
348 System.out.println("\nEssential logging libraries not found."
349 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
357 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
358 } catch (Exception ex)
360 System.err.println("Unexpected Look and Feel Exception");
361 ex.printStackTrace();
363 if (Platform.isAMacAndNotJS())
366 LookAndFeel lookAndFeel = ch.randelshofer.quaqua.QuaquaManager
368 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
370 System.setProperty("apple.laf.useScreenMenuBar", "true");
371 if (lookAndFeel != null)
375 UIManager.setLookAndFeel(lookAndFeel);
376 } catch (Throwable e)
379 "Failed to set QuaQua look and feel: " + e.toString());
382 if (lookAndFeel == null || !(lookAndFeel.getClass()
383 .isAssignableFrom(UIManager.getLookAndFeel().getClass()))
384 || !UIManager.getLookAndFeel().getClass().toString()
385 .toLowerCase().contains("quaqua"))
390 "Quaqua LaF not available on this plaform. Using VAqua(4).\nSee https://issues.jalview.org/browse/JAL-2976");
391 UIManager.setLookAndFeel("org.violetlib.aqua.AquaLookAndFeel");
392 } catch (Throwable e)
395 "Failed to reset look and feel: " + e.toString());
401 * configure 'full' SO model if preferences say to,
402 * else use the default (SO Lite)
404 if (Cache.getDefault("USE_FULL_SO", false))
406 SequenceOntologyFactory.setInstance(new SequenceOntology());
411 desktop = new Desktop()
415 // protected void processEvent(AWTEvent e) {
416 // System.out.println("Jalview.java " + e);
417 // super.processEvent(e);
421 desktop.setInBatchMode(true); // indicate we are starting up
422 desktop.setVisible(true);
425 * BH 2018 JS bypass this section
431 desktop.startServiceDiscovery();
432 if (!aparser.contains("nousagestats"))
434 startUsageStats(desktop);
438 System.err.println("CMD [-nousagestats] executed successfully!");
441 if (!aparser.contains("noquestionnaire"))
443 String url = aparser.getValue("questionnaire");
446 // Start the desktop questionnaire prompter with the specified
448 Cache.log.debug("Starting questionnaire url at " + url);
449 desktop.checkForQuestionnaire(url);
450 System.out.println("CMD questionnaire[-" + url
451 + "] executed successfully!");
455 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
457 // Start the desktop questionnaire prompter with the specified
460 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
462 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
464 "Starting questionnaire with default url: " + defurl);
465 desktop.checkForQuestionnaire(defurl);
472 .println("CMD [-noquestionnaire] executed successfully!");
475 if (!aparser.contains("nonews"))
477 desktop.checkForNews();
480 BioJsHTMLOutput.updateBioJS();
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!");
500 String vamsasImport = aparser.getValue("vdoc");
501 String vamsasSession = aparser.getValue("vsess");
502 if (vamsasImport != null || vamsasSession != null)
504 if (desktop == null || headless)
507 "Headless vamsas sessions not yet supported. Sorry.");
510 // if we have a file, start a new session and import it.
511 boolean inSession = false;
512 if (vamsasImport != null)
516 DataSourceType viprotocol = AppletFormatAdapter
517 .checkProtocol(vamsasImport);
518 if (viprotocol == DataSourceType.FILE)
520 inSession = desktop.vamsasImport(new File(vamsasImport));
522 else if (viprotocol == DataSourceType.URL)
524 inSession = desktop.vamsasImport(new URL(vamsasImport));
527 } catch (Exception e)
529 System.err.println("Exeption when importing " + vamsasImport
530 + " as a vamsas document.");
535 System.err.println("Failed to import " + vamsasImport
536 + " as a vamsas document.");
540 System.out.println("Imported Successfully into new session "
541 + desktop.getVamsasApplication().getCurrentSession());
544 if (vamsasSession != null)
546 if (vamsasImport != null)
548 // close the newly imported session and import the Jalview specific
549 // remnants into the new session later on.
550 desktop.vamsasStop_actionPerformed(null);
552 // now join the new session
555 if (desktop.joinVamsasSession(vamsasSession))
558 "Successfully joined vamsas session " + vamsasSession);
562 System.err.println("WARNING: Failed to join vamsas session "
565 } catch (Exception e)
568 "ERROR: Failed to join vamsas session " + vamsasSession);
571 if (vamsasImport != null)
573 // the Jalview specific remnants can now be imported into the new
574 // session at the user's leisure.
576 "Skipping Push for import of data into existing vamsas session."); // TODO:
581 // desktop.getVamsasApplication().push_update();
586 // Finally, deal with the remaining input data.
591 desktop.setProgressBar(
593 .getString("status.processing_commandline_args"),
594 progress = System.currentTimeMillis());
596 System.out.println("CMD [-open " + file + "] executed successfully!");
598 if (!Platform.isJS() && !file.startsWith("http://"))
600 if (!(new File(file)).exists())
602 System.out.println("Can't find " + file);
610 protocol = AppletFormatAdapter.checkProtocol(file);
614 format = new IdentifyFile().identify(file, protocol);
615 } catch (FileFormatException e1)
620 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
624 System.out.println("error");
628 setCurrentAlignFrame(af);
629 data = aparser.getValue("colour", true);
632 data.replaceAll("%20", " ");
634 ColourSchemeI cs = ColourSchemeProperty
635 .getColourScheme(af.getViewport(),
636 af.getViewport().getAlignment(), data);
641 "CMD [-color " + data + "] executed successfully!");
646 // Must maintain ability to use the groups flag
647 data = aparser.getValue("groups", true);
650 af.parseFeaturesFile(data,
651 AppletFormatAdapter.checkProtocol(data));
652 // System.out.println("Added " + data);
654 "CMD groups[-" + data + "] executed successfully!");
656 data = aparser.getValue("features", true);
659 af.parseFeaturesFile(data,
660 AppletFormatAdapter.checkProtocol(data));
661 // System.out.println("Added " + data);
663 "CMD [-features " + data + "] executed successfully!");
666 data = aparser.getValue("annotations", true);
669 af.loadJalviewDataFile(data, null, null, null);
670 // System.out.println("Added " + data);
672 "CMD [-annotations " + data + "] executed successfully!");
674 // set or clear the sortbytree flag.
675 if (aparser.contains("sortbytree"))
677 af.getViewport().setSortByTree(true);
678 if (af.getViewport().getSortByTree())
680 System.out.println("CMD [-sortbytree] executed successfully!");
683 if (aparser.contains("no-annotation"))
685 af.getViewport().setShowAnnotation(false);
686 if (!af.getViewport().isShowAnnotation())
688 System.out.println("CMD no-annotation executed successfully!");
691 if (aparser.contains("nosortbytree"))
693 af.getViewport().setSortByTree(false);
694 if (!af.getViewport().getSortByTree())
697 .println("CMD [-nosortbytree] executed successfully!");
700 data = aparser.getValue("tree", true);
706 "CMD [-tree " + data + "] executed successfully!");
707 NewickFile nf = new NewickFile(data,
708 AppletFormatAdapter.checkProtocol(data));
710 .setCurrentTree(af.showNewickTree(nf, data).getTree());
711 } catch (IOException ex)
713 System.err.println("Couldn't add tree " + data);
714 ex.printStackTrace(System.err);
717 // TODO - load PDB structure(s) to alignment JAL-629
718 // (associate with identical sequence in alignment, or a specified
720 if (groovyscript != null)
722 // Execute the groovy script after we've done all the rendering stuff
723 // and before any images or figures are generated.
724 System.out.println("Executing script " + groovyscript);
725 executeGroovyScript(groovyscript, af);
726 System.out.println("CMD groovy[" + groovyscript
727 + "] executed successfully!");
730 String imageName = "unnamed.png";
731 while (aparser.getSize() > 1)
733 String outputFormat = aparser.nextValue();
734 file = aparser.nextValue();
736 if (outputFormat.equalsIgnoreCase("png"))
738 af.createPNG(new File(file));
739 imageName = (new File(file)).getName();
740 System.out.println("Creating PNG image: " + file);
743 else if (outputFormat.equalsIgnoreCase("svg"))
745 File imageFile = new File(file);
746 imageName = imageFile.getName();
747 af.createSVG(imageFile);
748 System.out.println("Creating SVG image: " + file);
751 else if (outputFormat.equalsIgnoreCase("html"))
753 File imageFile = new File(file);
754 imageName = imageFile.getName();
755 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
756 htmlSVG.exportHTML(file);
758 System.out.println("Creating HTML image: " + file);
761 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
765 System.err.println("The output html file must not be null");
770 BioJsHTMLOutput.refreshVersionInfo(
771 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
772 } catch (URISyntaxException e)
776 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
777 bjs.exportHTML(file);
779 .println("Creating BioJS MSA Viwer HTML file: " + file);
782 else if (outputFormat.equalsIgnoreCase("imgMap"))
784 af.createImageMap(new File(file), imageName);
785 System.out.println("Creating image map: " + file);
788 else if (outputFormat.equalsIgnoreCase("eps"))
790 File outputFile = new File(file);
792 "Creating EPS file: " + outputFile.getAbsolutePath());
793 af.createEPS(outputFile);
797 af.saveAlignment(file, format);
798 if (af.isSaveAlignmentSuccessful())
800 System.out.println("Written alignment in " + format
801 + " format to " + file);
805 System.out.println("Error writing file " + file + " in "
806 + format + " format!!");
811 while (aparser.getSize() > 0)
813 System.out.println("Unknown arg: " + aparser.nextValue());
817 AlignFrame startUpAlframe = null;
818 // We'll only open the default file if the desktop is visible.
820 // ////////////////////
822 if (/** @j2sNative false && */ // BH 2018
823 !headless && file == null && vamsasImport == null
824 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
826 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
827 jalview.bin.Cache.getDefault("www.jalview.org",
828 "http://www.jalview.org")
829 + "/examples/exampleFile_2_7.jar");
831 "http://www.jalview.org/examples/exampleFile_2_3.jar"))
833 // hardwire upgrade of the startup file
834 file.replace("_2_3.jar", "_2_7.jar");
835 // and remove the stale setting
836 jalview.bin.Cache.removeProperty("STARTUP_FILE");
839 protocol = DataSourceType.FILE;
841 if (file.indexOf("http:") > -1)
843 protocol = DataSourceType.URL;
846 if (file.endsWith(".jar"))
848 format = FileFormat.Jalview;
854 format = new IdentifyFile().identify(file, protocol);
855 } catch (FileFormatException e)
861 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
863 // extract groovy arguments before anything else.
866 // Once all other stuff is done, execute any groovy scripts (in order)
867 if (groovyscript != null)
869 if (Cache.groovyJarsPresent())
871 System.out.println("Executing script " + groovyscript);
872 executeGroovyScript(groovyscript, startUpAlframe);
877 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
881 // and finally, turn off batch mode indicator - if the desktop still exists
886 desktop.setProgressBar(null, progress);
888 desktop.setInBatchMode(false);
892 private static void showUsage()
895 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
896 + "-nodisplay\tRun Jalview without User Interface.\n"
897 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
898 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
899 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
900 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
901 + "-features FILE\tUse the given file to mark features on the alignment.\n"
902 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
903 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
904 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
905 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
906 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
907 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
908 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
909 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
910 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
911 + "-png FILE\tCreate PNG image FILE from alignment.\n"
912 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
913 + "-html FILE\tCreate HTML file from alignment.\n"
914 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
915 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
916 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
917 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
918 + "-noquestionnaire\tTurn off questionnaire check.\n"
919 + "-nonews\tTurn off check for Jalview news.\n"
920 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
921 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
923 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
924 // after all other properties files have been read\n\t
925 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
926 // passed in correctly)"
927 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
928 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
930 // "-vdoc vamsas-document\tImport vamsas document into new
931 // session or join existing session with same URN\n"
932 // + "-vses vamsas-session\tJoin session with given URN\n"
933 + "-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"
934 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
937 private static void startUsageStats(final Desktop desktop)
940 * start a User Config prompt asking if we can log usage statistics.
942 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
943 "USAGESTATS", "Jalview Usage Statistics",
944 "Do you want to help make Jalview better by enabling "
945 + "the collection of usage statistics with Google Analytics ?"
946 + "\n\n(you can enable or disable usage tracking in the preferences)",
953 "Initialising googletracker for usage stats.");
954 Cache.initGoogleTracker();
955 Cache.log.debug("Tracking enabled.");
962 Cache.log.debug("Not enabling Google Tracking.");
965 desktop.addDialogThread(prompter);
969 * Locate the given string as a file and pass it to the groovy interpreter.
971 * @param groovyscript
972 * the script to execute
973 * @param jalviewContext
974 * the Jalview Desktop object passed in to the groovy binding as the
977 private void executeGroovyScript(String groovyscript, AlignFrame af)
980 * for scripts contained in files
987 if (groovyscript.trim().equals("STDIN"))
989 // read from stdin into a tempfile and execute it
992 tfile = File.createTempFile("jalview", "groovy");
993 PrintWriter outfile = new PrintWriter(
994 new OutputStreamWriter(new FileOutputStream(tfile)));
995 BufferedReader br = new BufferedReader(
996 new InputStreamReader(System.in));
998 while ((line = br.readLine()) != null)
1000 outfile.write(line + "\n");
1006 } catch (Exception ex)
1008 System.err.println("Failed to read from STDIN into tempfile "
1009 + ((tfile == null) ? "(tempfile wasn't created)"
1010 : tfile.toString()));
1011 ex.printStackTrace();
1016 sfile = tfile.toURI().toURL();
1017 } catch (Exception x)
1020 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1022 x.printStackTrace();
1030 sfile = new URI(groovyscript).toURL();
1031 } catch (Exception x)
1033 tfile = new File(groovyscript);
1034 if (!tfile.exists())
1036 System.err.println("File '" + groovyscript + "' does not exist.");
1039 if (!tfile.canRead())
1041 System.err.println("File '" + groovyscript + "' cannot be read.");
1044 if (tfile.length() < 1)
1046 System.err.println("File '" + groovyscript + "' is empty.");
1051 sfile = tfile.getAbsoluteFile().toURI().toURL();
1052 } catch (Exception ex)
1054 System.err.println("Failed to create a file URL for "
1055 + tfile.getAbsoluteFile());
1062 Map<String, Object> vbinding = new HashMap<>();
1063 vbinding.put("Jalview", this);
1066 vbinding.put("currentAlFrame", af);
1068 Binding gbinding = new Binding(vbinding);
1069 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1070 gse.run(sfile.toString(), gbinding);
1071 if ("STDIN".equals(groovyscript))
1073 // delete temp file that we made -
1074 // only if it was successfully executed
1077 } catch (Exception e)
1079 System.err.println("Exception Whilst trying to execute file " + sfile
1080 + " as a groovy script.");
1081 e.printStackTrace(System.err);
1086 public static boolean isHeadlessMode()
1088 String isheadless = System.getProperty("java.awt.headless");
1089 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1096 public AlignFrame[] getAlignFrames()
1098 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1099 : Desktop.getAlignFrames();
1104 * Quit method delegates to Desktop.quit - unless running in headless mode
1105 * when it just ends the JVM
1109 if (desktop != null)
1119 public static AlignFrame getCurrentAlignFrame()
1121 return Jalview.currentAlignFrame;
1124 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1126 Jalview.currentAlignFrame = currentAlignFrame;