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 public AnnotationPanel(AlignmentPanel ap)
\r
58 this.setLayout(null);
\r
59 adjustPanelHeight();
\r
61 addMouseMotionListener(new MouseMotionAdapter()
\r
63 public void mouseMoved(MouseEvent evt)
\r
69 // ap.annotationScroller.getVAdjustable().addAdjustmentListener( this );
\r
73 public AnnotationPanel(AlignViewport av)
\r
79 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
81 ap.alabels.setScrollOffset( -evt.getValue());
\r
84 public int adjustPanelHeight()
\r
86 // setHeight of panels
\r
87 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
93 for (int i = 0; i < aa.length; i++)
\r
104 aa[i].height += av.charHeight;
\r
106 if (aa[i].hasIcons)
\r
108 aa[i].height += 16;
\r
113 aa[i].height += GRAPH_HEIGHT;
\r
116 if (aa[i].height == 0)
\r
120 height += aa[i].height;
\r
128 this.setSize(getSize().width, height);
\r
130 ap.annotationScroller.setSize(getSize().width, height);
\r
139 public void addEditableColumn(int i)
\r
141 if (activeRow == -1)
\r
143 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
147 for (int j = 0; j < aa.length; j++)
\r
149 if (aa[j].editable)
\r
157 if (activeRes == null)
\r
159 activeRes = new Vector();
\r
160 activeRes.addElement(String.valueOf(i));
\r
164 activeRes.addElement(String.valueOf(i));
\r
167 public void doMouseMoved(MouseEvent evt)
\r
169 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
177 for (int i = 0; i < aa.length; i++)
\r
182 height += aa[i].height;
\r
185 if (evt.getY() < height)
\r
192 int res = evt.getX() / av.getCharWidth() + av.getStartRes();
\r
193 if (row > -1 && res < aa[row].annotations.length && aa[row].annotations[res] != null)
\r
195 StringBuffer text = new StringBuffer("Sequence position " + (res + 1) +
\r
197 aa[row].annotations[res].description);
\r
198 ap.alignFrame.statusBar.setText(text.toString());
\r
202 public void update(Graphics g)
\r
207 public void paint(Graphics g)
\r
209 g.setColor(Color.white);
\r
210 g.fillRect(0,0, getSize().width, getSize().height);
\r
211 imgWidth = (av.endRes - av.startRes + 1) * av.charWidth;
\r
213 if (image == null || imgWidth != image.getWidth(this))
\r
215 image = createImage(imgWidth, ap.annotationPanel.getSize().height);
\r
216 gg = image.getGraphics();
\r
217 gg.setFont(av.getFont());
\r
218 fm = gg.getFontMetrics();
\r
224 g.drawImage(image, 0, 0, this);
\r
229 drawComponent(gg, av.startRes, av.endRes + 1);
\r
230 g.drawImage(image, 0, 0, this);
\r
233 public void fastPaint(int horizontal)
\r
235 if (horizontal == 0
\r
236 || av.alignment.getAlignmentAnnotation() == null
\r
237 || av.alignment.getAlignmentAnnotation().length < 1
\r
244 gg.copyArea(0, 0, imgWidth, getSize().height, -horizontal * av.charWidth, 0);
\r
245 int sr = av.startRes, er = av.endRes + 1, transX = 0;
\r
247 if (horizontal > 0) // scrollbar pulled right, image to the left
\r
249 transX = (er - sr - horizontal) * av.charWidth;
\r
250 sr = er - horizontal;
\r
252 else if (horizontal < 0)
\r
254 er = sr - horizontal;
\r
257 gg.translate(transX, 0);
\r
259 drawComponent(gg, sr, er);
\r
261 gg.translate( -transX, 0);
\r
270 * @param g DOCUMENT ME!
\r
271 * @param startRes DOCUMENT ME!
\r
272 * @param endRes DOCUMENT ME!
\r
274 public void drawComponent(Graphics g, int startRes, int endRes)
\r
276 g.setFont(av.getFont());
\r
279 fm = g.getFontMetrics();
\r
282 g.setColor(Color.white);
\r
283 g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getSize().height);
\r
285 if ((av.alignment.getAlignmentAnnotation() == null) ||
\r
286 (av.alignment.getAlignmentAnnotation().length < 1))
\r
288 g.setColor(Color.white);
\r
289 g.fillRect(0, 0, getSize().width, getSize().height);
\r
290 g.setColor(Color.black);
\r
291 g.drawString("Alignment has no annotations", 20, 15);
\r
296 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
301 char[] lastSS = new char[aa.length];
\r
302 int[] lastSSX = new int[aa.length];
\r
303 int iconOffset = av.charHeight / 2;
\r
304 boolean validRes = false;
\r
306 boolean [] graphGroupDrawn = new boolean[aa.length];
\r
310 for (int i = 0; i < aa.length; i++)
\r
312 AlignmentAnnotation row = aa[i];
\r
323 if(row.graphGroup>-1 && graphGroupDrawn[ row.graphGroup ] )
\r
326 // this is so that we draw the characters below the graph
\r
331 y -= av.charHeight;
\r
337 iconOffset = av.charHeight / 2;
\r
344 for (j = startRes; j < endRes; j++)
\r
346 if ((row.annotations.length <= j) ||
\r
347 (row.annotations[j] == null))
\r
356 x = (j - startRes) * av.charWidth;
\r
358 if (activeRow == i)
\r
360 g.setColor(Color.red);
\r
362 if (activeRes != null)
\r
364 for (int n = 0; n < activeRes.size(); n++)
\r
366 int v = Integer.parseInt(activeRes.elementAt(n).toString());
\r
370 g.fillRect((j - startRes) * av.charWidth, y,
\r
371 av.charWidth, row.height);
\r
378 (row.annotations[j].displayCharacter.length() > 0))
\r
381 int charOffset = (av.charWidth -
\r
382 fm.charWidth(row.annotations[j].displayCharacter.charAt(
\r
384 g.setColor(row.annotations[j].colour);
\r
386 if (j == 0 || row.graph>0)
\r
388 g.drawString(row.annotations[j].displayCharacter, x+charOffset,
\r
389 y + iconOffset + 3);
\r
391 else if (((row.annotations[j - 1] == null) ||
\r
392 (row.annotations[j].displayCharacter != row.annotations[j -
\r
393 1].displayCharacter)))
\r
395 g.drawString(row.annotations[j].displayCharacter, x+charOffset,
\r
396 y + iconOffset + 3);
\r
403 (row.annotations[j].secondaryStructure != lastSS[i]))
\r
408 g.setColor(HELIX_COLOUR);
\r
409 g.fillRoundRect(lastSSX[i], y + 4 + iconOffset,
\r
410 x - lastSSX[i], 7, 8, 8);
\r
415 g.setColor(SHEET_COLOUR);
\r
416 g.fillRect(lastSSX[i], y + 4 + iconOffset,
\r
417 x - lastSSX[i] - 4, 7);
\r
418 g.fillPolygon(new int[] { x - 4, x - 4, x },
\r
421 y + iconOffset, y + 14 + iconOffset,
\r
429 g.setColor(Color.gray);
\r
430 g.fillRect(lastSSX[i], y + 6 + iconOffset,
\r
431 x - lastSSX[i], 2);
\r
438 lastSS[i] = row.annotations[j].secondaryStructure;
\r
457 g.setColor(HELIX_COLOUR);
\r
458 g.fillRoundRect(lastSSX[i], y + 4 + iconOffset,
\r
459 x - lastSSX[i], 7, 8, 8);
\r
464 g.setColor(SHEET_COLOUR);
\r
466 if (row.annotations.length > endRes
\r
467 && row.annotations[endRes].secondaryStructure != 'E')
\r
469 g.fillRect(lastSSX[i], y + 4 + iconOffset,
\r
470 x - lastSSX[i] - 4, 7);
\r
471 g.fillPolygon(new int[]
\r
475 y + iconOffset, y + 14 + iconOffset,
\r
480 g.fillRect(lastSSX[i], y + 4 + iconOffset,
\r
481 x - lastSSX[i], 7);
\r
489 g.setColor(Color.gray);
\r
490 g.fillRect(lastSSX[i], y + 6 + iconOffset, x - lastSSX[i], 2);
\r
498 if(row.graph == AlignmentAnnotation.LINE_GRAPH )
\r
500 if(row.graphGroup>-1 && !graphGroupDrawn[row.graphGroup])
\r
502 float groupmax=-999999, groupmin=9999999;
\r
503 for(int gg=0; gg<aa.length; gg++)
\r
505 if(aa[gg].graphGroup!=row.graphGroup)
\r
509 aa[gg].visible = false;
\r
511 if(aa[gg].graphMax>groupmax)
\r
512 groupmax = aa[gg].graphMax;
\r
513 if(aa[gg].graphMin<groupmin)
\r
514 groupmin = aa[gg].graphMin;
\r
517 for (int gg = 0; gg < aa.length; gg++)
\r
519 if (aa[gg].graphGroup == row.graphGroup)
\r
521 drawLineGraph(g, aa[gg], startRes, endRes, y,
\r
522 groupmin, groupmax,
\r
527 graphGroupDrawn[ row.graphGroup ] = true;
\r
530 drawLineGraph(g, row, startRes, endRes,
\r
531 y, row.graphMin, row.graphMax, row.graphHeight );
\r
533 else if(row.graph == AlignmentAnnotation.BAR_GRAPH )
\r
534 drawBarGraph(g, row, startRes, endRes,
\r
535 row.graphMin, row.graphMax, y);
\r
538 if (row.graph>0 && row.hasText)
\r
540 y += av.charHeight;
\r
550 public void drawLineGraph(Graphics g, AlignmentAnnotation aa,
\r
551 int sRes, int eRes,
\r
553 float min, float max,
\r
556 if(sRes>aa.annotations.length)
\r
561 //Adjustment for fastpaint to left
\r
572 float range = max - min;
\r
576 y2 = (int)(y - (0-min / range)*graphHeight);
\r
578 g.setColor(Color.gray);
\r
579 g.drawLine(x-av.charWidth,y2,(eRes-sRes+1)*av.charWidth,y2);
\r
582 if(aa.threshold!=null)
\r
584 g.setColor(aa.threshold.colour);
\r
585 y2 = (int)(y - ((aa.threshold.value-min) / range)*graphHeight);
\r
586 g.drawLine(x-av.charWidth,y2,(eRes-sRes+1)*av.charWidth,y2);
\r
589 eRes = Math.min(eRes, aa.annotations.length);
\r
590 for (int j = sRes; j < eRes; j++)
\r
592 if(aa.annotations[j]==null || aa.annotations[j-1]==null)
\r
597 g.setColor(aa.annotations[j].colour);
\r
598 y1 = y - (int) (((aa.annotations[j-1].value-min) / range) * graphHeight);
\r
599 y2 = y - (int) (((aa.annotations[j].value-min) / range) * graphHeight);
\r
600 g.drawLine(x-av.charWidth/2, y1, x+av.charWidth/2, y2);
\r
605 public void drawBarGraph(Graphics g, AlignmentAnnotation aa,
\r
606 int sRes, int eRes,
\r
607 float min, float max,
\r
610 if(sRes>aa.annotations.length)
\r
615 float range = max - min;
\r
617 if(aa.threshold!=null)
\r
619 g.setColor(aa.threshold.colour);
\r
620 y2 = (int)(y - ((aa.threshold.value-min) / range)*aa.graphHeight);
\r
621 g.drawLine(x-av.charWidth,y2,(eRes-sRes+1)*av.charWidth,y2);
\r
627 y2 = (int)(y - (0-min / (range))*aa.graphHeight);
\r
629 g.setColor(Color.gray);
\r
631 g.drawLine(x,y2,(eRes-sRes+1)*av.charWidth,y2);
\r
633 eRes = Math.min(eRes, aa.annotations.length-1);
\r
636 for (int j = sRes; j < eRes; j++)
\r
639 if (aa.annotations[j] == null)
\r
645 g.setColor(aa.annotations[j].colour);
\r
646 y1 = y - (int) (((aa.annotations[j].value-min) / (range)) * aa.graphHeight);
\r
649 g.fillRect(x, y2, av.charWidth, y1-y2 );
\r
651 g.fillRect(x, y1, av.charWidth, y2-y1 );
\r
658 // used by overview window
\r
659 public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y, int sRes, int eRes)
\r
661 g.setColor(Color.white);
\r
662 g.fillRect(0, 0, width, y);
\r
663 g.setColor(new Color(0, 0, 180));
\r
667 for (int j = sRes; j < eRes; j++)
\r
669 g.setColor(aa.annotations[j].colour);
\r
671 height = (int) ((aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT);
\r
674 g.fillRect(x, y - height, av.charWidth, height);
\r