ba1d0a848a75883a8dcbc01c2508df8f81e99660
[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</li>
145  * <li>ENABLE_RSBS_EDITOR (false for 2.7 release) enable or disable RSBS editing panel in web service preferences</li> 
146  * </ul>
147  * @author $author$
148  * @version $Revision$
149  */
150 public class Cache
151 {
152   /**
153    * property giving log4j level for CASTOR loggers
154    */
155   public static final String CASTORLOGLEVEL = "logs.Castor.level";
156
157   /**
158    * property giving log4j level for AXIS loggers
159    */
160   public static final String AXISLOGLEVEL = "logs.Axis.level";
161
162   /**
163    * property giving log4j level for Jalview Log
164    */
165   public static final String JALVIEWLOGLEVEL = "logs.Jalview.level";
166
167   public static final String DAS_LOCAL_SOURCE = "DAS_LOCAL_SOURCE";
168
169   public static final String DAS_REGISTRY_URL = "DAS_REGISTRY_URL";
170
171   public static final String DAS_ACTIVE_SOURCE = "DAS_ACTIVE_SOURCE";
172
173   /**
174    * Initialises the Jalview Application Log
175    */
176   public static Logger log;
177
178   /** Jalview Properties */
179   public static Properties applicationProperties = new Properties();
180
181   /** Default file is ~/.jalview_properties */
182   static String propertiesFile;
183
184   private static boolean propsAreReadOnly=false;
185
186   public static void initLogger()
187   {
188     if (log != null)
189     {
190       return;
191     }
192     try
193     {
194       // TODO: redirect stdout and stderr here in order to grab the output of
195       // the log
196
197       ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(),
198               "System.err");
199       ap.setName("JalviewLogger");
200       org.apache.log4j.Logger.getRootLogger().addAppender(ap); // catch all for
201       // log output
202       Logger laxis = Logger.getLogger("org.apache.axis");
203       Logger lcastor = Logger.getLogger("org.exolab.castor");
204       jalview.bin.Cache.log = Logger.getLogger("jalview.bin.Jalview");
205
206       laxis.setLevel(Level.toLevel(Cache.getDefault("logs.Axis.Level",
207               Level.INFO.toString())));
208       lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
209               Level.INFO.toString())));
210       lcastor = Logger.getLogger("org.exolab.castor.xml");
211       lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
212               Level.INFO.toString())));
213       // lcastor = Logger.getLogger("org.exolab.castor.xml.Marshaller");
214       // lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
215       // Level.INFO.toString())));
216       jalview.bin.Cache.log.setLevel(Level.toLevel(Cache.getDefault(
217               "logs.Jalview.level", Level.INFO.toString())));
218       // laxis.addAppender(ap);
219       // lcastor.addAppender(ap);
220       // jalview.bin.Cache.log.addAppender(ap);
221       // Tell the user that debug is enabled
222       jalview.bin.Cache.log.debug("Jalview Debugging Output Follows.");
223     } catch (Exception ex)
224     {
225       System.err.println("Problems initializing the log4j system\n");
226       ex.printStackTrace(System.err);
227     }
228   }
229
230   /** Called when Jalview is started */
231   public static void loadProperties(String propsFile)
232   {
233     propertiesFile = propsFile;
234     if (propsFile == null)
235     {
236       propertiesFile = System.getProperty("user.home") + File.separatorChar
237               + ".jalview_properties";
238     } else {
239       // don't corrupt the file we've been given.
240       propsAreReadOnly = true;
241     }
242
243     try
244     {
245       InputStream fis;
246       try
247       {
248         fis = new java.net.URL(propertiesFile).openStream();
249         System.out.println("Loading jalview properties from : "
250                 + propertiesFile);
251         System.out
252                 .println("Disabling Jalview writing to user's local properties file.");
253         propsAreReadOnly = true;
254
255       } catch (Exception ex)
256       {
257         fis = null;
258       }
259       if (fis == null)
260       {
261         fis = new FileInputStream(propertiesFile);
262       }
263       applicationProperties.load(fis);
264       applicationProperties.remove("LATEST_VERSION");
265       applicationProperties.remove("VERSION");
266       fis.close();
267     } catch (Exception ex)
268     {
269       System.out.println("Error reading properties file: " + ex);
270     }
271
272     if (getDefault("USE_PROXY", false))
273     {
274       System.out.println("Using proxyServer: "
275               + getDefault("PROXY_SERVER", null) + " proxyPort: "
276               + getDefault("PROXY_PORT", null));
277       System.setProperty("http.proxyHost", getDefault("PROXY_SERVER", null));
278       System.setProperty("http.proxyPort", getDefault("PROXY_PORT", null));
279     }
280
281     // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar
282     // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE
283     // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW
284     try
285     {
286       String buildDetails = "jar:".concat(Cache.class.getProtectionDomain()
287               .getCodeSource().getLocation().toString()
288               .concat("!/.build_properties"));
289
290       java.net.URL localJarFileURL = new java.net.URL(buildDetails);
291
292       InputStream in = localJarFileURL.openStream();
293       applicationProperties.load(in);
294       in.close();
295     } catch (Exception ex)
296     {
297       System.out.println("Error reading build details: " + ex);
298       applicationProperties.remove("VERSION");
299     }
300
301     String jnlpVersion = System.getProperty("jalview.version");
302     String codeVersion = getProperty("VERSION");
303
304     if (codeVersion == null)
305     {
306       // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
307       codeVersion = "Test";
308       jnlpVersion = "Test";
309     }
310
311     System.out.println("Jalview Version: " + codeVersion);
312
313     // jnlpVersion will be null if we're using InstallAnywhere
314     // Dont do this check if running in headless mode
315     if (jnlpVersion == null
316             && getDefault("VERSION_CHECK", true)
317             && (System.getProperty("java.awt.headless") == null || System
318                     .getProperty("java.awt.headless").equals("false")))
319     {
320
321       class VersionChecker extends Thread
322       {
323         public void run()
324         {
325           String orgtimeout = System
326                   .getProperty("sun.net.client.defaultConnectTimeout");
327           if (orgtimeout == null)
328           {
329             orgtimeout = "30";
330             System.out.println("# INFO: Setting default net timeout to "
331                     + orgtimeout + " seconds.");
332           }
333           String jnlpVersion = null;
334           try
335           {
336             System.setProperty("sun.net.client.defaultConnectTimeout",
337                     "5000");
338             java.net.URL url = new java.net.URL(
339                     Cache.getDefault("www.jalview.org", "http://www.jalview.org")+"/webstart/jalview.jnlp");
340             BufferedReader in = new BufferedReader(new InputStreamReader(
341                     url.openStream()));
342             String line = null;
343             while ((line = in.readLine()) != null)
344             {
345               if (line.indexOf("jalview.version") == -1)
346               {
347                 continue;
348               }
349
350               line = line.substring(line.indexOf("value=") + 7);
351               line = line.substring(0, line.lastIndexOf("\""));
352               jnlpVersion = line;
353               break;
354             }
355           } catch (Exception ex)
356           {
357             System.out
358                     .println("Non-fatal exceptions when checking version at www.jalview.org :");
359             System.out.println(ex);
360             jnlpVersion = getProperty("VERSION");
361           }
362           System.setProperty("sun.net.client.defaultConnectTimeout",
363                   orgtimeout);
364
365           setProperty("LATEST_VERSION", jnlpVersion);
366         }
367       }
368
369       VersionChecker vc = new VersionChecker();
370       vc.start();
371     }
372     else
373     {
374       if (jnlpVersion != null)
375       {
376         setProperty("LATEST_VERSION", jnlpVersion);
377       }
378       else
379       {
380         applicationProperties.remove("LATEST_VERSION");
381       }
382     }
383
384     setProperty("VERSION", codeVersion);
385
386     // LOAD USERDEFINED COLOURS
387     jalview.gui.UserDefinedColours
388             .initUserColourSchemes(getProperty("USER_DEFINED_COLOURS"));
389     jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER",
390             false);
391   }
392
393   /**
394    * Gets Jalview application property of given key. Returns null if key not
395    * found
396    * 
397    * @param key
398    *          Name of property
399    * 
400    * @return Property value
401    */
402   public static String getProperty(String key)
403   {
404     return applicationProperties.getProperty(key);
405   }
406
407   /**
408    * These methods are used when checking if the saved preference is different
409    * to the default setting
410    */
411
412   public static boolean getDefault(String property, boolean def)
413   {
414     String string = getProperty(property);
415     if (string != null)
416     {
417       def = Boolean.valueOf(string).booleanValue();
418     }
419
420     return def;
421   }
422
423   /**
424    * These methods are used when checking if the saved preference is different
425    * to the default setting
426    */
427   public static String getDefault(String property, String def)
428   {
429     String string = getProperty(property);
430     if (string != null)
431     {
432       return string;
433     }
434
435     return def;
436   }
437
438   /**
439    * Stores property in the file "HOME_DIR/.jalview_properties"
440    * 
441    * @param key
442    *          Name of object
443    * @param obj
444    *          String value of property
445    * 
446    * @return String value of property
447    */
448   public static String setProperty(String key, String obj)
449   {
450
451     try
452     {
453       applicationProperties.setProperty(key, obj);
454       if (!propsAreReadOnly)
455       {
456         FileOutputStream out = new FileOutputStream(propertiesFile);
457         applicationProperties.store(out, "---JalviewX Properties File---");
458         out.close();
459       }
460     } catch (Exception ex)
461     {
462       System.out.println("Error setting property: " + key + " " + obj
463               + "\n" + ex);
464     }
465     return obj;
466   }
467
468   /**
469    * remove the specified property from the jalview properties file
470    * 
471    * @param string
472    */
473   public static void removeProperty(String string)
474   {
475     applicationProperties.remove(string);
476     saveProperties();
477   }
478
479   /**
480    * save the properties to the jalview properties path
481    */
482   public static void saveProperties()
483   {
484     if (!propsAreReadOnly)
485     {
486       try
487       {
488         FileOutputStream out = new FileOutputStream(propertiesFile);
489         applicationProperties.store(out, "---JalviewX Properties File---");
490         out.close();
491       } catch (Exception ex)
492       {
493         System.out.println("Error saving properties: " + ex);
494       }
495     }
496   }
497
498   /**
499    * internal vamsas class discovery state
500    */
501   private static int vamsasJarsArePresent = -1;
502
503   /**
504    * Searches for vamsas client classes on class path.
505    * 
506    * @return true if vamsas client is present on classpath
507    */
508   public static boolean vamsasJarsPresent()
509   {
510     if (vamsasJarsArePresent == -1)
511     {
512       try
513       {
514         if (jalview.jbgui.GDesktop.class.getClassLoader().loadClass(
515                 "uk.ac.vamsas.client.VorbaId") != null)
516         {
517           jalview.bin.Cache.log
518                   .debug("Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
519           vamsasJarsArePresent = 1;
520           Logger lvclient = Logger.getLogger("uk.ac.vamsas");
521           lvclient.setLevel(Level.toLevel(Cache.getDefault(
522                   "logs.Vamsas.Level", Level.INFO.toString())));
523
524           lvclient.addAppender(log.getAppender("JalviewLogger"));
525           // Tell the user that debug is enabled
526           lvclient.debug("Jalview Vamsas Client Debugging Output Follows.");
527         }
528       } catch (Exception e)
529       {
530         vamsasJarsArePresent = 0;
531         jalview.bin.Cache.log.debug("Vamsas Classes are not present");
532       }
533     }
534     return (vamsasJarsArePresent > 0);
535   }
536
537   /**
538    * internal vamsas class discovery state
539    */
540   private static int groovyJarsArePresent = -1;
541
542   /**
543    * Searches for vamsas client classes on class path.
544    * 
545    * @return true if vamsas client is present on classpath
546    */
547   public static boolean groovyJarsPresent()
548   {
549     if (groovyJarsArePresent == -1)
550     {
551       try
552       {
553         if (Cache.class.getClassLoader().loadClass(
554                 "groovy.lang.GroovyObject") != null)
555         {
556           jalview.bin.Cache.log
557                   .debug("Found Groovy (groovy.lang.GroovyObject can be loaded)");
558           groovyJarsArePresent = 1;
559           Logger lgclient = Logger.getLogger("groovy");
560           lgclient.setLevel(Level.toLevel(Cache.getDefault(
561                   "logs.Groovy.Level", Level.INFO.toString())));
562
563           lgclient.addAppender(log.getAppender("JalviewLogger"));
564           // Tell the user that debug is enabled
565           lgclient.debug("Jalview Groovy Client Debugging Output Follows.");
566         }
567       } catch (Error e)
568       {
569         groovyJarsArePresent = 0;
570         jalview.bin.Cache.log.debug("Groovy Classes are not present", e);
571       } catch (Exception e)
572       {
573         groovyJarsArePresent = 0;
574         jalview.bin.Cache.log.debug("Groovy Classes are not present");
575       }
576     }
577     return (groovyJarsArePresent > 0);
578   }
579
580   /**
581    * generate Das1Sources from the local das source list
582    * 
583    * @return Vector of Das1Sources
584    */
585   public static Vector getLocalDasSources()
586   {
587     Vector localSources = new Vector();
588     String local = jalview.bin.Cache.getProperty("DAS_LOCAL_SOURCE");
589     if (local != null)
590     {
591       StringTokenizer st = new StringTokenizer(local, "\t");
592       while (st.hasMoreTokens())
593       {
594         String token = st.nextToken();
595         int bar = token.indexOf("|");
596         Das1Source source = new Das1Source();
597         source.setUrl(token.substring(bar + 1));
598         if (source.getUrl().startsWith("sequence:"))
599         {
600           source.setUrl(source.getUrl().substring(9));
601           // this source also serves sequences as well as features
602           source.setCapabilities(new String[]
603           { "sequence", "features" });
604         }
605         else
606         {
607           // default is that all user added sources serve features
608           source.setCapabilities(new String[]
609           { "features" });
610         }
611
612         source.setNickname(token.substring(0, bar));
613
614         localSources.addElement(source);
615       }
616     }
617     return localSources;
618   }
619
620   /**
621    * GA tracker object - actually JGoogleAnalyticsTracker null if tracking not
622    * enabled.
623    */
624   protected static Object tracker = null;
625
626   protected static Class trackerfocus = null;
627
628   protected static Class jgoogleanalyticstracker = null;
629
630   /**
631    * Initialise the google tracker if it is not done already.
632    */
633   public static void initGoogleTracker()
634   {
635     if (tracker == null)
636     {
637       if (jgoogleanalyticstracker == null)
638       {
639         // try to get the tracker class
640         try
641         {
642           jgoogleanalyticstracker = Cache.class
643                   .getClassLoader()
644                   .loadClass(
645                           "com.boxysystems.jgoogleanalytics.JGoogleAnalyticsTracker");
646           trackerfocus = Cache.class.getClassLoader().loadClass(
647                   "com.boxysystems.jgoogleanalytics.FocusPoint");
648         } catch (Exception e)
649         {
650           log.debug("com.boxysystems.jgoogleanalytics package is not present - tracking not enabled.");
651           tracker = null;
652           jgoogleanalyticstracker = null;
653           trackerfocus = null;
654           return;
655         }
656       }
657       // now initialise tracker
658       Exception re = null, ex = null;
659       Error err = null;
660       String vrs = "No Version Accessible";
661       try
662       {
663         // Google analytics tracking code for Library Finder
664         tracker = jgoogleanalyticstracker.getConstructor(new Class[]
665         { String.class, String.class, String.class }).newInstance(
666                 new Object[]
667                 {
668                     "Jalview Desktop",
669                     (vrs = jalview.bin.Cache.getProperty("VERSION")
670                             + "_"
671                             + jalview.bin.Cache.getDefault("BUILD_DATE",
672                                     "unknown")), "UA-9060947-1" });
673         jgoogleanalyticstracker.getMethod("trackAsynchronously",
674                 new Class[]
675                 { trackerfocus }).invoke(tracker, new Object[]
676         { trackerfocus.getConstructor(new Class[]
677         { String.class }).newInstance(new Object[]
678         { "Application Started." }) });
679       } catch (RuntimeException e)
680       {
681         re = e;
682       } catch (Exception e)
683       {
684         ex = e;
685       } catch (Error e)
686       {
687         err = e;
688       }
689       if (re != null || ex != null || err != null)
690       {
691         if (log != null)
692         {
693           if (re != null)
694             log.debug("Caught runtime exception in googletracker init:", re);
695           if (ex != null)
696             log.warn(
697                     "Failed to initialise GoogleTracker for Jalview Desktop with version "
698                             + vrs, ex);
699           if (err != null)
700             log.error(
701                     "Whilst initing GoogleTracker for Jalview Desktop version "
702                             + vrs, err);
703         }
704         else
705         {
706           if (re != null)
707           {
708             System.err
709                     .println("Debug: Caught runtime exception in googletracker init:"
710                             + vrs);
711             re.printStackTrace();
712           }
713           if (ex != null)
714           {
715             System.err
716                     .println("Warning:  Failed to initialise GoogleTracker for Jalview Desktop with version "
717                             + vrs);
718             ex.printStackTrace();
719           }
720
721           if (err != null)
722           {
723             System.err
724                     .println("ERROR: Whilst initing GoogleTracker for Jalview Desktop version "
725                             + vrs);
726             err.printStackTrace();
727           }
728         }
729       }
730       else
731       {
732         log.debug("Successfully initialised tracker.");
733       }
734     }
735   }
736
737   /**
738    * get the user's default colour if available
739    * @param property
740    * @param defcolour
741    * @return
742    */
743   public static Color getDefaultColour(String property, Color defcolour)
744   {
745     String colprop = getProperty(property);
746     if (colprop==null) {
747       return defcolour;
748     }
749     Color col = jalview.schemes.ColourSchemeProperty.getAWTColorFromName(colprop);
750     if (col==null)
751     {
752       try {
753         col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
754       } catch (Exception ex)
755       {
756         log.warn("Couldn't parse '"+colprop+"' as a colour for "+property);
757         col=null;
758       }
759     }
760     return (col==null) ? defcolour: col;
761   }
762
763   /**
764    * store a colour as a Jalview user default property
765    * @param property
766    * @param colour     
767    */
768   public static void setColourProperty(String property, Color colour)
769   {
770     setProperty(property, jalview.util.Format
771           .getHexString(colour));
772   }
773
774   public static final DateFormat  date_format = SimpleDateFormat.getDateTimeInstance();
775
776   /**
777    * store a date in a jalview property
778    * @param string
779    * @param time
780    */
781   public static void setDateProperty(String property, Date time)
782   {
783     setProperty(property, date_format.format(time));
784   }
785   /**
786    * read a date stored in a jalview property
787    * @param property
788    * @return valid date as stored by setDateProperty, or null
789    * 
790    */
791   public static Date getDateProperty(String property)
792   {
793     String val = getProperty(property);
794     if (val!=null)
795     {
796       try {
797         return date_format.parse(val);
798       } catch (Exception ex)
799       {
800         System.err.println("Invalid or corrupt date in property '"+property+"' : value was '"+val+"'");
801       }
802     }
803     return null;
804   }
805 }