2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, 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/>.
21 import java.awt.event.*;
22 import java.awt.image.*;
31 public class OverviewPanel extends JPanel implements Runnable
57 boolean resizing = false;
59 // Can set different properties in this seqCanvas than
60 // main visible SeqCanvas
66 * Creates a new OverviewPanel object.
71 public OverviewPanel(AlignmentPanel ap)
77 sr = new SequenceRenderer(av);
78 sr.renderGaps = false;
79 sr.forOverview = true;
80 fr = new FeatureRenderer(ap);
82 // scale the initial size of overviewpanel to shape of alignment
83 float initialScale = (float) av.alignment.getWidth()
84 / (float) av.alignment.getHeight();
86 if (av.conservation == null)
91 if (av.alignment.getWidth() > av.alignment.getHeight())
95 sequencesHeight = (int) (400f / initialScale);
96 if (sequencesHeight < 40)
104 width = (int) (400f * initialScale);
105 sequencesHeight = 300;
113 addComponentListener(new ComponentAdapter()
115 public void componentResized(ComponentEvent evt)
117 if ((getWidth() != width)
118 || (getHeight() != (sequencesHeight + graphHeight)))
120 updateOverviewImage();
125 addMouseMotionListener(new MouseMotionAdapter()
127 public void mouseDragged(MouseEvent evt)
129 if (!av.wrapAlignment)
131 // TODO: feature: jv2.5 detect shift drag and update selection from
140 addMouseListener(new MouseAdapter()
142 public void mousePressed(MouseEvent evt)
144 if (!av.wrapAlignment)
153 updateOverviewImage();
166 if (boxY > (sequencesHeight - boxHeight))
168 boxY = sequencesHeight - boxHeight + 1;
176 if (boxX > (width - boxWidth))
178 if (av.hasHiddenColumns)
180 // Try smallest possible box
181 boxWidth = (int) ((av.endRes - av.startRes + 1) * av.getCharWidth() * scalew);
183 boxX = width - boxWidth;
186 int col = (int) (boxX / scalew / av.getCharWidth());
187 int row = (int) (boxY / scaleh / av.getCharHeight());
189 if (av.hasHiddenColumns)
191 if (!av.getColumnSelection().isVisible(col))
196 col = av.getColumnSelection().findColumnPosition(col);
199 if (av.hasHiddenRows)
201 row = av.alignment.getHiddenSequences().findIndexWithoutHiddenSeqs(
205 ap.setScrollValues(col, row);
212 public void updateOverviewImage()
222 if ((getWidth() > 0) && (getHeight() > 0))
225 sequencesHeight = getHeight() - graphHeight;
228 setPreferredSize(new Dimension(width, sequencesHeight + graphHeight));
230 Thread thread = new Thread(this);
235 // This is set true if the user resizes whilst
236 // the overview is being calculated
237 boolean resizeAgain = false;
246 if (av.showSequenceFeatures)
248 fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer());
251 int alwidth = av.alignment.getWidth();
252 int alheight = av.alignment.getHeight()
253 + av.alignment.getHiddenSequences().getSize();
255 setPreferredSize(new Dimension(width, sequencesHeight + graphHeight));
257 int fullsizeWidth = alwidth * av.getCharWidth();
258 int fullsizeHeight = alheight * av.getCharHeight();
260 scalew = (float) width / (float) fullsizeWidth;
261 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
263 miniMe = new BufferedImage(width, sequencesHeight + graphHeight,
264 BufferedImage.TYPE_INT_RGB);
266 Graphics mg = miniMe.getGraphics();
267 mg.setColor(Color.orange);
268 mg.fillRect(0, 0, width, miniMe.getHeight());
270 float sampleCol = (float) alwidth / (float) width;
271 float sampleRow = (float) alheight / (float) sequencesHeight;
273 int lastcol = -1, lastrow = -1;
274 int color = Color.white.getRGB();
276 jalview.datamodel.SequenceI seq;
277 boolean hiddenRow = false;
278 for (row = 0; row < sequencesHeight; row++)
280 if ((int) (row * sampleRow) == lastrow)
282 // No need to recalculate the colours,
283 // Just copy from the row above
284 for (col = 0; col < width; col++)
286 miniMe.setRGB(col, row, miniMe.getRGB(col, row - 1));
291 lastrow = (int) (row * sampleRow);
294 if (av.hasHiddenRows)
296 seq = av.alignment.getHiddenSequences().getHiddenSequence(lastrow);
299 int index = av.alignment.getHiddenSequences()
300 .findIndexWithoutHiddenSeqs(lastrow);
302 seq = av.alignment.getSequenceAt(index);
311 seq = av.alignment.getSequenceAt(lastrow);
316 System.out.println(lastrow + " null");
320 for (col = 0; col < width; col++)
322 if ((int) (col * sampleCol) == lastcol
323 && (int) (row * sampleRow) == lastrow)
325 miniMe.setRGB(col, row, color);
329 lastcol = (int) (col * sampleCol);
331 if (seq.getLength() > lastcol)
333 color = sr.getResidueBoxColour(seq, lastcol).getRGB();
335 if (av.showSequenceFeatures)
337 color = fr.findFeatureColour(color, seq, lastcol);
346 || (av.hasHiddenColumns && !av.getColumnSelection()
347 .isVisible(lastcol)))
349 color = new Color(color).darker().darker().getRGB();
352 miniMe.setRGB(col, row, color);
357 if (av.conservation != null)
359 for (col = 0; col < width; col++)
361 lastcol = (int) (col * sampleCol);
363 mg.translate(col, sequencesHeight);
364 ap.annotationPanel.drawGraph(mg, av.conservation,
365 (int) (sampleCol) + 1, graphHeight,
366 (int) (col * sampleCol), (int) (col * sampleCol) + 1);
367 mg.translate(-col, -sequencesHeight);
380 updateOverviewImage();
387 public void setBoxPosition()
389 int fullsizeWidth = av.alignment.getWidth() * av.getCharWidth();
390 int fullsizeHeight = (av.alignment.getHeight() + av.alignment
391 .getHiddenSequences().getSize()) * av.getCharHeight();
393 int startRes = av.getStartRes();
394 int endRes = av.getEndRes();
396 if (av.hasHiddenColumns)
398 startRes = av.getColumnSelection().adjustForHiddenColumns(startRes);
399 endRes = av.getColumnSelection().adjustForHiddenColumns(endRes);
402 int startSeq = av.startSeq;
403 int endSeq = av.endSeq;
405 if (av.hasHiddenRows)
407 startSeq = av.alignment.getHiddenSequences().adjustForHiddenSeqs(
410 endSeq = av.alignment.getHiddenSequences()
411 .adjustForHiddenSeqs(endSeq);
415 scalew = (float) width / (float) fullsizeWidth;
416 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
418 boxX = (int) (startRes * av.getCharWidth() * scalew);
419 boxY = (int) (startSeq * av.getCharHeight() * scaleh);
421 if (av.hasHiddenColumns)
423 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
427 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
430 boxHeight = (int) ((endSeq - startSeq) * av.getCharHeight() * scaleh);
441 public void paintComponent(Graphics g)
445 g.setColor(Color.white);
446 g.fillRect(0, 0, getWidth(), getHeight());
448 else if (miniMe != null)
450 g.drawImage(miniMe, 0, 0, this);
453 g.setColor(Color.red);
454 g.drawRect(boxX, boxY, boxWidth, boxHeight);
455 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);