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.bin.ApplicationSingletonProvider.ApplicationSingletonI;
24 import jalview.datamodel.PDBEntry;
25 import jalview.gui.UserDefinedColours;
26 import jalview.schemes.ColourSchemeLoader;
27 import jalview.schemes.ColourSchemes;
28 import jalview.schemes.UserColourScheme;
29 import jalview.structure.StructureImportSettings;
30 import jalview.urls.IdOrgSettings;
31 import jalview.util.ColorUtils;
32 import jalview.util.Platform;
33 import jalview.ws.sifts.SiftsSettings;
35 import java.awt.Color;
36 import java.io.BufferedReader;
38 import java.io.FileInputStream;
39 import java.io.FileOutputStream;
40 import java.io.InputStream;
41 import java.io.InputStreamReader;
43 import java.text.DateFormat;
44 import java.text.SimpleDateFormat;
45 import java.util.Collections;
46 import java.util.Date;
47 import java.util.Enumeration;
48 import java.util.Locale;
49 import java.util.Properties;
50 import java.util.StringTokenizer;
51 import java.util.TreeSet;
53 import org.apache.log4j.ConsoleAppender;
54 import org.apache.log4j.Level;
55 import org.apache.log4j.Logger;
56 import org.apache.log4j.SimpleLayout;
59 * Stores and retrieves Jalview Application Properties Lists and fields within
60 * list entries are separated by '|' symbols unless otherwise stated (|) clauses
61 * are alternative values for a tag. <br>
63 * Current properties include:
66 * logs.Axis.Level - one of the stringified Levels for log4j controlling the
67 * logging level for axis (used for web services) <br>
69 * <li>logs.Castor.Level - one of the stringified Levels for log4j controlling
70 * the logging level for castor (used for serialization) <br>
72 * <li>logs.Jalview.Level - Cache.log stringified level. <br>
74 * <li>SCREEN_WIDTH</li>
75 * <li>SCREEN_HEIGHT</li>
76 * <li>SCREEN_Y=285</li>
77 * <li>SCREEN_X=371</li>
78 * <li>SHOW_FULLSCREEN boolean</li>
79 * <li>FONT_NAME java font name for alignment text display</li>
80 * <li>FONT_SIZE size of displayed alignment text</li>
81 * <li>FONT_STYLE style of font displayed (sequence labels are always
83 * <li>GAP_SYMBOL character to treat as gap symbol (usually -,.,' ')</li>
84 * <li>LAST_DIRECTORY last directory for browsing alignment</li>
85 * <li>USER_DEFINED_COLOURS list of user defined colour scheme files</li>
86 * <li>SHOW_FULL_ID show id with '/start-end' numbers appended</li>
87 * <li>SHOW_IDENTITY show percentage identity annotation</li>
88 * <li>SHOW_QUALITY show alignment quality annotation</li>
89 * <li>SHOW_ANNOTATIONS show alignment annotation rows</li>
90 * <li>SHOW_CONSERVATION show alignment conservation annotation</li>
91 * <li>SORT_ANNOTATIONS currently either SEQUENCE_AND_LABEL or
92 * LABEL_AND_SEQUENCE</li>
93 * <li>SHOW_AUTOCALC_ABOVE true to show autocalculated annotations above
94 * sequence annotations</li>
95 * <li>CENTRE_COLUMN_LABELS centre the labels at each column in a displayed
97 * <li>DEFAULT_COLOUR default colour scheme to apply for a new alignment</li>
98 * <li>DEFAULT_FILE_FORMAT file format used to save</li>
99 * <li>STARTUP_FILE file loaded on startup (may be a fully qualified url)</li>
100 * <li>SHOW_STARTUP_FILE flag to control loading of startup file</li>
101 * <li>VERSION the version of the jalview build</li>
102 * <li>BUILD_DATE date of this build</li>
103 * <li>LATEST_VERSION the latest jalview version advertised on the
104 * www.jalview.org</li>
105 * <li>PIR_MODELLER boolean indicating if PIR files are written with MODELLER
107 * <li>(FASTA,MSF,PILEUP,CLUSTAL,BLC,PIR,PFAM)_JVSUFFIX boolean for adding jv
108 * suffix to file</li>
109 * <li>RECENT_URL list of recently retrieved URLs</li>
110 * <li>RECENT_FILE list of recently opened files</li>
111 * <li>USE_PROXY flag for whether a http proxy is to be used</li>
112 * <li>PROXY_SERVER the proxy</li>
113 * <li>PROXY_PORT</li>
114 * <li>NOQUESTIONNAIRES true to prevent jalview from checking the questionnaire
116 * <li>QUESTIONNAIRE last questionnaire:responder id string from questionnaire
118 * <li>USAGESTATS (false - user prompted) Enable google analytics tracker for
119 * collecting usage statistics</li>
120 * <li>SHOW_OVERVIEW boolean for overview window display</li>
121 * <li>ANTI_ALIAS boolean for smooth fonts</li>
122 * <li>RIGHT_ALIGN_IDS boolean</li>
123 * <li>AUTO_CALC_CONSENSUS boolean for automatic recalculation of consensus</li>
124 * <li>PAD_GAPS boolean</li>
125 * <li>ID_ITALICS boolean</li>
126 * <li>SHOW_JV_SUFFIX</li>
127 * <li>WRAP_ALIGNMENT</li>
128 * <li>EPS_RENDERING (Prompt each time|Lineart|Text) default for EPS rendering
130 * <li>SORT_ALIGNMENT (No sort|Id|Pairwise Identity)</li>
131 * <li>SEQUENCE_LINKS list of name|URL pairs for opening a url with
133 * <li>STORED_LINKS list of name|url pairs which user has entered but are not
135 * <li>DEFAULT_LINK name of single url to be used when user double clicks a
136 * sequence id (must be in SEQUENCE_LINKS or STORED_LINKS)
137 * <li>GROUP_LINKS list of name|URL[|<separator>] tuples - see
138 * jalview.utils.GroupURLLink for more info</li>
139 * <li>DEFAULT_BROWSER for unix</li>
140 * <li>SHOW_MEMUSAGE boolean show memory usage and warning indicator on desktop
142 * <li>VERSION_CHECK (true) check for the latest release version from
143 * www.jalview.org (or the alias given by the www.jalview.org property)</li>
144 * <li>SHOW_NPFEATS_TOOLTIP (true) show non-positional features in the Sequence
146 * <li>SHOW_DBREFS_TOOLTIP (true) show Database Cross References in the Sequence
148 * <li>SHOW_UNCONSERVED (false) only render unconserved residues - conserved
149 * displayed as '.'</li>
150 * <li>SORT_BY_TREE (false) sort the current alignment view according to the
151 * order of a newly displayed tree</li>
152 * <li>DBFETCH_USEPICR (false) use PICR to recover valid DB references from
153 * sequence ID strings before attempting retrieval from any datasource</li>
154 * <li>SHOW_GROUP_CONSENSUS (false) Show consensus annotation for groups in the
156 * <li>SHOW_GROUP_CONSERVATION (false) Show conservation annotation for groups
157 * in the alignment.</li>
158 * <li>SHOW_CONSENSUS_HISTOGRAM (false) Show consensus annotation row's
160 * <li>SHOW_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
162 * <li>NORMALISE_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
163 * logo normalised to row height rather than histogram height.</li>
164 * <li>FOLLOW_SELECTIONS (true) Controls whether a new alignment view should
165 * respond to selections made in other alignments containing the same sequences.
167 * <li>JWS2HOSTURLS comma-separated list of URLs to try for JABAWS services</li>
168 * <li>SHOW_WSDISCOVERY_ERRORS (true) Controls if the web service URL discovery
169 * warning dialog box is displayed.</li>
170 * <li>ANNOTATIONCOLOUR_MIN (orange) Shade used for minimum value of annotation
171 * when shading by annotation</li>
172 * <li>ANNOTATIONCOLOUR_MAX (red) Shade used for maximum value of annotation
173 * when shading by annotation</li>
174 * <li>www.jalview.org (http://www.jalview.org) a property enabling all HTTP
175 * requests to be redirected to a mirror of http://www.jalview.org</li>
176 * <li>FIGURE_AUTOIDWIDTH (false) Expand the left hand column of an exported
177 * alignment figure to accommodate even the longest sequence ID or annotation
179 * <li>FIGURE_FIXEDIDWIDTH Specifies the width to use for the left-hand column
180 * when exporting an alignment as a figure (setting FIGURE_AUTOIDWIDTH to true
181 * will override this).</li>
182 * <li>STRUCT_FROM_PDB (false) derive secondary structure annotation from PDB
184 * <li>USE_RNAVIEW (false) use RNAViewer to derive secondary structure</li>
185 * <li>ADD_SS_ANN (false) add secondary structure annotation to alignment
187 * <li>ADD_TEMPFACT_ANN (false) add Temperature Factor annotation to alignment
189 * <li>STRUCTURE_DISPLAY choose from JMOL (default) or CHIMERA for 3D structure
191 * <li>CHIMERA_PATH specify full path to Chimera program (if non-standard)</li>
192 * <li>ID_ORG_HOSTURL location of jalview service providing identifiers.org urls
196 * Deprecated settings:
199 * <li>DISCOVERY_START - Boolean - controls if discovery services are queried on
200 * startup (JWS1 services only)</li>
201 * <li>DISCOVERY_URLS - comma separated list of Discovery Service endpoints.
202 * (JWS1 services only)</li>
203 * <li>SHOW_JWS1_SERVICES (true) enable or disable the original Jalview 2
204 * services in the desktop GUI</li>
205 * <li>ENABLE_RSBS_EDITOR (false for 2.7 release) enable or disable RSBS editing
206 * panel in web service preferences</li>
210 * @version $Revision$
212 public class Cache implements ApplicationSingletonI
221 * In Java, this will be a static field instance, which will be
222 * application-specific; in JavaScript it will be an applet-specific instance
223 * tied to the applet's ThreadGroup.
227 public static Cache getInstance()
229 return (Cache) ApplicationSingletonProvider.getInstance(Cache.class);
233 * property giving log4j level for CASTOR loggers
235 public static final String CASTORLOGLEVEL = "logs.Castor.level";
238 * property giving log4j level for AXIS loggers
240 public static final String AXISLOGLEVEL = "logs.Axis.level";
243 * property giving log4j level for Jalview Log
245 public static final String JALVIEWLOGLEVEL = "logs.Jalview.level";
250 public static final String DEFAULT_SIFTS_DOWNLOAD_DIR = System
251 .getProperty("user.home") + File.separatorChar
252 + ".sifts_downloads" + File.separatorChar;
254 private final static String DEFAULT_CACHE_THRESHOLD_IN_DAYS = "2";
256 private final static String DEFAULT_FAIL_SAFE_PID_THRESHOLD = "30";
259 * Identifiers.org download settings
261 private static final String ID_ORG_FILE = System.getProperty("user.home")
262 + File.separatorChar + ".identifiers.org.ids.json";
265 * Allowed values are PDB or mmCIF
267 private final static String PDB_DOWNLOAD_FORMAT = PDBEntry.Type.MMCIF
270 private final static String DEFAULT_PDB_FILE_PARSER = StructureImportSettings.StructureParser.JMOL_PARSER
274 * a date formatter using a fixed (rather than the user's) locale;
275 * this ensures that date properties can be written and re-read successfully
276 * even if the user changes their locale setting
278 private static final DateFormat date_format = SimpleDateFormat
279 .getDateTimeInstance(SimpleDateFormat.MEDIUM,
280 SimpleDateFormat.MEDIUM, Locale.UK);
283 * Initialises the Jalview Application Log
285 public static Logger log;
287 /** Jalview Properties */
288 private Properties applicationProperties = new Properties()
290 // override results in properties output in alphabetical order
292 public synchronized Enumeration<Object> keys()
294 return Collections.enumeration(new TreeSet<>(super.keySet()));
298 /** Default file is ~/.jalview_properties */
299 static String propertiesFile;
301 private static boolean propsAreReadOnly = Platform.isJS();
303 private final static String JS_PROPERTY_PREFIX = "jalview_";
305 public static void initLogger()
313 // TODO: redirect stdout and stderr here in order to grab the output of
316 ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(),
318 ap.setName("JalviewLogger");
319 org.apache.log4j.Logger.getRootLogger().addAppender(ap); // catch all for
321 Logger laxis = Logger.getLogger("org.apache.axis");
322 Logger lcastor = Logger.getLogger("org.exolab.castor");
323 jalview.bin.Cache.log = Logger.getLogger("jalview.bin.Jalview");
325 laxis.setLevel(Level.toLevel(
326 Cache.getDefault("logs.Axis.Level", Level.INFO.toString())));
327 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
328 Level.INFO.toString())));
329 lcastor = Logger.getLogger("org.exolab.castor.xml");
330 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
331 Level.INFO.toString())));
332 // lcastor = Logger.getLogger("org.exolab.castor.xml.Marshaller");
333 // lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
334 // Level.INFO.toString())));
335 jalview.bin.Cache.log.setLevel(Level.toLevel(Cache
336 .getDefault("logs.Jalview.level", Level.INFO.toString())));
337 // laxis.addAppender(ap);
338 // lcastor.addAppender(ap);
339 // jalview.bin.Cache.log.addAppender(ap);
340 // Tell the user that debug is enabled
341 jalview.bin.Cache.log.debug("Jalview Debugging Output Follows.");
342 } catch (Exception ex)
344 System.err.println("Problems initializing the log4j system\n");
345 ex.printStackTrace(System.err);
350 * Loads properties from the given properties file. Any existing properties
353 public static void loadProperties(String propsFile)
356 getInstance().loadPropertiesImpl(propsFile);
360 private void loadPropertiesImpl(String propsFile)
363 propertiesFile = propsFile;
364 if (propsFile == null && !propsAreReadOnly)
366 propertiesFile = System.getProperty("user.home") + File.separatorChar
367 + ".jalview_properties";
371 // don't corrupt the file we've been given.
372 propsAreReadOnly = true;
375 if (propertiesFile == null)
377 Platform.readInfoProperties(JS_PROPERTY_PREFIX,
378 applicationProperties);
387 fis = new java.net.URL(propertiesFile).openStream();
389 "Loading jalview properties from : " + propertiesFile);
391 "Disabling Jalview writing to user's local properties file.");
392 propsAreReadOnly = true;
394 } catch (Exception ex)
400 fis = new FileInputStream(propertiesFile);
402 applicationProperties.clear();
403 applicationProperties.load(fis);
405 // remove any old build properties
407 deleteBuildProperties();
409 } catch (Exception ex)
411 System.out.println("Error reading properties file: " + ex);
414 if (getDefault("USE_PROXY", false))
416 String proxyServer = getDefault("PROXY_SERVER", ""),
417 proxyPort = getDefault("PROXY_PORT", "8080");
419 System.out.println("Using proxyServer: " + proxyServer
420 + " proxyPort: " + proxyPort);
422 System.setProperty("http.proxyHost", proxyServer);
423 System.setProperty("http.proxyPort", proxyPort);
426 // LOAD THE AUTHORS FROM THE authors.props file
427 String authorDetails = resolveResourceURLFor("/authors.props");
431 if (authorDetails != null)
433 URL localJarFileURL = new URL(authorDetails);
434 InputStream in = localJarFileURL.openStream();
435 applicationProperties.load(in);
438 } catch (Exception ex)
440 System.out.println("Error reading author details: " + ex);
441 authorDetails = null;
443 if (authorDetails == null)
445 applicationProperties.remove("AUTHORS");
446 applicationProperties.remove("AUTHORFNAMES");
447 applicationProperties.remove("YEAR");
450 loadBuildProperties(false);
453 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
455 SiftsSettings.setSiftDownloadDirectory(jalview.bin.Cache
456 .getDefault("sifts_download_dir", DEFAULT_SIFTS_DOWNLOAD_DIR));
458 SiftsSettings.setFailSafePIDThreshold(
459 jalview.bin.Cache.getDefault("sifts_fail_safe_pid_threshold",
460 DEFAULT_FAIL_SAFE_PID_THRESHOLD));
462 SiftsSettings.setCacheThresholdInDays(
463 jalview.bin.Cache.getDefault("sifts_cache_threshold_in_days",
464 DEFAULT_CACHE_THRESHOLD_IN_DAYS));
466 IdOrgSettings.setUrl(getDefault("ID_ORG_HOSTURL",
467 "http://www.jalview.org/services/identifiers"));
468 IdOrgSettings.setDownloadLocation(ID_ORG_FILE);
470 StructureImportSettings.setDefaultStructureFileFormat(jalview.bin.Cache
471 .getDefault("PDB_DOWNLOAD_FORMAT", PDB_DOWNLOAD_FORMAT));
472 StructureImportSettings
473 .setDefaultPDBFileParser(DEFAULT_PDB_FILE_PARSER);
474 // StructureImportSettings
475 // .setDefaultPDBFileParser(jalview.bin.Cache.getDefault(
476 // "DEFAULT_PDB_FILE_PARSER", DEFAULT_PDB_FILE_PARSER));
478 String jnlpVersion = System.getProperty("jalview.version");
480 // jnlpVersion will be null if a latest version check for the channel needs
483 // Dont do this check if running in headless mode
485 if (jnlpVersion == null && getDefault("VERSION_CHECK", true)
486 && (System.getProperty("java.awt.headless") == null || System
487 .getProperty("java.awt.headless").equals("false")))
494 String orgtimeout = System
495 .getProperty("sun.net.client.defaultConnectTimeout");
496 if (orgtimeout == null)
499 System.out.println("# INFO: Setting default net timeout to "
500 + orgtimeout + " seconds.");
502 String remoteVersion = null;
505 System.setProperty("sun.net.client.defaultConnectTimeout",
507 java.net.URL url = new java.net.URL(Cache
508 .getDefault("www.jalview.org", "http://www.jalview.org")
509 + "/webstart/jalview.jnlp");
510 BufferedReader in = new BufferedReader(
511 new InputStreamReader(url.openStream()));
513 while ((line = in.readLine()) != null)
515 if (line.indexOf("jalview.version") == -1)
520 line = line.substring(line.indexOf("value=") + 7);
521 line = line.substring(0, line.lastIndexOf("\""));
522 remoteVersion = line;
525 } catch (Exception ex)
528 "Non-fatal exception when checking version at www.jalview.org :");
529 System.out.println(ex);
530 remoteVersion = getProperty("VERSION");
532 System.setProperty("sun.net.client.defaultConnectTimeout",
535 setProperty("LATEST_VERSION", remoteVersion);
541 if (jnlpVersion != null)
543 setProperty("LATEST_VERSION", jnlpVersion);
547 applicationProperties.remove("LATEST_VERSION");
551 // LOAD USERDEFINED COLOURS
552 Cache.initUserColourSchemes(getProperty("USER_DEFINED_COLOURS"));
553 jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER",
558 * construct a resource URL for the given absolute resource pathname
560 * @param resourcePath
563 private static String resolveResourceURLFor(String resourcePath)
566 if (Platform.isJS() || !Cache.class.getProtectionDomain()
567 .getCodeSource().getLocation().toString().endsWith(".jar"))
571 url = Cache.class.getResource(resourcePath).toString();
572 } catch (Exception ex)
574 System.err.println("Failed to resolve resource " + resourcePath
575 + ": " + ex.getMessage());
580 url = "jar:".concat(Cache.class.getProtectionDomain().getCodeSource()
581 .getLocation().toString().concat("!" + resourcePath));
586 public void loadBuildProperties(boolean reportVersion)
588 String codeInstallation = getProperty("INSTALLATION");
589 boolean printVersion = codeInstallation == null;
592 * read build properties - from the Jalview jar for a Java distribution,
593 * or from codebase file in test or JalviewJS context
597 String buildDetails = resolveResourceURLFor("/.build_properties");
598 URL localJarFileURL = new URL(buildDetails);
599 InputStream in = localJarFileURL.openStream();
600 applicationProperties.load(in);
602 } catch (Exception ex)
604 System.out.println("Error reading build details: " + ex);
605 applicationProperties.remove("VERSION");
607 String codeVersion = getProperty("VERSION");
608 codeInstallation = getProperty("INSTALLATION");
610 if (codeVersion == null)
612 // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
613 codeVersion = "Test";
614 codeInstallation = "";
618 codeInstallation = " (" + codeInstallation + ")";
620 setProperty("VERSION", codeVersion);
621 new BuildDetails(codeVersion, null, codeInstallation);
622 if (printVersion && reportVersion)
625 "Jalview Version: " + codeVersion + codeInstallation);
629 private void deleteBuildProperties()
631 applicationProperties.remove("LATEST_VERSION");
632 applicationProperties.remove("VERSION");
633 applicationProperties.remove("AUTHORS");
634 applicationProperties.remove("AUTHORFNAMES");
635 applicationProperties.remove("YEAR");
636 applicationProperties.remove("BUILD_DATE");
637 applicationProperties.remove("INSTALLATION");
641 * Gets Jalview application property of given key. Returns null if key not
647 * @return Property value
649 public static String getProperty(String key)
651 String prop = getInstance().applicationProperties.getProperty(key);
652 // if (prop == null && Platform.isJS())
654 // prop = applicationProperties.getProperty(Platform.getUniqueAppletID()
655 // + "_" + JS_PROPERTY_PREFIX + key);
661 * These methods are used when checking if the saved preference is different
662 * to the default setting
665 public static boolean getDefault(String property, boolean def)
667 String string = getProperty(property);
670 def = Boolean.valueOf(string).booleanValue();
676 public static int getDefault(String property, int def)
678 String string = getProperty(property);
683 def = Integer.parseInt(string);
684 } catch (NumberFormatException e)
686 System.out.println("Error parsing int property '" + property
687 + "' with value '" + string + "'");
695 * Answers the value of the given property, or the supplied default value if
696 * the property is not set
698 public static String getDefault(String property, String def)
700 String value = getProperty(property);
701 return value == null ? def : value;
705 * Stores property in the file "HOME_DIR/.jalview_properties"
710 * String value of property
712 * @return previous value of property (or null)
714 public static Object setProperty(String key, String obj)
716 return getInstance().setPropertyImpl(key, obj, true);
720 * Removes the specified property from the jalview properties file
724 public static void removeProperty(String key)
726 getInstance().removePropertyImpl(key, true);
730 * Removes the named property for the running application, without saving the
733 * BH noting that ColourMenuHelper calls this. If the intent is to save, then
734 * simply chanet that call to removeProperty(key).
738 public static void removePropertyNoSave(String key)
743 removePropertyImpl(key, false);
747 * Removes the named property, and optionally saves the current properties to
753 private void removePropertyImpl(String key, boolean andSave)
755 applicationProperties.remove(key);
761 * save the properties to the jalview properties path
763 public static void saveProperties()
765 getInstance().savePropertiesImpl();
769 * save the properties to the jalview properties path
771 private void savePropertiesImpl()
774 if (!propsAreReadOnly)
778 FileOutputStream out = new FileOutputStream(propertiesFile);
779 applicationProperties.store(out, "---JalviewX Properties File---");
781 } catch (Exception ex)
783 System.out.println("Error saving properties: " + ex);
789 * internal vamsas class discovery state
791 private static int vamsasJarsArePresent = -1;
794 * Searches for vamsas client classes on class path.
796 * @return true if vamsas client is present on classpath
798 public static boolean vamsasJarsPresent()
800 if (vamsasJarsArePresent == -1)
804 if (jalview.jbgui.GDesktop.class.getClassLoader()
805 .loadClass("uk.ac.vamsas.client.VorbaId") != null)
807 jalview.bin.Cache.log.debug(
808 "Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
809 vamsasJarsArePresent = 1;
810 Logger lvclient = Logger.getLogger("uk.ac.vamsas");
811 lvclient.setLevel(Level.toLevel(Cache
812 .getDefault("logs.Vamsas.Level", Level.INFO.toString())));
814 lvclient.addAppender(log.getAppender("JalviewLogger"));
815 // Tell the user that debug is enabled
816 lvclient.debug("Jalview Vamsas Client Debugging Output Follows.");
818 } catch (Exception e)
820 vamsasJarsArePresent = 0;
821 jalview.bin.Cache.log.debug("Vamsas Classes are not present");
824 return (vamsasJarsArePresent > 0);
828 * internal vamsas class discovery state
830 private static int groovyJarsArePresent = -1;
833 * Searches for vamsas client classes on class path.
835 * @return true if vamsas client is present on classpath
837 public static boolean groovyJarsPresent()
839 if (groovyJarsArePresent == -1)
843 if (Cache.class.getClassLoader()
844 .loadClass("groovy.lang.GroovyObject") != null)
846 jalview.bin.Cache.log.debug(
847 "Found Groovy (groovy.lang.GroovyObject can be loaded)");
848 groovyJarsArePresent = 1;
849 Logger lgclient = Logger.getLogger("groovy");
850 lgclient.setLevel(Level.toLevel(Cache
851 .getDefault("logs.Groovy.Level", Level.INFO.toString())));
853 lgclient.addAppender(log.getAppender("JalviewLogger"));
854 // Tell the user that debug is enabled
855 lgclient.debug("Jalview Groovy Client Debugging Output Follows.");
859 groovyJarsArePresent = 0;
860 jalview.bin.Cache.log.debug("Groovy Classes are not present", e);
861 } catch (Exception e)
863 groovyJarsArePresent = 0;
864 jalview.bin.Cache.log.debug("Groovy Classes are not present");
867 return (groovyJarsArePresent > 0);
871 * GA tracker object - actually JGoogleAnalyticsTracker null if tracking not
874 protected static Object tracker = null;
876 protected static Class trackerfocus = null;
878 protected static Class jgoogleanalyticstracker = null;
881 * Initialise the google tracker if it is not done already.
883 public static void initGoogleTracker()
887 if (jgoogleanalyticstracker == null)
889 // try to get the tracker class
892 jgoogleanalyticstracker = Cache.class.getClassLoader().loadClass(
893 "com.boxysystems.jgoogleanalytics.JGoogleAnalyticsTracker");
894 trackerfocus = Cache.class.getClassLoader()
895 .loadClass("com.boxysystems.jgoogleanalytics.FocusPoint");
896 } catch (Exception e)
899 "com.boxysystems.jgoogleanalytics package is not present - tracking not enabled.");
901 jgoogleanalyticstracker = null;
906 // now initialise tracker
907 Exception re = null, ex = null;
909 String vrs = "No Version Accessible";
912 // Google analytics tracking code for Library Finder
913 tracker = jgoogleanalyticstracker
914 .getConstructor(new Class[]
915 { String.class, String.class, String.class })
916 .newInstance(new Object[]
918 (vrs = jalview.bin.Cache.getProperty("VERSION") + "_"
919 + jalview.bin.Cache.getDefault("BUILD_DATE",
922 jgoogleanalyticstracker
923 .getMethod("trackAsynchronously", new Class[]
925 .invoke(tracker, new Object[]
926 { trackerfocus.getConstructor(new Class[] { String.class })
927 .newInstance(new Object[]
928 { "Application Started." }) });
929 } catch (RuntimeException e)
932 } catch (Exception e)
939 if (re != null || ex != null || err != null)
945 log.debug("Caught runtime exception in googletracker init:",
951 "Failed to initialise GoogleTracker for Jalview Desktop with version "
958 "Whilst initing GoogleTracker for Jalview Desktop version "
968 "Debug: Caught runtime exception in googletracker init:"
970 re.printStackTrace();
975 "Warning: Failed to initialise GoogleTracker for Jalview Desktop with version "
977 ex.printStackTrace();
983 "ERROR: Whilst initing GoogleTracker for Jalview Desktop version "
985 err.printStackTrace();
991 log.debug("Successfully initialised tracker.");
997 * get the user's default colour if available
1003 public static Color getDefaultColour(String property, Color defcolour)
1005 String colprop = getProperty(property);
1006 if (colprop == null)
1010 Color col = ColorUtils.parseColourString(colprop);
1013 log.warn("Couldn't parse '" + colprop + "' as a colour for "
1016 return (col == null) ? defcolour : col;
1020 * store a colour as a Jalview user default property
1025 public static void setColourPropertyNoSave(String property, Color colour)
1027 setPropertyNoSave(property, jalview.util.Format.getHexString(colour));
1031 * Stores a formatted date in a jalview property, using a fixed locale.
1033 * @param propertyName
1035 * @return the formatted date string
1037 public static String setDateProperty(String propertyName, Date date)
1039 String formatted = date_format.format(date);
1040 setProperty(propertyName, formatted);
1045 * Reads a date stored in a Jalview property, parses it (using a fixed locale
1046 * format) and returns as a Date, or null if parsing fails
1048 * @param propertyName
1052 public static Date getDateProperty(String propertyName)
1054 String val = getProperty(propertyName);
1059 return date_format.parse(val);
1060 } catch (Exception ex)
1062 System.err.println("Invalid or corrupt date in property '"
1063 + propertyName + "' : value was '" + val + "'");
1070 * get and parse a property as an integer. send any parsing problems to
1074 * @return null or Integer
1076 public static Integer getIntegerProperty(String property)
1078 String val = getProperty(property);
1079 if (val != null && (val = val.trim()).length() > 0)
1083 return Integer.valueOf(val);
1084 } catch (NumberFormatException x)
1086 System.err.println("Invalid integer in property '" + property
1087 + "' (value was '" + val + "')");
1094 * Set the specified value, or remove it if null or empty. Does not save the
1100 public static void setOrRemove(String propName, String value)
1102 if (propName == null)
1106 if (value == null || value.trim().length() < 1)
1108 getInstance().applicationProperties.remove(propName);
1112 getInstance().applicationProperties.setProperty(propName, value);
1117 * Loads in user colour schemes from files.
1120 * a '|'-delimited list of file paths
1122 public static void initUserColourSchemes(String files)
1124 if (files == null || files.length() == 0)
1129 // In case colours can't be loaded, we'll remove them
1130 // from the default list here.
1131 StringBuffer coloursFound = new StringBuffer();
1132 StringTokenizer st = new StringTokenizer(files, "|");
1133 while (st.hasMoreElements())
1135 String file = st.nextToken();
1138 UserColourScheme ucs = ColourSchemeLoader.loadColourScheme(file);
1141 if (coloursFound.length() > 0)
1143 coloursFound.append("|");
1145 coloursFound.append(file);
1146 ColourSchemes.getInstance().registerColourScheme(ucs);
1148 } catch (Exception ex)
1150 System.out.println("Error loading User ColourFile\n" + ex);
1153 if (!files.equals(coloursFound.toString()))
1155 if (coloursFound.toString().length() > 1)
1157 setProperty(UserDefinedColours.USER_DEFINED_COLOURS,
1158 coloursFound.toString());
1162 getInstance().applicationProperties
1163 .remove(UserDefinedColours.USER_DEFINED_COLOURS);
1169 * Initial logging information helper for various versions output
1173 * @param defaultValue
1175 private static void appendIfNotNull(StringBuilder sb, String prefix,
1176 String value, String suffix, String defaultValue)
1178 if (value == null && defaultValue == null)
1182 String line = prefix + (value != null ? value : defaultValue) + suffix;
1188 * @return Jalview version, build details and JVM platform version for console
1190 public static String getVersionDetailsForConsole()
1192 StringBuilder sb = new StringBuilder();
1193 sb.append("Jalview Version: "
1194 + jalview.bin.Cache.getDefault("VERSION", "TEST"));
1196 sb.append("Jalview Installation: "
1197 + jalview.bin.Cache.getDefault("INSTALLATION", "unknown"));
1199 sb.append("Build Date: "
1200 + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown"));
1202 sb.append("Java version: " + System.getProperty("java.version"));
1204 sb.append(System.getProperty("os.arch") + " "
1205 + System.getProperty("os.name") + " "
1206 + System.getProperty("os.version"));
1208 appendIfNotNull(sb, "Install4j version: ",
1209 System.getProperty("sys.install4jVersion"), "\n", null);
1210 appendIfNotNull(sb, "Install4j template version: ",
1211 System.getProperty("installer_template_version"), "\n", null);
1212 appendIfNotNull(sb, "Launcher version: ",
1213 System.getProperty("launcher_version"), "\n", null);
1214 if (jalview.bin.Cache.getDefault("VERSION", "TEST")
1215 .equals("DEVELOPMENT"))
1217 appendIfNotNull(sb, "Getdown appdir: ",
1218 System.getProperty("getdownappdir"), "\n", null);
1219 appendIfNotNull(sb, "Java home: ", System.getProperty("java.home"),
1222 return sb.toString();
1227 * @return build details as reported in splashscreen
1229 public static String getBuildDetailsForSplash()
1231 // consider returning more human friendly info
1232 // eg 'built from Source' or update channel
1233 return jalview.bin.Cache.getDefault("INSTALLATION", "unknown");
1238 * For AppletParams and Preferences ok_actionPerformed and
1239 * startupFileTextfield_mouseClicked
1241 * Sets a property value for the running application, without saving it to the
1247 public static void setPropertyNoSave(String key, String obj)
1249 getInstance().setPropertyImpl(key, obj, false);
1253 * Sets a property value, and optionally also saves the current properties to
1261 private Object setPropertyImpl(
1262 String key, String obj, boolean andSave)
1264 Object oldValue = null;
1267 oldValue = applicationProperties.setProperty(key, obj);
1268 if (andSave && !propsAreReadOnly && propertiesFile != null)
1270 FileOutputStream out = new FileOutputStream(propertiesFile);
1271 applicationProperties.store(out, "---JalviewX Properties File---");
1274 } catch (Exception ex)
1277 "Error setting property: " + key + " " + obj + "\n" + ex);