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