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.gui.AlignFrame;
24 import jalview.gui.Desktop;
25 import jalview.io.BioJsHTMLOutput;
26 import jalview.io.HtmlSvgOutput;
27 import jalview.util.MessageManager;
28 import jalview.util.Platform;
29 import jalview.ws.jws2.Jws2Discoverer;
31 import java.awt.event.ActionEvent;
32 import java.awt.event.ActionListener;
33 import java.io.BufferedReader;
35 import java.io.FileOutputStream;
36 import java.io.IOException;
37 import java.io.OutputStreamWriter;
38 import java.io.PrintWriter;
39 import java.lang.reflect.Constructor;
40 import java.net.MalformedURLException;
43 import java.net.URLDecoder;
44 import java.security.AllPermission;
45 import java.security.CodeSource;
46 import java.security.PermissionCollection;
47 import java.security.Permissions;
48 import java.security.Policy;
49 import java.util.HashMap;
51 import java.util.Vector;
53 import javax.swing.UIManager;
54 import javax.swing.UnsupportedLookAndFeelException;
57 * Main class for Jalview Application <br>
59 * start with java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview
68 // grab all the rights we can the JVM
69 Policy.setPolicy(new Policy()
71 public PermissionCollection getPermissions(CodeSource codesource)
73 Permissions perms = new Permissions();
74 perms.add(new AllPermission());
85 * main class for Jalview application
88 * open <em>filename</em>
90 public static void main(String[] args)
92 System.out.println("Java version: "
93 + System.getProperty("java.version"));
94 System.out.println(System.getProperty("os.arch") + " "
95 + System.getProperty("os.name") + " "
96 + System.getProperty("os.version"));
98 ArgsParser aparser = new ArgsParser(args);
99 boolean headless = false;
101 if (aparser.contains("help") || aparser.contains("h"))
106 if (aparser.contains("nodisplay") || aparser.contains("nogui")
107 || aparser.contains("headless"))
109 System.setProperty("java.awt.headless", "true");
112 Cache.loadProperties(aparser.getValue("props")); // must do this before
115 final String jabawsUrl = aparser.getValue("jabaws");
116 if (jabawsUrl != null)
120 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
121 } catch (MalformedURLException e)
123 System.err.println("Invalid jabaws parameter: " + jabawsUrl
128 String defs = aparser.getValue("setprop");
131 int p = defs.indexOf('=');
134 System.err.println("Ignoring invalid setprop argument : " + defs);
138 System.out.println("Executing setprop argument: " + defs);
139 // DISABLED FOR SECURITY REASONS
140 // TODO: add a property to allow properties to be overriden by cli args
141 // Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
143 defs = aparser.getValue("setprop");
145 if (System.getProperty("java.awt.headless") != null
146 && System.getProperty("java.awt.headless").equals("true"))
150 System.setProperty("http.agent",
151 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
155 } catch (java.lang.NoClassDefFoundError error)
157 error.printStackTrace();
159 .println("\nEssential logging libraries not found."
160 + "\nUse: java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview");
164 Desktop desktop = null;
168 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
169 } catch (Exception ex)
172 if (new Platform().isAMac())
174 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
176 System.setProperty("apple.laf.useScreenMenuBar", "true");
179 UIManager.setLookAndFeel(ch.randelshofer.quaqua.QuaquaManager
181 } catch (UnsupportedLookAndFeelException e)
183 // TODO Auto-generated catch block
190 desktop = new Desktop();
191 desktop.setInBatchMode(true); // indicate we are starting up
192 desktop.setVisible(true);
193 desktop.startServiceDiscovery();
194 if (!aparser.contains("nousagestats"))
196 startUsageStats(desktop);
198 if (!aparser.contains("noquestionnaire"))
200 String url = aparser.getValue("questionnaire");
203 // Start the desktop questionnaire prompter with the specified
205 Cache.log.debug("Starting questionnaire url at " + url);
206 desktop.checkForQuestionnaire(url);
210 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
212 // Start the desktop questionnaire prompter with the specified
215 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
217 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
218 Cache.log.debug("Starting questionnaire with default url: "
220 desktop.checkForQuestionnaire(defurl);
225 desktop.checkForNews();
228 if (!isHeadlessMode())
230 BioJsHTMLOutput.updateBioJS();
233 String file = null, protocol = null, format = null, data = null;
234 jalview.io.FileLoader fileLoader = new jalview.io.FileLoader(!headless);
235 Vector getFeatures = null; // vector of das source nicknames to fetch
238 String groovyscript = null; // script to execute after all loading is
239 // completed one way or another
240 // extract groovy argument and execute if necessary
241 groovyscript = aparser.getValue("groovy", true);
242 file = aparser.getValue("open", true);
244 if (file == null && desktop == null)
246 System.out.println("No files to open!");
249 String vamsasImport = aparser.getValue("vdoc"), vamsasSession = aparser
251 if (vamsasImport != null || vamsasSession != null)
253 if (desktop == null || headless)
256 .println("Headless vamsas sessions not yet supported. Sorry.");
259 // if we have a file, start a new session and import it.
260 boolean inSession = false;
261 if (vamsasImport != null)
265 String viprotocol = jalview.io.AppletFormatAdapter
266 .checkProtocol(vamsasImport);
267 if (viprotocol == jalview.io.FormatAdapter.FILE)
269 inSession = desktop.vamsasImport(new File(vamsasImport));
271 else if (viprotocol == jalview.io.FormatAdapter.URL)
273 inSession = desktop.vamsasImport(new URL(vamsasImport));
276 } catch (Exception e)
278 System.err.println("Exeption when importing " + vamsasImport
279 + " as a vamsas document.");
284 System.err.println("Failed to import " + vamsasImport
285 + " as a vamsas document.");
289 System.out.println("Imported Successfully into new session "
290 + desktop.getVamsasApplication().getCurrentSession());
293 if (vamsasSession != null)
295 if (vamsasImport != null)
297 // close the newly imported session and import the Jalview specific
298 // remnants into the new session later on.
299 desktop.vamsasStop_actionPerformed(null);
301 // now join the new session
304 if (desktop.joinVamsasSession(vamsasSession))
306 System.out.println("Successfully joined vamsas session "
311 System.err.println("WARNING: Failed to join vamsas session "
314 } catch (Exception e)
316 System.err.println("ERROR: Failed to join vamsas session "
320 if (vamsasImport != null)
322 // the Jalview specific remnants can now be imported into the new
323 // session at the user's leisure.
325 .info("Skipping Push for import of data into existing vamsas session."); // TODO:
330 // desktop.getVamsasApplication().push_update();
335 // Finally, deal with the remaining input data.
340 desktop.setProgressBar(MessageManager.getString("status.processing_commandline_args"),
341 progress = System.currentTimeMillis());
343 System.out.println("Opening file: " + file);
345 if (!file.startsWith("http://"))
347 if (!(new java.io.File(file)).exists())
349 System.out.println("Can't find " + file);
357 protocol = jalview.io.AppletFormatAdapter.checkProtocol(file);
359 format = new jalview.io.IdentifyFile().Identify(file, protocol);
361 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
365 System.out.println("error");
370 data = aparser.getValue("colour", true);
373 data.replaceAll("%20", " ");
375 jalview.schemes.ColourSchemeI cs = jalview.schemes.ColourSchemeProperty
376 .getColour(af.getViewport().getAlignment(), data);
380 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(
382 ucs.parseAppletParameter(data);
386 System.out.println("colour is " + data);
390 // Must maintain ability to use the groups flag
391 data = aparser.getValue("groups", true);
394 af.parseFeaturesFile(data,
395 jalview.io.AppletFormatAdapter.checkProtocol(data));
396 System.out.println("Added " + data);
398 data = aparser.getValue("features", true);
401 af.parseFeaturesFile(data,
402 jalview.io.AppletFormatAdapter.checkProtocol(data));
403 System.out.println("Added " + data);
406 data = aparser.getValue("annotations", true);
409 af.loadJalviewDataFile(data, null, null, null);
410 System.out.println("Added " + data);
412 // set or clear the sortbytree flag.
413 if (aparser.contains("sortbytree"))
415 af.getViewport().setSortByTree(true);
417 if (aparser.contains("no-annotation"))
419 af.getViewport().setShowAnnotation(false);
421 if (aparser.contains("nosortbytree"))
423 af.getViewport().setSortByTree(false);
425 data = aparser.getValue("tree", true);
428 jalview.io.NewickFile fin = null;
431 fin = new jalview.io.NewickFile(data,
432 jalview.io.AppletFormatAdapter.checkProtocol(data));
435 af.getViewport().setCurrentTree(
436 af.ShowNewickTree(fin, data).getTree());
437 System.out.println("Added tree " + data);
439 } catch (IOException ex)
441 System.err.println("Couldn't add tree " + data);
442 ex.printStackTrace(System.err);
445 // TODO - load PDB structure(s) to alignment JAL-629
446 // (associate with identical sequence in alignment, or a specified
449 getFeatures = checkDasArguments(aparser);
450 if (af != null && getFeatures != null)
452 FeatureFetcher ff = startFeatureFetching(getFeatures);
455 while (!ff.allFinished() || af.operationInProgress())
457 // wait around until fetching is finished.
461 } catch (Exception e)
467 getFeatures = null; // have retrieved features - forget them now.
469 if (groovyscript != null)
471 // Execute the groovy script after we've done all the rendering stuff
472 // and before any images or figures are generated.
473 if (jalview.bin.Cache.groovyJarsPresent())
475 System.out.println("Executing script " + groovyscript);
476 executeGroovyScript(groovyscript, new Object[]
482 .println("Sorry. Groovy Support is not available, so ignoring the provided groovy script "
487 String imageName = "unnamed.png";
488 while (aparser.getSize() > 1)
490 format = aparser.nextValue();
491 file = aparser.nextValue();
493 if (format.equalsIgnoreCase("png"))
495 af.createPNG(new java.io.File(file));
496 imageName = (new java.io.File(file)).getName();
497 System.out.println("Creating PNG image: " + file);
500 else if (format.equalsIgnoreCase("svg"))
502 File imageFile = new java.io.File(file);
503 imageName = imageFile.getName();
504 af.createSVG(imageFile);
505 System.out.println("Creating SVG image: " + file);
508 else if (format.equalsIgnoreCase("html"))
510 File imageFile = new java.io.File(file);
511 imageName = imageFile.getName();
512 new HtmlSvgOutput(new java.io.File(file), af.alignPanel);
513 System.out.println("Creating HTML image: " + file);
516 else if (format.equalsIgnoreCase("imgMap"))
518 af.createImageMap(new java.io.File(file), imageName);
519 System.out.println("Creating image map: " + file);
522 else if (format.equalsIgnoreCase("eps"))
524 File outputFile = new java.io.File(file);
525 System.out.println("Creating EPS file: "
526 + outputFile.getAbsolutePath());
527 af.createEPS(outputFile);
531 if (af.saveAlignment(file, format))
533 System.out.println("Written alignment in " + format
534 + " format to " + file);
538 System.out.println("Error writing file " + file + " in "
539 + format + " format!!");
544 while (aparser.getSize() > 0)
546 System.out.println("Unknown arg: " + aparser.nextValue());
550 AlignFrame startUpAlframe = null;
551 // We'll only open the default file if the desktop is visible.
553 // ////////////////////
555 if (!headless && file == null && vamsasImport == null
556 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
558 file = jalview.bin.Cache.getDefault(
560 jalview.bin.Cache.getDefault("www.jalview.org",
561 "http://www.jalview.org")
562 + "/examples/exampleFile_2_7.jar");
563 if (file.equals("http://www.jalview.org/examples/exampleFile_2_3.jar"))
565 // hardwire upgrade of the startup file
566 file.replace("_2_3.jar", "_2_7.jar");
567 // and remove the stale setting
568 jalview.bin.Cache.removeProperty("STARTUP_FILE");
573 if (file.indexOf("http:") > -1)
578 if (file.endsWith(".jar"))
584 format = new jalview.io.IdentifyFile().Identify(file, protocol);
587 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
589 getFeatures = checkDasArguments(aparser);
590 // extract groovy arguments before anything else.
592 // If the user has specified features to be retrieved,
593 // or a groovy script to be executed, do them if they
594 // haven't been done already
595 // fetch features for the default alignment
596 if (getFeatures != null)
598 if (startUpAlframe != null)
600 startFeatureFetching(getFeatures);
603 // Once all other stuff is done, execute any groovy scripts (in order)
604 if (groovyscript != null)
606 if (jalview.bin.Cache.groovyJarsPresent())
608 System.out.println("Executing script " + groovyscript);
609 executeGroovyScript(groovyscript, new Object[]
610 { desktop, startUpAlframe });
615 .println("Sorry. Groovy Support is not available, so ignoring the provided groovy script "
619 // and finally, turn off batch mode indicator - if the desktop still exists
624 desktop.setProgressBar(null, progress);
626 desktop.setInBatchMode(false);
630 private static void showUsage()
633 .println("Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
634 + "-nodisplay\tRun Jalview without User Interface.\n"
635 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
636 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
637 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
638 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
639 + "-features FILE\tUse the given file to mark features on the alignment.\n"
640 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
641 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
642 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
643 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
644 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
645 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
646 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
647 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
648 + "-png FILE\tCreate PNG image FILE from alignment.\n"
649 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
650 + "-html FILE\tCreate HTML file from alignment.\n"
651 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
652 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
653 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
654 + "-noquestionnaire\tTurn off questionnaire check.\n"
655 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
656 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
658 // "-setprop PROPERTY=VALUE\tSet the given Jalview property, after all other properties files have been read\n\t (quote the 'PROPERTY=VALUE' pair to ensure spaces are passed in correctly)"
659 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
660 + "-dasserver nickname=URL\tAdd and enable a das server with given nickname\n\t\t\t(alphanumeric or underscores only) for retrieval of features for all alignments.\n"
661 + "\t\t\tSources that also support the sequence command may be specified by prepending the URL with sequence:\n"
662 + "\t\t\t e.g. sequence:http://localdas.somewhere.org/das/source)\n"
663 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
665 // "-vdoc vamsas-document\tImport vamsas document into new session or join existing session with same URN\n"
666 // + "-vses vamsas-session\tJoin session with given URN\n"
667 + "-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"
668 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
671 private static void startUsageStats(final Desktop desktop)
674 * start a User Config prompt asking if we can log usage statistics.
676 jalview.gui.PromptUserConfig prompter = new jalview.gui.PromptUserConfig(
679 "Jalview Usage Statistics",
680 "Do you want to help make Jalview better by enabling "
681 + "the collection of usage statistics with Google Analytics ?"
682 + "\n\n(you can enable or disable usage tracking in the preferences)",
688 .debug("Initialising googletracker for usage stats.");
689 Cache.initGoogleTracker();
690 Cache.log.debug("Tracking enabled.");
696 Cache.log.debug("Not enabling Google Tracking.");
699 desktop.addDialogThread(prompter);
703 * Locate the given string as a file and pass it to the groovy interpreter.
705 * @param groovyscript
706 * the script to execute
707 * @param jalviewContext
708 * the Jalview Desktop object passed in to the groovy binding as the
711 private static void executeGroovyScript(String groovyscript,
712 Object[] jalviewContext)
714 if (jalviewContext == null)
717 .println("Sorry. Groovy support is currently only available when running with the Jalview GUI enabled.");
720 * for scripts contained in files
727 if (groovyscript.trim().equals("STDIN"))
729 // read from stdin into a tempfile and execute it
732 tfile = File.createTempFile("jalview", "groovy");
733 PrintWriter outfile = new PrintWriter(new OutputStreamWriter(
734 new FileOutputStream(tfile)));
735 BufferedReader br = new BufferedReader(
736 new java.io.InputStreamReader(System.in));
738 while ((line = br.readLine()) != null)
740 outfile.write(line + "\n");
746 } catch (Exception ex)
748 System.err.println("Failed to read from STDIN into tempfile "
749 + ((tfile == null) ? "(tempfile wasn't created)" : tfile
751 ex.printStackTrace();
756 sfile = tfile.toURI().toURL();
757 } catch (Exception x)
760 .println("Unexpected Malformed URL Exception for temporary file created from STDIN: "
770 sfile = new URI(groovyscript).toURL();
771 } catch (Exception x)
773 tfile = new File(groovyscript);
776 System.err.println("File '" + groovyscript + "' does not exist.");
779 if (!tfile.canRead())
781 System.err.println("File '" + groovyscript + "' cannot be read.");
784 if (tfile.length() < 1)
786 System.err.println("File '" + groovyscript + "' is empty.");
791 sfile = tfile.getAbsoluteFile().toURI().toURL();
792 } catch (Exception ex)
794 System.err.println("Failed to create a file URL for "
795 + tfile.getAbsoluteFile());
800 boolean success = false;
804 * The following code performs the GroovyScriptEngine invocation using
805 * reflection, and is equivalent to this fragment from the embedding
806 * groovy documentation on the groovy site: <code> import
807 * groovy.lang.Binding; import groovy.util.GroovyScriptEngine;
809 * String[] roots = new String[] { "/my/groovy/script/path" };
810 * GroovyScriptEngine gse = new GroovyScriptEngine(roots); Binding binding
811 * = new Binding(); binding.setVariable("input", "world");
812 * gse.run("hello.groovy", binding); </code>
816 int blen = ((jalviewContext[0] == null) ? 0 : 1)
817 + ((jalviewContext[1] == null) ? 0 : 1);
818 String cnames[] = new String[]
819 { "Jalview", "currentAlFrame" };
820 bspec = new Class[blen * 2];
821 binding = new Object[blen * 2];
823 ClassLoader cl = null;
824 Map<String, Object> vbinding = new HashMap<String, Object>();
825 for (int jc = 0; jc < jalviewContext.length; jc++)
827 if (jalviewContext[jc] != null)
831 cl = jalviewContext[jc].getClass().getClassLoader();
833 bspec[blen * 2] = String.class;
834 bspec[blen * 2 + 1] = Object.class;
835 binding[blen * 2] = cnames[jc];
836 binding[blen * 2 + 1] = jalviewContext[jc];
837 vbinding.put(cnames[jc], jalviewContext[jc]);
841 Class<?> gbindingc = cl.loadClass("groovy.lang.Binding");
842 Constructor<?> gbcons;
846 gbcons = gbindingc.getConstructor(Map.class);
847 gbinding = gbcons.newInstance(vbinding);
848 } catch (NoSuchMethodException x)
850 // old style binding config - using series of string/object values to
852 gbcons = gbindingc.getConstructor();
853 gbinding = gbcons.newInstance();
854 java.lang.reflect.Method setvar = gbindingc.getMethod(
855 "setVariable", bspec);
856 setvar.invoke(gbinding, binding);
859 Class<?> gsec = cl.loadClass("groovy.util.GroovyScriptEngine");
860 Constructor<?> gseccons = gsec.getConstructor(new Class[]
861 { URL[].class }); // String[].class });
862 Object gse = gseccons.newInstance(new Object[]
864 { sfile } }); // .toString() } });
865 java.lang.reflect.Method run = gsec.getMethod("run", new Class[]
866 { String.class, gbindingc });
867 run.invoke(gse, new Object[]
868 { sfile.toString(), gbinding });
870 } catch (Exception e)
872 System.err.println("Exception Whilst trying to execute file " + sfile
873 + " as a groovy script.");
874 e.printStackTrace(System.err);
877 if (success && groovyscript.equals("STDIN"))
879 // delete temp file that we made - but only if it was successfully
886 * Check commandline for any das server definitions or any fetchfrom switches
888 * @return vector of DAS source nicknames to retrieve from
890 private static Vector checkDasArguments(ArgsParser aparser)
892 Vector source = null;
894 String locsources = Cache.getProperty(Cache.DAS_LOCAL_SOURCE);
895 while ((data = aparser.getValue("dasserver", true)) != null)
897 String nickname = null;
899 boolean seq = false, feat = true;
900 int pos = data.indexOf('=');
901 // determine capabilities
904 nickname = data.substring(0, pos);
906 url = data.substring(pos + 1);
908 && (url.startsWith("http:") || url
909 .startsWith("sequence:http:")))
911 if (nickname == null)
915 if (locsources == null)
923 locsources = locsources + nickname + "|" + url;
925 .println("NOTE! dasserver parameter not yet really supported (got args of "
926 + nickname + "|" + url);
929 source = new Vector();
931 source.addElement(nickname);
933 } // loop until no more server entries are found.
934 if (locsources != null && locsources.indexOf('|') > -1)
936 Cache.log.debug("Setting local source list in properties file to:\n"
938 Cache.setProperty(Cache.DAS_LOCAL_SOURCE, locsources);
940 while ((data = aparser.getValue("fetchfrom", true)) != null)
942 System.out.println("adding source '" + data + "'");
945 source = new Vector();
947 source.addElement(data);
953 * start a feature fetcher for every alignment frame
957 private static FeatureFetcher startFeatureFetching(final Vector dasSources)
959 FeatureFetcher ff = new FeatureFetcher();
960 AlignFrame afs[] = Desktop.getAlignFrames();
961 if (afs == null || afs.length == 0)
965 for (int i = 0; i < afs.length; i++)
967 ff.addFetcher(afs[i], dasSources);
972 public static boolean isHeadlessMode()
974 String isheadless = System.getProperty("java.awt.headless");
975 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
984 * Notes: this argParser does not distinguish between parameter switches,
985 * parameter values and argument text. If an argument happens to be identical to
986 * a parameter, it will be taken as such (even though it didn't have a '-'
989 * @author Andrew Waterhouse and JBP documented.
993 class rnabuttonlistener implements ActionListener
995 public void actionPerformed(ActionEvent arg0)
997 System.out.println("Good idea ! ");
1002 class pbuttonlistener implements ActionListener
1004 public void actionPerformed(ActionEvent arg0)
1012 Vector vargs = null;
1014 public ArgsParser(String[] args)
1016 vargs = new Vector();
1017 for (int i = 0; i < args.length; i++)
1019 String arg = args[i].trim();
1020 if (arg.charAt(0) == '-')
1022 arg = arg.substring(1);
1024 vargs.addElement(arg);
1029 * check for and remove first occurence of arg+parameter in arglist.
1032 * @return return the argument following the given arg if arg was in list.
1034 public String getValue(String arg)
1036 return getValue(arg, false);
1039 public String getValue(String arg, boolean utf8decode)
1041 int index = vargs.indexOf(arg);
1042 String dc = null, ret = null;
1045 ret = vargs.elementAt(index + 1).toString();
1046 vargs.removeElementAt(index);
1047 vargs.removeElementAt(index);
1048 if (utf8decode && ret != null)
1052 dc = URLDecoder.decode(ret, "UTF-8");
1054 } catch (Exception e)
1056 // TODO: log failure to decode
1064 * check for and remove first occurence of arg in arglist.
1067 * @return true if arg was present in argslist.
1069 public boolean contains(String arg)
1071 if (vargs.contains(arg))
1073 vargs.removeElement(arg);
1082 public String nextValue()
1084 return vargs.remove(0).toString();
1087 public int getSize()
1089 return vargs.size();
1095 * keep track of feature fetching tasks.
1100 class FeatureFetcher
1103 * TODO: generalise to track all jalview events to orchestrate batch
1104 * processing events.
1107 private int queued = 0;
1109 private int running = 0;
1111 public FeatureFetcher()
1116 public void addFetcher(final AlignFrame af, final Vector dasSources)
1118 final long id = System.currentTimeMillis();
1120 final FeatureFetcher us = this;
1121 new Thread(new Runnable()
1132 af.setProgressBar(MessageManager.getString("status.das_features_being_retrived"), id);
1133 af.featureSettings_actionPerformed(null);
1134 af.featureSettings.fetchDasFeatures(dasSources, true);
1135 af.setProgressBar(null, id);
1144 public synchronized boolean allFinished()
1146 return queued == 0 && running == 0;