2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 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.*;
34 public class OverviewPanel extends JPanel implements Runnable
48 boolean resizing = false;
50 // Can set different properties in this seqCanvas than
51 // main visible SeqCanvas
56 * Creates a new OverviewPanel object.
58 * @param ap DOCUMENT ME!
60 public OverviewPanel(AlignmentPanel ap)
66 sr = new SequenceRenderer(av);
67 sr.renderGaps = false;
68 sr.forOverview = true;
69 fr = new FeatureRenderer(av);
71 // scale the initial size of overviewpanel to shape of alignment
72 float initialScale = (float) av.alignment.getWidth() / (float) av.alignment.getHeight();
74 if(av.conservation==null)
78 if (av.alignment.getWidth() > av.alignment.getHeight())
82 sequencesHeight = (int) (400f / initialScale);
83 if(sequencesHeight<40)
89 width = (int) (400f * initialScale);
90 sequencesHeight = 300;
98 addComponentListener(new ComponentAdapter()
100 public void componentResized(ComponentEvent evt)
102 if ((getWidth() != width) ||
103 (getHeight() != (sequencesHeight + graphHeight)))
105 updateOverviewImage();
110 addMouseMotionListener(new MouseMotionAdapter()
112 public void mouseDragged(MouseEvent evt)
114 if (!av.wrapAlignment)
123 addMouseListener(new MouseAdapter()
125 public void mousePressed(MouseEvent evt)
127 if(!av.wrapAlignment)
136 updateOverviewImage();
150 if (boxY > (sequencesHeight - boxHeight))
152 boxY = sequencesHeight - boxHeight + 1;
160 if (boxX > (width - boxWidth))
162 if(av.hasHiddenColumns)
164 //Try smallest possible box
165 boxWidth = (int) ( (av.endRes - av.startRes + 1) *
166 av.getCharWidth() * scalew);
168 boxX = width - boxWidth;
171 int col = (int) (boxX / scalew / av.getCharWidth());
172 int row = (int) (boxY / scaleh / av.getCharHeight());
174 if (av.hasHiddenColumns)
176 if (!av.getColumnSelection().isVisible(col))
181 col = av.getColumnSelection().findColumnPosition(col);
184 if( av.hasHiddenRows )
186 row = av.alignment.getHiddenSequences().findIndexWithoutHiddenSeqs(row);
189 ap.setScrollValues( col, row );
196 public void updateOverviewImage()
206 if ( (getWidth() > 0) && (getHeight() > 0))
209 sequencesHeight = getHeight() - graphHeight;
212 setPreferredSize(new Dimension(width, sequencesHeight + graphHeight));
214 Thread thread = new Thread(this);
219 // This is set true if the user resizes whilst
220 // the overview is being calculated
221 boolean resizeAgain = false;
230 if (av.showSequenceFeatures)
232 fr.transferSettings( ap.seqPanel.seqCanvas.getFeatureRenderer() );
235 int alwidth = av.alignment.getWidth();
236 int alheight = av.alignment.getHeight()
237 +av.alignment.getHiddenSequences().getSize();
239 setPreferredSize(new Dimension(width, sequencesHeight + graphHeight));
241 int fullsizeWidth = alwidth * av.getCharWidth();
242 int fullsizeHeight = alheight * av.getCharHeight();
244 scalew = (float) width / (float) fullsizeWidth;
245 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
247 miniMe = new BufferedImage(width, sequencesHeight + graphHeight,
248 BufferedImage.TYPE_INT_RGB);
251 Graphics mg = miniMe.getGraphics();
252 mg.setColor(Color.orange);
253 mg.fillRect(0,0,width, miniMe.getHeight());
255 float sampleCol = (float) alwidth / (float) width;
256 float sampleRow = (float) alheight / (float) sequencesHeight;
258 int lastcol=-1, lastrow=-1;
259 int color = Color.white.getRGB();
261 jalview.datamodel.SequenceI seq;
262 boolean hiddenRow = false;
263 for (row = 0; row < sequencesHeight; row++)
265 if((int)(row*sampleRow)==lastrow)
267 //No need to recalculate the colours,
268 //Just copy from the row above
269 for (col = 0; col < width; col++)
271 miniMe.setRGB(col, row, miniMe.getRGB(col, row-1));
276 lastrow = (int)(row*sampleRow);
279 if (av.hasHiddenRows)
281 seq = av.alignment.getHiddenSequences().getHiddenSequence(lastrow);
285 av.alignment.getHiddenSequences().findIndexWithoutHiddenSeqs(lastrow);
287 seq = av.alignment.getSequenceAt(index);
295 seq = av.alignment.getSequenceAt(lastrow);
299 System.out.println(lastrow+" null");
303 for (col = 0; col < width; col++)
305 if((int)(col*sampleCol) == lastcol && (int)(row*sampleRow)==lastrow)
307 miniMe.setRGB(col,row,color);
312 lastcol = (int)(col*sampleCol);
314 if (seq.getLength() > lastcol)
316 color = sr.getResidueBoxColour(
317 seq, lastcol).getRGB();
319 if (av.showSequenceFeatures)
320 color = fr.findFeatureColour(color, seq, lastcol);
328 (av.hasHiddenColumns && !av.getColumnSelection().isVisible(lastcol)))
330 color = new Color(color).darker().darker().getRGB();
334 miniMe.setRGB(col,row,color);
340 if (av.conservation != null)
342 for (col = 0; col < width; col++)
344 lastcol = (int) (col * sampleCol);
346 mg.translate(col, sequencesHeight);
347 ap.annotationPanel.drawGraph(mg, av.conservation,
348 (int) (sampleCol) + 1,
350 (int) (col * sampleCol),
351 (int) (col * sampleCol) + 1);
352 mg.translate( -col, -sequencesHeight);
365 updateOverviewImage();
372 public void setBoxPosition()
374 int fullsizeWidth = av.alignment.getWidth() * av.getCharWidth();
375 int fullsizeHeight = (av.alignment.getHeight()
376 +av.alignment.getHiddenSequences().getSize()) * av.getCharHeight();
378 int startRes = av.getStartRes();
379 int endRes = av.getEndRes();
381 if(av.hasHiddenColumns)
383 startRes = av.getColumnSelection().adjustForHiddenColumns(startRes);
384 endRes = av.getColumnSelection().adjustForHiddenColumns(endRes);
387 int startSeq = av.startSeq;
388 int endSeq = av.endSeq;
390 if (av.hasHiddenRows)
393 av.alignment.getHiddenSequences().adjustForHiddenSeqs(startSeq);
396 av.alignment.getHiddenSequences().adjustForHiddenSeqs(endSeq);
401 scalew = (float) width / (float) fullsizeWidth;
402 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
404 boxX = (int) (startRes * av.getCharWidth() * scalew);
405 boxY = (int) (startSeq * av.getCharHeight() * scaleh);
409 if(av.hasHiddenColumns)
410 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
412 boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
415 boxHeight = (int) ((endSeq - startSeq) * av.getCharHeight() * scaleh);
424 * @param g DOCUMENT ME!
426 public void paintComponent(Graphics g)
428 if (miniMe != null && !resizing)
430 g.drawImage(miniMe, 0, 0, this);
434 g.setColor(Color.white);
435 g.fillRect(0, 0, getWidth(), getHeight());
436 g.setColor(Color.black);
437 g.setFont(new Font("Verdana", Font.BOLD, 15));
438 g.drawString("Recalculating", 5, sequencesHeight / 2);
439 g.drawString("Overview.....", 5, (sequencesHeight / 2) + 20);
443 g.setColor(Color.red);
444 g.drawRect(boxX, boxY, boxWidth, boxHeight);
445 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);