2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b2)
3 * Copyright (C) 2015 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;
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()
71 public PermissionCollection getPermissions(CodeSource codesource)
73 Permissions perms = new Permissions();
74 perms.add(new AllPermission());
86 * main class for Jalview application
89 * open <em>filename</em>
91 public static void main(String[] args)
93 System.out.println("Java version: "
94 + System.getProperty("java.version"));
95 System.out.println(System.getProperty("os.arch") + " "
96 + System.getProperty("os.name") + " "
97 + System.getProperty("os.version"));
99 ArgsParser aparser = new ArgsParser(args);
100 boolean headless = false;
102 if (aparser.contains("help") || aparser.contains("h"))
107 if (aparser.contains("nodisplay") || aparser.contains("nogui")
108 || aparser.contains("headless"))
110 System.setProperty("java.awt.headless", "true");
113 String usrPropsFile = aparser.getValue("props");
114 Cache.loadProperties(usrPropsFile); // must do this before
115 if (usrPropsFile != null)
117 System.out.println("CMD [-props " + usrPropsFile
118 + "] executed successfully!");
123 final String jabawsUrl = aparser.getValue("jabaws");
124 if (jabawsUrl != null)
128 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
129 System.out.println("CMD [-jabaws " + jabawsUrl
130 + "] executed successfully!");
131 } catch (MalformedURLException e)
133 System.err.println("Invalid jabaws parameter: " + jabawsUrl
138 String defs = aparser.getValue("setprop");
141 int p = defs.indexOf('=');
144 System.err.println("Ignoring invalid setprop argument : " + defs);
148 System.out.println("Executing setprop argument: " + defs);
149 // DISABLED FOR SECURITY REASONS
150 // TODO: add a property to allow properties to be overriden by cli args
151 // Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
153 defs = aparser.getValue("setprop");
155 if (System.getProperty("java.awt.headless") != null
156 && System.getProperty("java.awt.headless").equals("true"))
160 System.setProperty("http.agent",
161 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
165 } catch (java.lang.NoClassDefFoundError error)
167 error.printStackTrace();
169 .println("\nEssential logging libraries not found."
170 + "\nUse: java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview");
174 Desktop desktop = null;
178 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
179 } catch (Exception ex)
182 if (Platform.isAMac())
184 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
186 System.setProperty("apple.laf.useScreenMenuBar", "true");
189 UIManager.setLookAndFeel(ch.randelshofer.quaqua.QuaquaManager
191 } catch (Throwable e)
193 System.err.println("Failed to set QuaQua look and feel: "
200 desktop = new Desktop();
201 desktop.setInBatchMode(true); // indicate we are starting up
202 desktop.setVisible(true);
203 desktop.startServiceDiscovery();
204 if (!aparser.contains("nousagestats"))
206 startUsageStats(desktop);
210 System.err.println("CMD [-nousagestats] executed successfully!");
213 if (!aparser.contains("noquestionnaire"))
215 String url = aparser.getValue("questionnaire");
218 // Start the desktop questionnaire prompter with the specified
220 Cache.log.debug("Starting questionnaire url at " + url);
221 desktop.checkForQuestionnaire(url);
222 System.out.println("CMD questionnaire[-" + url
223 + "] executed successfully!");
227 if (Cache.getProperty("NOQUESTIONNAIRES") == null)
229 // Start the desktop questionnaire prompter with the specified
232 // "http://anaplog.compbio.dundee.ac.uk/cgi-bin/questionnaire.pl";
234 String defurl = "http://www.jalview.org/cgi-bin/questionnaire.pl";
235 Cache.log.debug("Starting questionnaire with default url: "
237 desktop.checkForQuestionnaire(defurl);
244 System.err.println("CMD [-noquestionnaire] executed successfully!");
246 desktop.checkForNews();
249 if (!isHeadlessMode())
251 BioJsHTMLOutput.updateBioJS();
254 String file = null, protocol = null, format = null, data = null;
255 jalview.io.FileLoader fileLoader = new jalview.io.FileLoader(!headless);
256 Vector getFeatures = null; // vector of das source nicknames to fetch
259 String groovyscript = null; // script to execute after all loading is
260 // completed one way or another
261 // extract groovy argument and execute if necessary
262 groovyscript = aparser.getValue("groovy", true);
263 file = aparser.getValue("open", true);
265 if (file == null && desktop == null)
267 System.out.println("No files to open!");
270 String vamsasImport = aparser.getValue("vdoc"), vamsasSession = aparser
272 if (vamsasImport != null || vamsasSession != null)
274 if (desktop == null || headless)
277 .println("Headless vamsas sessions not yet supported. Sorry.");
280 // if we have a file, start a new session and import it.
281 boolean inSession = false;
282 if (vamsasImport != null)
286 String viprotocol = jalview.io.AppletFormatAdapter
287 .checkProtocol(vamsasImport);
288 if (viprotocol == jalview.io.FormatAdapter.FILE)
290 inSession = desktop.vamsasImport(new File(vamsasImport));
292 else if (viprotocol == jalview.io.FormatAdapter.URL)
294 inSession = desktop.vamsasImport(new URL(vamsasImport));
297 } catch (Exception e)
299 System.err.println("Exeption when importing " + vamsasImport
300 + " as a vamsas document.");
305 System.err.println("Failed to import " + vamsasImport
306 + " as a vamsas document.");
310 System.out.println("Imported Successfully into new session "
311 + desktop.getVamsasApplication().getCurrentSession());
314 if (vamsasSession != null)
316 if (vamsasImport != null)
318 // close the newly imported session and import the Jalview specific
319 // remnants into the new session later on.
320 desktop.vamsasStop_actionPerformed(null);
322 // now join the new session
325 if (desktop.joinVamsasSession(vamsasSession))
327 System.out.println("Successfully joined vamsas session "
332 System.err.println("WARNING: Failed to join vamsas session "
335 } catch (Exception e)
337 System.err.println("ERROR: Failed to join vamsas session "
341 if (vamsasImport != null)
343 // the Jalview specific remnants can now be imported into the new
344 // session at the user's leisure.
346 .info("Skipping Push for import of data into existing vamsas session."); // TODO:
351 // desktop.getVamsasApplication().push_update();
356 // Finally, deal with the remaining input data.
361 desktop.setProgressBar(MessageManager
362 .getString("status.processing_commandline_args"),
363 progress = System.currentTimeMillis());
365 System.out.println("CMD [-open " + file + "] executed successfully!");
367 if (!file.startsWith("http://"))
369 if (!(new java.io.File(file)).exists())
371 System.out.println("Can't find " + file);
379 protocol = jalview.io.AppletFormatAdapter.checkProtocol(file);
381 format = new jalview.io.IdentifyFile().Identify(file, protocol);
383 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
387 System.out.println("error");
391 Desktop.setCurrentAlignFrame(af);
392 data = aparser.getValue("colour", true);
395 data.replaceAll("%20", " ");
397 jalview.schemes.ColourSchemeI cs = jalview.schemes.ColourSchemeProperty
398 .getColour(af.getViewport().getAlignment(), data);
402 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(
404 ucs.parseAppletParameter(data);
409 System.out.println("CMD [-color " + data
410 + "] executed successfully!");
415 // Must maintain ability to use the groups flag
416 data = aparser.getValue("groups", true);
419 af.parseFeaturesFile(data,
420 jalview.io.AppletFormatAdapter.checkProtocol(data));
421 // System.out.println("Added " + data);
422 System.out.println("CMD groups[-" + data
423 + "] executed successfully!");
425 data = aparser.getValue("features", true);
428 af.parseFeaturesFile(data,
429 jalview.io.AppletFormatAdapter.checkProtocol(data));
430 // System.out.println("Added " + data);
431 System.out.println("CMD [-features " + data
432 + "] executed successfully!");
435 data = aparser.getValue("annotations", true);
438 af.loadJalviewDataFile(data, null, null, null);
439 // System.out.println("Added " + data);
440 System.out.println("CMD [-annotations " + data
441 + "] executed successfully!");
443 // set or clear the sortbytree flag.
444 if (aparser.contains("sortbytree"))
446 af.getViewport().setSortByTree(true);
447 if (af.getViewport().getSortByTree())
449 System.out.println("CMD [-sortbytree] executed successfully!");
452 if (aparser.contains("no-annotation"))
454 af.getViewport().setShowAnnotation(false);
455 if (!af.getViewport().isShowAnnotation())
457 System.out.println("CMD no-annotation executed successfully!");
460 if (aparser.contains("nosortbytree"))
462 af.getViewport().setSortByTree(false);
463 if (!af.getViewport().getSortByTree())
466 .println("CMD [-nosortbytree] executed successfully!");
469 data = aparser.getValue("tree", true);
472 jalview.io.NewickFile fin = null;
475 System.out.println("CMD [-tree " + data
476 + "] executed successfully!");
477 fin = new jalview.io.NewickFile(data,
478 jalview.io.AppletFormatAdapter.checkProtocol(data));
481 af.getViewport().setCurrentTree(
482 af.ShowNewickTree(fin, data).getTree());
484 } catch (IOException ex)
486 System.err.println("Couldn't add tree " + data);
487 ex.printStackTrace(System.err);
490 // TODO - load PDB structure(s) to alignment JAL-629
491 // (associate with identical sequence in alignment, or a specified
494 getFeatures = checkDasArguments(aparser);
495 if (af != null && getFeatures != null)
497 FeatureFetcher ff = startFeatureFetching(getFeatures);
500 while (!ff.allFinished() || af.operationInProgress())
502 // wait around until fetching is finished.
506 } catch (Exception e)
512 getFeatures = null; // have retrieved features - forget them now.
514 if (groovyscript != null)
516 // Execute the groovy script after we've done all the rendering stuff
517 // and before any images or figures are generated.
518 if (jalview.bin.Cache.groovyJarsPresent())
520 System.out.println("Executing script " + groovyscript);
521 executeGroovyScript(groovyscript, new Object[] { desktop, af });
523 System.out.println("CMD groovy[" + groovyscript
524 + "] executed successfully!");
529 .println("Sorry. Groovy Support is not available, so ignoring the provided groovy script "
534 String imageName = "unnamed.png";
535 while (aparser.getSize() > 1)
537 format = aparser.nextValue();
538 file = aparser.nextValue();
540 if (format.equalsIgnoreCase("png"))
542 af.createPNG(new java.io.File(file));
543 imageName = (new java.io.File(file)).getName();
544 System.out.println("Creating PNG image: " + file);
547 else if (format.equalsIgnoreCase("svg"))
549 File imageFile = new java.io.File(file);
550 imageName = imageFile.getName();
551 af.createSVG(imageFile);
552 System.out.println("Creating SVG image: " + file);
555 else if (format.equalsIgnoreCase("html"))
557 File imageFile = new java.io.File(file);
558 imageName = imageFile.getName();
559 new HtmlSvgOutput(new java.io.File(file), af.alignPanel);
560 System.out.println("Creating HTML image: " + file);
563 else if (format.equalsIgnoreCase("imgMap"))
565 af.createImageMap(new java.io.File(file), imageName);
566 System.out.println("Creating image map: " + file);
569 else if (format.equalsIgnoreCase("eps"))
571 File outputFile = new java.io.File(file);
572 System.out.println("Creating EPS file: "
573 + outputFile.getAbsolutePath());
574 af.createEPS(outputFile);
578 if (af.saveAlignment(file, format))
580 System.out.println("Written alignment in " + format
581 + " format to " + file);
585 System.out.println("Error writing file " + file + " in "
586 + format + " format!!");
591 while (aparser.getSize() > 0)
593 System.out.println("Unknown arg: " + aparser.nextValue());
597 AlignFrame startUpAlframe = null;
598 // We'll only open the default file if the desktop is visible.
600 // ////////////////////
602 if (!headless && file == null && vamsasImport == null
603 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
605 file = jalview.bin.Cache.getDefault(
607 jalview.bin.Cache.getDefault("www.jalview.org",
608 "http://www.jalview.org")
609 + "/examples/exampleFile_2_7.jar");
610 if (file.equals("http://www.jalview.org/examples/exampleFile_2_3.jar"))
612 // hardwire upgrade of the startup file
613 file.replace("_2_3.jar", "_2_7.jar");
614 // and remove the stale setting
615 jalview.bin.Cache.removeProperty("STARTUP_FILE");
620 if (file.indexOf("http:") > -1)
625 if (file.endsWith(".jar"))
631 format = new jalview.io.IdentifyFile().Identify(file, protocol);
634 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
636 getFeatures = checkDasArguments(aparser);
637 // extract groovy arguments before anything else.
639 // If the user has specified features to be retrieved,
640 // or a groovy script to be executed, do them if they
641 // haven't been done already
642 // fetch features for the default alignment
643 if (getFeatures != null)
645 if (startUpAlframe != null)
647 startFeatureFetching(getFeatures);
650 // Once all other stuff is done, execute any groovy scripts (in order)
651 if (groovyscript != null)
653 if (jalview.bin.Cache.groovyJarsPresent())
655 System.out.println("Executing script " + groovyscript);
656 executeGroovyScript(groovyscript, new Object[] { desktop,
662 .println("Sorry. Groovy Support is not available, so ignoring the provided groovy script "
666 // and finally, turn off batch mode indicator - if the desktop still exists
671 desktop.setProgressBar(null, progress);
673 desktop.setInBatchMode(false);
677 private static void showUsage()
680 .println("Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
681 + "-nodisplay\tRun Jalview without User Interface.\n"
682 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
683 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
684 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
685 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
686 + "-features FILE\tUse the given file to mark features on the alignment.\n"
687 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
688 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
689 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
690 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
691 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
692 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
693 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
694 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
695 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
696 + "-png FILE\tCreate PNG image FILE from alignment.\n"
697 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
698 + "-html FILE\tCreate HTML file from alignment.\n"
699 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
700 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
701 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
702 + "-noquestionnaire\tTurn off questionnaire check.\n"
703 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
704 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
706 // "-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)"
707 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
708 + "-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"
709 + "\t\t\tSources that also support the sequence command may be specified by prepending the URL with sequence:\n"
710 + "\t\t\t e.g. sequence:http://localdas.somewhere.org/das/source)\n"
711 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
713 // "-vdoc vamsas-document\tImport vamsas document into new session or join existing session with same URN\n"
714 // + "-vses vamsas-session\tJoin session with given URN\n"
715 + "-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"
716 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
719 private static void startUsageStats(final Desktop desktop)
722 * start a User Config prompt asking if we can log usage statistics.
724 jalview.gui.PromptUserConfig prompter = new jalview.gui.PromptUserConfig(
727 "Jalview Usage Statistics",
728 "Do you want to help make Jalview better by enabling "
729 + "the collection of usage statistics with Google Analytics ?"
730 + "\n\n(you can enable or disable usage tracking in the preferences)",
737 .debug("Initialising googletracker for usage stats.");
738 Cache.initGoogleTracker();
739 Cache.log.debug("Tracking enabled.");
746 Cache.log.debug("Not enabling Google Tracking.");
749 desktop.addDialogThread(prompter);
753 * Locate the given string as a file and pass it to the groovy interpreter.
755 * @param groovyscript
756 * the script to execute
757 * @param jalviewContext
758 * the Jalview Desktop object passed in to the groovy binding as the
761 private static void executeGroovyScript(String groovyscript,
762 Object[] jalviewContext)
764 if (jalviewContext == null)
767 .println("Sorry. Groovy support is currently only available when running with the Jalview GUI enabled.");
770 * for scripts contained in files
777 if (groovyscript.trim().equals("STDIN"))
779 // read from stdin into a tempfile and execute it
782 tfile = File.createTempFile("jalview", "groovy");
783 PrintWriter outfile = new PrintWriter(new OutputStreamWriter(
784 new FileOutputStream(tfile)));
785 BufferedReader br = new BufferedReader(
786 new java.io.InputStreamReader(System.in));
788 while ((line = br.readLine()) != null)
790 outfile.write(line + "\n");
796 } catch (Exception ex)
798 System.err.println("Failed to read from STDIN into tempfile "
799 + ((tfile == null) ? "(tempfile wasn't created)" : tfile
801 ex.printStackTrace();
806 sfile = tfile.toURI().toURL();
807 } catch (Exception x)
810 .println("Unexpected Malformed URL Exception for temporary file created from STDIN: "
820 sfile = new URI(groovyscript).toURL();
821 } catch (Exception x)
823 tfile = new File(groovyscript);
826 System.err.println("File '" + groovyscript + "' does not exist.");
829 if (!tfile.canRead())
831 System.err.println("File '" + groovyscript + "' cannot be read.");
834 if (tfile.length() < 1)
836 System.err.println("File '" + groovyscript + "' is empty.");
841 sfile = tfile.getAbsoluteFile().toURI().toURL();
842 } catch (Exception ex)
844 System.err.println("Failed to create a file URL for "
845 + tfile.getAbsoluteFile());
850 boolean success = false;
854 * The following code performs the GroovyScriptEngine invocation using
855 * reflection, and is equivalent to this fragment from the embedding
856 * groovy documentation on the groovy site: <code> import
857 * groovy.lang.Binding; import groovy.util.GroovyScriptEngine;
859 * String[] roots = new String[] { "/my/groovy/script/path" };
860 * GroovyScriptEngine gse = new GroovyScriptEngine(roots); Binding binding
861 * = new Binding(); binding.setVariable("input", "world");
862 * gse.run("hello.groovy", binding); </code>
866 int blen = ((jalviewContext[0] == null) ? 0 : 1)
867 + ((jalviewContext[1] == null) ? 0 : 1);
868 String cnames[] = new String[] { "Jalview", "currentAlFrame" };
869 bspec = new Class[blen * 2];
870 binding = new Object[blen * 2];
872 ClassLoader cl = null;
873 Map<String, Object> vbinding = new HashMap<String, Object>();
874 for (int jc = 0; jc < jalviewContext.length; jc++)
876 if (jalviewContext[jc] != null)
880 cl = jalviewContext[jc].getClass().getClassLoader();
882 bspec[blen * 2] = String.class;
883 bspec[blen * 2 + 1] = Object.class;
884 binding[blen * 2] = cnames[jc];
885 binding[blen * 2 + 1] = jalviewContext[jc];
886 vbinding.put(cnames[jc], jalviewContext[jc]);
890 Class<?> gbindingc = cl.loadClass("groovy.lang.Binding");
891 Constructor<?> gbcons;
895 gbcons = gbindingc.getConstructor(Map.class);
896 gbinding = gbcons.newInstance(vbinding);
897 } catch (NoSuchMethodException x)
899 // old style binding config - using series of string/object values to
901 gbcons = gbindingc.getConstructor();
902 gbinding = gbcons.newInstance();
903 java.lang.reflect.Method setvar = gbindingc.getMethod(
904 "setVariable", bspec);
905 setvar.invoke(gbinding, binding);
908 Class<?> gsec = cl.loadClass("groovy.util.GroovyScriptEngine");
909 Constructor<?> gseccons = gsec
910 .getConstructor(new Class[] { URL[].class }); // String[].class
912 Object gse = gseccons
913 .newInstance(new Object[] { new URL[] { sfile } }); // .toString()
915 java.lang.reflect.Method run = gsec.getMethod("run", new Class[] {
916 String.class, gbindingc });
917 run.invoke(gse, new Object[] { sfile.toString(), gbinding });
919 } catch (Exception e)
921 System.err.println("Exception Whilst trying to execute file " + sfile
922 + " as a groovy script.");
923 e.printStackTrace(System.err);
926 if (success && groovyscript.equals("STDIN"))
928 // delete temp file that we made - but only if it was successfully
935 * Check commandline for any das server definitions or any fetchfrom switches
937 * @return vector of DAS source nicknames to retrieve from
939 private static Vector checkDasArguments(ArgsParser aparser)
941 Vector source = null;
943 String locsources = Cache.getProperty(Cache.DAS_LOCAL_SOURCE);
944 while ((data = aparser.getValue("dasserver", true)) != null)
946 String nickname = null;
948 boolean seq = false, feat = true;
949 int pos = data.indexOf('=');
950 // determine capabilities
953 nickname = data.substring(0, pos);
955 url = data.substring(pos + 1);
957 && (url.startsWith("http:") || url
958 .startsWith("sequence:http:")))
960 if (nickname == null)
964 if (locsources == null)
972 locsources = locsources + nickname + "|" + url;
974 .println("NOTE! dasserver parameter not yet really supported (got args of "
975 + nickname + "|" + url);
978 source = new Vector();
980 source.addElement(nickname);
982 System.out.println("CMD [-dasserver " + data
983 + "] executed successfully!");
984 } // loop until no more server entries are found.
985 if (locsources != null && locsources.indexOf('|') > -1)
987 Cache.log.debug("Setting local source list in properties file to:\n"
989 Cache.setProperty(Cache.DAS_LOCAL_SOURCE, locsources);
991 while ((data = aparser.getValue("fetchfrom", true)) != null)
993 System.out.println("adding source '" + data + "'");
996 source = new Vector();
998 source.addElement(data);
1004 * start a feature fetcher for every alignment frame
1008 private static FeatureFetcher startFeatureFetching(final Vector dasSources)
1010 FeatureFetcher ff = new FeatureFetcher();
1011 AlignFrame afs[] = Desktop.getAlignFrames();
1012 if (afs == null || afs.length == 0)
1016 for (int i = 0; i < afs.length; i++)
1018 ff.addFetcher(afs[i], dasSources);
1023 public static boolean isHeadlessMode()
1025 String isheadless = System.getProperty("java.awt.headless");
1026 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1035 * Notes: this argParser does not distinguish between parameter switches,
1036 * parameter values and argument text. If an argument happens to be identical to
1037 * a parameter, it will be taken as such (even though it didn't have a '-'
1040 * @author Andrew Waterhouse and JBP documented.
1044 class rnabuttonlistener implements ActionListener
1047 public void actionPerformed(ActionEvent arg0)
1049 System.out.println("Good idea ! ");
1054 class pbuttonlistener implements ActionListener
1057 public void actionPerformed(ActionEvent arg0)
1065 Vector vargs = null;
1067 public ArgsParser(String[] args)
1069 vargs = new Vector();
1070 for (int i = 0; i < args.length; i++)
1072 String arg = args[i].trim();
1073 if (arg.charAt(0) == '-')
1075 arg = arg.substring(1);
1077 vargs.addElement(arg);
1082 * check for and remove first occurence of arg+parameter in arglist.
1085 * @return return the argument following the given arg if arg was in list.
1087 public String getValue(String arg)
1089 return getValue(arg, false);
1092 public String getValue(String arg, boolean utf8decode)
1094 int index = vargs.indexOf(arg);
1095 String dc = null, ret = null;
1098 ret = vargs.elementAt(index + 1).toString();
1099 vargs.removeElementAt(index);
1100 vargs.removeElementAt(index);
1101 if (utf8decode && ret != null)
1105 dc = URLDecoder.decode(ret, "UTF-8");
1107 } catch (Exception e)
1109 // TODO: log failure to decode
1117 * check for and remove first occurence of arg in arglist.
1120 * @return true if arg was present in argslist.
1122 public boolean contains(String arg)
1124 if (vargs.contains(arg))
1126 vargs.removeElement(arg);
1135 public String nextValue()
1137 return vargs.remove(0).toString();
1140 public int getSize()
1142 return vargs.size();
1148 * keep track of feature fetching tasks.
1153 class FeatureFetcher
1156 * TODO: generalise to track all jalview events to orchestrate batch
1157 * processing events.
1160 private int queued = 0;
1162 private int running = 0;
1164 public FeatureFetcher()
1169 public void addFetcher(final AlignFrame af, final Vector dasSources)
1171 final long id = System.currentTimeMillis();
1173 final FeatureFetcher us = this;
1174 new Thread(new Runnable()
1186 af.setProgressBar(MessageManager
1187 .getString("status.das_features_being_retrived"), id);
1188 af.featureSettings_actionPerformed(null);
1189 af.featureSettings.fetchDasFeatures(dasSources, true);
1190 af.setProgressBar(null, id);
1199 public synchronized boolean allFinished()
1201 return queued == 0 && running == 0;