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.FileFormats;
61 import jalview.io.FileLoader;
62 import jalview.io.HtmlSvgOutput;
63 import jalview.io.IdentifyFile;
64 import jalview.io.NewickFile;
65 import jalview.io.gff.SequenceOntologyFactory;
66 import jalview.schemes.ColourSchemeI;
67 import jalview.schemes.ColourSchemeProperty;
68 import jalview.util.MessageManager;
69 import jalview.util.Platform;
70 import jalview.ws.jws2.Jws2Discoverer;
73 * Main class for Jalview Application <br>
75 * start with: java -classpath "$PATH_TO_LIB$/*:$PATH_TO_CLASSES$" \
78 * or on Windows: java -classpath "$PATH_TO_LIB$/*;$PATH_TO_CLASSES$" \
79 * jalview.bin.Jalview jalview.bin.Jalview
81 * (ensure -classpath arg is quoted to avoid shell expansion of '*' and do not
82 * embellish '*' to e.g. '*.jar')
90 * singleton instance of this class
92 private static Jalview instance;
94 private Desktop desktop;
96 public static AlignFrame currentAlignFrame;
100 // grab all the rights we can the JVM
101 Policy.setPolicy(new Policy()
104 public PermissionCollection getPermissions(CodeSource codesource)
106 Permissions perms = new Permissions();
107 perms.add(new AllPermission());
112 public void refresh()
119 * keep track of feature fetching tasks.
127 * TODO: generalise to track all jalview events to orchestrate batch processing
131 private int queued = 0;
133 private int running = 0;
135 public FeatureFetcher()
140 public void addFetcher(final AlignFrame af,
141 final Vector<String> dasSources)
143 final long id = System.currentTimeMillis();
145 final FeatureFetcher us = this;
146 new Thread(new Runnable()
158 af.setProgressBar(MessageManager
159 .getString("status.das_features_being_retrived"), id);
160 af.featureSettings_actionPerformed(null);
161 af.setProgressBar(null, id);
170 public synchronized boolean allFinished()
172 return queued == 0 && running == 0;
177 public static Jalview getInstance()
183 * main class for Jalview application
186 * open <em>filename</em>
188 public static void main(String[] args)
190 instance = new Jalview();
191 instance.doMain(args);
197 void doMain(String[] args)
199 System.setSecurityManager(null);
201 .println("Java version: " + System.getProperty("java.version"));
202 System.out.println("Java Home: " + System.getProperty("java.home"));
203 System.out.println(System.getProperty("os.arch") + " "
204 + System.getProperty("os.name") + " "
205 + System.getProperty("os.version"));
206 String val = System.getProperty("sys.install4jVersion");
209 System.out.println("Install4j version: " + val);
211 val = System.getProperty("installer_template_version");
214 System.out.println("Install4j template version: " + val);
216 val = System.getProperty("launcher_version");
219 System.out.println("Launcher version: " + val);
222 // report Jalview version
223 Cache.loadBuildProperties(true);
225 ArgsParser aparser = new ArgsParser(args);
226 boolean headless = false;
228 if (aparser.contains("help") || aparser.contains("h"))
233 if (aparser.contains("nodisplay") || aparser.contains("nogui")
234 || aparser.contains("headless"))
236 System.setProperty("java.awt.headless", "true");
239 String usrPropsFile = aparser.getValue("props");
240 Cache.loadProperties(usrPropsFile); // must do this before
241 if (usrPropsFile != null)
244 "CMD [-props " + usrPropsFile + "] executed successfully!");
249 final String jabawsUrl = aparser.getValue("jabaws");
250 if (jabawsUrl != null)
254 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
256 "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
257 } catch (MalformedURLException e)
260 "Invalid jabaws parameter: " + jabawsUrl + " ignored");
264 String defs = aparser.getValue("setprop");
267 int p = defs.indexOf('=');
270 System.err.println("Ignoring invalid setprop argument : " + defs);
274 System.out.println("Executing setprop argument: " + defs);
275 // DISABLED FOR SECURITY REASONS
276 // TODO: add a property to allow properties to be overriden by cli args
277 // Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
279 defs = aparser.getValue("setprop");
281 if (System.getProperty("java.awt.headless") != null
282 && System.getProperty("java.awt.headless").equals("true"))
286 System.setProperty("http.agent",
287 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
291 } catch (NoClassDefFoundError error)
293 error.printStackTrace();
294 System.out.println("\nEssential logging libraries not found."
295 + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview");
304 * configure 'full' SO model if preferences say to, else use the default (SO
307 if (Cache.getDefault("USE_FULL_SO", true))
309 SequenceOntologyFactory.setInstance(new SequenceOntology());
315 desktop = new Desktop();
316 desktop.setInBatchMode(true); // indicate we are starting up
320 JalviewTaskbar.setTaskbar(this);
321 } catch (Exception e)
323 Cache.log.info("Cannot set Taskbar");
324 Cache.log.error(e.getMessage());
325 // e.printStackTrace();
326 } catch (Throwable t)
328 Cache.log.info("Cannot set Taskbar");
329 Cache.log.error(t.getMessage());
330 // t.printStackTrace();
333 desktop.setVisible(true);
334 desktop.startServiceDiscovery();
335 if (!aparser.contains("nousagestats"))
337 startUsageStats(desktop);
341 System.err.println("CMD [-nousagestats] executed successfully!");
344 if (!aparser.contains("noquestionnaire"))
346 String url = aparser.getValue("questionnaire");
349 // Start the desktop questionnaire prompter with the specified
351 Cache.log.debug("Starting questionnaire url at " + url);
352 desktop.checkForQuestionnaire(url);
354 "CMD questionnaire[-" + url + "] executed successfully!");
358 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
360 // Start the desktop questionnaire prompter with the specified
363 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
365 String defurl = "https://www.jalview.org/cgi-bin/questionnaire.pl";
367 "Starting questionnaire with default url: " + defurl);
368 desktop.checkForQuestionnaire(defurl);
374 System.err.println("CMD [-noquestionnaire] executed successfully!");
377 if (!aparser.contains("nonews"))
379 desktop.checkForNews();
382 BioJsHTMLOutput.updateBioJS();
385 // Move any new getdown-launcher-new.jar into place over old
386 // getdown-launcher.jar
387 String appdirString = System.getProperty("getdownappdir");
388 if (appdirString != null && appdirString.length() > 0)
390 final File appdir = new File(appdirString);
396 LaunchUtil.upgradeGetdown(
397 new File(appdir, "getdown-launcher-old.jar"),
398 new File(appdir, "getdown-launcher.jar"),
399 new File(appdir, "getdown-launcher-new.jar"));
404 String file = null, data = null;
405 FileFormatI format = null;
406 DataSourceType protocol = null;
407 FileLoader fileLoader = new FileLoader(!headless);
409 String groovyscript = null; // script to execute after all loading is
410 // completed one way or another
411 // extract groovy argument and execute if necessary
412 groovyscript = aparser.getValue("groovy", true);
413 file = aparser.getValue("open", true);
415 if (file == null && desktop == null)
417 System.out.println("No files to open!");
421 // Finally, deal with the remaining input data.
426 desktop.setProgressBar(
428 .getString("status.processing_commandline_args"),
429 progress = System.currentTimeMillis());
431 System.out.println("CMD [-open " + file + "] executed successfully!");
433 protocol = AppletFormatAdapter.checkProtocol(file);
435 if (protocol == DataSourceType.FILE)
437 if (!(new File(file)).exists())
439 System.out.println("Can't find " + file);
449 format = new IdentifyFile().identify(file, protocol);
450 } catch (FileFormatException e1)
455 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
459 System.out.println("error");
463 setCurrentAlignFrame(af);
464 data = aparser.getValue("colour", true);
467 data.replaceAll("%20", " ");
469 ColourSchemeI cs = ColourSchemeProperty.getColourScheme(
470 af.getViewport(), af.getViewport().getAlignment(), data);
475 "CMD [-color " + data + "] executed successfully!");
480 // Must maintain ability to use the groups flag
481 data = aparser.getValue("groups", true);
484 af.parseFeaturesFile(data,
485 AppletFormatAdapter.checkProtocol(data));
486 // System.out.println("Added " + data);
488 "CMD groups[-" + data + "] executed successfully!");
490 data = aparser.getValue("features", true);
493 af.parseFeaturesFile(data,
494 AppletFormatAdapter.checkProtocol(data));
495 // System.out.println("Added " + data);
497 "CMD [-features " + data + "] executed successfully!");
500 data = aparser.getValue("annotations", true);
503 af.loadJalviewDataFile(data, null, null, null);
504 // System.out.println("Added " + data);
506 "CMD [-annotations " + data + "] executed successfully!");
508 // set or clear the sortbytree flag.
509 if (aparser.contains("sortbytree"))
511 af.getViewport().setSortByTree(true);
512 if (af.getViewport().getSortByTree())
514 System.out.println("CMD [-sortbytree] executed successfully!");
517 if (aparser.contains("no-annotation"))
519 af.getViewport().setShowAnnotation(false);
520 if (!af.getViewport().isShowAnnotation())
522 System.out.println("CMD no-annotation executed successfully!");
525 if (aparser.contains("nosortbytree"))
527 af.getViewport().setSortByTree(false);
528 if (!af.getViewport().getSortByTree())
531 .println("CMD [-nosortbytree] executed successfully!");
534 data = aparser.getValue("tree", true);
540 "CMD [-tree " + data + "] executed successfully!");
541 NewickFile nf = new NewickFile(data,
542 AppletFormatAdapter.checkProtocol(data));
544 .setCurrentTree(af.showNewickTree(nf, data).getTree());
545 } catch (IOException ex)
547 System.err.println("Couldn't add tree " + data);
548 ex.printStackTrace(System.err);
551 // TODO - load PDB structure(s) to alignment JAL-629
552 // (associate with identical sequence in alignment, or a specified
554 if (groovyscript != null)
556 // Execute the groovy script after we've done all the rendering stuff
557 // and before any images or figures are generated.
558 System.out.println("Executing script " + groovyscript);
559 executeGroovyScript(groovyscript, af);
560 System.out.println("CMD groovy[" + groovyscript
561 + "] executed successfully!");
564 String imageName = "unnamed.png";
565 while (aparser.getSize() > 1)
567 String outputFormat = aparser.nextValue();
568 file = aparser.nextValue();
570 if (outputFormat.equalsIgnoreCase("png"))
572 af.createPNG(new File(file));
573 imageName = (new File(file)).getName();
574 System.out.println("Creating PNG image: " + file);
577 else if (outputFormat.equalsIgnoreCase("svg"))
579 File imageFile = new File(file);
580 imageName = imageFile.getName();
581 af.createSVG(imageFile);
582 System.out.println("Creating SVG image: " + file);
585 else if (outputFormat.equalsIgnoreCase("html"))
587 File imageFile = new File(file);
588 imageName = imageFile.getName();
589 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
590 htmlSVG.exportHTML(file);
592 System.out.println("Creating HTML image: " + file);
595 else if (outputFormat.equalsIgnoreCase("biojsmsa"))
599 System.err.println("The output html file must not be null");
604 BioJsHTMLOutput.refreshVersionInfo(
605 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
606 } catch (URISyntaxException e)
610 BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
611 bjs.exportHTML(file);
613 .println("Creating BioJS MSA Viwer HTML file: " + file);
616 else if (outputFormat.equalsIgnoreCase("imgMap"))
618 af.createImageMap(new File(file), imageName);
619 System.out.println("Creating image map: " + file);
622 else if (outputFormat.equalsIgnoreCase("eps"))
624 File outputFile = new File(file);
626 "Creating EPS file: " + outputFile.getAbsolutePath());
627 af.createEPS(outputFile);
630 FileFormatI outFormat = null;
633 outFormat = FileFormats.getInstance().forName(outputFormat);
634 } catch (Exception formatP)
636 System.out.println("Couldn't parse " + outFormat
637 + " as a valid Jalview format string.");
639 if (outFormat != null)
641 if (!outFormat.isWritable())
644 "This version of Jalview does not support alignment export as "
649 if (af.saveAlignment(file, outFormat))
651 System.out.println("Written alignment in " + format
652 + " format to " + file);
656 System.out.println("Error writing file " + file + " in "
657 + format + " format!!");
663 while (aparser.getSize() > 0)
665 System.out.println("Unknown arg: " + aparser.nextValue());
669 AlignFrame startUpAlframe = null;
670 // We'll only open the default file if the desktop is visible.
672 // ////////////////////
674 if (!headless && file == null
675 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
677 file = jalview.bin.Cache.getDefault("STARTUP_FILE",
678 jalview.bin.Cache.getDefault("www.jalview.org",
679 "https://www.jalview.org")
680 + "/examples/exampleFile_2_7.jvp");
681 if (file.equals("http://www.jalview.org/examples/exampleFile_2_3.jar")
683 "http://www.jalview.org/examples/exampleFile_2_7.jar"))
685 file.replace("http:", "https:");
686 // hardwire upgrade of the startup file
687 file.replace("_2_3", "_2_7");
688 file.replace("2_7.jar", "2_7.jvp");
689 // and remove the stale setting
690 jalview.bin.Cache.removeProperty("STARTUP_FILE");
693 protocol = DataSourceType.FILE;
695 if (file.indexOf("http:") > -1)
697 protocol = DataSourceType.URL;
700 if (file.endsWith(".jar"))
702 format = FileFormat.Jalview;
708 format = new IdentifyFile().identify(file, protocol);
709 } catch (FileFormatException e)
715 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
717 // extract groovy arguments before anything else.
720 // Once all other stuff is done, execute any groovy scripts (in order)
721 if (groovyscript != null)
723 if (Cache.groovyJarsPresent())
725 System.out.println("Executing script " + groovyscript);
726 executeGroovyScript(groovyscript, startUpAlframe);
731 "Sorry. Groovy Support is not available, so ignoring the provided groovy script "
735 // and finally, turn off batch mode indicator - if the desktop still exists
740 desktop.setProgressBar(null, progress);
742 desktop.setInBatchMode(false);
746 private static void setLookAndFeel()
748 // property laf = "crossplatform", "system", "gtk", "metal", "nimbus" or
750 // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac,
752 String lafProp = System.getProperty("laf");
753 String lafSetting = Cache.getDefault("PREFERRED_LAF", null);
759 else if (lafSetting != null)
763 boolean lafSet = false;
766 case "crossplatform":
767 lafSet = setCrossPlatformLookAndFeel();
770 Cache.log.error("Could not set requested laf=" + laf);
774 lafSet = setSystemLookAndFeel();
777 Cache.log.error("Could not set requested laf=" + laf);
781 lafSet = setGtkLookAndFeel();
784 Cache.log.error("Could not set requested laf=" + laf);
788 lafSet = setMetalLookAndFeel();
791 Cache.log.error("Could not set requested laf=" + laf);
795 lafSet = setNimbusLookAndFeel();
798 Cache.log.error("Could not set requested laf=" + laf);
802 lafSet = setQuaquaLookAndFeel();
805 Cache.log.error("Could not set requested laf=" + laf);
809 lafSet = setVaquaLookAndFeel();
812 Cache.log.error("Could not set requested laf=" + laf);
816 lafSet = setMacLookAndFeel();
819 Cache.log.error("Could not set requested laf=" + laf);
825 Cache.log.error("Requested laf=" + laf + " not implemented");
829 setSystemLookAndFeel();
830 if (Platform.isLinux())
832 setMetalLookAndFeel();
834 if (Platform.isAMac())
841 private static boolean setCrossPlatformLookAndFeel()
843 return setGenericLookAndFeel(false);
846 private static boolean setSystemLookAndFeel()
848 return setGenericLookAndFeel(true);
851 private static boolean setGenericLookAndFeel(boolean system)
856 UIManager.setLookAndFeel(
857 system ? UIManager.getSystemLookAndFeelClassName()
858 : UIManager.getCrossPlatformLookAndFeelClassName());
860 } catch (Exception ex)
862 Cache.log.error("Unexpected Look and Feel Exception");
863 Cache.log.error(ex.getMessage());
864 Cache.log.debug(Cache.getStackTraceString(ex));
869 private static boolean setSpecificLookAndFeel(String name,
870 String className, boolean nameStartsWith)
875 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
877 if (info.getName() != null && nameStartsWith
878 ? info.getName().toLowerCase()
879 .startsWith(name.toLowerCase())
880 : info.getName().toLowerCase().equals(name.toLowerCase()))
882 className = info.getClassName();
886 UIManager.setLookAndFeel(className);
888 } catch (Exception ex)
890 Cache.log.error("Unexpected Look and Feel Exception");
891 Cache.log.error(ex.getMessage());
892 Cache.log.debug(Cache.getStackTraceString(ex));
897 private static boolean setGtkLookAndFeel()
899 return setSpecificLookAndFeel("gtk",
900 "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", true);
903 private static boolean setMetalLookAndFeel()
905 return setSpecificLookAndFeel("metal",
906 "javax.swing.plaf.metal.MetalLookAndFeel", false);
909 private static boolean setNimbusLookAndFeel()
911 return setSpecificLookAndFeel("nimbus",
912 "javax.swing.plaf.nimbus.NimbusLookAndFeel", false);
915 private static boolean setQuaquaLookAndFeel()
917 return setSpecificLookAndFeel("quaqua",
918 ch.randelshofer.quaqua.QuaquaManager.getLookAndFeel().getClass()
923 private static boolean setVaquaLookAndFeel()
925 return setSpecificLookAndFeel("vaqua",
926 "org.violetlib.aqua.AquaLookAndFeel", false);
929 private static boolean setMacLookAndFeel()
932 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
934 System.setProperty("apple.laf.useScreenMenuBar", "true");
935 set = setQuaquaLookAndFeel();
936 if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
937 .toLowerCase().contains("quaqua"))
939 set = setVaquaLookAndFeel();
944 private static void showUsage()
947 "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
948 + "-nodisplay\tRun Jalview without User Interface.\n"
949 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
950 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
951 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
952 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
953 + "-features FILE\tUse the given file to mark features on the alignment.\n"
954 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
955 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
956 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
957 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
958 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
959 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
960 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
961 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
962 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
963 + "-png FILE\tCreate PNG image FILE from alignment.\n"
964 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
965 + "-html FILE\tCreate HTML file from alignment.\n"
966 + "-biojsMSA FILE\tCreate BioJS MSA Viewer HTML file from alignment.\n"
967 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
968 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
969 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
970 + "-noquestionnaire\tTurn off questionnaire check.\n"
971 + "-nonews\tTurn off check for Jalview news.\n"
972 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
973 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
975 // "-setprop PROPERTY=VALUE\tSet the given Jalview property,
976 // after all other properties files have been read\n\t
977 // (quote the 'PROPERTY=VALUE' pair to ensure spaces are
978 // passed in correctly)"
979 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
980 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
981 + "-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"
982 + "-jvmmempc=PERCENT\tOnly available with standalone executable jar or jalview.bin.Launcher. Limit maximum heap size (memory) to PERCENT% of total physical memory detected. This defaults to 90 if total physical memory can be detected. See https://www.jalview.org/help/html/memory.html for more details.\n"
983 + "-jvmmemmax=MAXMEMORY\tOnly available with standalone executable jar or jalview.bin.Launcher. Limit maximum heap size (memory) to MAXMEMORY. MAXMEMORY can be specified in bytes, kilobytes(k), megabytes(m), gigabytes(g) or if you're lucky enough, terabytes(t). This defaults to 32g if total physical memory can be detected, or to 8g if total physical memory cannot be detected. See https://www.jalview.org/help/html/memory.html for more details.\n"
984 + "\n~Read documentation in Application or visit https://www.jalview.org for description of Features and Annotations file~\n\n");
987 private static void startUsageStats(final Desktop desktop)
990 * start a User Config prompt asking if we can log usage statistics.
992 PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
993 "USAGESTATS", "Jalview Usage Statistics",
994 "Do you want to help make Jalview better by enabling "
995 + "the collection of usage statistics with Google Analytics ?"
996 + "\n\n(you can enable or disable usage tracking in the preferences)",
1003 "Initialising googletracker for usage stats.");
1004 Cache.initGoogleTracker();
1005 Cache.log.debug("Tracking enabled.");
1012 Cache.log.debug("Not enabling Google Tracking.");
1015 desktop.addDialogThread(prompter);
1019 * Locate the given string as a file and pass it to the groovy interpreter.
1021 * @param groovyscript
1022 * the script to execute
1023 * @param jalviewContext
1024 * the Jalview Desktop object passed in to the groovy binding as the
1027 private void executeGroovyScript(String groovyscript, AlignFrame af)
1030 * for scripts contained in files
1037 if (groovyscript.trim().equals("STDIN"))
1039 // read from stdin into a tempfile and execute it
1042 tfile = File.createTempFile("jalview", "groovy");
1043 PrintWriter outfile = new PrintWriter(
1044 new OutputStreamWriter(new FileOutputStream(tfile)));
1045 BufferedReader br = new BufferedReader(
1046 new InputStreamReader(System.in));
1048 while ((line = br.readLine()) != null)
1050 outfile.write(line + "\n");
1056 } catch (Exception ex)
1058 System.err.println("Failed to read from STDIN into tempfile "
1059 + ((tfile == null) ? "(tempfile wasn't created)"
1060 : tfile.toString()));
1061 ex.printStackTrace();
1066 sfile = tfile.toURI().toURL();
1067 } catch (Exception x)
1070 "Unexpected Malformed URL Exception for temporary file created from STDIN: "
1072 x.printStackTrace();
1080 sfile = new URI(groovyscript).toURL();
1081 } catch (Exception x)
1083 tfile = new File(groovyscript);
1084 if (!tfile.exists())
1086 System.err.println("File '" + groovyscript + "' does not exist.");
1089 if (!tfile.canRead())
1091 System.err.println("File '" + groovyscript + "' cannot be read.");
1094 if (tfile.length() < 1)
1096 System.err.println("File '" + groovyscript + "' is empty.");
1101 sfile = tfile.getAbsoluteFile().toURI().toURL();
1102 } catch (Exception ex)
1104 System.err.println("Failed to create a file URL for "
1105 + tfile.getAbsoluteFile());
1112 Map<String, java.lang.Object> vbinding = new HashMap<>();
1113 vbinding.put("Jalview", this);
1116 vbinding.put("currentAlFrame", af);
1118 Binding gbinding = new Binding(vbinding);
1119 GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
1120 gse.run(sfile.toString(), gbinding);
1121 if ("STDIN".equals(groovyscript))
1123 // delete temp file that we made -
1124 // only if it was successfully executed
1127 } catch (Exception e)
1129 System.err.println("Exception Whilst trying to execute file " + sfile
1130 + " as a groovy script.");
1131 e.printStackTrace(System.err);
1136 public static boolean isHeadlessMode()
1138 String isheadless = System.getProperty("java.awt.headless");
1139 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1146 public AlignFrame[] getAlignFrames()
1148 return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
1149 : Desktop.getAlignFrames();
1154 * Quit method delegates to Desktop.quit - unless running in headless mode
1155 * when it just ends the JVM
1159 if (desktop != null)
1169 public static AlignFrame getCurrentAlignFrame()
1171 return Jalview.currentAlignFrame;
1174 public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
1176 Jalview.currentAlignFrame = currentAlignFrame;