2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, 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();
61 boolean resizing = false;
63 // Can set different properties in this seqCanvas than
64 // main visible SeqCanvas
70 * Creates a new OverviewPanel object.
75 public OverviewPanel(AlignmentPanel ap)
81 sr = new SequenceRenderer(av);
82 sr.renderGaps = false;
83 sr.forOverview = true;
84 fr = new FeatureRenderer(ap);
86 // scale the initial size of overviewpanel to shape of alignment
87 float initialScale = (float) av.getAlignment().getWidth()
88 / (float) av.getAlignment().getHeight();
90 if (av.getAlignmentConservationAnnotation() == null)
95 if (av.getAlignment().getWidth() > av.getAlignment().getHeight())
99 sequencesHeight = (int) (400f / initialScale);
100 if (sequencesHeight < 40)
102 sequencesHeight = 40;
108 width = (int) (400f * initialScale);
109 sequencesHeight = 300;
117 addComponentListener(new ComponentAdapter()
120 public void componentResized(ComponentEvent evt)
122 if ((getWidth() != width)
123 || (getHeight() != (sequencesHeight + graphHeight)))
125 updateOverviewImage();
130 addMouseMotionListener(new MouseMotionAdapter()
133 public void mouseDragged(MouseEvent evt)
135 if (!av.wrapAlignment)
137 // TODO: feature: jv2.5 detect shift drag and update selection from
146 addMouseListener(new MouseAdapter()
149 public void mousePressed(MouseEvent evt)
151 if (!av.wrapAlignment)
160 updateOverviewImage();
173 if (boxY > (sequencesHeight - boxHeight))
175 boxY = sequencesHeight - boxHeight + 1;
183 if (boxX > (width - boxWidth))
185 if (av.hasHiddenColumns())
187 // Try smallest possible box
188 boxWidth = (int) ((av.endRes - av.startRes + 1) * av.getCharWidth() * scalew);
190 boxX = width - boxWidth;
193 int col = (int) (boxX / scalew / av.getCharWidth());
194 int row = (int) (boxY / scaleh / av.getCharHeight());
196 if (av.hasHiddenColumns())
198 if (!av.getColumnSelection().isVisible(col))
203 col = av.getColumnSelection().findColumnPosition(col);
206 if (av.hasHiddenRows())
208 row = av.getAlignment().getHiddenSequences()
209 .findIndexWithoutHiddenSeqs(row);
212 ap.setScrollValues(col, row);
219 public void updateOverviewImage()
229 if ((getWidth() > 0) && (getHeight() > 0))
232 sequencesHeight = getHeight() - graphHeight;
235 setPreferredSize(new Dimension(width, sequencesHeight + graphHeight));
237 Thread thread = new Thread(this);
242 // This is set true if the user resizes whilst
243 // the overview is being calculated
244 boolean resizeAgain = false;
254 if (av.showSequenceFeatures)
256 fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer());
259 int alwidth = av.getAlignment().getWidth();
260 int alheight = av.getAlignment().getHeight()
261 + av.getAlignment().getHiddenSequences().getSize();
263 setPreferredSize(new Dimension(width, sequencesHeight + graphHeight));
265 int fullsizeWidth = alwidth * av.getCharWidth();
266 int fullsizeHeight = alheight * av.getCharHeight();
268 scalew = (float) width / (float) fullsizeWidth;
269 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
271 miniMe = new BufferedImage(width, sequencesHeight + graphHeight,
272 BufferedImage.TYPE_INT_RGB);
274 Graphics mg = miniMe.getGraphics();
275 mg.setColor(Color.orange);
276 mg.fillRect(0, 0, width, miniMe.getHeight());
278 float sampleCol = (float) alwidth / (float) width;
279 float sampleRow = (float) alheight / (float) sequencesHeight;
281 int lastcol = -1, lastrow = -1;
282 int color = Color.white.getRGB();
284 jalview.datamodel.SequenceI seq;
285 boolean hiddenRow = false;
286 for (row = 0; row < sequencesHeight; row++)
288 if ((int) (row * sampleRow) == lastrow)
290 // No need to recalculate the colours,
291 // Just copy from the row above
292 for (col = 0; col < width; col++)
294 miniMe.setRGB(col, row, miniMe.getRGB(col, row - 1));
299 lastrow = (int) (row * sampleRow);
302 if (av.hasHiddenRows())
304 seq = av.getAlignment().getHiddenSequences()
305 .getHiddenSequence(lastrow);
308 int index = av.getAlignment().getHiddenSequences()
309 .findIndexWithoutHiddenSeqs(lastrow);
311 seq = av.getAlignment().getSequenceAt(index);
320 seq = av.getAlignment().getSequenceAt(lastrow);
325 System.out.println(lastrow + " null");
329 for (col = 0; col < width; col++)
331 if ((int) (col * sampleCol) == lastcol
332 && (int) (row * sampleRow) == lastrow)
334 miniMe.setRGB(col, row, color);
338 lastcol = (int) (col * sampleCol);
340 if (seq.getLength() > lastcol)
342 color = sr.getResidueBoxColour(seq, lastcol).getRGB();
344 if (av.showSequenceFeatures)
346 color = fr.findFeatureColour(color, seq, lastcol);
355 || (av.hasHiddenColumns() && !av.getColumnSelection()
356 .isVisible(lastcol)))
358 color = new Color(color).darker().darker().getRGB();
361 miniMe.setRGB(col, row, color);
366 if (av.getAlignmentConservationAnnotation() != null)
368 renderer.updateFromAlignViewport(av);
369 for (col = 0; col < width; col++)
371 lastcol = (int) (col * sampleCol);
373 mg.translate(col, sequencesHeight);
374 renderer.drawGraph(mg, av.getAlignmentConservationAnnotation(),
375 av.getAlignmentConservationAnnotation().annotations,
376 (int) (sampleCol) + 1, graphHeight,
377 (int) (col * sampleCol), (int) (col * sampleCol) + 1);
378 mg.translate(-col, -sequencesHeight);
391 updateOverviewImage();
398 public void setBoxPosition()
400 int fullsizeWidth = av.getAlignment().getWidth() * av.getCharWidth();
401 int fullsizeHeight = (av.getAlignment().getHeight() + av.getAlignment()
402 .getHiddenSequences().getSize())
403 * av.getCharHeight();
405 int startRes = av.getStartRes();
406 int endRes = av.getEndRes();
408 if (av.hasHiddenColumns())
410 startRes = av.getColumnSelection().adjustForHiddenColumns(startRes);
411 endRes = av.getColumnSelection().adjustForHiddenColumns(endRes);
414 int startSeq = av.startSeq;
415 int endSeq = av.endSeq;
417 if (av.hasHiddenRows())
419 startSeq = av.getAlignment().getHiddenSequences()
420 .adjustForHiddenSeqs(startSeq);
422 endSeq = av.getAlignment().getHiddenSequences()
423 .adjustForHiddenSeqs(endSeq);
427 scalew = (float) width / (float) fullsizeWidth;
428 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
430 boxX = (int) (startRes * av.getCharWidth() * scalew);
431 boxY = (int) (startSeq * av.getCharHeight() * scaleh);
433 if (av.hasHiddenColumns())
435 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
439 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
442 boxHeight = (int) ((endSeq - startSeq) * av.getCharHeight() * scaleh);
454 public void paintComponent(Graphics g)
458 g.setColor(Color.white);
459 g.fillRect(0, 0, getWidth(), getHeight());
461 else if (miniMe != null)
463 g.drawImage(miniMe, 0, 0, this);
466 g.setColor(Color.red);
467 g.drawRect(boxX, boxY, boxWidth, boxHeight);
468 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);