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
\r
34 public int width, sequencesHeight;
\r
35 int graphHeight = 30;
\r
36 int boxX = -1, boxY = -1, boxWidth = -1, boxHeight = -1;
\r
38 boolean resizing = false;
\r
42 public OverviewPanel(AlignmentPanel ap)
\r
47 nullFrame = new Frame();
\r
48 nullFrame.addNotify();
\r
50 // scale the initial size of overviewpanel to shape of alignment
\r
51 float initialScale = (float) av.alignment.getWidth() /
\r
52 (float) av.alignment.getHeight();
\r
53 if (av.alignment.getWidth() > av.alignment.getHeight())
\r
57 sequencesHeight = (int) (400f / initialScale);
\r
62 width = (int) (400f * initialScale);
\r
63 sequencesHeight = 300;
\r
70 setSize(new Dimension(width, sequencesHeight + graphHeight));
\r
71 addComponentListener(new ComponentAdapter()
\r
74 public void componentResized(ComponentEvent evt)
\r
76 if (getSize().width != width ||
\r
77 getSize().height != sequencesHeight + graphHeight)
\r
79 updateOverviewImage();
\r
84 addMouseMotionListener(new MouseMotionAdapter()
\r
86 public void mouseDragged(MouseEvent evt)
\r
88 doMouseDragged(evt);
\r
92 addMouseListener(new MouseAdapter()
\r
94 public void mousePressed(MouseEvent evt)
\r
96 doMousePressed(evt);
\r
99 public void mouseReleased(MouseEvent evt)
\r
101 doMouseReleased(evt);
\r
105 updateOverviewImage();
\r
109 public void doMousePressed(MouseEvent evt)
\r
118 public void doMouseReleased(MouseEvent evt)
\r
125 ap.setScrollValues( (int) (boxX / scalew / av.getCharWidth()),
\r
126 (int) (boxY / scaleh / av.getCharHeight()));
\r
130 public void doMouseDragged(MouseEvent evt)
\r
137 ap.setScrollValues( (int) (boxX / scalew / av.getCharWidth()),
\r
138 (int) (boxY / scaleh / av.getCharHeight()));
\r
151 if (boxY > sequencesHeight - boxHeight)
\r
153 boxY = sequencesHeight - boxHeight + 1;
\r
161 if (boxX > width - boxWidth)
\r
163 boxX = width - boxWidth;
\r
167 public void updateOverviewImage()
\r
175 Thread thread = new Thread(this);
\r
183 int alwidth = av.alignment.getWidth();
\r
184 int alheight = av.alignment.getHeight();
\r
186 if (getSize().width > 0 && getSize().height > 0)
\r
188 width = getSize().width;
\r
189 sequencesHeight = getSize().height - graphHeight;
\r
192 setSize(new Dimension(width, sequencesHeight + graphHeight));
\r
194 int fullsizeWidth = alwidth * av.getCharWidth();
\r
195 int fullsizeHeight = alheight * av.getCharHeight();
\r
197 scalew = (float) width / (float) fullsizeWidth;
\r
198 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
\r
200 miniMe = nullFrame.createImage(width, sequencesHeight + graphHeight);
\r
202 Graphics mg = miniMe.getGraphics();
\r
203 Image consensus = nullFrame.createImage(fullsizeWidth, 60);
\r
204 Graphics g = consensus.getGraphics();
\r
205 ap.annotationPanel.drawGraph(g, av.conservation, fullsizeWidth, 60);
\r
206 mg.drawImage(consensus, 0, sequencesHeight, width,
\r
207 sequencesHeight + graphHeight, 0, 0, fullsizeWidth, 60, this);
\r
209 boolean oldRenderGaps = av.renderGaps;
\r
212 // We'll have to draw the full size alignment in chunks, as an image of the
\r
213 // whole alignment requires too much memory
\r
215 // Max size depends on the font size, the following is a
\r
216 // guess at a size which works
\r
217 int maxSize = 2000 / av.getFont().getSize();
\r
219 int blockx = 0, blocky = 0, blockw = 0, blockh = 0, eRes = 0, eSeq = 0;
\r
221 av.setRenderGaps(false);
\r
222 for (int sRes = 0, chunkx = 0; sRes < alwidth; sRes += maxSize, chunkx++)
\r
226 if (eRes > alwidth)
\r
231 for (int sSeq = 0, chunky = 0; sSeq < alheight; sSeq += maxSize, chunky++)
\r
234 if (eSeq > alheight)
\r
240 blockx = (int) ( (float) sRes / (float) alwidth * width);
\r
242 block = nullFrame.createImage( (eRes - sRes) * av.charWidth,
\r
243 (eSeq - sSeq) * av.charHeight);
\r
244 g = block.getGraphics();
\r
246 ap.seqPanel.seqCanvas.drawPanel(g, sRes, eRes, sSeq, eSeq, sRes, sSeq,
\r
249 blockh = (int) ( (float) (eSeq - sSeq) / (float) alheight *
\r
250 sequencesHeight) + 1;
\r
251 blockw = (int) ( (float) (eRes - sRes) / (float) alwidth * width) + 1;
\r
253 blocky += (int) ( (float) sSeq / (float) alheight * sequencesHeight);
\r
255 mg.drawImage(block, blockx,
\r
260 0, 0, block.getWidth(null), block.getHeight(null), this);
\r
268 catch (OutOfMemoryError error)
\r
270 System.err.println(
\r
271 "Out of memory when trying to calculate the overview window image!");
\r
274 av.setRenderGaps(oldRenderGaps);
\r
280 public void setBoxPosition()
\r
282 boxX = (int) (av.getStartRes() * av.getCharWidth() * scalew);
\r
283 boxY = (int) (av.getStartSeq() * av.getCharHeight() * scaleh);
\r
284 boxWidth = (int) ( (av.getEndRes() - av.getStartRes() + 1) *
\r
285 av.getCharWidth() * scalew);
\r
286 boxHeight = (int) (av.getEndSeq() * av.getCharHeight() * scaleh) - boxY;
\r
290 public void update(Graphics g)
\r
295 public void paint(Graphics g)
\r
299 g.setColor(Color.white);
\r
300 g.fillRect(0, 0, getSize().width, getSize().height);
\r
301 g.setColor(Color.black);
\r
303 g.setFont(new Font("Verdana", Font.BOLD, 15));
\r
304 g.drawString("Recalculating", 5, sequencesHeight / 2);
\r
305 g.drawString("Overview.....", 5, sequencesHeight / 2 + 20);
\r
309 if (miniMe != null)
\r
311 g.drawImage(miniMe, 0, 0, this);
\r
314 g.setColor(Color.red);
\r
315 g.drawRect(boxX, boxY, boxWidth, boxHeight);
\r
316 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
\r