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
33 extends JPanel implements Runnable
47 boolean resizing = false;
49 // Can set different properties in this seqCanvas than
50 // main visible SeqCanvas
55 * Creates a new OverviewPanel object.
57 * @param ap DOCUMENT ME!
59 public OverviewPanel(AlignmentPanel ap)
65 sr = new SequenceRenderer(av);
66 sr.renderGaps = false;
67 sr.forOverview = true;
68 fr = new FeatureRenderer(ap);
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.conservation == 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;
101 addComponentListener(new ComponentAdapter()
103 public void componentResized(ComponentEvent evt)
105 if ( (getWidth() != width) ||
106 (getHeight() != (sequencesHeight + graphHeight)))
108 updateOverviewImage();
113 addMouseMotionListener(new MouseMotionAdapter()
115 public void mouseDragged(MouseEvent evt)
117 if (!av.wrapAlignment)
126 addMouseListener(new MouseAdapter()
128 public void mousePressed(MouseEvent evt)
130 if (!av.wrapAlignment)
139 updateOverviewImage();
152 if (boxY > (sequencesHeight - boxHeight))
154 boxY = sequencesHeight - boxHeight + 1;
162 if (boxX > (width - boxWidth))
164 if (av.hasHiddenColumns)
166 //Try smallest possible box
167 boxWidth = (int) ( (av.endRes - av.startRes + 1) *
168 av.getCharWidth() * scalew);
170 boxX = width - boxWidth;
173 int col = (int) (boxX / scalew / av.getCharWidth());
174 int row = (int) (boxY / scaleh / av.getCharHeight());
176 if (av.hasHiddenColumns)
178 if (!av.getColumnSelection().isVisible(col))
183 col = av.getColumnSelection().findColumnPosition(col);
186 if (av.hasHiddenRows)
188 row = av.alignment.getHiddenSequences().findIndexWithoutHiddenSeqs(row);
191 ap.setScrollValues(col, row);
198 public void updateOverviewImage()
208 if ( (getWidth() > 0) && (getHeight() > 0))
211 sequencesHeight = getHeight() - graphHeight;
214 setPreferredSize(new Dimension(width, sequencesHeight + graphHeight));
216 Thread thread = new Thread(this);
221 // This is set true if the user resizes whilst
222 // the overview is being calculated
223 boolean resizeAgain = false;
232 if (av.showSequenceFeatures)
234 fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer());
237 int alwidth = av.alignment.getWidth();
238 int alheight = av.alignment.getHeight()
239 + av.alignment.getHiddenSequences().getSize();
241 setPreferredSize(new Dimension(width, sequencesHeight + graphHeight));
243 int fullsizeWidth = alwidth * av.getCharWidth();
244 int fullsizeHeight = alheight * av.getCharHeight();
246 scalew = (float) width / (float) fullsizeWidth;
247 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
249 miniMe = new BufferedImage(width, sequencesHeight + graphHeight,
250 BufferedImage.TYPE_INT_RGB);
252 Graphics mg = miniMe.getGraphics();
253 mg.setColor(Color.orange);
254 mg.fillRect(0, 0, width, miniMe.getHeight());
256 float sampleCol = (float) alwidth / (float) width;
257 float sampleRow = (float) alheight / (float) sequencesHeight;
259 int lastcol = -1, lastrow = -1;
260 int color = Color.white.getRGB();
262 jalview.datamodel.SequenceI seq;
263 boolean hiddenRow = false;
264 for (row = 0; row < sequencesHeight; row++)
266 if ( (int) (row * sampleRow) == lastrow)
268 //No need to recalculate the colours,
269 //Just copy from the row above
270 for (col = 0; col < width; col++)
272 miniMe.setRGB(col, row, miniMe.getRGB(col, row - 1));
277 lastrow = (int) (row * sampleRow);
280 if (av.hasHiddenRows)
282 seq = av.alignment.getHiddenSequences().getHiddenSequence(lastrow);
286 av.alignment.getHiddenSequences().findIndexWithoutHiddenSeqs(
289 seq = av.alignment.getSequenceAt(index);
298 seq = av.alignment.getSequenceAt(lastrow);
303 System.out.println(lastrow + " null");
307 for (col = 0; col < width; col++)
309 if ( (int) (col * sampleCol) == lastcol &&
310 (int) (row * sampleRow) == lastrow)
312 miniMe.setRGB(col, row, color);
316 lastcol = (int) (col * sampleCol);
318 if (seq.getLength() > lastcol)
320 color = sr.getResidueBoxColour(
321 seq, lastcol).getRGB();
323 if (av.showSequenceFeatures)
325 color = fr.findFeatureColour(color, seq, lastcol);
334 (av.hasHiddenColumns && !av.getColumnSelection().isVisible(lastcol)))
336 color = new Color(color).darker().darker().getRGB();
339 miniMe.setRGB(col, row, color);
344 if (av.conservation != null)
346 for (col = 0; col < width; col++)
348 lastcol = (int) (col * sampleCol);
350 mg.translate(col, sequencesHeight);
351 ap.annotationPanel.drawGraph(mg, av.conservation,
352 (int) (sampleCol) + 1,
354 (int) (col * sampleCol),
355 (int) (col * sampleCol) + 1);
356 mg.translate( -col, -sequencesHeight);
369 updateOverviewImage();
376 public void setBoxPosition()
378 int fullsizeWidth = av.alignment.getWidth() * av.getCharWidth();
379 int fullsizeHeight = (av.alignment.getHeight()
380 + av.alignment.getHiddenSequences().getSize()) *
383 int startRes = av.getStartRes();
384 int endRes = av.getEndRes();
386 if (av.hasHiddenColumns)
388 startRes = av.getColumnSelection().adjustForHiddenColumns(startRes);
389 endRes = av.getColumnSelection().adjustForHiddenColumns(endRes);
392 int startSeq = av.startSeq;
393 int endSeq = av.endSeq;
395 if (av.hasHiddenRows)
398 av.alignment.getHiddenSequences().adjustForHiddenSeqs(startSeq);
401 av.alignment.getHiddenSequences().adjustForHiddenSeqs(endSeq);
405 scalew = (float) width / (float) fullsizeWidth;
406 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
408 boxX = (int) (startRes * av.getCharWidth() * scalew);
409 boxY = (int) (startSeq * av.getCharHeight() * scaleh);
411 if (av.hasHiddenColumns)
413 boxWidth = (int) ( (endRes - startRes + 1) * av.getCharWidth() * scalew);
417 boxWidth = (int) ( (endRes - startRes + 1) * av.getCharWidth() * scalew);
420 boxHeight = (int) ( (endSeq - startSeq) * av.getCharHeight() * scaleh);
428 * @param g DOCUMENT ME!
430 public void paintComponent(Graphics g)
434 g.setColor(Color.white);
435 g.fillRect(0,0,getWidth(),getHeight());
437 else if (miniMe != null)
439 g.drawImage(miniMe, 0, 0, this);
442 g.setColor(Color.red);
443 g.drawRect(boxX, boxY, boxWidth, boxHeight);
444 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);