2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\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
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
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
20 package jalview.appletgui;
\r
25 import java.awt.event.*;
\r
27 import jalview.datamodel.*;
\r
29 public class AnnotationPanel
\r
30 extends Panel implements AdjustmentListener
\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
50 boolean fastPaint = false;
\r
52 public static int GRAPH_HEIGHT = 40;
\r
54 boolean MAC = false;
\r
56 public AnnotationPanel(AlignmentPanel ap)
\r
58 if (System.getProperty("os.name").startsWith("Mac"))
\r
64 adjustPanelHeight();
\r
66 addMouseMotionListener(new MouseMotionAdapter()
\r
68 public void mouseMoved(MouseEvent evt)
\r
74 // ap.annotationScroller.getVAdjustable().addAdjustmentListener( this );
\r
78 public AnnotationPanel(AlignViewport av)
\r
84 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
86 ap.alabels.setScrollOffset( -evt.getValue());
\r
89 public int adjustPanelHeight()
\r
91 // setHeight of panels
\r
92 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
98 for (int i = 0; i < aa.length; i++)
\r
100 if (!aa[i].visible)
\r
109 aa[i].height += av.charHeight;
\r
111 if (aa[i].hasIcons)
\r
113 aa[i].height += 16;
\r
118 aa[i].height += GRAPH_HEIGHT;
\r
121 if (aa[i].height == 0)
\r
125 height += aa[i].height;
\r
133 this.setSize(getSize().width, height);
\r
141 public void addEditableColumn(int i)
\r
143 if (activeRow == -1)
\r
145 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
149 for (int j = 0; j < aa.length; j++)
\r
151 if (aa[j].editable)
\r
159 if (activeRes == null)
\r
161 activeRes = new Vector();
\r
162 activeRes.addElement(String.valueOf(i));
\r
166 activeRes.addElement(String.valueOf(i));
\r
169 public void doMouseMoved(MouseEvent evt)
\r
171 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
179 for (int i = 0; i < aa.length; i++)
\r
184 height += aa[i].height;
\r
187 if (evt.getY() < height)
\r
194 int res = evt.getX() / av.getCharWidth() + av.getStartRes();
\r
196 if(av.hasHiddenColumns)
\r
197 res = av.getColumnSelection().adjustForHiddenColumns(res);
\r
199 if (row > -1 && res < aa[row].annotations.length && aa[row].annotations[res] != null)
\r
201 StringBuffer text = new StringBuffer("Sequence position " + (res + 1) +
\r
203 aa[row].annotations[res].description);
\r
204 ap.alignFrame.statusBar.setText(text.toString());
\r
208 public void update(Graphics g)
\r
213 public void paint(Graphics g)
\r
216 imgWidth = (av.endRes - av.startRes + 1) * av.charWidth;
\r
218 if (image == null || imgWidth != image.getWidth(this))
\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
229 g.drawImage(image, 0, 0, this);
\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
240 public void fastPaint(int horizontal)
\r
242 if (horizontal == 0
\r
243 || av.alignment.getAlignmentAnnotation() == null
\r
244 || av.alignment.getAlignmentAnnotation().length < 1
\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
254 if (horizontal > 0) // scrollbar pulled right, image to the left
\r
256 transX = (er - sr - horizontal) * av.charWidth;
\r
257 sr = er - horizontal;
\r
259 else if (horizontal < 0)
\r
261 er = sr - horizontal;
\r
264 gg.translate(transX, 0);
\r
266 drawComponent(gg, sr, er);
\r
268 gg.translate( -transX, 0);
\r
277 * @param g DOCUMENT ME!
\r
278 * @param startRes DOCUMENT ME!
\r
279 * @param endRes DOCUMENT ME!
\r
281 public void drawComponent(Graphics g, int startRes, int endRes)
\r
283 g.setFont(av.getFont());
\r
286 fm = g.getFontMetrics();
\r
289 g.setColor(Color.white);
\r
290 g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getSize().height);
\r
292 if ((av.alignment.getAlignmentAnnotation() == null) ||
\r
293 (av.alignment.getAlignmentAnnotation().length < 1))
\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
304 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
311 int iconOffset = av.charHeight / 2;
\r
312 boolean validRes = false;
\r
314 boolean [] graphGroupDrawn = new boolean[aa.length];
\r
318 for (int i = 0; i < aa.length; i++)
\r
320 AlignmentAnnotation row = aa[i];
\r
332 if(row.graphGroup>-1 && graphGroupDrawn[ row.graphGroup ] )
\r
335 // this is so that we draw the characters below the graph
\r
340 y -= av.charHeight;
\r
346 iconOffset = av.charHeight / 2;
\r
354 while(x < endRes-startRes)
\r
356 if (av.hasHiddenColumns)
\r
358 column = av.getColumnSelection().adjustForHiddenColumns(startRes+x);
\r
359 if (column > row.annotations.length-1)
\r
365 column = startRes+x;
\r
367 if ( (row.annotations.length <= column) ||
\r
368 (row.annotations[column] == null))
\r
378 if (av.validCharWidth && validRes &&
\r
379 (row.annotations[column].displayCharacter.length() > 0))
\r
381 int charOffset = (av.charWidth -
\r
382 fm.charWidth(row.annotations[column].displayCharacter.charAt(
\r
384 g.setColor(row.annotations[column].colour);
\r
386 if (column == 0 || row.graph>0)
\r
388 g.drawString(row.annotations[column].displayCharacter,
\r
389 (x*av.charWidth)+charOffset,
\r
390 y + iconOffset + 3);
\r
393 row.annotations[column - 1] == null
\r
394 ||(!row.annotations[column].displayCharacter.equals(
\r
395 row.annotations[column - 1].displayCharacter)
\r
397 (row.annotations[column].displayCharacter.length() <2 &&
\r
398 row.annotations[column].secondaryStructure==' ')))
\r
400 g.drawString(row.annotations[column].displayCharacter,
\r
401 (x*av.charWidth)+charOffset,
\r
402 y + iconOffset + 3);
\r
409 (row.annotations[column].secondaryStructure != lastSS))
\r
414 g.setColor(HELIX_COLOUR);
\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
424 int sCol = (lastSSX / av.charWidth) + startRes;
\r
426 int x2 = (x*av.charWidth);
\r
429 row.annotations[sCol-1]==null ||
\r
430 row.annotations[sCol-1].secondaryStructure!='H')
\r
432 g.fillArc(lastSSX, y+4+iconOffset, av.charWidth, 8, 90,180) ;
\r
433 x1 += av.charWidth/2;
\r
436 if(row.annotations[column]==null ||
\r
437 row.annotations[column].secondaryStructure!='H')
\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
444 g.fillRect(x1, y+4+iconOffset, x2-x1, 8);
\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
456 y + iconOffset, y + 14 + iconOffset,
\r
464 g.setColor(Color.gray);
\r
465 g.fillRect(lastSSX, y + 6 + iconOffset,
\r
466 (x*av.charWidth) - lastSSX, 2);
\r
473 lastSS = row.annotations[column].secondaryStructure;
\r
480 lastSSX = (x*av.charWidth);
\r
489 if(column>=row.annotations.length)
\r
490 column = row.annotations.length-1;
\r
499 g.setColor(HELIX_COLOUR);
\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
509 int sCol = (lastSSX / av.charWidth) + startRes;
\r
511 int x2 = (x*av.charWidth);
\r
514 row.annotations[sCol - 1] == null ||
\r
515 row.annotations[sCol - 1].secondaryStructure != 'H')
\r
517 g.fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8, 90, 180);
\r
518 x1 += av.charWidth / 2;
\r
521 if (row.annotations[column] == null ||
\r
522 row.annotations[column].secondaryStructure != 'H')
\r
524 g.fillArc((x*av.charWidth) - av.charWidth,
\r
525 y + 4 + iconOffset, av.charWidth, 8, 270,
\r
527 x2 -= av.charWidth / 2;
\r
530 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
\r
535 g.setColor(SHEET_COLOUR);
\r
537 if (row.annotations[endRes] == null
\r
538 || row.annotations[endRes].secondaryStructure != 'E')
\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
548 y + iconOffset, y + 14 + iconOffset,
\r
554 g.fillRect(lastSSX, y + 4 + iconOffset,
\r
555 (x+1) * av.charWidth - lastSSX, 7);
\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
571 if(row.graph == AlignmentAnnotation.LINE_GRAPH )
\r
573 if(row.graphGroup>-1 && !graphGroupDrawn[row.graphGroup])
\r
575 float groupmax=-999999, groupmin=9999999;
\r
576 for(int gg=0; gg<aa.length; gg++)
\r
578 if(aa[gg].graphGroup!=row.graphGroup)
\r
582 aa[gg].visible = false;
\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
590 for (int gg = 0; gg < aa.length; gg++)
\r
592 if (aa[gg].graphGroup == row.graphGroup)
\r
594 drawLineGraph(g, aa[gg], startRes, endRes, y,
\r
595 groupmin, groupmax,
\r
600 graphGroupDrawn[ row.graphGroup ] = true;
\r
603 drawLineGraph(g, row, startRes, endRes,
\r
604 y, row.graphMin, row.graphMax, row.graphHeight );
\r
606 else if(row.graph == AlignmentAnnotation.BAR_GRAPH )
\r
607 drawBarGraph(g, row, startRes, endRes,
\r
608 row.graphMin, row.graphMax, y);
\r
611 if (row.graph>0 && row.hasText)
\r
613 y += av.charHeight;
\r
623 public void drawLineGraph(Graphics g, AlignmentAnnotation aa,
\r
624 int sRes, int eRes,
\r
626 float min, float max,
\r
629 if(sRes>aa.annotations.length)
\r
636 //Adjustment for fastpaint to left
\r
640 eRes = Math.min(eRes, aa.annotations.length);
\r
650 float range = max - min;
\r
654 y2 = y - (int)((0-min / range)*graphHeight);
\r
656 g.setColor(Color.gray);
\r
657 g.drawLine(x-av.charWidth,y2,(eRes-sRes)*av.charWidth,y2);
\r
659 eRes = Math.min(eRes, aa.annotations.length);
\r
662 int aaMax = aa.annotations.length-1;
\r
664 while( x < eRes - sRes )
\r
667 if(av.hasHiddenColumns)
\r
669 column = av.getColumnSelection().adjustForHiddenColumns(column);
\r
672 if (column > aaMax)
\r
677 if(aa.annotations[column]==null || aa.annotations[column-1]==null)
\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
687 g.drawLine(x*av.charWidth-av.charWidth/2, y1, x*av.charWidth+av.charWidth/2, y2);
\r
691 if(aa.threshold!=null)
\r
693 g.setColor(aa.threshold.colour);
\r
695 y2 = (int)(y - ((aa.threshold.value-min) / range)*graphHeight);
\r
696 g.drawLine(0,y2,(eRes-sRes)*av.charWidth,y2);
\r
700 public void drawBarGraph(Graphics g, AlignmentAnnotation aa,
\r
701 int sRes, int eRes,
\r
702 float min, float max,
\r
705 if(sRes>aa.annotations.length)
\r
708 eRes = Math.min(eRes, aa.annotations.length);
\r
710 int x=0, y1=y, y2=y;
\r
712 float range = max - min;
\r
715 y2 = y - (int)((0-min / (range))*aa.graphHeight);
\r
717 g.setColor(Color.gray);
\r
719 g.drawLine(x,y2,(eRes-sRes)*av.charWidth,y2);
\r
722 int aaMax = aa.annotations.length-1;
\r
724 while( x < eRes-sRes )
\r
727 if(av.hasHiddenColumns)
\r
729 column = av.getColumnSelection().adjustForHiddenColumns(column);
\r
737 if (aa.annotations[column] == null)
\r
743 g.setColor(aa.annotations[column].colour);
\r
744 y1 = y - (int) (((aa.annotations[column].value-min) / (range)) * aa.graphHeight);
\r
747 g.fillRect(x*av.charWidth, y2, av.charWidth, y1-y2 );
\r
749 g.fillRect(x*av.charWidth, y1, av.charWidth, y2-y1 );
\r
754 if(aa.threshold!=null)
\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
762 // used by overview window
\r
763 public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y, int sRes, int eRes)
\r
765 g.setColor(Color.white);
\r
766 g.fillRect(0, 0, width, y);
\r
767 g.setColor(new Color(0, 0, 180));
\r
771 for (int j = sRes; j < eRes; j++)
\r
773 g.setColor(aa.annotations[j].colour);
\r
775 height = (int) ((aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT);
\r
778 g.fillRect(x, y - height, av.charWidth, height);
\r