Check default colour is not null
authoramwaterhouse <Andrew Waterhouse>
Wed, 17 Aug 2005 13:03:41 +0000 (13:03 +0000)
committeramwaterhouse <Andrew Waterhouse>
Wed, 17 Aug 2005 13:03:41 +0000 (13:03 +0000)
src/jalview/gui/UserDefinedColours.java

index e85a74c..044069e 100755 (executable)
@@ -336,23 +336,28 @@ public class UserDefinedColours extends GUserDefinedColours
      */\r
     public static UserColourScheme loadDefaultColours()\r
     {\r
+        UserColourScheme ret = null;\r
+\r
         String colours = jalview.bin.Cache.getProperty("USER_DEFINED_COLOURS");\r
-        if ( colours != null)\r
+        if ( colours != null )\r
         {\r
           if(colours.indexOf("|")>-1)\r
             colours = colours.substring(0, colours.indexOf("|"));\r
 \r
-            return loadColours(colours);\r
+          ret = loadColours(colours);\r
         }\r
-        else\r
+\r
+        if(ret == null)\r
         {\r
           Color[] newColours = new Color[24];\r
           for (int i = 0; i < 24; i++)\r
           {\r
             newColours[i] = Color.white;\r
           }\r
-          return new UserColourScheme(newColours);\r
+          ret =  new UserColourScheme(newColours);\r
         }\r
+\r
+        return ret;\r
     }\r
 \r
     /**\r
@@ -517,9 +522,10 @@ public class UserDefinedColours extends GUserDefinedColours
     {\r
       userColourSchemes = new Hashtable();\r
 \r
-      if(files==null)\r
+      if(files==null || files.length()==0)\r
         return;\r
 \r
+\r
       // In case colours can't be loaded, we'll remove them\r
       // from the default list here.\r
       StringBuffer coloursFound = new StringBuffer();\r
@@ -548,4 +554,40 @@ public class UserDefinedColours extends GUserDefinedColours
         jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS", coloursFound.toString());\r
       }\r
     }\r
+\r
+    public static void removeColourFromDefaults(String target)\r
+    {\r
+      // The only way to find colours by name is to load them in\r
+      // In case colours can't be loaded, we'll remove them\r
+      // from the default list here.\r
+\r
+      userColourSchemes = new Hashtable();\r
+\r
+      StringBuffer coloursFound = new StringBuffer();\r
+      StringTokenizer st = new StringTokenizer(\r
+           jalview.bin.Cache.getProperty("USER_DEFINED_COLOURS"), "|");\r
+\r
+      while (st.hasMoreElements())\r
+      {\r
+        String file = st.nextToken();\r
+        try\r
+        {\r
+          UserColourScheme ucs = loadColours(file);\r
+          if (ucs != null && !ucs.getName().equals(target))\r
+          {\r
+            if (coloursFound.length() > 0)\r
+              coloursFound.append("|");\r
+            coloursFound.append(file);\r
+            userColourSchemes.put(ucs.getName(), ucs);\r
+          }\r
+        }\r
+        catch (Exception ex)\r
+        {\r
+          System.out.println("Error loading User ColourFile\n" + ex);\r
+        }\r
+      }\r
+\r
+      jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS", coloursFound.toString());\r
+\r
+    }\r
 }\r