2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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.datamodel.SequenceI;
24 import jalview.renderer.AnnotationRenderer;
26 import java.awt.Color;
27 import java.awt.Dimension;
28 import java.awt.Graphics;
29 import java.awt.event.ComponentAdapter;
30 import java.awt.event.ComponentEvent;
31 import java.awt.event.MouseAdapter;
32 import java.awt.event.MouseEvent;
33 import java.awt.event.MouseMotionAdapter;
34 import java.awt.image.BufferedImage;
36 import javax.swing.JPanel;
44 public class OverviewPanel extends JPanel implements Runnable
52 final AnnotationRenderer renderer = new AnnotationRenderer();
72 boolean resizing = false;
74 // Can set different properties in this seqCanvas than
75 // main visible SeqCanvas
78 jalview.renderer.seqfeatures.FeatureRenderer fr;
81 * Creates a new OverviewPanel object.
86 public OverviewPanel(AlignmentPanel ap)
92 sr = new SequenceRenderer(av);
93 sr.renderGaps = false;
94 sr.forOverview = true;
95 fr = new FeatureRenderer(ap);
97 // scale the initial size of overviewpanel to shape of alignment
98 float initialScale = (float) av.getAlignment().getWidth()
99 / (float) av.getAlignment().getHeight();
101 if (av.getAlignmentConservationAnnotation() == null)
106 if (av.getAlignment().getWidth() > av.getAlignment().getHeight())
110 sequencesHeight = (int) (400f / initialScale);
111 if (sequencesHeight < 40)
113 sequencesHeight = 40;
119 width = (int) (400f * initialScale);
120 sequencesHeight = 300;
128 addComponentListener(new ComponentAdapter()
131 public void componentResized(ComponentEvent evt)
133 if ((getWidth() != width)
134 || (getHeight() != (sequencesHeight + graphHeight)))
136 updateOverviewImage();
141 addMouseMotionListener(new MouseMotionAdapter()
144 public void mouseDragged(MouseEvent evt)
146 if (!av.getWrapAlignment())
148 // TODO: feature: jv2.5 detect shift drag and update selection from
157 addMouseListener(new MouseAdapter()
160 public void mousePressed(MouseEvent evt)
162 if (!av.getWrapAlignment())
171 updateOverviewImage();
184 if (boxY > (sequencesHeight - boxHeight))
186 boxY = sequencesHeight - boxHeight + 1;
194 if (boxX > (width - boxWidth))
196 if (av.hasHiddenColumns())
198 // Try smallest possible box
199 boxWidth = (int) ((av.endRes - av.startRes + 1) * av.getCharWidth() * scalew);
201 boxX = width - boxWidth;
204 int col = (int) (boxX / scalew / av.getCharWidth());
205 int row = (int) (boxY / scaleh / av.getCharHeight());
207 if (av.hasHiddenColumns())
209 if (!av.getColumnSelection().isVisible(col))
214 col = av.getColumnSelection().findColumnPosition(col);
217 if (av.hasHiddenRows())
219 row = av.getAlignment().getHiddenSequences()
220 .findIndexWithoutHiddenSeqs(row);
223 ap.setScrollValues(col, row);
230 public void updateOverviewImage()
240 if ((getWidth() > 0) && (getHeight() > 0))
243 sequencesHeight = getHeight() - graphHeight;
246 setPreferredSize(new Dimension(width, sequencesHeight + graphHeight));
248 Thread thread = new Thread(this);
253 // This is set true if the user resizes whilst
254 // the overview is being calculated
255 boolean resizeAgain = false;
265 if (av.isShowSequenceFeatures())
267 fr.transferSettings(ap.getSeqPanel().seqCanvas.getFeatureRenderer());
270 int alwidth = av.getAlignment().getWidth();
271 int alheight = av.getAlignment().getHeight()
272 + av.getAlignment().getHiddenSequences().getSize();
274 setPreferredSize(new Dimension(width, sequencesHeight + graphHeight));
276 int fullsizeWidth = alwidth * av.getCharWidth();
277 int fullsizeHeight = alheight * av.getCharHeight();
279 scalew = (float) width / (float) fullsizeWidth;
280 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
282 miniMe = new BufferedImage(width, sequencesHeight + graphHeight,
283 BufferedImage.TYPE_INT_RGB);
285 Graphics mg = miniMe.getGraphics();
286 mg.setColor(Color.orange);
287 mg.fillRect(0, 0, width, miniMe.getHeight());
289 float sampleCol = (float) alwidth / (float) width;
290 float sampleRow = (float) alheight / (float) sequencesHeight;
292 int lastcol = -1, lastrow = -1;
293 int color = Color.white.getRGB();
296 final boolean hasHiddenRows = av.hasHiddenRows(), hasHiddenCols = av
298 boolean hiddenRow = false;
299 for (row = 0; row < sequencesHeight; row++)
301 if ((int) (row * sampleRow) == lastrow)
303 // No need to recalculate the colours,
304 // Just copy from the row above
305 for (col = 0; col < width; col++)
307 miniMe.setRGB(col, row, miniMe.getRGB(col, row - 1));
312 lastrow = (int) (row * sampleRow);
317 seq = av.getAlignment().getHiddenSequences()
318 .getHiddenSequence(lastrow);
321 int index = av.getAlignment().getHiddenSequences()
322 .findIndexWithoutHiddenSeqs(lastrow);
324 seq = av.getAlignment().getSequenceAt(index);
333 seq = av.getAlignment().getSequenceAt(lastrow);
338 System.out.println(lastrow + " null");
342 for (col = 0; col < width; col++)
344 if ((int) (col * sampleCol) == lastcol
345 && (int) (row * sampleRow) == lastrow)
347 miniMe.setRGB(col, row, color);
351 lastcol = (int) (col * sampleCol);
353 if (seq.getLength() > lastcol)
355 color = sr.getResidueBoxColour(seq, lastcol).getRGB();
357 if (av.isShowSequenceFeatures())
359 color = fr.findFeatureColour(color, seq, lastcol);
368 || (hasHiddenCols && !av.getColumnSelection()
369 .isVisible(lastcol)))
371 color = new Color(color).darker().darker().getRGB();
374 miniMe.setRGB(col, row, color);
379 if (av.getAlignmentConservationAnnotation() != null)
381 renderer.updateFromAlignViewport(av);
382 for (col = 0; col < width; col++)
384 lastcol = (int) (col * sampleCol);
386 mg.translate(col, sequencesHeight);
387 renderer.drawGraph(mg, av.getAlignmentConservationAnnotation(),
388 av.getAlignmentConservationAnnotation().annotations,
389 (int) (sampleCol) + 1, graphHeight,
390 (int) (col * sampleCol), (int) (col * sampleCol) + 1);
391 mg.translate(-col, -sequencesHeight);
404 updateOverviewImage();
411 public void setBoxPosition()
413 int fullsizeWidth = av.getAlignment().getWidth() * av.getCharWidth();
414 int fullsizeHeight = (av.getAlignment().getHeight() + av.getAlignment()
415 .getHiddenSequences().getSize())
416 * av.getCharHeight();
418 int startRes = av.getStartRes();
419 int endRes = av.getEndRes();
421 if (av.hasHiddenColumns())
423 startRes = av.getColumnSelection().adjustForHiddenColumns(startRes);
424 endRes = av.getColumnSelection().adjustForHiddenColumns(endRes);
427 int startSeq = av.startSeq;
428 int endSeq = av.endSeq;
430 if (av.hasHiddenRows())
432 startSeq = av.getAlignment().getHiddenSequences()
433 .adjustForHiddenSeqs(startSeq);
435 endSeq = av.getAlignment().getHiddenSequences()
436 .adjustForHiddenSeqs(endSeq);
440 scalew = (float) width / (float) fullsizeWidth;
441 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
443 boxX = (int) (startRes * av.getCharWidth() * scalew);
444 boxY = (int) (startSeq * av.getCharHeight() * scaleh);
446 if (av.hasHiddenColumns())
448 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
452 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
455 boxHeight = (int) ((endSeq - startSeq) * av.getCharHeight() * scaleh);
467 public void paintComponent(Graphics g)
471 g.setColor(Color.white);
472 g.fillRect(0, 0, getWidth(), getHeight());
474 else if (miniMe != null)
476 g.drawImage(miniMe, 0, 0, this);
479 g.setColor(Color.red);
480 g.drawRect(boxX, boxY, boxWidth, boxHeight);
481 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);