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