Remove viewport from constructor
[jalview.git] / src / jalview / gui / SequenceRenderer.java
1 package jalview.gui;\r
2 \r
3 import jalview.datamodel.*;\r
4 import jalview.schemes.*;\r
5 \r
6 import java.awt.*;\r
7 import java.util.*;\r
8 \r
9 public class SequenceRenderer implements RendererI\r
10 {\r
11   FontMetrics fm;\r
12 \r
13   public Color getResidueBoxColour(ColourSchemeI cs, SequenceI seq, int i) {\r
14 \r
15     Color c  = cs.findColour(seq, seq.getSequence(i, i + 1), i, null);\r
16     return c;\r
17 \r
18   }\r
19 \r
20 \r
21   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
22 \r
23 \r
24     if (displayBoxes)\r
25         drawBoxes(g,cs,seq,start,end,x1,y1,(int)width, height,freq);\r
26 \r
27     if (displayText)\r
28     {\r
29         fm = g.getFontMetrics();\r
30         drawText(g,cs,colourText,seq,start,end,x1,y1,(int)width,height);\r
31     }\r
32   }\r
33 \r
34   public void drawBoxes(Graphics g,ColourSchemeI cs, SequenceI seq,int start, int end, int x1, int y1, int width, int height,Vector freq) {\r
35     int i      = start;\r
36     int length = seq.getLength();\r
37 \r
38     Color currentColor = Color.WHITE;\r
39 \r
40     int curStart = x1;\r
41     int curWidth = width;\r
42 \r
43   //  int threshold = 80;\r
44 \r
45     while (i <= end && i < length) {\r
46       Color c = getResidueBoxColour(cs,seq,i);\r
47 \r
48     //  Hashtable hash  = (Hashtable)freq.elementAt(i-start);\r
49     //  String    s     = (String)hash.get("maxResidue");\r
50     //  int       count = ((Integer)hash.get("maxCount")).intValue();\r
51   //    int       max   = ((Integer)hash.get("size")).intValue();\r
52    //   int       nongap = ((Integer)hash.get("nongap")).intValue();\r
53    //   float     frac  = (float)(count*1.0/(1.0*nongap));\r
54 \r
55       //System.out.println("Frac/count/nongap " + frac + " " + count + " " + nongap);\r
56     /*  if (!seq.getSequence().substring(i,i+1).equals(s) ||\r
57           s.equals("-") ||\r
58           s.equals(".") ||\r
59           s.equals(" "))\r
60       {\r
61         c = Color.white;\r
62       } else {\r
63         if (frac > 0.9) {\r
64           c = Color.red;\r
65         } else if (frac > 0.8) {\r
66           c = Color.orange;\r
67         } else if (frac > 0.7) {\r
68           c = Color.pink;\r
69         } else if (frac > 0.5) {\r
70           c = Color.yellow;\r
71         } else if (frac> 0.3) {\r
72             c = Color.lightGray;\r
73         }\r
74       }*/\r
75 \r
76       if (c != currentColor || c != null)\r
77       {\r
78         g.fillRect(x1+width*(curStart-start),y1,curWidth,height);\r
79 \r
80         currentColor = c;\r
81         g.setColor(c);\r
82 \r
83         curStart = i;\r
84         curWidth = width;\r
85       }\r
86       else\r
87         curWidth += width;\r
88 \r
89       i++;\r
90     }\r
91     g.fillRect(x1+width*(curStart-start),y1,curWidth,height);\r
92   }\r
93 \r
94   public void drawText(Graphics g, ColourSchemeI cs, boolean colText, SequenceI seq,int start, int end, int x1, int y1, int width, int height)\r
95   {\r
96     int pady = height/5;\r
97     int charOffset=0;\r
98     g.setColor(Color.black);\r
99 \r
100     char s;\r
101     // Need to find the sequence position here.\r
102     for (int i = start; i <= end; i++)\r
103     {\r
104         if (i < end && i < seq.getLength())\r
105           s = seq.getSequence().charAt(i);\r
106         else if(i<seq.getLength())\r
107           s = seq.getSequence().charAt(i);\r
108         else\r
109           s = ' ';\r
110 \r
111         if (colText)\r
112         {\r
113             Color c = getResidueBoxColour(cs, seq, i);\r
114             g.setColor(c.darker());\r
115         }\r
116 \r
117       charOffset =  (width - fm.charWidth(s))/2;\r
118 \r
119 \r
120       g.drawString(String.valueOf(s), charOffset + x1 + width * (i - start), y1 + height - pady);\r
121     }\r
122   }\r
123 \r
124 }\r