2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
20 import jalview.renderer.AnnotationRenderer;
23 import java.awt.event.*;
24 import java.awt.image.*;
33 public class OverviewPanel extends JPanel implements Runnable
41 final AnnotationRenderer renderer = new AnnotationRenderer();
60 boolean resizing = false;
62 // Can set different properties in this seqCanvas than
63 // main visible SeqCanvas
69 * Creates a new OverviewPanel object.
74 public OverviewPanel(AlignmentPanel ap)
80 sr = new SequenceRenderer(av);
81 sr.renderGaps = false;
82 sr.forOverview = true;
83 fr = new FeatureRenderer(ap);
85 // scale the initial size of overviewpanel to shape of alignment
86 float initialScale = (float) av.getAlignment().getWidth()
87 / (float) av.getAlignment().getHeight();
89 if (av.getAlignmentConservationAnnotation()== null)
94 if (av.getAlignment().getWidth() > av.getAlignment().getHeight())
98 sequencesHeight = (int) (400f / initialScale);
99 if (sequencesHeight < 40)
101 sequencesHeight = 40;
107 width = (int) (400f * initialScale);
108 sequencesHeight = 300;
116 addComponentListener(new ComponentAdapter()
118 public void componentResized(ComponentEvent evt)
120 if ((getWidth() != width)
121 || (getHeight() != (sequencesHeight + graphHeight)))
123 updateOverviewImage();
128 addMouseMotionListener(new MouseMotionAdapter()
130 public void mouseDragged(MouseEvent evt)
132 if (!av.wrapAlignment)
134 // TODO: feature: jv2.5 detect shift drag and update selection from
143 addMouseListener(new MouseAdapter()
145 public void mousePressed(MouseEvent evt)
147 if (!av.wrapAlignment)
156 updateOverviewImage();
169 if (boxY > (sequencesHeight - boxHeight))
171 boxY = sequencesHeight - boxHeight + 1;
179 if (boxX > (width - boxWidth))
181 if (av.hasHiddenColumns())
183 // Try smallest possible box
184 boxWidth = (int) ((av.endRes - av.startRes + 1) * av.getCharWidth() * scalew);
186 boxX = width - boxWidth;
189 int col = (int) (boxX / scalew / av.getCharWidth());
190 int row = (int) (boxY / scaleh / av.getCharHeight());
192 if (av.hasHiddenColumns())
194 if (!av.getColumnSelection().isVisible(col))
199 col = av.getColumnSelection().findColumnPosition(col);
202 if (av.hasHiddenRows())
204 row = av.getAlignment().getHiddenSequences().findIndexWithoutHiddenSeqs(
208 ap.setScrollValues(col, row);
215 public void updateOverviewImage()
225 if ((getWidth() > 0) && (getHeight() > 0))
228 sequencesHeight = getHeight() - graphHeight;
231 setPreferredSize(new Dimension(width, sequencesHeight + graphHeight));
233 Thread thread = new Thread(this);
238 // This is set true if the user resizes whilst
239 // the overview is being calculated
240 boolean resizeAgain = false;
249 if (av.showSequenceFeatures)
251 fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer());
254 int alwidth = av.getAlignment().getWidth();
255 int alheight = av.getAlignment().getHeight()
256 + av.getAlignment().getHiddenSequences().getSize();
258 setPreferredSize(new Dimension(width, sequencesHeight + graphHeight));
260 int fullsizeWidth = alwidth * av.getCharWidth();
261 int fullsizeHeight = alheight * av.getCharHeight();
263 scalew = (float) width / (float) fullsizeWidth;
264 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
266 miniMe = new BufferedImage(width, sequencesHeight + graphHeight,
267 BufferedImage.TYPE_INT_RGB);
269 Graphics mg = miniMe.getGraphics();
270 mg.setColor(Color.orange);
271 mg.fillRect(0, 0, width, miniMe.getHeight());
273 float sampleCol = (float) alwidth / (float) width;
274 float sampleRow = (float) alheight / (float) sequencesHeight;
276 int lastcol = -1, lastrow = -1;
277 int color = Color.white.getRGB();
279 jalview.datamodel.SequenceI seq;
280 boolean hiddenRow = false;
281 for (row = 0; row < sequencesHeight; row++)
283 if ((int) (row * sampleRow) == lastrow)
285 // No need to recalculate the colours,
286 // Just copy from the row above
287 for (col = 0; col < width; col++)
289 miniMe.setRGB(col, row, miniMe.getRGB(col, row - 1));
294 lastrow = (int) (row * sampleRow);
297 if (av.hasHiddenRows())
299 seq = av.getAlignment().getHiddenSequences().getHiddenSequence(lastrow);
302 int index = av.getAlignment().getHiddenSequences()
303 .findIndexWithoutHiddenSeqs(lastrow);
305 seq = av.getAlignment().getSequenceAt(index);
314 seq = av.getAlignment().getSequenceAt(lastrow);
319 System.out.println(lastrow + " null");
323 for (col = 0; col < width; col++)
325 if ((int) (col * sampleCol) == lastcol
326 && (int) (row * sampleRow) == lastrow)
328 miniMe.setRGB(col, row, color);
332 lastcol = (int) (col * sampleCol);
334 if (seq.getLength() > lastcol)
336 color = sr.getResidueBoxColour(seq, lastcol).getRGB();
338 if (av.showSequenceFeatures)
340 color = fr.findFeatureColour(color, seq, lastcol);
349 || (av.hasHiddenColumns() && !av.getColumnSelection()
350 .isVisible(lastcol)))
352 color = new Color(color).darker().darker().getRGB();
355 miniMe.setRGB(col, row, color);
360 if (av.getAlignmentConservationAnnotation()!= null)
362 renderer.updateFromAlignViewport(av);
363 for (col = 0; col < width; col++)
365 lastcol = (int) (col * sampleCol);
367 mg.translate(col, sequencesHeight);
368 renderer.drawGraph(mg, av.getAlignmentConservationAnnotation(),
369 (int) (sampleCol) + 1, graphHeight,
370 (int) (col * sampleCol), (int) (col * sampleCol) + 1);
371 mg.translate(-col, -sequencesHeight);
384 updateOverviewImage();
391 public void setBoxPosition()
393 int fullsizeWidth = av.getAlignment().getWidth() * av.getCharWidth();
394 int fullsizeHeight = (av.getAlignment().getHeight() + av.getAlignment()
395 .getHiddenSequences().getSize()) * av.getCharHeight();
397 int startRes = av.getStartRes();
398 int endRes = av.getEndRes();
400 if (av.hasHiddenColumns())
402 startRes = av.getColumnSelection().adjustForHiddenColumns(startRes);
403 endRes = av.getColumnSelection().adjustForHiddenColumns(endRes);
406 int startSeq = av.startSeq;
407 int endSeq = av.endSeq;
409 if (av.hasHiddenRows())
411 startSeq = av.getAlignment().getHiddenSequences().adjustForHiddenSeqs(
414 endSeq = av.getAlignment().getHiddenSequences()
415 .adjustForHiddenSeqs(endSeq);
419 scalew = (float) width / (float) fullsizeWidth;
420 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
422 boxX = (int) (startRes * av.getCharWidth() * scalew);
423 boxY = (int) (startSeq * av.getCharHeight() * scaleh);
425 if (av.hasHiddenColumns())
427 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
431 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
434 boxHeight = (int) ((endSeq - startSeq) * av.getCharHeight() * scaleh);
445 public void paintComponent(Graphics g)
449 g.setColor(Color.white);
450 g.fillRect(0, 0, getWidth(), getHeight());
452 else if (miniMe != null)
454 g.drawImage(miniMe, 0, 0, this);
457 g.setColor(Color.red);
458 g.drawRect(boxX, boxY, boxWidth, boxHeight);
459 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);