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
267 public void drawComponent(Graphics g, int startRes, int endRes)
\r
269 g.setFont(av.getFont());
\r
272 fm = g.getFontMetrics();
\r
275 g.setColor(Color.white);
\r
276 g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getSize().height);
\r
278 if ((av.alignment.getAlignmentAnnotation() == null) ||
\r
279 (av.alignment.getAlignmentAnnotation().length < 1))
\r
281 g.setColor(Color.white);
\r
282 g.fillRect(0, 0, getSize().width, getSize().height);
\r
283 g.setColor(Color.black);
\r
284 g.drawString("Alignment has no annotations", 20, 15);
\r
289 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
294 char[] lastSS = new char[aa.length];
\r
295 int[] lastSSX = new int[aa.length];
\r
296 int iconOffset = av.charHeight / 2;
\r
297 boolean validRes = false;
\r
300 for (int i = 0; i < aa.length; i++)
\r
302 AlignmentAnnotation row = aa[i];
\r
312 // this is so that we draw the characters below the graph
\r
317 y -= av.charHeight;
\r
323 iconOffset = av.charHeight / 2;
\r
330 for (j = startRes; j < endRes; j++)
\r
332 if ((row.annotations.length <= j) ||
\r
333 (row.annotations[j] == null))
\r
342 x = (j - startRes) * av.charWidth;
\r
346 (row.annotations[j].displayCharacter.length() > 0))
\r
349 int charOffset = (av.charWidth -
\r
350 fm.charWidth(row.annotations[j].displayCharacter.charAt(
\r
352 g.setColor(row.annotations[j].colour);
\r
354 if (j == 0 || row.isGraph)
\r
356 g.drawString(row.annotations[j].displayCharacter, x+charOffset,
\r
357 y + iconOffset + 3);
\r
359 else if (((row.annotations[j - 1] == null) ||
\r
360 (row.annotations[j].displayCharacter != row.annotations[j -
\r
361 1].displayCharacter)))
\r
363 g.drawString(row.annotations[j].displayCharacter, x+charOffset,
\r
364 y + iconOffset + 3);
\r
371 (row.annotations[j].secondaryStructure != lastSS[i]))
\r
376 g.setColor(HELIX_COLOUR);
\r
377 g.fillRoundRect(lastSSX[i], y + 4 + iconOffset,
\r
378 x - lastSSX[i], 7, 8, 8);
\r
383 g.setColor(SHEET_COLOUR);
\r
384 g.fillRect(lastSSX[i], y + 4 + iconOffset,
\r
385 x - lastSSX[i] - 4, 7);
\r
386 g.fillPolygon(new int[] { x - 4, x - 4, x },
\r
389 y + iconOffset, y + 14 + iconOffset,
\r
399 g.setColor(Color.gray);
\r
400 g.fillRect(lastSSX[i], y + 6 + iconOffset,
\r
401 x - lastSSX[i], 2);
\r
408 lastSS[i] = row.annotations[j].secondaryStructure;
\r
419 if (validRes && row.isGraph)
\r
421 g.setColor(new Color(0, 0, 180));
\r
423 int height = (int) ((row.annotations[j].value / row.graphMax) * GRAPH_HEIGHT);
\r
425 if (row.windowLength > 1)
\r
429 for (int i2 = j - (row.windowLength / 2);
\r
430 i2 < (j + (row.windowLength / 2)); i2++)
\r
432 if ((i2 < 0) || (i2 >= av.alignment.getWidth()))
\r
437 total += row.annotations[i2].value;
\r
440 total /= row.windowLength;
\r
441 height = (int) ((total / row.graphMax) * GRAPH_HEIGHT);
\r
444 g.setColor(row.annotations[j].colour);
\r
445 g.fillRect(x, y - height, av.charWidth, height);
\r
456 g.setColor(HELIX_COLOUR);
\r
457 g.fillRoundRect(lastSSX[i], y + 4 + iconOffset,
\r
458 x - lastSSX[i], 7, 8, 8);
\r
463 g.setColor(SHEET_COLOUR);
\r
464 g.fillRect(lastSSX[i], y + 4 + iconOffset,
\r
465 x - lastSSX[i] - 4, 7);
\r
466 g.fillPolygon(new int[] { x - 4, x - 4, x },
\r
469 y + iconOffset, y + 14 + iconOffset,
\r
479 g.setColor(Color.gray);
\r
480 g.fillRect(lastSSX[i], y + 6 + iconOffset, x - lastSSX[i], 2);
\r
486 if (row.isGraph && row.hasText)
\r
488 y += av.charHeight;
\r
498 // used by overview window
\r
499 public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y, int sRes, int eRes)
\r
501 g.setColor(Color.white);
\r
502 g.fillRect(0, 0, width, y);
\r
503 g.setColor(new Color(0, 0, 180));
\r
507 for (int j = sRes; j < eRes; j++)
\r
509 g.setColor(new Color(0, 0, 180));
\r
511 height = (int) ((aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT);
\r
514 g.fillRect(x, y - height, av.charWidth, height);
\r