X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fext%2Frbvi%2Fchimera%2FChimeraCommands.java;h=d3c8c0950b4f7def85e5d0f226edbdb3baedd718;hb=5a98fbf31c418758a11bbf8f54d5def7e509bb31;hp=41c7abbf251beda9f67558e735ece5d708fc795e;hpb=ae216fceddd8539d20fa5425cdaef3da73aba8f0;p=jalview.git diff --git a/src/jalview/ext/rbvi/chimera/ChimeraCommands.java b/src/jalview/ext/rbvi/chimera/ChimeraCommands.java index 41c7abb..d3c8c09 100644 --- a/src/jalview/ext/rbvi/chimera/ChimeraCommands.java +++ b/src/jalview/ext/rbvi/chimera/ChimeraCommands.java @@ -32,6 +32,7 @@ import jalview.util.Format; import java.awt.Color; import java.util.ArrayList; +import java.util.Hashtable; /** * Routines for generating Chimera commands for Jalview/Chimera binding @@ -56,7 +57,7 @@ public class ChimeraCommands { ArrayList cset = new ArrayList(); - + Hashtable colranges=new Hashtable(); for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++) { float cols[] = new float[4]; @@ -101,22 +102,7 @@ public class ChimeraCommands { if (lastCol != null) { - - lastCol.getRGBComponents(cols); - String newSelcom = "color " + cols[0] + "," + cols[1] - + "," + cols[2] + " #" + startModel + ":" - + startPos + "-" + lastPos + "." + lastChain; - if (str.size() > 0 - && (str.get(str.size() - 1).length() + newSelcom - .length()) < 4096) - { - str.set(str.size() - 1, str.get(str.size() - 1) + ";" - + newSelcom); - } - else - { - str.add(newSelcom); - } + addColourRange(colranges, lastCol,startModel,startPos,lastPos,lastChain); } lastCol = null; startPos = pos; @@ -131,32 +117,42 @@ public class ChimeraCommands // final colour range if (lastCol != null) { - - lastCol.getRGBComponents(cols); - String newSelcom = "color " + cols[0] + "," + cols[1] + "," - + cols[2] + " #" + startModel + ":" + startPos + "-" - + lastPos + "." + lastChain; - if (str.size() > 0 - && (str.get(str.size() - 1).length() + newSelcom - .length()) < 4096) - { - str.set(str.size() - 1, str.get(str.size() - 1) + ";" - + newSelcom); - } - else - { - str.add(newSelcom); - } + addColourRange(colranges, lastCol,startModel,startPos,lastPos,lastChain); } break; } } } // Finally, add the command set ready to be returned. + StringBuffer coms=new StringBuffer(); + for (String cr:colranges.keySet()) + { + coms.append("color #"+cr+" "+colranges.get(cr)+";"); + } cset.add(new StructureMappingcommandSet(ChimeraCommands.class, - files[pdbfnum], str.toArray(new String[str.size()]))); + files[pdbfnum], new String[] { coms.toString() })); } return cset.toArray(new StructureMappingcommandSet[cset.size()]); } + private static void addColourRange(Hashtable colranges, Color lastCol, int startModel, + int startPos, int lastPos, String lastChain) + { + + String colstring = ((lastCol.getRed()< 16) ? "0":"")+Integer.toHexString(lastCol.getRed()) + + ((lastCol.getGreen()< 16) ? "0":"")+Integer.toHexString(lastCol.getGreen()) + + ((lastCol.getBlue()< 16) ? "0":"")+Integer.toHexString(lastCol.getBlue()); + StringBuffer currange = colranges.get(colstring); + if (currange==null) + { + colranges.put(colstring,currange = new StringBuffer()); + } + if (currange.length()>0) + { + currange.append("|"); + } + currange.append("#" + startModel + ":" + ((startPos==lastPos) ? startPos : startPos + "-" + + lastPos) + "." + lastChain); + } + }