X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FSequenceRenderer.java;h=69db54d3b00590f249de23480df4944af244a9ab;hb=8220e64aa2718d0f81f39a93df46c3f2265a9fa4;hp=e8cf340051d669e508f8888ac3080a9dc1c15b55;hpb=10c6c64a1ad5f2f4ebd75dc0a4eb3c0dbc9798d5;p=jalview.git diff --git a/src/jalview/gui/SequenceRenderer.java b/src/jalview/gui/SequenceRenderer.java index e8cf340..69db54d 100755 --- a/src/jalview/gui/SequenceRenderer.java +++ b/src/jalview/gui/SequenceRenderer.java @@ -11,7 +11,9 @@ public class SequenceRenderer implements RendererI FontMetrics fm; boolean renderGaps = true; SequenceGroup currentSequenceGroup = null; - Color color; + SequenceGroup [] allGroups = null; + Color resBoxColour; + Graphics graphics; public SequenceRenderer(AlignViewport av) { @@ -26,101 +28,74 @@ public class SequenceRenderer implements RendererI public Color getResidueBoxColour(ColourSchemeI cs, SequenceI seq, int i) { - Color c = Color.white; - - if (cs != null) - c = cs.findColour(seq, seq.getSequence(i, i + 1), i, av.getConsensus(false)); + getBoxColour(cs, seq, i); + return resBoxColour; + } - return c; + void getBoxColour(ColourSchemeI cs, SequenceI seq, int i) + { + if (cs != null) + resBoxColour = cs.findColour(seq.getSequence(i, i + 1), i, av.getConsensus(false)); + else + resBoxColour = Color.white; } - public void drawSequence(Graphics g,SequenceI seq,SequenceGroup sg, int start, int end, int x1, int y1, int width, int height, Vector pid, int seqnum) + public void drawSequence(Graphics g,SequenceI seq,SequenceGroup [] sg, int start, int end, int x1, int y1, int width, int height, Vector pid, int seqnum) { - currentSequenceGroup = sg; + allGroups = sg; + + graphics = g; - drawBoxes(g, seq, start, end, x1, y1, (int) width, height, pid); + drawBoxes(seq, start, end, x1, y1, (int) width, height, pid); fm = g.getFontMetrics(); - drawText(g,seq,start,end,x1,y1,(int)width,height); + drawText(seq,start,end,x1,y1,(int)width,height); } - public void drawBoxes(Graphics g, SequenceI seq,int start, int end, int x1, int y1, int width, int height,Vector freq) { + public void drawBoxes(SequenceI seq,int start, int end, int x1, int y1, int width, int height,Vector freq) { int i = start; int length = seq.getLength(); - Color currentColor = Color.WHITE; - int curStart = x1; int curWidth = width; - // int threshold = 80; - + Color tempColour = null; while (i <= end && i < length) { - color = color.white; - if(inCurrentSequenceGroup(i)) { if( currentSequenceGroup.getDisplayBoxes()) - color = getResidueBoxColour(currentSequenceGroup.cs, seq, i); + getBoxColour(currentSequenceGroup.cs, seq, i); } else if(av.getShowBoxes()) - color = getResidueBoxColour(av.getGlobalColourScheme(), seq, i); - + getBoxColour(av.getGlobalColourScheme(), seq, i); + else + resBoxColour = Color.white; - // Hashtable hash = (Hashtable)freq.elementAt(i-start); - // String s = (String)hash.get("maxResidue"); - // int count = ((Integer)hash.get("maxCount")).intValue(); - // int max = ((Integer)hash.get("size")).intValue(); - // int nongap = ((Integer)hash.get("nongap")).intValue(); - // float frac = (float)(count*1.0/(1.0*nongap)); - //System.out.println("Frac/count/nongap " + frac + " " + count + " " + nongap); - /* if (!seq.getSequence().substring(i,i+1).equals(s) || - s.equals("-") || - s.equals(".") || - s.equals(" ")) - { - c = Color.white; - } else { - if (frac > 0.9) { - c = Color.red; - } else if (frac > 0.8) { - c = Color.orange; - } else if (frac > 0.7) { - c = Color.pink; - } else if (frac > 0.5) { - c = Color.yellow; - } else if (frac> 0.3) { - c = Color.lightGray; - } - }*/ - - if (color != currentColor || color != null) + if (resBoxColour != tempColour) { - g.fillRect(x1+width*(curStart-start),y1,curWidth,height); - - currentColor = color; - g.setColor(color); + graphics.fillRect(x1+width*(curStart-start),y1,curWidth,height); + graphics.setColor(resBoxColour); curStart = i; curWidth = width; + tempColour = resBoxColour; + } else curWidth += width; i++; } - g.fillRect(x1+width*(curStart-start),y1,curWidth,height); + graphics.fillRect(x1+width*(curStart-start),y1,curWidth,height); } - public void drawText(Graphics g, SequenceI seq,int start, int end, int x1, int y1, int width, int height) + public void drawText(SequenceI seq,int start, int end, int x1, int y1, int width, int height) { int pady = height/5; int charOffset=0; - g.setColor(Color.black); - char s; // Need to find the sequence position here. for (int i = start; i <= end; i++) @@ -130,18 +105,21 @@ public class SequenceRenderer implements RendererI else s = ' '; - if(!renderGaps && (s=='-' || s=='.' || s==' ')) + if(!renderGaps && jalview.util.Comparison.isGap(s)) continue; - g.setColor(Color.black); + graphics.setColor(Color.black); if (inCurrentSequenceGroup(i)) { if(!currentSequenceGroup.getDisplayText()) continue; - if(currentSequenceGroup.getColourText()) - g.setColor(getResidueBoxColour(currentSequenceGroup.cs, seq, i).darker()); + if (currentSequenceGroup.getColourText()) + { + getBoxColour(currentSequenceGroup.cs, seq, i); + graphics.setColor(resBoxColour.darker()); + } } else { @@ -149,11 +127,14 @@ public class SequenceRenderer implements RendererI continue; if(av.getColourText()) - g.setColor(getResidueBoxColour(av.getGlobalColourScheme(), seq, i).darker()); + { + getBoxColour(av.getGlobalColourScheme(), seq, i); + graphics.setColor(resBoxColour.darker()); + } } charOffset = (width - fm.charWidth(s))/2; - g.drawString(String.valueOf(s), charOffset + x1 + width * (i - start), y1 + height - pady); + graphics.drawString(String.valueOf(s), charOffset + x1 + width * (i - start), y1 + height - pady); } @@ -161,19 +142,26 @@ public class SequenceRenderer implements RendererI boolean inCurrentSequenceGroup(int res) { - if(currentSequenceGroup==null) + if(allGroups ==null) return false; - return (currentSequenceGroup.getStartRes()<=res && currentSequenceGroup.getEndRes()>=res)?true:false; + for(int i=0; i=res) + { + currentSequenceGroup = allGroups[i]; + return true; + } + + return false; } - public void drawHighlightedText(Graphics g, SequenceI seq,int start, int end, int x1, int y1, int width, int height) + public void drawHighlightedText(SequenceI seq,int start, int end, int x1, int y1, int width, int height) { int pady = height/5; int charOffset=0; - g.setColor(Color.BLACK); - g.fillRect(x1,y1,width*(end-start+1),height); - g.setColor(Color.white); + graphics.setColor(Color.BLACK); + graphics.fillRect(x1,y1,width*(end-start+1),height); + graphics.setColor(Color.white); char s='~'; // Need to find the sequence position here. @@ -183,7 +171,7 @@ public class SequenceRenderer implements RendererI s = seq.getSequence().charAt(i); charOffset = (width - fm.charWidth(s))/2; - g.drawString(String.valueOf(s), charOffset + x1 + width * (i - start), y1 + height - pady); + graphics.drawString(String.valueOf(s), charOffset + x1 + width * (i - start), y1 + height - pady); } }