remove property user_defined if none left
[jalview.git] / src / jalview / gui / UserDefinedColours.java
index e85a74c..79df106 100755 (executable)
@@ -68,7 +68,7 @@ public class UserDefinedColours extends GUserDefinedColours
 \r
         if (System.getProperty("os.name").startsWith("Mac"))\r
         {\r
-            frame.setSize(450, 560);\r
+            frame.setSize(760, 370);\r
         }\r
 \r
         if (sg != null)\r
@@ -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
@@ -545,7 +551,50 @@ public class UserDefinedColours extends GUserDefinedColours
       }\r
       if (!files.equals(coloursFound.toString()))\r
       {\r
-        jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS", coloursFound.toString());\r
+        if (coloursFound.toString().length() > 1)\r
+          jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS",\r
+                                        coloursFound.toString());\r
+        else\r
+          jalview.bin.Cache.applicationProperties.remove("USER_DEFINED_COLOURS");\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
+      if (coloursFound.toString().length() > 1)\r
+        jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS", coloursFound.toString());\r
+      else\r
+        jalview.bin.Cache.applicationProperties.remove("USER_DEFINED_COLOURS");\r
+\r
     }\r
 }\r