*/
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;
* @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
*
* @return
*/
- public static Cache getInstance()
+ private static Cache getInstance()
{
-
- // BH 2019.05.08 need to isolate static fields in JavaScript
-
- Cache i = instance;
- @SuppressWarnings("unused")
- ThreadGroup g = null;
- if (Platform.isJS())
- {
- g = Thread.currentThread().getThreadGroup();
- /**
- * @j2sNative i = g._jalviewCacheInstance;
- *
- */
- }
- if (i == null)
- {
- i = new Cache();
- if (Platform.isJS())
- {
- /**
- * @j2sNative g._jalviewCacheInstance = i;
- *
- */
- }
- else
- {
- instance = i;
- }
- }
- return i;
+ return (Cache) ApplicationSingletonProvider.getInstance(Cache.class);
}
/**
*/
public static Logger log;
- private Cache()
- {
- // inaccessible
- }
-
/** Jalview Properties */
// BH 2019.05.08 was static
@SuppressWarnings("serial")
};
/** 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
jalview.bin.Cache.log = Logger.getLogger("jalview.bin.Jalview");
laxis.setLevel(Level.toLevel(
- Cache.getDefault("logs.Axis.Level", Level.INFO.toString())));
- lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
- Level.INFO.toString())));
+ getDefault("logs.Axis.Level", Level.INFO.toString())));
+ lcastor.setLevel(Level.toLevel(
+ getDefault("logs.Castor.Level", Level.INFO.toString())));
lcastor = Logger.getLogger("org.exolab.castor.xml");
- lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
- Level.INFO.toString())));
+ lcastor.setLevel(Level.toLevel(
+ getDefault("logs.Castor.Level", Level.INFO.toString())));
// lcastor = Logger.getLogger("org.exolab.castor.xml.Marshaller");
- // lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
+ // lcastor.setLevel(Level.toLevel(getDefault("logs.Castor.Level",
// Level.INFO.toString())));
jalview.bin.Cache.log.setLevel(Level.toLevel(Cache
.getDefault("logs.Jalview.level", Level.INFO.toString())));
}
new BuildDetails(codeVersion, null, codeInstallation);
- SiftsSettings
- .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
+ SiftsSettings.setMapWithSifts(getDefault("MAP_WITH_SIFTS", false));
SiftsSettings.setSiftDownloadDirectory(jalview.bin.Cache
.getDefault("sifts_download_dir", DEFAULT_SIFTS_DOWNLOAD_DIR));
SiftsSettings.setFailSafePIDThreshold(
- jalview.bin.Cache.getDefault("sifts_fail_safe_pid_threshold",
+ getDefault("sifts_fail_safe_pid_threshold",
DEFAULT_FAIL_SAFE_PID_THRESHOLD));
SiftsSettings.setCacheThresholdInDays(
- jalview.bin.Cache.getDefault("sifts_cache_threshold_in_days",
+ getDefault("sifts_cache_threshold_in_days",
DEFAULT_CACHE_THRESHOLD_IN_DAYS));
IdOrgSettings.setUrl(getDefault("ID_ORG_HOSTURL",
StructureImportSettings
.setDefaultPDBFileParser(DEFAULT_PDB_FILE_PARSER);
// StructureImportSettings
- // .setDefaultPDBFileParser(jalview.bin.Cache.getDefault(
+ // .setDefaultPDBFileParser(jalview.bin.getDefault(
// "DEFAULT_PDB_FILE_PARSER", DEFAULT_PDB_FILE_PARSER));
// jnlpVersion will be null if we're using InstallAnywhere
// Dont do this check if running in headless mode
setProperty("VERSION", codeVersion);
// LOAD USERDEFINED COLOURS
- jalview.bin.Cache
- .initUserColourSchemes(getProperty("USER_DEFINED_COLOURS"));
- jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER",
- false);
+ initUserColourSchemes(getProperty(Preferences.USER_DEFINED_COLOURS));
}
-
private void deleteBuildProperties()
{
applicationProperties.remove("LATEST_VERSION");
*/
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);
}
/**
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---");
.newInstance(new Object[]
{ "Jalview Desktop",
(vrs = jalview.bin.Cache.getProperty("VERSION") + "_"
- + jalview.bin.Cache.getDefault("BUILD_DATE",
- "unknown")),
+ + getDefault("BUILD_DATE", "unknown")),
"UA-9060947-1" });
jgoogleanalyticstracker
.getMethod("trackAsynchronously", new Class[]
{
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);
}
}
}