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
23 import java.awt.event.*;
\r
25 import jalview.analysis.*;
\r
26 import jalview.datamodel.*;
\r
27 import jalview.jbappletgui.*;
\r
28 import jalview.schemes.*;
\r
30 public class AlignmentPanel
\r
31 extends GAlignmentPanel implements AdjustmentListener
\r
35 OverviewPanel overviewPanel;
\r
38 IdwidthAdjuster idwidthAdjuster;
\r
39 public AlignFrame alignFrame;
\r
40 ScalePanel scalePanel;
\r
41 AnnotationPanel annotationPanel;
\r
42 AnnotationLabels alabels;
\r
44 // this value is set false when selection area being dragged
\r
45 boolean fastPaint = true;
\r
47 public AlignmentPanel(AlignFrame af, final AlignViewport av)
\r
51 seqPanel = new SeqPanel(av, this);
\r
52 idPanel = new IdPanel(av, this);
\r
53 scalePanel = new ScalePanel(av, this);
\r
54 idwidthAdjuster = new IdwidthAdjuster(this);
\r
55 annotationPanel = new AnnotationPanel(this);
\r
56 alabels = new AnnotationLabels(this);
\r
58 idPanelHolder.add(idPanel, BorderLayout.CENTER);
\r
59 idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);
\r
60 annotationScroller.add(annotationPanel);
\r
61 annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER);
\r
62 scalePanelHolder.add(scalePanel, BorderLayout.CENTER);
\r
63 seqPanelHolder.add(seqPanel, BorderLayout.CENTER);
\r
66 setScrollValues(0, 0);
\r
68 hscroll.addAdjustmentListener(this);
\r
69 vscroll.addAdjustmentListener(this);
\r
71 seqPanel.seqCanvas.addKeyListener(new MyKeyAdapter());
\r
72 idPanel.idCanvas.addKeyListener(new MyKeyAdapter());
\r
74 addComponentListener(new ComponentAdapter()
\r
76 public void componentResized(ComponentEvent evt)
\r
78 setScrollValues(av.getStartRes(), av.getStartSeq());
\r
83 Dimension d = calculateIdWidth();
\r
84 idPanel.idCanvas.setSize(d);
\r
86 hscrollFillerPanel.setSize(d.width, annotationPanel.getSize().height);
\r
87 annotationScroller.setSize(annotationPanel.getSize());
\r
89 idPanel.idCanvas.setSize(d.width, seqPanel.seqCanvas.getSize().height);
\r
90 annotationSpaceFillerHolder.setSize(d.width,
\r
91 annotationPanel.getSize().height);
\r
92 alabels.setSize(d.width, annotationPanel.getSize().height);
\r
99 public void keyPressed(KeyEvent evt)
\r
101 // System.out.println(evt.getKeyCode()); log.
\r
102 switch (evt.getKeyCode())
\r
104 case 27: // escape key
\r
105 av.setSelectionGroup(null);
\r
106 alignFrame.alignPanel.repaint();
\r
108 case KeyEvent.VK_X:
\r
109 if (evt.isControlDown())
\r
111 alignFrame.cut_actionPerformed(null);
\r
114 case KeyEvent.VK_C:
\r
115 if (evt.isControlDown())
\r
117 alignFrame.copy_actionPerformed(null);
\r
120 case KeyEvent.VK_V:
\r
121 if (evt.isControlDown())
\r
123 alignFrame.paste(true);
\r
126 case KeyEvent.VK_A:
\r
127 if (evt.isControlDown())
\r
129 alignFrame.selectAllSequenceMenuItem_actionPerformed(null);
\r
132 case KeyEvent.VK_DOWN:
\r
133 alignFrame.moveSelectedSequences(false);
\r
135 case KeyEvent.VK_UP:
\r
136 alignFrame.moveSelectedSequences(true);
\r
138 case KeyEvent.VK_F:
\r
139 if (evt.isControlDown())
\r
141 alignFrame.findMenuItem_actionPerformed(null);
\r
144 case KeyEvent.VK_BACK_SPACE:
\r
145 case KeyEvent.VK_DELETE:
\r
146 alignFrame.cut_actionPerformed(null);
\r
153 public void fontChanged()
\r
155 // set idCanvas bufferedImage to null
\r
156 // to prevent drawing old image
\r
157 FontMetrics fm = getFontMetrics(av.getFont());
\r
159 scalePanel.setSize(new Dimension(10, av.charHeight + fm.getDescent()));
\r
160 idwidthAdjuster.setSize(new Dimension(10, av.charHeight + fm.getDescent()));
\r
162 annotationPanel.adjustPanelHeight();
\r
163 annotationPanel.repaint();
\r
164 Dimension d = calculateIdWidth();
\r
165 d.setSize(d.width + 4, seqPanel.seqCanvas.getSize().height);
\r
166 idPanel.idCanvas.setSize(d);
\r
167 hscrollFillerPanel.setSize(d);
\r
172 public void setIdWidth(int w, int h)
\r
174 idPanel.idCanvas.setSize(w, h);
\r
175 idPanelHolder.setSize(w, idPanelHolder.getSize().height);
\r
176 alabels.setSize(w, alabels.getSize().height);
\r
180 Dimension calculateIdWidth()
\r
182 Frame frame = new Frame();
\r
184 Graphics g = frame.getGraphics();
\r
187 Frame f = new Frame();
\r
189 g = f.getGraphics();
\r
192 FontMetrics fm = g.getFontMetrics(av.font);
\r
193 AlignmentI al = av.getAlignment();
\r
198 while (i < al.getHeight() && al.getSequenceAt(i) != null)
\r
200 SequenceI s = al.getSequenceAt(i);
\r
201 if (av.getShowFullId())
\r
203 id = s.getDisplayId();
\r
210 if (fm.stringWidth(id) > idWidth)
\r
212 idWidth = fm.stringWidth(id);
\r
217 // Also check annotation label widths
\r
219 if (al.getAlignmentAnnotation() != null)
\r
221 fm = g.getFontMetrics(frame.getFont());
\r
222 while (i < al.getAlignmentAnnotation().length)
\r
224 String label = al.getAlignmentAnnotation()[i].label;
\r
225 if (fm.stringWidth(label) > idWidth)
\r
227 idWidth = fm.stringWidth(label);
\r
233 return new Dimension(idWidth, idPanel.idCanvas.getSize().height);
\r
236 public void highlightSearchResults(int[] results)
\r
238 seqPanel.seqCanvas.highlightSearchResults(results);
\r
240 // do we need to scroll the panel?
\r
241 if (results != null)
\r
243 SequenceI seq = av.alignment.getSequenceAt(results[0]);
\r
244 int start = seq.findIndex(results[1]) - 1;
\r
245 int end = seq.findIndex(results[2]) - 1;
\r
246 if (av.getStartRes() > start
\r
247 || av.getEndRes() < end
\r
248 || (av.getStartSeq() > results[0]
\r
249 || av.getEndSeq() < results[0]))
\r
251 setScrollValues(start, results[0]);
\r
257 public OverviewPanel getOverviewPanel()
\r
259 return overviewPanel;
\r
262 public void setOverviewPanel(OverviewPanel op)
\r
264 overviewPanel = op;
\r
267 public void setAnnotationVisible(boolean b)
\r
269 annotationSpaceFillerHolder.setVisible(b);
\r
270 annotationScroller.setVisible(b);
\r
275 public void setWrapAlignment(boolean wrap)
\r
277 scalePanelHolder.setVisible(!wrap);
\r
278 hscroll.setVisible(!wrap);
\r
279 idwidthAdjuster.setVisible(!wrap);
\r
281 av.setShowAnnotation(!wrap);
\r
282 annotationScroller.setVisible(!wrap);
\r
283 annotationSpaceFillerHolder.setVisible(!wrap);
\r
284 idSpaceFillerPanel1.setVisible(!wrap);
\r
291 public void setColourScheme()
\r
293 ColourSchemeI cs = av.getGlobalColourScheme();
\r
295 if (av.getConservationSelected())
\r
298 Alignment al = (Alignment) av.getAlignment();
\r
299 Conservation c = new Conservation("All",
\r
300 ResidueProperties.propHash, 3,
\r
301 al.getSequences(), 0,
\r
305 c.verdict(false, av.ConsPercGaps);
\r
306 ConservationColourScheme ccs = new ConservationColourScheme(c, cs);
\r
308 av.setGlobalColourScheme(ccs);
\r
318 // return value is true if the scroll is valid
\r
319 public boolean scrollUp(boolean up)
\r
323 if (vscroll.getValue() < 1)
\r
328 vscroll.setValue(vscroll.getValue() - 1);
\r
332 if (vextent + vscroll.getValue() >= av.getAlignment().getHeight())
\r
337 vscroll.setValue(vscroll.getValue() + 1);
\r
343 public boolean scrollRight(boolean right)
\r
348 if (hscroll.getValue() < 1)
\r
353 hscroll.setValue(hscroll.getValue() - 1);
\r
357 if (hextent + hscroll.getValue() >= av.getAlignment().getWidth())
\r
362 hscroll.setValue(hscroll.getValue() + 1);
\r
368 public void setScrollValues(int x, int y)
\r
373 av.setEndRes(x + seqPanel.seqCanvas.getSize().width / av.getCharWidth() - 1);
\r
375 hextent = seqPanel.seqCanvas.getSize().width / av.charWidth;
\r
376 vextent = seqPanel.seqCanvas.getSize().height / av.charHeight;
\r
378 if (hextent > av.alignment.getWidth())
\r
380 hextent = av.alignment.getWidth();
\r
382 if (vextent > av.alignment.getHeight())
\r
384 vextent = av.alignment.getHeight();
\r
387 if (hextent + x > av.getAlignment().getWidth())
\r
389 x = av.getAlignment().getWidth() - hextent;
\r
392 if (vextent + y > av.getAlignment().getHeight())
\r
394 y = av.getAlignment().getHeight() - vextent;
\r
407 int endSeq = y + vextent;
\r
408 if (endSeq > av.alignment.getHeight())
\r
410 endSeq = av.alignment.getHeight();
\r
413 av.setEndSeq(endSeq);
\r
414 hscroll.setValues(x, hextent, 0, av.getAlignment().getWidth());
\r
415 vscroll.setValues(y, vextent, 0, av.getAlignment().getHeight());
\r
419 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
421 int oldX = av.getStartRes();
\r
422 int oldY = av.getStartSeq();
\r
424 if (evt.getSource() == hscroll)
\r
426 int x = hscroll.getValue();
\r
428 av.setEndRes(x + seqPanel.seqCanvas.getSize().width / av.getCharWidth() -
\r
432 if (evt.getSource() == vscroll)
\r
434 int offy = vscroll.getValue();
\r
435 if (av.getWrapAlignment())
\r
437 int rowSize = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.
\r
438 seqCanvas.getSize().width);
\r
439 av.setStartRes(vscroll.getValue() * rowSize);
\r
440 av.setEndRes( (vscroll.getValue() + 1) * rowSize);
\r
444 av.setStartSeq(offy);
\r
445 av.setEndSeq(offy +
\r
446 seqPanel.seqCanvas.getSize().height / av.getCharHeight());
\r
450 if (overviewPanel != null)
\r
452 overviewPanel.setBoxPosition();
\r
455 if (av.getWrapAlignment() || !fastPaint)
\r
461 idPanel.idCanvas.fastPaint(av.getStartSeq() - oldY);
\r
462 seqPanel.seqCanvas.fastPaint(av.getStartRes() - oldX,
\r
463 av.getStartSeq() - oldY);
\r
465 scalePanel.repaint();
\r
466 if (av.getShowAnnotation())
\r
468 annotationPanel.fastPaint(av.getStartRes() - oldX);
\r
474 public void update(Graphics g)
\r
479 public void paint(Graphics g)
\r
481 Dimension d = idPanel.idCanvas.getSize();
\r
482 idPanel.idCanvas.setSize(d.width, seqPanel.seqCanvas.getSize().height);
\r
483 annotationSpaceFillerHolder.setSize(d.width,
\r
484 annotationPanel.getSize().height);
\r
485 alabels.setSize(d.width, annotationPanel.getSize().height);
\r
488 idPanel.idCanvas.repaint();
\r
489 seqPanel.seqCanvas.repaint();
\r
490 scalePanel.repaint();
\r
491 annotationPanel.repaint();
\r
493 if (av.getWrapAlignment())
\r
495 int max = av.alignment.getWidth() /
\r
496 seqPanel.seqCanvas.
\r
497 getWrappedCanvasWidth(seqPanel.seqCanvas.getSize().width);
\r
498 vscroll.setMaximum(max);
\r
499 vscroll.setUnitIncrement(1);
\r
500 vscroll.setVisibleAmount(1);
\r
504 setScrollValues(av.getStartRes(), av.getStartSeq());
\r