From e92de6ab4f67f594f4ff1e1abeecdb8ac94d5420 Mon Sep 17 00:00:00 2001 From: "j.procter@dundee.ac.uk" Date: Tue, 8 Jul 2014 15:15:11 -0400 Subject: [PATCH] JAL-1333 more efficient color statement --- src/jalview/ext/rbvi/chimera/ChimeraCommands.java | 64 ++++++++++----------- 1 file changed, 30 insertions(+), 34 deletions(-) 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); + } + } -- 1.7.10.2