From 44fd5b65bdaf29b0d4bfd9549bcb086a81211c51 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Wed, 17 Aug 2005 13:03:41 +0000 Subject: [PATCH] Check default colour is not null --- src/jalview/gui/UserDefinedColours.java | 52 ++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/src/jalview/gui/UserDefinedColours.java b/src/jalview/gui/UserDefinedColours.java index e85a74c..044069e 100755 --- a/src/jalview/gui/UserDefinedColours.java +++ b/src/jalview/gui/UserDefinedColours.java @@ -336,23 +336,28 @@ public class UserDefinedColours extends GUserDefinedColours */ public static UserColourScheme loadDefaultColours() { + UserColourScheme ret = null; + String colours = jalview.bin.Cache.getProperty("USER_DEFINED_COLOURS"); - if ( colours != null) + if ( colours != null ) { if(colours.indexOf("|")>-1) colours = colours.substring(0, colours.indexOf("|")); - return loadColours(colours); + ret = loadColours(colours); } - else + + if(ret == null) { Color[] newColours = new Color[24]; for (int i = 0; i < 24; i++) { newColours[i] = Color.white; } - return new UserColourScheme(newColours); + ret = new UserColourScheme(newColours); } + + return ret; } /** @@ -517,9 +522,10 @@ public class UserDefinedColours extends GUserDefinedColours { userColourSchemes = new Hashtable(); - if(files==null) + 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(); @@ -548,4 +554,40 @@ public class UserDefinedColours extends GUserDefinedColours jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS", coloursFound.toString()); } } + + public static void removeColourFromDefaults(String target) + { + // The only way to find colours by name is to load them in + // In case colours can't be loaded, we'll remove them + // from the default list here. + + userColourSchemes = new Hashtable(); + + StringBuffer coloursFound = new StringBuffer(); + StringTokenizer st = new StringTokenizer( + jalview.bin.Cache.getProperty("USER_DEFINED_COLOURS"), "|"); + + while (st.hasMoreElements()) + { + String file = st.nextToken(); + try + { + UserColourScheme ucs = loadColours(file); + if (ucs != null && !ucs.getName().equals(target)) + { + if (coloursFound.length() > 0) + coloursFound.append("|"); + coloursFound.append(file); + userColourSchemes.put(ucs.getName(), ucs); + } + } + catch (Exception ex) + { + System.out.println("Error loading User ColourFile\n" + ex); + } + } + + jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS", coloursFound.toString()); + + } } -- 1.7.10.2