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()
119 public void componentResized(ComponentEvent evt)
121 if ((getWidth() != width)
122 || (getHeight() != (sequencesHeight + graphHeight)))
124 updateOverviewImage();
129 addMouseMotionListener(new MouseMotionAdapter()
132 public void mouseDragged(MouseEvent evt)
134 if (!av.wrapAlignment)
136 // TODO: feature: jv2.5 detect shift drag and update selection from
145 addMouseListener(new MouseAdapter()
148 public void mousePressed(MouseEvent evt)
150 if (!av.wrapAlignment)
159 updateOverviewImage();
172 if (boxY > (sequencesHeight - boxHeight))
174 boxY = sequencesHeight - boxHeight + 1;
182 if (boxX > (width - boxWidth))
184 if (av.hasHiddenColumns())
186 // Try smallest possible box
187 boxWidth = (int) ((av.endRes - av.startRes + 1) * av.getCharWidth() * scalew);
189 boxX = width - boxWidth;
192 int col = (int) (boxX / scalew / av.getCharWidth());
193 int row = (int) (boxY / scaleh / av.getCharHeight());
195 if (av.hasHiddenColumns())
197 if (!av.getColumnSelection().isVisible(col))
202 col = av.getColumnSelection().findColumnPosition(col);
205 if (av.hasHiddenRows())
207 row = av.getAlignment().getHiddenSequences().findIndexWithoutHiddenSeqs(
211 ap.setScrollValues(col, row);
218 public void updateOverviewImage()
228 if ((getWidth() > 0) && (getHeight() > 0))
231 sequencesHeight = getHeight() - graphHeight;
234 setPreferredSize(new Dimension(width, sequencesHeight + graphHeight));
236 Thread thread = new Thread(this);
241 // This is set true if the user resizes whilst
242 // the overview is being calculated
243 boolean resizeAgain = false;
253 if (av.showSequenceFeatures)
255 fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer());
258 int alwidth = av.getAlignment().getWidth();
259 int alheight = av.getAlignment().getHeight()
260 + av.getAlignment().getHiddenSequences().getSize();
262 setPreferredSize(new Dimension(width, sequencesHeight + graphHeight));
264 int fullsizeWidth = alwidth * av.getCharWidth();
265 int fullsizeHeight = alheight * av.getCharHeight();
267 scalew = (float) width / (float) fullsizeWidth;
268 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
270 miniMe = new BufferedImage(width, sequencesHeight + graphHeight,
271 BufferedImage.TYPE_INT_RGB);
273 Graphics mg = miniMe.getGraphics();
274 mg.setColor(Color.orange);
275 mg.fillRect(0, 0, width, miniMe.getHeight());
277 float sampleCol = (float) alwidth / (float) width;
278 float sampleRow = (float) alheight / (float) sequencesHeight;
280 int lastcol = -1, lastrow = -1;
281 int color = Color.white.getRGB();
283 jalview.datamodel.SequenceI seq;
284 boolean hiddenRow = false;
285 for (row = 0; row < sequencesHeight; row++)
287 if ((int) (row * sampleRow) == lastrow)
289 // No need to recalculate the colours,
290 // Just copy from the row above
291 for (col = 0; col < width; col++)
293 miniMe.setRGB(col, row, miniMe.getRGB(col, row - 1));
298 lastrow = (int) (row * sampleRow);
301 if (av.hasHiddenRows())
303 seq = av.getAlignment().getHiddenSequences().getHiddenSequence(lastrow);
306 int index = av.getAlignment().getHiddenSequences()
307 .findIndexWithoutHiddenSeqs(lastrow);
309 seq = av.getAlignment().getSequenceAt(index);
318 seq = av.getAlignment().getSequenceAt(lastrow);
323 System.out.println(lastrow + " null");
327 for (col = 0; col < width; col++)
329 if ((int) (col * sampleCol) == lastcol
330 && (int) (row * sampleRow) == lastrow)
332 miniMe.setRGB(col, row, color);
336 lastcol = (int) (col * sampleCol);
338 if (seq.getLength() > lastcol)
340 color = sr.getResidueBoxColour(seq, lastcol).getRGB();
342 if (av.showSequenceFeatures)
344 color = fr.findFeatureColour(color, seq, lastcol);
353 || (av.hasHiddenColumns() && !av.getColumnSelection()
354 .isVisible(lastcol)))
356 color = new Color(color).darker().darker().getRGB();
359 miniMe.setRGB(col, row, color);
364 if (av.getAlignmentConservationAnnotation()!= null)
366 renderer.updateFromAlignViewport(av);
367 for (col = 0; col < width; col++)
369 lastcol = (int) (col * sampleCol);
371 mg.translate(col, sequencesHeight);
372 renderer.drawGraph(mg, av.getAlignmentConservationAnnotation(),av.getAlignmentConservationAnnotation().annotations,
373 (int) (sampleCol) + 1, graphHeight,
374 (int) (col * sampleCol), (int) (col * sampleCol) + 1);
375 mg.translate(-col, -sequencesHeight);
388 updateOverviewImage();
395 public void setBoxPosition()
397 int fullsizeWidth = av.getAlignment().getWidth() * av.getCharWidth();
398 int fullsizeHeight = (av.getAlignment().getHeight() + av.getAlignment()
399 .getHiddenSequences().getSize()) * av.getCharHeight();
401 int startRes = av.getStartRes();
402 int endRes = av.getEndRes();
404 if (av.hasHiddenColumns())
406 startRes = av.getColumnSelection().adjustForHiddenColumns(startRes);
407 endRes = av.getColumnSelection().adjustForHiddenColumns(endRes);
410 int startSeq = av.startSeq;
411 int endSeq = av.endSeq;
413 if (av.hasHiddenRows())
415 startSeq = av.getAlignment().getHiddenSequences().adjustForHiddenSeqs(
418 endSeq = av.getAlignment().getHiddenSequences()
419 .adjustForHiddenSeqs(endSeq);
423 scalew = (float) width / (float) fullsizeWidth;
424 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
426 boxX = (int) (startRes * av.getCharWidth() * scalew);
427 boxY = (int) (startSeq * av.getCharHeight() * scaleh);
429 if (av.hasHiddenColumns())
431 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
435 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
438 boxHeight = (int) ((endSeq - startSeq) * av.getCharHeight() * scaleh);
450 public void paintComponent(Graphics g)
454 g.setColor(Color.white);
455 g.fillRect(0, 0, getWidth(), getHeight());
457 else if (miniMe != null)
459 g.drawImage(miniMe, 0, 0, this);
462 g.setColor(Color.red);
463 g.drawRect(boxX, boxY, boxWidth, boxHeight);
464 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);