2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
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
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;
26 import java.awt.event.*;
27 import java.awt.image.*;
36 public class OverviewPanel extends JPanel implements Runnable
44 final AnnotationRenderer renderer = new AnnotationRenderer();
64 boolean resizing = false;
66 // Can set different properties in this seqCanvas than
67 // main visible SeqCanvas
73 * Creates a new OverviewPanel object.
78 public OverviewPanel(AlignmentPanel ap)
84 sr = new SequenceRenderer(av);
85 sr.renderGaps = false;
86 sr.forOverview = true;
87 fr = new FeatureRenderer(ap);
89 // scale the initial size of overviewpanel to shape of alignment
90 float initialScale = (float) av.getAlignment().getWidth()
91 / (float) av.getAlignment().getHeight();
93 if (av.getAlignmentConservationAnnotation() == null)
98 if (av.getAlignment().getWidth() > av.getAlignment().getHeight())
102 sequencesHeight = (int) (400f / initialScale);
103 if (sequencesHeight < 40)
105 sequencesHeight = 40;
111 width = (int) (400f * initialScale);
112 sequencesHeight = 300;
120 addComponentListener(new ComponentAdapter()
123 public void componentResized(ComponentEvent evt)
125 if ((getWidth() != width)
126 || (getHeight() != (sequencesHeight + graphHeight)))
128 updateOverviewImage();
133 addMouseMotionListener(new MouseMotionAdapter()
136 public void mouseDragged(MouseEvent evt)
138 if (!av.wrapAlignment)
140 // TODO: feature: jv2.5 detect shift drag and update selection from
149 addMouseListener(new MouseAdapter()
152 public void mousePressed(MouseEvent evt)
154 if (!av.wrapAlignment)
163 updateOverviewImage();
176 if (boxY > (sequencesHeight - boxHeight))
178 boxY = sequencesHeight - boxHeight + 1;
186 if (boxX > (width - boxWidth))
188 if (av.hasHiddenColumns())
190 // Try smallest possible box
191 boxWidth = (int) ((av.endRes - av.startRes + 1) * av.getCharWidth() * scalew);
193 boxX = width - boxWidth;
196 int col = (int) (boxX / scalew / av.getCharWidth());
197 int row = (int) (boxY / scaleh / av.getCharHeight());
199 if (av.hasHiddenColumns())
201 if (!av.getColumnSelection().isVisible(col))
206 col = av.getColumnSelection().findColumnPosition(col);
209 if (av.hasHiddenRows())
211 row = av.getAlignment().getHiddenSequences()
212 .findIndexWithoutHiddenSeqs(row);
215 ap.setScrollValues(col, row);
222 public void updateOverviewImage()
232 if ((getWidth() > 0) && (getHeight() > 0))
235 sequencesHeight = getHeight() - graphHeight;
238 setPreferredSize(new Dimension(width, sequencesHeight + graphHeight));
240 Thread thread = new Thread(this);
245 // This is set true if the user resizes whilst
246 // the overview is being calculated
247 boolean resizeAgain = false;
257 if (av.showSequenceFeatures)
259 fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer());
262 int alwidth = av.getAlignment().getWidth();
263 int alheight = av.getAlignment().getHeight()
264 + av.getAlignment().getHiddenSequences().getSize();
266 setPreferredSize(new Dimension(width, sequencesHeight + graphHeight));
268 int fullsizeWidth = alwidth * av.getCharWidth();
269 int fullsizeHeight = alheight * av.getCharHeight();
271 scalew = (float) width / (float) fullsizeWidth;
272 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
274 miniMe = new BufferedImage(width, sequencesHeight + graphHeight,
275 BufferedImage.TYPE_INT_RGB);
277 Graphics mg = miniMe.getGraphics();
278 mg.setColor(Color.orange);
279 mg.fillRect(0, 0, width, miniMe.getHeight());
281 float sampleCol = (float) alwidth / (float) width;
282 float sampleRow = (float) alheight / (float) sequencesHeight;
284 int lastcol = -1, lastrow = -1;
285 int color = Color.white.getRGB();
287 jalview.datamodel.SequenceI seq;
288 boolean hiddenRow = false;
289 for (row = 0; row < sequencesHeight; row++)
291 if ((int) (row * sampleRow) == lastrow)
293 // No need to recalculate the colours,
294 // Just copy from the row above
295 for (col = 0; col < width; col++)
297 miniMe.setRGB(col, row, miniMe.getRGB(col, row - 1));
302 lastrow = (int) (row * sampleRow);
305 if (av.hasHiddenRows())
307 seq = av.getAlignment().getHiddenSequences()
308 .getHiddenSequence(lastrow);
311 int index = av.getAlignment().getHiddenSequences()
312 .findIndexWithoutHiddenSeqs(lastrow);
314 seq = av.getAlignment().getSequenceAt(index);
323 seq = av.getAlignment().getSequenceAt(lastrow);
328 System.out.println(lastrow + " null");
332 for (col = 0; col < width; col++)
334 if ((int) (col * sampleCol) == lastcol
335 && (int) (row * sampleRow) == lastrow)
337 miniMe.setRGB(col, row, color);
341 lastcol = (int) (col * sampleCol);
343 if (seq.getLength() > lastcol)
345 color = sr.getResidueBoxColour(seq, lastcol).getRGB();
347 if (av.showSequenceFeatures)
349 color = fr.findFeatureColour(color, seq, lastcol);
358 || (av.hasHiddenColumns() && !av.getColumnSelection()
359 .isVisible(lastcol)))
361 color = new Color(color).darker().darker().getRGB();
364 miniMe.setRGB(col, row, color);
369 if (av.getAlignmentConservationAnnotation() != null)
371 renderer.updateFromAlignViewport(av);
372 for (col = 0; col < width; col++)
374 lastcol = (int) (col * sampleCol);
376 mg.translate(col, sequencesHeight);
377 renderer.drawGraph(mg, av.getAlignmentConservationAnnotation(),
378 av.getAlignmentConservationAnnotation().annotations,
379 (int) (sampleCol) + 1, graphHeight,
380 (int) (col * sampleCol), (int) (col * sampleCol) + 1);
381 mg.translate(-col, -sequencesHeight);
394 updateOverviewImage();
401 public void setBoxPosition()
403 int fullsizeWidth = av.getAlignment().getWidth() * av.getCharWidth();
404 int fullsizeHeight = (av.getAlignment().getHeight() + av.getAlignment()
405 .getHiddenSequences().getSize())
406 * av.getCharHeight();
408 int startRes = av.getStartRes();
409 int endRes = av.getEndRes();
411 if (av.hasHiddenColumns())
413 startRes = av.getColumnSelection().adjustForHiddenColumns(startRes);
414 endRes = av.getColumnSelection().adjustForHiddenColumns(endRes);
417 int startSeq = av.startSeq;
418 int endSeq = av.endSeq;
420 if (av.hasHiddenRows())
422 startSeq = av.getAlignment().getHiddenSequences()
423 .adjustForHiddenSeqs(startSeq);
425 endSeq = av.getAlignment().getHiddenSequences()
426 .adjustForHiddenSeqs(endSeq);
430 scalew = (float) width / (float) fullsizeWidth;
431 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
433 boxX = (int) (startRes * av.getCharWidth() * scalew);
434 boxY = (int) (startSeq * av.getCharHeight() * scaleh);
436 if (av.hasHiddenColumns())
438 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
442 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
445 boxHeight = (int) ((endSeq - startSeq) * av.getCharHeight() * scaleh);
457 public void paintComponent(Graphics g)
461 g.setColor(Color.white);
462 g.fillRect(0, 0, getWidth(), getHeight());
464 else if (miniMe != null)
466 g.drawImage(miniMe, 0, 0, this);
469 g.setColor(Color.red);
470 g.drawRect(boxX, boxY, boxWidth, boxHeight);
471 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);