Allows loading of archive XML
authoramwaterhouse <Andrew Waterhouse>
Tue, 4 Apr 2006 09:31:05 +0000 (09:31 +0000)
committeramwaterhouse <Andrew Waterhouse>
Tue, 4 Apr 2006 09:31:05 +0000 (09:31 +0000)
src/jalview/gui/UserDefinedColours.java

index 556ae41..ede020c 100755 (executable)
@@ -423,10 +423,14 @@ public class UserDefinedColours extends GUserDefinedColours
             InputStreamReader in = new InputStreamReader(new FileInputStream(\r
                         file), "UTF-8");\r
 \r
-            jalview.binding.JalviewUserColours jucs = new jalview.binding.JalviewUserColours();\r
-            jucs = (jalview.binding.JalviewUserColours) jucs.unmarshal(in);\r
+              jalview.schemabinding.version2.JalviewUserColours jucs\r
+                  = new jalview.schemabinding.version2.JalviewUserColours();\r
 \r
-            newColours = new Color[jucs.getColourCount()];\r
+              org.exolab.castor.xml.Unmarshaller unmar\r
+                  = new org.exolab.castor.xml.Unmarshaller(jucs);\r
+              jucs = (jalview.schemabinding.version2.JalviewUserColours) unmar.unmarshal( in );\r
+\r
+              newColours = new Color[jucs.getColourCount()];\r
 \r
             for (int i = 0; i < 24; i++)\r
             {\r
@@ -442,9 +446,34 @@ public class UserDefinedColours extends GUserDefinedColours
         }\r
         catch (Exception ex)\r
         {\r
-            System.out.println("Error loading User ColourFile\n"+ex);\r
-        }\r
+            //Could be Archive Jalview format\r
+            try{\r
+              InputStreamReader in = new InputStreamReader(new FileInputStream(\r
+                  file), "UTF-8");\r
+\r
+              jalview.binding.JalviewUserColours jucs\r
+                  = new jalview.binding.JalviewUserColours();\r
+\r
+              jucs = (jalview.binding.JalviewUserColours) jucs.unmarshal(in);\r
 \r
+              newColours = new Color[jucs.getColourCount()];\r
+\r
+              for (int i = 0; i < 24; i++)\r
+              {\r
+                newColours[i] = new Color(Integer.parseInt(\r
+                    jucs.getColour(i).getRGB(), 16));\r
+              }\r
+              if (newColours != null)\r
+              {\r
+                ucs = new UserColourScheme(newColours);\r
+                ucs.setName(jucs.getSchemeName());\r
+              }\r
+            }catch(Exception ex2)\r
+            { ex2.printStackTrace(); }\r
+\r
+            if(newColours==null)\r
+              System.out.println("Error loading User ColourFile\n"+ex);\r
+        }\r
 \r
        return ucs;\r
     }\r