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
72 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
74 ap.alabels.setScrollOffset( -evt.getValue());
\r
77 public void adjustPanelHeight()
\r
79 // setHeight of panels
\r
80 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
84 for (int i = 0; i < aa.length; i++)
\r
95 aa[i].height += av.charHeight;
\r
104 aa[i].height += GRAPH_HEIGHT;
\r
107 if (aa[i].height == 0)
\r
111 height += aa[i].height;
\r
119 this.setSize(getSize().width, height);
\r
120 ap.annotationScroller.setSize(getSize().width, height);
\r
122 // ap.annotationSpaceFillerHolder.setSize(d.width,annotationPanel.getSize().height);
\r
128 public void addEditableColumn(int i)
\r
130 if (activeRow == -1)
\r
132 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
133 for (int j = 0; j < aa.length; j++)
\r
135 if (aa[j].editable)
\r
143 if (activeRes == null)
\r
145 activeRes = new Vector();
\r
146 activeRes.addElement(String.valueOf(i));
\r
150 activeRes.addElement(String.valueOf(i));
\r
153 public void doMouseMoved(MouseEvent evt)
\r
155 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
163 for (int i = 0; i < aa.length; i++)
\r
168 height += aa[i].height;
\r
171 if (evt.getY() < height)
\r
178 int res = evt.getX() / av.getCharWidth() + av.getStartRes();
\r
179 if (row > -1 && res < aa[row].annotations.length && aa[row].annotations[res] != null)
\r
181 StringBuffer text = new StringBuffer("Sequence position " + (res + 1) +
\r
183 aa[row].annotations[res].description);
\r
184 ap.alignFrame.statusBar.setText(text.toString());
\r
188 public void update(Graphics g)
\r
193 public void paint(Graphics g)
\r
195 g.setColor(Color.white);
\r
196 g.fillRect(0,0, getSize().width, getSize().height);
\r
197 imgWidth = (av.endRes - av.startRes + 1) * av.charWidth;
\r
199 if (image == null || imgWidth != image.getWidth(this))
\r
201 image = createImage(imgWidth, ap.annotationPanel.getSize().height);
\r
202 gg = image.getGraphics();
\r
203 gg.setFont(av.getFont());
\r
204 fm = gg.getFontMetrics();
\r
210 g.drawImage(image, 0, 0, this);
\r
215 drawComponent(gg, av.startRes, av.endRes + 1);
\r
216 g.drawImage(image, 0, 0, this);
\r
220 public void fastPaint(int horizontal)
\r
222 if (horizontal == 0
\r
223 || av.alignment.getAlignmentAnnotation() == null
\r
224 || av.alignment.getAlignmentAnnotation().length < 1
\r
231 gg.copyArea(0, 0, imgWidth, getSize().height, -horizontal * av.charWidth, 0);
\r
232 int sr = av.startRes, er = av.endRes + 1, transX = 0;
\r
234 if (horizontal > 0) // scrollbar pulled right, image to the left
\r
236 transX = (er - sr - horizontal) * av.charWidth;
\r
237 sr = er - horizontal;
\r
239 else if (horizontal < 0)
\r
241 er = sr - horizontal;
\r
244 gg.translate(transX, 0);
\r
246 drawComponent(gg, sr, er);
\r
248 gg.translate( -transX, 0);
\r
254 public void drawComponent(Graphics g, int startRes, int endRes)
\r
256 g.setColor(Color.white);
\r
257 g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getSize().height);
\r
258 if (av.alignment.getAlignmentAnnotation() == null ||
\r
259 av.alignment.getAlignmentAnnotation().length < 1)
\r
261 g.setColor(Color.white);
\r
262 g.fillRect(0, 0, getSize().width, getSize().height);
\r
263 g.setColor(Color.black);
\r
264 g.drawString("Alignment has no annotations", 20, 15);
\r
268 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
270 int j, x = 0, y = 0;
\r
271 char[] lastSS = new char[aa.length];
\r
272 int[] lastSSX = new int[aa.length];
\r
273 int iconOffset = av.charHeight / 2;
\r
274 boolean validRes = false;
\r
277 for (int i = 0; i < aa.length; i++)
\r
279 AlignmentAnnotation row = aa[i];
\r
287 // this is so that we draw the characters below the graph
\r
291 y -= av.charHeight;
\r
296 iconOffset = av.charHeight / 2;
\r
303 for (j = startRes; j < endRes; j++)
\r
305 if (row.annotations.length <= j || row.annotations[j] == null)
\r
314 x = (j - startRes) * av.charWidth;
\r
316 if (activeRow == i)
\r
319 g.setColor(Color.red);
\r
321 if (activeRes != null)
\r
323 for (int n = 0; n < activeRes.size(); n++)
\r
325 int v = Integer.parseInt(activeRes.elementAt(n).toString());
\r
328 g.fillRect( (j - startRes) * av.charWidth, y, av.charWidth,
\r
335 if (validRes && row.annotations[j].displayCharacter.length() > 0)
\r
337 int charOffset = (av.charWidth -
\r
338 fm.charWidth(row.annotations[j].displayCharacter.
\r
340 g.setColor(row.annotations[j].colour);
\r
341 if (j == 0 || row.isGraph)
\r
343 if (row.annotations[0].secondaryStructure == 'H'
\r
344 || row.annotations[0].secondaryStructure == 'E')
\r
346 g.drawString(row.annotations[j].displayCharacter, x,
\r
347 y + iconOffset + 3);
\r
350 else if ( (row.annotations[j].secondaryStructure == 'H'
\r
351 || row.annotations[j].secondaryStructure == 'E') &&
\r
352 (row.annotations[j - 1] == null ||
\r
353 row.annotations[j].secondaryStructure !=
\r
354 row.annotations[j - 1].secondaryStructure))
\r
357 g.drawString(row.annotations[j].displayCharacter, x + charOffset,
\r
358 y + iconOffset + 3);
\r
363 g.drawString(row.annotations[j].displayCharacter, x + charOffset,
\r
364 y + iconOffset + 3);
\r
370 if (!validRes || row.annotations[j].secondaryStructure != lastSS[i])
\r
375 g.setColor(HELIX_COLOUR);
\r
376 g.fillRoundRect(lastSSX[i], y + 4 + iconOffset, x - lastSSX[i],
\r
380 g.setColor(SHEET_COLOUR);
\r
381 g.fillRect(lastSSX[i], y + 4 + iconOffset, x - lastSSX[i] - 4,
\r
383 g.fillPolygon(new int[]
\r
386 {y + iconOffset, y + 14 + iconOffset,
\r
387 y + 8 + iconOffset}, 3);
\r
392 g.setColor(Color.gray);
\r
393 g.fillRect(lastSSX[i], y + 6 + iconOffset, x - lastSSX[i], 2);
\r
399 lastSS[i] = row.annotations[j].secondaryStructure;
\r
409 if (validRes && row.isGraph)
\r
411 g.setColor(new Color(0, 0, 180));
\r
412 int height = (int) ( (row.annotations[j].value / row.graphMax) *
\r
415 if (row.windowLength > 1)
\r
418 for (int i2 = j - (row.windowLength / 2);
\r
419 i2 < j + (row.windowLength / 2); i2++)
\r
421 if (i2 < 0 || i2 >= av.alignment.getWidth())
\r
426 total += row.annotations[i2].value;
\r
429 total /= row.windowLength;
\r
430 height = (int) ( (total / row.graphMax) * GRAPH_HEIGHT);
\r
433 g.setColor(row.annotations[j].colour);
\r
434 g.fillRect(x, y - height, av.charWidth, height);
\r
446 g.setColor(HELIX_COLOUR);
\r
447 g.fillRoundRect(lastSSX[i], y + 4 + iconOffset, x - lastSSX[i], 7,
\r
451 g.setColor(SHEET_COLOUR);
\r
452 g.fillRect(lastSSX[i], y + 4 + iconOffset, x - lastSSX[i] - 4, 7);
\r
453 g.fillPolygon(new int[]
\r
456 {y + iconOffset, y + 14 + iconOffset,
\r
457 y + 7 + iconOffset}
\r
463 g.setColor(Color.gray);
\r
464 g.fillRect(lastSSX[i], y + 6 + iconOffset, x - lastSSX[i], 2);
\r
470 if (row.isGraph && row.hasText)
\r
472 y += av.charHeight;
\r
481 // used by overview window
\r
482 public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y)
\r
484 g.setColor(Color.white);
\r
485 g.fillRect(0, 0, width, y);
\r
486 g.setColor(new Color(0, 0, 180));
\r
488 for (int j = 0; j < aa.annotations.length; j++)
\r
490 g.setColor(new Color(0, 0, 180));
\r
491 int height = (int) ( (aa.annotations[j].value / aa.graphMax) *
\r
493 g.fillRect(x, y - height, av.charWidth, height);
\r