X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fbin%2FCache.java;h=b15c317657342c7f3514fd0c809399c56ccf59f0;hb=a3d82d30b2bc55f250bbf1c94975308407e8aae7;hp=ee97b7f56d7c18659f43afb2cde1842b6ac596e5;hpb=881c6a099be11108b04ff7446204dfc0623fb0b2;p=jalview.git diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index ee97b7f..b15c317 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -20,8 +20,9 @@ */ package jalview.bin; +import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI; import jalview.datamodel.PDBEntry; -import jalview.gui.UserDefinedColours; +import jalview.gui.Preferences; import jalview.schemes.ColourSchemeLoader; import jalview.schemes.ColourSchemes; import jalview.schemes.UserColourScheme; @@ -32,6 +33,7 @@ import jalview.util.Platform; import jalview.ws.sifts.SiftsSettings; import java.awt.Color; +import java.awt.Dimension; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -207,9 +209,14 @@ import org.apache.log4j.SimpleLayout; * @author $author$ * @version $Revision$ */ -public class Cache +public class Cache implements ApplicationSingletonI { + private Cache() + { + // private singleton + } + /** * In Java, this will be a static field instance, which will be * application-specific; in JavaScript it will be an applet-specific instance @@ -217,10 +224,9 @@ public class Cache * * @return */ - public static Cache getInstance() + private static Cache getInstance() { - Jalview j = Jalview.getInstance(); - return (j.cache == null ? j.cache = new Cache() : j.cache); + return (Cache) ApplicationSingletonProvider.getInstance(Cache.class); } /** @@ -278,11 +284,6 @@ public class Cache */ public static Logger log; - private Cache() - { - // inaccessible - } - /** Jalview Properties */ // BH 2019.05.08 was static @SuppressWarnings("serial") @@ -297,8 +298,7 @@ public class Cache }; /** Default file is ~/.jalview_properties */ - // BH 2019.05.07 note: Instances of Jalview will share this file. - static String propertiesFile; + private String propertiesFile; /** * flag to possibly allow properties to be written to a property file @@ -511,7 +511,7 @@ public class Cache getDefault("sifts_cache_threshold_in_days", DEFAULT_CACHE_THRESHOLD_IN_DAYS)); - IdOrgSettings.setUrl(getDefault("ID_ORG_HOSTURL", + IdOrgSettings.setUrl(getDefault(Preferences.ID_ORG_HOSTURL, "http://www.jalview.org/services/identifiers")); IdOrgSettings.setDownloadLocation(ID_ORG_FILE); @@ -519,7 +519,7 @@ public class Cache .println("Jalview Version: " + codeVersion + codeInstallation); StructureImportSettings.setDefaultStructureFileFormat(jalview.bin.Cache - .getDefault("PDB_DOWNLOAD_FORMAT", PDB_DOWNLOAD_FORMAT)); + .getDefault(Preferences.PDB_DOWNLOAD_FORMAT, PDB_DOWNLOAD_FORMAT)); StructureImportSettings .setDefaultPDBFileParser(DEFAULT_PDB_FILE_PARSER); // StructureImportSettings @@ -599,7 +599,7 @@ public class Cache setProperty("VERSION", codeVersion); // LOAD USERDEFINED COLOURS - initUserColourSchemes(getProperty("USER_DEFINED_COLOURS")); + initUserColourSchemes(getProperty(Preferences.USER_DEFINED_COLOURS)); } private void deleteBuildProperties() @@ -624,18 +624,7 @@ public class Cache */ public static String getProperty(String key) { - return getInstance().getPropertyImpl(key); - } - - private String getPropertyImpl(String key) - { - String prop = applicationProperties.getProperty(key); - if (prop == null && Platform.isJS()) - { - prop = applicationProperties.getProperty(Platform.getUniqueAppletID() - + "_" + JS_PROPERTY_PREFIX + key); - } - return prop; + return getInstance().applicationProperties.getProperty(key); } /** @@ -673,6 +662,40 @@ public class Cache } /** + * retrieve a dimension, such as for Jmol + * + * @param property + * @param def + * @return + */ + public static Dimension getDefaultDim(String property, Dimension def) + { + String s = getProperty(property); + if (s != null) + { + if (s.indexOf(',') < 0) + { + s = s.trim().replace(' ', ','); + if (s.indexOf(',') < 0) + { + s += "," + s; + } + } + try + { + int pt = s.indexOf(","); + return new Dimension(Integer.parseInt(s.substring(0, pt)), + Integer.parseInt(s.substring(pt + 1))); + } catch (NumberFormatException e) + { + System.out.println("Error parsing Dimension property '" + property + + "' with value '" + s + "'"); + } + } + return def; + } + + /** * Answers the value of the given property, or the supplied default value if * the property is not set */ @@ -1149,13 +1172,13 @@ public class Cache { if (coloursFound.toString().length() > 1) { - setProperty(UserDefinedColours.USER_DEFINED_COLOURS, + setProperty(Preferences.USER_DEFINED_COLOURS, coloursFound.toString()); } else { getInstance().applicationProperties - .remove(UserDefinedColours.USER_DEFINED_COLOURS); + .remove(Preferences.USER_DEFINED_COLOURS); } } }