package jalview.gui;
+import jalview.bin.Cache;
import jalview.datamodel.AnnotatedCollectionI;
import jalview.schemes.ColourSchemeI;
import jalview.schemes.ColourSchemes;
/*
* scan registered colour schemes (built-in or user-defined
- * and add them to the menu (in the order they were added)
+ * and add them to the menu (in the order they were registered)
*/
Iterable<ColourSchemeI> colourSchemes = ColourSchemes.getInstance()
.getColourSchemes();
JvOptionPane.YES_NO_OPTION);
if (option == JvOptionPane.YES_OPTION)
{
- UserDefinedColours.removeColourFromDefaults(radioItem
- .getName());
ColourSchemes.getInstance().removeColourScheme(
radioItem.getName());
colourMenu.remove(radioItem);
+ updatePreferences();
}
else
{
setColourSelected(colourMenu, cs == null ? ResidueColourScheme.NONE
: cs.getSchemeName());
}
+
+ /**
+ * Updates the USER_DEFINE_COLOURS preference to remove any de-registered
+ * colour scheme
+ */
+ static void updatePreferences()
+ {
+ StringBuilder coloursFound = new StringBuilder();
+ String[] files = Cache.getProperty("USER_DEFINED_COLOURS").split("\\|");
+
+ /*
+ * the property does not include the scheme name, it is in the file;
+ * so just load the colour schemes and discard any whose name is not
+ * registered
+ */
+ for (String file : files)
+ {
+ try
+ {
+ UserColourScheme ucs = ColourSchemes.loadColourScheme(file);
+ if (ucs != null
+ && ColourSchemes.getInstance().nameExists(ucs.getName()))
+ {
+ if (coloursFound.length() > 0)
+ {
+ coloursFound.append("|");
+ }
+ coloursFound.append(file);
+ }
+ } catch (Exception ex)
+ {
+ System.out.println("Error loading User ColourFile\n" + ex);
+ }
+ }
+
+ if (coloursFound.toString().length() > 1)
+ {
+ Cache.setProperty("USER_DEFINED_COLOURS", coloursFound.toString());
+ }
+ else
+ {
+ Cache.applicationProperties.remove("USER_DEFINED_COLOURS");
+ }
+ }
}