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
195 if (row > -1 && res < aa[row].annotations.length && aa[row].annotations[res] != null)
\r
197 StringBuffer text = new StringBuffer("Sequence position " + (res + 1) +
\r
199 aa[row].annotations[res].description);
\r
200 ap.alignFrame.statusBar.setText(text.toString());
\r
204 public void update(Graphics g)
\r
209 public void paint(Graphics g)
\r
213 imgWidth = (av.endRes - av.startRes + 1) * av.charWidth;
\r
215 if (image == null || imgWidth != image.getWidth(this))
\r
217 image = createImage(imgWidth, ap.annotationPanel.getSize().height);
\r
218 gg = image.getGraphics();
\r
219 gg.setFont(av.getFont());
\r
220 fm = gg.getFontMetrics();
\r
226 g.drawImage(image, 0, 0, this);
\r
231 drawComponent(gg, av.startRes, av.endRes + 1);
\r
232 g.setColor(Color.white);
\r
233 g.fillRect(0, 0, getSize().width, getSize().height);
\r
234 g.drawImage(image, 0, 0, this);
\r
237 public void fastPaint(int horizontal)
\r
239 if (horizontal == 0
\r
240 || av.alignment.getAlignmentAnnotation() == null
\r
241 || av.alignment.getAlignmentAnnotation().length < 1
\r
248 gg.copyArea(0, 0, imgWidth, getSize().height, -horizontal * av.charWidth, 0);
\r
249 int sr = av.startRes, er = av.endRes + 1, transX = 0;
\r
251 if (horizontal > 0) // scrollbar pulled right, image to the left
\r
253 transX = (er - sr - horizontal) * av.charWidth;
\r
254 sr = er - horizontal;
\r
256 else if (horizontal < 0)
\r
258 er = sr - horizontal;
\r
261 gg.translate(transX, 0);
\r
263 drawComponent(gg, sr, er);
\r
265 gg.translate( -transX, 0);
\r
274 * @param g DOCUMENT ME!
\r
275 * @param startRes DOCUMENT ME!
\r
276 * @param endRes DOCUMENT ME!
\r
278 public void drawComponent(Graphics g, int startRes, int endRes)
\r
280 g.setFont(av.getFont());
\r
283 fm = g.getFontMetrics();
\r
286 g.setColor(Color.white);
\r
287 g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getSize().height);
\r
289 if ((av.alignment.getAlignmentAnnotation() == null) ||
\r
290 (av.alignment.getAlignmentAnnotation().length < 1))
\r
292 g.setColor(Color.white);
\r
293 g.fillRect(0, 0, getSize().width, getSize().height);
\r
294 g.setColor(Color.black);
\r
295 if(av.validCharWidth)
\r
296 g.drawString("Alignment has no annotations", 20, 15);
\r
301 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
307 int iconOffset = av.charHeight / 2;
\r
308 boolean validRes = false;
\r
310 boolean [] graphGroupDrawn = new boolean[aa.length];
\r
314 for (int i = 0; i < aa.length; i++)
\r
316 AlignmentAnnotation row = aa[i];
\r
328 if(row.graphGroup>-1 && graphGroupDrawn[ row.graphGroup ] )
\r
331 // this is so that we draw the characters below the graph
\r
336 y -= av.charHeight;
\r
342 iconOffset = av.charHeight / 2;
\r
349 int column = startRes;
\r
350 while(column < endRes)
\r
352 if ((row.annotations.length <= column) ||
\r
353 (row.annotations[column] == null))
\r
362 x = (column - startRes) * av.charWidth;
\r
365 if (av.validCharWidth && validRes &&
\r
366 (row.annotations[column].displayCharacter.length() > 0))
\r
368 int charOffset = (av.charWidth -
\r
369 fm.charWidth(row.annotations[column].displayCharacter.charAt(
\r
371 g.setColor(row.annotations[column].colour);
\r
373 if (column == 0 || row.graph>0)
\r
375 g.drawString(row.annotations[column].displayCharacter, x+charOffset,
\r
376 y + iconOffset + 3);
\r
379 row.annotations[column - 1] == null
\r
380 ||(!row.annotations[column].displayCharacter.equals(
\r
381 row.annotations[column - 1].displayCharacter)
\r
383 (row.annotations[column].displayCharacter.length() <2 &&
\r
384 row.annotations[column].secondaryStructure==' ')))
\r
386 g.drawString(row.annotations[column].displayCharacter, x+charOffset,
\r
387 y + iconOffset + 3);
\r
394 (row.annotations[column].secondaryStructure != lastSS))
\r
399 g.setColor(HELIX_COLOUR);
\r
402 //Off by 1 offset when drawing rects and ovals
\r
403 //to offscreen image on the MAC
\r
404 g.fillRoundRect(lastSSX, y + 4 + iconOffset,
\r
405 x - lastSSX, 7, 8, 8);
\r
409 int sCol = (lastSSX / av.charWidth) + startRes;
\r
414 row.annotations[sCol-1]==null ||
\r
415 row.annotations[sCol-1].secondaryStructure!='H')
\r
417 g.fillArc(lastSSX, y+4+iconOffset, av.charWidth, 8, 90,180) ;
\r
418 x1 += av.charWidth/2;
\r
421 if(row.annotations[column]==null ||
\r
422 row.annotations[column].secondaryStructure!='H')
\r
424 g.fillArc(x-av.charWidth, y+4+iconOffset, av.charWidth, 8, 270,180);
\r
425 x2 -= av.charWidth/2;
\r
428 g.fillRect(x1, y+4+iconOffset, x2-x1, 8);
\r
432 g.setColor(SHEET_COLOUR);
\r
433 g.fillRect(lastSSX, y + 4 + iconOffset,
\r
434 x - lastSSX - 4, 7);
\r
435 g.fillPolygon(new int[] { x - 4, x - 4, x },
\r
438 y + iconOffset, y + 14 + iconOffset,
\r
446 g.setColor(Color.gray);
\r
447 g.fillRect(lastSSX, y + 6 + iconOffset,
\r
455 lastSS = row.annotations[column].secondaryStructure;
\r
470 if(column>=row.annotations.length)
\r
471 column = row.annotations.length-1;
\r
480 g.setColor(HELIX_COLOUR);
\r
483 //Off by 1 offset when drawing rects and ovals
\r
484 //to offscreen image on the MAC
\r
485 g.fillRoundRect(lastSSX, y + 4 + iconOffset,
\r
486 x - lastSSX, 7, 8, 8);
\r
491 int sCol = (lastSSX / av.charWidth) + startRes;
\r
496 row.annotations[sCol-1]==null ||
\r
497 row.annotations[sCol-1].secondaryStructure!='H')
\r
499 g.fillArc(lastSSX, y+4+iconOffset, av.charWidth, 8, 90,180) ;
\r
500 x1 += av.charWidth/2;
\r
503 if(row.annotations[column]==null ||
\r
504 row.annotations[column].secondaryStructure!='H')
\r
506 g.fillArc(x-av.charWidth, y+4+iconOffset, av.charWidth, 8, 270,180);
\r
507 x2 -= av.charWidth/2;
\r
510 g.fillRect(x1, y+4+iconOffset, x2-x1, 8);
\r
515 g.setColor(SHEET_COLOUR);
\r
517 if (row.annotations[endRes] ==null
\r
518 || row.annotations[endRes].secondaryStructure != 'E')
\r
520 g.fillRect(lastSSX, y + 4 + iconOffset,
\r
521 x - lastSSX - 4, 7);
\r
522 g.fillPolygon(new int[]
\r
526 y + iconOffset, y + 14 + iconOffset,
\r
531 g.fillRect(lastSSX, y + 4 + iconOffset,
\r
538 g.setColor(Color.gray);
\r
539 g.fillRect(lastSSX, y + 6 + iconOffset, x - lastSSX, 2);
\r
547 if(row.graph == AlignmentAnnotation.LINE_GRAPH )
\r
549 if(row.graphGroup>-1 && !graphGroupDrawn[row.graphGroup])
\r
551 float groupmax=-999999, groupmin=9999999;
\r
552 for(int gg=0; gg<aa.length; gg++)
\r
554 if(aa[gg].graphGroup!=row.graphGroup)
\r
558 aa[gg].visible = false;
\r
560 if(aa[gg].graphMax>groupmax)
\r
561 groupmax = aa[gg].graphMax;
\r
562 if(aa[gg].graphMin<groupmin)
\r
563 groupmin = aa[gg].graphMin;
\r
566 for (int gg = 0; gg < aa.length; gg++)
\r
568 if (aa[gg].graphGroup == row.graphGroup)
\r
570 drawLineGraph(g, aa[gg], startRes, endRes, y,
\r
571 groupmin, groupmax,
\r
576 graphGroupDrawn[ row.graphGroup ] = true;
\r
579 drawLineGraph(g, row, startRes, endRes,
\r
580 y, row.graphMin, row.graphMax, row.graphHeight );
\r
582 else if(row.graph == AlignmentAnnotation.BAR_GRAPH )
\r
583 drawBarGraph(g, row, startRes, endRes,
\r
584 row.graphMin, row.graphMax, y);
\r
587 if (row.graph>0 && row.hasText)
\r
589 y += av.charHeight;
\r
599 public void drawLineGraph(Graphics g, AlignmentAnnotation aa,
\r
600 int sRes, int eRes,
\r
602 float min, float max,
\r
605 if(sRes>aa.annotations.length)
\r
612 //Adjustment for fastpaint to left
\r
616 eRes = Math.min(eRes, aa.annotations.length);
\r
626 float range = max - min;
\r
630 y2 = y - (int)((0-min / range)*graphHeight);
\r
632 g.setColor(Color.gray);
\r
633 g.drawLine(x-av.charWidth,y2,(eRes-sRes)*av.charWidth,y2);
\r
636 for (int j = sRes; j < eRes; j++)
\r
638 if(aa.annotations[j]==null || aa.annotations[j-1]==null)
\r
643 g.setColor(aa.annotations[j].colour);
\r
644 y1 = y - (int) (((aa.annotations[j-1].value-min) / range) * graphHeight);
\r
645 y2 = y - (int) (((aa.annotations[j].value-min) / range) * graphHeight);
\r
646 g.drawLine(x-av.charWidth/2, y1, x+av.charWidth/2, y2);
\r
651 if(aa.threshold!=null)
\r
653 g.setColor(aa.threshold.colour);
\r
654 y2 = (int)(y - ((aa.threshold.value-min) / range)*aa.graphHeight);
\r
655 g.drawLine(0,y2,(eRes-sRes)*av.charWidth,y2);
\r
660 public void drawBarGraph(Graphics g, AlignmentAnnotation aa,
\r
661 int sRes, int eRes,
\r
662 float min, float max,
\r
665 if(sRes>aa.annotations.length)
\r
669 eRes = Math.min(eRes, aa.annotations.length);
\r
673 float range = max - min;
\r
678 y2 = y -(int)( (0-min / (range))*aa.graphHeight);
\r
680 g.setColor(Color.gray);
\r
682 g.drawLine(x,y2,(eRes-sRes)*av.charWidth,y2);
\r
684 for (int j = sRes; j < eRes; j++)
\r
687 if (aa.annotations[j] == null)
\r
693 g.setColor(aa.annotations[j].colour);
\r
694 y1 = y - (int) (((aa.annotations[j].value-min) / (range)) * aa.graphHeight);
\r
697 g.fillRect(x, y2, av.charWidth, y1-y2 );
\r
699 g.fillRect(x, y1, av.charWidth, y2-y1 );
\r
705 if(aa.threshold!=null)
\r
707 g.setColor(aa.threshold.colour);
\r
708 y2 = (int)(y - ((aa.threshold.value-min) / range)*aa.graphHeight);
\r
709 g.drawLine(0,y2,(eRes-sRes)*av.charWidth,y2);
\r
715 // used by overview window
\r
716 public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y, int sRes, int eRes)
\r
718 g.setColor(Color.white);
\r
719 g.fillRect(0, 0, width, y);
\r
720 g.setColor(new Color(0, 0, 180));
\r
724 for (int j = sRes; j < eRes; j++)
\r
726 g.setColor(aa.annotations[j].colour);
\r
728 height = (int) ((aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT);
\r
731 g.fillRect(x, y - height, av.charWidth, height);
\r