2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5.1)
3 * Copyright (C) 2010 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/>.
18 package jalview.appletgui;
21 import java.awt.event.*;
23 public class OverviewPanel extends Panel implements Runnable,
24 MouseMotionListener, MouseListener
38 public int width, sequencesHeight;
42 int boxX = -1, boxY = -1, boxWidth = -1, boxHeight = -1;
44 boolean resizing = false;
46 // Can set different properties in this seqCanvas than
47 // main visible SeqCanvas
54 public OverviewPanel(AlignmentPanel ap)
59 nullFrame = new Frame();
60 nullFrame.addNotify();
62 sr = new SequenceRenderer(av);
63 sr.graphics = nullFrame.getGraphics();
64 sr.renderGaps = false;
65 sr.forOverview = true;
66 fr = new FeatureRenderer(av);
69 // scale the initial size of overviewpanel to shape of alignment
70 float initialScale = (float) av.alignment.getWidth()
71 / (float) av.alignment.getHeight();
73 if (av.hconsensus == null)
78 if (av.alignment.getWidth() > av.alignment.getHeight())
82 sequencesHeight = (int) (400f / initialScale);
83 if (sequencesHeight < 40)
91 width = (int) (400f * initialScale);
92 sequencesHeight = 300;
99 setSize(new Dimension(width, sequencesHeight + graphHeight));
100 addComponentListener(new ComponentAdapter()
103 public void componentResized(ComponentEvent evt)
105 if (getSize().width != width
106 || getSize().height != sequencesHeight + graphHeight)
108 updateOverviewImage();
113 addMouseMotionListener(this);
115 addMouseListener(this);
117 updateOverviewImage();
121 public void mouseEntered(MouseEvent evt)
125 public void mouseExited(MouseEvent evt)
129 public void mouseClicked(MouseEvent evt)
133 public void mouseMoved(MouseEvent evt)
137 public void mousePressed(MouseEvent evt)
144 public void mouseReleased(MouseEvent evt)
151 public void mouseDragged(MouseEvent evt)
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);
205 ap.paintAlignment(false);
211 public void updateOverviewImage()
219 if (av.showSequenceFeatures)
221 fr.featureGroups = ap.seqPanel.seqCanvas.getFeatureRenderer().featureGroups;
222 fr.featureColours = ap.seqPanel.seqCanvas.getFeatureRenderer().featureColours;
227 if ((getSize().width > 0) && (getSize().height > 0))
229 width = getSize().width;
230 sequencesHeight = getSize().height - graphHeight;
232 setSize(new Dimension(width, sequencesHeight + graphHeight));
234 Thread thread = new Thread(this);
239 // This is set true if the user resizes whilst
240 // the overview is being calculated
241 boolean resizeAgain = false;
246 int alwidth = av.alignment.getWidth();
247 int alheight = av.alignment.getHeight();
249 if (av.showSequenceFeatures)
251 fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer());
254 if (getSize().width > 0 && getSize().height > 0)
256 width = getSize().width;
257 sequencesHeight = getSize().height - graphHeight;
260 setSize(new Dimension(width, sequencesHeight + graphHeight));
262 int fullsizeWidth = alwidth * av.getCharWidth();
263 int fullsizeHeight = alheight * av.getCharHeight();
265 scalew = (float) width / (float) fullsizeWidth;
266 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
268 miniMe = nullFrame.createImage(width, sequencesHeight + graphHeight);
269 offscreen = nullFrame.createImage(width, sequencesHeight + graphHeight);
271 Graphics mg = miniMe.getGraphics();
272 float sampleCol = (float) alwidth / (float) width;
273 float sampleRow = (float) alheight / (float) sequencesHeight;
275 int lastcol = 0, lastrow = 0;
276 int xstart = 0, ystart = 0;
277 Color color = Color.yellow;
278 int row, col, sameRow = 0, sameCol = 0;
279 jalview.datamodel.SequenceI seq;
280 boolean hiddenRow = false;
281 for (row = 0; row <= sequencesHeight; row++)
283 if ((int) (row * sampleRow) == lastrow)
290 if (av.hasHiddenRows)
292 seq = av.alignment.getHiddenSequences().getHiddenSequence(lastrow);
295 int index = av.alignment.getHiddenSequences()
296 .findIndexWithoutHiddenSeqs(lastrow);
298 seq = av.alignment.getSequenceAt(index);
307 seq = av.alignment.getSequenceAt(lastrow);
310 for (col = 0; col < width; col++)
312 if ((int) (col * sampleCol) == lastcol
313 && (int) (row * sampleRow) == lastrow)
319 lastcol = (int) (col * sampleCol);
321 if (seq.getLength() > lastcol)
323 color = sr.getResidueBoxColour(seq, lastcol);
325 if (av.showSequenceFeatures)
327 color = fr.findFeatureColour(color, seq, lastcol);
332 color = Color.white; // White
336 || (av.hasHiddenColumns && !av.getColumnSelection()
337 .isVisible(lastcol)))
339 color = color.darker().darker();
343 if (sameCol == 1 && sameRow == 1)
345 mg.drawLine(xstart, ystart, xstart, ystart);
349 mg.fillRect(xstart, ystart, sameCol, sameRow);
355 lastrow = (int) (row * sampleRow);
360 if (av.conservation != null)
362 for (col = 0; col < width; col++)
364 lastcol = (int) (col * sampleCol);
366 mg.translate(col, sequencesHeight);
367 ap.annotationPanel.drawGraph(mg, av.conservation,
368 (int) (sampleCol) + 1, graphHeight,
369 (int) (col * sampleCol), (int) (col * sampleCol) + 1);
370 mg.translate(-col, -sequencesHeight);
383 updateOverviewImage();
387 public void setBoxPosition()
389 int fullsizeWidth = av.alignment.getWidth() * av.getCharWidth();
390 int fullsizeHeight = (av.alignment.getHeight() + av.alignment
391 .getHiddenSequences().getSize())
392 * av.getCharHeight();
394 int startRes = av.getStartRes();
395 int endRes = av.getEndRes();
397 if (av.hasHiddenColumns)
399 startRes = av.getColumnSelection().adjustForHiddenColumns(startRes);
400 endRes = av.getColumnSelection().adjustForHiddenColumns(endRes);
403 int startSeq = av.startSeq;
404 int endSeq = av.endSeq;
406 if (av.hasHiddenRows)
408 startSeq = av.alignment.getHiddenSequences().adjustForHiddenSeqs(
411 endSeq = av.alignment.getHiddenSequences()
412 .adjustForHiddenSeqs(endSeq);
416 scalew = (float) width / (float) fullsizeWidth;
417 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
419 boxX = (int) (startRes * av.getCharWidth() * scalew);
420 boxY = (int) (startSeq * av.getCharHeight() * scaleh);
422 if (av.hasHiddenColumns)
424 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
428 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
431 boxHeight = (int) ((endSeq - startSeq) * av.getCharHeight() * scaleh);
436 public void update(Graphics g)
441 public void paint(Graphics g)
443 Graphics og = offscreen.getGraphics();
446 og.drawImage(miniMe, 0, 0, this);
447 og.setColor(Color.red);
448 og.drawRect(boxX, boxY, boxWidth, boxHeight);
449 og.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
450 g.drawImage(offscreen, 0, 0, this);