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 BioJsHTMLOutput bjs = new BioJsHTMLOutput(null, null);
231 String file = null, protocol = null, format = null, data = null;
232 jalview.io.FileLoader fileLoader = new jalview.io.FileLoader();
233 Vector getFeatures = null; // vector of das source nicknames to fetch
236 String groovyscript = null; // script to execute after all loading is
237 // completed one way or another
238 // extract groovy argument and execute if necessary
239 groovyscript = aparser.getValue("groovy", true);
240 file = aparser.getValue("open", true);
242 if (file == null && desktop == null)
244 System.out.println("No files to open!");
247 String vamsasImport = aparser.getValue("vdoc"), vamsasSession = aparser
249 if (vamsasImport != null || vamsasSession != null)
251 if (desktop == null || headless)
254 .println("Headless vamsas sessions not yet supported. Sorry.");
257 // if we have a file, start a new session and import it.
258 boolean inSession = false;
259 if (vamsasImport != null)
263 String viprotocol = jalview.io.AppletFormatAdapter
264 .checkProtocol(vamsasImport);
265 if (viprotocol == jalview.io.FormatAdapter.FILE)
267 inSession = desktop.vamsasImport(new File(vamsasImport));
269 else if (viprotocol == jalview.io.FormatAdapter.URL)
271 inSession = desktop.vamsasImport(new URL(vamsasImport));
274 } catch (Exception e)
276 System.err.println("Exeption when importing " + vamsasImport
277 + " as a vamsas document.");
282 System.err.println("Failed to import " + vamsasImport
283 + " as a vamsas document.");
287 System.out.println("Imported Successfully into new session "
288 + desktop.getVamsasApplication().getCurrentSession());
291 if (vamsasSession != null)
293 if (vamsasImport != null)
295 // close the newly imported session and import the Jalview specific
296 // remnants into the new session later on.
297 desktop.vamsasStop_actionPerformed(null);
299 // now join the new session
302 if (desktop.joinVamsasSession(vamsasSession))
304 System.out.println("Successfully joined vamsas session "
309 System.err.println("WARNING: Failed to join vamsas session "
312 } catch (Exception e)
314 System.err.println("ERROR: Failed to join vamsas session "
318 if (vamsasImport != null)
320 // the Jalview specific remnants can now be imported into the new
321 // session at the user's leisure.
323 .info("Skipping Push for import of data into existing vamsas session."); // TODO:
328 // desktop.getVamsasApplication().push_update();
333 // Finally, deal with the remaining input data.
338 desktop.setProgressBar(MessageManager.getString("status.processing_commandline_args"),
339 progress = System.currentTimeMillis());
341 System.out.println("Opening file: " + file);
343 if (!file.startsWith("http://"))
345 if (!(new java.io.File(file)).exists())
347 System.out.println("Can't find " + file);
355 protocol = jalview.io.AppletFormatAdapter.checkProtocol(file);
357 format = new jalview.io.IdentifyFile().Identify(file, protocol);
359 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
363 System.out.println("error");
368 data = aparser.getValue("colour", true);
371 data.replaceAll("%20", " ");
373 jalview.schemes.ColourSchemeI cs = jalview.schemes.ColourSchemeProperty
374 .getColour(af.getViewport().getAlignment(), data);
378 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(
380 ucs.parseAppletParameter(data);
384 System.out.println("colour is " + data);
388 // Must maintain ability to use the groups flag
389 data = aparser.getValue("groups", true);
392 af.parseFeaturesFile(data,
393 jalview.io.AppletFormatAdapter.checkProtocol(data));
394 System.out.println("Added " + data);
396 data = aparser.getValue("features", true);
399 af.parseFeaturesFile(data,
400 jalview.io.AppletFormatAdapter.checkProtocol(data));
401 System.out.println("Added " + data);
404 data = aparser.getValue("annotations", true);
407 af.loadJalviewDataFile(data, null, null, null);
408 System.out.println("Added " + data);
410 // set or clear the sortbytree flag.
411 if (aparser.contains("sortbytree"))
413 af.getViewport().setSortByTree(true);
415 if (aparser.contains("no-annotation"))
417 af.getViewport().setShowAnnotation(false);
419 if (aparser.contains("nosortbytree"))
421 af.getViewport().setSortByTree(false);
423 data = aparser.getValue("tree", true);
426 jalview.io.NewickFile fin = null;
429 fin = new jalview.io.NewickFile(data,
430 jalview.io.AppletFormatAdapter.checkProtocol(data));
433 af.getViewport().setCurrentTree(
434 af.ShowNewickTree(fin, data).getTree());
435 System.out.println("Added tree " + data);
437 } catch (IOException ex)
439 System.err.println("Couldn't add tree " + data);
440 ex.printStackTrace(System.err);
443 // TODO - load PDB structure(s) to alignment JAL-629
444 // (associate with identical sequence in alignment, or a specified
447 getFeatures = checkDasArguments(aparser);
448 if (af != null && getFeatures != null)
450 FeatureFetcher ff = startFeatureFetching(getFeatures);
453 while (!ff.allFinished() || af.operationInProgress())
455 // wait around until fetching is finished.
459 } catch (Exception e)
465 getFeatures = null; // have retrieved features - forget them now.
467 if (groovyscript != null)
469 // Execute the groovy script after we've done all the rendering stuff
470 // and before any images or figures are generated.
471 if (jalview.bin.Cache.groovyJarsPresent())
473 System.out.println("Executing script " + groovyscript);
474 executeGroovyScript(groovyscript, new Object[]
480 .println("Sorry. Groovy Support is not available, so ignoring the provided groovy script "
485 String imageName = "unnamed.png";
486 while (aparser.getSize() > 1)
488 format = aparser.nextValue();
489 file = aparser.nextValue();
491 if (format.equalsIgnoreCase("png"))
493 af.createPNG(new java.io.File(file));
494 imageName = (new java.io.File(file)).getName();
495 System.out.println("Creating PNG image: " + file);
498 else if (format.equalsIgnoreCase("svg"))
500 File imageFile = new java.io.File(file);
501 imageName = imageFile.getName();
502 af.createSVG(imageFile);
503 System.out.println("Creating SVG image: " + file);
506 else if (format.equalsIgnoreCase("html"))
508 File imageFile = new java.io.File(file);
509 imageName = imageFile.getName();
510 new HtmlSvgOutput(new java.io.File(file), af.alignPanel);
511 System.out.println("Creating HTML image: " + file);
514 else if (format.equalsIgnoreCase("imgMap"))
516 af.createImageMap(new java.io.File(file), imageName);
517 System.out.println("Creating image map: " + file);
520 else if (format.equalsIgnoreCase("eps"))
522 System.out.println("Creating EPS file: " + file);
523 af.createEPS(new java.io.File(file));
527 if (af.saveAlignment(file, format))
529 System.out.println("Written alignment in " + format
530 + " format to " + file);
534 System.out.println("Error writing file " + file + " in "
535 + format + " format!!");
540 while (aparser.getSize() > 0)
542 System.out.println("Unknown arg: " + aparser.nextValue());
546 AlignFrame startUpAlframe = null;
547 // We'll only open the default file if the desktop is visible.
549 // ////////////////////
551 if (!headless && file == null && vamsasImport == null
552 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
554 file = jalview.bin.Cache.getDefault(
556 jalview.bin.Cache.getDefault("www.jalview.org",
557 "http://www.jalview.org")
558 + "/examples/exampleFile_2_7.jar");
559 if (file.equals("http://www.jalview.org/examples/exampleFile_2_3.jar"))
561 // hardwire upgrade of the startup file
562 file.replace("_2_3.jar", "_2_7.jar");
563 // and remove the stale setting
564 jalview.bin.Cache.removeProperty("STARTUP_FILE");
569 if (file.indexOf("http:") > -1)
574 if (file.endsWith(".jar"))
580 format = new jalview.io.IdentifyFile().Identify(file, protocol);
583 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
585 getFeatures = checkDasArguments(aparser);
586 // extract groovy arguments before anything else.
588 // If the user has specified features to be retrieved,
589 // or a groovy script to be executed, do them if they
590 // haven't been done already
591 // fetch features for the default alignment
592 if (getFeatures != null)
594 if (startUpAlframe != null)
596 startFeatureFetching(getFeatures);
599 // Once all other stuff is done, execute any groovy scripts (in order)
600 if (groovyscript != null)
602 if (jalview.bin.Cache.groovyJarsPresent())
604 System.out.println("Executing script " + groovyscript);
605 executeGroovyScript(groovyscript, new Object[]
606 { desktop, startUpAlframe });
611 .println("Sorry. Groovy Support is not available, so ignoring the provided groovy script "
615 // and finally, turn off batch mode indicator - if the desktop still exists
620 desktop.setProgressBar(null, progress);
622 desktop.setInBatchMode(false);
626 private static void showUsage()
629 .println("Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
630 + "-nodisplay\tRun Jalview without User Interface.\n"
631 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
632 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
633 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
634 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
635 + "-features FILE\tUse the given file to mark features on the alignment.\n"
636 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
637 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
638 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
639 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
640 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
641 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
642 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
643 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
644 + "-png FILE\tCreate PNG image FILE from alignment.\n"
645 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
646 + "-html FILE\tCreate HTML file from alignment.\n"
647 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
648 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
649 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
650 + "-noquestionnaire\tTurn off questionnaire check.\n"
651 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
652 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
654 // "-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)"
655 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
656 + "-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"
657 + "\t\t\tSources that also support the sequence command may be specified by prepending the URL with sequence:\n"
658 + "\t\t\t e.g. sequence:http://localdas.somewhere.org/das/source)\n"
659 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
661 // "-vdoc vamsas-document\tImport vamsas document into new session or join existing session with same URN\n"
662 // + "-vses vamsas-session\tJoin session with given URN\n"
663 + "-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"
664 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
667 private static void startUsageStats(final Desktop desktop)
670 * start a User Config prompt asking if we can log usage statistics.
672 jalview.gui.PromptUserConfig prompter = new jalview.gui.PromptUserConfig(
675 "Jalview Usage Statistics",
676 "Do you want to help make Jalview better by enabling "
677 + "the collection of usage statistics with Google Analytics ?"
678 + "\n\n(you can enable or disable usage tracking in the preferences)",
684 .debug("Initialising googletracker for usage stats.");
685 Cache.initGoogleTracker();
686 Cache.log.debug("Tracking enabled.");
692 Cache.log.debug("Not enabling Google Tracking.");
695 desktop.addDialogThread(prompter);
699 * Locate the given string as a file and pass it to the groovy interpreter.
701 * @param groovyscript
702 * the script to execute
703 * @param jalviewContext
704 * the Jalview Desktop object passed in to the groovy binding as the
707 private static void executeGroovyScript(String groovyscript,
708 Object[] jalviewContext)
710 if (jalviewContext == null)
713 .println("Sorry. Groovy support is currently only available when running with the Jalview GUI enabled.");
716 * for scripts contained in files
723 if (groovyscript.trim().equals("STDIN"))
725 // read from stdin into a tempfile and execute it
728 tfile = File.createTempFile("jalview", "groovy");
729 PrintWriter outfile = new PrintWriter(new OutputStreamWriter(
730 new FileOutputStream(tfile)));
731 BufferedReader br = new BufferedReader(
732 new java.io.InputStreamReader(System.in));
734 while ((line = br.readLine()) != null)
736 outfile.write(line + "\n");
742 } catch (Exception ex)
744 System.err.println("Failed to read from STDIN into tempfile "
745 + ((tfile == null) ? "(tempfile wasn't created)" : tfile
747 ex.printStackTrace();
752 sfile = tfile.toURI().toURL();
753 } catch (Exception x)
756 .println("Unexpected Malformed URL Exception for temporary file created from STDIN: "
766 sfile = new URI(groovyscript).toURL();
767 } catch (Exception x)
769 tfile = new File(groovyscript);
772 System.err.println("File '" + groovyscript + "' does not exist.");
775 if (!tfile.canRead())
777 System.err.println("File '" + groovyscript + "' cannot be read.");
780 if (tfile.length() < 1)
782 System.err.println("File '" + groovyscript + "' is empty.");
787 sfile = tfile.getAbsoluteFile().toURI().toURL();
788 } catch (Exception ex)
790 System.err.println("Failed to create a file URL for "
791 + tfile.getAbsoluteFile());
796 boolean success = false;
800 * The following code performs the GroovyScriptEngine invocation using
801 * reflection, and is equivalent to this fragment from the embedding
802 * groovy documentation on the groovy site: <code> import
803 * groovy.lang.Binding; import groovy.util.GroovyScriptEngine;
805 * String[] roots = new String[] { "/my/groovy/script/path" };
806 * GroovyScriptEngine gse = new GroovyScriptEngine(roots); Binding binding
807 * = new Binding(); binding.setVariable("input", "world");
808 * gse.run("hello.groovy", binding); </code>
812 int blen = ((jalviewContext[0] == null) ? 0 : 1)
813 + ((jalviewContext[1] == null) ? 0 : 1);
814 String cnames[] = new String[]
815 { "Jalview", "currentAlFrame" };
816 bspec = new Class[blen * 2];
817 binding = new Object[blen * 2];
819 ClassLoader cl = null;
820 Map<String, Object> vbinding = new HashMap<String, Object>();
821 for (int jc = 0; jc < jalviewContext.length; jc++)
823 if (jalviewContext[jc] != null)
827 cl = jalviewContext[jc].getClass().getClassLoader();
829 bspec[blen * 2] = String.class;
830 bspec[blen * 2 + 1] = Object.class;
831 binding[blen * 2] = cnames[jc];
832 binding[blen * 2 + 1] = jalviewContext[jc];
833 vbinding.put(cnames[jc], jalviewContext[jc]);
837 Class<?> gbindingc = cl.loadClass("groovy.lang.Binding");
838 Constructor<?> gbcons;
842 gbcons = gbindingc.getConstructor(Map.class);
843 gbinding = gbcons.newInstance(vbinding);
844 } catch (NoSuchMethodException x)
846 // old style binding config - using series of string/object values to
848 gbcons = gbindingc.getConstructor();
849 gbinding = gbcons.newInstance();
850 java.lang.reflect.Method setvar = gbindingc.getMethod(
851 "setVariable", bspec);
852 setvar.invoke(gbinding, binding);
855 Class<?> gsec = cl.loadClass("groovy.util.GroovyScriptEngine");
856 Constructor<?> gseccons = gsec.getConstructor(new Class[]
857 { URL[].class }); // String[].class });
858 Object gse = gseccons.newInstance(new Object[]
860 { sfile } }); // .toString() } });
861 java.lang.reflect.Method run = gsec.getMethod("run", new Class[]
862 { String.class, gbindingc });
863 run.invoke(gse, new Object[]
864 { sfile.toString(), gbinding });
866 } catch (Exception e)
868 System.err.println("Exception Whilst trying to execute file " + sfile
869 + " as a groovy script.");
870 e.printStackTrace(System.err);
873 if (success && groovyscript.equals("STDIN"))
875 // delete temp file that we made - but only if it was successfully
882 * Check commandline for any das server definitions or any fetchfrom switches
884 * @return vector of DAS source nicknames to retrieve from
886 private static Vector checkDasArguments(ArgsParser aparser)
888 Vector source = null;
890 String locsources = Cache.getProperty(Cache.DAS_LOCAL_SOURCE);
891 while ((data = aparser.getValue("dasserver", true)) != null)
893 String nickname = null;
895 boolean seq = false, feat = true;
896 int pos = data.indexOf('=');
897 // determine capabilities
900 nickname = data.substring(0, pos);
902 url = data.substring(pos + 1);
904 && (url.startsWith("http:") || url
905 .startsWith("sequence:http:")))
907 if (nickname == null)
911 if (locsources == null)
919 locsources = locsources + nickname + "|" + url;
921 .println("NOTE! dasserver parameter not yet really supported (got args of "
922 + nickname + "|" + url);
925 source = new Vector();
927 source.addElement(nickname);
929 } // loop until no more server entries are found.
930 if (locsources != null && locsources.indexOf('|') > -1)
932 Cache.log.debug("Setting local source list in properties file to:\n"
934 Cache.setProperty(Cache.DAS_LOCAL_SOURCE, locsources);
936 while ((data = aparser.getValue("fetchfrom", true)) != null)
938 System.out.println("adding source '" + data + "'");
941 source = new Vector();
943 source.addElement(data);
949 * start a feature fetcher for every alignment frame
953 private static FeatureFetcher startFeatureFetching(final Vector dasSources)
955 FeatureFetcher ff = new FeatureFetcher();
956 AlignFrame afs[] = Desktop.getAlignFrames();
957 if (afs == null || afs.length == 0)
961 for (int i = 0; i < afs.length; i++)
963 ff.addFetcher(afs[i], dasSources);
970 * Notes: this argParser does not distinguish between parameter switches,
971 * parameter values and argument text. If an argument happens to be identical to
972 * a parameter, it will be taken as such (even though it didn't have a '-'
975 * @author Andrew Waterhouse and JBP documented.
979 class rnabuttonlistener implements ActionListener
981 public void actionPerformed(ActionEvent arg0)
983 System.out.println("Good idea ! ");
988 class pbuttonlistener implements ActionListener
990 public void actionPerformed(ActionEvent arg0)
1000 public ArgsParser(String[] args)
1002 vargs = new Vector();
1003 for (int i = 0; i < args.length; i++)
1005 String arg = args[i].trim();
1006 if (arg.charAt(0) == '-')
1008 arg = arg.substring(1);
1010 vargs.addElement(arg);
1015 * check for and remove first occurence of arg+parameter in arglist.
1018 * @return return the argument following the given arg if arg was in list.
1020 public String getValue(String arg)
1022 return getValue(arg, false);
1025 public String getValue(String arg, boolean utf8decode)
1027 int index = vargs.indexOf(arg);
1028 String dc = null, ret = null;
1031 ret = vargs.elementAt(index + 1).toString();
1032 vargs.removeElementAt(index);
1033 vargs.removeElementAt(index);
1034 if (utf8decode && ret != null)
1038 dc = URLDecoder.decode(ret, "UTF-8");
1040 } catch (Exception e)
1042 // TODO: log failure to decode
1050 * check for and remove first occurence of arg in arglist.
1053 * @return true if arg was present in argslist.
1055 public boolean contains(String arg)
1057 if (vargs.contains(arg))
1059 vargs.removeElement(arg);
1068 public String nextValue()
1070 return vargs.remove(0).toString();
1073 public int getSize()
1075 return vargs.size();
1081 * keep track of feature fetching tasks.
1086 class FeatureFetcher
1089 * TODO: generalise to track all jalview events to orchestrate batch
1090 * processing events.
1093 private int queued = 0;
1095 private int running = 0;
1097 public FeatureFetcher()
1102 public void addFetcher(final AlignFrame af, final Vector dasSources)
1104 final long id = System.currentTimeMillis();
1106 final FeatureFetcher us = this;
1107 new Thread(new Runnable()
1118 af.setProgressBar(MessageManager.getString("status.das_features_being_retrived"), id);
1119 af.featureSettings_actionPerformed(null);
1120 af.featureSettings.fetchDasFeatures(dasSources, true);
1121 af.setProgressBar(null, id);
1130 public synchronized boolean allFinished()
1132 return queued == 0 && running == 0;