From f59f68c0a389bef51cfc9397dc0c4b645be51c05 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Thu, 13 Jan 2005 12:05:10 +0000 Subject: [PATCH] GetResidueBoxColour altered for faster rendering --- src/jalview/gui/SequenceRenderer.java | 71 +++++++++++++++++---------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/src/jalview/gui/SequenceRenderer.java b/src/jalview/gui/SequenceRenderer.java index 5022050..6483e8b 100755 --- a/src/jalview/gui/SequenceRenderer.java +++ b/src/jalview/gui/SequenceRenderer.java @@ -11,7 +11,8 @@ public class SequenceRenderer implements RendererI FontMetrics fm; boolean renderGaps = true; SequenceGroup currentSequenceGroup = null; - Color color; + Color resBoxColour = Color.white; + Graphics graphics; public SequenceRenderer(AlignViewport av) { @@ -26,72 +27,72 @@ public class SequenceRenderer implements RendererI public Color getResidueBoxColour(ColourSchemeI cs, SequenceI seq, int i) { - Color c = Color.white; -try{ - if (cs != null) - c = cs.findColour(seq.getSequence(i, i + 1), i, av.getConsensus(false)); - }catch(Exception ex){} + getBoxColour(cs, seq, i); + return resBoxColour; + } + + void getBoxColour(ColourSchemeI cs, SequenceI seq, int i) + { - return c; + 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) { currentSequenceGroup = sg; - drawBoxes(g, seq, start, end, x1, y1, (int) width, height, pid); + graphics = g; + + 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; + Color tempColour = Color.red; 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); - 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++) @@ -104,7 +105,7 @@ try{ if(!renderGaps && jalview.util.Comparison.isGap(s)) continue; - g.setColor(Color.black); + graphics.setColor(Color.black); if (inCurrentSequenceGroup(i)) { @@ -112,7 +113,7 @@ try{ continue; if(currentSequenceGroup.getColourText()) - g.setColor(getResidueBoxColour(currentSequenceGroup.cs, seq, i).darker()); + graphics.setColor(resBoxColour.darker()); } else { @@ -120,11 +121,11 @@ try{ continue; if(av.getColourText()) - g.setColor(getResidueBoxColour(av.getGlobalColourScheme(), seq, i).darker()); + 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); } @@ -138,13 +139,13 @@ try{ return (currentSequenceGroup.getStartRes()<=res && currentSequenceGroup.getEndRes()>=res)?true: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. @@ -154,7 +155,7 @@ try{ 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); } } -- 1.7.10.2