3 import jalview.datamodel.*;
\r
4 import jalview.schemes.*;
\r
9 public class SequenceRenderer implements RendererI
\r
13 public Color getResidueBoxColour(ColourSchemeI cs, SequenceI seq, int i)
\r
15 Color c = Color.white;
\r
17 c = cs.findColour(seq, seq.getSequence(i, i + 1), i, null);
\r
18 }catch(Exception ex){}
\r
24 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) {
\r
28 drawBoxes(g,cs,seq,start,end,x1,y1,(int)width, height,freq);
\r
32 fm = g.getFontMetrics();
\r
33 drawText(g,cs,colourText,seq,start,end,x1,y1,(int)width,height);
\r
37 public void drawBoxes(Graphics g,ColourSchemeI cs, SequenceI seq,int start, int end, int x1, int y1, int width, int height,Vector freq) {
\r
39 int length = seq.getLength();
\r
41 Color currentColor = Color.WHITE;
\r
44 int curWidth = width;
\r
46 // int threshold = 80;
\r
48 while (i <= end && i < length) {
\r
49 Color c = getResidueBoxColour(cs,seq,i);
\r
51 // Hashtable hash = (Hashtable)freq.elementAt(i-start);
\r
52 // String s = (String)hash.get("maxResidue");
\r
53 // int count = ((Integer)hash.get("maxCount")).intValue();
\r
54 // int max = ((Integer)hash.get("size")).intValue();
\r
55 // int nongap = ((Integer)hash.get("nongap")).intValue();
\r
56 // float frac = (float)(count*1.0/(1.0*nongap));
\r
58 //System.out.println("Frac/count/nongap " + frac + " " + count + " " + nongap);
\r
59 /* if (!seq.getSequence().substring(i,i+1).equals(s) ||
\r
68 } else if (frac > 0.8) {
\r
70 } else if (frac > 0.7) {
\r
72 } else if (frac > 0.5) {
\r
74 } else if (frac> 0.3) {
\r
75 c = Color.lightGray;
\r
79 if (c != currentColor || c != null)
\r
81 g.fillRect(x1+width*(curStart-start),y1,curWidth,height);
\r
94 g.fillRect(x1+width*(curStart-start),y1,curWidth,height);
\r
97 public void drawText(Graphics g, ColourSchemeI cs, boolean colText, SequenceI seq,int start, int end, int x1, int y1, int width, int height)
\r
99 int pady = height/5;
\r
101 g.setColor(Color.black);
\r
104 // Need to find the sequence position here.
\r
105 for (int i = start; i <= end; i++)
\r
107 if (i < end && i < seq.getLength())
\r
108 s = seq.getSequence().charAt(i);
\r
109 else if(i<seq.getLength())
\r
110 s = seq.getSequence().charAt(i);
\r
116 Color c = getResidueBoxColour(cs, seq, i);
\r
117 g.setColor(c.darker());
\r
120 charOffset = (width - fm.charWidth(s))/2;
\r
123 g.drawString(String.valueOf(s), charOffset + x1 + width * (i - start), y1 + height - pady);
\r