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.
23 import jalview.renderer.AnnotationRenderer;
25 import java.awt.Color;
26 import java.awt.Dimension;
27 import java.awt.Graphics;
28 import java.awt.event.ComponentAdapter;
29 import java.awt.event.ComponentEvent;
30 import java.awt.event.MouseAdapter;
31 import java.awt.event.MouseEvent;
32 import java.awt.event.MouseMotionAdapter;
33 import java.awt.image.BufferedImage;
35 import javax.swing.JPanel;
43 public class OverviewPanel extends JPanel implements Runnable
51 final AnnotationRenderer renderer = new AnnotationRenderer();
71 boolean resizing = false;
73 // Can set different properties in this seqCanvas than
74 // main visible SeqCanvas
77 jalview.renderer.seqfeatures.FeatureRenderer fr;
80 * Creates a new OverviewPanel object.
85 public OverviewPanel(AlignmentPanel ap)
91 sr = new SequenceRenderer(av);
92 sr.renderGaps = false;
93 sr.forOverview = true;
94 fr = new FeatureRenderer(ap);
96 // scale the initial size of overviewpanel to shape of alignment
97 float initialScale = (float) av.getAlignment().getWidth()
98 / (float) av.getAlignment().getHeight();
100 if (av.getAlignmentConservationAnnotation() == null)
105 if (av.getAlignment().getWidth() > av.getAlignment().getHeight())
109 sequencesHeight = (int) (400f / initialScale);
110 if (sequencesHeight < 40)
112 sequencesHeight = 40;
118 width = (int) (400f * initialScale);
119 sequencesHeight = 300;
127 addComponentListener(new ComponentAdapter()
130 public void componentResized(ComponentEvent evt)
132 if ((getWidth() != width)
133 || (getHeight() != (sequencesHeight + graphHeight)))
135 updateOverviewImage();
140 addMouseMotionListener(new MouseMotionAdapter()
143 public void mouseDragged(MouseEvent evt)
145 if (!av.getWrapAlignment())
147 // TODO: feature: jv2.5 detect shift drag and update selection from
156 addMouseListener(new MouseAdapter()
159 public void mousePressed(MouseEvent evt)
161 if (!av.getWrapAlignment())
170 updateOverviewImage();
183 if (boxY > (sequencesHeight - boxHeight))
185 boxY = sequencesHeight - boxHeight + 1;
193 if (boxX > (width - boxWidth))
195 if (av.hasHiddenColumns())
197 // Try smallest possible box
198 boxWidth = (int) ((av.endRes - av.startRes + 1) * av.getCharWidth() * scalew);
200 boxX = width - boxWidth;
203 int col = (int) (boxX / scalew / av.getCharWidth());
204 int row = (int) (boxY / scaleh / av.getCharHeight());
206 if (av.hasHiddenColumns())
208 if (!av.getColumnSelection().isVisible(col))
213 col = av.getColumnSelection().findColumnPosition(col);
216 if (av.hasHiddenRows())
218 row = av.getAlignment().getHiddenSequences()
219 .findIndexWithoutHiddenSeqs(row);
222 ap.setScrollValues(col, row);
229 public void updateOverviewImage()
239 if ((getWidth() > 0) && (getHeight() > 0))
242 sequencesHeight = getHeight() - graphHeight;
245 setPreferredSize(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;
264 if (av.isShowSequenceFeatures())
266 fr.transferSettings(ap.getSeqPanel().seqCanvas.getFeatureRenderer());
269 int alwidth = av.getAlignment().getWidth();
270 int alheight = av.getAlignment().getHeight()
271 + av.getAlignment().getHiddenSequences().getSize();
273 setPreferredSize(new Dimension(width, sequencesHeight + graphHeight));
275 int fullsizeWidth = alwidth * av.getCharWidth();
276 int fullsizeHeight = alheight * av.getCharHeight();
278 scalew = (float) width / (float) fullsizeWidth;
279 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
281 miniMe = new BufferedImage(width, sequencesHeight + graphHeight,
282 BufferedImage.TYPE_INT_RGB);
284 Graphics mg = miniMe.getGraphics();
285 mg.setColor(Color.orange);
286 mg.fillRect(0, 0, width, miniMe.getHeight());
288 float sampleCol = (float) alwidth / (float) width;
289 float sampleRow = (float) alheight / (float) sequencesHeight;
291 int lastcol = -1, lastrow = -1;
292 int color = Color.white.getRGB();
294 jalview.datamodel.SequenceI seq;
295 final boolean hasHiddenRows = av.hasHiddenRows(), hasHiddenCols = av
297 boolean hiddenRow = false;
298 for (row = 0; row < sequencesHeight; row++)
304 if ((int) (row * sampleRow) == lastrow)
306 // No need to recalculate the colours,
307 // Just copy from the row above
308 for (col = 0; col < width; col++)
314 miniMe.setRGB(col, row, miniMe.getRGB(col, row - 1));
319 lastrow = (int) (row * sampleRow);
324 seq = av.getAlignment().getHiddenSequences()
325 .getHiddenSequence(lastrow);
328 int index = av.getAlignment().getHiddenSequences()
329 .findIndexWithoutHiddenSeqs(lastrow);
331 seq = av.getAlignment().getSequenceAt(index);
340 seq = av.getAlignment().getSequenceAt(lastrow);
345 System.out.println(lastrow + " null");
349 for (col = 0; col < width; col++)
355 if ((int) (col * sampleCol) == lastcol
356 && (int) (row * sampleRow) == lastrow)
358 miniMe.setRGB(col, row, color);
362 lastcol = (int) (col * sampleCol);
364 if (seq.getLength() > lastcol)
366 color = sr.getResidueBoxColour(seq, lastcol).getRGB();
368 if (av.isShowSequenceFeatures())
370 color = fr.findFeatureColour(color, seq, lastcol);
379 || (hasHiddenCols && !av.getColumnSelection().isVisible(
382 color = new Color(color).darker().darker().getRGB();
385 miniMe.setRGB(col, row, color);
390 if (av.getAlignmentConservationAnnotation() != null)
392 renderer.updateFromAlignViewport(av);
393 for (col = 0; col < width; col++)
399 lastcol = (int) (col * sampleCol);
401 mg.translate(col, sequencesHeight);
402 renderer.drawGraph(mg, av.getAlignmentConservationAnnotation(),
403 av.getAlignmentConservationAnnotation().annotations,
404 (int) (sampleCol) + 1, graphHeight,
405 (int) (col * sampleCol), (int) (col * sampleCol) + 1);
406 mg.translate(-col, -sequencesHeight);
419 updateOverviewImage();
426 public void setBoxPosition()
428 int fullsizeWidth = av.getAlignment().getWidth() * av.getCharWidth();
429 int fullsizeHeight = (av.getAlignment().getHeight() + av.getAlignment()
430 .getHiddenSequences().getSize())
431 * av.getCharHeight();
433 int startRes = av.getStartRes();
434 int endRes = av.getEndRes();
436 if (av.hasHiddenColumns())
438 startRes = av.getColumnSelection().adjustForHiddenColumns(startRes);
439 endRes = av.getColumnSelection().adjustForHiddenColumns(endRes);
442 int startSeq = av.startSeq;
443 int endSeq = av.endSeq;
445 if (av.hasHiddenRows())
447 startSeq = av.getAlignment().getHiddenSequences()
448 .adjustForHiddenSeqs(startSeq);
450 endSeq = av.getAlignment().getHiddenSequences()
451 .adjustForHiddenSeqs(endSeq);
455 scalew = (float) width / (float) fullsizeWidth;
456 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
458 boxX = (int) (startRes * av.getCharWidth() * scalew);
459 boxY = (int) (startSeq * av.getCharHeight() * scaleh);
461 if (av.hasHiddenColumns())
463 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
467 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
470 boxHeight = (int) ((endSeq - startSeq) * av.getCharHeight() * scaleh);
482 public void paintComponent(Graphics g)
486 g.setColor(Color.white);
487 g.fillRect(0, 0, getWidth(), getHeight());
489 else if (miniMe != null)
491 g.drawImage(miniMe, 0, 0, this);
494 g.setColor(Color.red);
495 g.drawRect(boxX, boxY, boxWidth, boxHeight);
496 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);