2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.HtmlSvgOutput;
26 import jalview.util.MessageManager;
27 import jalview.util.Platform;
28 import jalview.ws.jws2.Jws2Discoverer;
30 import java.awt.event.ActionEvent;
31 import java.awt.event.ActionListener;
32 import java.io.BufferedReader;
34 import java.io.FileOutputStream;
35 import java.io.IOException;
36 import java.io.OutputStreamWriter;
37 import java.io.PrintWriter;
38 import java.lang.reflect.Constructor;
39 import java.net.MalformedURLException;
42 import java.net.URLDecoder;
43 import java.security.AllPermission;
44 import java.security.CodeSource;
45 import java.security.PermissionCollection;
46 import java.security.Permissions;
47 import java.security.Policy;
48 import java.util.Hashtable;
50 import java.util.Vector;
52 import javax.swing.UIManager;
53 import javax.swing.UnsupportedLookAndFeelException;
56 * Main class for Jalview Application <br>
58 * start with java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview
67 // grab all the rights we can the JVM
68 Policy.setPolicy(new Policy()
70 public PermissionCollection getPermissions(CodeSource codesource)
72 Permissions perms = new Permissions();
73 perms.add(new AllPermission());
84 * main class for Jalview application
87 * open <em>filename</em>
89 public static void main(String[] args)
91 System.out.println("Java version: "
92 + System.getProperty("java.version"));
93 System.out.println(System.getProperty("os.arch") + " "
94 + System.getProperty("os.name") + " "
95 + System.getProperty("os.version"));
96 // if (new Platform().isAMac())
98 // // System.setProperty("com.apple.mrj.application.apple.menu.about.name",
100 // // System.setProperty("apple.laf.useScreenMenuBar", "true");
103 // UIManager.setLookAndFeel(ch.randelshofer.quaqua.QuaquaManager
104 // .getLookAndFeel());
106 // .println("--------------------------------------------> in here");
107 // } catch (UnsupportedLookAndFeelException e)
109 // // TODO Auto-generated catch block
110 // e.printStackTrace();
114 ArgsParser aparser = new ArgsParser(args);
115 boolean headless = false;
117 if (aparser.contains("help") || aparser.contains("h"))
122 if (aparser.contains("nodisplay") || aparser.contains("nogui")
123 || aparser.contains("headless"))
125 System.setProperty("java.awt.headless", "true");
128 Cache.loadProperties(aparser.getValue("props")); // must do this before
131 final String jabawsUrl = aparser.getValue("jabaws");
132 if (jabawsUrl != null)
136 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
137 } catch (MalformedURLException e)
139 System.err.println("Invalid jabaws parameter: " + jabawsUrl
144 String defs = aparser.getValue("setprop");
147 int p = defs.indexOf('=');
150 System.err.println("Ignoring invalid setprop argument : " + defs);
154 System.out.println("Executing setprop argument: " + defs);
155 // DISABLED FOR SECURITY REASONS
156 // TODO: add a property to allow properties to be overriden by cli args
157 // Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
159 defs = aparser.getValue("setprop");
161 if (System.getProperty("java.awt.headless") != null
162 && System.getProperty("java.awt.headless").equals("true"))
166 System.setProperty("http.agent",
167 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
171 } catch (java.lang.NoClassDefFoundError error)
173 error.printStackTrace();
175 .println("\nEssential logging libraries not found."
176 + "\nUse: java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview");
180 Desktop desktop = null;
184 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
185 } catch (Exception ex)
188 if (new Platform().isAMac())
190 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
192 System.setProperty("apple.laf.useScreenMenuBar", "true");
195 UIManager.setLookAndFeel(ch.randelshofer.quaqua.QuaquaManager
197 } catch (UnsupportedLookAndFeelException e)
199 // TODO Auto-generated catch block
206 desktop = new Desktop();
207 desktop.setInBatchMode(true); // indicate we are starting up
208 desktop.setVisible(true);
209 desktop.startServiceDiscovery();
210 if (!aparser.contains("nousagestats"))
212 startUsageStats(desktop);
214 if (!aparser.contains("noquestionnaire"))
216 String url = aparser.getValue("questionnaire");
219 // Start the desktop questionnaire prompter with the specified
221 Cache.log.debug("Starting questionnaire url at " + url);
222 desktop.checkForQuestionnaire(url);
226 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
228 // Start the desktop questionnaire prompter with the specified
231 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
233 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
234 Cache.log.debug("Starting questionnaire with default url: "
236 desktop.checkForQuestionnaire(defurl);
241 desktop.checkForNews();
244 String file = null, protocol = null, format = null, data = null;
245 jalview.io.FileLoader fileLoader = new jalview.io.FileLoader();
246 Vector getFeatures = null; // vector of das source nicknames to fetch
249 String groovyscript = null; // script to execute after all loading is
250 // completed one way or another
251 // extract groovy argument and execute if necessary
252 groovyscript = aparser.getValue("groovy", true);
253 file = aparser.getValue("open", true);
255 if (file == null && desktop == null)
257 System.out.println("No files to open!");
260 String vamsasImport = aparser.getValue("vdoc"), vamsasSession = aparser
262 if (vamsasImport != null || vamsasSession != null)
264 if (desktop == null || headless)
267 .println("Headless vamsas sessions not yet supported. Sorry.");
270 // if we have a file, start a new session and import it.
271 boolean inSession = false;
272 if (vamsasImport != null)
276 String viprotocol = jalview.io.AppletFormatAdapter
277 .checkProtocol(vamsasImport);
278 if (viprotocol == jalview.io.FormatAdapter.FILE)
280 inSession = desktop.vamsasImport(new File(vamsasImport));
282 else if (viprotocol == jalview.io.FormatAdapter.URL)
284 inSession = desktop.vamsasImport(new URL(vamsasImport));
287 } catch (Exception e)
289 System.err.println("Exeption when importing " + vamsasImport
290 + " as a vamsas document.");
295 System.err.println("Failed to import " + vamsasImport
296 + " as a vamsas document.");
300 System.out.println("Imported Successfully into new session "
301 + desktop.getVamsasApplication().getCurrentSession());
304 if (vamsasSession != null)
306 if (vamsasImport != null)
308 // close the newly imported session and import the Jalview specific
309 // remnants into the new session later on.
310 desktop.vamsasStop_actionPerformed(null);
312 // now join the new session
315 if (desktop.joinVamsasSession(vamsasSession))
317 System.out.println("Successfully joined vamsas session "
322 System.err.println("WARNING: Failed to join vamsas session "
325 } catch (Exception e)
327 System.err.println("ERROR: Failed to join vamsas session "
331 if (vamsasImport != null)
333 // the Jalview specific remnants can now be imported into the new
334 // session at the user's leisure.
336 .info("Skipping Push for import of data into existing vamsas session."); // TODO:
341 // desktop.getVamsasApplication().push_update();
346 // Finally, deal with the remaining input data.
351 desktop.setProgressBar(MessageManager.getString("status.processing_commandline_args"),
352 progress = System.currentTimeMillis());
354 System.out.println("Opening file: " + file);
356 if (!file.startsWith("http://"))
358 if (!(new java.io.File(file)).exists())
360 System.out.println("Can't find " + file);
368 protocol = jalview.io.AppletFormatAdapter.checkProtocol(file);
370 format = new jalview.io.IdentifyFile().Identify(file, protocol);
372 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
376 System.out.println("error");
381 data = aparser.getValue("colour", true);
384 data.replaceAll("%20", " ");
386 jalview.schemes.ColourSchemeI cs = jalview.schemes.ColourSchemeProperty
387 .getColour(af.getViewport().getAlignment(), data);
391 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(
393 ucs.parseAppletParameter(data);
397 System.out.println("colour is " + data);
401 // Must maintain ability to use the groups flag
402 data = aparser.getValue("groups", true);
405 af.parseFeaturesFile(data,
406 jalview.io.AppletFormatAdapter.checkProtocol(data));
407 System.out.println("Added " + data);
409 data = aparser.getValue("features", true);
412 af.parseFeaturesFile(data,
413 jalview.io.AppletFormatAdapter.checkProtocol(data));
414 System.out.println("Added " + data);
417 data = aparser.getValue("annotations", true);
420 af.loadJalviewDataFile(data, null, null, null);
421 System.out.println("Added " + data);
423 // set or clear the sortbytree flag.
424 if (aparser.contains("sortbytree"))
426 af.getViewport().setSortByTree(true);
428 if (aparser.contains("no-annotation"))
430 af.getViewport().setShowAnnotation(false);
432 if (aparser.contains("nosortbytree"))
434 af.getViewport().setSortByTree(false);
436 data = aparser.getValue("tree", true);
439 jalview.io.NewickFile fin = null;
442 fin = new jalview.io.NewickFile(data,
443 jalview.io.AppletFormatAdapter.checkProtocol(data));
446 af.getViewport().setCurrentTree(
447 af.ShowNewickTree(fin, data).getTree());
448 System.out.println("Added tree " + data);
450 } catch (IOException ex)
452 System.err.println("Couldn't add tree " + data);
453 ex.printStackTrace(System.err);
456 // TODO - load PDB structure(s) to alignment JAL-629
457 // (associate with identical sequence in alignment, or a specified
460 getFeatures = checkDasArguments(aparser);
461 if (af != null && getFeatures != null)
463 FeatureFetcher ff = startFeatureFetching(getFeatures);
466 while (!ff.allFinished() || af.operationInProgress())
468 // wait around until fetching is finished.
472 } catch (Exception e)
478 getFeatures = null; // have retrieved features - forget them now.
480 if (groovyscript != null)
482 // Execute the groovy script after we've done all the rendering stuff
483 // and before any images or figures are generated.
484 if (jalview.bin.Cache.groovyJarsPresent())
486 System.out.println("Executing script " + groovyscript);
487 executeGroovyScript(groovyscript, new Object[]
493 .println("Sorry. Groovy Support is not available, so ignoring the provided groovy script "
498 String imageName = "unnamed.png";
499 while (aparser.getSize() > 1)
501 format = aparser.nextValue();
502 file = aparser.nextValue();
504 if (format.equalsIgnoreCase("png"))
506 af.createPNG(new java.io.File(file));
507 imageName = (new java.io.File(file)).getName();
508 System.out.println("Creating PNG image: " + file);
511 else if (format.equalsIgnoreCase("svg"))
513 File imageFile = new java.io.File(file);
514 imageName = imageFile.getName();
515 af.createSVG(imageFile);
516 System.out.println("Creating SVG image: " + file);
519 else if (format.equalsIgnoreCase("html"))
521 File imageFile = new java.io.File(file);
522 imageName = imageFile.getName();
523 new HtmlSvgOutput(new java.io.File(file), af.alignPanel);
524 System.out.println("Creating HTML image: " + file);
527 else if (format.equalsIgnoreCase("imgMap"))
529 af.createImageMap(new java.io.File(file), imageName);
530 System.out.println("Creating image map: " + file);
533 else if (format.equalsIgnoreCase("eps"))
535 System.out.println("Creating EPS file: " + file);
536 af.createEPS(new java.io.File(file));
540 if (af.saveAlignment(file, format))
542 System.out.println("Written alignment in " + format
543 + " format to " + file);
547 System.out.println("Error writing file " + file + " in "
548 + format + " format!!");
553 while (aparser.getSize() > 0)
555 System.out.println("Unknown arg: " + aparser.nextValue());
559 AlignFrame startUpAlframe = null;
560 // We'll only open the default file if the desktop is visible.
562 // ////////////////////
564 if (!headless && file == null && vamsasImport == null
565 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
567 file = jalview.bin.Cache.getDefault(
569 jalview.bin.Cache.getDefault("www.jalview.org",
570 "http://www.jalview.org")
571 + "/examples/exampleFile_2_7.jar");
572 if (file.equals("http://www.jalview.org/examples/exampleFile_2_3.jar"))
574 // hardwire upgrade of the startup file
575 file.replace("_2_3.jar", "_2_7.jar");
576 // and remove the stale setting
577 jalview.bin.Cache.removeProperty("STARTUP_FILE");
582 if (file.indexOf("http:") > -1)
587 if (file.endsWith(".jar"))
593 format = new jalview.io.IdentifyFile().Identify(file, protocol);
596 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
598 getFeatures = checkDasArguments(aparser);
599 // extract groovy arguments before anything else.
601 // If the user has specified features to be retrieved,
602 // or a groovy script to be executed, do them if they
603 // haven't been done already
604 // fetch features for the default alignment
605 if (getFeatures != null)
607 if (startUpAlframe != null)
609 startFeatureFetching(getFeatures);
612 // Once all other stuff is done, execute any groovy scripts (in order)
613 if (groovyscript != null)
615 if (jalview.bin.Cache.groovyJarsPresent())
617 System.out.println("Executing script " + groovyscript);
618 executeGroovyScript(groovyscript, new Object[]
619 { desktop, startUpAlframe });
624 .println("Sorry. Groovy Support is not available, so ignoring the provided groovy script "
628 // and finally, turn off batch mode indicator - if the desktop still exists
633 desktop.setProgressBar(null, progress);
635 desktop.setInBatchMode(false);
639 private static void showUsage()
642 .println("Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
643 + "-nodisplay\tRun Jalview without User Interface.\n"
644 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
645 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
646 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
647 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
648 + "-features FILE\tUse the given file to mark features on the alignment.\n"
649 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
650 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
651 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
652 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
653 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
654 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
655 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
656 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
657 + "-png FILE\tCreate PNG image FILE from alignment.\n"
658 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
659 + "-html FILE\tCreate HTML file from alignment.\n"
660 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
661 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
662 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
663 + "-noquestionnaire\tTurn off questionnaire check.\n"
664 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
665 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
667 // "-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)"
668 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
669 + "-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"
670 + "\t\t\tSources that also support the sequence command may be specified by prepending the URL with sequence:\n"
671 + "\t\t\t e.g. sequence:http://localdas.somewhere.org/das/source)\n"
672 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
674 // "-vdoc vamsas-document\tImport vamsas document into new session or join existing session with same URN\n"
675 // + "-vses vamsas-session\tJoin session with given URN\n"
676 + "-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"
677 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
680 private static void startUsageStats(final Desktop desktop)
683 * start a User Config prompt asking if we can log usage statistics.
685 jalview.gui.PromptUserConfig prompter = new jalview.gui.PromptUserConfig(
688 "Jalview Usage Statistics",
689 "Do you want to help make Jalview better by enabling "
690 + "the collection of usage statistics with Google Analytics ?"
691 + "\n\n(you can enable or disable usage tracking in the preferences)",
697 .debug("Initialising googletracker for usage stats.");
698 Cache.initGoogleTracker();
699 Cache.log.debug("Tracking enabled.");
705 Cache.log.debug("Not enabling Google Tracking.");
708 desktop.addDialogThread(prompter);
712 * Locate the given string as a file and pass it to the groovy interpreter.
714 * @param groovyscript
715 * the script to execute
716 * @param jalviewContext
717 * the Jalview Desktop object passed in to the groovy binding as the
720 private static void executeGroovyScript(String groovyscript,
721 Object[] jalviewContext)
723 if (jalviewContext == null)
726 .println("Sorry. Groovy support is currently only available when running with the Jalview GUI enabled.");
729 * for scripts contained in files
736 if (groovyscript.trim().equals("STDIN"))
738 // read from stdin into a tempfile and execute it
741 tfile = File.createTempFile("jalview", "groovy");
742 PrintWriter outfile = new PrintWriter(new OutputStreamWriter(
743 new FileOutputStream(tfile)));
744 BufferedReader br = new BufferedReader(
745 new java.io.InputStreamReader(System.in));
747 while ((line = br.readLine()) != null)
749 outfile.write(line + "\n");
755 } catch (Exception ex)
757 System.err.println("Failed to read from STDIN into tempfile "
758 + ((tfile == null) ? "(tempfile wasn't created)" : tfile
760 ex.printStackTrace();
765 sfile = tfile.toURI().toURL();
766 } catch (Exception x)
769 .println("Unexpected Malformed URL Exception for temporary file created from STDIN: "
779 sfile = new URI(groovyscript).toURL();
780 } catch (Exception x)
782 tfile = new File(groovyscript);
785 System.err.println("File '" + groovyscript + "' does not exist.");
788 if (!tfile.canRead())
790 System.err.println("File '" + groovyscript + "' cannot be read.");
793 if (tfile.length() < 1)
795 System.err.println("File '" + groovyscript + "' is empty.");
800 sfile = tfile.getAbsoluteFile().toURI().toURL();
801 } catch (Exception ex)
803 System.err.println("Failed to create a file URL for "
804 + tfile.getAbsoluteFile());
809 boolean success = false;
813 * The following code performs the GroovyScriptEngine invocation using
814 * reflection, and is equivalent to this fragment from the embedding
815 * groovy documentation on the groovy site: <code> import
816 * groovy.lang.Binding; import groovy.util.GroovyScriptEngine;
818 * String[] roots = new String[] { "/my/groovy/script/path" };
819 * GroovyScriptEngine gse = new GroovyScriptEngine(roots); Binding binding
820 * = new Binding(); binding.setVariable("input", "world");
821 * gse.run("hello.groovy", binding); </code>
825 int blen = ((jalviewContext[0] == null) ? 0 : 1)
826 + ((jalviewContext[1] == null) ? 0 : 1);
827 String cnames[] = new String[]
828 { "Jalview", "currentAlFrame" };
829 bspec = new Class[blen * 2];
830 binding = new Object[blen * 2];
832 ClassLoader cl = null;
833 Map vbinding = new Hashtable();
834 for (int jc = 0; jc < jalviewContext.length; jc++)
836 if (jalviewContext[jc] != null)
840 cl = jalviewContext[jc].getClass().getClassLoader();
842 bspec[blen * 2] = String.class;
843 bspec[blen * 2 + 1] = Object.class;
844 binding[blen * 2] = cnames[jc];
845 binding[blen * 2 + 1] = jalviewContext[jc];
846 vbinding.put(cnames[jc], jalviewContext[jc]);
850 Class gbindingc = cl.loadClass("groovy.lang.Binding");
855 gbcons = gbindingc.getConstructor(Map.class);
856 gbinding = gbcons.newInstance(vbinding);
857 } catch (NoSuchMethodException x)
859 // old style binding config - using series of string/object values to
861 gbcons = gbindingc.getConstructor(null);
862 gbinding = gbcons.newInstance(null);
863 java.lang.reflect.Method setvar = gbindingc.getMethod(
864 "setVariable", bspec);
865 setvar.invoke(gbinding, binding);
868 Class gsec = cl.loadClass("groovy.util.GroovyScriptEngine");
869 Constructor gseccons = gsec.getConstructor(new Class[]
870 { URL[].class }); // String[].class });
871 Object gse = gseccons.newInstance(new Object[]
873 { sfile } }); // .toString() } });
874 java.lang.reflect.Method run = gsec.getMethod("run", new Class[]
875 { String.class, gbindingc });
876 run.invoke(gse, new Object[]
877 { sfile.toString(), gbinding });
879 } catch (Exception e)
881 System.err.println("Exception Whilst trying to execute file " + sfile
882 + " as a groovy script.");
883 e.printStackTrace(System.err);
886 if (success && groovyscript.equals("STDIN"))
888 // delete temp file that we made - but only if it was successfully
895 * Check commandline for any das server definitions or any fetchfrom switches
897 * @return vector of DAS source nicknames to retrieve from
899 private static Vector checkDasArguments(ArgsParser aparser)
901 Vector source = null;
903 String locsources = Cache.getProperty(Cache.DAS_LOCAL_SOURCE);
904 while ((data = aparser.getValue("dasserver", true)) != null)
906 String nickname = null;
908 boolean seq = false, feat = true;
909 int pos = data.indexOf('=');
910 // determine capabilities
913 nickname = data.substring(0, pos);
915 url = data.substring(pos + 1);
917 && (url.startsWith("http:") || url
918 .startsWith("sequence:http:")))
920 if (nickname == null)
924 if (locsources == null)
932 locsources = locsources + nickname + "|" + url;
934 .println("NOTE! dasserver parameter not yet really supported (got args of "
935 + nickname + "|" + url);
938 source = new Vector();
940 source.addElement(nickname);
942 } // loop until no more server entries are found.
943 if (locsources != null && locsources.indexOf('|') > -1)
945 Cache.log.debug("Setting local source list in properties file to:\n"
947 Cache.setProperty(Cache.DAS_LOCAL_SOURCE, locsources);
949 while ((data = aparser.getValue("fetchfrom", true)) != null)
951 System.out.println("adding source '" + data + "'");
954 source = new Vector();
956 source.addElement(data);
962 * start a feature fetcher for every alignment frame
966 private static FeatureFetcher startFeatureFetching(final Vector dasSources)
968 FeatureFetcher ff = new FeatureFetcher();
969 AlignFrame afs[] = Desktop.getAlignframes();
970 if (afs == null || afs.length == 0)
974 for (int i = 0; i < afs.length; i++)
976 ff.addFetcher(afs[i], dasSources);
983 * Notes: this argParser does not distinguish between parameter switches,
984 * parameter values and argument text. If an argument happens to be identical to
985 * a parameter, it will be taken as such (even though it didn't have a '-'
988 * @author Andrew Waterhouse and JBP documented.
992 class rnabuttonlistener implements ActionListener
994 public void actionPerformed(ActionEvent arg0)
996 System.out.println("Good idea ! ");
1001 class pbuttonlistener implements ActionListener
1003 public void actionPerformed(ActionEvent arg0)
1011 Vector vargs = null;
1013 public ArgsParser(String[] args)
1015 vargs = new Vector();
1016 for (int i = 0; i < args.length; i++)
1018 String arg = args[i].trim();
1019 if (arg.charAt(0) == '-')
1021 arg = arg.substring(1);
1023 vargs.addElement(arg);
1028 * check for and remove first occurence of arg+parameter in arglist.
1031 * @return return the argument following the given arg if arg was in list.
1033 public String getValue(String arg)
1035 return getValue(arg, false);
1038 public String getValue(String arg, boolean utf8decode)
1040 int index = vargs.indexOf(arg);
1041 String dc = null, ret = null;
1044 ret = vargs.elementAt(index + 1).toString();
1045 vargs.removeElementAt(index);
1046 vargs.removeElementAt(index);
1047 if (utf8decode && ret != null)
1051 dc = URLDecoder.decode(ret, "UTF-8");
1053 } catch (Exception e)
1055 // TODO: log failure to decode
1063 * check for and remove first occurence of arg in arglist.
1066 * @return true if arg was present in argslist.
1068 public boolean contains(String arg)
1070 if (vargs.contains(arg))
1072 vargs.removeElement(arg);
1081 public String nextValue()
1083 return vargs.remove(0).toString();
1086 public int getSize()
1088 return vargs.size();
1094 * keep track of feature fetching tasks.
1099 class FeatureFetcher
1102 * TODO: generalise to track all jalview events to orchestrate batch
1103 * processing events.
1106 private int queued = 0;
1108 private int running = 0;
1110 public FeatureFetcher()
1115 public void addFetcher(final AlignFrame af, final Vector dasSources)
1117 final long id = System.currentTimeMillis();
1119 final FeatureFetcher us = this;
1120 new Thread(new Runnable()
1131 af.setProgressBar(MessageManager.getString("status.das_features_being_retrived"), id);
1132 af.featureSettings_actionPerformed(null);
1133 af.featureSettings.fetchDasFeatures(dasSources, true);
1134 af.setProgressBar(null, id);
1143 public synchronized boolean allFinished()
1145 return queued == 0 && running == 0;