2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 import java.awt.event.*;
23 import java.awt.image.*;
32 public class OverviewPanel extends JPanel implements Runnable
58 boolean resizing = false;
60 // Can set different properties in this seqCanvas than
61 // main visible SeqCanvas
67 * Creates a new OverviewPanel object.
72 public OverviewPanel(AlignmentPanel ap)
78 sr = new SequenceRenderer(av);
79 sr.renderGaps = false;
80 sr.forOverview = true;
81 fr = new FeatureRenderer(ap);
83 // scale the initial size of overviewpanel to shape of alignment
84 float initialScale = (float) av.alignment.getWidth()
85 / (float) av.alignment.getHeight();
87 if (av.conservation == null)
92 if (av.alignment.getWidth() > av.alignment.getHeight())
96 sequencesHeight = (int) (400f / initialScale);
97 if (sequencesHeight < 40)
105 width = (int) (400f * initialScale);
106 sequencesHeight = 300;
114 addComponentListener(new ComponentAdapter()
116 public void componentResized(ComponentEvent evt)
118 if ((getWidth() != width)
119 || (getHeight() != (sequencesHeight + graphHeight)))
121 updateOverviewImage();
126 addMouseMotionListener(new MouseMotionAdapter()
128 public void mouseDragged(MouseEvent evt)
130 if (!av.wrapAlignment)
139 addMouseListener(new MouseAdapter()
141 public void mousePressed(MouseEvent evt)
143 if (!av.wrapAlignment)
152 updateOverviewImage();
165 if (boxY > (sequencesHeight - boxHeight))
167 boxY = sequencesHeight - boxHeight + 1;
175 if (boxX > (width - boxWidth))
177 if (av.hasHiddenColumns)
179 // Try smallest possible box
180 boxWidth = (int) ((av.endRes - av.startRes + 1) * av.getCharWidth() * scalew);
182 boxX = width - boxWidth;
185 int col = (int) (boxX / scalew / av.getCharWidth());
186 int row = (int) (boxY / scaleh / av.getCharHeight());
188 if (av.hasHiddenColumns)
190 if (!av.getColumnSelection().isVisible(col))
195 col = av.getColumnSelection().findColumnPosition(col);
198 if (av.hasHiddenRows)
200 row = av.alignment.getHiddenSequences().findIndexWithoutHiddenSeqs(
204 ap.setScrollValues(col, row);
211 public void updateOverviewImage()
221 if ((getWidth() > 0) && (getHeight() > 0))
224 sequencesHeight = getHeight() - graphHeight;
227 setPreferredSize(new Dimension(width, sequencesHeight + graphHeight));
229 Thread thread = new Thread(this);
234 // This is set true if the user resizes whilst
235 // the overview is being calculated
236 boolean resizeAgain = false;
245 if (av.showSequenceFeatures)
247 fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer());
250 int alwidth = av.alignment.getWidth();
251 int alheight = av.alignment.getHeight()
252 + av.alignment.getHiddenSequences().getSize();
254 setPreferredSize(new Dimension(width, sequencesHeight + graphHeight));
256 int fullsizeWidth = alwidth * av.getCharWidth();
257 int fullsizeHeight = alheight * av.getCharHeight();
259 scalew = (float) width / (float) fullsizeWidth;
260 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
262 miniMe = new BufferedImage(width, sequencesHeight + graphHeight,
263 BufferedImage.TYPE_INT_RGB);
265 Graphics mg = miniMe.getGraphics();
266 mg.setColor(Color.orange);
267 mg.fillRect(0, 0, width, miniMe.getHeight());
269 float sampleCol = (float) alwidth / (float) width;
270 float sampleRow = (float) alheight / (float) sequencesHeight;
272 int lastcol = -1, lastrow = -1;
273 int color = Color.white.getRGB();
275 jalview.datamodel.SequenceI seq;
276 boolean hiddenRow = false;
277 for (row = 0; row < sequencesHeight; row++)
279 if ((int) (row * sampleRow) == lastrow)
281 // No need to recalculate the colours,
282 // Just copy from the row above
283 for (col = 0; col < width; col++)
285 miniMe.setRGB(col, row, miniMe.getRGB(col, row - 1));
290 lastrow = (int) (row * sampleRow);
293 if (av.hasHiddenRows)
295 seq = av.alignment.getHiddenSequences().getHiddenSequence(lastrow);
298 int index = av.alignment.getHiddenSequences()
299 .findIndexWithoutHiddenSeqs(lastrow);
301 seq = av.alignment.getSequenceAt(index);
310 seq = av.alignment.getSequenceAt(lastrow);
315 System.out.println(lastrow + " null");
319 for (col = 0; col < width; col++)
321 if ((int) (col * sampleCol) == lastcol
322 && (int) (row * sampleRow) == lastrow)
324 miniMe.setRGB(col, row, color);
328 lastcol = (int) (col * sampleCol);
330 if (seq.getLength() > lastcol)
332 color = sr.getResidueBoxColour(seq, lastcol).getRGB();
334 if (av.showSequenceFeatures)
336 color = fr.findFeatureColour(color, seq, lastcol);
345 || (av.hasHiddenColumns && !av.getColumnSelection()
346 .isVisible(lastcol)))
348 color = new Color(color).darker().darker().getRGB();
351 miniMe.setRGB(col, row, color);
356 if (av.conservation != null)
358 for (col = 0; col < width; col++)
360 lastcol = (int) (col * sampleCol);
362 mg.translate(col, sequencesHeight);
363 ap.annotationPanel.drawGraph(mg, av.conservation,
364 (int) (sampleCol) + 1, graphHeight,
365 (int) (col * sampleCol), (int) (col * sampleCol) + 1);
366 mg.translate(-col, -sequencesHeight);
379 updateOverviewImage();
386 public void setBoxPosition()
388 int fullsizeWidth = av.alignment.getWidth() * av.getCharWidth();
389 int fullsizeHeight = (av.alignment.getHeight() + av.alignment
390 .getHiddenSequences().getSize())
391 * 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);