2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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;
26 import java.awt.event.*;
28 public class OverviewPanel extends Panel implements Runnable,
29 MouseMotionListener, MouseListener
43 public int width, sequencesHeight;
47 int boxX = -1, boxY = -1, boxWidth = -1, boxHeight = -1;
49 boolean resizing = false;
51 // Can set different properties in this seqCanvas than
52 // main visible SeqCanvas
59 public OverviewPanel(AlignmentPanel ap)
64 nullFrame = new Frame();
65 nullFrame.addNotify();
67 sr = new SequenceRenderer(av);
68 sr.graphics = nullFrame.getGraphics();
69 sr.renderGaps = false;
70 sr.forOverview = true;
71 fr = new FeatureRenderer(av);
74 // scale the initial size of overviewpanel to shape of alignment
75 float initialScale = (float) av.getAlignment().getWidth()
76 / (float) av.getAlignment().getHeight();
78 if (av.getSequenceConsensusHash() == null)
83 if (av.getAlignment().getWidth() > av.getAlignment().getHeight())
87 sequencesHeight = (int) (400f / initialScale);
88 if (sequencesHeight < 40)
96 width = (int) (400f * initialScale);
97 sequencesHeight = 300;
104 setSize(new Dimension(width, sequencesHeight + graphHeight));
105 addComponentListener(new ComponentAdapter()
109 public void componentResized(ComponentEvent evt)
111 if (getSize().width != width
112 || getSize().height != sequencesHeight + graphHeight)
114 updateOverviewImage();
119 addMouseMotionListener(this);
121 addMouseListener(this);
123 updateOverviewImage();
128 public void mouseEntered(MouseEvent evt)
133 public void mouseExited(MouseEvent evt)
138 public void mouseClicked(MouseEvent evt)
143 public void mouseMoved(MouseEvent evt)
148 public void mousePressed(MouseEvent evt)
156 public void mouseReleased(MouseEvent evt)
164 public void mouseDragged(MouseEvent evt)
178 if (boxY > (sequencesHeight - boxHeight))
180 boxY = sequencesHeight - boxHeight + 1;
188 if (boxX > (width - boxWidth))
190 if (av.hasHiddenColumns())
192 // Try smallest possible box
193 boxWidth = (int) ((av.endRes - av.startRes + 1) * av.getCharWidth() * scalew);
195 boxX = width - boxWidth;
198 int col = (int) (boxX / scalew / av.getCharWidth());
199 int row = (int) (boxY / scaleh / av.getCharHeight());
201 if (av.hasHiddenColumns())
203 if (!av.getColumnSelection().isVisible(col))
208 col = av.getColumnSelection().findColumnPosition(col);
211 if (av.hasHiddenRows())
213 row = av.getAlignment().getHiddenSequences()
214 .findIndexWithoutHiddenSeqs(row);
217 ap.setScrollValues(col, row);
218 ap.paintAlignment(false);
224 public void updateOverviewImage()
232 if (av.showSequenceFeatures)
234 fr.featureGroups = ap.seqPanel.seqCanvas.getFeatureRenderer().featureGroups;
235 fr.featureColours = ap.seqPanel.seqCanvas.getFeatureRenderer().featureColours;
240 if ((getSize().width > 0) && (getSize().height > 0))
242 width = getSize().width;
243 sequencesHeight = getSize().height - graphHeight;
245 setSize(new Dimension(width, sequencesHeight + graphHeight));
247 Thread thread = new Thread(this);
252 // This is set true if the user resizes whilst
253 // the overview is being calculated
254 boolean resizeAgain = false;
260 int alwidth = av.getAlignment().getWidth();
261 int alheight = av.getAlignment().getHeight();
263 if (av.showSequenceFeatures)
265 fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer());
268 if (getSize().width > 0 && getSize().height > 0)
270 width = getSize().width;
271 sequencesHeight = getSize().height - graphHeight;
274 setSize(new Dimension(width, sequencesHeight + graphHeight));
276 int fullsizeWidth = alwidth * av.getCharWidth();
277 int fullsizeHeight = alheight * av.getCharHeight();
279 scalew = (float) width / (float) fullsizeWidth;
280 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
282 miniMe = nullFrame.createImage(width, sequencesHeight + graphHeight);
283 offscreen = nullFrame.createImage(width, sequencesHeight + graphHeight);
285 Graphics mg = miniMe.getGraphics();
286 float sampleCol = (float) alwidth / (float) width;
287 float sampleRow = (float) alheight / (float) sequencesHeight;
289 int lastcol = 0, lastrow = 0;
290 int xstart = 0, ystart = 0;
291 Color color = Color.yellow;
292 int row, col, sameRow = 0, sameCol = 0;
293 jalview.datamodel.SequenceI seq;
294 boolean hiddenRow = false;
295 AlignmentI alignment = av.getAlignment();
296 for (row = 0; row <= sequencesHeight; row++)
298 if ((int) (row * sampleRow) == lastrow)
305 if (av.hasHiddenRows())
307 seq = alignment.getHiddenSequences().getHiddenSequence(lastrow);
310 int index = alignment.getHiddenSequences()
311 .findIndexWithoutHiddenSeqs(lastrow);
313 seq = alignment.getSequenceAt(index);
322 seq = alignment.getSequenceAt(lastrow);
325 for (col = 0; col < width; col++)
327 if ((int) (col * sampleCol) == lastcol
328 && (int) (row * sampleRow) == lastrow)
334 lastcol = (int) (col * sampleCol);
336 if (seq.getLength() > lastcol)
338 color = sr.getResidueBoxColour(seq, lastcol);
340 if (av.showSequenceFeatures)
342 color = fr.findFeatureColour(color, seq, lastcol);
347 color = Color.white; // White
351 || (av.hasHiddenColumns() && !av.getColumnSelection()
352 .isVisible(lastcol)))
354 color = color.darker().darker();
358 if (sameCol == 1 && sameRow == 1)
360 mg.drawLine(xstart, ystart, xstart, ystart);
364 mg.fillRect(xstart, ystart, sameCol, sameRow);
370 lastrow = (int) (row * sampleRow);
375 if (av.getAlignmentConservationAnnotation() != null)
377 for (col = 0; col < width; col++)
379 lastcol = (int) (col * sampleCol);
381 mg.translate(col, sequencesHeight);
382 ap.annotationPanel.renderer.drawGraph(mg,
383 av.getAlignmentConservationAnnotation(),
384 av.getAlignmentConservationAnnotation().annotations,
385 (int) (sampleCol) + 1, graphHeight,
386 (int) (col * sampleCol), (int) (col * sampleCol) + 1);
387 mg.translate(-col, -sequencesHeight);
400 updateOverviewImage();
404 public void setBoxPosition()
406 int fullsizeWidth = av.getAlignment().getWidth() * av.getCharWidth();
407 int fullsizeHeight = (av.getAlignment().getHeight() + av.getAlignment()
408 .getHiddenSequences().getSize())
409 * av.getCharHeight();
411 int startRes = av.getStartRes();
412 int endRes = av.getEndRes();
414 if (av.hasHiddenColumns())
416 startRes = av.getColumnSelection().adjustForHiddenColumns(startRes);
417 endRes = av.getColumnSelection().adjustForHiddenColumns(endRes);
420 int startSeq = av.startSeq;
421 int endSeq = av.endSeq;
423 if (av.hasHiddenRows())
425 startSeq = av.getAlignment().getHiddenSequences()
426 .adjustForHiddenSeqs(startSeq);
428 endSeq = av.getAlignment().getHiddenSequences()
429 .adjustForHiddenSeqs(endSeq);
433 scalew = (float) width / (float) fullsizeWidth;
434 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
436 boxX = (int) (startRes * av.getCharWidth() * scalew);
437 boxY = (int) (startSeq * av.getCharHeight() * scaleh);
439 if (av.hasHiddenColumns())
441 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
445 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
448 boxHeight = (int) ((endSeq - startSeq) * av.getCharHeight() * scaleh);
454 public void update(Graphics g)
460 public void paint(Graphics g)
462 Graphics og = offscreen.getGraphics();
465 og.drawImage(miniMe, 0, 0, this);
466 og.setColor(Color.red);
467 og.drawRect(boxX, boxY, boxWidth, boxHeight);
468 og.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
469 g.drawImage(offscreen, 0, 0, this);