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
20 package jalview.appletgui;
\r
23 import java.awt.event.*;
\r
25 public class OverviewPanel
\r
26 extends Panel implements Runnable, MouseMotionListener, MouseListener
\r
34 public int width, sequencesHeight;
\r
35 int graphHeight = 20;
\r
36 int boxX = -1, boxY = -1, boxWidth = -1, boxHeight = -1;
\r
38 boolean resizing = false;
\r
40 // Can set different properties in this seqCanvas than
\r
41 // main visible SeqCanvas
\r
42 SequenceRenderer sr;
\r
48 public OverviewPanel(AlignmentPanel ap)
\r
53 nullFrame = new Frame();
\r
54 nullFrame.addNotify();
\r
57 sr = new SequenceRenderer(av);
\r
58 sr.graphics = nullFrame.getGraphics();
\r
59 sr.renderGaps = false;
\r
60 sr.forOverview = true;
\r
61 fr = new FeatureRenderer(av);
\r
66 // scale the initial size of overviewpanel to shape of alignment
\r
67 float initialScale = (float) av.alignment.getWidth() /
\r
68 (float) av.alignment.getHeight();
\r
70 if(av.vconsensus==null)
\r
73 if (av.alignment.getWidth() > av.alignment.getHeight())
\r
77 sequencesHeight = (int) (400f / initialScale);
\r
78 if(sequencesHeight<40)
\r
79 sequencesHeight = 40;
\r
84 width = (int) (400f * initialScale);
\r
85 sequencesHeight = 300;
\r
92 setSize(new Dimension(width, sequencesHeight + graphHeight));
\r
93 addComponentListener(new ComponentAdapter()
\r
96 public void componentResized(ComponentEvent evt)
\r
98 if (getSize().width != width ||
\r
99 getSize().height != sequencesHeight + graphHeight)
\r
101 updateOverviewImage();
\r
106 addMouseMotionListener(this);
\r
108 addMouseListener(this);
\r
110 updateOverviewImage();
\r
115 public void mouseEntered(MouseEvent evt)
\r
117 public void mouseExited(MouseEvent evt)
\r
119 public void mouseClicked(MouseEvent evt)
\r
121 public void mouseMoved(MouseEvent evt)
\r
123 public void mousePressed(MouseEvent evt)
\r
130 public void mouseReleased(MouseEvent evt)
\r
137 public void mouseDragged(MouseEvent evt)
\r
152 if (boxY > (sequencesHeight - boxHeight))
\r
154 boxY = sequencesHeight - boxHeight + 1;
\r
162 if (boxX > (width - boxWidth))
\r
164 if(av.hasHiddenColumns)
\r
166 //Try smallest possible box
\r
167 boxWidth = (int) ( (av.endRes - av.startRes + 1) *
\r
168 av.getCharWidth() * scalew);
\r
170 boxX = width - boxWidth;
\r
173 int col = (int) (boxX / scalew / av.getCharWidth());
\r
174 int row = (int) (boxY / scaleh / av.getCharHeight());
\r
176 if (av.hasHiddenColumns)
\r
178 if (!av.getColumnSelection().isVisible(col))
\r
183 col = av.getColumnSelection().findColumnPosition(col);
\r
186 if( av.hasHiddenRows )
\r
188 row = av.alignment.getHiddenSequences().findIndexWithoutHiddenSeqs(row);
\r
191 ap.setScrollValues( col, row );
\r
198 public void updateOverviewImage()
\r
202 resizeAgain = true;
\r
206 if (av.showSequenceFeatures)
\r
208 fr.featureGroups = ap.seqPanel.seqCanvas.getFeatureRenderer().featureGroups;
\r
209 fr.featureColours = ap.seqPanel.seqCanvas.getFeatureRenderer().featureColours;
\r
214 if ( (getSize().width > 0) && (getSize().height > 0))
\r
216 width = getSize().width;
\r
217 sequencesHeight = getSize().height - graphHeight;
\r
219 setSize(new Dimension(width, sequencesHeight + graphHeight));
\r
221 Thread thread = new Thread(this);
\r
226 // This is set true if the user resizes whilst
\r
227 // the overview is being calculated
\r
228 boolean resizeAgain = false;
\r
233 int alwidth = av.alignment.getWidth();
\r
234 int alheight = av.alignment.getHeight();
\r
236 if (av.showSequenceFeatures)
\r
238 fr.transferSettings( ap.seqPanel.seqCanvas.getFeatureRenderer() );
\r
241 if (getSize().width > 0 && getSize().height > 0)
\r
243 width = getSize().width;
\r
244 sequencesHeight = getSize().height - graphHeight;
\r
247 setSize(new Dimension(width, sequencesHeight + graphHeight));
\r
249 int fullsizeWidth = alwidth * av.getCharWidth();
\r
250 int fullsizeHeight = alheight * av.getCharHeight();
\r
252 scalew = (float) width / (float) fullsizeWidth;
\r
253 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
\r
255 miniMe = nullFrame.createImage(width, sequencesHeight + graphHeight);
\r
257 Graphics mg = miniMe.getGraphics();
\r
258 float sampleCol = (float) alwidth / (float) width;
\r
259 float sampleRow = (float) alheight / (float) sequencesHeight;
\r
261 int lastcol=-1, lastrow=-1;
\r
262 Color color = Color.yellow;
\r
263 int row, col, sameRow = 0, sameCol = 0;
\r
264 jalview.datamodel.SequenceI seq;
\r
265 boolean hiddenRow = false;
\r
266 for (row = 0; row < sequencesHeight; row++)
\r
268 if((int)(row*sampleRow)==lastrow)
\r
274 lastrow = (int)(row*sampleRow);
\r
277 if (av.hasHiddenRows)
\r
279 seq = av.alignment.getHiddenSequences().getHiddenSequence(lastrow);
\r
283 av.alignment.getHiddenSequences().findIndexWithoutHiddenSeqs(lastrow);
\r
285 seq = av.alignment.getSequenceAt(index);
\r
293 seq = av.alignment.getSequenceAt(lastrow);
\r
297 System.out.println(lastrow+" null");
\r
301 for (col = 0; col < width; col++)
\r
303 if ( (int) (col * sampleCol) == lastcol && (int) (row * sampleRow) == lastrow)
\r
309 lastcol = (int) (col * sampleCol);
\r
311 if (seq.getLength() > lastcol)
\r
313 color = sr.getResidueBoxColour(
\r
316 if (av.showSequenceFeatures)
\r
317 color = fr.findFeatureColour(color, seq, lastcol);
\r
321 color = Color.white; //White
\r
325 (av.hasHiddenColumns && !av.getColumnSelection().isVisible(lastcol)))
\r
327 color = color.darker().darker();
\r
330 mg.setColor(color);
\r
331 if (sameCol == 1 && sameRow == 1)
\r
332 mg.drawLine(col, row, col, row);
\r
334 mg.fillRect(col, row, col+sameCol, col+sameRow);
\r
341 if (av.conservation != null)
\r
343 for (col = 0; col < width; col++)
\r
345 lastcol = (int) (col * sampleCol);
\r
347 mg.translate(col, sequencesHeight);
\r
348 ap.annotationPanel.drawGraph(mg, av.conservation,
\r
349 (int) (sampleCol) + 1,
\r
351 (int) (col * sampleCol),
\r
352 (int) (col * sampleCol) + 1);
\r
353 mg.translate( -col, -sequencesHeight);
\r
365 resizeAgain = false;
\r
366 updateOverviewImage();
\r
370 public void setBoxPosition()
\r
372 int fullsizeWidth = av.alignment.getWidth() * av.getCharWidth();
\r
373 int fullsizeHeight = (av.alignment.getHeight()
\r
374 + av.alignment.getHiddenSequences().getSize()) *
\r
375 av.getCharHeight();
\r
377 int startRes = av.getStartRes();
\r
378 int endRes = av.getEndRes();
\r
380 if (av.hasHiddenColumns)
\r
382 startRes = av.getColumnSelection().adjustForHiddenColumns(startRes);
\r
383 endRes = av.getColumnSelection().adjustForHiddenColumns(endRes);
\r
386 int startSeq = av.startSeq;
\r
387 int endSeq = av.endSeq;
\r
389 if (av.hasHiddenRows)
\r
392 av.alignment.getHiddenSequences().adjustForHiddenSeqs(startSeq);
\r
395 av.alignment.getHiddenSequences().adjustForHiddenSeqs(endSeq);
\r
399 scalew = (float) width / (float) fullsizeWidth;
\r
400 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
\r
402 boxX = (int) (startRes * av.getCharWidth() * scalew);
\r
403 boxY = (int) (startSeq * av.getCharHeight() * scaleh);
\r
405 if (av.hasHiddenColumns)
\r
406 boxWidth = (int) ( (endRes - startRes + 1) * av.getCharWidth() * scalew);
\r
408 boxWidth = (int) ( (endRes - startRes + 1) * av.getCharWidth() * scalew);
\r
410 boxHeight = (int) ( (endSeq - startSeq) * av.getCharHeight() * scaleh);
\r
415 public void update(Graphics g)
\r
420 public void paint(Graphics g)
\r
422 if (miniMe != null)
\r
424 g.drawImage(miniMe, 0, 0, this);
\r
428 g.setColor(Color.white);
\r
429 g.fillRect(0, 0, getSize().width, getSize().height);
\r
430 g.setColor(Color.black);
\r
431 g.setFont(new Font("Verdana", Font.BOLD, 15));
\r
432 g.drawString("Recalculating", 5, sequencesHeight / 2);
\r
433 g.drawString("Overview.....", 5, (sequencesHeight / 2) + 20);
\r
436 g.setColor(Color.red);
\r
437 g.drawRect(boxX, boxY, boxWidth, boxHeight);
\r
438 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
\r