2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.structure.StructureImportSettings;
24 import jalview.ws.dbsources.das.api.DasSourceRegistryI;
25 import jalview.ws.dbsources.das.datamodel.DasSourceRegistry;
26 import jalview.ws.sifts.SiftsSettings;
28 import java.awt.Color;
29 import java.io.BufferedReader;
31 import java.io.FileInputStream;
32 import java.io.FileOutputStream;
33 import java.io.InputStream;
34 import java.io.InputStreamReader;
35 import java.text.DateFormat;
36 import java.text.SimpleDateFormat;
37 import java.util.Collections;
38 import java.util.Date;
39 import java.util.Enumeration;
40 import java.util.Properties;
41 import java.util.TreeSet;
43 import org.apache.log4j.ConsoleAppender;
44 import org.apache.log4j.Level;
45 import org.apache.log4j.Logger;
46 import org.apache.log4j.SimpleLayout;
49 * Stores and retrieves Jalview Application Properties Lists and fields within
50 * list entries are separated by '|' symbols unless otherwise stated (|) clauses
51 * are alternative values for a tag. <br>
53 * Current properties include:
56 * logs.Axis.Level - one of the stringified Levels for log4j controlling the
57 * logging level for axis (used for web services) <br>
59 * <li>logs.Castor.Level - one of the stringified Levels for log4j controlling
60 * the logging level for castor (used for serialization) <br>
62 * <li>logs.Jalview.Level - Cache.log stringified level. <br>
64 * <li>SCREEN_WIDTH</li>
65 * <li>SCREEN_HEIGHT</li>
66 * <li>SCREEN_Y=285</li>
67 * <li>SCREEN_X=371</li>
68 * <li>SHOW_FULLSCREEN boolean</li>
69 * <li>FONT_NAME java font name for alignment text display</li>
70 * <li>FONT_SIZE size of displayed alignment text</li>
71 * <li>FONT_STYLE style of font displayed (sequence labels are always italic)</li>
72 * <li>GAP_SYMBOL character to treat as gap symbol (usually -,.,' ')</li>
73 * <li>LAST_DIRECTORY last directory for browsing alignment</li>
74 * <li>USER_DEFINED_COLOURS list of user defined colour scheme files</li>
75 * <li>SHOW_FULL_ID show id with '/start-end' numbers appended</li>
76 * <li>SHOW_IDENTITY show percentage identity annotation</li>
77 * <li>SHOW_QUALITY show alignment quality annotation</li>
78 * <li>SHOW_ANNOTATIONS show alignment annotation rows</li>
79 * <li>SHOW_CONSERVATION show alignment conservation annotation</li>
80 * <li>SORT_ANNOTATIONS currently either SEQUENCE_AND_LABEL or
81 * LABEL_AND_SEQUENCE</li>
82 * <li>SHOW_AUTOCALC_ABOVE true to show autocalculated annotations above
83 * sequence annotations</li>
84 * <li>CENTRE_COLUMN_LABELS centre the labels at each column in a displayed
86 * <li>DEFAULT_COLOUR default colour scheme to apply for a new alignment</li>
87 * <li>DEFAULT_FILE_FORMAT file format used to save</li>
88 * <li>STARTUP_FILE file loaded on startup (may be a fully qualified url)</li>
89 * <li>SHOW_STARTUP_FILE flag to control loading of startup file</li>
90 * <li>VERSION the version of the jalview build</li>
91 * <li>BUILD_DATE date of this build</li>
92 * <li>LATEST_VERSION the latest jalview version advertised on the
93 * www.jalview.org</li>
94 * <li>PIR_MODELLER boolean indicating if PIR files are written with MODELLER
96 * <li>(FASTA,MSF,PILEUP,CLUSTAL,BLC,PIR,PFAM)_JVSUFFIX boolean for adding jv
98 * <li>RECENT_URL list of recently retrieved URLs</li>
99 * <li>RECENT_FILE list of recently opened files</li>
100 * <li>USE_PROXY flag for whether a http proxy is to be used</li>
101 * <li>PROXY_SERVER the proxy</li>
102 * <li>PROXY_PORT</li>
103 * <li>NOQUESTIONNAIRES true to prevent jalview from checking the questionnaire
105 * <li>QUESTIONNAIRE last questionnaire:responder id string from questionnaire
107 * <li>USAGESTATS (false - user prompted) Enable google analytics tracker for
108 * collecting usage statistics</li>
109 * <li>DAS_LOCAL_SOURCE list of local das sources</li>
110 * <li>SHOW_OVERVIEW boolean for overview window display</li>
111 * <li>ANTI_ALIAS boolean for smooth fonts</li>
112 * <li>RIGHT_ALIGN_IDS boolean</li>
113 * <li>AUTO_CALC_CONSENSUS boolean for automatic recalculation of consensus</li>
114 * <li>PAD_GAPS boolean</li>
115 * <li>ID_ITALICS boolean</li>
116 * <li>SHOW_JV_SUFFIX</li>
117 * <li>WRAP_ALIGNMENT</li>
118 * <li>EPS_RENDERING (Prompt each time|Lineart|Text) default for EPS rendering
120 * <li>SORT_ALIGNMENT (No sort|Id|Pairwise Identity)</li>
121 * <li>SEQUENCE_LINKS list of name|URL pairs for opening a url with
123 * <li>GROUP_LINKS list of name|URL[|<separator>] tuples - see
124 * jalview.utils.GroupURLLink for more info</li>
125 * <li>DAS_REGISTRY_URL the registry to query</li>
126 * <li>DEFAULT_BROWSER for unix</li>
127 * <li>DAS_ACTIVE_SOURCE list of active sources</li>
128 * <li>SHOW_MEMUSAGE boolean show memory usage and warning indicator on desktop
130 * <li>VERSION_CHECK (true) check for the latest release version from
131 * www.jalview.org (or the alias given by the www.jalview.org property)</li>
132 * <li>SHOW_NPFEATS_TOOLTIP (true) show non-positional features in the Sequence
134 * <li>SHOW_DBREFS_TOOLTIP (true) show Database Cross References in the Sequence
136 * <li>SHOW_UNCONSERVED (false) only render unconserved residues - conserved
137 * displayed as '.'</li>
138 * <li>SORT_BY_TREE (false) sort the current alignment view according to the
139 * order of a newly displayed tree</li>
140 * <li>DBFETCH_USEPICR (false) use PICR to recover valid DB references from
141 * sequence ID strings before attempting retrieval from any datasource</li>
142 * <li>SHOW_GROUP_CONSENSUS (false) Show consensus annotation for groups in the
144 * <li>SHOW_GROUP_CONSERVATION (false) Show conservation annotation for groups
145 * in the alignment.</li>
146 * <li>SHOW_CONSENSUS_HISTOGRAM (false) Show consensus annotation row's
148 * <li>SHOW_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
150 * <li>NORMALISE_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
151 * logo normalised to row height rather than histogram height.</li>
152 * <li>FOLLOW_SELECTIONS (true) Controls whether a new alignment view should
153 * respond to selections made in other alignments containing the same sequences.
155 * <li>JWS2HOSTURLS comma-separated list of URLs to try for JABAWS services</li>
156 * <li>SHOW_WSDISCOVERY_ERRORS (true) Controls if the web service URL discovery
157 * warning dialog box is displayed.</li>
158 * <li>ANNOTATIONCOLOUR_MIN (orange) Shade used for minimum value of annotation
159 * when shading by annotation</li>
160 * <li>ANNOTATIONCOLOUR_MAX (red) Shade used for maximum value of annotation
161 * when shading by annotation</li>
162 * <li>www.jalview.org (http://www.jalview.org) a property enabling all HTTP
163 * requests to be redirected to a mirror of http://www.jalview.org</li>
164 * <li>FIGURE_AUTOIDWIDTH (false) Expand the left hand column of an exported
165 * alignment figure to accommodate even the longest sequence ID or annotation
167 * <li>FIGURE_FIXEDIDWIDTH Specifies the width to use for the left-hand column
168 * when exporting an alignment as a figure (setting FIGURE_AUTOIDWIDTH to true
169 * will override this).</li>
170 * <li>STRUCT_FROM_PDB (false) derive secondary structure annotation from PDB
172 * <li>USE_RNAVIEW (false) use RNAViewer to derive secondary structure</li>
173 * <li>ADD_SS_ANN (false) add secondary structure annotation to alignment
175 * <li>ADD_TEMPFACT_ANN (false) add Temperature Factor annotation to alignment
177 * <li>STRUCTURE_DISPLAY choose from JMOL (default) or CHIMERA for 3D structure
179 * <li>CHIMERA_PATH specify full path to Chimera program (if non-standard)</li>
182 * Deprecated settings:
185 * <li>DISCOVERY_START - Boolean - controls if discovery services are queried on
186 * startup (JWS1 services only)</li>
187 * <li>DISCOVERY_URLS - comma separated list of Discovery Service endpoints.
188 * (JWS1 services only)</li>
189 * <li>SHOW_JWS1_SERVICES (true) enable or disable the original Jalview 2
190 * services in the desktop GUI</li>
191 * <li>ENABLE_RSBS_EDITOR (false for 2.7 release) enable or disable RSBS editing
192 * panel in web service preferences</li>
196 * @version $Revision$
201 * property giving log4j level for CASTOR loggers
203 public static final String CASTORLOGLEVEL = "logs.Castor.level";
206 * property giving log4j level for AXIS loggers
208 public static final String AXISLOGLEVEL = "logs.Axis.level";
211 * property giving log4j level for Jalview Log
213 public static final String JALVIEWLOGLEVEL = "logs.Jalview.level";
215 public static final String DAS_LOCAL_SOURCE = "DAS_LOCAL_SOURCE";
217 public static final String DAS_REGISTRY_URL = "DAS_REGISTRY_URL";
219 public static final String DAS_ACTIVE_SOURCE = "DAS_ACTIVE_SOURCE";
221 public static final String DEFAULT_SIFTS_DOWNLOAD_DIR = System
222 .getProperty("user.home")
224 + ".sifts_downloads" + File.separatorChar;
226 private final static String DEFAULT_CACHE_THRESHOLD_IN_DAYS = "2";
228 private final static String DEFAULT_FAIL_SAFE_PID_THRESHOLD = "30";
230 private final static String DEFAULT_STRUCTURE_FORMAT = StructureImportSettings.MMCIF;
232 private final static String DEFAULT_PDB_FILE_PARSER = StructureImportSettings.JMOL_PARSER;
235 * Initialises the Jalview Application Log
237 public static Logger log;
239 /** Jalview Properties */
240 public static Properties applicationProperties = new Properties()
242 // override results in properties output in alphabetical order
244 public synchronized Enumeration<Object> keys()
246 return Collections.enumeration(new TreeSet<Object>(super.keySet()));
250 /** Default file is ~/.jalview_properties */
251 static String propertiesFile;
253 private static boolean propsAreReadOnly = false;
255 public static void initLogger()
263 // TODO: redirect stdout and stderr here in order to grab the output of
266 ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(),
268 ap.setName("JalviewLogger");
269 org.apache.log4j.Logger.getRootLogger().addAppender(ap); // catch all for
271 Logger laxis = Logger.getLogger("org.apache.axis");
272 Logger lcastor = Logger.getLogger("org.exolab.castor");
273 jalview.bin.Cache.log = Logger.getLogger("jalview.bin.Jalview");
275 laxis.setLevel(Level.toLevel(Cache.getDefault("logs.Axis.Level",
276 Level.INFO.toString())));
277 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
278 Level.INFO.toString())));
279 lcastor = Logger.getLogger("org.exolab.castor.xml");
280 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
281 Level.INFO.toString())));
282 // lcastor = Logger.getLogger("org.exolab.castor.xml.Marshaller");
283 // lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
284 // Level.INFO.toString())));
285 jalview.bin.Cache.log.setLevel(Level.toLevel(Cache.getDefault(
286 "logs.Jalview.level", Level.INFO.toString())));
287 // laxis.addAppender(ap);
288 // lcastor.addAppender(ap);
289 // jalview.bin.Cache.log.addAppender(ap);
290 // Tell the user that debug is enabled
291 jalview.bin.Cache.log.debug("Jalview Debugging Output Follows.");
292 } catch (Exception ex)
294 System.err.println("Problems initializing the log4j system\n");
295 ex.printStackTrace(System.err);
299 /** Called when Jalview is started */
300 public static void loadProperties(String propsFile)
302 propertiesFile = propsFile;
303 if (propsFile == null)
305 propertiesFile = System.getProperty("user.home") + File.separatorChar
306 + ".jalview_properties";
310 // don't corrupt the file we've been given.
311 propsAreReadOnly = true;
319 fis = new java.net.URL(propertiesFile).openStream();
320 System.out.println("Loading jalview properties from : "
323 .println("Disabling Jalview writing to user's local properties file.");
324 propsAreReadOnly = true;
326 } catch (Exception ex)
332 fis = new FileInputStream(propertiesFile);
334 applicationProperties.load(fis);
336 // remove any old build properties
338 deleteBuildProperties();
340 } catch (Exception ex)
342 System.out.println("Error reading properties file: " + ex);
345 if (getDefault("USE_PROXY", false))
347 String proxyServer = getDefault("PROXY_SERVER", ""), proxyPort = getDefault(
348 "PROXY_PORT", "8080");
350 System.out.println("Using proxyServer: " + proxyServer
351 + " proxyPort: " + proxyPort);
353 System.setProperty("http.proxyHost", proxyServer);
354 System.setProperty("http.proxyPort", proxyPort);
357 // LOAD THE AUTHORS FROM THE authors.props file
360 String authorDetails = "jar:".concat(Cache.class
361 .getProtectionDomain().getCodeSource().getLocation()
362 .toString().concat("!/authors.props"));
364 java.net.URL localJarFileURL = new java.net.URL(authorDetails);
366 InputStream in = localJarFileURL.openStream();
367 applicationProperties.load(in);
369 } catch (Exception ex)
371 System.out.println("Error reading author details: " + ex);
372 applicationProperties.remove("AUTHORS");
373 applicationProperties.remove("AUTHORFNAMES");
374 applicationProperties.remove("YEAR");
377 // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar
378 // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE
379 // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW
382 String buildDetails = "jar:".concat(Cache.class.getProtectionDomain()
383 .getCodeSource().getLocation().toString()
384 .concat("!/.build_properties"));
386 java.net.URL localJarFileURL = new java.net.URL(buildDetails);
388 InputStream in = localJarFileURL.openStream();
389 applicationProperties.load(in);
391 } catch (Exception ex)
393 System.out.println("Error reading build details: " + ex);
394 applicationProperties.remove("VERSION");
397 String jnlpVersion = System.getProperty("jalview.version");
398 String codeVersion = getProperty("VERSION");
399 String codeInstallation = getProperty("INSTALLATION");
400 if (codeVersion == null)
402 // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
403 codeVersion = "Test";
404 jnlpVersion = "Test";
405 codeInstallation = "";
409 codeInstallation = " (" + codeInstallation + ")";
411 new BuildDetails(codeVersion, null, codeInstallation);
414 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
416 SiftsSettings.setSiftDownloadDirectory(jalview.bin.Cache.getDefault(
417 "sifts_download_dir", DEFAULT_SIFTS_DOWNLOAD_DIR));
419 SiftsSettings.setFailSafePIDThreshold(jalview.bin.Cache.getDefault(
420 "sifts_fail_safe_pid_threshold",
421 DEFAULT_FAIL_SAFE_PID_THRESHOLD));
423 SiftsSettings.setCacheThresholdInDays(jalview.bin.Cache.getDefault(
424 "sifts_cache_threshold_in_days",
425 DEFAULT_CACHE_THRESHOLD_IN_DAYS));
428 .println("Jalview Version: " + codeVersion + codeInstallation);
430 StructureImportSettings.setDefaultStructureFileFormat(jalview.bin.Cache
432 "DEFAULT_STRUCTURE_FORMAT", DEFAULT_STRUCTURE_FORMAT));
433 StructureImportSettings
434 .setDefaultPDBFileParser(jalview.bin.Cache.getDefault(
435 "DEFAULT_PDB_FILE_PARSER", DEFAULT_PDB_FILE_PARSER));
436 StructureImportSettings.setProcessHETATMs(jalview.bin.Cache.getDefault(
437 "PROCESS_HETATM", false));
438 // jnlpVersion will be null if we're using InstallAnywhere
439 // Dont do this check if running in headless mode
440 if (jnlpVersion == null
441 && getDefault("VERSION_CHECK", true)
442 && (System.getProperty("java.awt.headless") == null || System
443 .getProperty("java.awt.headless").equals("false")))
446 class VersionChecker extends Thread
451 String orgtimeout = System
452 .getProperty("sun.net.client.defaultConnectTimeout");
453 if (orgtimeout == null)
456 System.out.println("# INFO: Setting default net timeout to "
457 + orgtimeout + " seconds.");
459 String remoteVersion = null;
462 System.setProperty("sun.net.client.defaultConnectTimeout",
464 java.net.URL url = new java.net.URL(Cache.getDefault(
465 "www.jalview.org", "http://www.jalview.org")
466 + "/webstart/jalview.jnlp");
467 BufferedReader in = new BufferedReader(new InputStreamReader(
470 while ((line = in.readLine()) != null)
472 if (line.indexOf("jalview.version") == -1)
477 line = line.substring(line.indexOf("value=") + 7);
478 line = line.substring(0, line.lastIndexOf("\""));
479 remoteVersion = line;
482 } catch (Exception ex)
485 .println("Non-fatal exception when checking version at www.jalview.org :");
486 System.out.println(ex);
487 remoteVersion = getProperty("VERSION");
489 System.setProperty("sun.net.client.defaultConnectTimeout",
492 setProperty("LATEST_VERSION", remoteVersion);
496 VersionChecker vc = new VersionChecker();
501 if (jnlpVersion != null)
503 setProperty("LATEST_VERSION", jnlpVersion);
507 applicationProperties.remove("LATEST_VERSION");
511 setProperty("VERSION", codeVersion);
513 // LOAD USERDEFINED COLOURS
514 jalview.gui.UserDefinedColours
515 .initUserColourSchemes(getProperty("USER_DEFINED_COLOURS"));
516 jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER",
520 private static void deleteBuildProperties()
522 applicationProperties.remove("LATEST_VERSION");
523 applicationProperties.remove("VERSION");
524 applicationProperties.remove("AUTHORS");
525 applicationProperties.remove("AUTHORFNAMES");
526 applicationProperties.remove("YEAR");
527 applicationProperties.remove("BUILD_DATE");
528 applicationProperties.remove("INSTALLATION");
532 * Gets Jalview application property of given key. Returns null if key not
538 * @return Property value
540 public static String getProperty(String key)
542 return applicationProperties.getProperty(key);
546 * These methods are used when checking if the saved preference is different
547 * to the default setting
550 public static boolean getDefault(String property, boolean def)
552 String string = getProperty(property);
555 def = Boolean.valueOf(string).booleanValue();
562 * These methods are used when checking if the saved preference is different
563 * to the default setting
565 public static String getDefault(String property, String def)
567 String string = getProperty(property);
577 * Stores property in the file "HOME_DIR/.jalview_properties"
582 * String value of property
584 * @return String value of property
586 public static String setProperty(String key, String obj)
591 applicationProperties.setProperty(key, obj);
592 if (!propsAreReadOnly)
594 FileOutputStream out = new FileOutputStream(propertiesFile);
595 applicationProperties.store(out, "---JalviewX Properties File---");
598 } catch (Exception ex)
600 System.out.println("Error setting property: " + key + " " + obj
607 * remove the specified property from the jalview properties file
611 public static void removeProperty(String string)
613 applicationProperties.remove(string);
618 * save the properties to the jalview properties path
620 public static void saveProperties()
622 if (!propsAreReadOnly)
626 FileOutputStream out = new FileOutputStream(propertiesFile);
627 applicationProperties.store(out, "---JalviewX Properties File---");
629 } catch (Exception ex)
631 System.out.println("Error saving properties: " + ex);
637 * internal vamsas class discovery state
639 private static int vamsasJarsArePresent = -1;
642 * Searches for vamsas client classes on class path.
644 * @return true if vamsas client is present on classpath
646 public static boolean vamsasJarsPresent()
648 if (vamsasJarsArePresent == -1)
652 if (jalview.jbgui.GDesktop.class.getClassLoader().loadClass(
653 "uk.ac.vamsas.client.VorbaId") != null)
655 jalview.bin.Cache.log
656 .debug("Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
657 vamsasJarsArePresent = 1;
658 Logger lvclient = Logger.getLogger("uk.ac.vamsas");
659 lvclient.setLevel(Level.toLevel(Cache.getDefault(
660 "logs.Vamsas.Level", Level.INFO.toString())));
662 lvclient.addAppender(log.getAppender("JalviewLogger"));
663 // Tell the user that debug is enabled
664 lvclient.debug("Jalview Vamsas Client Debugging Output Follows.");
666 } catch (Exception e)
668 vamsasJarsArePresent = 0;
669 jalview.bin.Cache.log.debug("Vamsas Classes are not present");
672 return (vamsasJarsArePresent > 0);
676 * internal vamsas class discovery state
678 private static int groovyJarsArePresent = -1;
681 * Searches for vamsas client classes on class path.
683 * @return true if vamsas client is present on classpath
685 public static boolean groovyJarsPresent()
687 if (groovyJarsArePresent == -1)
691 if (Cache.class.getClassLoader().loadClass(
692 "groovy.lang.GroovyObject") != null)
694 jalview.bin.Cache.log
695 .debug("Found Groovy (groovy.lang.GroovyObject can be loaded)");
696 groovyJarsArePresent = 1;
697 Logger lgclient = Logger.getLogger("groovy");
698 lgclient.setLevel(Level.toLevel(Cache.getDefault(
699 "logs.Groovy.Level", Level.INFO.toString())));
701 lgclient.addAppender(log.getAppender("JalviewLogger"));
702 // Tell the user that debug is enabled
703 lgclient.debug("Jalview Groovy Client Debugging Output Follows.");
707 groovyJarsArePresent = 0;
708 jalview.bin.Cache.log.debug("Groovy Classes are not present", e);
709 } catch (Exception e)
711 groovyJarsArePresent = 0;
712 jalview.bin.Cache.log.debug("Groovy Classes are not present");
715 return (groovyJarsArePresent > 0);
719 * GA tracker object - actually JGoogleAnalyticsTracker null if tracking not
722 protected static Object tracker = null;
724 protected static Class trackerfocus = null;
726 protected static Class jgoogleanalyticstracker = null;
729 * Initialise the google tracker if it is not done already.
731 public static void initGoogleTracker()
735 if (jgoogleanalyticstracker == null)
737 // try to get the tracker class
740 jgoogleanalyticstracker = Cache.class
743 "com.boxysystems.jgoogleanalytics.JGoogleAnalyticsTracker");
744 trackerfocus = Cache.class.getClassLoader().loadClass(
745 "com.boxysystems.jgoogleanalytics.FocusPoint");
746 } catch (Exception e)
748 log.debug("com.boxysystems.jgoogleanalytics package is not present - tracking not enabled.");
750 jgoogleanalyticstracker = null;
755 // now initialise tracker
756 Exception re = null, ex = null;
758 String vrs = "No Version Accessible";
761 // Google analytics tracking code for Library Finder
762 tracker = jgoogleanalyticstracker.getConstructor(
763 new Class[] { String.class, String.class, String.class })
767 (vrs = jalview.bin.Cache.getProperty("VERSION")
769 + jalview.bin.Cache.getDefault(
770 "BUILD_DATE", "unknown")),
772 jgoogleanalyticstracker.getMethod("trackAsynchronously",
773 new Class[] { trackerfocus }).invoke(
775 new Object[] { trackerfocus.getConstructor(
776 new Class[] { String.class }).newInstance(
777 new Object[] { "Application Started." }) });
778 } catch (RuntimeException e)
781 } catch (Exception e)
788 if (re != null || ex != null || err != null)
794 log.debug("Caught runtime exception in googletracker init:", re);
799 "Failed to initialise GoogleTracker for Jalview Desktop with version "
805 "Whilst initing GoogleTracker for Jalview Desktop version "
814 .println("Debug: Caught runtime exception in googletracker init:"
816 re.printStackTrace();
821 .println("Warning: Failed to initialise GoogleTracker for Jalview Desktop with version "
823 ex.printStackTrace();
829 .println("ERROR: Whilst initing GoogleTracker for Jalview Desktop version "
831 err.printStackTrace();
837 log.debug("Successfully initialised tracker.");
843 * get the user's default colour if available
849 public static Color getDefaultColour(String property, Color defcolour)
851 String colprop = getProperty(property);
856 Color col = jalview.schemes.ColourSchemeProperty
857 .getAWTColorFromName(colprop);
862 col = new jalview.schemes.UserColourScheme(colprop).findColour('A');
863 } catch (Exception ex)
865 log.warn("Couldn't parse '" + colprop + "' as a colour for "
870 return (col == null) ? defcolour : col;
874 * store a colour as a Jalview user default property
879 public static void setColourProperty(String property, Color colour)
881 setProperty(property, jalview.util.Format.getHexString(colour));
884 public static final DateFormat date_format = SimpleDateFormat
885 .getDateTimeInstance();
888 * store a date in a jalview property
893 public static void setDateProperty(String property, Date time)
895 setProperty(property, date_format.format(time));
899 * read a date stored in a jalview property
902 * @return valid date as stored by setDateProperty, or null
905 public static Date getDateProperty(String property)
907 String val = getProperty(property);
912 return date_format.parse(val);
913 } catch (Exception ex)
915 System.err.println("Invalid or corrupt date in property '"
916 + property + "' : value was '" + val + "'");
923 * get and parse a property as an integer. send any parsing problems to
927 * @return null or Integer
929 public static Integer getIntegerProperty(String property)
931 String val = getProperty(property);
932 if (val != null && (val = val.trim()).length() > 0)
936 return Integer.valueOf(val);
937 } catch (NumberFormatException x)
939 System.err.println("Invalid integer in property '" + property
940 + "' (value was '" + val + "')");
946 private static DasSourceRegistryI sourceRegistry = null;
951 * @return instance of the das source registry
953 public static DasSourceRegistryI getDasSourceRegistry()
955 if (sourceRegistry == null)
957 sourceRegistry = new DasSourceRegistry();
959 return sourceRegistry;
963 * Set the specified value, or remove it if null or empty. Does not save the
969 public static void setOrRemove(String propName, String value)
971 if (propName == null)
975 if (value == null || value.trim().length() < 1)
977 Cache.applicationProperties.remove(propName);
981 Cache.applicationProperties.setProperty(propName, value);