2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 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
35 public int width, sequencesHeight;
\r
36 int graphHeight = 20;
\r
37 int boxX = -1, boxY = -1, boxWidth = -1, boxHeight = -1;
\r
39 boolean resizing = false;
\r
41 // Can set different properties in this seqCanvas than
\r
42 // main visible SeqCanvas
\r
43 SequenceRenderer sr;
\r
48 public OverviewPanel(AlignmentPanel ap)
\r
53 nullFrame = new Frame();
\r
54 nullFrame.addNotify();
\r
56 sr = new SequenceRenderer(av);
\r
57 sr.graphics = nullFrame.getGraphics();
\r
58 sr.renderGaps = false;
\r
59 sr.forOverview = true;
\r
60 fr = new FeatureRenderer(av);
\r
63 // scale the initial size of overviewpanel to shape of alignment
\r
64 float initialScale = (float) av.alignment.getWidth() /
\r
65 (float) av.alignment.getHeight();
\r
67 if (av.hconsensus == null)
\r
72 if (av.alignment.getWidth() > av.alignment.getHeight())
\r
76 sequencesHeight = (int) (400f / initialScale);
\r
77 if (sequencesHeight < 40)
\r
79 sequencesHeight = 40;
\r
85 width = (int) (400f * initialScale);
\r
86 sequencesHeight = 300;
\r
93 setSize(new Dimension(width, sequencesHeight + graphHeight));
\r
94 addComponentListener(new ComponentAdapter()
\r
97 public void componentResized(ComponentEvent evt)
\r
99 if (getSize().width != width ||
\r
100 getSize().height != sequencesHeight + graphHeight)
\r
102 updateOverviewImage();
\r
107 addMouseMotionListener(this);
\r
109 addMouseListener(this);
\r
111 updateOverviewImage();
\r
115 public void mouseEntered(MouseEvent evt)
\r
118 public void mouseExited(MouseEvent evt)
\r
121 public void mouseClicked(MouseEvent evt)
\r
124 public void mouseMoved(MouseEvent evt)
\r
127 public void mousePressed(MouseEvent evt)
\r
134 public void mouseReleased(MouseEvent evt)
\r
141 public void mouseDragged(MouseEvent evt)
\r
155 if (boxY > (sequencesHeight - boxHeight))
\r
157 boxY = sequencesHeight - boxHeight + 1;
\r
165 if (boxX > (width - boxWidth))
\r
167 if (av.hasHiddenColumns)
\r
169 //Try smallest possible box
\r
170 boxWidth = (int) ( (av.endRes - av.startRes + 1) *
\r
171 av.getCharWidth() * scalew);
\r
173 boxX = width - boxWidth;
\r
176 int col = (int) (boxX / scalew / av.getCharWidth());
\r
177 int row = (int) (boxY / scaleh / av.getCharHeight());
\r
179 if (av.hasHiddenColumns)
\r
181 if (!av.getColumnSelection().isVisible(col))
\r
186 col = av.getColumnSelection().findColumnPosition(col);
\r
189 if (av.hasHiddenRows)
\r
191 row = av.alignment.getHiddenSequences().findIndexWithoutHiddenSeqs(row);
\r
194 ap.setScrollValues(col, row);
\r
195 ap.paintAlignment(false);
\r
201 public void updateOverviewImage()
\r
205 resizeAgain = true;
\r
209 if (av.showSequenceFeatures)
\r
211 fr.featureGroups = ap.seqPanel.seqCanvas.getFeatureRenderer().
\r
213 fr.featureColours = ap.seqPanel.seqCanvas.getFeatureRenderer().
\r
219 if ( (getSize().width > 0) && (getSize().height > 0))
\r
221 width = getSize().width;
\r
222 sequencesHeight = getSize().height - graphHeight;
\r
224 setSize(new Dimension(width, sequencesHeight + graphHeight));
\r
226 Thread thread = new Thread(this);
\r
231 // This is set true if the user resizes whilst
\r
232 // the overview is being calculated
\r
233 boolean resizeAgain = false;
\r
238 int alwidth = av.alignment.getWidth();
\r
239 int alheight = av.alignment.getHeight();
\r
241 if (av.showSequenceFeatures)
\r
243 fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer());
\r
246 if (getSize().width > 0 && getSize().height > 0)
\r
248 width = getSize().width;
\r
249 sequencesHeight = getSize().height - graphHeight;
\r
252 setSize(new Dimension(width, sequencesHeight + graphHeight));
\r
254 int fullsizeWidth = alwidth * av.getCharWidth();
\r
255 int fullsizeHeight = alheight * av.getCharHeight();
\r
257 scalew = (float) width / (float) fullsizeWidth;
\r
258 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
\r
260 miniMe = nullFrame.createImage(width, sequencesHeight + graphHeight);
\r
261 offscreen = nullFrame.createImage(width, sequencesHeight + graphHeight);
\r
263 Graphics mg = miniMe.getGraphics();
\r
264 float sampleCol = (float) alwidth / (float) width;
\r
265 float sampleRow = (float) alheight / (float) sequencesHeight;
\r
267 int lastcol = 0, lastrow = 0;
\r
268 int xstart = 0, ystart = 0;
\r
269 Color color = Color.yellow;
\r
270 int row, col, sameRow = 0, sameCol = 0;
\r
271 jalview.datamodel.SequenceI seq;
\r
272 boolean hiddenRow = false;
\r
273 for (row = 0; row <= sequencesHeight; row++)
\r
275 if ( (int) (row * sampleRow) == lastrow)
\r
282 if (av.hasHiddenRows)
\r
284 seq = av.alignment.getHiddenSequences().getHiddenSequence(lastrow);
\r
288 av.alignment.getHiddenSequences().findIndexWithoutHiddenSeqs(
\r
291 seq = av.alignment.getSequenceAt(index);
\r
300 seq = av.alignment.getSequenceAt(lastrow);
\r
303 for (col = 0; col < width; col++)
\r
305 if ( (int) (col * sampleCol) == lastcol &&
\r
306 (int) (row * sampleRow) == lastrow)
\r
312 lastcol = (int) (col * sampleCol);
\r
314 if (seq.getLength() > lastcol)
\r
316 color = sr.getResidueBoxColour(
\r
319 if (av.showSequenceFeatures)
\r
321 color = fr.findFeatureColour(color, seq, lastcol);
\r
326 color = Color.white; //White
\r
330 (av.hasHiddenColumns && !av.getColumnSelection().isVisible(lastcol)))
\r
332 color = color.darker().darker();
\r
335 mg.setColor(color);
\r
336 if (sameCol == 1 && sameRow == 1)
\r
338 mg.drawLine(xstart, ystart, xstart, ystart);
\r
342 mg.fillRect(xstart, ystart, sameCol, sameRow);
\r
348 lastrow = (int) (row * sampleRow);
\r
353 if (av.conservation != null)
\r
355 for (col = 0; col < width; col++)
\r
357 lastcol = (int) (col * sampleCol);
\r
359 mg.translate(col, sequencesHeight);
\r
360 ap.annotationPanel.drawGraph(mg, av.conservation,
\r
361 (int) (sampleCol) + 1,
\r
363 (int) (col * sampleCol),
\r
364 (int) (col * sampleCol) + 1);
\r
365 mg.translate( -col, -sequencesHeight);
\r
377 resizeAgain = false;
\r
378 updateOverviewImage();
\r
382 public void setBoxPosition()
\r
384 int fullsizeWidth = av.alignment.getWidth() * av.getCharWidth();
\r
385 int fullsizeHeight = (av.alignment.getHeight()
\r
386 + av.alignment.getHiddenSequences().getSize()) *
\r
387 av.getCharHeight();
\r
389 int startRes = av.getStartRes();
\r
390 int endRes = av.getEndRes();
\r
392 if (av.hasHiddenColumns)
\r
394 startRes = av.getColumnSelection().adjustForHiddenColumns(startRes);
\r
395 endRes = av.getColumnSelection().adjustForHiddenColumns(endRes);
\r
398 int startSeq = av.startSeq;
\r
399 int endSeq = av.endSeq;
\r
401 if (av.hasHiddenRows)
\r
404 av.alignment.getHiddenSequences().adjustForHiddenSeqs(startSeq);
\r
407 av.alignment.getHiddenSequences().adjustForHiddenSeqs(endSeq);
\r
411 scalew = (float) width / (float) fullsizeWidth;
\r
412 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
\r
414 boxX = (int) (startRes * av.getCharWidth() * scalew);
\r
415 boxY = (int) (startSeq * av.getCharHeight() * scaleh);
\r
417 if (av.hasHiddenColumns)
\r
419 boxWidth = (int) ( (endRes - startRes + 1) * av.getCharWidth() * scalew);
\r
423 boxWidth = (int) ( (endRes - startRes + 1) * av.getCharWidth() * scalew);
\r
426 boxHeight = (int) ( (endSeq - startSeq) * av.getCharHeight() * scaleh);
\r
431 public void update(Graphics g)
\r
436 public void paint(Graphics g)
\r
438 Graphics og = offscreen.getGraphics();
\r
439 if (miniMe != null)
\r
441 og.drawImage(miniMe, 0, 0, this);
\r
442 og.setColor(Color.red);
\r
443 og.drawRect(boxX, boxY, boxWidth, boxHeight);
\r
444 og.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
\r
445 g.drawImage(offscreen, 0, 0, this);
\r