JAL-972 - refactored local source builder to registry implementation and made Cache...
[jalview.git] / src / jalview / bin / Cache.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3  * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
4  * 
5  * This file is part of Jalview.
6  * 
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 of the License, or (at your option) any later version.
10  * 
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 package jalview.bin;
19
20 import jalview.ws.dbsources.das.api.DasSourceRegistryI;
21 import jalview.ws.dbsources.das.datamodel.DasSourceRegistry;
22
23 import java.awt.Color;
24 import java.io.*;
25 import java.text.DateFormat;
26 import java.text.SimpleDateFormat;
27 import java.util.*;
28
29 import org.apache.log4j.*;
30
31 /**
32  * Stores and retrieves Jalview Application Properties Lists and fields within
33  * list entries are separated by '|' symbols unless otherwise stated (|) clauses
34  * are alternative values for a tag. <br>
35  * <br>
36  * Current properties include:
37  * <ul>
38  * <br>
39  * logs.Axis.Level - one of the stringified Levels for log4j controlling the
40  * logging level for axis (used for web services) <br>
41  * </li>
42  * <li>logs.Castor.Level - one of the stringified Levels for log4j controlling
43  * the logging level for castor (used for serialization) <br>
44  * </li>
45  * <li>logs.Jalview.Level - Cache.log stringified level. <br>
46  * </li>
47  * <li>SCREEN_WIDTH</li>
48  * <li>SCREEN_HEIGHT</li>
49  * <li>SCREEN_Y=285</li>
50  * <li>SCREEN_X=371</li>
51  * <li>SHOW_FULLSCREEN boolean</li>
52  * <li>FONT_NAME java font name for alignment text display</li>
53  * <li>FONT_SIZE size of displayed alignment text</li>
54  * <li>FONT_STYLE style of font displayed (sequence labels are always italic)</li>
55  * <li>GAP_SYMBOL character to treat as gap symbol (usually -,.,' ')</li>
56  * <li>LAST_DIRECTORY last directory for browsing alignment</li>
57  * <li>USER_DEFINED_COLOURS list of user defined colour scheme files</li>
58  * <li>SHOW_FULL_ID show id with '/start-end' numbers appended</li>
59  * <li>SHOW_IDENTITY show percentage identity annotation</li>
60  * <li>SHOW_QUALITY show alignment quality annotation</li>
61  * <li>SHOW_ANNOTATIONS show alignment annotation rows</li>
62  * <li>SHOW_CONSERVATION show alignment conservation annotation</li>
63  * <li>CENTRE_COLUMN_LABELS centre the labels at each column in a displayed
64  * annotation row</li>
65  * <li>DEFAULT_COLOUR default colour scheme to apply for a new alignment</li>
66  * <li>DEFAULT_FILE_FORMAT file format used to save</li>
67  * <li>STARTUP_FILE file loaded on startup (may be a fully qualified url)</li>
68  * <li>SHOW_STARTUP_FILE flag to control loading of startup file</li>
69  * <li>VERSION the version of the jalview build</li>
70  * <li>BUILD_DATE date of this build</li>
71  * <li>LATEST_VERSION the latest jalview version advertised on the
72  * www.jalview.org</li>
73  * <li>PIR_MODELLER boolean indicating if PIR files are written with MODELLER
74  * descriptions</li>
75  * <li>(FASTA,MSF,PILEUP,CLUSTAL,BLC,PIR,PFAM)_JVSUFFIX boolean for adding jv
76  * suffix to file</li>
77  * <li>RECENT_URL list of recently retrieved URLs</li>
78  * <li>RECENT_FILE list of recently opened files</li>
79  * <li>USE_PROXY flag for whether a http proxy is to be used</li>
80  * <li>PROXY_SERVER the proxy</li>
81  * <li>PROXY_PORT</li>
82  * <li>NOQUESTIONNAIRES true to prevent jalview from checking the questionnaire
83  * service</li>
84  * <li>QUESTIONNAIRE last questionnaire:responder id string from questionnaire
85  * service</li>
86  * <li>USAGESTATS (false - user prompted) Enable google analytics tracker for
87  * collecting usage statistics</li>
88  * <li>DAS_LOCAL_SOURCE list of local das sources</li>
89  * <li>SHOW_OVERVIEW boolean for overview window display</li>
90  * <li>ANTI_ALIAS boolean for smooth fonts</li>
91  * <li>RIGHT_ALIGN_IDS boolean</li>
92  * <li>AUTO_CALC_CONSENSUS boolean for automatic recalculation of consensus</li>
93  * <li>PAD_GAPS boolean</li>
94  * <li>ID_ITALICS boolean</li>
95  * <li>SHOW_JV_SUFFIX</li>
96  * <li>WRAP_ALIGNMENT</li>
97  * <li>EPS_RENDERING (Prompt each time|Lineart|Text) default for EPS rendering
98  * style check</li>
99  * <li>SORT_ALIGNMENT (No sort|Id|Pairwise Identity)</li>
100  * <li>SEQUENCE_LINKS list of name|URL pairs for opening a url with
101  * $SEQUENCE_ID$</li>
102  * <li>GROUP_LINKS list of name|URL[|&lt;separator&gt;] tuples - see
103  * jalview.utils.GroupURLLink for more info</li>
104  * <li>DAS_REGISTRY_URL the registry to query</li>
105  * <li>DEFAULT_BROWSER for unix</li>
106  * <li>DAS_ACTIVE_SOURCE list of active sources</li>
107  * <li>SHOW_MEMUSAGE boolean show memory usage and warning indicator on desktop
108  * (false)</li>
109  * <li>VERSION_CHECK (true) check for the latest release version from
110  * www.jalview.org (or the alias given by the www.jalview.org property)</li>
111  * <li>SHOW_NPFEATS_TOOLTIP (true) show non-positional features in the Sequence
112  * ID tooltip</li>
113  * <li>SHOW_DBREFS_TOOLTIP (true) show Database Cross References in the Sequence
114  * ID tooltip</li>
115  * <li>SHOW_UNCONSERVED (false) only render unconserved residues - conserved
116  * displayed as '.'</li>
117  * <li>SORT_BY_TREE (false) sort the current alignment view according to the
118  * order of a newly displayed tree</li>
119  * <li>DBFETCH_USEPICR (false) use PICR to recover valid DB references from
120  * sequence ID strings before attempting retrieval from any datasource</li>
121  * <li>SHOW_GROUP_CONSENSUS (false) Show consensus annotation for groups in the
122  * alignment.</li>
123  * <li>SHOW_GROUP_CONSERVATION (false) Show conservation annotation for groups
124  * in the alignment.</li>
125  * <li>SHOW_CONSENSUS_HISTOGRAM (false) Show consensus annotation row's
126  * histogram.</li>
127  * <li>SHOW_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
128  * logo.</li>
129  * <li>FOLLOW_SELECTIONS (true) Controls whether a new alignment view should
130  * respond to selections made in other alignments containing the same sequences.
131  * </li>
132  * <li>SHOW_WSDISCOVERY_ERRORS (true) Controls if the web service URL discovery
133  * warning dialog box is displayed.</li>
134  * <li>ANNOTATIONCOLOUR_MIN (orange) Shade used for minimum value of annotation when shading by annotation</li>
135  * <li>ANNOTATIONCOLOUR_MAX (red) Shade used for maximum value of annotation when shading by annotation</li>
136  * <li>www.jalview.org (http://www.jalview.org) a property enabling all HTTP requests to be redirected to a mirror of http://www.jalview.org</li>
137  * 
138  * <li>FIGURE_AUTOIDWIDTH (false) Expand the left hand column of an exported alignment figure to accommodate even the longest sequence ID or annotation label.</li>
139  * <li>FIGURE_FIXEDIDWIDTH Specifies the width to use for the left-hand column when exporting an alignment as a figure (setting FIGURE_AUTOIDWIDTH to true will override this).</li>
140  * <li></li>
141  * 
142  * </ul>
143  * Deprecated settings:
144  * <ul>
145  *  * <li>DISCOVERY_START - Boolean - controls if discovery services are queried on
146  * startup (JWS1 services only)</li>
147  * <li>DISCOVERY_URLS - comma separated list of Discovery Service endpoints. (JWS1 services only)</li>
148  * <li>SHOW_JWS1_SERVICES (true) enable or disable the original Jalview 2 services in the desktop GUI</li>
149  * <li>ENABLE_RSBS_EDITOR (false for 2.7 release) enable or disable RSBS editing panel in web service preferences</li> 
150  * </ul>
151  * @author $author$
152  * @version $Revision$
153  */
154 public class Cache
155 {
156   /**
157    * property giving log4j level for CASTOR loggers
158    */
159   public static final String CASTORLOGLEVEL = "logs.Castor.level";
160
161   /**
162    * property giving log4j level for AXIS loggers
163    */
164   public static final String AXISLOGLEVEL = "logs.Axis.level";
165
166   /**
167    * property giving log4j level for Jalview Log
168    */
169   public static final String JALVIEWLOGLEVEL = "logs.Jalview.level";
170
171   public static final String DAS_LOCAL_SOURCE = "DAS_LOCAL_SOURCE";
172
173   public static final String DAS_REGISTRY_URL = "DAS_REGISTRY_URL";
174
175   public static final String DAS_ACTIVE_SOURCE = "DAS_ACTIVE_SOURCE";
176
177   /**
178    * Initialises the Jalview Application Log
179    */
180   public static Logger log;
181
182   /** Jalview Properties */
183   public static Properties applicationProperties = new Properties();
184
185   /** Default file is ~/.jalview_properties */
186   static String propertiesFile;
187
188   private static boolean propsAreReadOnly=false;
189
190   public static void initLogger()
191   {
192     if (log != null)
193     {
194       return;
195     }
196     try
197     {
198       // TODO: redirect stdout and stderr here in order to grab the output of
199       // the log
200
201       ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(),
202               "System.err");
203       ap.setName("JalviewLogger");
204       org.apache.log4j.Logger.getRootLogger().addAppender(ap); // catch all for
205       // log output
206       Logger laxis = Logger.getLogger("org.apache.axis");
207       Logger lcastor = Logger.getLogger("org.exolab.castor");
208       jalview.bin.Cache.log = Logger.getLogger("jalview.bin.Jalview");
209
210       laxis.setLevel(Level.toLevel(Cache.getDefault("logs.Axis.Level",
211               Level.INFO.toString())));
212       lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
213               Level.INFO.toString())));
214       lcastor = Logger.getLogger("org.exolab.castor.xml");
215       lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
216               Level.INFO.toString())));
217       // lcastor = Logger.getLogger("org.exolab.castor.xml.Marshaller");
218       // lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
219       // Level.INFO.toString())));
220       jalview.bin.Cache.log.setLevel(Level.toLevel(Cache.getDefault(
221               "logs.Jalview.level", Level.INFO.toString())));
222       // laxis.addAppender(ap);
223       // lcastor.addAppender(ap);
224       // jalview.bin.Cache.log.addAppender(ap);
225       // Tell the user that debug is enabled
226       jalview.bin.Cache.log.debug("Jalview Debugging Output Follows.");
227     } catch (Exception ex)
228     {
229       System.err.println("Problems initializing the log4j system\n");
230       ex.printStackTrace(System.err);
231     }
232   }
233
234   /** Called when Jalview is started */
235   public static void loadProperties(String propsFile)
236   {
237     propertiesFile = propsFile;
238     if (propsFile == null)
239     {
240       propertiesFile = System.getProperty("user.home") + File.separatorChar
241               + ".jalview_properties";
242     } else {
243       // don't corrupt the file we've been given.
244       propsAreReadOnly = true;
245     }
246
247     try
248     {
249       InputStream fis;
250       try
251       {
252         fis = new java.net.URL(propertiesFile).openStream();
253         System.out.println("Loading jalview properties from : "
254                 + propertiesFile);
255         System.out
256                 .println("Disabling Jalview writing to user's local properties file.");
257         propsAreReadOnly = true;
258
259       } catch (Exception ex)
260       {
261         fis = null;
262       }
263       if (fis == null)
264       {
265         fis = new FileInputStream(propertiesFile);
266       }
267       applicationProperties.load(fis);
268       applicationProperties.remove("LATEST_VERSION");
269       applicationProperties.remove("VERSION");
270       fis.close();
271     } catch (Exception ex)
272     {
273       System.out.println("Error reading properties file: " + ex);
274     }
275
276     if (getDefault("USE_PROXY", false))
277     {
278       System.out.println("Using proxyServer: "
279               + getDefault("PROXY_SERVER", null) + " proxyPort: "
280               + getDefault("PROXY_PORT", null));
281       System.setProperty("http.proxyHost", getDefault("PROXY_SERVER", null));
282       System.setProperty("http.proxyPort", getDefault("PROXY_PORT", null));
283     }
284
285     // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar
286     // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE
287     // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW
288     try
289     {
290       String buildDetails = "jar:".concat(Cache.class.getProtectionDomain()
291               .getCodeSource().getLocation().toString()
292               .concat("!/.build_properties"));
293
294       java.net.URL localJarFileURL = new java.net.URL(buildDetails);
295
296       InputStream in = localJarFileURL.openStream();
297       applicationProperties.load(in);
298       in.close();
299     } catch (Exception ex)
300     {
301       System.out.println("Error reading build details: " + ex);
302       applicationProperties.remove("VERSION");
303     }
304
305     String jnlpVersion = System.getProperty("jalview.version");
306     String codeVersion = getProperty("VERSION");
307
308     if (codeVersion == null)
309     {
310       // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
311       codeVersion = "Test";
312       jnlpVersion = "Test";
313     }
314
315     System.out.println("Jalview Version: " + codeVersion);
316
317     // jnlpVersion will be null if we're using InstallAnywhere
318     // Dont do this check if running in headless mode
319     if (jnlpVersion == null
320             && getDefault("VERSION_CHECK", true)
321             && (System.getProperty("java.awt.headless") == null || System
322                     .getProperty("java.awt.headless").equals("false")))
323     {
324
325       class VersionChecker extends Thread
326       {
327         public void run()
328         {
329           String orgtimeout = System
330                   .getProperty("sun.net.client.defaultConnectTimeout");
331           if (orgtimeout == null)
332           {
333             orgtimeout = "30";
334             System.out.println("# INFO: Setting default net timeout to "
335                     + orgtimeout + " seconds.");
336           }
337           String jnlpVersion = null;
338           try
339           {
340             System.setProperty("sun.net.client.defaultConnectTimeout",
341                     "5000");
342             java.net.URL url = new java.net.URL(
343                     Cache.getDefault("www.jalview.org", "http://www.jalview.org")+"/webstart/jalview.jnlp");
344             BufferedReader in = new BufferedReader(new InputStreamReader(
345                     url.openStream()));
346             String line = null;
347             while ((line = in.readLine()) != null)
348             {
349               if (line.indexOf("jalview.version") == -1)
350               {
351                 continue;
352               }
353
354               line = line.substring(line.indexOf("value=") + 7);
355               line = line.substring(0, line.lastIndexOf("\""));
356               jnlpVersion = line;
357               break;
358             }
359           } catch (Exception ex)
360           {
361             System.out
362                     .println("Non-fatal exceptions when checking version at www.jalview.org :");
363             System.out.println(ex);
364             jnlpVersion = getProperty("VERSION");
365           }
366           System.setProperty("sun.net.client.defaultConnectTimeout",
367                   orgtimeout);
368
369           setProperty("LATEST_VERSION", jnlpVersion);
370         }
371       }
372
373       VersionChecker vc = new VersionChecker();
374       vc.start();
375     }
376     else
377     {
378       if (jnlpVersion != null)
379       {
380         setProperty("LATEST_VERSION", jnlpVersion);
381       }
382       else
383       {
384         applicationProperties.remove("LATEST_VERSION");
385       }
386     }
387
388     setProperty("VERSION", codeVersion);
389
390     // LOAD USERDEFINED COLOURS
391     jalview.gui.UserDefinedColours
392             .initUserColourSchemes(getProperty("USER_DEFINED_COLOURS"));
393     jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER",
394             false);
395   }
396
397   /**
398    * Gets Jalview application property of given key. Returns null if key not
399    * found
400    * 
401    * @param key
402    *          Name of property
403    * 
404    * @return Property value
405    */
406   public static String getProperty(String key)
407   {
408     return applicationProperties.getProperty(key);
409   }
410
411   /**
412    * These methods are used when checking if the saved preference is different
413    * to the default setting
414    */
415
416   public static boolean getDefault(String property, boolean def)
417   {
418     String string = getProperty(property);
419     if (string != null)
420     {
421       def = Boolean.valueOf(string).booleanValue();
422     }
423
424     return def;
425   }
426
427   /**
428    * These methods are used when checking if the saved preference is different
429    * to the default setting
430    */
431   public static String getDefault(String property, String def)
432   {
433     String string = getProperty(property);
434     if (string != null)
435     {
436       return string;
437     }
438
439     return def;
440   }
441
442   /**
443    * Stores property in the file "HOME_DIR/.jalview_properties"
444    * 
445    * @param key
446    *          Name of object
447    * @param obj
448    *          String value of property
449    * 
450    * @return String value of property
451    */
452   public static String setProperty(String key, String obj)
453   {
454
455     try
456     {
457       applicationProperties.setProperty(key, obj);
458       if (!propsAreReadOnly)
459       {
460         FileOutputStream out = new FileOutputStream(propertiesFile);
461         applicationProperties.store(out, "---JalviewX Properties File---");
462         out.close();
463       }
464     } catch (Exception ex)
465     {
466       System.out.println("Error setting property: " + key + " " + obj
467               + "\n" + ex);
468     }
469     return obj;
470   }
471
472   /**
473    * remove the specified property from the jalview properties file
474    * 
475    * @param string
476    */
477   public static void removeProperty(String string)
478   {
479     applicationProperties.remove(string);
480     saveProperties();
481   }
482
483   /**
484    * save the properties to the jalview properties path
485    */
486   public static void saveProperties()
487   {
488     if (!propsAreReadOnly)
489     {
490       try
491       {
492         FileOutputStream out = new FileOutputStream(propertiesFile);
493         applicationProperties.store(out, "---JalviewX Properties File---");
494         out.close();
495       } catch (Exception ex)
496       {
497         System.out.println("Error saving properties: " + ex);
498       }
499     }
500   }
501
502   /**
503    * internal vamsas class discovery state
504    */
505   private static int vamsasJarsArePresent = -1;
506
507   /**
508    * Searches for vamsas client classes on class path.
509    * 
510    * @return true if vamsas client is present on classpath
511    */
512   public static boolean vamsasJarsPresent()
513   {
514     if (vamsasJarsArePresent == -1)
515     {
516       try
517       {
518         if (jalview.jbgui.GDesktop.class.getClassLoader().loadClass(
519                 "uk.ac.vamsas.client.VorbaId") != null)
520         {
521           jalview.bin.Cache.log
522                   .debug("Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
523           vamsasJarsArePresent = 1;
524           Logger lvclient = Logger.getLogger("uk.ac.vamsas");
525           lvclient.setLevel(Level.toLevel(Cache.getDefault(
526                   "logs.Vamsas.Level", Level.INFO.toString())));
527
528           lvclient.addAppender(log.getAppender("JalviewLogger"));
529           // Tell the user that debug is enabled
530           lvclient.debug("Jalview Vamsas Client Debugging Output Follows.");
531         }
532       } catch (Exception e)
533       {
534         vamsasJarsArePresent = 0;
535         jalview.bin.Cache.log.debug("Vamsas Classes are not present");
536       }
537     }
538     return (vamsasJarsArePresent > 0);
539   }
540
541   /**
542    * internal vamsas class discovery state
543    */
544   private static int groovyJarsArePresent = -1;
545
546   /**
547    * Searches for vamsas client classes on class path.
548    * 
549    * @return true if vamsas client is present on classpath
550    */
551   public static boolean groovyJarsPresent()
552   {
553     if (groovyJarsArePresent == -1)
554     {
555       try
556       {
557         if (Cache.class.getClassLoader().loadClass(
558                 "groovy.lang.GroovyObject") != null)
559         {
560           jalview.bin.Cache.log
561                   .debug("Found Groovy (groovy.lang.GroovyObject can be loaded)");
562           groovyJarsArePresent = 1;
563           Logger lgclient = Logger.getLogger("groovy");
564           lgclient.setLevel(Level.toLevel(Cache.getDefault(
565                   "logs.Groovy.Level", Level.INFO.toString())));
566
567           lgclient.addAppender(log.getAppender("JalviewLogger"));
568           // Tell the user that debug is enabled
569           lgclient.debug("Jalview Groovy Client Debugging Output Follows.");
570         }
571       } catch (Error e)
572       {
573         groovyJarsArePresent = 0;
574         jalview.bin.Cache.log.debug("Groovy Classes are not present", e);
575       } catch (Exception e)
576       {
577         groovyJarsArePresent = 0;
578         jalview.bin.Cache.log.debug("Groovy Classes are not present");
579       }
580     }
581     return (groovyJarsArePresent > 0);
582   }
583
584   /**
585    * GA tracker object - actually JGoogleAnalyticsTracker null if tracking not
586    * enabled.
587    */
588   protected static Object tracker = null;
589
590   protected static Class trackerfocus = null;
591
592   protected static Class jgoogleanalyticstracker = null;
593
594   /**
595    * Initialise the google tracker if it is not done already.
596    */
597   public static void initGoogleTracker()
598   {
599     if (tracker == null)
600     {
601       if (jgoogleanalyticstracker == null)
602       {
603         // try to get the tracker class
604         try
605         {
606           jgoogleanalyticstracker = Cache.class
607                   .getClassLoader()
608                   .loadClass(
609                           "com.boxysystems.jgoogleanalytics.JGoogleAnalyticsTracker");
610           trackerfocus = Cache.class.getClassLoader().loadClass(
611                   "com.boxysystems.jgoogleanalytics.FocusPoint");
612         } catch (Exception e)
613         {
614           log.debug("com.boxysystems.jgoogleanalytics package is not present - tracking not enabled.");
615           tracker = null;
616           jgoogleanalyticstracker = null;
617           trackerfocus = null;
618           return;
619         }
620       }
621       // now initialise tracker
622       Exception re = null, ex = null;
623       Error err = null;
624       String vrs = "No Version Accessible";
625       try
626       {
627         // Google analytics tracking code for Library Finder
628         tracker = jgoogleanalyticstracker.getConstructor(new Class[]
629         { String.class, String.class, String.class }).newInstance(
630                 new Object[]
631                 {
632                     "Jalview Desktop",
633                     (vrs = jalview.bin.Cache.getProperty("VERSION")
634                             + "_"
635                             + jalview.bin.Cache.getDefault("BUILD_DATE",
636                                     "unknown")), "UA-9060947-1" });
637         jgoogleanalyticstracker.getMethod("trackAsynchronously",
638                 new Class[]
639                 { trackerfocus }).invoke(tracker, new Object[]
640         { trackerfocus.getConstructor(new Class[]
641         { String.class }).newInstance(new Object[]
642         { "Application Started." }) });
643       } catch (RuntimeException e)
644       {
645         re = e;
646       } catch (Exception e)
647       {
648         ex = e;
649       } catch (Error e)
650       {
651         err = e;
652       }
653       if (re != null || ex != null || err != null)
654       {
655         if (log != null)
656         {
657           if (re != null)
658             log.debug("Caught runtime exception in googletracker init:", re);
659           if (ex != null)
660             log.warn(
661                     "Failed to initialise GoogleTracker for Jalview Desktop with version "
662                             + vrs, ex);
663           if (err != null)
664             log.error(
665                     "Whilst initing GoogleTracker for Jalview Desktop version "
666                             + vrs, err);
667         }
668         else
669         {
670           if (re != null)
671           {
672             System.err
673                     .println("Debug: Caught runtime exception in googletracker init:"
674                             + vrs);
675             re.printStackTrace();
676           }
677           if (ex != null)
678           {
679             System.err
680                     .println("Warning:  Failed to initialise GoogleTracker for Jalview Desktop with version "
681                             + vrs);
682             ex.printStackTrace();
683           }
684
685           if (err != null)
686           {
687             System.err
688                     .println("ERROR: Whilst initing GoogleTracker for Jalview Desktop version "
689                             + vrs);
690             err.printStackTrace();
691           }
692         }
693       }
694       else
695       {
696         log.debug("Successfully initialised tracker.");
697       }
698     }
699   }
700
701   /**
702    * get the user's default colour if available
703    * @param property
704    * @param defcolour
705    * @return
706    */
707   public static Color getDefaultColour(String property, Color defcolour)
708   {
709     String colprop = getProperty(property);
710     if (colprop==null) {
711       return defcolour;
712     }
713     Color col = jalview.schemes.ColourSchemeProperty.getAWTColorFromName(colprop);
714     if (col==null)
715     {
716       try {
717         col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
718       } catch (Exception ex)
719       {
720         log.warn("Couldn't parse '"+colprop+"' as a colour for "+property);
721         col=null;
722       }
723     }
724     return (col==null) ? defcolour: col;
725   }
726
727   /**
728    * store a colour as a Jalview user default property
729    * @param property
730    * @param colour     
731    */
732   public static void setColourProperty(String property, Color colour)
733   {
734     setProperty(property, jalview.util.Format
735           .getHexString(colour));
736   }
737
738   public static final DateFormat  date_format = SimpleDateFormat.getDateTimeInstance();
739
740   /**
741    * store a date in a jalview property
742    * @param string
743    * @param time
744    */
745   public static void setDateProperty(String property, Date time)
746   {
747     setProperty(property, date_format.format(time));
748   }
749   /**
750    * read a date stored in a jalview property
751    * @param property
752    * @return valid date as stored by setDateProperty, or null
753    * 
754    */
755   public static Date getDateProperty(String property)
756   {
757     String val = getProperty(property);
758     if (val!=null)
759     {
760       try {
761         return date_format.parse(val);
762       } catch (Exception ex)
763       {
764         System.err.println("Invalid or corrupt date in property '"+property+"' : value was '"+val+"'");
765       }
766     }
767     return null;
768   }
769
770   /**
771    * get and parse a property as an integer. send any parsing problems to System.err
772    * @param property
773    * @return null or Integer
774    */
775   public static Integer getIntegerProperty(String property)
776   {
777     String val=getProperty(property);
778     if (val!=null && (val=val.trim()).length()>0)
779     {
780       try {
781         return Integer.valueOf(val);
782       } catch (NumberFormatException x)
783       {
784         System.err.println("Invalid integer in property '"+property+"' (value was '"+val+"')");
785       }
786     }
787     return null;
788   }
789
790   private static DasSourceRegistryI sourceRegistry=null;
791   /**
792    * initialise and ..
793    * @return instance of the das source registry
794    */
795   public static DasSourceRegistryI getDasSourceRegistry()
796   {
797     if (sourceRegistry==null)
798     {
799       sourceRegistry = new DasSourceRegistry();
800     }
801     return sourceRegistry;
802   }
803 }