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.Preferences;
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.awt.Dimension;
37 import java.io.BufferedReader;
39 import java.io.FileInputStream;
40 import java.io.FileOutputStream;
41 import java.io.InputStream;
42 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 public class Cache implements ApplicationSingletonI
219 * In Java, this will be a static field instance, which will be
220 * application-specific; in JavaScript it will be an applet-specific instance
221 * tied to the applet's ThreadGroup.
225 public static Cache getInstance()
227 return (Cache) ApplicationSingletonProvider.getInstance(Cache.class);
231 * property giving log4j level for CASTOR loggers
233 public static final String CASTORLOGLEVEL = "logs.Castor.level";
236 * property giving log4j level for AXIS loggers
238 public static final String AXISLOGLEVEL = "logs.Axis.level";
241 * property giving log4j level for Jalview Log
243 public static final String JALVIEWLOGLEVEL = "logs.Jalview.level";
248 public static final String DEFAULT_SIFTS_DOWNLOAD_DIR = System
249 .getProperty("user.home") + File.separatorChar
250 + ".sifts_downloads" + File.separatorChar;
252 private final static String DEFAULT_CACHE_THRESHOLD_IN_DAYS = "2";
254 private final static String DEFAULT_FAIL_SAFE_PID_THRESHOLD = "30";
257 * Identifiers.org download settings
259 private static final String ID_ORG_FILE = System.getProperty("user.home")
260 + File.separatorChar + ".identifiers.org.ids.json";
263 * Allowed values are PDB or mmCIF
265 private final static String PDB_DOWNLOAD_FORMAT = PDBEntry.Type.MMCIF
268 private final static String DEFAULT_PDB_FILE_PARSER = StructureImportSettings.StructureParser.JMOL_PARSER
272 * a date formatter using a fixed (rather than the user's) locale;
273 * this ensures that date properties can be written and re-read successfully
274 * even if the user changes their locale setting
276 private static final DateFormat date_format = SimpleDateFormat
277 .getDateTimeInstance(SimpleDateFormat.MEDIUM,
278 SimpleDateFormat.MEDIUM, Locale.UK);
281 * Initialises the Jalview Application Log
283 public static Logger log;
285 /** Jalview Properties */
286 // BH 2019.05.08 was static
287 @SuppressWarnings("serial")
288 public 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 private String propertiesFile;
302 * flag to possibly allow properties to be written to a property file
304 private boolean propsAreReadOnly = Platform.isJS();
306 private final static String JS_PROPERTY_PREFIX = "jalview_";
308 public static void initLogger()
316 // TODO: redirect stdout and stderr here in order to grab the output of
319 ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(),
321 ap.setName("JalviewLogger");
322 org.apache.log4j.Logger.getRootLogger().addAppender(ap); // catch all for
324 Logger laxis = Logger.getLogger("org.apache.axis");
325 Logger lcastor = Logger.getLogger("org.exolab.castor");
326 jalview.bin.Cache.log = Logger.getLogger("jalview.bin.Jalview");
328 laxis.setLevel(Level.toLevel(
329 getDefault("logs.Axis.Level", Level.INFO.toString())));
330 lcastor.setLevel(Level.toLevel(
331 getDefault("logs.Castor.Level", Level.INFO.toString())));
332 lcastor = Logger.getLogger("org.exolab.castor.xml");
333 lcastor.setLevel(Level.toLevel(
334 getDefault("logs.Castor.Level", Level.INFO.toString())));
335 // lcastor = Logger.getLogger("org.exolab.castor.xml.Marshaller");
336 // lcastor.setLevel(Level.toLevel(getDefault("logs.Castor.Level",
337 // Level.INFO.toString())));
338 jalview.bin.Cache.log.setLevel(Level.toLevel(Cache
339 .getDefault("logs.Jalview.level", Level.INFO.toString())));
340 // laxis.addAppender(ap);
341 // lcastor.addAppender(ap);
342 // jalview.bin.Cache.log.addAppender(ap);
343 // Tell the user that debug is enabled
344 jalview.bin.Cache.log.debug("Jalview Debugging Output Follows.");
345 } catch (Exception ex)
347 System.err.println("Problems initializing the log4j system\n");
348 ex.printStackTrace(System.err);
353 * Loads properties from the given properties file. Any existing properties
356 public static void loadProperties(String propsFile)
358 getInstance().loadPropertiesImpl(propsFile);
361 private void loadPropertiesImpl(String propsFile)
363 propertiesFile = propsFile;
364 if (!propsAreReadOnly)
367 if (propsFile == null)
369 propertiesFile = System.getProperty("user.home")
370 + File.separatorChar + ".jalview_properties";
374 // don't corrupt the file we've been given.
375 propsAreReadOnly = true;
379 if (propertiesFile == null)
380 { // BH 2019 read properties from the Info object associated with this
382 Platform.readInfoProperties(JS_PROPERTY_PREFIX,
383 applicationProperties);
392 fis = new java.net.URL(propertiesFile).openStream();
394 "Loading jalview properties from : " + propertiesFile);
396 "Disabling Jalview writing to user's local properties file.");
397 propsAreReadOnly = true;
399 } catch (Exception ex)
405 fis = new FileInputStream(propertiesFile);
407 applicationProperties.clear();
408 applicationProperties.load(fis);
410 // remove any old build properties
412 deleteBuildProperties();
414 } catch (Exception ex)
416 System.out.println("Error reading properties file: " + ex);
419 if (getDefault("USE_PROXY", false))
421 String proxyServer = getDefault("PROXY_SERVER", ""),
422 proxyPort = getDefault("PROXY_PORT", "8080");
424 System.out.println("Using proxyServer: " + proxyServer
425 + " proxyPort: " + proxyPort);
427 System.setProperty("http.proxyHost", proxyServer);
428 System.setProperty("http.proxyPort", proxyPort);
431 // LOAD THE AUTHORS FROM THE authors.props file
432 String authorDetails = (Platform.isJS() ? null
433 : "jar:".concat(Cache.class.getProtectionDomain()
434 .getCodeSource().getLocation().toString()
435 .concat("!/authors.props")));
439 if (authorDetails != null)
441 java.net.URL localJarFileURL = new java.net.URL(authorDetails);
442 InputStream in = localJarFileURL.openStream();
443 applicationProperties.load(in);
446 } catch (Exception ex)
448 System.out.println("Error reading author details: " + ex);
449 authorDetails = null;
451 if (authorDetails == null)
453 applicationProperties.remove("AUTHORS");
454 applicationProperties.remove("AUTHORFNAMES");
455 applicationProperties.remove("YEAR");
458 // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar
459 // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE
460 // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW
461 String buildDetails = (Platform.isJS() ? null
462 : "jar:".concat(Cache.class.getProtectionDomain()
463 .getCodeSource().getLocation().toString()
464 .concat("!/.build_properties")));
465 if (buildDetails != null)
469 java.net.URL localJarFileURL = new java.net.URL(buildDetails);
470 InputStream in = localJarFileURL.openStream();
471 applicationProperties.load(in);
473 } catch (Exception ex)
475 System.out.println("Error reading build details: " + ex);
479 if (buildDetails == null)
481 applicationProperties.remove("VERSION");
483 String jnlpVersion = System.getProperty("jalview.version");
484 String codeVersion = getProperty("VERSION");
485 String codeInstallation = getProperty("INSTALLATION");
486 if (codeVersion == null)
488 // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
489 codeVersion = "Test";
490 jnlpVersion = "Test";
491 codeInstallation = "";
495 codeInstallation = " (" + codeInstallation + ")";
497 new BuildDetails(codeVersion, null, codeInstallation);
499 SiftsSettings.setMapWithSifts(getDefault("MAP_WITH_SIFTS", false));
501 SiftsSettings.setSiftDownloadDirectory(jalview.bin.Cache
502 .getDefault("sifts_download_dir", DEFAULT_SIFTS_DOWNLOAD_DIR));
504 SiftsSettings.setFailSafePIDThreshold(
505 getDefault("sifts_fail_safe_pid_threshold",
506 DEFAULT_FAIL_SAFE_PID_THRESHOLD));
508 SiftsSettings.setCacheThresholdInDays(
509 getDefault("sifts_cache_threshold_in_days",
510 DEFAULT_CACHE_THRESHOLD_IN_DAYS));
512 IdOrgSettings.setUrl(getDefault(Preferences.ID_ORG_HOSTURL,
513 "http://www.jalview.org/services/identifiers"));
514 IdOrgSettings.setDownloadLocation(ID_ORG_FILE);
517 .println("Jalview Version: " + codeVersion + codeInstallation);
519 StructureImportSettings.setDefaultStructureFileFormat(jalview.bin.Cache
520 .getDefault(Preferences.PDB_DOWNLOAD_FORMAT, PDB_DOWNLOAD_FORMAT));
521 StructureImportSettings
522 .setDefaultPDBFileParser(DEFAULT_PDB_FILE_PARSER);
523 // StructureImportSettings
524 // .setDefaultPDBFileParser(jalview.bin.getDefault(
525 // "DEFAULT_PDB_FILE_PARSER", DEFAULT_PDB_FILE_PARSER));
526 // jnlpVersion will be null if we're using InstallAnywhere
527 // Dont do this check if running in headless mode
528 if (jnlpVersion == null && !Jalview.isHeadlessMode()
529 && getDefault("VERSION_CHECK", true))
532 class VersionChecker extends Thread
537 String orgtimeout = System
538 .getProperty("sun.net.client.defaultConnectTimeout");
539 if (orgtimeout == null)
542 System.out.println("# INFO: Setting default net timeout to "
543 + orgtimeout + " seconds.");
545 String remoteVersion = null;
548 System.setProperty("sun.net.client.defaultConnectTimeout",
550 java.net.URL url = new java.net.URL(Cache
551 .getDefault("www.jalview.org", "http://www.jalview.org")
552 + "/webstart/jalview.jnlp");
553 BufferedReader in = new BufferedReader(
554 new InputStreamReader(url.openStream()));
556 while ((line = in.readLine()) != null)
558 if (line.indexOf("jalview.version") == -1)
563 line = line.substring(line.indexOf("value=") + 7);
564 line = line.substring(0, line.lastIndexOf("\""));
565 remoteVersion = line;
568 } catch (Exception ex)
571 "Non-fatal exception when checking version at www.jalview.org :");
572 System.out.println(ex);
573 remoteVersion = getProperty("VERSION");
575 System.setProperty("sun.net.client.defaultConnectTimeout",
578 setProperty("LATEST_VERSION", remoteVersion);
582 VersionChecker vc = new VersionChecker();
587 if (jnlpVersion != null)
589 setProperty("LATEST_VERSION", jnlpVersion);
593 applicationProperties.remove("LATEST_VERSION");
597 setProperty("VERSION", codeVersion);
599 // LOAD USERDEFINED COLOURS
600 initUserColourSchemes(getProperty(Preferences.USER_DEFINED_COLOURS));
603 private void deleteBuildProperties()
605 applicationProperties.remove("LATEST_VERSION");
606 applicationProperties.remove("VERSION");
607 applicationProperties.remove("AUTHORS");
608 applicationProperties.remove("AUTHORFNAMES");
609 applicationProperties.remove("YEAR");
610 applicationProperties.remove("BUILD_DATE");
611 applicationProperties.remove("INSTALLATION");
615 * Gets Jalview application property of given key. Returns null if key not
621 * @return Property value
623 public static String getProperty(String key)
625 return getInstance().applicationProperties.getProperty(key);
629 * Returns the boolean property value for the given property name. If the
630 * value is absent then the default value is returned instead.
636 public static boolean getDefault(String property, final boolean def)
638 String string = getProperty(property);
639 return string == null ? def : Boolean.parseBoolean(string);
643 * Returns the integer property value for the given property name. If the
644 * value is absent, or malformed (not an integer), then the default value is
651 public static int getDefault(String property, final int def)
653 String string = getProperty(property);
658 return Integer.parseInt(string);
659 } catch (NumberFormatException e)
661 System.out.println("Error parsing int property '" + property
662 + "' with value '" + string + "'");
670 * retrieve a dimension, such as for Jmol
676 public static Dimension getDefaultDim(String property, Dimension def)
678 String s = getProperty(property);
681 if (s.indexOf(',') < 0)
683 s = s.trim().replace(' ', ',');
684 if (s.indexOf(',') < 0)
691 int pt = s.indexOf(",");
692 return new Dimension(Integer.parseInt(s.substring(0, pt)),
693 Integer.parseInt(s.substring(pt + 1)));
694 } catch (NumberFormatException e)
696 System.out.println("Error parsing Dimension property '" + property
697 + "' with value '" + s + "'");
704 * Returns the value of the given property, or the supplied default value if
705 * the property is not set
711 public static String getDefault(String property, final String def)
713 String value = getProperty(property);
714 return value == null ? def : value;
718 * Stores property in the file "HOME_DIR/.jalview_properties"
723 * String value of property
725 * @return previous value of property (or null)
727 public static Object setProperty(String key, String obj)
729 return getInstance().setPropertyImpl(key, obj, true);
733 * Sets a property value for the running application, without saving it to the
739 public static void setPropertyNoSave(String key, String obj)
741 getInstance().setPropertyImpl(key, obj, false);
745 * Sets a property value, and optionally also saves the current properties to
753 private Object setPropertyImpl(String key, String obj, boolean andSave)
755 Object oldValue = null;
758 oldValue = applicationProperties.setProperty(key, obj);
759 if (andSave && !propsAreReadOnly && propertiesFile != null)
761 FileOutputStream out = new FileOutputStream(propertiesFile);
762 applicationProperties.store(out, "---JalviewX Properties File---");
765 } catch (Exception ex)
768 "Error setting property: " + key + " " + obj + "\n" + ex);
774 * Removes the specified property from the jalview properties file
778 public static void removeProperty(String key)
780 getInstance().removePropertyImpl(key, true);
784 * Removes the named property for the running application, without saving the
789 public static void removePropertyNoSave(String key)
791 getInstance().removePropertyImpl(key, false);
795 * Removes the named property, and optionally saves the current properties to
801 private void removePropertyImpl(String key, boolean andSave)
803 applicationProperties.remove(key);
806 savePropertiesImpl();
811 * Saves the current properties to file
813 public static void saveProperties()
815 getInstance().savePropertiesImpl();
819 * save the properties to the jalview properties path
821 private void savePropertiesImpl()
823 if (!propsAreReadOnly)
827 FileOutputStream out = new FileOutputStream(propertiesFile);
828 applicationProperties.store(out, "---JalviewX Properties File---");
830 } catch (Exception ex)
832 System.out.println("Error saving properties: " + ex);
837 private final static int UNTESTED = -1;
839 private final static int TRUE = 1;
841 private final static int FALSE = 0;
844 * internal vamsas class discovery state
846 private static int vamsasJarsArePresent = (Platform.isJS() ? FALSE
850 * Searches for vamsas client classes on class path.
852 * @return true if vamsas client is present on classpath
854 public static boolean vamsasJarsPresent()
856 if (vamsasJarsArePresent == UNTESTED)
860 if (jalview.jbgui.GDesktop.class.getClassLoader()
861 .loadClass("uk.ac.vamsas.client.VorbaId") != null)
863 jalview.bin.Cache.log.debug(
864 "Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
865 vamsasJarsArePresent = TRUE;
866 Logger lvclient = Logger.getLogger("uk.ac.vamsas");
867 lvclient.setLevel(Level.toLevel(Cache
868 .getDefault("logs.Vamsas.Level", Level.INFO.toString())));
870 lvclient.addAppender(log.getAppender("JalviewLogger"));
871 // Tell the user that debug is enabled
872 lvclient.debug("Jalview Vamsas Client Debugging Output Follows.");
874 } catch (Exception e)
876 vamsasJarsArePresent = FALSE;
877 jalview.bin.Cache.log.debug("Vamsas Classes are not present");
880 return (vamsasJarsArePresent == TRUE);
884 * internal vamsas class discovery state
886 private static int groovyJarsArePresent = (Platform.isJS() ? FALSE
890 * Searches for vamsas client classes on class path.
892 * @return true if vamsas client is present on classpath
894 public static boolean groovyJarsPresent()
896 if (groovyJarsArePresent == UNTESTED)
900 if (Cache.class.getClassLoader()
901 .loadClass("groovy.lang.GroovyObject") != null)
903 jalview.bin.Cache.log.debug(
904 "Found Groovy (groovy.lang.GroovyObject can be loaded)");
905 groovyJarsArePresent = TRUE;
906 Logger lgclient = Logger.getLogger("groovy");
907 lgclient.setLevel(Level.toLevel(Cache
908 .getDefault("logs.Groovy.Level", Level.INFO.toString())));
910 lgclient.addAppender(log.getAppender("JalviewLogger"));
911 // Tell the user that debug is enabled
912 lgclient.debug("Jalview Groovy Client Debugging Output Follows.");
916 groovyJarsArePresent = FALSE;
917 jalview.bin.Cache.log.debug("Groovy Classes are not present", e);
918 } catch (Exception e)
920 groovyJarsArePresent = FALSE;
921 jalview.bin.Cache.log.debug("Groovy Classes are not present");
924 return (groovyJarsArePresent == TRUE);
928 * GA tracker object - actually JGoogleAnalyticsTracker null if tracking not
931 protected static Object tracker = null;
933 protected static Class<?> trackerfocus = null;
935 protected static Class<?> jgoogleanalyticstracker = null;
938 * Initialise the google tracker if it is not done already.
940 public static void initGoogleTracker()
943 // TODO: SwingJS JavaScript tracker?
947 if (jgoogleanalyticstracker == null)
949 // try to get the tracker class
952 jgoogleanalyticstracker = Cache.class.getClassLoader().loadClass(
953 "com.boxysystems.jgoogleanalytics.JGoogleAnalyticsTracker");
954 trackerfocus = Cache.class.getClassLoader()
955 .loadClass("com.boxysystems.jgoogleanalytics.FocusPoint");
956 } catch (Exception e)
959 "com.boxysystems.jgoogleanalytics package is not present - tracking not enabled.");
961 jgoogleanalyticstracker = null;
966 // now initialise tracker
967 Exception re = null, ex = null;
969 String vrs = "No Version Accessible";
972 // Google analytics tracking code for Library Finder
973 tracker = jgoogleanalyticstracker
974 .getConstructor(new Class[]
975 { String.class, String.class, String.class })
976 .newInstance(new Object[]
978 (vrs = jalview.bin.Cache.getProperty("VERSION") + "_"
979 + getDefault("BUILD_DATE", "unknown")),
981 jgoogleanalyticstracker
982 .getMethod("trackAsynchronously", new Class[]
984 .invoke(tracker, new Object[]
985 { trackerfocus.getConstructor(new Class[] { String.class })
986 .newInstance(new Object[]
987 { "Application Started." }) });
988 } catch (RuntimeException e)
991 } catch (Exception e)
998 if (re != null || ex != null || err != null)
1004 log.debug("Caught runtime exception in googletracker init:",
1010 "Failed to initialise GoogleTracker for Jalview Desktop with version "
1017 "Whilst initing GoogleTracker for Jalview Desktop version "
1027 "Debug: Caught runtime exception in googletracker init:"
1029 re.printStackTrace();
1034 "Warning: Failed to initialise GoogleTracker for Jalview Desktop with version "
1036 ex.printStackTrace();
1042 "ERROR: Whilst initing GoogleTracker for Jalview Desktop version "
1044 err.printStackTrace();
1050 log.debug("Successfully initialised tracker.");
1056 * Returns the Color value of the given property's value, or the supplied
1057 * default colour if no property is found, or it cannot be parsed to a colour.
1058 * Colours are normally saved as hex rgb values, though other formats may be
1062 * @param defaultColour
1064 * @see Cache#setColourPropertyNoSave(String, Color)
1065 * @see ColorUtils#parseColourString(String)
1067 public static Color getDefaultColour(String property,
1068 final Color defaultColour)
1070 String colprop = getProperty(property);
1071 if (colprop == null)
1073 return defaultColour;
1075 Color col = ColorUtils.parseColourString(colprop);
1078 log.warn("Couldn't parse '" + colprop + "' as a colour for "
1081 return (col == null) ? defaultColour : col;
1085 * Stores a colour as a Jalview property, converted to hex values for rgb.
1086 * Properties are not saved to file.
1091 public static void setColourPropertyNoSave(String property, Color colour)
1093 setProperty(property, jalview.util.Format.getHexString(colour));
1097 * Stores a formatted date in a jalview property, using a fixed locale.
1098 * Updated properties are written out to the properties file.
1100 * @param propertyName
1102 * @return the formatted date string
1104 public static String setDateProperty(String propertyName, Date date)
1106 String formatted = date_format.format(date);
1107 setProperty(propertyName, formatted);
1112 * Reads a date stored in a Jalview property, parses it (using a fixed locale
1113 * format) and returns as a Date, or null if parsing fails
1115 * @param propertyName
1119 public static Date getDateProperty(String propertyName)
1121 String val = getProperty(propertyName);
1126 return date_format.parse(val);
1127 } catch (Exception ex)
1129 System.err.println("Invalid or corrupt date in property '"
1130 + propertyName + "' : value was '" + val + "'");
1137 * get and parse a property as an integer. send any parsing problems to
1141 * @return null or Integer
1143 public static Integer getIntegerProperty(String property)
1145 String val = getProperty(property);
1146 if (val != null && (val = val.trim()).length() > 0)
1150 return Integer.valueOf(val);
1151 } catch (NumberFormatException x)
1153 System.err.println("Invalid integer in property '" + property
1154 + "' (value was '" + val + "')");
1161 * Set the specified value, or remove it if null or empty. Does not save the
1167 public static void setOrRemove(String propName, String value)
1169 if (propName == null)
1173 if (value == null || value.trim().length() < 1)
1175 getInstance().applicationProperties.remove(propName);
1179 getInstance().applicationProperties.setProperty(propName, value);
1184 * Loads in user colour schemes from files.
1187 * a '|'-delimited list of file paths
1189 public static void initUserColourSchemes(String files)
1191 if (files == null || files.length() == 0)
1196 // In case colours can't be loaded, we'll remove them
1197 // from the default list here.
1198 StringBuffer coloursFound = new StringBuffer();
1199 StringTokenizer st = new StringTokenizer(files, "|");
1200 while (st.hasMoreElements())
1202 String file = st.nextToken();
1205 UserColourScheme ucs = ColourSchemeLoader.loadColourScheme(file);
1208 if (coloursFound.length() > 0)
1210 coloursFound.append("|");
1212 coloursFound.append(file);
1213 ColourSchemes.getInstance().registerColourScheme(ucs);
1215 } catch (Exception ex)
1217 System.out.println("Error loading User ColourFile\n" + ex);
1220 if (!files.equals(coloursFound.toString()))
1222 if (coloursFound.toString().length() > 1)
1224 setProperty(Preferences.USER_DEFINED_COLOURS,
1225 coloursFound.toString());
1229 getInstance().applicationProperties
1230 .remove(Preferences.USER_DEFINED_COLOURS);