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 imgWidth = (av.endRes - av.startRes + 1) * av.charWidth;
\r
197 if (image == null || imgWidth != image.getWidth(this))
\r
199 image = createImage(imgWidth, ap.annotationPanel.getSize().height);
\r
200 gg = image.getGraphics();
\r
201 gg.setFont(av.getFont());
\r
202 fm = gg.getFontMetrics();
\r
208 g.drawImage(image, 0, 0, this);
\r
213 drawComponent(gg, av.startRes, av.endRes + 1);
\r
214 g.drawImage(image, 0, 0, this);
\r
218 public void fastPaint(int horizontal)
\r
220 if (horizontal == 0
\r
221 || av.alignment.getAlignmentAnnotation() == null
\r
222 || av.alignment.getAlignmentAnnotation().length < 1
\r
229 gg.copyArea(0, 0, imgWidth, getSize().height, -horizontal * av.charWidth, 0);
\r
230 int sr = av.startRes, er = av.endRes + 1, transX = 0;
\r
232 if (horizontal > 0) // scrollbar pulled right, image to the left
\r
234 transX = (er - sr - horizontal) * av.charWidth;
\r
235 sr = er - horizontal;
\r
237 else if (horizontal < 0)
\r
239 er = sr - horizontal;
\r
242 gg.translate(transX, 0);
\r
244 drawComponent(gg, sr, er);
\r
246 gg.translate( -transX, 0);
\r
252 public void drawComponent(Graphics g, int startRes, int endRes)
\r
254 g.setColor(Color.white);
\r
255 g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getSize().height);
\r
256 if (av.alignment.getAlignmentAnnotation() == null ||
\r
257 av.alignment.getAlignmentAnnotation().length < 1)
\r
259 g.setColor(Color.white);
\r
260 g.fillRect(0, 0, getSize().width, getSize().height);
\r
261 g.setColor(Color.black);
\r
262 g.drawString("Alignment has no annotations", 20, 15);
\r
266 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
268 int j, x = 0, y = 0;
\r
269 char[] lastSS = new char[aa.length];
\r
270 int[] lastSSX = new int[aa.length];
\r
271 int iconOffset = av.charHeight / 2;
\r
272 boolean validRes = false;
\r
275 for (int i = 0; i < aa.length; i++)
\r
277 AlignmentAnnotation row = aa[i];
\r
285 // this is so that we draw the characters below the graph
\r
289 y -= av.charHeight;
\r
294 iconOffset = av.charHeight / 2;
\r
301 for (j = startRes; j < endRes; j++)
\r
303 if (row.annotations.length <= j || row.annotations[j] == null)
\r
312 x = (j - startRes) * av.charWidth;
\r
314 if (activeRow == i)
\r
317 g.setColor(Color.red);
\r
319 if (activeRes != null)
\r
321 for (int n = 0; n < activeRes.size(); n++)
\r
323 int v = Integer.parseInt(activeRes.elementAt(n).toString());
\r
326 g.fillRect( (j - startRes) * av.charWidth, y, av.charWidth,
\r
333 if (validRes && row.annotations[j].displayCharacter.length() > 0)
\r
335 int charOffset = (av.charWidth -
\r
336 fm.charWidth(row.annotations[j].displayCharacter.
\r
338 g.setColor(row.annotations[j].colour);
\r
339 if (j == 0 || row.isGraph)
\r
341 if (row.annotations[0].secondaryStructure == 'H'
\r
342 || row.annotations[0].secondaryStructure == 'E')
\r
344 g.drawString(row.annotations[j].displayCharacter, x,
\r
345 y + iconOffset + 2);
\r
348 else if ( (row.annotations[j].secondaryStructure == 'H'
\r
349 || row.annotations[j].secondaryStructure == 'E') &&
\r
350 (row.annotations[j - 1] == null ||
\r
351 row.annotations[j].secondaryStructure !=
\r
352 row.annotations[j - 1].secondaryStructure))
\r
355 g.drawString(row.annotations[j].displayCharacter, x + charOffset,
\r
356 y + iconOffset + 2);
\r
361 g.drawString(row.annotations[j].displayCharacter, x + charOffset,
\r
362 y + iconOffset + 2);
\r
368 if (!validRes || row.annotations[j].secondaryStructure != lastSS[i])
\r
373 g.setColor(HELIX_COLOUR);
\r
374 g.fillRoundRect(lastSSX[i], y + 4 + iconOffset, x - lastSSX[i],
\r
378 g.setColor(SHEET_COLOUR);
\r
379 g.fillRect(lastSSX[i], y + 4 + iconOffset, x - lastSSX[i] - 4,
\r
381 g.fillPolygon(new int[]
\r
384 {y + iconOffset, y + 14 + iconOffset,
\r
385 y + 8 + iconOffset}, 3);
\r
390 g.setColor(Color.gray);
\r
391 g.fillRect(lastSSX[i], y + 6 + iconOffset, x - lastSSX[i], 2);
\r
397 lastSS[i] = row.annotations[j].secondaryStructure;
\r
407 if (validRes && row.isGraph)
\r
409 g.setColor(new Color(0, 0, 180));
\r
410 int height = (int) ( (row.annotations[j].value / row.graphMax) *
\r
413 if (row.windowLength > 1)
\r
416 for (int i2 = j - (row.windowLength / 2);
\r
417 i2 < j + (row.windowLength / 2); i2++)
\r
419 if (i2 < 0 || i2 >= av.alignment.getWidth())
\r
424 total += row.annotations[i2].value;
\r
427 total /= row.windowLength;
\r
428 height = (int) ( (total / row.graphMax) * GRAPH_HEIGHT);
\r
431 g.setColor(row.annotations[j].colour);
\r
432 g.fillRect(x, y - height, av.charWidth, height);
\r
444 g.setColor(HELIX_COLOUR);
\r
445 g.fillRoundRect(lastSSX[i], y + 4 + iconOffset, x - lastSSX[i], 7,
\r
449 g.setColor(SHEET_COLOUR);
\r
450 g.fillRect(lastSSX[i], y + 4 + iconOffset, x - lastSSX[i] - 4, 7);
\r
451 g.fillPolygon(new int[]
\r
454 {y + iconOffset, y + 14 + iconOffset,
\r
455 y + 7 + iconOffset}
\r
461 g.setColor(Color.gray);
\r
462 g.fillRect(lastSSX[i], y + 6 + iconOffset, x - lastSSX[i], 2);
\r
468 if (row.isGraph && row.hasText)
\r
470 y += av.charHeight;
\r
479 // used by overview window
\r
480 public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y)
\r
482 g.setColor(Color.white);
\r
483 g.fillRect(0, 0, width, y);
\r
484 g.setColor(new Color(0, 0, 180));
\r
486 for (int j = 0; j < aa.annotations.length; j++)
\r
488 g.setColor(new Color(0, 0, 180));
\r
489 int height = (int) ( (aa.annotations[j].value / aa.graphMax) *
\r
491 g.fillRect(x, y - height, av.charWidth, height);
\r