2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 import jalview.renderer.AnnotationRenderer;
24 import java.awt.event.*;
25 import java.awt.image.*;
34 public class OverviewPanel extends JPanel implements Runnable
42 final AnnotationRenderer renderer = new AnnotationRenderer();
62 boolean resizing = false;
64 // Can set different properties in this seqCanvas than
65 // main visible SeqCanvas
71 * Creates a new OverviewPanel object.
76 public OverviewPanel(AlignmentPanel ap)
82 sr = new SequenceRenderer(av);
83 sr.renderGaps = false;
84 sr.forOverview = true;
85 fr = new FeatureRenderer(ap);
87 // scale the initial size of overviewpanel to shape of alignment
88 float initialScale = (float) av.getAlignment().getWidth()
89 / (float) av.getAlignment().getHeight();
91 if (av.getAlignmentConservationAnnotation() == null)
96 if (av.getAlignment().getWidth() > av.getAlignment().getHeight())
100 sequencesHeight = (int) (400f / initialScale);
101 if (sequencesHeight < 40)
103 sequencesHeight = 40;
109 width = (int) (400f * initialScale);
110 sequencesHeight = 300;
118 addComponentListener(new ComponentAdapter()
121 public void componentResized(ComponentEvent evt)
123 if ((getWidth() != width)
124 || (getHeight() != (sequencesHeight + graphHeight)))
126 updateOverviewImage();
131 addMouseMotionListener(new MouseMotionAdapter()
134 public void mouseDragged(MouseEvent evt)
136 if (!av.wrapAlignment)
138 // TODO: feature: jv2.5 detect shift drag and update selection from
147 addMouseListener(new MouseAdapter()
150 public void mousePressed(MouseEvent evt)
152 if (!av.wrapAlignment)
161 updateOverviewImage();
174 if (boxY > (sequencesHeight - boxHeight))
176 boxY = sequencesHeight - boxHeight + 1;
184 if (boxX > (width - boxWidth))
186 if (av.hasHiddenColumns())
188 // Try smallest possible box
189 boxWidth = (int) ((av.endRes - av.startRes + 1) * av.getCharWidth() * scalew);
191 boxX = width - boxWidth;
194 int col = (int) (boxX / scalew / av.getCharWidth());
195 int row = (int) (boxY / scaleh / av.getCharHeight());
197 if (av.hasHiddenColumns())
199 if (!av.getColumnSelection().isVisible(col))
204 col = av.getColumnSelection().findColumnPosition(col);
207 if (av.hasHiddenRows())
209 row = av.getAlignment().getHiddenSequences()
210 .findIndexWithoutHiddenSeqs(row);
213 ap.setScrollValues(col, row);
220 public void updateOverviewImage()
230 if ((getWidth() > 0) && (getHeight() > 0))
233 sequencesHeight = getHeight() - graphHeight;
236 setPreferredSize(new Dimension(width, sequencesHeight + graphHeight));
238 Thread thread = new Thread(this);
243 // This is set true if the user resizes whilst
244 // the overview is being calculated
245 boolean resizeAgain = false;
255 if (av.showSequenceFeatures)
257 fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer());
260 int alwidth = av.getAlignment().getWidth();
261 int alheight = av.getAlignment().getHeight()
262 + av.getAlignment().getHiddenSequences().getSize();
264 setPreferredSize(new Dimension(width, sequencesHeight + graphHeight));
266 int fullsizeWidth = alwidth * av.getCharWidth();
267 int fullsizeHeight = alheight * av.getCharHeight();
269 scalew = (float) width / (float) fullsizeWidth;
270 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
272 miniMe = new BufferedImage(width, sequencesHeight + graphHeight,
273 BufferedImage.TYPE_INT_RGB);
275 Graphics mg = miniMe.getGraphics();
276 mg.setColor(Color.orange);
277 mg.fillRect(0, 0, width, miniMe.getHeight());
279 float sampleCol = (float) alwidth / (float) width;
280 float sampleRow = (float) alheight / (float) sequencesHeight;
282 int lastcol = -1, lastrow = -1;
283 int color = Color.white.getRGB();
285 jalview.datamodel.SequenceI seq;
286 boolean hiddenRow = false;
287 for (row = 0; row < sequencesHeight; row++)
289 if ((int) (row * sampleRow) == lastrow)
291 // No need to recalculate the colours,
292 // Just copy from the row above
293 for (col = 0; col < width; col++)
295 miniMe.setRGB(col, row, miniMe.getRGB(col, row - 1));
300 lastrow = (int) (row * sampleRow);
303 if (av.hasHiddenRows())
305 seq = av.getAlignment().getHiddenSequences()
306 .getHiddenSequence(lastrow);
309 int index = av.getAlignment().getHiddenSequences()
310 .findIndexWithoutHiddenSeqs(lastrow);
312 seq = av.getAlignment().getSequenceAt(index);
321 seq = av.getAlignment().getSequenceAt(lastrow);
326 System.out.println(lastrow + " null");
330 for (col = 0; col < width; col++)
332 if ((int) (col * sampleCol) == lastcol
333 && (int) (row * sampleRow) == lastrow)
335 miniMe.setRGB(col, row, color);
339 lastcol = (int) (col * sampleCol);
341 if (seq.getLength() > lastcol)
343 color = sr.getResidueBoxColour(seq, lastcol).getRGB();
345 if (av.showSequenceFeatures)
347 color = fr.findFeatureColour(color, seq, lastcol);
356 || (av.hasHiddenColumns() && !av.getColumnSelection()
357 .isVisible(lastcol)))
359 color = new Color(color).darker().darker().getRGB();
362 miniMe.setRGB(col, row, color);
367 if (av.getAlignmentConservationAnnotation() != null)
369 renderer.updateFromAlignViewport(av);
370 for (col = 0; col < width; col++)
372 lastcol = (int) (col * sampleCol);
374 mg.translate(col, sequencesHeight);
375 renderer.drawGraph(mg, av.getAlignmentConservationAnnotation(),
376 av.getAlignmentConservationAnnotation().annotations,
377 (int) (sampleCol) + 1, graphHeight,
378 (int) (col * sampleCol), (int) (col * sampleCol) + 1);
379 mg.translate(-col, -sequencesHeight);
392 updateOverviewImage();
399 public void setBoxPosition()
401 int fullsizeWidth = av.getAlignment().getWidth() * av.getCharWidth();
402 int fullsizeHeight = (av.getAlignment().getHeight() + av.getAlignment()
403 .getHiddenSequences().getSize())
404 * av.getCharHeight();
406 int startRes = av.getStartRes();
407 int endRes = av.getEndRes();
409 if (av.hasHiddenColumns())
411 startRes = av.getColumnSelection().adjustForHiddenColumns(startRes);
412 endRes = av.getColumnSelection().adjustForHiddenColumns(endRes);
415 int startSeq = av.startSeq;
416 int endSeq = av.endSeq;
418 if (av.hasHiddenRows())
420 startSeq = av.getAlignment().getHiddenSequences()
421 .adjustForHiddenSeqs(startSeq);
423 endSeq = av.getAlignment().getHiddenSequences()
424 .adjustForHiddenSeqs(endSeq);
428 scalew = (float) width / (float) fullsizeWidth;
429 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
431 boxX = (int) (startRes * av.getCharWidth() * scalew);
432 boxY = (int) (startSeq * av.getCharHeight() * scaleh);
434 if (av.hasHiddenColumns())
436 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
440 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
443 boxHeight = (int) ((endSeq - startSeq) * av.getCharHeight() * scaleh);
455 public void paintComponent(Graphics g)
459 g.setColor(Color.white);
460 g.fillRect(0, 0, getWidth(), getHeight());
462 else if (miniMe != null)
464 g.drawImage(miniMe, 0, 0, this);
467 g.setColor(Color.red);
468 g.drawRect(boxX, boxY, boxWidth, boxHeight);
469 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);