2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 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
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
208 public void update(Graphics g)
\r
213 public void paint(Graphics g)
\r
216 imgWidth = getSize().width;
\r
217 //(av.endRes - av.startRes + 1) * av.charWidth;
\r
219 if (image == null || imgWidth != image.getWidth(this))
\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
231 g.drawImage(image, 0, 0, this);
\r
236 gg.setColor(Color.white);
\r
237 gg.fillRect(0, 0, getSize().width, getSize().height);
\r
238 drawComponent(gg, av.startRes, av.endRes + 1);
\r
241 g.drawImage(image, 0, 0, this);
\r
244 public void fastPaint(int horizontal)
\r
246 if (horizontal == 0
\r
247 || av.alignment.getAlignmentAnnotation() == null
\r
248 || av.alignment.getAlignmentAnnotation().length < 1
\r
255 gg.copyArea(0, 0, imgWidth, getSize().height, -horizontal * av.charWidth, 0);
\r
256 int sr = av.startRes, er = av.endRes + 1, transX = 0;
\r
258 if (horizontal > 0) // scrollbar pulled right, image to the left
\r
260 transX = (er - sr - horizontal) * av.charWidth;
\r
261 sr = er - horizontal;
\r
263 else if (horizontal < 0)
\r
265 er = sr - horizontal;
\r
268 gg.translate(transX, 0);
\r
270 drawComponent(gg, sr, er);
\r
272 gg.translate( -transX, 0);
\r
281 * @param g DOCUMENT ME!
\r
282 * @param startRes DOCUMENT ME!
\r
283 * @param endRes DOCUMENT ME!
\r
285 public void drawComponent(Graphics g, int startRes, int endRes)
\r
287 g.setFont(av.getFont());
\r
290 g.setColor(Color.white);
\r
291 g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getSize().height);
\r
295 fm = g.getFontMetrics();
\r
298 if ((av.alignment.getAlignmentAnnotation() == null) ||
\r
299 (av.alignment.getAlignmentAnnotation().length < 1))
\r
301 g.setColor(Color.white);
\r
302 g.fillRect(0, 0, getSize().width, getSize().height);
\r
303 g.setColor(Color.black);
\r
304 if(av.validCharWidth)
\r
305 g.drawString("Alignment has no annotations", 20, 15);
\r
310 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
317 int iconOffset = av.charHeight / 2;
\r
318 boolean validRes = false;
\r
320 boolean [] graphGroupDrawn = new boolean[aa.length];
\r
324 for (int i = 0; i < aa.length; i++)
\r
326 AlignmentAnnotation row = aa[i];
\r
338 if(row.graphGroup>-1 && graphGroupDrawn[ row.graphGroup ] )
\r
341 // this is so that we draw the characters below the graph
\r
346 y -= av.charHeight;
\r
352 iconOffset = av.charHeight / 2;
\r
360 while(x < endRes-startRes)
\r
362 if (av.hasHiddenColumns)
\r
364 column = av.getColumnSelection().adjustForHiddenColumns(startRes+x);
\r
365 if (column > row.annotations.length-1)
\r
371 column = startRes+x;
\r
373 if ( (row.annotations.length <= column) ||
\r
374 (row.annotations[column] == null))
\r
384 if (av.validCharWidth && validRes &&
\r
385 (row.annotations[column].displayCharacter.length() > 0))
\r
387 int charOffset = (av.charWidth -
\r
388 fm.charWidth(row.annotations[column].displayCharacter.charAt(
\r
390 g.setColor(row.annotations[column].colour);
\r
392 if (column == 0 || row.graph>0)
\r
394 g.drawString(row.annotations[column].displayCharacter,
\r
395 (x*av.charWidth)+charOffset,
\r
396 y + iconOffset + 3);
\r
399 row.annotations[column - 1] == null
\r
400 ||(!row.annotations[column].displayCharacter.equals(
\r
401 row.annotations[column - 1].displayCharacter)
\r
403 (row.annotations[column].displayCharacter.length() <2 &&
\r
404 row.annotations[column].secondaryStructure==' ')))
\r
406 g.drawString(row.annotations[column].displayCharacter,
\r
407 (x*av.charWidth)+charOffset,
\r
408 y + iconOffset + 3);
\r
415 (row.annotations[column].secondaryStructure != lastSS))
\r
420 g.setColor(HELIX_COLOUR);
\r
423 //Off by 1 offset when drawing rects and ovals
\r
424 //to offscreen image on the MAC
\r
425 g.fillRoundRect(lastSSX, y + 4 + iconOffset,
\r
426 (x*av.charWidth) - lastSSX, 7, 8, 8);
\r
430 int sCol = (lastSSX / av.charWidth) + startRes;
\r
432 int x2 = (x*av.charWidth);
\r
435 row.annotations[sCol-1]==null ||
\r
436 row.annotations[sCol-1].secondaryStructure!='H')
\r
438 g.fillArc(lastSSX, y+4+iconOffset, av.charWidth, 8, 90,180) ;
\r
439 x1 += av.charWidth/2;
\r
442 if(row.annotations[column]==null ||
\r
443 row.annotations[column].secondaryStructure!='H')
\r
445 g.fillArc((x*av.charWidth)-av.charWidth,
\r
446 y+4+iconOffset, av.charWidth, 8, 270,180);
\r
447 x2 -= av.charWidth/2;
\r
450 g.fillRect(x1, y+4+iconOffset, x2-x1, 8);
\r
454 g.setColor(SHEET_COLOUR);
\r
455 g.fillRect(lastSSX, y + 4 + iconOffset,
\r
456 (x*av.charWidth) - lastSSX - 4, 7);
\r
457 g.fillPolygon(new int[] { (x*av.charWidth) - 4,
\r
458 (x*av.charWidth) - 4,
\r
459 (x*av.charWidth) },
\r
462 y + iconOffset, y + 14 + iconOffset,
\r
470 g.setColor(Color.gray);
\r
471 g.fillRect(lastSSX, y + 6 + iconOffset,
\r
472 (x*av.charWidth) - lastSSX, 2);
\r
479 lastSS = row.annotations[column].secondaryStructure;
\r
486 lastSSX = (x*av.charWidth);
\r
495 if(column>=row.annotations.length)
\r
496 column = row.annotations.length-1;
\r
505 g.setColor(HELIX_COLOUR);
\r
508 //Off by 1 offset when drawing rects and ovals
\r
509 //to offscreen image on the MAC
\r
510 g.fillRoundRect(lastSSX, y + 4 + iconOffset,
\r
511 (x*av.charWidth) - lastSSX, 7, 8, 8);
\r
515 int sCol = (lastSSX / av.charWidth) + startRes;
\r
517 int x2 = (x*av.charWidth);
\r
520 row.annotations[sCol - 1] == null ||
\r
521 row.annotations[sCol - 1].secondaryStructure != 'H')
\r
523 g.fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8, 90, 180);
\r
524 x1 += av.charWidth / 2;
\r
527 if (row.annotations[column] == null ||
\r
528 row.annotations[column].secondaryStructure != 'H')
\r
530 g.fillArc((x*av.charWidth) - av.charWidth,
\r
531 y + 4 + iconOffset, av.charWidth, 8, 270,
\r
533 x2 -= av.charWidth / 2;
\r
536 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
\r
541 g.setColor(SHEET_COLOUR);
\r
543 if (row.annotations[endRes] == null
\r
544 || row.annotations[endRes].secondaryStructure != 'E')
\r
546 g.fillRect(lastSSX, y + 4 + iconOffset,
\r
547 (x*av.charWidth) - lastSSX - 4, 7);
\r
548 g.fillPolygon(new int[]
\r
549 {(x*av.charWidth) - 4,
\r
550 (x*av.charWidth) - 4,
\r
554 y + iconOffset, y + 14 + iconOffset,
\r
560 g.fillRect(lastSSX, y + 4 + iconOffset,
\r
561 x * av.charWidth - lastSSX, 7);
\r
566 g.setColor(Color.gray);
\r
567 if(!av.wrapAlignment || endRes==av.endRes)
\r
568 g.fillRect(lastSSX, y + 6 + iconOffset,
\r
569 (x*av.charWidth) - lastSSX, 2);
\r
577 if(row.graph == AlignmentAnnotation.LINE_GRAPH )
\r
579 if(row.graphGroup>-1 && !graphGroupDrawn[row.graphGroup])
\r
581 float groupmax=-999999, groupmin=9999999;
\r
582 for(int gg=0; gg<aa.length; gg++)
\r
584 if(aa[gg].graphGroup!=row.graphGroup)
\r
588 aa[gg].visible = false;
\r
590 if(aa[gg].graphMax>groupmax)
\r
591 groupmax = aa[gg].graphMax;
\r
592 if(aa[gg].graphMin<groupmin)
\r
593 groupmin = aa[gg].graphMin;
\r
596 for (int gg = 0; gg < aa.length; gg++)
\r
598 if (aa[gg].graphGroup == row.graphGroup)
\r
600 drawLineGraph(g, aa[gg], startRes, endRes, y,
\r
601 groupmin, groupmax,
\r
606 graphGroupDrawn[ row.graphGroup ] = true;
\r
609 drawLineGraph(g, row, startRes, endRes,
\r
610 y, row.graphMin, row.graphMax, row.graphHeight );
\r
612 else if(row.graph == AlignmentAnnotation.BAR_GRAPH )
\r
613 drawBarGraph(g, row, startRes, endRes,
\r
614 row.graphMin, row.graphMax, y);
\r
617 if (row.graph>0 && row.hasText)
\r
619 y += av.charHeight;
\r
629 public void drawLineGraph(Graphics g, AlignmentAnnotation aa,
\r
630 int sRes, int eRes,
\r
632 float min, float max,
\r
635 if(sRes>aa.annotations.length)
\r
642 //Adjustment for fastpaint to left
\r
646 eRes = Math.min(eRes, aa.annotations.length);
\r
656 float range = max - min;
\r
660 y2 = y - (int)((0-min / range)*graphHeight);
\r
662 g.setColor(Color.gray);
\r
663 g.drawLine(x-av.charWidth,y2,(eRes-sRes)*av.charWidth,y2);
\r
665 eRes = Math.min(eRes, aa.annotations.length);
\r
668 int aaMax = aa.annotations.length-1;
\r
670 while( x < eRes - sRes )
\r
673 if(av.hasHiddenColumns)
\r
675 column = av.getColumnSelection().adjustForHiddenColumns(column);
\r
678 if (column > aaMax)
\r
683 if(aa.annotations[column]==null || aa.annotations[column-1]==null)
\r
689 g.setColor(aa.annotations[column].colour);
\r
690 y1 = y - (int) (((aa.annotations[column-1].value-min) / range) * graphHeight);
\r
691 y2 = y - (int) (((aa.annotations[column].value-min) / range) * graphHeight);
\r
693 g.drawLine(x*av.charWidth-av.charWidth/2, y1, x*av.charWidth+av.charWidth/2, y2);
\r
697 if(aa.threshold!=null)
\r
699 g.setColor(aa.threshold.colour);
\r
701 y2 = (int)(y - ((aa.threshold.value-min) / range)*graphHeight);
\r
702 g.drawLine(0,y2,(eRes-sRes)*av.charWidth,y2);
\r
706 public void drawBarGraph(Graphics g, AlignmentAnnotation aa,
\r
707 int sRes, int eRes,
\r
708 float min, float max,
\r
711 if(sRes>aa.annotations.length)
\r
714 eRes = Math.min(eRes, aa.annotations.length);
\r
716 int x=0, y1=y, y2=y;
\r
718 float range = max - min;
\r
721 y2 = y - (int)((0-min / (range))*aa.graphHeight);
\r
723 g.setColor(Color.gray);
\r
725 g.drawLine(x,y2,(eRes-sRes)*av.charWidth,y2);
\r
728 int aaMax = aa.annotations.length-1;
\r
730 while( x < eRes-sRes )
\r
733 if(av.hasHiddenColumns)
\r
735 column = av.getColumnSelection().adjustForHiddenColumns(column);
\r
743 if (aa.annotations[column] == null)
\r
749 g.setColor(aa.annotations[column].colour);
\r
750 y1 = y - (int) (((aa.annotations[column].value-min) / (range)) * aa.graphHeight);
\r
753 g.fillRect(x*av.charWidth, y2, av.charWidth, y1-y2 );
\r
755 g.fillRect(x*av.charWidth, y1, av.charWidth, y2-y1 );
\r
760 if(aa.threshold!=null)
\r
762 g.setColor(aa.threshold.colour);
\r
763 y2 = (int)(y - ((aa.threshold.value-min) / range)*aa.graphHeight);
\r
764 g.drawLine(0,y2,(eRes-sRes)*av.charWidth,y2);
\r
768 // used by overview window
\r
769 public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y, int sRes, int eRes)
\r
771 g.setColor(Color.white);
\r
772 g.fillRect(0, 0, width, y);
\r
773 g.setColor(new Color(0, 0, 180));
\r
777 for (int j = sRes; j < eRes; j++)
\r
779 g.setColor(aa.annotations[j].colour);
\r
781 height = (int) ((aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT);
\r
784 g.fillRect(x, y - height, av.charWidth, height);
\r