Merge branch 'JAL-986_idwidthprefs' into develop
[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, J Engelhardt, LM Lui, 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>NORMALISE_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
128  * logo normalised to row height rather than histogram height.</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     // LOAD THE AUTHORS FROM THE authors.props file
286     try
287     {
288       String authorDetails = "jar:".concat(Cache.class.getProtectionDomain()
289               .getCodeSource().getLocation().toString()
290               .concat("!/authors.props"));
291
292       java.net.URL localJarFileURL = new java.net.URL(authorDetails);
293
294       InputStream in = localJarFileURL.openStream();
295       applicationProperties.load(in);
296       in.close();
297     } catch (Exception ex)
298     {
299       System.out.println("Error reading author details: " + ex);
300       applicationProperties.remove("AUTHORS");
301       applicationProperties.remove("AUTHORFNAMES");
302       applicationProperties.remove("YEAR");
303     }
304
305     // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar
306     // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE
307     // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW
308     try
309     {
310       String buildDetails = "jar:".concat(Cache.class.getProtectionDomain()
311               .getCodeSource().getLocation().toString()
312               .concat("!/.build_properties"));
313
314       java.net.URL localJarFileURL = new java.net.URL(buildDetails);
315
316       InputStream in = localJarFileURL.openStream();
317       applicationProperties.load(in);
318       in.close();
319     } catch (Exception ex)
320     {
321       System.out.println("Error reading build details: " + ex);
322       applicationProperties.remove("VERSION");
323     }
324
325     String jnlpVersion = System.getProperty("jalview.version");
326     String codeVersion = getProperty("VERSION");
327
328     if (codeVersion == null)
329     {
330       // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
331       codeVersion = "Test";
332       jnlpVersion = "Test";
333     }
334
335     System.out.println("Jalview Version: " + codeVersion);
336
337     // jnlpVersion will be null if we're using InstallAnywhere
338     // Dont do this check if running in headless mode
339     if (jnlpVersion == null
340             && getDefault("VERSION_CHECK", true)
341             && (System.getProperty("java.awt.headless") == null || System
342                     .getProperty("java.awt.headless").equals("false")))
343     {
344
345       class VersionChecker extends Thread
346       {
347         public void run()
348         {
349           String orgtimeout = System
350                   .getProperty("sun.net.client.defaultConnectTimeout");
351           if (orgtimeout == null)
352           {
353             orgtimeout = "30";
354             System.out.println("# INFO: Setting default net timeout to "
355                     + orgtimeout + " seconds.");
356           }
357           String jnlpVersion = null;
358           try
359           {
360             System.setProperty("sun.net.client.defaultConnectTimeout",
361                     "5000");
362             java.net.URL url = new java.net.URL(
363                     Cache.getDefault("www.jalview.org", "http://www.jalview.org")+"/webstart/jalview.jnlp");
364             BufferedReader in = new BufferedReader(new InputStreamReader(
365                     url.openStream()));
366             String line = null;
367             while ((line = in.readLine()) != null)
368             {
369               if (line.indexOf("jalview.version") == -1)
370               {
371                 continue;
372               }
373
374               line = line.substring(line.indexOf("value=") + 7);
375               line = line.substring(0, line.lastIndexOf("\""));
376               jnlpVersion = line;
377               break;
378             }
379           } catch (Exception ex)
380           {
381             System.out
382                     .println("Non-fatal exceptions when checking version at www.jalview.org :");
383             System.out.println(ex);
384             jnlpVersion = getProperty("VERSION");
385           }
386           System.setProperty("sun.net.client.defaultConnectTimeout",
387                   orgtimeout);
388
389           setProperty("LATEST_VERSION", jnlpVersion);
390         }
391       }
392
393       VersionChecker vc = new VersionChecker();
394       vc.start();
395     }
396     else
397     {
398       if (jnlpVersion != null)
399       {
400         setProperty("LATEST_VERSION", jnlpVersion);
401       }
402       else
403       {
404         applicationProperties.remove("LATEST_VERSION");
405       }
406     }
407
408     setProperty("VERSION", codeVersion);
409
410     // LOAD USERDEFINED COLOURS
411     jalview.gui.UserDefinedColours
412             .initUserColourSchemes(getProperty("USER_DEFINED_COLOURS"));
413     jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER",
414             false);
415   }
416
417   /**
418    * Gets Jalview application property of given key. Returns null if key not
419    * found
420    * 
421    * @param key
422    *          Name of property
423    * 
424    * @return Property value
425    */
426   public static String getProperty(String key)
427   {
428     return applicationProperties.getProperty(key);
429   }
430
431   /**
432    * These methods are used when checking if the saved preference is different
433    * to the default setting
434    */
435
436   public static boolean getDefault(String property, boolean def)
437   {
438     String string = getProperty(property);
439     if (string != null)
440     {
441       def = Boolean.valueOf(string).booleanValue();
442     }
443
444     return def;
445   }
446
447   /**
448    * These methods are used when checking if the saved preference is different
449    * to the default setting
450    */
451   public static String getDefault(String property, String def)
452   {
453     String string = getProperty(property);
454     if (string != null)
455     {
456       return string;
457     }
458
459     return def;
460   }
461
462   /**
463    * Stores property in the file "HOME_DIR/.jalview_properties"
464    * 
465    * @param key
466    *          Name of object
467    * @param obj
468    *          String value of property
469    * 
470    * @return String value of property
471    */
472   public static String setProperty(String key, String obj)
473   {
474
475     try
476     {
477       applicationProperties.setProperty(key, obj);
478       if (!propsAreReadOnly)
479       {
480         FileOutputStream out = new FileOutputStream(propertiesFile);
481         applicationProperties.store(out, "---JalviewX Properties File---");
482         out.close();
483       }
484     } catch (Exception ex)
485     {
486       System.out.println("Error setting property: " + key + " " + obj
487               + "\n" + ex);
488     }
489     return obj;
490   }
491
492   /**
493    * remove the specified property from the jalview properties file
494    * 
495    * @param string
496    */
497   public static void removeProperty(String string)
498   {
499     applicationProperties.remove(string);
500     saveProperties();
501   }
502
503   /**
504    * save the properties to the jalview properties path
505    */
506   public static void saveProperties()
507   {
508     if (!propsAreReadOnly)
509     {
510       try
511       {
512         FileOutputStream out = new FileOutputStream(propertiesFile);
513         applicationProperties.store(out, "---JalviewX Properties File---");
514         out.close();
515       } catch (Exception ex)
516       {
517         System.out.println("Error saving properties: " + ex);
518       }
519     }
520   }
521
522   /**
523    * internal vamsas class discovery state
524    */
525   private static int vamsasJarsArePresent = -1;
526
527   /**
528    * Searches for vamsas client classes on class path.
529    * 
530    * @return true if vamsas client is present on classpath
531    */
532   public static boolean vamsasJarsPresent()
533   {
534     if (vamsasJarsArePresent == -1)
535     {
536       try
537       {
538         if (jalview.jbgui.GDesktop.class.getClassLoader().loadClass(
539                 "uk.ac.vamsas.client.VorbaId") != null)
540         {
541           jalview.bin.Cache.log
542                   .debug("Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
543           vamsasJarsArePresent = 1;
544           Logger lvclient = Logger.getLogger("uk.ac.vamsas");
545           lvclient.setLevel(Level.toLevel(Cache.getDefault(
546                   "logs.Vamsas.Level", Level.INFO.toString())));
547
548           lvclient.addAppender(log.getAppender("JalviewLogger"));
549           // Tell the user that debug is enabled
550           lvclient.debug("Jalview Vamsas Client Debugging Output Follows.");
551         }
552       } catch (Exception e)
553       {
554         vamsasJarsArePresent = 0;
555         jalview.bin.Cache.log.debug("Vamsas Classes are not present");
556       }
557     }
558     return (vamsasJarsArePresent > 0);
559   }
560
561   /**
562    * internal vamsas class discovery state
563    */
564   private static int groovyJarsArePresent = -1;
565
566   /**
567    * Searches for vamsas client classes on class path.
568    * 
569    * @return true if vamsas client is present on classpath
570    */
571   public static boolean groovyJarsPresent()
572   {
573     if (groovyJarsArePresent == -1)
574     {
575       try
576       {
577         if (Cache.class.getClassLoader().loadClass(
578                 "groovy.lang.GroovyObject") != null)
579         {
580           jalview.bin.Cache.log
581                   .debug("Found Groovy (groovy.lang.GroovyObject can be loaded)");
582           groovyJarsArePresent = 1;
583           Logger lgclient = Logger.getLogger("groovy");
584           lgclient.setLevel(Level.toLevel(Cache.getDefault(
585                   "logs.Groovy.Level", Level.INFO.toString())));
586
587           lgclient.addAppender(log.getAppender("JalviewLogger"));
588           // Tell the user that debug is enabled
589           lgclient.debug("Jalview Groovy Client Debugging Output Follows.");
590         }
591       } catch (Error e)
592       {
593         groovyJarsArePresent = 0;
594         jalview.bin.Cache.log.debug("Groovy Classes are not present", e);
595       } catch (Exception e)
596       {
597         groovyJarsArePresent = 0;
598         jalview.bin.Cache.log.debug("Groovy Classes are not present");
599       }
600     }
601     return (groovyJarsArePresent > 0);
602   }
603
604   /**
605    * generate Das1Sources from the local das source list
606    * 
607    * @return Vector of Das1Sources
608    */
609   public static Vector getLocalDasSources()
610   {
611     Vector localSources = new Vector();
612     String local = jalview.bin.Cache.getProperty("DAS_LOCAL_SOURCE");
613     if (local != null)
614     {
615       StringTokenizer st = new StringTokenizer(local, "\t");
616       while (st.hasMoreTokens())
617       {
618         String token = st.nextToken();
619         int bar = token.indexOf("|");
620         Das1Source source = new Das1Source();
621         source.setUrl(token.substring(bar + 1));
622         if (source.getUrl().startsWith("sequence:"))
623         {
624           source.setUrl(source.getUrl().substring(9));
625           // this source also serves sequences as well as features
626           source.setCapabilities(new String[]
627           { "sequence", "features" });
628         }
629         else
630         {
631           // default is that all user added sources serve features
632           source.setCapabilities(new String[]
633           { "features" });
634         }
635
636         source.setNickname(token.substring(0, bar));
637
638         localSources.addElement(source);
639       }
640     }
641     return localSources;
642   }
643
644   /**
645    * GA tracker object - actually JGoogleAnalyticsTracker null if tracking not
646    * enabled.
647    */
648   protected static Object tracker = null;
649
650   protected static Class trackerfocus = null;
651
652   protected static Class jgoogleanalyticstracker = null;
653
654   /**
655    * Initialise the google tracker if it is not done already.
656    */
657   public static void initGoogleTracker()
658   {
659     if (tracker == null)
660     {
661       if (jgoogleanalyticstracker == null)
662       {
663         // try to get the tracker class
664         try
665         {
666           jgoogleanalyticstracker = Cache.class
667                   .getClassLoader()
668                   .loadClass(
669                           "com.boxysystems.jgoogleanalytics.JGoogleAnalyticsTracker");
670           trackerfocus = Cache.class.getClassLoader().loadClass(
671                   "com.boxysystems.jgoogleanalytics.FocusPoint");
672         } catch (Exception e)
673         {
674           log.debug("com.boxysystems.jgoogleanalytics package is not present - tracking not enabled.");
675           tracker = null;
676           jgoogleanalyticstracker = null;
677           trackerfocus = null;
678           return;
679         }
680       }
681       // now initialise tracker
682       Exception re = null, ex = null;
683       Error err = null;
684       String vrs = "No Version Accessible";
685       try
686       {
687         // Google analytics tracking code for Library Finder
688         tracker = jgoogleanalyticstracker.getConstructor(new Class[]
689         { String.class, String.class, String.class }).newInstance(
690                 new Object[]
691                 {
692                     "Jalview Desktop",
693                     (vrs = jalview.bin.Cache.getProperty("VERSION")
694                             + "_"
695                             + jalview.bin.Cache.getDefault("BUILD_DATE",
696                                     "unknown")), "UA-9060947-1" });
697         jgoogleanalyticstracker.getMethod("trackAsynchronously",
698                 new Class[]
699                 { trackerfocus }).invoke(tracker, new Object[]
700         { trackerfocus.getConstructor(new Class[]
701         { String.class }).newInstance(new Object[]
702         { "Application Started." }) });
703       } catch (RuntimeException e)
704       {
705         re = e;
706       } catch (Exception e)
707       {
708         ex = e;
709       } catch (Error e)
710       {
711         err = e;
712       }
713       if (re != null || ex != null || err != null)
714       {
715         if (log != null)
716         {
717           if (re != null)
718             log.debug("Caught runtime exception in googletracker init:", re);
719           if (ex != null)
720             log.warn(
721                     "Failed to initialise GoogleTracker for Jalview Desktop with version "
722                             + vrs, ex);
723           if (err != null)
724             log.error(
725                     "Whilst initing GoogleTracker for Jalview Desktop version "
726                             + vrs, err);
727         }
728         else
729         {
730           if (re != null)
731           {
732             System.err
733                     .println("Debug: Caught runtime exception in googletracker init:"
734                             + vrs);
735             re.printStackTrace();
736           }
737           if (ex != null)
738           {
739             System.err
740                     .println("Warning:  Failed to initialise GoogleTracker for Jalview Desktop with version "
741                             + vrs);
742             ex.printStackTrace();
743           }
744
745           if (err != null)
746           {
747             System.err
748                     .println("ERROR: Whilst initing GoogleTracker for Jalview Desktop version "
749                             + vrs);
750             err.printStackTrace();
751           }
752         }
753       }
754       else
755       {
756         log.debug("Successfully initialised tracker.");
757       }
758     }
759   }
760
761   /**
762    * get the user's default colour if available
763    * @param property
764    * @param defcolour
765    * @return
766    */
767   public static Color getDefaultColour(String property, Color defcolour)
768   {
769     String colprop = getProperty(property);
770     if (colprop==null) {
771       return defcolour;
772     }
773     Color col = jalview.schemes.ColourSchemeProperty.getAWTColorFromName(colprop);
774     if (col==null)
775     {
776       try {
777         col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
778       } catch (Exception ex)
779       {
780         log.warn("Couldn't parse '"+colprop+"' as a colour for "+property);
781         col=null;
782       }
783     }
784     return (col==null) ? defcolour: col;
785   }
786
787   /**
788    * store a colour as a Jalview user default property
789    * @param property
790    * @param colour     
791    */
792   public static void setColourProperty(String property, Color colour)
793   {
794     setProperty(property, jalview.util.Format
795           .getHexString(colour));
796   }
797
798   public static final DateFormat  date_format = SimpleDateFormat.getDateTimeInstance();
799
800   /**
801    * store a date in a jalview property
802    * @param string
803    * @param time
804    */
805   public static void setDateProperty(String property, Date time)
806   {
807     setProperty(property, date_format.format(time));
808   }
809   /**
810    * read a date stored in a jalview property
811    * @param property
812    * @return valid date as stored by setDateProperty, or null
813    * 
814    */
815   public static Date getDateProperty(String property)
816   {
817     String val = getProperty(property);
818     if (val!=null)
819     {
820       try {
821         return date_format.parse(val);
822       } catch (Exception ex)
823       {
824         System.err.println("Invalid or corrupt date in property '"+property+"' : value was '"+val+"'");
825       }
826     }
827     return null;
828   }
829
830   /**
831    * get and parse a property as an integer. send any parsing problems to System.err
832    * @param property
833    * @return null or Integer
834    */
835   public static Integer getIntegerProperty(String property)
836   {
837     String val=getProperty(property);
838     if (val!=null && (val=val.trim()).length()>0)
839     {
840       try {
841         return Integer.valueOf(val);
842       } catch (NumberFormatException x)
843       {
844         System.err.println("Invalid integer in property '"+property+"' (value was '"+val+"')");
845       }
846     }
847     return null;
848   }
849 }