3 import jalview.datamodel.*;
\r
4 import jalview.schemes.*;
\r
8 public class SequenceRenderer implements RendererI
\r
12 boolean renderGaps = true;
\r
13 SequenceGroup currentSequenceGroup = null;
\r
16 public SequenceRenderer(AlignViewport av)
\r
22 public void renderGaps(boolean b)
\r
27 public Color getResidueBoxColour(ColourSchemeI cs, SequenceI seq, int i)
\r
29 Color c = Color.white;
\r
31 c = cs.findColour(seq, seq.getSequence(i, i + 1), i, null);
\r
32 }catch(Exception ex){}
\r
37 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)
\r
39 currentSequenceGroup = sg;
\r
41 drawBoxes(g, seq, start, end, x1, y1, (int) width, height, pid);
\r
43 fm = g.getFontMetrics();
\r
44 drawText(g,seq,start,end,x1,y1,(int)width,height);
\r
48 public void drawBoxes(Graphics g, SequenceI seq,int start, int end, int x1, int y1, int width, int height,Vector freq) {
\r
50 int length = seq.getLength();
\r
52 Color currentColor = Color.WHITE;
\r
55 int curWidth = width;
\r
57 // int threshold = 80;
\r
59 while (i <= end && i < length)
\r
61 color = color.white;
\r
63 if(inCurrentSequenceGroup(i))
\r
65 if( currentSequenceGroup.getDisplayBoxes())
\r
66 color = getResidueBoxColour(currentSequenceGroup.cs, seq, i);
\r
68 else if(av.getShowBoxes())
\r
69 color = getResidueBoxColour(av.getGlobalColourScheme(), seq, i);
\r
72 // Hashtable hash = (Hashtable)freq.elementAt(i-start);
\r
73 // String s = (String)hash.get("maxResidue");
\r
74 // int count = ((Integer)hash.get("maxCount")).intValue();
\r
75 // int max = ((Integer)hash.get("size")).intValue();
\r
76 // int nongap = ((Integer)hash.get("nongap")).intValue();
\r
77 // float frac = (float)(count*1.0/(1.0*nongap));
\r
79 //System.out.println("Frac/count/nongap " + frac + " " + count + " " + nongap);
\r
80 /* if (!seq.getSequence().substring(i,i+1).equals(s) ||
\r
89 } else if (frac > 0.8) {
\r
91 } else if (frac > 0.7) {
\r
93 } else if (frac > 0.5) {
\r
95 } else if (frac> 0.3) {
\r
96 c = Color.lightGray;
\r
100 if (color != currentColor || color != null)
\r
102 g.fillRect(x1+width*(curStart-start),y1,curWidth,height);
\r
104 currentColor = color;
\r
115 g.fillRect(x1+width*(curStart-start),y1,curWidth,height);
\r
118 public void drawText(Graphics g, SequenceI seq,int start, int end, int x1, int y1, int width, int height)
\r
120 int pady = height/5;
\r
122 g.setColor(Color.black);
\r
125 // Need to find the sequence position here.
\r
126 for (int i = start; i <= end; i++)
\r
128 if(i<seq.getLength())
\r
129 s = seq.getSequence().charAt(i);
\r
133 if(!renderGaps && (s=='-' || s=='.' || s==' '))
\r
136 g.setColor(Color.black);
\r
138 if (inCurrentSequenceGroup(i))
\r
140 if(!currentSequenceGroup.getDisplayText())
\r
143 if(currentSequenceGroup.getColourText())
\r
144 g.setColor(getResidueBoxColour(currentSequenceGroup.cs, seq, i).darker());
\r
148 if(!av.getShowText())
\r
151 if(av.getColourText())
\r
152 g.setColor(getResidueBoxColour(av.getGlobalColourScheme(), seq, i).darker());
\r
155 charOffset = (width - fm.charWidth(s))/2;
\r
156 g.drawString(String.valueOf(s), charOffset + x1 + width * (i - start), y1 + height - pady);
\r
162 boolean inCurrentSequenceGroup(int res)
\r
164 if(currentSequenceGroup==null)
\r
167 return (currentSequenceGroup.getStartRes()<=res && currentSequenceGroup.getEndRes()>=res)?true:false;
\r
170 public void drawHighlightedText(Graphics g, SequenceI seq,int start, int end, int x1, int y1, int width, int height)
\r
172 int pady = height/5;
\r
174 g.setColor(Color.BLACK);
\r
175 g.fillRect(x1,y1,width*(end-start+1),height);
\r
176 g.setColor(Color.white);
\r
179 // Need to find the sequence position here.
\r
180 for (int i = start; i <= end; i++)
\r
182 if(i<seq.getLength())
\r
183 s = seq.getSequence().charAt(i);
\r
185 charOffset = (width - fm.charWidth(s))/2;
\r
186 g.drawString(String.valueOf(s), charOffset + x1 + width * (i - start), y1 + height - pady);
\r