X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FSequenceRenderer.java;h=54785ef0e4bbc42237350d9ef5367ecbe4e1147b;hb=4932359fd4e14cbe82294b76d66f693cc8d3ffa8;hp=4264c64cb58ff8c4902230b6190328bc5455e9c8;hpb=a11e13d8fffacf8115a4d83e4254bf94a87d6600;p=jalview.git diff --git a/src/jalview/gui/SequenceRenderer.java b/src/jalview/gui/SequenceRenderer.java index 4264c64..54785ef 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,113 +28,90 @@ public class SequenceRenderer implements RendererI public Color getResidueBoxColour(ColourSchemeI cs, SequenceI seq, int i) { - Color c = Color.white; - try{ - c = cs.findColour(seq, seq.getSequence(i, i + 1), i, null); - }catch(Exception ex){} + 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); + 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; - drawBoxes(g, seq, start, end, x1, y1, (int) width, height, pid); + graphics = g; + + drawBoxes(seq, start, end, x1, y1, (int) width, height); 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) { int i = start; int length = seq.getLength(); - Color currentColor = Color.WHITE; - - int curStart = x1; + int curStart = -1; int curWidth = width; - if(currentSequenceGroup!=null && currentSequenceGroup.getDisplayBoxes()) - { - curStart = currentSequenceGroup.getStartRes(); - curWidth = currentSequenceGroup.getEndRes(); - } - - // int threshold = 80; - + Color tempColour = null; while (i <= end && i < length) { if(inCurrentSequenceGroup(i)) { - color = getResidueBoxColour(currentSequenceGroup.cs, seq, i); + if( currentSequenceGroup.getDisplayBoxes()) + getBoxColour(currentSequenceGroup.cs, seq, i); } + else if(av.getShowBoxes()) + getBoxColour(av.getGlobalColourScheme(), seq, i); else - color = getResidueBoxColour(av.getGlobalColourScheme(), seq, i); - - // 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) - { - g.fillRect(x1+width*(curStart-start),y1,curWidth,height); + resBoxColour = Color.white; - currentColor = color; - g.setColor(color); + + if (resBoxColour != tempColour) + { + if(tempColour!=null) + 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. + + graphics.setColor(Color.black); + String sequence = seq.getSequence(); for (int i = start; i <= end; i++) { - if(i=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. @@ -177,8 +180,8 @@ public class SequenceRenderer implements RendererI if(i