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 = 30;
\r
48 boolean resizing = false;
\r
51 * Creates a new OverviewPanel object.
\r
53 * @param ap DOCUMENT ME!
\r
55 public OverviewPanel(AlignmentPanel ap)
\r
61 // scale the initial size of overviewpanel to shape of alignment
\r
62 float initialScale = (float) av.alignment.getWidth() / (float) av.alignment.getHeight();
\r
64 if (av.alignment.getWidth() > av.alignment.getHeight())
\r
68 sequencesHeight = (int) (400f / initialScale);
\r
73 width = (int) (400f * initialScale);
\r
74 sequencesHeight = 300;
\r
82 addComponentListener(new ComponentAdapter()
\r
84 public void componentResized(ComponentEvent evt)
\r
86 if ((getWidth() != width) ||
\r
87 (getHeight() != (sequencesHeight + graphHeight)))
\r
89 updateOverviewImage();
\r
94 addMouseMotionListener(new MouseMotionAdapter()
\r
96 public void mouseDragged(MouseEvent evt)
\r
98 doMouseDragged(evt);
\r
102 addMouseListener(new MouseAdapter()
\r
104 public void mousePressed(MouseEvent evt)
\r
106 doMousePressed(evt);
\r
109 public void mouseReleased(MouseEvent evt)
\r
111 doMouseReleased(evt);
\r
115 updateOverviewImage();
\r
121 * @param evt DOCUMENT ME!
\r
123 public void doMousePressed(MouseEvent evt)
\r
135 * @param evt DOCUMENT ME!
\r
137 public void doMouseReleased(MouseEvent evt)
\r
145 ap.setScrollValues((int) (boxX / scalew / av.getCharWidth()),
\r
146 (int) (boxY / scaleh / av.getCharHeight()));
\r
153 * @param evt DOCUMENT ME!
\r
155 public void doMouseDragged(MouseEvent evt)
\r
163 ap.setScrollValues((int) (boxX / scalew / av.getCharWidth()),
\r
164 (int) (boxY / scaleh / av.getCharHeight()));
\r
178 if (boxY > (sequencesHeight - boxHeight))
\r
180 boxY = sequencesHeight - boxHeight + 1;
\r
188 if (boxX > (width - boxWidth))
\r
190 boxX = width - boxWidth;
\r
197 public void updateOverviewImage()
\r
206 Thread thread = new Thread(this);
\r
218 int alwidth = av.alignment.getWidth();
\r
219 int alheight = av.alignment.getHeight();
\r
221 if ((getWidth() > 0) && (getHeight() > 0))
\r
223 width = getWidth();
\r
224 sequencesHeight = getHeight() - graphHeight;
\r
227 setPreferredSize(new Dimension(width, sequencesHeight + graphHeight));
\r
229 int fullsizeWidth = alwidth * av.getCharWidth();
\r
230 int fullsizeHeight = alheight * av.getCharHeight();
\r
232 scalew = (float) width / (float) fullsizeWidth;
\r
233 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
\r
235 miniMe = new BufferedImage(width, sequencesHeight + graphHeight,
\r
236 BufferedImage.TYPE_INT_RGB);
\r
238 Graphics mg = miniMe.getGraphics();
\r
239 BufferedImage consensus = new BufferedImage(fullsizeWidth, 60,
\r
240 BufferedImage.TYPE_3BYTE_BGR);
\r
241 Graphics g = consensus.getGraphics();
\r
242 ap.annotationPanel.drawGraph(g, av.conservation, fullsizeWidth, 60);
\r
243 mg.drawImage(consensus, 0, sequencesHeight, width,
\r
244 sequencesHeight + graphHeight, 0, 0, fullsizeWidth, 60, this);
\r
246 boolean oldRenderGaps = av.renderGaps;
\r
250 // We'll have to draw the full size alignment in chunks, as an image of the
\r
251 // whole alignment requires too much memory
\r
252 // Max size depends on the font size, the following is a
\r
253 // guess at a size which works
\r
254 int maxSize = 2000 / av.getFont().getSize();
\r
255 BufferedImage block;
\r
263 av.setRenderGaps(false);
\r
265 for (int sRes = 0, chunkx = 0; sRes < alwidth;
\r
266 sRes += maxSize, chunkx++)
\r
271 if (eRes > alwidth)
\r
276 for (int sSeq = 0, chunky = 0; sSeq < alheight;
\r
277 sSeq += maxSize, chunky++)
\r
281 if (eSeq > alheight)
\r
287 blockx = (int) ((float) sRes / (float) alwidth * width);
\r
289 block = new BufferedImage((eRes - sRes) * av.charWidth,
\r
290 (eSeq - sSeq) * av.charHeight,
\r
291 BufferedImage.TYPE_3BYTE_BGR);
\r
292 g = block.getGraphics();
\r
294 ap.seqPanel.seqCanvas.drawPanel(g, sRes, eRes, sSeq, eSeq,
\r
297 blockh = (int) ((float) (eSeq - sSeq) / (float) alheight * sequencesHeight) +
\r
299 blockw = (int) ((float) (eRes - sRes) / (float) alwidth * width) +
\r
302 blocky += (int) ((float) sSeq / (float) alheight * sequencesHeight);
\r
304 mg.drawImage(block, blockx, blocky, blockx + blockw,
\r
305 blocky + blockh, 0, 0, block.getWidth(),
\r
306 block.getHeight(), this);
\r
312 catch (OutOfMemoryError error)
\r
314 System.err.println(
\r
315 "Out of memory when trying to calculate the overview window image!");
\r
318 av.setRenderGaps(oldRenderGaps);
\r
327 public void setBoxPosition()
\r
329 boxX = (int) (av.getStartRes() * av.getCharWidth() * scalew);
\r
330 boxY = (int) (av.getStartSeq() * av.getCharHeight() * scaleh);
\r
331 boxWidth = (int) ((av.getEndRes() - av.getStartRes() + 1) * av.getCharWidth() * scalew);
\r
332 boxHeight = (int) (av.getEndSeq() * av.getCharHeight() * scaleh) -
\r
340 * @param g DOCUMENT ME!
\r
342 public void paintComponent(Graphics g)
\r
344 g.setColor(Color.white);
\r
345 g.fillRect(0, 0, getWidth(), getHeight());
\r
346 g.setColor(Color.black);
\r
350 g.setFont(new Font("Verdana", Font.BOLD, 15));
\r
351 g.drawString("Recalculating", 5, sequencesHeight / 2);
\r
352 g.drawString("Overview.....", 5, (sequencesHeight / 2) + 20);
\r
356 if (miniMe != null)
\r
358 g.drawImage(miniMe, 0, 0, this);
\r
361 g.setColor(Color.red);
\r
362 g.drawRect(boxX, boxY, boxWidth, boxHeight);
\r
363 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
\r