image is panel size
[jalview.git] / src / jalview / appletgui / AnnotationPanel.java
1 /*\r
2  * Jalview - A Sequence Alignment Editor and Viewer\r
3  * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4  *\r
5  * This program is free software; you can redistribute it and/or\r
6  * modify it under the terms of the GNU General Public License\r
7  * as published by the Free Software Foundation; either version 2\r
8  * of the License, or (at your option) any later version.\r
9  *\r
10  * This program is distributed in the hope that it will be useful,\r
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13  * GNU General Public License for more details.\r
14  *\r
15  * You should have received a copy of the GNU General Public License\r
16  * along with this program; if not, write to the Free Software\r
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
18  */\r
19 \r
20 package jalview.appletgui;\r
21 \r
22 import java.util.*;\r
23 \r
24 import java.awt.*;\r
25 import java.awt.event.*;\r
26 \r
27 import jalview.datamodel.*;\r
28 \r
29 public class AnnotationPanel\r
30     extends Panel implements AdjustmentListener\r
31 {\r
32   AlignViewport av;\r
33   AlignmentPanel ap;\r
34   int activeRow = -1;\r
35 \r
36   Vector activeRes;\r
37   static String HELIX = "Helix";\r
38   static String SHEET = "Sheet";\r
39   static String LABEL = "Label";\r
40   static String REMOVE = "Remove Annotation";\r
41   static String COLOUR = "Colour";\r
42   static Color HELIX_COLOUR = Color.red.darker();\r
43   static Color SHEET_COLOUR = Color.green.darker().darker();\r
44 \r
45   Image image;\r
46   Graphics gg;\r
47   FontMetrics fm;\r
48   int imgWidth = 0;\r
49 \r
50   boolean fastPaint = false;\r
51 \r
52   public static int GRAPH_HEIGHT = 40;\r
53 \r
54   boolean MAC = false;\r
55 \r
56   public AnnotationPanel(AlignmentPanel ap)\r
57   {\r
58     if (System.getProperty("os.name").startsWith("Mac"))\r
59       MAC = true;\r
60 \r
61     this.ap = ap;\r
62     av = ap.av;\r
63     setLayout(null);\r
64     adjustPanelHeight();\r
65 \r
66     addMouseMotionListener(new MouseMotionAdapter()\r
67     {\r
68       public void mouseMoved(MouseEvent evt)\r
69       {\r
70         doMouseMoved(evt);\r
71       }\r
72     });\r
73 \r
74     // ap.annotationScroller.getVAdjustable().addAdjustmentListener( this );\r
75   }\r
76 \r
77 \r
78   public AnnotationPanel(AlignViewport av)\r
79   {\r
80     this.av = av;\r
81   }\r
82 \r
83 \r
84   public void adjustmentValueChanged(AdjustmentEvent evt)\r
85   {\r
86     ap.alabels.setScrollOffset( -evt.getValue());\r
87   }\r
88 \r
89   public int adjustPanelHeight()\r
90   {\r
91     // setHeight of panels\r
92     AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();\r
93 \r
94 \r
95     int height = 0;\r
96     if (aa != null)\r
97     {\r
98       for (int i = 0; i < aa.length; i++)\r
99       {\r
100         if (!aa[i].visible)\r
101         {\r
102           continue;\r
103         }\r
104 \r
105         aa[i].height = 0;\r
106 \r
107         if (aa[i].hasText)\r
108         {\r
109           aa[i].height += av.charHeight;\r
110         }\r
111         if (aa[i].hasIcons)\r
112         {\r
113           aa[i].height += 16;\r
114         }\r
115 \r
116         if (aa[i].graph>0)\r
117         {\r
118           aa[i].height += GRAPH_HEIGHT;\r
119         }\r
120 \r
121         if (aa[i].height == 0)\r
122         {\r
123           aa[i].height = 20;\r
124         }\r
125         height += aa[i].height;\r
126       }\r
127     }\r
128     else\r
129     {\r
130       height = 20;\r
131     }\r
132 \r
133     this.setSize(getSize().width, height);\r
134 \r
135     repaint();\r
136 \r
137     return height;\r
138 \r
139   }\r
140 \r
141   public void addEditableColumn(int i)\r
142   {\r
143     if (activeRow == -1)\r
144     {\r
145       AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();\r
146       if(aa ==null)\r
147         return;\r
148 \r
149       for (int j = 0; j < aa.length; j++)\r
150       {\r
151         if (aa[j].editable)\r
152         {\r
153           activeRow = j;\r
154           break;\r
155         }\r
156       }\r
157     }\r
158 \r
159     if (activeRes == null)\r
160     {\r
161       activeRes = new Vector();\r
162       activeRes.addElement(String.valueOf(i));\r
163       return;\r
164     }\r
165 \r
166     activeRes.addElement(String.valueOf(i));\r
167   }\r
168 \r
169   public void doMouseMoved(MouseEvent evt)\r
170   {\r
171     AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();\r
172     if (aa == null)\r
173     {\r
174       return;\r
175     }\r
176 \r
177     int row = -1;\r
178     int height = 0;\r
179     for (int i = 0; i < aa.length; i++)\r
180     {\r
181 \r
182       if (aa[i].visible)\r
183       {\r
184         height += aa[i].height;\r
185       }\r
186 \r
187       if (evt.getY() < height)\r
188       {\r
189         row = i;\r
190         break;\r
191       }\r
192     }\r
193 \r
194     int res = evt.getX() / av.getCharWidth() + av.getStartRes();\r
195 \r
196     if(av.hasHiddenColumns)\r
197           res = av.getColumnSelection().adjustForHiddenColumns(res);\r
198 \r
199         if (row > -1 && res < aa[row].annotations.length && aa[row].annotations[res] != null)\r
200         {\r
201           StringBuffer text = new StringBuffer("Sequence position " + (res + 1));\r
202           if (aa[row].annotations[res].description != null)\r
203             text.append("  " + aa[row].annotations[res].description);\r
204           ap.alignFrame.statusBar.setText(text.toString());\r
205         }\r
206   }\r
207 \r
208   public void update(Graphics g)\r
209   {\r
210     paint(g);\r
211   }\r
212 \r
213   public void paint(Graphics g)\r
214   {\r
215 \r
216     imgWidth = getSize().width;\r
217         //(av.endRes - av.startRes + 1) * av.charWidth;\r
218 \r
219     if (image == null || imgWidth != image.getWidth(this))\r
220     {\r
221       image = createImage(imgWidth, ap.annotationPanel.getSize().height);\r
222       gg = image.getGraphics();\r
223       gg.setFont(av.getFont());\r
224       fm = gg.getFontMetrics();\r
225       fastPaint = false;\r
226     }\r
227 \r
228     if (fastPaint)\r
229     {\r
230       g.drawImage(image, 0, 0, this);\r
231       fastPaint = false;\r
232       return;\r
233     }\r
234 \r
235     drawComponent(gg, av.startRes, av.endRes + 1);\r
236     g.drawImage(image, 0, 0, this);\r
237   }\r
238 \r
239   public void fastPaint(int horizontal)\r
240   {\r
241     if (horizontal == 0\r
242         || av.alignment.getAlignmentAnnotation() == null\r
243         || av.alignment.getAlignmentAnnotation().length < 1\r
244         )\r
245     {\r
246       repaint();\r
247       return;\r
248     }\r
249 \r
250     gg.copyArea(0, 0, imgWidth, getSize().height, -horizontal * av.charWidth, 0);\r
251     int sr = av.startRes, er = av.endRes + 1, transX = 0;\r
252 \r
253     if (horizontal > 0) // scrollbar pulled right, image to the left\r
254     {\r
255       transX = (er - sr - horizontal) * av.charWidth;\r
256       sr = er - horizontal;\r
257     }\r
258     else if (horizontal < 0)\r
259     {\r
260       er = sr - horizontal;\r
261     }\r
262 \r
263     gg.translate(transX, 0);\r
264 \r
265     drawComponent(gg, sr, er);\r
266 \r
267     gg.translate( -transX, 0);\r
268 \r
269     fastPaint = true;\r
270     repaint();\r
271   }\r
272 \r
273   /**\r
274    * DOCUMENT ME!\r
275    *\r
276    * @param g DOCUMENT ME!\r
277    * @param startRes DOCUMENT ME!\r
278    * @param endRes DOCUMENT ME!\r
279    */\r
280   public void drawComponent(Graphics g, int startRes, int endRes)\r
281   {\r
282     g.setFont(av.getFont());\r
283 \r
284     if (fm == null)\r
285       fm = g.getFontMetrics();\r
286 \r
287 \r
288       g.setColor(Color.white);\r
289       g.fillRect(0, 0, getSize().width, getSize().height);\r
290 \r
291       if ((av.alignment.getAlignmentAnnotation() == null) ||\r
292               (av.alignment.getAlignmentAnnotation().length < 1))\r
293       {\r
294           g.setColor(Color.white);\r
295           g.fillRect(0, 0, getSize().width, getSize().height);\r
296           g.setColor(Color.black);\r
297           if(av.validCharWidth)\r
298             g.drawString("Alignment has no annotations", 20, 15);\r
299 \r
300           return;\r
301       }\r
302 \r
303       AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();\r
304 \r
305       int x = 0;\r
306       int y = 0;\r
307       int column=0;\r
308       char lastSS;\r
309       int lastSSX;\r
310       int iconOffset = av.charHeight / 2;\r
311       boolean validRes = false;\r
312 \r
313       boolean [] graphGroupDrawn = new boolean[aa.length];\r
314 \r
315 \r
316       //\u03B2 \u03B1\r
317       for (int i = 0; i < aa.length; i++)\r
318       {\r
319           AlignmentAnnotation row = aa[i];\r
320 \r
321           if (!row.visible)\r
322           {\r
323               continue;\r
324           }\r
325 \r
326           lastSS = ' ';\r
327           lastSSX = 0;\r
328 \r
329           if (row.graph>0)\r
330           {\r
331               if(row.graphGroup>-1 && graphGroupDrawn[ row.graphGroup ] )\r
332                 continue;\r
333 \r
334               // this is so that we draw the characters below the graph\r
335               y += row.height;\r
336 \r
337               if (row.hasText)\r
338               {\r
339                   y -= av.charHeight;\r
340               }\r
341           }\r
342 \r
343           if (row.hasText)\r
344           {\r
345               iconOffset = av.charHeight / 2;\r
346           }\r
347           else\r
348           {\r
349               iconOffset = 0;\r
350           }\r
351 \r
352            x = 0;\r
353           while(x < endRes-startRes)\r
354           {\r
355             if (av.hasHiddenColumns)\r
356             {\r
357               column = av.getColumnSelection().adjustForHiddenColumns(startRes+x);\r
358               if (column > row.annotations.length-1)\r
359               {\r
360                 break;\r
361               }\r
362             }\r
363             else\r
364                 column = startRes+x;\r
365 \r
366               if ( (row.annotations.length <= column) ||\r
367                   (row.annotations[column] == null))\r
368               {\r
369                 validRes = false;\r
370               }\r
371               else\r
372               {\r
373                 validRes = true;\r
374               }\r
375 \r
376 \r
377               if (av.validCharWidth && validRes &&\r
378                         (row.annotations[column].displayCharacter.length() > 0))\r
379               {\r
380                 int charOffset = (av.charWidth -\r
381                     fm.charWidth(row.annotations[column].displayCharacter.charAt(\r
382                             0))) / 2;\r
383                 g.setColor(row.annotations[column].colour);\r
384 \r
385                 if (column == 0 || row.graph>0)\r
386                 {\r
387                     g.drawString(row.annotations[column].displayCharacter,\r
388                                 (x*av.charWidth)+charOffset,\r
389                         y + iconOffset + 3);\r
390                 }\r
391                 else if (\r
392                     row.annotations[column - 1] == null\r
393                     ||(!row.annotations[column].displayCharacter.equals(\r
394                         row.annotations[column - 1].displayCharacter)\r
395                     ||\r
396               (row.annotations[column].displayCharacter.length() <2 &&\r
397                row.annotations[column].secondaryStructure==' ')))\r
398                 {\r
399                     g.drawString(row.annotations[column].displayCharacter,\r
400                        (x*av.charWidth)+charOffset,\r
401                         y + iconOffset + 3);\r
402                     }\r
403               }\r
404 \r
405               if (row.hasIcons)\r
406               {\r
407                   if (!validRes ||\r
408                           (row.annotations[column].secondaryStructure != lastSS))\r
409                   {\r
410                       switch (lastSS)\r
411                       {\r
412                       case 'H':\r
413                         g.setColor(HELIX_COLOUR);\r
414                         if (MAC)\r
415                         {\r
416                           //Off by 1 offset when drawing rects and ovals\r
417                           //to offscreen image on the MAC\r
418                           g.fillRoundRect(lastSSX, y + 4 + iconOffset,\r
419                                           (x*av.charWidth) - lastSSX, 7, 8, 8);\r
420                           break;\r
421                         }\r
422 \r
423                         int sCol = (lastSSX / av.charWidth) + startRes;\r
424                         int x1 = lastSSX;\r
425                         int x2 = (x*av.charWidth);\r
426 \r
427                        if(sCol==0 ||\r
428                           row.annotations[sCol-1]==null ||\r
429                           row.annotations[sCol-1].secondaryStructure!='H')\r
430                        {\r
431                          g.fillArc(lastSSX, y+4+iconOffset, av.charWidth, 8, 90,180) ;\r
432                          x1 += av.charWidth/2;\r
433                        }\r
434 \r
435                         if(row.annotations[column]==null ||\r
436                            row.annotations[column].secondaryStructure!='H')\r
437                         {\r
438                           g.fillArc((x*av.charWidth)-av.charWidth,\r
439                                     y+4+iconOffset, av.charWidth, 8, 270,180);\r
440                           x2 -= av.charWidth/2;\r
441                         }\r
442 \r
443                         g.fillRect(x1, y+4+iconOffset, x2-x1, 8);\r
444                             break;\r
445 \r
446                       case 'E':\r
447                           g.setColor(SHEET_COLOUR);\r
448                           g.fillRect(lastSSX, y + 4 + iconOffset,\r
449                               (x*av.charWidth) - lastSSX - 4, 7);\r
450                           g.fillPolygon(new int[] { (x*av.charWidth) - 4,\r
451                                         (x*av.charWidth) - 4,\r
452                                         (x*av.charWidth) },\r
453                               new int[]\r
454                               {\r
455                                   y + iconOffset, y + 14 + iconOffset,\r
456                                   y + 8 + iconOffset\r
457                               }, 3);\r
458 \r
459                           break;\r
460 \r
461 \r
462                       default:\r
463                           g.setColor(Color.gray);\r
464                           g.fillRect(lastSSX, y + 6 + iconOffset,\r
465                               (x*av.charWidth) - lastSSX, 2);\r
466 \r
467                           break;\r
468                       }\r
469 \r
470                       if (validRes)\r
471                       {\r
472                           lastSS = row.annotations[column].secondaryStructure;\r
473                       }\r
474                       else\r
475                       {\r
476                           lastSS = ' ';\r
477                       }\r
478 \r
479                       lastSSX = (x*av.charWidth);\r
480                   }\r
481               }\r
482 \r
483 \r
484           column++;\r
485           x++;\r
486           }\r
487 \r
488           if(column>=row.annotations.length)\r
489               column = row.annotations.length-1;\r
490 \r
491         //  x ++;\r
492 \r
493           if (row.hasIcons)\r
494           {\r
495             switch (lastSS)\r
496             {\r
497               case 'H':\r
498                 g.setColor(HELIX_COLOUR);\r
499                 if (MAC)\r
500                 {\r
501                   //Off by 1 offset when drawing rects and ovals\r
502                   //to offscreen image on the MAC\r
503                   g.fillRoundRect(lastSSX, y + 4 + iconOffset,\r
504                                   (x*av.charWidth) - lastSSX, 7, 8, 8);\r
505                   break;\r
506                 }\r
507 \r
508                 int sCol = (lastSSX / av.charWidth) + startRes;\r
509                 int x1 = lastSSX;\r
510                 int x2 = (x*av.charWidth);\r
511 \r
512                 if (sCol == 0 ||\r
513                     row.annotations[sCol - 1] == null ||\r
514                     row.annotations[sCol - 1].secondaryStructure != 'H')\r
515                 {\r
516                   g.fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8, 90, 180);\r
517                   x1 += av.charWidth / 2;\r
518                 }\r
519 \r
520                 if (row.annotations[column] == null ||\r
521                     row.annotations[column].secondaryStructure != 'H')\r
522                 {\r
523                   g.fillArc((x*av.charWidth) - av.charWidth,\r
524                             y + 4 + iconOffset, av.charWidth, 8, 270,\r
525                             180);\r
526                   x2 -= av.charWidth / 2;\r
527                 }\r
528 \r
529                 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);\r
530 \r
531                 break;\r
532 \r
533               case 'E':\r
534                 g.setColor(SHEET_COLOUR);\r
535 \r
536                 if (row.annotations[endRes] == null\r
537                     || row.annotations[endRes].secondaryStructure != 'E')\r
538                 {\r
539                   g.fillRect(lastSSX, y + 4 + iconOffset,\r
540                              (x*av.charWidth) - lastSSX - 4, 7);\r
541                   g.fillPolygon(new int[]\r
542                                 {(x*av.charWidth) - 4,\r
543                                 (x*av.charWidth) - 4,\r
544                                (x*av.charWidth)},\r
545                                 new int[]\r
546                                 {\r
547                                 y + iconOffset, y + 14 + iconOffset,\r
548                                 y + 7 + iconOffset\r
549                   }, 3);\r
550                 }\r
551                 else\r
552                  {\r
553                    g.fillRect(lastSSX, y + 4 + iconOffset,\r
554                               x * av.charWidth - lastSSX, 7);\r
555                  }\r
556                 break;\r
557 \r
558               default:\r
559                 g.setColor(Color.gray);\r
560                 if(!av.wrapAlignment || endRes==av.endRes)\r
561                 g.fillRect(lastSSX, y + 6 + iconOffset,\r
562                            (x*av.charWidth) - lastSSX, 2);\r
563 \r
564                 break;\r
565             }\r
566           }\r
567 \r
568           if (row.graph>0)\r
569           {\r
570               if(row.graph == AlignmentAnnotation.LINE_GRAPH )\r
571               {\r
572                 if(row.graphGroup>-1 && !graphGroupDrawn[row.graphGroup])\r
573                  {\r
574                    float groupmax=-999999, groupmin=9999999;\r
575                    for(int gg=0; gg<aa.length; gg++)\r
576                    {\r
577                      if(aa[gg].graphGroup!=row.graphGroup)\r
578                        continue;\r
579 \r
580                      if(aa[gg]!=row)\r
581                        aa[gg].visible = false;\r
582 \r
583                      if(aa[gg].graphMax>groupmax)\r
584                        groupmax = aa[gg].graphMax;\r
585                      if(aa[gg].graphMin<groupmin)\r
586                        groupmin = aa[gg].graphMin;\r
587                    }\r
588 \r
589                    for (int gg = 0; gg < aa.length; gg++)\r
590                    {\r
591                      if (aa[gg].graphGroup == row.graphGroup)\r
592                      {\r
593                        drawLineGraph(g, aa[gg], startRes, endRes, y,\r
594                                      groupmin, groupmax,\r
595                                      row.graphHeight);\r
596                      }\r
597                    }\r
598 \r
599                    graphGroupDrawn[ row.graphGroup ] = true;\r
600                  }\r
601                  else\r
602                    drawLineGraph(g, row, startRes, endRes,\r
603                                  y, row.graphMin, row.graphMax, row.graphHeight  );\r
604               }\r
605               else if(row.graph == AlignmentAnnotation.BAR_GRAPH )\r
606                  drawBarGraph(g, row, startRes, endRes,\r
607                               row.graphMin, row.graphMax, y);\r
608           }\r
609 \r
610           if (row.graph>0 && row.hasText)\r
611           {\r
612               y += av.charHeight;\r
613           }\r
614 \r
615           if (row.graph==0)\r
616           {\r
617               y += aa[i].height;\r
618           }\r
619       }\r
620   }\r
621 \r
622   public void drawLineGraph(Graphics g, AlignmentAnnotation aa,\r
623                             int sRes, int eRes,\r
624                             int y,\r
625                             float min, float max,\r
626                             int graphHeight)\r
627   {\r
628     if(sRes>aa.annotations.length)\r
629       return;\r
630 \r
631 \r
632 \r
633     int x = 0;\r
634 \r
635     //Adjustment for fastpaint to left\r
636     if(eRes<av.endRes)\r
637       eRes++;\r
638 \r
639     eRes = Math.min(eRes, aa.annotations.length);\r
640 \r
641 \r
642     if(sRes==0)\r
643     {\r
644       sRes++;\r
645       x+=av.charWidth;\r
646     }\r
647 \r
648     int y1=y, y2=y;\r
649     float range = max - min;\r
650 \r
651     ////Draw origin\r
652     if(min<0)\r
653       y2 = y - (int)((0-min / range)*graphHeight);\r
654 \r
655     g.setColor(Color.gray);\r
656     g.drawLine(x-av.charWidth,y2,(eRes-sRes)*av.charWidth,y2);\r
657 \r
658     eRes = Math.min(eRes, aa.annotations.length);\r
659 \r
660     int column;\r
661     int aaMax = aa.annotations.length-1;\r
662 \r
663     while( x < eRes - sRes )\r
664     {\r
665       column = sRes + x;\r
666       if(av.hasHiddenColumns)\r
667       {\r
668         column = av.getColumnSelection().adjustForHiddenColumns(column);\r
669       }\r
670 \r
671       if (column > aaMax)\r
672       {\r
673         break;\r
674       }\r
675 \r
676       if(aa.annotations[column]==null || aa.annotations[column-1]==null)\r
677       {\r
678         x++;\r
679         continue;\r
680       }\r
681 \r
682         g.setColor(aa.annotations[column].colour);\r
683         y1 = y - (int) (((aa.annotations[column-1].value-min) / range) * graphHeight);\r
684         y2 = y - (int) (((aa.annotations[column].value-min) / range) * graphHeight);\r
685 \r
686         g.drawLine(x*av.charWidth-av.charWidth/2, y1, x*av.charWidth+av.charWidth/2, y2);\r
687         x ++;\r
688      }\r
689 \r
690      if(aa.threshold!=null)\r
691      {\r
692          g.setColor(aa.threshold.colour);\r
693 \r
694          y2 = (int)(y - ((aa.threshold.value-min) / range)*graphHeight);\r
695          g.drawLine(0,y2,(eRes-sRes)*av.charWidth,y2);\r
696     }\r
697   }\r
698 \r
699   public void drawBarGraph(Graphics g, AlignmentAnnotation aa,\r
700                            int sRes, int eRes,\r
701                            float min, float max,\r
702                            int y)\r
703   {\r
704     if(sRes>aa.annotations.length)\r
705       return;\r
706 \r
707     eRes = Math.min(eRes, aa.annotations.length);\r
708 \r
709     int x=0, y1=y, y2=y;\r
710 \r
711     float range = max - min;\r
712 \r
713     if(min<0)\r
714       y2 = y - (int)((0-min / (range))*aa.graphHeight);\r
715 \r
716     g.setColor(Color.gray);\r
717 \r
718     g.drawLine(x,y2,(eRes-sRes)*av.charWidth,y2);\r
719 \r
720     int column;\r
721     int aaMax = aa.annotations.length-1;\r
722 \r
723     while( x < eRes-sRes )\r
724     {\r
725       column = sRes + x;\r
726       if(av.hasHiddenColumns)\r
727       {\r
728         column = av.getColumnSelection().adjustForHiddenColumns(column);\r
729       }\r
730 \r
731       if(column > aaMax)\r
732       {\r
733           break;\r
734       }\r
735 \r
736       if (aa.annotations[column] == null)\r
737       {\r
738         x ++;\r
739         continue;\r
740       }\r
741 \r
742         g.setColor(aa.annotations[column].colour);\r
743         y1 = y - (int) (((aa.annotations[column].value-min) / (range)) * aa.graphHeight);\r
744 \r
745         if(y1-y2>0)\r
746           g.fillRect(x*av.charWidth, y2, av.charWidth, y1-y2 );\r
747         else\r
748           g.fillRect(x*av.charWidth, y1, av.charWidth, y2-y1 );\r
749 \r
750         x ++ ;\r
751 \r
752     }\r
753     if(aa.threshold!=null)\r
754     {\r
755         g.setColor(aa.threshold.colour);\r
756         y2 = (int)(y - ((aa.threshold.value-min) / range)*aa.graphHeight);\r
757         g.drawLine(0,y2,(eRes-sRes)*av.charWidth,y2);\r
758       }\r
759   }\r
760 \r
761   // used by overview window\r
762   public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y, int sRes, int eRes)\r
763   {\r
764       g.setColor(Color.white);\r
765       g.fillRect(0, 0, width, y);\r
766       g.setColor(new Color(0, 0, 180));\r
767 \r
768       int x = 0, height;\r
769 \r
770       for (int j = sRes; j < eRes; j++)\r
771       {\r
772           g.setColor(aa.annotations[j].colour);\r
773 \r
774           height = (int) ((aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT);\r
775           if(height>y)\r
776               height = y;\r
777           g.fillRect(x, y - height, av.charWidth, height);\r
778           x += av.charWidth;\r
779       }\r
780     }\r
781 }\r