From 8d25e88f6a9d1bea9569c23e425df7b1b498fd14 Mon Sep 17 00:00:00 2001 From: BobHanson Date: Tue, 2 Jun 2020 18:47:20 -0500 Subject: [PATCH] JAL-3446 from JAL-3253 ApplicationSingletonProvider 1/many --- src/jalview/analysis/AlignmentSorter.java | 147 +++++++++++------- src/jalview/analysis/scoremodels/ScoreModels.java | 30 ++-- src/jalview/bin/ApplicationSingletonProvider.java | 163 +++++++++++++++++++ src/jalview/bin/Cache.java | 172 ++++++++++----------- src/jalview/bin/Jalview.java | 2 +- src/jalview/gui/Preferences.java | 8 +- 6 files changed, 352 insertions(+), 170 deletions(-) create mode 100644 src/jalview/bin/ApplicationSingletonProvider.java diff --git a/src/jalview/analysis/AlignmentSorter.java b/src/jalview/analysis/AlignmentSorter.java index b88ef3a..8634db6 100755 --- a/src/jalview/analysis/AlignmentSorter.java +++ b/src/jalview/analysis/AlignmentSorter.java @@ -22,6 +22,8 @@ package jalview.analysis; import jalview.analysis.scoremodels.PIDModel; import jalview.analysis.scoremodels.SimilarityParams; +import jalview.bin.ApplicationSingletonProvider; +import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentOrder; @@ -51,40 +53,65 @@ import java.util.List; * from the first tobesorted position in the alignment. e.g. (a,tb2,b,tb1,c,tb3 * becomes a,tb1,tb2,tb3,b,c) */ -public class AlignmentSorter +public class AlignmentSorter implements ApplicationSingletonI { + + private AlignmentSorter() + { + // private singleton + } + + private static AlignmentSorter getInstance() + { + return (AlignmentSorter) ApplicationSingletonProvider + .getInstance(AlignmentSorter.class); + } + + /** + * types of feature ordering: Sort by score : average score - or total score - + * over all features in region Sort by feature label text: (or if null - + * feature type text) - numerical or alphabetical Sort by feature density: + * based on counts - ignoring individual text or scores for each feature + */ + public static final String FEATURE_SCORE = "average_score"; + + public static final String FEATURE_LABEL = "text"; + + public static final String FEATURE_DENSITY = "density"; + /* * todo: refactor searches to follow a basic pattern: (search property, last * search state, current sort direction) */ - static boolean sortIdAscending = true; + boolean sortIdAscending = true; - static int lastGroupHash = 0; + int lastGroupHash = 0; - static boolean sortGroupAscending = true; + boolean sortGroupAscending = true; - static AlignmentOrder lastOrder = null; + AlignmentOrder lastOrder = null; - static boolean sortOrderAscending = true; + boolean sortOrderAscending = true; - static TreeModel lastTree = null; + TreeModel lastTree = null; - static boolean sortTreeAscending = true; + boolean sortTreeAscending = true; - /* + + /** * last Annotation Label used for sort by Annotation score */ - private static String lastSortByAnnotation; + private String lastSortByAnnotation; - /* - * string hash of last arguments to sortByFeature - * (sort order toggles if this is unchanged between sorts) + /** + * string hash of last arguments to sortByFeature (sort order toggles if this + * is unchanged between sorts) */ - private static String sortByFeatureCriteria; + private String sortByFeatureCriteria; - private static boolean sortByFeatureAscending = true; + private boolean sortByFeatureAscending = true; - private static boolean sortLengthAscending; + private boolean sortLengthAscending; /** * Sorts sequences in the alignment by Percentage Identity with the given @@ -222,7 +249,8 @@ public class AlignmentSorter QuickSort.sort(ids, seqs); - if (sortIdAscending) + AlignmentSorter as = getInstance(); + if (as.sortIdAscending) { setReverseOrder(align, seqs); } @@ -231,7 +259,7 @@ public class AlignmentSorter setOrder(align, seqs); } - sortIdAscending = !sortIdAscending; + as.sortIdAscending = !as.sortIdAscending; } /** @@ -255,7 +283,9 @@ public class AlignmentSorter QuickSort.sort(length, seqs); - if (sortLengthAscending) + AlignmentSorter as = getInstance(); + + if (as.sortLengthAscending) { setReverseOrder(align, seqs); } @@ -264,7 +294,7 @@ public class AlignmentSorter setOrder(align, seqs); } - sortLengthAscending = !sortLengthAscending; + as.sortLengthAscending = !as.sortLengthAscending; } /** @@ -281,14 +311,16 @@ public class AlignmentSorter // ORDERS BY GROUP SIZE List groups = new ArrayList<>(); - if (groups.hashCode() != lastGroupHash) + AlignmentSorter as = getInstance(); + + if (groups.hashCode() != as.lastGroupHash) { - sortGroupAscending = true; - lastGroupHash = groups.hashCode(); + as.sortGroupAscending = true; + as.lastGroupHash = groups.hashCode(); } else { - sortGroupAscending = !sortGroupAscending; + as.sortGroupAscending = !as.sortGroupAscending; } // SORTS GROUPS BY SIZE @@ -328,7 +360,7 @@ public class AlignmentSorter } } - if (sortGroupAscending) + if (as.sortGroupAscending) { setOrder(align, seqs); } @@ -401,16 +433,18 @@ public class AlignmentSorter // Get an ordered vector of sequences which may also be present in align List tmp = order.getOrder(); - if (lastOrder == order) + AlignmentSorter as = getInstance(); + + if (as.lastOrder == order) { - sortOrderAscending = !sortOrderAscending; + as.sortOrderAscending = !as.sortOrderAscending; } else { - sortOrderAscending = true; + as.sortOrderAscending = true; } - if (sortOrderAscending) + if (as.sortOrderAscending) { setOrder(align, tmp); } @@ -473,18 +507,20 @@ public class AlignmentSorter { List tmp = getOrderByTree(align, tree); + AlignmentSorter as = getInstance(); + // tmp should properly permute align with tree. - if (lastTree != tree) + if (as.lastTree != tree) { - sortTreeAscending = true; - lastTree = tree; + as.sortTreeAscending = true; + as.lastTree = tree; } else { - sortTreeAscending = !sortTreeAscending; + as.sortTreeAscending = !as.sortTreeAscending; } - if (sortTreeAscending) + if (as.sortTreeAscending) { setOrder(align, tmp); } @@ -586,7 +622,7 @@ public class AlignmentSorter for (int i = 0; i < alignment.length; i++) { - ids[i] = (Float.valueOf(alignment[i].getName().substring(8))) + ids[i] = (new Float(alignment[i].getName().substring(8))) .floatValue(); } @@ -658,9 +694,12 @@ public class AlignmentSorter } jalview.util.QuickSort.sort(scores, seqs); - if (lastSortByAnnotation != scoreLabel) + + AlignmentSorter as = getInstance(); + + if (as.lastSortByAnnotation != scoreLabel) { - lastSortByAnnotation = scoreLabel; + as.lastSortByAnnotation = scoreLabel; setOrder(alignment, seqs); } else @@ -670,18 +709,6 @@ public class AlignmentSorter } /** - * types of feature ordering: Sort by score : average score - or total score - - * over all features in region Sort by feature label text: (or if null - - * feature type text) - numerical or alphabetical Sort by feature density: - * based on counts - ignoring individual text or scores for each feature - */ - public static String FEATURE_SCORE = "average_score"; - - public static String FEATURE_LABEL = "text"; - - public static String FEATURE_DENSITY = "density"; - - /** * Sort sequences by feature score or density, optionally restricted by * feature types, feature groups, or alignment start/end positions. *

@@ -809,6 +836,8 @@ public class AlignmentSorter } } + boolean doSort = false; + if (FEATURE_SCORE.equals(method)) { if (hasScores == 0) @@ -834,7 +863,7 @@ public class AlignmentSorter } } } - QuickSort.sortByDouble(scores, seqs, sortByFeatureAscending); + doSort = true; } else if (FEATURE_DENSITY.equals(method)) { @@ -846,9 +875,12 @@ public class AlignmentSorter // System.err.println("Sorting on Density: seq "+seqs[i].getName()+ // " Feats: "+featureCount+" Score : "+scores[i]); } - QuickSort.sortByDouble(scores, seqs, sortByFeatureAscending); + doSort = true; + } + if (doSort) + { + QuickSort.sortByDouble(scores, seqs, getInstance().sortByFeatureAscending); } - setOrder(alignment, seqs); } @@ -883,16 +915,17 @@ public class AlignmentSorter /* * if resorting on the same criteria, toggle sort order */ - if (sortByFeatureCriteria == null - || !scoreCriteria.equals(sortByFeatureCriteria)) + AlignmentSorter as = getInstance(); + if (as.sortByFeatureCriteria == null + || !scoreCriteria.equals(as.sortByFeatureCriteria)) { - sortByFeatureAscending = true; + as.sortByFeatureAscending = true; } else { - sortByFeatureAscending = !sortByFeatureAscending; + as.sortByFeatureAscending = !as.sortByFeatureAscending; } - sortByFeatureCriteria = scoreCriteria; + as.sortByFeatureCriteria = scoreCriteria; } } diff --git a/src/jalview/analysis/scoremodels/ScoreModels.java b/src/jalview/analysis/scoremodels/ScoreModels.java index ebc9a26..8700ec0 100644 --- a/src/jalview/analysis/scoremodels/ScoreModels.java +++ b/src/jalview/analysis/scoremodels/ScoreModels.java @@ -22,6 +22,8 @@ package jalview.analysis.scoremodels; import jalview.api.AlignmentViewPanel; import jalview.api.analysis.ScoreModelI; +import jalview.bin.ApplicationSingletonProvider; +import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI; import jalview.io.DataSourceType; import jalview.io.FileParse; import jalview.io.ScoreMatrixFile; @@ -33,18 +35,8 @@ import java.util.Map; /** * A class that can register and serve instances of ScoreModelI */ -public class ScoreModels +public class ScoreModels implements ApplicationSingletonI { - private final ScoreMatrix BLOSUM62; - - private final ScoreMatrix PAM250; - - private final ScoreMatrix DNA; - - private static ScoreModels instance; - - private Map models; - /** * Answers the singleton instance of this class, with lazy initialisation * (built-in score models are loaded on the first call to this method) @@ -53,11 +45,7 @@ public class ScoreModels */ public static ScoreModels getInstance() { - if (instance == null) - { - instance = new ScoreModels(); - } - return instance; + return (ScoreModels) ApplicationSingletonProvider.getInstance(ScoreModels.class); } /** @@ -84,6 +72,14 @@ public class ScoreModels registerScoreModel(new FeatureDistanceModel()); } + private final ScoreMatrix BLOSUM62; + + private final ScoreMatrix PAM250; + + private final ScoreMatrix DNA; + + private Map models; + /** * Tries to load a score matrix from the given resource file, and if * successful, registers it. @@ -153,7 +149,7 @@ public class ScoreModels */ public void reset() { - instance = new ScoreModels(); + ApplicationSingletonProvider.removeInstance(this.getClass()); } /** diff --git a/src/jalview/bin/ApplicationSingletonProvider.java b/src/jalview/bin/ApplicationSingletonProvider.java new file mode 100644 index 0000000..b64f40c --- /dev/null +++ b/src/jalview/bin/ApplicationSingletonProvider.java @@ -0,0 +1,163 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ +package jalview.bin; + +import jalview.util.Platform; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.Map; + +/** + * A class to hold singleton objects, whose scope (context) is + *

    + *
  • the Java runtime (JVM) when running as Java
  • + *
  • one 'applet', when running as JalviewJS
  • + *
+ * This allows separation of multiple JS applets running on the same browser + * page, each with their own 'singleton' instances. + *

+ * Instance objects are held in a separate Map (keyed by Class) for each + * context. For Java, this is just a single static Map. For SwingJS, the map is + * stored as a field {@code _swingjsSingletons} of + * {@code Thread.currentThread.getThreadGroup()}, as a proxy for the applet. + *

+ * Note that when an applet is stopped, its ThreadGroup is removed, allowing any + * singleton references to be garbage collected. + * + * @author hansonr + */ +public class ApplicationSingletonProvider +{ + /** + * A tagging interface to mark classes whose singleton instances may be served + * by {@code ApplicationSingletonProvider}, giving a distinct instance per JS + * 'applet'. + *

+ * A class whose singleton should have global scope (be shared across all + * applets on a page) should not use this mechanism, but just provide + * a single instance (class static member) in the normal way. + */ + public interface ApplicationSingletonI + { + } + + /* + * Map used to hold singletons in JVM context + */ + private static Map, ApplicationSingletonI> singletons = new HashMap<>(); + + /** + * private constructor for non-instantiable class + */ + private ApplicationSingletonProvider() + { + } + + /** + * Returns the singletons map for the current context (JVM for Java, + * ThreadGroup for JS), creating the map on the first request for each JS + * ThreadGroup + * + * @return + */ + private static Map, ApplicationSingletonI> getContextMap() + { + @SuppressWarnings("unused") + ThreadGroup g = (Platform.isJS() + ? Thread.currentThread().getThreadGroup() + : null); + Map, ApplicationSingletonI> map = singletons; + /** @j2sNative map = g._swingjsSingletons; */ + if (map == null) + { + map = new HashMap<>(); + /** @j2sNative g._swingjsSingletons = map; */ + } + + return map; + } + + /** + * Answers the singleton instance of the given class for the current context + * (JVM or SwingJS 'applet'). If no instance yet exists, one is created, by + * calling the class's no-argument constructor. Answers null if any error + * occurs (or occurred previously for the same class). + * + * @param c + * @return + */ + public static ApplicationSingletonI getInstance(Class c) + { + Map, ApplicationSingletonI> map = getContextMap(); + if (map.containsKey(c)) + { + /* + * singleton already created _or_ creation failed (null value stored) + */ + return map.get(c); + } + + /* + * create and save the singleton + */ + ApplicationSingletonI o = map.get(c); + try + { + Constructor con = c + .getDeclaredConstructor(); + con.setAccessible(true); + o = con.newInstance(); + } catch (IllegalAccessException | InstantiationException + | IllegalArgumentException | InvocationTargetException + | NoSuchMethodException | SecurityException e) + { + Cache.log.error("Failed to create singleton for " + c.toString() + + ", error was: " + e.toString()); + e.printStackTrace(); + } + + /* + * store the new singleton; note that a + * null value is saved if construction failed + */ + getContextMap().put(c, o); + return o; + } + + /** + * Removes the current singleton instance of the given class from the current + * application context. This has the effect of ensuring that a new instance is + * created the next time one is requested. + * + * @param c + */ + public static void removeInstance( + Class c) + { + Map, ApplicationSingletonI> map = getContextMap(); + if (map != null) + { + map.remove(c); + } + } +} diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 2c8986c..bb26c13 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -20,6 +20,7 @@ */ package jalview.bin; +import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI; import jalview.datamodel.PDBEntry; import jalview.gui.UserDefinedColours; import jalview.schemes.ColourSchemeLoader; @@ -208,8 +209,26 @@ 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 + * tied to the applet's ThreadGroup. + * + * @return + */ + public static Cache getInstance() + { + return (Cache) ApplicationSingletonProvider.getInstance(Cache.class); + } + /** * property giving log4j level for CASTOR loggers */ @@ -266,7 +285,7 @@ public class Cache public static Logger log; /** Jalview Properties */ - private static Properties applicationProperties = new Properties() + private Properties applicationProperties = new Properties() { // override results in properties output in alphabetical order @Override @@ -333,20 +352,14 @@ public class Cache */ public static void loadProperties(String propsFile) { - /* for JalviewJS should be - - getInstance(). - - */ - loadPropertiesImpl(propsFile); - + + getInstance().loadPropertiesImpl(propsFile); + } - private /* JalviewJS should not be static */ - static // - void loadPropertiesImpl(String propsFile) + private void loadPropertiesImpl(String propsFile) { - + propertiesFile = propsFile; if (propsFile == null && !propsAreReadOnly) { @@ -429,9 +442,9 @@ public class Cache } if (authorDetails == null) { - applicationProperties.remove("AUTHORS"); - applicationProperties.remove("AUTHORFNAMES"); - applicationProperties.remove("YEAR"); + applicationProperties.remove("AUTHORS"); + applicationProperties.remove("AUTHORFNAMES"); + applicationProperties.remove("YEAR"); } loadBuildProperties(false); @@ -464,7 +477,8 @@ public class Cache String jnlpVersion = System.getProperty("jalview.version"); - // jnlpVersion will be null if a latest version check for the channel needs to + // jnlpVersion will be null if a latest version check for the channel needs + // to // be done // Dont do this check if running in headless mode @@ -557,8 +571,8 @@ public class Cache url = Cache.class.getResource(resourcePath).toString(); } catch (Exception ex) { - System.err.println("Failed to resolve resource " + resourcePath + ": " - + ex.getMessage()); + System.err.println("Failed to resolve resource " + resourcePath + + ": " + ex.getMessage()); } } else @@ -569,7 +583,7 @@ public class Cache return url; } - public static void loadBuildProperties(boolean reportVersion) + public void loadBuildProperties(boolean reportVersion) { String codeInstallation = getProperty("INSTALLATION"); boolean printVersion = codeInstallation == null; @@ -607,12 +621,12 @@ public class Cache new BuildDetails(codeVersion, null, codeInstallation); if (printVersion && reportVersion) { - System.out - .println("Jalview Version: " + codeVersion + codeInstallation); + System.out.println( + "Jalview Version: " + codeVersion + codeInstallation); } } - private static void deleteBuildProperties() + private void deleteBuildProperties() { applicationProperties.remove("LATEST_VERSION"); applicationProperties.remove("VERSION"); @@ -634,17 +648,12 @@ public class Cache */ public static String getProperty(String key) { - String prop = /* for JalviewJS should be - - getInstance(). - - */ - applicationProperties.getProperty(key); -// if (prop == null && Platform.isJS()) -// { -// prop = applicationProperties.getProperty(Platform.getUniqueAppletID() -// + "_" + JS_PROPERTY_PREFIX + key); -// } + String prop = getInstance().applicationProperties.getProperty(key); + // if (prop == null && Platform.isJS()) + // { + // prop = applicationProperties.getProperty(Platform.getUniqueAppletID() + // + "_" + JS_PROPERTY_PREFIX + key); + // } return prop; } @@ -704,22 +713,7 @@ public class Cache */ public static Object setProperty(String key, String obj) { - Object oldValue = null; - try - { - oldValue = applicationProperties.setProperty(key, obj); - if (propertiesFile != null && !propsAreReadOnly) - { - FileOutputStream out = new FileOutputStream(propertiesFile); - applicationProperties.store(out, "---JalviewX Properties File---"); - out.close(); - } - } catch (Exception ex) - { - System.out.println( - "Error setting property: " + key + " " + obj + "\n" + ex); - } - return oldValue; + return getInstance().setPropertyImpl(key, obj, true); } /** @@ -729,31 +723,24 @@ public class Cache */ public static void removeProperty(String key) { - /* for JalviewJS should be - - getInstance(). - - */ - removePropertyImpl(key, true); + getInstance().removePropertyImpl(key, true); } /** * Removes the named property for the running application, without saving the * properties file * - * BH noting that ColourMenuHelper calls this. If the intent is to save, - * then simply chanet that call to removeProperty(key). + * BH noting that ColourMenuHelper calls this. If the intent is to save, then + * simply chanet that call to removeProperty(key). * * @param key */ public static void removePropertyNoSave(String key) { - /* for JalviewJS should be - + getInstance(). - - */ - removePropertyImpl(key, false); + + removePropertyImpl(key, false); } /** @@ -763,9 +750,7 @@ public class Cache * @param key * @param andSave */ - private /* JalviewJS should not be static */ - static // - void removePropertyImpl(String key, boolean andSave) + private void removePropertyImpl(String key, boolean andSave) { applicationProperties.remove(key); if (andSave) @@ -777,6 +762,15 @@ public class Cache */ public static void saveProperties() { + getInstance().savePropertiesImpl(); + } + + /** + * save the properties to the jalview properties path + */ + private void savePropertiesImpl() + + { if (!propsAreReadOnly) { try @@ -1028,9 +1022,9 @@ public class Cache * @param property * @param colour */ - public static void setColourProperty(String property, Color colour) + public static void setColourPropertyNoSave(String property, Color colour) { - setProperty(property, jalview.util.Format.getHexString(colour)); + setPropertyNoSave(property, jalview.util.Format.getHexString(colour)); } /** @@ -1111,11 +1105,11 @@ public class Cache } if (value == null || value.trim().length() < 1) { - Cache.applicationProperties.remove(propName); + getInstance().applicationProperties.remove(propName); } else { - Cache.applicationProperties.setProperty(propName, value); + getInstance().applicationProperties.setProperty(propName, value); } } @@ -1160,17 +1154,12 @@ public class Cache { if (coloursFound.toString().length() > 1) { - /* for JalviewJS should be - - getInstance(). - - */ setProperty(UserDefinedColours.USER_DEFINED_COLOURS, coloursFound.toString()); } else { - applicationProperties + getInstance().applicationProperties .remove(UserDefinedColours.USER_DEFINED_COLOURS); } } @@ -1201,16 +1190,20 @@ public class Cache public static String getVersionDetailsForConsole() { StringBuilder sb = new StringBuilder(); - sb.append("Jalview Version: " + jalview.bin.Cache.getDefault("VERSION", "TEST")); + sb.append("Jalview Version: " + + jalview.bin.Cache.getDefault("VERSION", "TEST")); sb.append("\n"); sb.append("Jalview Installation: " + jalview.bin.Cache.getDefault("INSTALLATION", "unknown")); sb.append("\n"); - sb.append("Build Date: " + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown")); + sb.append("Build Date: " + + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown")); sb.append("\n"); sb.append("Java version: " + System.getProperty("java.version")); sb.append("\n"); - sb.append(System.getProperty("os.arch") + " " + System.getProperty("os.name") + " " + System.getProperty("os.version")); + sb.append(System.getProperty("os.arch") + " " + + System.getProperty("os.name") + " " + + System.getProperty("os.version")); sb.append("\n"); appendIfNotNull(sb, "Install4j version: ", System.getProperty("sys.install4jVersion"), "\n", null); @@ -1218,7 +1211,9 @@ public class Cache System.getProperty("installer_template_version"), "\n", null); appendIfNotNull(sb, "Launcher version: ", System.getProperty("launcher_version"), "\n", null); - if (jalview.bin.Cache.getDefault("VERSION", "TEST").equals("DEVELOPMENT")) { + if (jalview.bin.Cache.getDefault("VERSION", "TEST") + .equals("DEVELOPMENT")) + { appendIfNotNull(sb, "Getdown appdir: ", System.getProperty("getdownappdir"), "\n", null); appendIfNotNull(sb, "Java home: ", System.getProperty("java.home"), @@ -1237,10 +1232,11 @@ public class Cache // eg 'built from Source' or update channel return jalview.bin.Cache.getDefault("INSTALLATION", "unknown"); } - + /** * - * For AppletParams and Preferences ok_actionPerformed and startupFileTextfield_mouseClicked + * For AppletParams and Preferences ok_actionPerformed and + * startupFileTextfield_mouseClicked * * Sets a property value for the running application, without saving it to the * properties file @@ -1250,12 +1246,7 @@ public class Cache */ public static void setPropertyNoSave(String key, String obj) { - /* for JalviewJS should be - - getInstance(). - - */ - setPropertyImpl(key, obj, false); + getInstance().setPropertyImpl(key, obj, false); } /** @@ -1267,7 +1258,8 @@ public class Cache * @param andSave * @return */ - private /* for JalviewJS should not be static */ static Object setPropertyImpl(String key, String obj, boolean andSave) + private Object setPropertyImpl( + String key, String obj, boolean andSave) { Object oldValue = null; try @@ -1287,6 +1279,4 @@ public class Cache return oldValue; } - - } diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index f23ebfa..a3f934c 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -305,7 +305,7 @@ public class Jalview implements JalviewJSApi } // report Jalview version - Cache.loadBuildProperties(true); + Cache.getInstance().loadBuildProperties(true); ArgsParser aparser = new ArgsParser(args); headless = false; diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index dc274e9..2354072 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -781,16 +781,16 @@ public class Preferences extends GPreferences protColour.getSelectedItem().toString()); Cache.setPropertyNoSave(DEFAULT_COLOUR_NUC, nucColour.getSelectedItem().toString()); - Cache.setColourProperty("ANNOTATIONCOLOUR_MIN", + Cache.setColourPropertyNoSave("ANNOTATIONCOLOUR_MIN", minColour.getBackground()); - Cache.setColourProperty("ANNOTATIONCOLOUR_MAX", + Cache.setColourPropertyNoSave("ANNOTATIONCOLOUR_MAX", maxColour.getBackground()); /* * Save Overview settings */ - Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground()); - Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground()); + Cache.setColourPropertyNoSave(GAP_COLOUR, gapColour.getBackground()); + Cache.setColourPropertyNoSave(HIDDEN_COLOUR, hiddenColour.getBackground()); Cache.setPropertyNoSave(USE_LEGACY_GAP, Boolean.toString(useLegacyGap.isSelected())); Cache.setPropertyNoSave(SHOW_OV_HIDDEN_AT_START, -- 1.7.10.2