2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 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
285 av.alignment.getHiddenSequences().findIndexWithoutHiddenSeqs(lastrow);
\r
287 seq = av.alignment.getSequenceAt(index);
\r
295 seq = av.alignment.getSequenceAt(lastrow);
\r
299 System.out.println(lastrow+" null");
\r
303 for (col = 0; col < width; col++)
\r
305 if((int)(col*sampleCol) == lastcol && (int)(row*sampleRow)==lastrow)
\r
307 miniMe.setRGB(col,row,color);
\r
312 lastcol = (int)(col*sampleCol);
\r
314 if (seq.getLength() > lastcol)
\r
316 color = sr.getResidueBoxColour(
\r
317 seq, lastcol).getRGB();
\r
319 if (av.showSequenceFeatures)
\r
320 color = fr.findFeatureColour(color, seq, lastcol);
\r
324 color = -1; //White
\r
328 (av.hasHiddenColumns && !av.getColumnSelection().isVisible(lastcol)))
\r
330 color = new Color(color).darker().darker().getRGB();
\r
334 miniMe.setRGB(col,row,color);
\r
340 if (av.conservation != null)
\r
342 for (col = 0; col < width; col++)
\r
344 lastcol = (int) (col * sampleCol);
\r
346 mg.translate(col, sequencesHeight);
\r
347 ap.annotationPanel.drawGraph(mg, av.conservation,
\r
348 (int) (sampleCol) + 1,
\r
350 (int) (col * sampleCol),
\r
351 (int) (col * sampleCol) + 1);
\r
352 mg.translate( -col, -sequencesHeight);
\r
364 resizeAgain = false;
\r
365 updateOverviewImage();
\r
372 public void setBoxPosition()
\r
374 int fullsizeWidth = av.alignment.getWidth() * av.getCharWidth();
\r
375 int fullsizeHeight = (av.alignment.getHeight()
\r
376 +av.alignment.getHiddenSequences().getSize()) * av.getCharHeight();
\r
378 int startRes = av.getStartRes();
\r
379 int endRes = av.getEndRes();
\r
381 if(av.hasHiddenColumns)
\r
383 startRes = av.getColumnSelection().adjustForHiddenColumns(startRes);
\r
384 endRes = av.getColumnSelection().adjustForHiddenColumns(endRes);
\r
387 int startSeq = av.startSeq;
\r
388 int endSeq = av.endSeq;
\r
390 if (av.hasHiddenRows)
\r
393 av.alignment.getHiddenSequences().adjustForHiddenSeqs(startSeq);
\r
396 av.alignment.getHiddenSequences().adjustForHiddenSeqs(endSeq);
\r
401 scalew = (float) width / (float) fullsizeWidth;
\r
402 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
\r
404 boxX = (int) (startRes * av.getCharWidth() * scalew);
\r
405 boxY = (int) (startSeq * av.getCharHeight() * scaleh);
\r
409 if(av.hasHiddenColumns)
\r
410 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
\r
412 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
\r
415 boxHeight = (int) ((endSeq - startSeq) * av.getCharHeight() * scaleh);
\r
424 * @param g DOCUMENT ME!
\r
426 public void paintComponent(Graphics g)
\r
428 if (miniMe != null && !resizing)
\r
430 g.drawImage(miniMe, 0, 0, this);
\r
434 g.setColor(Color.white);
\r
435 g.fillRect(0, 0, getWidth(), getHeight());
\r
436 g.setColor(Color.black);
\r
437 g.setFont(new Font("Verdana", Font.BOLD, 15));
\r
438 g.drawString("Recalculating", 5, sequencesHeight / 2);
\r
439 g.drawString("Overview.....", 5, (sequencesHeight / 2) + 20);
\r
443 g.setColor(Color.red);
\r
444 g.drawRect(boxX, boxY, boxWidth, boxHeight);
\r
445 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
\r