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
136 for (int j = 0; j < aa.length; j++)
\r
138 if (aa[j].editable)
\r
146 if (activeRes == null)
\r
148 activeRes = new Vector();
\r
149 activeRes.addElement(String.valueOf(i));
\r
153 activeRes.addElement(String.valueOf(i));
\r
156 public void doMouseMoved(MouseEvent evt)
\r
158 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
166 for (int i = 0; i < aa.length; i++)
\r
171 height += aa[i].height;
\r
174 if (evt.getY() < height)
\r
181 int res = evt.getX() / av.getCharWidth() + av.getStartRes();
\r
182 if (row > -1 && res < aa[row].annotations.length && aa[row].annotations[res] != null)
\r
184 StringBuffer text = new StringBuffer("Sequence position " + (res + 1) +
\r
186 aa[row].annotations[res].description);
\r
187 ap.alignFrame.statusBar.setText(text.toString());
\r
191 public void update(Graphics g)
\r
196 public void paint(Graphics g)
\r
198 g.setColor(Color.white);
\r
199 g.fillRect(0,0, getSize().width, getSize().height);
\r
200 imgWidth = (av.endRes - av.startRes + 1) * av.charWidth;
\r
202 if (image == null || imgWidth != image.getWidth(this))
\r
204 image = createImage(imgWidth, ap.annotationPanel.getSize().height);
\r
205 gg = image.getGraphics();
\r
206 gg.setFont(av.getFont());
\r
207 fm = gg.getFontMetrics();
\r
213 g.drawImage(image, 0, 0, this);
\r
218 drawComponent(gg, av.startRes, av.endRes + 1);
\r
219 g.drawImage(image, 0, 0, this);
\r
223 public void fastPaint(int horizontal)
\r
225 if (horizontal == 0
\r
226 || av.alignment.getAlignmentAnnotation() == null
\r
227 || av.alignment.getAlignmentAnnotation().length < 1
\r
234 gg.copyArea(0, 0, imgWidth, getSize().height, -horizontal * av.charWidth, 0);
\r
235 int sr = av.startRes, er = av.endRes + 1, transX = 0;
\r
237 if (horizontal > 0) // scrollbar pulled right, image to the left
\r
239 transX = (er - sr - horizontal) * av.charWidth;
\r
240 sr = er - horizontal;
\r
242 else if (horizontal < 0)
\r
244 er = sr - horizontal;
\r
247 gg.translate(transX, 0);
\r
249 drawComponent(gg, sr, er);
\r
251 gg.translate( -transX, 0);
\r
257 public void drawComponent(Graphics g, int startRes, int endRes)
\r
259 g.setColor(Color.white);
\r
260 g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getSize().height);
\r
261 if (av.alignment.getAlignmentAnnotation() == null ||
\r
262 av.alignment.getAlignmentAnnotation().length < 1)
\r
264 g.setColor(Color.white);
\r
265 g.fillRect(0, 0, getSize().width, getSize().height);
\r
266 g.setColor(Color.black);
\r
267 g.drawString("Alignment has no annotations", 20, 15);
\r
271 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
273 int j, x = 0, y = 0;
\r
274 char[] lastSS = new char[aa.length];
\r
275 int[] lastSSX = new int[aa.length];
\r
276 int iconOffset = av.charHeight / 2;
\r
277 boolean validRes = false;
\r
280 for (int i = 0; i < aa.length; i++)
\r
282 AlignmentAnnotation row = aa[i];
\r
290 // this is so that we draw the characters below the graph
\r
294 y -= av.charHeight;
\r
299 iconOffset = av.charHeight / 2;
\r
306 for (j = startRes; j < endRes; j++)
\r
308 if (row.annotations.length <= j || row.annotations[j] == null)
\r
317 x = (j - startRes) * av.charWidth;
\r
319 if (activeRow == i)
\r
322 g.setColor(Color.red);
\r
324 if (activeRes != null)
\r
326 for (int n = 0; n < activeRes.size(); n++)
\r
328 int v = Integer.parseInt(activeRes.elementAt(n).toString());
\r
331 g.fillRect( (j - startRes) * av.charWidth, y, av.charWidth,
\r
338 if (validRes && row.annotations[j].displayCharacter.length() > 0)
\r
340 int charOffset = (av.charWidth -
\r
341 fm.charWidth(row.annotations[j].displayCharacter.
\r
343 g.setColor(row.annotations[j].colour);
\r
344 if (j == 0 || row.isGraph)
\r
346 if (row.annotations[0].secondaryStructure == 'H'
\r
347 || row.annotations[0].secondaryStructure == 'E')
\r
349 g.drawString(row.annotations[j].displayCharacter, x,
\r
350 y + iconOffset + 3);
\r
353 else if ( (row.annotations[j].secondaryStructure == 'H'
\r
354 || row.annotations[j].secondaryStructure == 'E') &&
\r
355 (row.annotations[j - 1] == null ||
\r
356 row.annotations[j].secondaryStructure !=
\r
357 row.annotations[j - 1].secondaryStructure))
\r
360 g.drawString(row.annotations[j].displayCharacter, x + charOffset,
\r
361 y + iconOffset + 3);
\r
366 g.drawString(row.annotations[j].displayCharacter, x + charOffset,
\r
367 y + iconOffset + 3);
\r
373 if (!validRes || row.annotations[j].secondaryStructure != lastSS[i])
\r
378 g.setColor(HELIX_COLOUR);
\r
379 g.fillRoundRect(lastSSX[i], y + 4 + iconOffset, x - lastSSX[i],
\r
383 g.setColor(SHEET_COLOUR);
\r
384 g.fillRect(lastSSX[i], y + 4 + iconOffset, x - lastSSX[i] - 4,
\r
386 g.fillPolygon(new int[]
\r
389 {y + iconOffset, y + 14 + iconOffset,
\r
390 y + 8 + iconOffset}, 3);
\r
395 g.setColor(Color.gray);
\r
396 g.fillRect(lastSSX[i], y + 6 + iconOffset, x - lastSSX[i], 2);
\r
402 lastSS[i] = row.annotations[j].secondaryStructure;
\r
412 if (validRes && row.isGraph)
\r
414 g.setColor(new Color(0, 0, 180));
\r
415 int height = (int) ( (row.annotations[j].value / row.graphMax) *
\r
418 if (row.windowLength > 1)
\r
421 for (int i2 = j - (row.windowLength / 2);
\r
422 i2 < j + (row.windowLength / 2); i2++)
\r
424 if (i2 < 0 || i2 >= av.alignment.getWidth())
\r
429 total += row.annotations[i2].value;
\r
432 total /= row.windowLength;
\r
433 height = (int) ( (total / row.graphMax) * GRAPH_HEIGHT);
\r
436 g.setColor(row.annotations[j].colour);
\r
437 g.fillRect(x, y - height, av.charWidth, height);
\r
449 g.setColor(HELIX_COLOUR);
\r
450 g.fillRoundRect(lastSSX[i], y + 4 + iconOffset, x - lastSSX[i], 7,
\r
454 g.setColor(SHEET_COLOUR);
\r
455 g.fillRect(lastSSX[i], y + 4 + iconOffset, x - lastSSX[i] - 4, 7);
\r
456 g.fillPolygon(new int[]
\r
459 {y + iconOffset, y + 14 + iconOffset,
\r
460 y + 7 + iconOffset}
\r
466 g.setColor(Color.gray);
\r
467 g.fillRect(lastSSX[i], y + 6 + iconOffset, x - lastSSX[i], 2);
\r
473 if (row.isGraph && row.hasText)
\r
475 y += av.charHeight;
\r
484 // used by overview window
\r
485 public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y, int sRes, int eRes)
\r
487 g.setColor(Color.white);
\r
488 g.fillRect(0, 0, width, y);
\r
489 g.setColor(new Color(0, 0, 180));
\r
493 for (int j = sRes; j < eRes; j++)
\r
495 g.setColor(new Color(0, 0, 180));
\r
497 height = (int) ((aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT);
\r
500 g.fillRect(x, y - height, av.charWidth, height);
\r