2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.appletgui;
23 import jalview.datamodel.AlignmentI;
25 import java.awt.Color;
26 import java.awt.Dimension;
27 import java.awt.Frame;
28 import java.awt.Graphics;
29 import java.awt.Image;
30 import java.awt.Panel;
31 import java.awt.event.ComponentAdapter;
32 import java.awt.event.ComponentEvent;
33 import java.awt.event.MouseEvent;
34 import java.awt.event.MouseListener;
35 import java.awt.event.MouseMotionListener;
37 public class OverviewPanel extends Panel implements Runnable,
38 MouseMotionListener, MouseListener
52 public int width, sequencesHeight;
56 int boxX = -1, boxY = -1, boxWidth = -1, boxHeight = -1;
58 boolean resizing = false;
60 // Can set different properties in this seqCanvas than
61 // main visible SeqCanvas
68 public OverviewPanel(AlignmentPanel ap)
73 nullFrame = new Frame();
74 nullFrame.addNotify();
76 sr = new SequenceRenderer(av);
77 sr.graphics = nullFrame.getGraphics();
78 sr.renderGaps = false;
79 sr.forOverview = true;
80 fr = new FeatureRenderer(av);
82 // scale the initial size of overviewpanel to shape of alignment
83 float initialScale = (float) av.getAlignment().getWidth()
84 / (float) av.getAlignment().getHeight();
86 if (av.getSequenceConsensusHash() == null)
91 if (av.getAlignment().getWidth() > av.getAlignment().getHeight())
95 sequencesHeight = (int) (400f / initialScale);
96 if (sequencesHeight < 40)
104 width = (int) (400f * initialScale);
105 sequencesHeight = 300;
112 setSize(new Dimension(width, sequencesHeight + graphHeight));
113 addComponentListener(new ComponentAdapter()
117 public void componentResized(ComponentEvent evt)
119 if (getSize().width != width
120 || getSize().height != sequencesHeight + graphHeight)
122 updateOverviewImage();
127 addMouseMotionListener(this);
129 addMouseListener(this);
131 updateOverviewImage();
136 public void mouseEntered(MouseEvent evt)
141 public void mouseExited(MouseEvent evt)
146 public void mouseClicked(MouseEvent evt)
151 public void mouseMoved(MouseEvent evt)
156 public void mousePressed(MouseEvent evt)
164 public void mouseReleased(MouseEvent evt)
172 public void mouseDragged(MouseEvent evt)
186 if (boxY > (sequencesHeight - boxHeight))
188 boxY = sequencesHeight - boxHeight + 1;
196 if (boxX > (width - boxWidth))
198 if (av.hasHiddenColumns())
200 // Try smallest possible box
201 boxWidth = (int) ((av.endRes - av.startRes + 1) * av.getCharWidth() * scalew);
203 boxX = width - boxWidth;
206 int col = (int) (boxX / scalew / av.getCharWidth());
207 int row = (int) (boxY / scaleh / av.getCharHeight());
209 if (av.hasHiddenColumns())
211 if (!av.getColumnSelection().isVisible(col))
216 col = av.getColumnSelection().findColumnPosition(col);
219 if (av.hasHiddenRows())
221 row = av.getAlignment().getHiddenSequences()
222 .findIndexWithoutHiddenSeqs(row);
225 ap.setScrollValues(col, row);
226 ap.paintAlignment(false);
232 public void updateOverviewImage()
240 if (av.isShowSequenceFeatures())
242 fr.transferSettings(ap.seqPanel.seqCanvas.fr);
247 if ((getSize().width > 0) && (getSize().height > 0))
249 width = getSize().width;
250 sequencesHeight = getSize().height - graphHeight;
252 setSize(new Dimension(width, sequencesHeight + graphHeight));
254 Thread thread = new Thread(this);
259 // This is set true if the user resizes whilst
260 // the overview is being calculated
261 boolean resizeAgain = false;
267 int alwidth = av.getAlignment().getWidth();
268 int alheight = av.getAlignment().getHeight();
270 if (av.isShowSequenceFeatures())
272 fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer());
275 if (getSize().width > 0 && getSize().height > 0)
277 width = getSize().width;
278 sequencesHeight = getSize().height - graphHeight;
281 setSize(new Dimension(width, sequencesHeight + graphHeight));
283 int fullsizeWidth = alwidth * av.getCharWidth();
284 int fullsizeHeight = alheight * av.getCharHeight();
286 scalew = (float) width / (float) fullsizeWidth;
287 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
289 miniMe = nullFrame.createImage(width, sequencesHeight + graphHeight);
290 offscreen = nullFrame.createImage(width, sequencesHeight + graphHeight);
292 Graphics mg = miniMe.getGraphics();
293 float sampleCol = (float) alwidth / (float) width;
294 float sampleRow = (float) alheight / (float) sequencesHeight;
296 int lastcol = 0, lastrow = 0;
297 int xstart = 0, ystart = 0;
298 Color color = Color.yellow;
299 int row, col, sameRow = 0, sameCol = 0;
300 jalview.datamodel.SequenceI seq;
301 final boolean hasHiddenRows = av.hasHiddenRows(), hasHiddenCols = av
303 boolean hiddenRow = false;
304 AlignmentI alignment = av.getAlignment();
305 for (row = 0; row <= sequencesHeight; row++)
311 if ((int) (row * sampleRow) == lastrow)
320 seq = alignment.getHiddenSequences().getHiddenSequence(lastrow);
323 int index = alignment.getHiddenSequences()
324 .findIndexWithoutHiddenSeqs(lastrow);
326 seq = alignment.getSequenceAt(index);
335 seq = alignment.getSequenceAt(lastrow);
338 for (col = 0; col < width; col++)
340 if ((int) (col * sampleCol) == lastcol
341 && (int) (row * sampleRow) == lastrow)
347 lastcol = (int) (col * sampleCol);
349 if (seq.getLength() > lastcol)
351 color = sr.getResidueBoxColour(seq, lastcol);
353 if (av.isShowSequenceFeatures())
355 color = fr.findFeatureColour(color, seq, lastcol);
360 color = Color.white; // White
364 || (hasHiddenCols && !av.getColumnSelection().isVisible(
367 color = color.darker().darker();
371 if (sameCol == 1 && sameRow == 1)
373 mg.drawLine(xstart, ystart, xstart, ystart);
377 mg.fillRect(xstart, ystart, sameCol, sameRow);
383 lastrow = (int) (row * sampleRow);
388 if (av.getAlignmentConservationAnnotation() != null)
390 for (col = 0; col < width; col++)
396 lastcol = (int) (col * sampleCol);
398 mg.translate(col, sequencesHeight);
399 ap.annotationPanel.renderer.drawGraph(mg,
400 av.getAlignmentConservationAnnotation(),
401 av.getAlignmentConservationAnnotation().annotations,
402 (int) (sampleCol) + 1, graphHeight,
403 (int) (col * sampleCol), (int) (col * sampleCol) + 1);
404 mg.translate(-col, -sequencesHeight);
417 updateOverviewImage();
421 public void setBoxPosition()
423 int fullsizeWidth = av.getAlignment().getWidth() * av.getCharWidth();
424 int fullsizeHeight = (av.getAlignment().getHeight() + av.getAlignment()
425 .getHiddenSequences().getSize())
426 * av.getCharHeight();
428 int startRes = av.getStartRes();
429 int endRes = av.getEndRes();
431 if (av.hasHiddenColumns())
433 startRes = av.getColumnSelection().adjustForHiddenColumns(startRes);
434 endRes = av.getColumnSelection().adjustForHiddenColumns(endRes);
437 int startSeq = av.startSeq;
438 int endSeq = av.endSeq;
440 if (av.hasHiddenRows())
442 startSeq = av.getAlignment().getHiddenSequences()
443 .adjustForHiddenSeqs(startSeq);
445 endSeq = av.getAlignment().getHiddenSequences()
446 .adjustForHiddenSeqs(endSeq);
450 scalew = (float) width / (float) fullsizeWidth;
451 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
453 boxX = (int) (startRes * av.getCharWidth() * scalew);
454 boxY = (int) (startSeq * av.getCharHeight() * scaleh);
456 if (av.hasHiddenColumns())
458 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
462 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
465 boxHeight = (int) ((endSeq - startSeq) * av.getCharHeight() * scaleh);
471 public void update(Graphics g)
477 public void paint(Graphics g)
479 Graphics og = offscreen.getGraphics();
482 og.drawImage(miniMe, 0, 0, this);
483 og.setColor(Color.red);
484 og.drawRect(boxX, boxY, boxWidth, boxHeight);
485 og.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
486 g.drawImage(offscreen, 0, 0, this);