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