Jalview-JS/JAL-3253-applet adding more applet parameters and setting
[jalview.git] / src / jalview / bin / Cache.java
index d7542b8..c95b507 100755 (executable)
@@ -20,6 +20,7 @@
  */
 package jalview.bin;
 
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
 import jalview.datamodel.PDBEntry;
 import jalview.gui.UserDefinedColours;
 import jalview.schemes.ColourSchemeLoader;
@@ -207,10 +208,13 @@ import org.apache.log4j.SimpleLayout;
  * @author $author$
  * @version $Revision$
  */
-public class Cache
+public class Cache implements ApplicationSingletonI
 {
 
-  static Cache instance;
+  private Cache()
+  {
+    // private singleton
+  }
 
   /**
    * In Java, this will be a static field instance, which will be
@@ -219,10 +223,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);
   }
 
   /**
@@ -280,11 +283,6 @@ public class Cache
    */
   public static Logger log;
 
-  private Cache()
-  {
-    // inaccessible
-  }
-
   /** Jalview Properties */
   // BH 2019.05.08 was static
   @SuppressWarnings("serial")
@@ -299,8 +297,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
@@ -626,18 +623,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);
   }
 
   /**
@@ -710,7 +696,7 @@ public class Cache
     try
     {
       oldValue = applicationProperties.setProperty(key, obj);
-      if (andSave && !propsAreReadOnly)
+      if (andSave && !propsAreReadOnly && propertiesFile != null)
       {
         FileOutputStream out = new FileOutputStream(propertiesFile);
         applicationProperties.store(out, "---JalviewX Properties File---");