Dont clear graphics g before drawing the image
[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 = (av.endRes - av.startRes + 1) * av.charWidth;\r
217 \r
218     if (image == null || imgWidth != image.getWidth(this))\r
219     {\r
220       image = createImage(imgWidth, ap.annotationPanel.getSize().height);\r
221       gg = image.getGraphics();\r
222       gg.setFont(av.getFont());\r
223       fm = gg.getFontMetrics();\r
224       fastPaint = false;\r
225     }\r
226 \r
227     if (fastPaint)\r
228     {\r
229       g.drawImage(image, 0, 0, this);\r
230       fastPaint = false;\r
231       return;\r
232     }\r
233 \r
234     drawComponent(gg, av.startRes, av.endRes + 1);\r
235     g.drawImage(image, 0, 0, this);\r
236   }\r
237 \r
238   public void fastPaint(int horizontal)\r
239   {\r
240     if (horizontal == 0\r
241         || av.alignment.getAlignmentAnnotation() == null\r
242         || av.alignment.getAlignmentAnnotation().length < 1\r
243         )\r
244     {\r
245       repaint();\r
246       return;\r
247     }\r
248 \r
249     gg.copyArea(0, 0, imgWidth, getSize().height, -horizontal * av.charWidth, 0);\r
250     int sr = av.startRes, er = av.endRes + 1, transX = 0;\r
251 \r
252     if (horizontal > 0) // scrollbar pulled right, image to the left\r
253     {\r
254       transX = (er - sr - horizontal) * av.charWidth;\r
255       sr = er - horizontal;\r
256     }\r
257     else if (horizontal < 0)\r
258     {\r
259       er = sr - horizontal;\r
260     }\r
261 \r
262     gg.translate(transX, 0);\r
263 \r
264     drawComponent(gg, sr, er);\r
265 \r
266     gg.translate( -transX, 0);\r
267 \r
268     fastPaint = true;\r
269     repaint();\r
270   }\r
271 \r
272   /**\r
273    * DOCUMENT ME!\r
274    *\r
275    * @param g DOCUMENT ME!\r
276    * @param startRes DOCUMENT ME!\r
277    * @param endRes DOCUMENT ME!\r
278    */\r
279   public void drawComponent(Graphics g, int startRes, int endRes)\r
280   {\r
281     g.setFont(av.getFont());\r
282 \r
283     if (fm == null)\r
284       fm = g.getFontMetrics();\r
285 \r
286 \r
287       g.setColor(Color.white);\r
288       g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getSize().height);\r
289 \r
290       if ((av.alignment.getAlignmentAnnotation() == null) ||\r
291               (av.alignment.getAlignmentAnnotation().length < 1))\r
292       {\r
293           g.setColor(Color.white);\r
294           g.fillRect(0, 0, getSize().width, getSize().height);\r
295           g.setColor(Color.black);\r
296           if(av.validCharWidth)\r
297             g.drawString("Alignment has no annotations", 20, 15);\r
298 \r
299           return;\r
300       }\r
301 \r
302       AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();\r
303 \r
304       int x = 0;\r
305       int y = 0;\r
306       int column=0;\r
307       char lastSS;\r
308       int lastSSX;\r
309       int iconOffset = av.charHeight / 2;\r
310       boolean validRes = false;\r
311 \r
312       boolean [] graphGroupDrawn = new boolean[aa.length];\r
313 \r
314 \r
315       //\u03B2 \u03B1\r
316       for (int i = 0; i < aa.length; i++)\r
317       {\r
318           AlignmentAnnotation row = aa[i];\r
319 \r
320           if (!row.visible)\r
321           {\r
322               continue;\r
323           }\r
324 \r
325           lastSS = ' ';\r
326           lastSSX = 0;\r
327 \r
328           if (row.graph>0)\r
329           {\r
330               if(row.graphGroup>-1 && graphGroupDrawn[ row.graphGroup ] )\r
331                 continue;\r
332 \r
333               // this is so that we draw the characters below the graph\r
334               y += row.height;\r
335 \r
336               if (row.hasText)\r
337               {\r
338                   y -= av.charHeight;\r
339               }\r
340           }\r
341 \r
342           if (row.hasText)\r
343           {\r
344               iconOffset = av.charHeight / 2;\r
345           }\r
346           else\r
347           {\r
348               iconOffset = 0;\r
349           }\r
350 \r
351            x = 0;\r
352           while(x < endRes-startRes)\r
353           {\r
354             if (av.hasHiddenColumns)\r
355             {\r
356               column = av.getColumnSelection().adjustForHiddenColumns(startRes+x);\r
357               if (column > row.annotations.length-1)\r
358               {\r
359                 break;\r
360               }\r
361             }\r
362             else\r
363                 column = startRes+x;\r
364 \r
365               if ( (row.annotations.length <= column) ||\r
366                   (row.annotations[column] == null))\r
367               {\r
368                 validRes = false;\r
369               }\r
370               else\r
371               {\r
372                 validRes = true;\r
373               }\r
374 \r
375 \r
376               if (av.validCharWidth && validRes &&\r
377                         (row.annotations[column].displayCharacter.length() > 0))\r
378               {\r
379                 int charOffset = (av.charWidth -\r
380                     fm.charWidth(row.annotations[column].displayCharacter.charAt(\r
381                             0))) / 2;\r
382                 g.setColor(row.annotations[column].colour);\r
383 \r
384                 if (column == 0 || row.graph>0)\r
385                 {\r
386                     g.drawString(row.annotations[column].displayCharacter,\r
387                                 (x*av.charWidth)+charOffset,\r
388                         y + iconOffset + 3);\r
389                 }\r
390                 else if (\r
391                     row.annotations[column - 1] == null\r
392                     ||(!row.annotations[column].displayCharacter.equals(\r
393                         row.annotations[column - 1].displayCharacter)\r
394                     ||\r
395               (row.annotations[column].displayCharacter.length() <2 &&\r
396                row.annotations[column].secondaryStructure==' ')))\r
397                 {\r
398                     g.drawString(row.annotations[column].displayCharacter,\r
399                        (x*av.charWidth)+charOffset,\r
400                         y + iconOffset + 3);\r
401                     }\r
402               }\r
403 \r
404               if (row.hasIcons)\r
405               {\r
406                   if (!validRes ||\r
407                           (row.annotations[column].secondaryStructure != lastSS))\r
408                   {\r
409                       switch (lastSS)\r
410                       {\r
411                       case 'H':\r
412                         g.setColor(HELIX_COLOUR);\r
413                         if (MAC)\r
414                         {\r
415                           //Off by 1 offset when drawing rects and ovals\r
416                           //to offscreen image on the MAC\r
417                           g.fillRoundRect(lastSSX, y + 4 + iconOffset,\r
418                                           (x*av.charWidth) - lastSSX, 7, 8, 8);\r
419                           break;\r
420                         }\r
421 \r
422                         int sCol = (lastSSX / av.charWidth) + startRes;\r
423                         int x1 = lastSSX;\r
424                         int x2 = (x*av.charWidth);\r
425 \r
426                        if(sCol==0 ||\r
427                           row.annotations[sCol-1]==null ||\r
428                           row.annotations[sCol-1].secondaryStructure!='H')\r
429                        {\r
430                          g.fillArc(lastSSX, y+4+iconOffset, av.charWidth, 8, 90,180) ;\r
431                          x1 += av.charWidth/2;\r
432                        }\r
433 \r
434                         if(row.annotations[column]==null ||\r
435                            row.annotations[column].secondaryStructure!='H')\r
436                         {\r
437                           g.fillArc((x*av.charWidth)-av.charWidth,\r
438                                     y+4+iconOffset, av.charWidth, 8, 270,180);\r
439                           x2 -= av.charWidth/2;\r
440                         }\r
441 \r
442                         g.fillRect(x1, y+4+iconOffset, x2-x1, 8);\r
443                             break;\r
444 \r
445                       case 'E':\r
446                           g.setColor(SHEET_COLOUR);\r
447                           g.fillRect(lastSSX, y + 4 + iconOffset,\r
448                               (x*av.charWidth) - lastSSX - 4, 7);\r
449                           g.fillPolygon(new int[] { (x*av.charWidth) - 4,\r
450                                         (x*av.charWidth) - 4,\r
451                                         (x*av.charWidth) },\r
452                               new int[]\r
453                               {\r
454                                   y + iconOffset, y + 14 + iconOffset,\r
455                                   y + 8 + iconOffset\r
456                               }, 3);\r
457 \r
458                           break;\r
459 \r
460 \r
461                       default:\r
462                           g.setColor(Color.gray);\r
463                           g.fillRect(lastSSX, y + 6 + iconOffset,\r
464                               (x*av.charWidth) - lastSSX, 2);\r
465 \r
466                           break;\r
467                       }\r
468 \r
469                       if (validRes)\r
470                       {\r
471                           lastSS = row.annotations[column].secondaryStructure;\r
472                       }\r
473                       else\r
474                       {\r
475                           lastSS = ' ';\r
476                       }\r
477 \r
478                       lastSSX = (x*av.charWidth);\r
479                   }\r
480               }\r
481 \r
482 \r
483           column++;\r
484           x++;\r
485           }\r
486 \r
487           if(column>=row.annotations.length)\r
488               column = row.annotations.length-1;\r
489 \r
490         //  x ++;\r
491 \r
492           if (row.hasIcons)\r
493           {\r
494             switch (lastSS)\r
495             {\r
496               case 'H':\r
497                 g.setColor(HELIX_COLOUR);\r
498                 if (MAC)\r
499                 {\r
500                   //Off by 1 offset when drawing rects and ovals\r
501                   //to offscreen image on the MAC\r
502                   g.fillRoundRect(lastSSX, y + 4 + iconOffset,\r
503                                   (x*av.charWidth) - lastSSX, 7, 8, 8);\r
504                   break;\r
505                 }\r
506 \r
507                 int sCol = (lastSSX / av.charWidth) + startRes;\r
508                 int x1 = lastSSX;\r
509                 int x2 = (x*av.charWidth);\r
510 \r
511                 if (sCol == 0 ||\r
512                     row.annotations[sCol - 1] == null ||\r
513                     row.annotations[sCol - 1].secondaryStructure != 'H')\r
514                 {\r
515                   g.fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8, 90, 180);\r
516                   x1 += av.charWidth / 2;\r
517                 }\r
518 \r
519                 if (row.annotations[column] == null ||\r
520                     row.annotations[column].secondaryStructure != 'H')\r
521                 {\r
522                   g.fillArc((x*av.charWidth) - av.charWidth,\r
523                             y + 4 + iconOffset, av.charWidth, 8, 270,\r
524                             180);\r
525                   x2 -= av.charWidth / 2;\r
526                 }\r
527 \r
528                 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);\r
529 \r
530                 break;\r
531 \r
532               case 'E':\r
533                 g.setColor(SHEET_COLOUR);\r
534 \r
535                 if (row.annotations[endRes] == null\r
536                     || row.annotations[endRes].secondaryStructure != 'E')\r
537                 {\r
538                   g.fillRect(lastSSX, y + 4 + iconOffset,\r
539                              (x*av.charWidth) - lastSSX - 4, 7);\r
540                   g.fillPolygon(new int[]\r
541                                 {(x*av.charWidth) - 4,\r
542                                 (x*av.charWidth) - 4,\r
543                                (x*av.charWidth)},\r
544                                 new int[]\r
545                                 {\r
546                                 y + iconOffset, y + 14 + iconOffset,\r
547                                 y + 7 + iconOffset\r
548                   }, 3);\r
549                 }\r
550                 else\r
551                  {\r
552                    g.fillRect(lastSSX, y + 4 + iconOffset,\r
553                               (x+1) * av.charWidth - lastSSX, 7);\r
554                  }\r
555                 break;\r
556 \r
557               default:\r
558                 g.setColor(Color.gray);\r
559                 if(!av.wrapAlignment || endRes==av.endRes)\r
560                 g.fillRect(lastSSX, y + 6 + iconOffset,\r
561                            (x*av.charWidth) - lastSSX, 2);\r
562 \r
563                 break;\r
564             }\r
565           }\r
566 \r
567           if (row.graph>0)\r
568           {\r
569               if(row.graph == AlignmentAnnotation.LINE_GRAPH )\r
570               {\r
571                 if(row.graphGroup>-1 && !graphGroupDrawn[row.graphGroup])\r
572                  {\r
573                    float groupmax=-999999, groupmin=9999999;\r
574                    for(int gg=0; gg<aa.length; gg++)\r
575                    {\r
576                      if(aa[gg].graphGroup!=row.graphGroup)\r
577                        continue;\r
578 \r
579                      if(aa[gg]!=row)\r
580                        aa[gg].visible = false;\r
581 \r
582                      if(aa[gg].graphMax>groupmax)\r
583                        groupmax = aa[gg].graphMax;\r
584                      if(aa[gg].graphMin<groupmin)\r
585                        groupmin = aa[gg].graphMin;\r
586                    }\r
587 \r
588                    for (int gg = 0; gg < aa.length; gg++)\r
589                    {\r
590                      if (aa[gg].graphGroup == row.graphGroup)\r
591                      {\r
592                        drawLineGraph(g, aa[gg], startRes, endRes, y,\r
593                                      groupmin, groupmax,\r
594                                      row.graphHeight);\r
595                      }\r
596                    }\r
597 \r
598                    graphGroupDrawn[ row.graphGroup ] = true;\r
599                  }\r
600                  else\r
601                    drawLineGraph(g, row, startRes, endRes,\r
602                                  y, row.graphMin, row.graphMax, row.graphHeight  );\r
603               }\r
604               else if(row.graph == AlignmentAnnotation.BAR_GRAPH )\r
605                  drawBarGraph(g, row, startRes, endRes,\r
606                               row.graphMin, row.graphMax, y);\r
607           }\r
608 \r
609           if (row.graph>0 && row.hasText)\r
610           {\r
611               y += av.charHeight;\r
612           }\r
613 \r
614           if (row.graph==0)\r
615           {\r
616               y += aa[i].height;\r
617           }\r
618       }\r
619   }\r
620 \r
621   public void drawLineGraph(Graphics g, AlignmentAnnotation aa,\r
622                             int sRes, int eRes,\r
623                             int y,\r
624                             float min, float max,\r
625                             int graphHeight)\r
626   {\r
627     if(sRes>aa.annotations.length)\r
628       return;\r
629 \r
630 \r
631 \r
632     int x = 0;\r
633 \r
634     //Adjustment for fastpaint to left\r
635     if(eRes<av.endRes)\r
636       eRes++;\r
637 \r
638     eRes = Math.min(eRes, aa.annotations.length);\r
639 \r
640 \r
641     if(sRes==0)\r
642     {\r
643       sRes++;\r
644       x+=av.charWidth;\r
645     }\r
646 \r
647     int y1=y, y2=y;\r
648     float range = max - min;\r
649 \r
650     ////Draw origin\r
651     if(min<0)\r
652       y2 = y - (int)((0-min / range)*graphHeight);\r
653 \r
654     g.setColor(Color.gray);\r
655     g.drawLine(x-av.charWidth,y2,(eRes-sRes)*av.charWidth,y2);\r
656 \r
657     eRes = Math.min(eRes, aa.annotations.length);\r
658 \r
659     int column;\r
660     int aaMax = aa.annotations.length-1;\r
661 \r
662     while( x < eRes - sRes )\r
663     {\r
664       column = sRes + x;\r
665       if(av.hasHiddenColumns)\r
666       {\r
667         column = av.getColumnSelection().adjustForHiddenColumns(column);\r
668       }\r
669 \r
670       if (column > aaMax)\r
671       {\r
672         break;\r
673       }\r
674 \r
675       if(aa.annotations[column]==null || aa.annotations[column-1]==null)\r
676       {\r
677         x++;\r
678         continue;\r
679       }\r
680 \r
681         g.setColor(aa.annotations[column].colour);\r
682         y1 = y - (int) (((aa.annotations[column-1].value-min) / range) * graphHeight);\r
683         y2 = y - (int) (((aa.annotations[column].value-min) / range) * graphHeight);\r
684 \r
685         g.drawLine(x*av.charWidth-av.charWidth/2, y1, x*av.charWidth+av.charWidth/2, y2);\r
686         x ++;\r
687      }\r
688 \r
689      if(aa.threshold!=null)\r
690      {\r
691          g.setColor(aa.threshold.colour);\r
692 \r
693          y2 = (int)(y - ((aa.threshold.value-min) / range)*graphHeight);\r
694          g.drawLine(0,y2,(eRes-sRes)*av.charWidth,y2);\r
695     }\r
696   }\r
697 \r
698   public void drawBarGraph(Graphics g, AlignmentAnnotation aa,\r
699                            int sRes, int eRes,\r
700                            float min, float max,\r
701                            int y)\r
702   {\r
703     if(sRes>aa.annotations.length)\r
704       return;\r
705 \r
706     eRes = Math.min(eRes, aa.annotations.length);\r
707 \r
708     int x=0, y1=y, y2=y;\r
709 \r
710     float range = max - min;\r
711 \r
712     if(min<0)\r
713       y2 = y - (int)((0-min / (range))*aa.graphHeight);\r
714 \r
715     g.setColor(Color.gray);\r
716 \r
717     g.drawLine(x,y2,(eRes-sRes)*av.charWidth,y2);\r
718 \r
719     int column;\r
720     int aaMax = aa.annotations.length-1;\r
721 \r
722     while( x < eRes-sRes )\r
723     {\r
724       column = sRes + x;\r
725       if(av.hasHiddenColumns)\r
726       {\r
727         column = av.getColumnSelection().adjustForHiddenColumns(column);\r
728       }\r
729 \r
730       if(column > aaMax)\r
731       {\r
732           break;\r
733       }\r
734 \r
735       if (aa.annotations[column] == null)\r
736       {\r
737         x ++;\r
738         continue;\r
739       }\r
740 \r
741         g.setColor(aa.annotations[column].colour);\r
742         y1 = y - (int) (((aa.annotations[column].value-min) / (range)) * aa.graphHeight);\r
743 \r
744         if(y1-y2>0)\r
745           g.fillRect(x*av.charWidth, y2, av.charWidth, y1-y2 );\r
746         else\r
747           g.fillRect(x*av.charWidth, y1, av.charWidth, y2-y1 );\r
748 \r
749         x ++ ;\r
750 \r
751     }\r
752     if(aa.threshold!=null)\r
753     {\r
754         g.setColor(aa.threshold.colour);\r
755         y2 = (int)(y - ((aa.threshold.value-min) / range)*aa.graphHeight);\r
756         g.drawLine(0,y2,(eRes-sRes)*av.charWidth,y2);\r
757       }\r
758   }\r
759 \r
760   // used by overview window\r
761   public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y, int sRes, int eRes)\r
762   {\r
763       g.setColor(Color.white);\r
764       g.fillRect(0, 0, width, y);\r
765       g.setColor(new Color(0, 0, 180));\r
766 \r
767       int x = 0, height;\r
768 \r
769       for (int j = sRes; j < eRes; j++)\r
770       {\r
771           g.setColor(aa.annotations[j].colour);\r
772 \r
773           height = (int) ((aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT);\r
774           if(height>y)\r
775               height = y;\r
776           g.fillRect(x, y - height, av.charWidth, height);\r
777           x += av.charWidth;\r
778       }\r
779     }\r
780 }\r