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
19 package jalview.appletgui;
22 import java.awt.event.*;
24 public class OverviewPanel
25 extends Panel implements Runnable, MouseMotionListener, MouseListener
34 public int width, sequencesHeight;
36 int boxX = -1, boxY = -1, boxWidth = -1, boxHeight = -1;
38 boolean resizing = false;
40 // Can set different properties in this seqCanvas than
41 // main visible SeqCanvas
47 public OverviewPanel(AlignmentPanel ap)
52 nullFrame = new Frame();
53 nullFrame.addNotify();
55 sr = new SequenceRenderer(av);
56 sr.graphics = nullFrame.getGraphics();
57 sr.renderGaps = false;
58 sr.forOverview = true;
59 fr = new FeatureRenderer(av);
62 // scale the initial size of overviewpanel to shape of alignment
63 float initialScale = (float) av.alignment.getWidth() /
64 (float) av.alignment.getHeight();
66 if (av.hconsensus == null)
71 if (av.alignment.getWidth() > av.alignment.getHeight())
75 sequencesHeight = (int) (400f / initialScale);
76 if (sequencesHeight < 40)
84 width = (int) (400f * initialScale);
85 sequencesHeight = 300;
92 setSize(new Dimension(width, sequencesHeight + graphHeight));
93 addComponentListener(new ComponentAdapter()
96 public void componentResized(ComponentEvent evt)
98 if (getSize().width != width ||
99 getSize().height != sequencesHeight + graphHeight)
101 updateOverviewImage();
106 addMouseMotionListener(this);
108 addMouseListener(this);
110 updateOverviewImage();
114 public void mouseEntered(MouseEvent evt)
117 public void mouseExited(MouseEvent evt)
120 public void mouseClicked(MouseEvent evt)
123 public void mouseMoved(MouseEvent evt)
126 public void mousePressed(MouseEvent evt)
133 public void mouseReleased(MouseEvent evt)
140 public void mouseDragged(MouseEvent evt)
154 if (boxY > (sequencesHeight - boxHeight))
156 boxY = sequencesHeight - boxHeight + 1;
164 if (boxX > (width - boxWidth))
166 if (av.hasHiddenColumns)
168 //Try smallest possible box
169 boxWidth = (int) ( (av.endRes - av.startRes + 1) *
170 av.getCharWidth() * scalew);
172 boxX = width - boxWidth;
175 int col = (int) (boxX / scalew / av.getCharWidth());
176 int row = (int) (boxY / scaleh / av.getCharHeight());
178 if (av.hasHiddenColumns)
180 if (!av.getColumnSelection().isVisible(col))
185 col = av.getColumnSelection().findColumnPosition(col);
188 if (av.hasHiddenRows)
190 row = av.alignment.getHiddenSequences().findIndexWithoutHiddenSeqs(row);
193 ap.setScrollValues(col, row);
194 ap.paintAlignment(false);
200 public void updateOverviewImage()
208 if (av.showSequenceFeatures)
210 fr.featureGroups = ap.seqPanel.seqCanvas.getFeatureRenderer().
212 fr.featureColours = ap.seqPanel.seqCanvas.getFeatureRenderer().
218 if ( (getSize().width > 0) && (getSize().height > 0))
220 width = getSize().width;
221 sequencesHeight = getSize().height - graphHeight;
223 setSize(new Dimension(width, sequencesHeight + graphHeight));
225 Thread thread = new Thread(this);
230 // This is set true if the user resizes whilst
231 // the overview is being calculated
232 boolean resizeAgain = false;
237 int alwidth = av.alignment.getWidth();
238 int alheight = av.alignment.getHeight();
240 if (av.showSequenceFeatures)
242 fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer());
245 if (getSize().width > 0 && getSize().height > 0)
247 width = getSize().width;
248 sequencesHeight = getSize().height - graphHeight;
251 setSize(new Dimension(width, sequencesHeight + graphHeight));
253 int fullsizeWidth = alwidth * av.getCharWidth();
254 int fullsizeHeight = alheight * av.getCharHeight();
256 scalew = (float) width / (float) fullsizeWidth;
257 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
259 miniMe = nullFrame.createImage(width, sequencesHeight + graphHeight);
260 offscreen = nullFrame.createImage(width, sequencesHeight + graphHeight);
262 Graphics mg = miniMe.getGraphics();
263 float sampleCol = (float) alwidth / (float) width;
264 float sampleRow = (float) alheight / (float) sequencesHeight;
266 int lastcol = 0, lastrow = 0;
267 int xstart = 0, ystart = 0;
268 Color color = Color.yellow;
269 int row, col, sameRow = 0, sameCol = 0;
270 jalview.datamodel.SequenceI seq;
271 boolean hiddenRow = false;
272 for (row = 0; row <= sequencesHeight; row++)
274 if ( (int) (row * sampleRow) == lastrow)
281 if (av.hasHiddenRows)
283 seq = av.alignment.getHiddenSequences().getHiddenSequence(lastrow);
287 av.alignment.getHiddenSequences().findIndexWithoutHiddenSeqs(
290 seq = av.alignment.getSequenceAt(index);
299 seq = av.alignment.getSequenceAt(lastrow);
302 for (col = 0; col < width; col++)
304 if ( (int) (col * sampleCol) == lastcol &&
305 (int) (row * sampleRow) == lastrow)
311 lastcol = (int) (col * sampleCol);
313 if (seq.getLength() > lastcol)
315 color = sr.getResidueBoxColour(
318 if (av.showSequenceFeatures)
320 color = fr.findFeatureColour(color, seq, lastcol);
325 color = Color.white; //White
329 (av.hasHiddenColumns && !av.getColumnSelection().isVisible(lastcol)))
331 color = color.darker().darker();
335 if (sameCol == 1 && sameRow == 1)
337 mg.drawLine(xstart, ystart, xstart, ystart);
341 mg.fillRect(xstart, ystart, sameCol, sameRow);
347 lastrow = (int) (row * sampleRow);
352 if (av.conservation != null)
354 for (col = 0; col < width; col++)
356 lastcol = (int) (col * sampleCol);
358 mg.translate(col, sequencesHeight);
359 ap.annotationPanel.drawGraph(mg, av.conservation,
360 (int) (sampleCol) + 1,
362 (int) (col * sampleCol),
363 (int) (col * sampleCol) + 1);
364 mg.translate( -col, -sequencesHeight);
377 updateOverviewImage();
381 public void setBoxPosition()
383 int fullsizeWidth = av.alignment.getWidth() * av.getCharWidth();
384 int fullsizeHeight = (av.alignment.getHeight()
385 + av.alignment.getHiddenSequences().getSize()) *
388 int startRes = av.getStartRes();
389 int endRes = av.getEndRes();
391 if (av.hasHiddenColumns)
393 startRes = av.getColumnSelection().adjustForHiddenColumns(startRes);
394 endRes = av.getColumnSelection().adjustForHiddenColumns(endRes);
397 int startSeq = av.startSeq;
398 int endSeq = av.endSeq;
400 if (av.hasHiddenRows)
403 av.alignment.getHiddenSequences().adjustForHiddenSeqs(startSeq);
406 av.alignment.getHiddenSequences().adjustForHiddenSeqs(endSeq);
410 scalew = (float) width / (float) fullsizeWidth;
411 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
413 boxX = (int) (startRes * av.getCharWidth() * scalew);
414 boxY = (int) (startSeq * av.getCharHeight() * scaleh);
416 if (av.hasHiddenColumns)
418 boxWidth = (int) ( (endRes - startRes + 1) * av.getCharWidth() * scalew);
422 boxWidth = (int) ( (endRes - startRes + 1) * av.getCharWidth() * scalew);
425 boxHeight = (int) ( (endSeq - startSeq) * av.getCharHeight() * scaleh);
430 public void update(Graphics g)
435 public void paint(Graphics g)
437 Graphics og = offscreen.getGraphics();
440 og.drawImage(miniMe, 0, 0, this);
441 og.setColor(Color.red);
442 og.drawRect(boxX, boxY, boxWidth, boxHeight);
443 og.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
444 g.drawImage(offscreen, 0, 0, this);