2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.gui;
\r
22 import java.awt.event.*;
\r
23 import java.awt.image.*;
\r
25 import javax.swing.*;
\r
32 * @version $Revision$
\r
34 public class OverviewPanel extends JPanel implements Runnable
\r
36 BufferedImage miniMe;
\r
42 int sequencesHeight;
\r
43 int graphHeight = 20;
\r
48 boolean resizing = false;
\r
50 // Can set different properties in this seqCanvas than
\r
51 // main visible SeqCanvas
\r
52 SequenceRenderer sr;
\r
56 * Creates a new OverviewPanel object.
\r
58 * @param ap DOCUMENT ME!
\r
60 public OverviewPanel(AlignmentPanel ap)
\r
66 sr = new SequenceRenderer(av);
\r
67 sr.renderGaps = false;
\r
68 sr.forOverview = true;
\r
69 fr = new FeatureRenderer(av);
\r
71 // scale the initial size of overviewpanel to shape of alignment
\r
72 float initialScale = (float) av.alignment.getWidth() / (float) av.alignment.getHeight();
\r
74 if(av.conservation==null)
\r
78 if (av.alignment.getWidth() > av.alignment.getHeight())
\r
82 sequencesHeight = (int) (400f / initialScale);
\r
83 if(sequencesHeight<40)
\r
84 sequencesHeight = 40;
\r
89 width = (int) (400f * initialScale);
\r
90 sequencesHeight = 300;
\r
98 addComponentListener(new ComponentAdapter()
\r
100 public void componentResized(ComponentEvent evt)
\r
102 if ((getWidth() != width) ||
\r
103 (getHeight() != (sequencesHeight + graphHeight)))
\r
105 updateOverviewImage();
\r
110 addMouseMotionListener(new MouseMotionAdapter()
\r
112 public void mouseDragged(MouseEvent evt)
\r
114 if (!av.wrapAlignment)
\r
123 addMouseListener(new MouseAdapter()
\r
125 public void mousePressed(MouseEvent evt)
\r
127 if(!av.wrapAlignment)
\r
136 updateOverviewImage();
\r
150 if (boxY > (sequencesHeight - boxHeight))
\r
152 boxY = sequencesHeight - boxHeight + 1;
\r
160 if (boxX > (width - boxWidth))
\r
162 if(av.hasHiddenColumns)
\r
164 //Try smallest possible box
\r
165 boxWidth = (int) ( (av.endRes - av.startRes + 1) *
\r
166 av.getCharWidth() * scalew);
\r
168 boxX = width - boxWidth;
\r
171 int col = (int) (boxX / scalew / av.getCharWidth());
\r
172 int row = (int) (boxY / scaleh / av.getCharHeight());
\r
174 if (av.hasHiddenColumns)
\r
176 if (!av.getColumnSelection().isVisible(col))
\r
181 col = av.getColumnSelection().findColumnPosition(col);
\r
184 if( av.hasHiddenRows )
\r
186 row = av.alignment.getHiddenSequences().findIndexWithoutHiddenSeqs(row);
\r
189 ap.setScrollValues( col, row );
\r
196 public void updateOverviewImage()
\r
200 resizeAgain = true;
\r
206 if ( (getWidth() > 0) && (getHeight() > 0))
\r
208 width = getWidth();
\r
209 sequencesHeight = getHeight() - graphHeight;
\r
212 setPreferredSize(new Dimension(width, sequencesHeight + graphHeight));
\r
214 Thread thread = new Thread(this);
\r
219 // This is set true if the user resizes whilst
\r
220 // the overview is being calculated
\r
221 boolean resizeAgain = false;
\r
230 if (av.showSequenceFeatures)
\r
232 fr.transferSettings( ap.seqPanel.seqCanvas.getFeatureRenderer() );
\r
235 int alwidth = av.alignment.getWidth();
\r
236 int alheight = av.alignment.getHeight()
\r
237 +av.alignment.getHiddenSequences().getSize();
\r
239 setPreferredSize(new Dimension(width, sequencesHeight + graphHeight));
\r
241 int fullsizeWidth = alwidth * av.getCharWidth();
\r
242 int fullsizeHeight = alheight * av.getCharHeight();
\r
244 scalew = (float) width / (float) fullsizeWidth;
\r
245 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
\r
247 miniMe = new BufferedImage(width, sequencesHeight + graphHeight,
\r
248 BufferedImage.TYPE_INT_RGB);
\r
251 Graphics mg = miniMe.getGraphics();
\r
252 mg.setColor(Color.orange);
\r
253 mg.fillRect(0,0,width, miniMe.getHeight());
\r
255 float sampleCol = (float) alwidth / (float) width;
\r
256 float sampleRow = (float) alheight / (float) sequencesHeight;
\r
258 int lastcol=-1, lastrow=-1;
\r
259 int color = Color.white.getRGB();
\r
261 jalview.datamodel.SequenceI seq;
\r
262 boolean hiddenRow = false;
\r
263 for (row = 0; row < sequencesHeight; row++)
\r
265 if((int)(row*sampleRow)==lastrow)
\r
267 //No need to recalculate the colours,
\r
268 //Just copy from the row above
\r
269 for (col = 0; col < width; col++)
\r
271 miniMe.setRGB(col, row, miniMe.getRGB(col, row-1));
\r
276 lastrow = (int)(row*sampleRow);
\r
279 if (av.hasHiddenRows)
\r
281 seq = av.alignment.getHiddenSequences().getHiddenSequence(lastrow);
\r
286 av.alignment.getHiddenSequences().findIndexWithoutHiddenSeqs(lastrow);
\r
289 seq = av.alignment.getSequenceAt(index);
\r
297 seq = av.alignment.getSequenceAt(lastrow);
\r
301 System.out.println(lastrow+" null");
\r
305 for (col = 0; col < width; col++)
\r
307 if((int)(col*sampleCol) == lastcol && (int)(row*sampleRow)==lastrow)
\r
309 miniMe.setRGB(col,row,color);
\r
314 lastcol = (int)(col*sampleCol);
\r
316 if (seq.getLength() > lastcol)
\r
318 color = sr.getResidueBoxColour(
\r
319 seq, lastcol).getRGB();
\r
321 if (av.showSequenceFeatures)
\r
322 color = fr.findFeatureColour(color, lastrow, lastcol);
\r
326 color = -1; //White
\r
330 (av.hasHiddenColumns && !av.getColumnSelection().isVisible(lastcol)))
\r
332 color = new Color(color).darker().darker().getRGB();
\r
336 miniMe.setRGB(col,row,color);
\r
342 if (av.conservation != null)
\r
344 for (col = 0; col < width; col++)
\r
346 lastcol = (int) (col * sampleCol);
\r
348 mg.translate(col, sequencesHeight);
\r
349 ap.annotationPanel.drawGraph(mg, av.conservation,
\r
350 (int) (sampleCol) + 1,
\r
352 (int) (col * sampleCol),
\r
353 (int) (col * sampleCol) + 1);
\r
354 mg.translate( -col, -sequencesHeight);
\r
366 resizeAgain = false;
\r
367 updateOverviewImage();
\r
374 public void setBoxPosition()
\r
376 int fullsizeWidth = av.alignment.getWidth() * av.getCharWidth();
\r
377 int fullsizeHeight = (av.alignment.getHeight()
\r
378 +av.alignment.getHiddenSequences().getSize()) * av.getCharHeight();
\r
380 int startRes = av.getStartRes();
\r
381 int endRes = av.getEndRes();
\r
383 if(av.hasHiddenColumns)
\r
385 startRes = av.getColumnSelection().adjustForHiddenColumns(startRes);
\r
386 endRes = av.getColumnSelection().adjustForHiddenColumns(endRes);
\r
389 int startSeq = av.startSeq;
\r
390 int endSeq = av.endSeq;
\r
392 if (av.hasHiddenRows)
\r
395 av.alignment.getHiddenSequences().adjustForHiddenSeqs(startSeq);
\r
398 av.alignment.getHiddenSequences().adjustForHiddenSeqs(endSeq);
\r
403 scalew = (float) width / (float) fullsizeWidth;
\r
404 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
\r
406 boxX = (int) (startRes * av.getCharWidth() * scalew);
\r
407 boxY = (int) (startSeq * av.getCharHeight() * scaleh);
\r
411 if(av.hasHiddenColumns)
\r
412 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
\r
414 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
\r
417 boxHeight = (int) ((endSeq - startSeq) * av.getCharHeight() * scaleh);
\r
426 * @param g DOCUMENT ME!
\r
428 public void paintComponent(Graphics g)
\r
430 if (miniMe != null && !resizing)
\r
432 g.drawImage(miniMe, 0, 0, this);
\r
436 g.setColor(Color.white);
\r
437 g.fillRect(0, 0, getWidth(), getHeight());
\r
438 g.setColor(Color.black);
\r
439 g.setFont(new Font("Verdana", Font.BOLD, 15));
\r
440 g.drawString("Recalculating", 5, sequencesHeight / 2);
\r
441 g.drawString("Overview.....", 5, (sequencesHeight / 2) + 20);
\r
445 g.setColor(Color.red);
\r
446 g.drawRect(boxX, boxY, boxWidth, boxHeight);
\r
447 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
\r