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 String usrPropsFile = aparser.getValue("props");
113 Cache.loadProperties(usrPropsFile); // must do this before
114 if (usrPropsFile != null)
116 System.out.println("CMD [-props " + usrPropsFile
117 + "] executed successfully!");
122 final String jabawsUrl = aparser.getValue("jabaws");
123 if (jabawsUrl != null)
127 Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
128 System.out.println("CMD [-jabaws " + jabawsUrl
129 + "] executed successfully!");
130 } catch (MalformedURLException e)
132 System.err.println("Invalid jabaws parameter: " + jabawsUrl
137 String defs = aparser.getValue("setprop");
140 int p = defs.indexOf('=');
143 System.err.println("Ignoring invalid setprop argument : " + defs);
147 System.out.println("Executing setprop argument: " + defs);
148 // DISABLED FOR SECURITY REASONS
149 // TODO: add a property to allow properties to be overriden by cli args
150 // Cache.setProperty(defs.substring(0,p), defs.substring(p+1));
152 defs = aparser.getValue("setprop");
154 if (System.getProperty("java.awt.headless") != null
155 && System.getProperty("java.awt.headless").equals("true"))
159 System.setProperty("http.agent",
160 "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
164 } catch (java.lang.NoClassDefFoundError error)
166 error.printStackTrace();
168 .println("\nEssential logging libraries not found."
169 + "\nUse: java -Djava.ext.dirs=$PATH_TO_LIB$ jalview.bin.Jalview");
173 Desktop desktop = null;
177 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
178 } catch (Exception ex)
181 if (new Platform().isAMac())
183 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
185 System.setProperty("apple.laf.useScreenMenuBar", "true");
188 UIManager.setLookAndFeel(ch.randelshofer.quaqua.QuaquaManager
190 } catch (UnsupportedLookAndFeelException e)
192 // TODO Auto-generated catch block
199 desktop = new Desktop();
200 desktop.setInBatchMode(true); // indicate we are starting up
201 desktop.setVisible(true);
202 desktop.startServiceDiscovery();
203 if (!aparser.contains("nousagestats"))
205 startUsageStats(desktop);
209 System.err.println("CMD [-nousagestats] executed successfully!");
212 if (!aparser.contains("noquestionnaire"))
214 String url = aparser.getValue("questionnaire");
217 // Start the desktop questionnaire prompter with the specified
219 Cache.log.debug("Starting questionnaire url at " + url);
220 desktop.checkForQuestionnaire(url);
221 System.out.println("CMD questionnaire[-" + url
222 + "] executed successfully!");
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);
243 System.err.println("CMD [-noquestionnaire] executed successfully!");
245 desktop.checkForNews();
248 if (!isHeadlessMode())
250 BioJsHTMLOutput.updateBioJS();
253 String file = null, protocol = null, format = null, data = null;
254 jalview.io.FileLoader fileLoader = new jalview.io.FileLoader(!headless);
255 Vector getFeatures = null; // vector of das source nicknames to fetch
258 String groovyscript = null; // script to execute after all loading is
259 // completed one way or another
260 // extract groovy argument and execute if necessary
261 groovyscript = aparser.getValue("groovy", true);
262 file = aparser.getValue("open", true);
264 if (file == null && desktop == null)
266 System.out.println("No files to open!");
269 String vamsasImport = aparser.getValue("vdoc"), vamsasSession = aparser
271 if (vamsasImport != null || vamsasSession != null)
273 if (desktop == null || headless)
276 .println("Headless vamsas sessions not yet supported. Sorry.");
279 // if we have a file, start a new session and import it.
280 boolean inSession = false;
281 if (vamsasImport != null)
285 String viprotocol = jalview.io.AppletFormatAdapter
286 .checkProtocol(vamsasImport);
287 if (viprotocol == jalview.io.FormatAdapter.FILE)
289 inSession = desktop.vamsasImport(new File(vamsasImport));
291 else if (viprotocol == jalview.io.FormatAdapter.URL)
293 inSession = desktop.vamsasImport(new URL(vamsasImport));
296 } catch (Exception e)
298 System.err.println("Exeption when importing " + vamsasImport
299 + " as a vamsas document.");
304 System.err.println("Failed to import " + vamsasImport
305 + " as a vamsas document.");
309 System.out.println("Imported Successfully into new session "
310 + desktop.getVamsasApplication().getCurrentSession());
313 if (vamsasSession != null)
315 if (vamsasImport != null)
317 // close the newly imported session and import the Jalview specific
318 // remnants into the new session later on.
319 desktop.vamsasStop_actionPerformed(null);
321 // now join the new session
324 if (desktop.joinVamsasSession(vamsasSession))
326 System.out.println("Successfully joined vamsas session "
331 System.err.println("WARNING: Failed to join vamsas session "
334 } catch (Exception e)
336 System.err.println("ERROR: Failed to join vamsas session "
340 if (vamsasImport != null)
342 // the Jalview specific remnants can now be imported into the new
343 // session at the user's leisure.
345 .info("Skipping Push for import of data into existing vamsas session."); // TODO:
350 // desktop.getVamsasApplication().push_update();
355 // Finally, deal with the remaining input data.
360 desktop.setProgressBar(MessageManager
361 .getString("status.processing_commandline_args"),
362 progress = System.currentTimeMillis());
364 System.out.println("CMD [-open " + file + "] executed successfully!");
366 if (!file.startsWith("http://"))
368 if (!(new java.io.File(file)).exists())
370 System.out.println("Can't find " + file);
378 protocol = jalview.io.AppletFormatAdapter.checkProtocol(file);
380 format = new jalview.io.IdentifyFile().identify(file, protocol);
382 AlignFrame af = fileLoader.LoadFileWaitTillLoaded(file, protocol,
386 System.out.println("error");
390 Desktop.setCurrentAlignFrame(af);
391 data = aparser.getValue("colour", true);
394 data.replaceAll("%20", " ");
396 jalview.schemes.ColourSchemeI cs = jalview.schemes.ColourSchemeProperty
397 .getColour(af.getViewport().getAlignment(), data);
401 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(
403 ucs.parseAppletParameter(data);
408 System.out.println("CMD [-color " + data
409 + "] executed successfully!");
414 // Must maintain ability to use the groups flag
415 data = aparser.getValue("groups", true);
418 af.parseFeaturesFile(data,
419 jalview.io.AppletFormatAdapter.checkProtocol(data));
420 // System.out.println("Added " + data);
421 System.out.println("CMD groups[-" + data
422 + "] executed successfully!");
424 data = aparser.getValue("features", true);
427 af.parseFeaturesFile(data,
428 jalview.io.AppletFormatAdapter.checkProtocol(data));
429 // System.out.println("Added " + data);
430 System.out.println("CMD [-features " + data
431 + "] executed successfully!");
434 data = aparser.getValue("annotations", true);
437 af.loadJalviewDataFile(data, null, null, null);
438 // System.out.println("Added " + data);
439 System.out.println("CMD [-annotations " + data
440 + "] executed successfully!");
442 // set or clear the sortbytree flag.
443 if (aparser.contains("sortbytree"))
445 af.getViewport().setSortByTree(true);
446 if (af.getViewport().getSortByTree())
448 System.out.println("CMD [-sortbytree] executed successfully!");
451 if (aparser.contains("no-annotation"))
453 af.getViewport().setShowAnnotation(false);
454 if (!af.getViewport().isShowAnnotation())
456 System.out.println("CMD no-annotation executed successfully!");
459 if (aparser.contains("nosortbytree"))
461 af.getViewport().setSortByTree(false);
462 if (!af.getViewport().getSortByTree())
465 .println("CMD [-nosortbytree] executed successfully!");
468 data = aparser.getValue("tree", true);
471 jalview.io.NewickFile fin = null;
474 System.out.println("CMD [-tree " + data
475 + "] executed successfully!");
476 fin = new jalview.io.NewickFile(data,
477 jalview.io.AppletFormatAdapter.checkProtocol(data));
480 af.getViewport().setCurrentTree(
481 af.ShowNewickTree(fin, data).getTree());
483 } catch (IOException ex)
485 System.err.println("Couldn't add tree " + data);
486 ex.printStackTrace(System.err);
489 // TODO - load PDB structure(s) to alignment JAL-629
490 // (associate with identical sequence in alignment, or a specified
493 getFeatures = checkDasArguments(aparser);
494 if (af != null && getFeatures != null)
496 FeatureFetcher ff = startFeatureFetching(getFeatures);
499 while (!ff.allFinished() || af.operationInProgress())
501 // wait around until fetching is finished.
505 } catch (Exception e)
511 getFeatures = null; // have retrieved features - forget them now.
513 if (groovyscript != null)
515 // Execute the groovy script after we've done all the rendering stuff
516 // and before any images or figures are generated.
517 if (jalview.bin.Cache.groovyJarsPresent())
519 System.out.println("Executing script " + groovyscript);
520 executeGroovyScript(groovyscript, new Object[] { desktop, af });
522 System.out.println("CMD groovy[" + groovyscript
523 + "] executed successfully!");
528 .println("Sorry. Groovy Support is not available, so ignoring the provided groovy script "
533 String imageName = "unnamed.png";
534 while (aparser.getSize() > 1)
536 format = aparser.nextValue();
537 file = aparser.nextValue();
539 if (format.equalsIgnoreCase("png"))
541 af.createPNG(new java.io.File(file));
542 imageName = (new java.io.File(file)).getName();
543 System.out.println("Creating PNG image: " + file);
546 else if (format.equalsIgnoreCase("svg"))
548 File imageFile = new java.io.File(file);
549 imageName = imageFile.getName();
550 af.createSVG(imageFile);
551 System.out.println("Creating SVG image: " + file);
554 else if (format.equalsIgnoreCase("html"))
556 File imageFile = new java.io.File(file);
557 imageName = imageFile.getName();
558 new HtmlSvgOutput(new java.io.File(file), af.alignPanel);
559 System.out.println("Creating HTML image: " + file);
562 else if (format.equalsIgnoreCase("imgMap"))
564 af.createImageMap(new java.io.File(file), imageName);
565 System.out.println("Creating image map: " + file);
568 else if (format.equalsIgnoreCase("eps"))
570 File outputFile = new java.io.File(file);
571 System.out.println("Creating EPS file: "
572 + outputFile.getAbsolutePath());
573 af.createEPS(outputFile);
577 if (af.saveAlignment(file, format))
579 System.out.println("Written alignment in " + format
580 + " format to " + file);
584 System.out.println("Error writing file " + file + " in "
585 + format + " format!!");
590 while (aparser.getSize() > 0)
592 System.out.println("Unknown arg: " + aparser.nextValue());
596 AlignFrame startUpAlframe = null;
597 // We'll only open the default file if the desktop is visible.
599 // ////////////////////
601 if (!headless && file == null && vamsasImport == null
602 && jalview.bin.Cache.getDefault("SHOW_STARTUP_FILE", true))
604 file = jalview.bin.Cache.getDefault(
606 jalview.bin.Cache.getDefault("www.jalview.org",
607 "http://www.jalview.org")
608 + "/examples/exampleFile_2_7.jar");
609 if (file.equals("http://www.jalview.org/examples/exampleFile_2_3.jar"))
611 // hardwire upgrade of the startup file
612 file.replace("_2_3.jar", "_2_7.jar");
613 // and remove the stale setting
614 jalview.bin.Cache.removeProperty("STARTUP_FILE");
619 if (file.indexOf("http:") > -1)
624 if (file.endsWith(".jar"))
630 format = new jalview.io.IdentifyFile().identify(file, protocol);
633 startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
635 getFeatures = checkDasArguments(aparser);
636 // extract groovy arguments before anything else.
638 // If the user has specified features to be retrieved,
639 // or a groovy script to be executed, do them if they
640 // haven't been done already
641 // fetch features for the default alignment
642 if (getFeatures != null)
644 if (startUpAlframe != null)
646 startFeatureFetching(getFeatures);
649 // Once all other stuff is done, execute any groovy scripts (in order)
650 if (groovyscript != null)
652 if (jalview.bin.Cache.groovyJarsPresent())
654 System.out.println("Executing script " + groovyscript);
655 executeGroovyScript(groovyscript, new Object[] { desktop,
661 .println("Sorry. Groovy Support is not available, so ignoring the provided groovy script "
665 // and finally, turn off batch mode indicator - if the desktop still exists
670 desktop.setProgressBar(null, progress);
672 desktop.setInBatchMode(false);
676 private static void showUsage()
679 .println("Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n"
680 + "-nodisplay\tRun Jalview without User Interface.\n"
681 + "-props FILE\tUse the given Jalview properties file instead of users default.\n"
682 + "-colour COLOURSCHEME\tThe colourscheme to be applied to the alignment\n"
683 + "-annotations FILE\tAdd precalculated annotations to the alignment.\n"
684 + "-tree FILE\tLoad the given newick format tree file onto the alignment\n"
685 + "-features FILE\tUse the given file to mark features on the alignment.\n"
686 + "-fasta FILE\tCreate alignment file FILE in Fasta format.\n"
687 + "-clustal FILE\tCreate alignment file FILE in Clustal format.\n"
688 + "-pfam FILE\tCreate alignment file FILE in PFAM format.\n"
689 + "-msf FILE\tCreate alignment file FILE in MSF format.\n"
690 + "-pileup FILE\tCreate alignment file FILE in Pileup format\n"
691 + "-pir FILE\tCreate alignment file FILE in PIR format.\n"
692 + "-blc FILE\tCreate alignment file FILE in BLC format.\n"
693 + "-json FILE\tCreate alignment file FILE in JSON format.\n"
694 + "-jalview FILE\tCreate alignment file FILE in Jalview format.\n"
695 + "-png FILE\tCreate PNG image FILE from alignment.\n"
696 + "-svg FILE\tCreate SVG image FILE from alignment.\n"
697 + "-html FILE\tCreate HTML file from alignment.\n"
698 + "-imgMap FILE\tCreate HTML file FILE with image map of PNG image.\n"
699 + "-eps FILE\tCreate EPS file FILE from alignment.\n"
700 + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n"
701 + "-noquestionnaire\tTurn off questionnaire check.\n"
702 + "-nousagestats\tTurn off google analytics tracking for this session.\n"
703 + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n"
705 // "-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)"
706 + "-jabaws URL\tSpecify URL for Jabaws services (e.g. for a local installation).\n"
707 + "-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"
708 + "\t\t\tSources that also support the sequence command may be specified by prepending the URL with sequence:\n"
709 + "\t\t\t e.g. sequence:http://localdas.somewhere.org/das/source)\n"
710 + "-fetchfrom nickname\tQuery nickname for features for the alignments and display them.\n"
712 // "-vdoc vamsas-document\tImport vamsas document into new session or join existing session with same URN\n"
713 // + "-vses vamsas-session\tJoin session with given URN\n"
714 + "-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"
715 + "\n~Read documentation in Application or visit http://www.jalview.org for description of Features and Annotations file~\n\n");
718 private static void startUsageStats(final Desktop desktop)
721 * start a User Config prompt asking if we can log usage statistics.
723 jalview.gui.PromptUserConfig prompter = new jalview.gui.PromptUserConfig(
726 "Jalview Usage Statistics",
727 "Do you want to help make Jalview better by enabling "
728 + "the collection of usage statistics with Google Analytics ?"
729 + "\n\n(you can enable or disable usage tracking in the preferences)",
735 .debug("Initialising googletracker for usage stats.");
736 Cache.initGoogleTracker();
737 Cache.log.debug("Tracking enabled.");
743 Cache.log.debug("Not enabling Google Tracking.");
746 desktop.addDialogThread(prompter);
750 * Locate the given string as a file and pass it to the groovy interpreter.
752 * @param groovyscript
753 * the script to execute
754 * @param jalviewContext
755 * the Jalview Desktop object passed in to the groovy binding as the
758 private static void executeGroovyScript(String groovyscript,
759 Object[] jalviewContext)
761 if (jalviewContext == null)
764 .println("Sorry. Groovy support is currently only available when running with the Jalview GUI enabled.");
767 * for scripts contained in files
774 if (groovyscript.trim().equals("STDIN"))
776 // read from stdin into a tempfile and execute it
779 tfile = File.createTempFile("jalview", "groovy");
780 PrintWriter outfile = new PrintWriter(new OutputStreamWriter(
781 new FileOutputStream(tfile)));
782 BufferedReader br = new BufferedReader(
783 new java.io.InputStreamReader(System.in));
785 while ((line = br.readLine()) != null)
787 outfile.write(line + "\n");
793 } catch (Exception ex)
795 System.err.println("Failed to read from STDIN into tempfile "
796 + ((tfile == null) ? "(tempfile wasn't created)" : tfile
798 ex.printStackTrace();
803 sfile = tfile.toURI().toURL();
804 } catch (Exception x)
807 .println("Unexpected Malformed URL Exception for temporary file created from STDIN: "
817 sfile = new URI(groovyscript).toURL();
818 } catch (Exception x)
820 tfile = new File(groovyscript);
823 System.err.println("File '" + groovyscript + "' does not exist.");
826 if (!tfile.canRead())
828 System.err.println("File '" + groovyscript + "' cannot be read.");
831 if (tfile.length() < 1)
833 System.err.println("File '" + groovyscript + "' is empty.");
838 sfile = tfile.getAbsoluteFile().toURI().toURL();
839 } catch (Exception ex)
841 System.err.println("Failed to create a file URL for "
842 + tfile.getAbsoluteFile());
847 boolean success = false;
851 * The following code performs the GroovyScriptEngine invocation using
852 * reflection, and is equivalent to this fragment from the embedding
853 * groovy documentation on the groovy site: <code> import
854 * groovy.lang.Binding; import groovy.util.GroovyScriptEngine;
856 * String[] roots = new String[] { "/my/groovy/script/path" };
857 * GroovyScriptEngine gse = new GroovyScriptEngine(roots); Binding binding
858 * = new Binding(); binding.setVariable("input", "world");
859 * gse.run("hello.groovy", binding); </code>
863 int blen = ((jalviewContext[0] == null) ? 0 : 1)
864 + ((jalviewContext[1] == null) ? 0 : 1);
865 String cnames[] = new String[] { "Jalview", "currentAlFrame" };
866 bspec = new Class[blen * 2];
867 binding = new Object[blen * 2];
869 ClassLoader cl = null;
870 Map<String, Object> vbinding = new HashMap<String, Object>();
871 for (int jc = 0; jc < jalviewContext.length; jc++)
873 if (jalviewContext[jc] != null)
877 cl = jalviewContext[jc].getClass().getClassLoader();
879 bspec[blen * 2] = String.class;
880 bspec[blen * 2 + 1] = Object.class;
881 binding[blen * 2] = cnames[jc];
882 binding[blen * 2 + 1] = jalviewContext[jc];
883 vbinding.put(cnames[jc], jalviewContext[jc]);
887 Class<?> gbindingc = cl.loadClass("groovy.lang.Binding");
888 Constructor<?> gbcons;
892 gbcons = gbindingc.getConstructor(Map.class);
893 gbinding = gbcons.newInstance(vbinding);
894 } catch (NoSuchMethodException x)
896 // old style binding config - using series of string/object values to
898 gbcons = gbindingc.getConstructor();
899 gbinding = gbcons.newInstance();
900 java.lang.reflect.Method setvar = gbindingc.getMethod(
901 "setVariable", bspec);
902 setvar.invoke(gbinding, binding);
905 Class<?> gsec = cl.loadClass("groovy.util.GroovyScriptEngine");
906 Constructor<?> gseccons = gsec
907 .getConstructor(new Class[] { URL[].class }); // String[].class
909 Object gse = gseccons
910 .newInstance(new Object[] { new URL[] { sfile } }); // .toString()
912 java.lang.reflect.Method run = gsec.getMethod("run", new Class[] {
913 String.class, gbindingc });
914 run.invoke(gse, new Object[] { sfile.toString(), gbinding });
916 } catch (Exception e)
918 System.err.println("Exception Whilst trying to execute file " + sfile
919 + " as a groovy script.");
920 e.printStackTrace(System.err);
923 if (success && groovyscript.equals("STDIN"))
925 // delete temp file that we made - but only if it was successfully
932 * Check commandline for any das server definitions or any fetchfrom switches
934 * @return vector of DAS source nicknames to retrieve from
936 private static Vector checkDasArguments(ArgsParser aparser)
938 Vector source = null;
940 String locsources = Cache.getProperty(Cache.DAS_LOCAL_SOURCE);
941 while ((data = aparser.getValue("dasserver", true)) != null)
943 String nickname = null;
945 boolean seq = false, feat = true;
946 int pos = data.indexOf('=');
947 // determine capabilities
950 nickname = data.substring(0, pos);
952 url = data.substring(pos + 1);
954 && (url.startsWith("http:") || url
955 .startsWith("sequence:http:")))
957 if (nickname == null)
961 if (locsources == null)
969 locsources = locsources + nickname + "|" + url;
971 .println("NOTE! dasserver parameter not yet really supported (got args of "
972 + nickname + "|" + url);
975 source = new Vector();
977 source.addElement(nickname);
979 System.out.println("CMD [-dasserver " + data
980 + "] executed successfully!");
981 } // loop until no more server entries are found.
982 if (locsources != null && locsources.indexOf('|') > -1)
984 Cache.log.debug("Setting local source list in properties file to:\n"
986 Cache.setProperty(Cache.DAS_LOCAL_SOURCE, locsources);
988 while ((data = aparser.getValue("fetchfrom", true)) != null)
990 System.out.println("adding source '" + data + "'");
993 source = new Vector();
995 source.addElement(data);
1001 * start a feature fetcher for every alignment frame
1005 private static FeatureFetcher startFeatureFetching(final Vector dasSources)
1007 FeatureFetcher ff = new FeatureFetcher();
1008 AlignFrame afs[] = Desktop.getAlignFrames();
1009 if (afs == null || afs.length == 0)
1013 for (int i = 0; i < afs.length; i++)
1015 ff.addFetcher(afs[i], dasSources);
1020 public static boolean isHeadlessMode()
1022 String isheadless = System.getProperty("java.awt.headless");
1023 if (isheadless != null && isheadless.equalsIgnoreCase("true"))
1032 * Notes: this argParser does not distinguish between parameter switches,
1033 * parameter values and argument text. If an argument happens to be identical to
1034 * a parameter, it will be taken as such (even though it didn't have a '-'
1037 * @author Andrew Waterhouse and JBP documented.
1041 class rnabuttonlistener implements ActionListener
1043 public void actionPerformed(ActionEvent arg0)
1045 System.out.println("Good idea ! ");
1050 class pbuttonlistener implements ActionListener
1052 public void actionPerformed(ActionEvent arg0)
1060 Vector vargs = null;
1062 public ArgsParser(String[] args)
1064 vargs = new Vector();
1065 for (int i = 0; i < args.length; i++)
1067 String arg = args[i].trim();
1068 if (arg.charAt(0) == '-')
1070 arg = arg.substring(1);
1072 vargs.addElement(arg);
1077 * check for and remove first occurence of arg+parameter in arglist.
1080 * @return return the argument following the given arg if arg was in list.
1082 public String getValue(String arg)
1084 return getValue(arg, false);
1087 public String getValue(String arg, boolean utf8decode)
1089 int index = vargs.indexOf(arg);
1090 String dc = null, ret = null;
1093 ret = vargs.elementAt(index + 1).toString();
1094 vargs.removeElementAt(index);
1095 vargs.removeElementAt(index);
1096 if (utf8decode && ret != null)
1100 dc = URLDecoder.decode(ret, "UTF-8");
1102 } catch (Exception e)
1104 // TODO: log failure to decode
1112 * check for and remove first occurence of arg in arglist.
1115 * @return true if arg was present in argslist.
1117 public boolean contains(String arg)
1119 if (vargs.contains(arg))
1121 vargs.removeElement(arg);
1130 public String nextValue()
1132 return vargs.remove(0).toString();
1135 public int getSize()
1137 return vargs.size();
1143 * keep track of feature fetching tasks.
1148 class FeatureFetcher
1151 * TODO: generalise to track all jalview events to orchestrate batch
1152 * processing events.
1155 private int queued = 0;
1157 private int running = 0;
1159 public FeatureFetcher()
1164 public void addFetcher(final AlignFrame af, final Vector dasSources)
1166 final long id = System.currentTimeMillis();
1168 final FeatureFetcher us = this;
1169 new Thread(new Runnable()
1180 af.setProgressBar(MessageManager
1181 .getString("status.das_features_being_retrived"), id);
1182 af.featureSettings_actionPerformed(null);
1183 af.featureSettings.fetchDasFeatures(dasSources, true);
1184 af.setProgressBar(null, id);
1193 public synchronized boolean allFinished()
1195 return queued == 0 && running == 0;