saves usercolours
authoramwaterhouse <Andrew Waterhouse>
Wed, 25 May 2005 16:36:40 +0000 (16:36 +0000)
committeramwaterhouse <Andrew Waterhouse>
Wed, 25 May 2005 16:36:40 +0000 (16:36 +0000)
src/jalview/gui/Jalview2XML.java

index 6b6bd86..3eebf5c 100755 (executable)
@@ -80,6 +80,7 @@ public class Jalview2XML
   {\r
 \r
     Vector seqids = new Vector();\r
+    Vector userColours = new Vector();\r
 \r
     AlignViewport av = af.viewport;\r
 \r
@@ -185,11 +186,15 @@ public class Jalview2XML
 \r
         if (sg.cs instanceof ResidueColourScheme)\r
           groups[i].setPidThreshold( ( (ResidueColourScheme) sg.cs).getThreshold());\r
-       else if (sg.cs instanceof ScoreColourScheme)\r
-         groups[i].setPidThreshold( ( (ScoreColourScheme) sg.cs).getThreshold());\r
+        else if (sg.cs instanceof ScoreColourScheme)\r
+          groups[i].setPidThreshold( ( (ScoreColourScheme) sg.cs).getThreshold());\r
 \r
 \r
-        groups[i].setColour( ColourSchemeProperty.getColourName(sg.cs) );\r
+        if (sg.cs instanceof jalview.schemes.UserColourScheme)\r
+          groups[i].setColour(SetUserColourScheme(sg.cs, userColours, jms));\r
+        else\r
+          groups[i].setColour(ColourSchemeProperty.getColourName(sg.cs));\r
+\r
         groups[i].setOutlineColour(sg.getOutlineColour().getRGB());\r
         groups[i].setDisplayBoxes(sg.getDisplayBoxes());\r
         groups[i].setDisplayText(sg.getDisplayText());\r
@@ -203,7 +208,6 @@ public class Jalview2XML
         }\r
 \r
       }\r
-\r
       jms.setJGroup(groups);\r
 \r
     }\r
@@ -217,6 +221,12 @@ public class Jalview2XML
    view.setHeight(af.getHeight());\r
    view.setStartRes(av.startRes);\r
    view.setStartSeq(av.startSeq);\r
+\r
+\r
+ if( av.getGlobalColourScheme() instanceof jalview.schemes.UserColourScheme)\r
+   view.setBgColour( SetUserColourScheme(av.getGlobalColourScheme(),\r
+                                         userColours, jms) );\r
+ else\r
    view.setBgColour( ColourSchemeProperty.getColourName\r
                      ( av.getGlobalColourScheme()));\r
 \r
@@ -269,6 +279,52 @@ public class Jalview2XML
     }\r
   }\r
 \r
+  static String SetUserColourScheme(jalview.schemes.ColourSchemeI cs,\r
+                                    Vector userColours,\r
+                                    JalviewModelSequence jms)\r
+  {\r
+    String id=null;\r
+    jalview.schemes.UserColourScheme ucs = (jalview.schemes.UserColourScheme)cs;\r
+    if (!userColours.contains(ucs))\r
+    {\r
+      userColours.add(ucs);\r
+      java.awt.Color [] colours = ucs.getColours();\r
+      jalview.binding.UserColours uc = new jalview.binding.UserColours();\r
+      jalview.binding.UserColourScheme jbucs = new jalview.binding.UserColourScheme();\r
+      for(int i=0; i<colours.length; i++)\r
+      {\r
+             jalview.binding.Colour col = new jalview.binding.Colour();\r
+             col.setRGB( jalview.util.Format.getHexString(colours[i]) );\r
+             jbucs.addColour(col);\r
+      }\r
+      id = "ucs"+userColours.indexOf(ucs);\r
+      uc.setId(id);\r
+      uc.setUserColourScheme(jbucs);\r
+      jms.addUserColours(uc);\r
+    }\r
+    return id;\r
+  }\r
+\r
+  static jalview.schemes.UserColourScheme GetUserColourScheme(JalviewModelSequence jms, String id)\r
+  {\r
+    UserColours [] uc = jms.getUserColours();\r
+    UserColours colours=null;\r
+    for(int i=0; i<uc.length; i++)\r
+    {\r
+       if(uc[i].getId().equals(id))\r
+       {  colours = uc[i]; break;  }\r
+    }\r
+    int csize = colours.getUserColourScheme().getColourCount();\r
+    java.awt.Color [] newColours = new java.awt.Color[csize];\r
+\r
+    for(int i=0; i<csize;i++)\r
+      newColours[i] = new java.awt.Color(\r
+        Integer.parseInt( colours.getUserColourScheme().getColour(i).getRGB(), 16) );\r
+\r
+    return  new jalview.schemes.UserColourScheme(newColours);\r
+\r
+  }\r
+\r
 \r
   public static void LoadJalviewAlign(String file)\r
   {\r
@@ -374,7 +430,12 @@ public class Jalview2XML
       JGroup[] groups = jms.getJGroup();\r
       for (int i = 0; i < groups.length; i++)\r
       {\r
-       ColourSchemeI cs = ColourSchemeProperty.getColour(al, groups[i].getColour() );\r
+       ColourSchemeI cs=null;\r
+       if(groups[i].getColour().startsWith("ucs"))\r
+         cs = GetUserColourScheme(jms,groups[i].getColour());\r
+       else\r
+         cs = ColourSchemeProperty.getColour(al, groups[i].getColour() );\r
+\r
        if (cs instanceof ResidueColourScheme)\r
          ( (ResidueColourScheme) cs).setThreshold(groups[i].getPidThreshold());\r
        else if (cs instanceof ScoreColourScheme)\r
@@ -442,12 +503,13 @@ public class Jalview2XML
     af.viewport.setShowBoxes( view.getShowBoxes() );\r
     af.viewport.setShowText( view.getShowText() );\r
 \r
-    af.viewport.setGlobalColourScheme( ColourSchemeProperty.getColour(al, view.getBgColour()));\r
-    af.viewport.setColourAppliesToAllGroups(false);\r
-    af.changeColour( af.viewport.getGlobalColourScheme() );\r
-    af.viewport.setColourAppliesToAllGroups(true);\r
+    ColourSchemeI cs=null;\r
+    if (view.getBgColour().startsWith("ucs"))\r
+      cs = GetUserColourScheme(jms, view.getBgColour());\r
+    else\r
+      cs = ColourSchemeProperty.getColour(al, view.getBgColour());\r
+    af.viewport.setGlobalColourScheme( cs );\r
 \r
-    ColourSchemeI cs = af.viewport.getGlobalColourScheme();\r
     if(cs instanceof ConservationColourScheme)\r
       ( (ConservationColourScheme) cs).inc = view.getConsThreshold();\r
 \r
@@ -456,6 +518,11 @@ public class Jalview2XML
     else if (cs instanceof ScoreColourScheme)\r
       ( (ScoreColourScheme) cs).setThreshold(view.getPidThreshold());\r
 \r
+    af.viewport.setColourAppliesToAllGroups(false);\r
+    af.changeColour(af.viewport.getGlobalColourScheme());\r
+    af.viewport.setColourAppliesToAllGroups(true);\r
+\r
+\r
     //LOAD TREES - THIS RELEASE ONLY ALLOWS 1 TREE\r
     if(object.getVamsasModel().getTreeCount()>0)\r
     {\r