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 extends Panel implements Runnable,
25 MouseMotionListener, MouseListener
39 public int width, sequencesHeight;
43 int boxX = -1, boxY = -1, boxWidth = -1, boxHeight = -1;
45 boolean resizing = false;
47 // Can set different properties in this seqCanvas than
48 // main visible SeqCanvas
55 public OverviewPanel(AlignmentPanel ap)
60 nullFrame = new Frame();
61 nullFrame.addNotify();
63 sr = new SequenceRenderer(av);
64 sr.graphics = nullFrame.getGraphics();
65 sr.renderGaps = false;
66 sr.forOverview = true;
67 fr = new FeatureRenderer(av);
70 // scale the initial size of overviewpanel to shape of alignment
71 float initialScale = (float) av.alignment.getWidth()
72 / (float) av.alignment.getHeight();
74 if (av.hconsensus == null)
79 if (av.alignment.getWidth() > av.alignment.getHeight())
83 sequencesHeight = (int) (400f / initialScale);
84 if (sequencesHeight < 40)
92 width = (int) (400f * initialScale);
93 sequencesHeight = 300;
100 setSize(new Dimension(width, sequencesHeight + graphHeight));
101 addComponentListener(new ComponentAdapter()
104 public void componentResized(ComponentEvent evt)
106 if (getSize().width != width
107 || getSize().height != sequencesHeight + graphHeight)
109 updateOverviewImage();
114 addMouseMotionListener(this);
116 addMouseListener(this);
118 updateOverviewImage();
122 public void mouseEntered(MouseEvent evt)
126 public void mouseExited(MouseEvent evt)
130 public void mouseClicked(MouseEvent evt)
134 public void mouseMoved(MouseEvent evt)
138 public void mousePressed(MouseEvent evt)
145 public void mouseReleased(MouseEvent evt)
152 public void mouseDragged(MouseEvent evt)
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);
206 ap.paintAlignment(false);
212 public void updateOverviewImage()
220 if (av.showSequenceFeatures)
222 fr.featureGroups = ap.seqPanel.seqCanvas.getFeatureRenderer().featureGroups;
223 fr.featureColours = ap.seqPanel.seqCanvas.getFeatureRenderer().featureColours;
228 if ((getSize().width > 0) && (getSize().height > 0))
230 width = getSize().width;
231 sequencesHeight = getSize().height - graphHeight;
233 setSize(new Dimension(width, sequencesHeight + graphHeight));
235 Thread thread = new Thread(this);
240 // This is set true if the user resizes whilst
241 // the overview is being calculated
242 boolean resizeAgain = false;
247 int alwidth = av.alignment.getWidth();
248 int alheight = av.alignment.getHeight();
250 if (av.showSequenceFeatures)
252 fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer());
255 if (getSize().width > 0 && getSize().height > 0)
257 width = getSize().width;
258 sequencesHeight = getSize().height - graphHeight;
261 setSize(new Dimension(width, sequencesHeight + graphHeight));
263 int fullsizeWidth = alwidth * av.getCharWidth();
264 int fullsizeHeight = alheight * av.getCharHeight();
266 scalew = (float) width / (float) fullsizeWidth;
267 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
269 miniMe = nullFrame.createImage(width, sequencesHeight + graphHeight);
270 offscreen = nullFrame.createImage(width, sequencesHeight + graphHeight);
272 Graphics mg = miniMe.getGraphics();
273 float sampleCol = (float) alwidth / (float) width;
274 float sampleRow = (float) alheight / (float) sequencesHeight;
276 int lastcol = 0, lastrow = 0;
277 int xstart = 0, ystart = 0;
278 Color color = Color.yellow;
279 int row, col, sameRow = 0, sameCol = 0;
280 jalview.datamodel.SequenceI seq;
281 boolean hiddenRow = false;
282 for (row = 0; row <= sequencesHeight; row++)
284 if ((int) (row * sampleRow) == lastrow)
291 if (av.hasHiddenRows)
293 seq = av.alignment.getHiddenSequences().getHiddenSequence(lastrow);
296 int index = av.alignment.getHiddenSequences()
297 .findIndexWithoutHiddenSeqs(lastrow);
299 seq = av.alignment.getSequenceAt(index);
308 seq = av.alignment.getSequenceAt(lastrow);
311 for (col = 0; col < width; col++)
313 if ((int) (col * sampleCol) == lastcol
314 && (int) (row * sampleRow) == lastrow)
320 lastcol = (int) (col * sampleCol);
322 if (seq.getLength() > lastcol)
324 color = sr.getResidueBoxColour(seq, lastcol);
326 if (av.showSequenceFeatures)
328 color = fr.findFeatureColour(color, seq, lastcol);
333 color = Color.white; // White
337 || (av.hasHiddenColumns && !av.getColumnSelection()
338 .isVisible(lastcol)))
340 color = color.darker().darker();
344 if (sameCol == 1 && sameRow == 1)
346 mg.drawLine(xstart, ystart, xstart, ystart);
350 mg.fillRect(xstart, ystart, sameCol, sameRow);
356 lastrow = (int) (row * sampleRow);
361 if (av.conservation != null)
363 for (col = 0; col < width; col++)
365 lastcol = (int) (col * sampleCol);
367 mg.translate(col, sequencesHeight);
368 ap.annotationPanel.drawGraph(mg, av.conservation,
369 (int) (sampleCol) + 1, graphHeight,
370 (int) (col * sampleCol), (int) (col * sampleCol) + 1);
371 mg.translate(-col, -sequencesHeight);
384 updateOverviewImage();
388 public void setBoxPosition()
390 int fullsizeWidth = av.alignment.getWidth() * av.getCharWidth();
391 int fullsizeHeight = (av.alignment.getHeight() + av.alignment
392 .getHiddenSequences().getSize())
393 * av.getCharHeight();
395 int startRes = av.getStartRes();
396 int endRes = av.getEndRes();
398 if (av.hasHiddenColumns)
400 startRes = av.getColumnSelection().adjustForHiddenColumns(startRes);
401 endRes = av.getColumnSelection().adjustForHiddenColumns(endRes);
404 int startSeq = av.startSeq;
405 int endSeq = av.endSeq;
407 if (av.hasHiddenRows)
409 startSeq = av.alignment.getHiddenSequences().adjustForHiddenSeqs(
412 endSeq = av.alignment.getHiddenSequences()
413 .adjustForHiddenSeqs(endSeq);
417 scalew = (float) width / (float) fullsizeWidth;
418 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
420 boxX = (int) (startRes * av.getCharWidth() * scalew);
421 boxY = (int) (startSeq * av.getCharHeight() * scaleh);
423 if (av.hasHiddenColumns)
425 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
429 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
432 boxHeight = (int) ((endSeq - startSeq) * av.getCharHeight() * scaleh);
437 public void update(Graphics g)
442 public void paint(Graphics g)
444 Graphics og = offscreen.getGraphics();
447 og.drawImage(miniMe, 0, 0, this);
448 og.setColor(Color.red);
449 og.drawRect(boxX, boxY, boxWidth, boxHeight);
450 og.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
451 g.drawImage(offscreen, 0, 0, this);