X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FSequenceRenderer.java;h=7aa89eb1ca4f44b77a575dfbeb2c1a05826f89f6;hb=58ba1562a8a739699ce47a338803b2641f6d7913;hp=7a52bcc7b82803a496931cb4e56b3ba70d7cb4dc;hpb=526094d494484bfa89f9659fccf83a37b8c19829;p=jalview.git diff --git a/src/jalview/gui/SequenceRenderer.java b/src/jalview/gui/SequenceRenderer.java index 7a52bcc..7aa89eb 100755 --- a/src/jalview/gui/SequenceRenderer.java +++ b/src/jalview/gui/SequenceRenderer.java @@ -2,123 +2,188 @@ package jalview.gui; import jalview.datamodel.*; import jalview.schemes.*; - import java.awt.*; import java.util.*; -public class SequenceRenderer implements RendererI +public class SequenceRenderer { + AlignViewport av; FontMetrics fm; + boolean renderGaps = true; + SequenceGroup currentSequenceGroup = null; + SequenceGroup [] allGroups = null; + Color resBoxColour; + Graphics graphics; + + public SequenceRenderer(AlignViewport av) + { + this.av = av; + } - public Color getResidueBoxColour(ColourSchemeI cs, SequenceI seq, int i) { - Color c = cs.findColour(seq, seq.getSequence(i, i + 1), i, null); - return c; + public void renderGaps(boolean b) + { + renderGaps = b; + } + + public Color getResidueBoxColour(ColourSchemeI cs, SequenceI seq, int i) + { + getBoxColour(cs, seq, i); + return resBoxColour; + } + 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) + { + allGroups = sg; - public void drawSequence(Graphics g,ColourSchemeI cs,SequenceI seq,int start, int end, int x1, int y1, double width, int height,boolean showScores, boolean displayBoxes, boolean displayText, boolean colourText,Vector freq, int seqnum) { + graphics = g; + drawBoxes(seq, start, end, x1, y1, (int) width, height); - if (displayBoxes) - drawBoxes(g,cs,seq,start,end,x1,y1,(int)width, height,freq); + fm = g.getFontMetrics(); + drawText(seq,start,end,x1,y1,(int)width,height); - if (displayText) - { - fm = g.getFontMetrics(); - drawText(g,cs,colourText,seq,start,end,x1,y1,(int)width,height); - } } - public void drawBoxes(Graphics g,ColourSchemeI cs, 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; - // int threshold = 80; - - while (i <= end && i < length) { - Color c = getResidueBoxColour(cs,seq,i); + Color tempColour = null; + while (i <= end && i < length) + { + if(inCurrentSequenceGroup(i)) + { + if( currentSequenceGroup.getDisplayBoxes()) + getBoxColour(currentSequenceGroup.cs, seq, i); + } + else if(av.getShowBoxes()) + 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 (c != currentColor || c != null) + if (resBoxColour != tempColour) { - g.fillRect(x1+width*(curStart-start),y1,curWidth,height); - - currentColor = c; - g.setColor(c); + 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, ColourSchemeI cs, boolean colText, 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 < end && i < seq.getLength()) - s = seq.getSequence().charAt(i); - else if(i=res) + { + currentSequenceGroup = allGroups[i]; + return true; + } + + return false; + } + public void drawHighlightedText(SequenceI seq,int start, int end, int x1, int y1, int width, int height) + { + int pady = height/5; + int charOffset=0; + graphics.setColor(Color.BLACK); + graphics.fillRect(x1,y1,width*(end-start+1),height); + graphics.setColor(Color.white); - g.drawString(String.valueOf(s), charOffset + x1 + width * (i - start), y1 + height - pady); + char s='~'; + // Need to find the sequence position here. + for (int i = start; i <= end; i++) + { + if(i