X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fbin%2FCache.java;h=9363c233c17ebe530e8ee62cf39f80a809a01a5b;hb=7d6bf4ac01167499c0f4e07de63edcdd72a6d595;hp=00c8b86fbd116038da11e4b864a77ec6e55c08df;hpb=3ea56b3730e5115138af264f5b5408104ebd9c20;p=jalview.git diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 00c8b86..9363c23 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -21,7 +21,11 @@ package jalview.bin; import jalview.datamodel.PDBEntry; +import jalview.gui.UserDefinedColours; +import jalview.schemes.ColourSchemes; +import jalview.schemes.UserColourScheme; import jalview.structure.StructureImportSettings; +import jalview.util.ColorUtils; import jalview.ws.dbsources.das.api.DasSourceRegistryI; import jalview.ws.dbsources.das.datamodel.DasSourceRegistry; import jalview.ws.sifts.SiftsSettings; @@ -40,6 +44,7 @@ import java.util.Date; import java.util.Enumeration; import java.util.Locale; import java.util.Properties; +import java.util.StringTokenizer; import java.util.TreeSet; import org.apache.log4j.ConsoleAppender; @@ -228,7 +233,7 @@ public class Cache private final static String DEFAULT_CACHE_THRESHOLD_IN_DAYS = "2"; private final static String DEFAULT_FAIL_SAFE_PID_THRESHOLD = "30"; - + /** * Allowed values are PDB or mmCIF */ @@ -526,7 +531,7 @@ public class Cache setProperty("VERSION", codeVersion); // LOAD USERDEFINED COLOURS - jalview.gui.UserDefinedColours + jalview.bin.Cache .initUserColourSchemes(getProperty("USER_DEFINED_COLOURS")); jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER", false); @@ -868,19 +873,11 @@ public class Cache { return defcolour; } - Color col = jalview.schemes.ColourSchemeProperty - .getAWTColorFromName(colprop); + Color col = ColorUtils.parseColourString(colprop); if (col == null) { - try - { - col = new jalview.schemes.UserColourScheme(colprop).findColour('A'); - } catch (Exception ex) - { - log.warn("Couldn't parse '" + colprop + "' as a colour for " - + property); - col = null; - } + log.warn("Couldn't parse '" + colprop + "' as a colour for " + + property); } return (col == null) ? defcolour : col; } @@ -895,7 +892,7 @@ public class Cache { setProperty(property, jalview.util.Format.getHexString(colour)); } - + /** * Stores a formatted date in a jalview property, using a fixed locale. * @@ -997,4 +994,54 @@ public class Cache Cache.applicationProperties.setProperty(propName, value); } } + + /** + * Loads in user colour schemes from files. + * + * @param files + * a '|'-delimited list of file paths + */ + public static void initUserColourSchemes(String files) + { + if (files == null || files.length() == 0) + { + return; + } + + // In case colours can't be loaded, we'll remove them + // from the default list here. + StringBuffer coloursFound = new StringBuffer(); + StringTokenizer st = new StringTokenizer(files, "|"); + while (st.hasMoreElements()) + { + String file = st.nextToken(); + try + { + UserColourScheme ucs = ColourSchemes.loadColourScheme(file); + if (ucs != null) + { + if (coloursFound.length() > 0) + { + coloursFound.append("|"); + } + coloursFound.append(file); + ColourSchemes.getInstance().registerColourScheme(ucs); + } + } catch (Exception ex) + { + System.out.println("Error loading User ColourFile\n" + ex); + } + } + if (!files.equals(coloursFound.toString())) + { + if (coloursFound.toString().length() > 1) + { + setProperty(UserDefinedColours.USER_DEFINED_COLOURS, coloursFound.toString()); + } + else + { + applicationProperties.remove(UserDefinedColours.USER_DEFINED_COLOURS); + } + } + } }