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
22 import java.awt.event.*;
\r
25 public class OverviewPanel extends Panel implements Runnable
\r
33 public int width, sequencesHeight;
\r
35 int boxX=-1, boxY=-1, boxWidth=-1, boxHeight=-1;
\r
37 boolean resizing = false;
\r
41 public OverviewPanel(AlignmentPanel ap)
\r
46 nullFrame = new Frame();
\r
47 nullFrame.addNotify();
\r
49 // scale the initial size of overviewpanel to shape of alignment
\r
50 float initialScale = (float)av.alignment.getWidth()/(float)av.alignment.getHeight();
\r
51 if(av.alignment.getWidth() > av.alignment.getHeight())
\r
55 sequencesHeight = (int)(400f/initialScale);
\r
60 width = (int)(400f*initialScale);
\r
61 sequencesHeight = 300;
\r
66 setSize (new Dimension(width, sequencesHeight+graphHeight));
\r
67 addComponentListener(new ComponentAdapter()
\r
70 public void componentResized(ComponentEvent evt)
\r
72 if( getSize().width!=width || getSize().height!=sequencesHeight+graphHeight)
\r
74 updateOverviewImage();
\r
79 addMouseMotionListener(new MouseMotionAdapter()
\r
81 public void mouseDragged(MouseEvent evt)
\r
82 { doMouseDragged(evt);}
\r
85 addMouseListener(new MouseAdapter()
\r
87 public void mousePressed(MouseEvent evt)
\r
88 { doMousePressed(evt);}
\r
89 public void mouseReleased(MouseEvent evt)
\r
90 { doMouseReleased(evt);}
\r
93 updateOverviewImage();
\r
97 public void doMousePressed(MouseEvent evt)
\r
106 public void doMouseReleased(MouseEvent evt)
\r
112 ap.setScrollValues( (int)(boxX/scalew/av.getCharWidth()),
\r
113 (int)(boxY/scaleh/av.getCharHeight()) );
\r
116 public void doMouseDragged(MouseEvent evt)
\r
122 ap.setScrollValues( (int)(boxX/scalew/av.getCharWidth()),
\r
123 (int)(boxY/scaleh/av.getCharHeight()) );
\r
133 if (boxY > sequencesHeight - boxHeight)
\r
134 boxY = sequencesHeight - boxHeight+1;
\r
139 if (boxX > width - boxWidth)
\r
140 boxX = width - boxWidth;
\r
143 public void updateOverviewImage()
\r
151 Thread thread = new Thread(this);
\r
159 int alwidth = av.alignment.getWidth();
\r
160 int alheight = av.alignment.getHeight();
\r
162 if(getSize().width>0 && getSize().height>0)
\r
164 width = getSize().width;
\r
165 sequencesHeight = getSize().height - graphHeight;
\r
168 setSize (new Dimension(width, sequencesHeight+graphHeight));
\r
170 int fullsizeWidth = alwidth * av.getCharWidth();
\r
171 int fullsizeHeight = alheight * av.getCharHeight();
\r
173 scalew = (float) width / (float) fullsizeWidth;
\r
174 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
\r
176 miniMe = nullFrame.createImage(width, sequencesHeight + graphHeight);
\r
178 Graphics mg = miniMe.getGraphics();
\r
179 Image consensus = nullFrame.createImage(fullsizeWidth, 60);
\r
180 Graphics g = consensus.getGraphics();
\r
181 ap.annotationPanel.drawGraph(g, av.conservation, fullsizeWidth, 60);
\r
182 mg.drawImage(consensus, 0, sequencesHeight, width,
\r
183 sequencesHeight + graphHeight, 0, 0, fullsizeWidth, 60, this);
\r
186 boolean oldRenderGaps = av.renderGaps;
\r
188 // We'll have to draw the full size alignment in chunks, as an image of the
\r
189 // whole alignment requires too much memory
\r
191 // Max size depends on the font size, the following is a
\r
192 // guess at a size which works
\r
193 int maxSize = 2000 / av.getFont().getSize();
\r
195 int blockx=0, blocky=0, blockw=0, blockh=0, eRes=0, eSeq=0;
\r
197 av.setRenderGaps(false);
\r
198 for(int sRes=0, chunkx=0; sRes<alwidth; sRes+=maxSize, chunkx++)
\r
205 for(int sSeq=0, chunky=0; sSeq<alheight; sSeq+=maxSize, chunky++)
\r
212 blockx = (int)((float)sRes/(float)alwidth * width);
\r
214 block = nullFrame.createImage((eRes-sRes)*av.charWidth, (eSeq-sSeq)*av.charHeight);
\r
215 g = block.getGraphics();
\r
217 ap.seqPanel.seqCanvas.drawPanel(g, sRes, eRes, sSeq, eSeq, sRes, sSeq, 0);
\r
219 blockh = (int)( (float)(eSeq-sSeq)/(float)alheight * sequencesHeight )+1 ;
\r
220 blockw = (int)( (float)(eRes-sRes)/(float)alwidth * width )+1;
\r
222 blocky += (int) ((float)sSeq/(float)alheight* sequencesHeight);
\r
224 mg.drawImage(block, blockx,
\r
229 0, 0, block.getWidth(null),block.getHeight(null), this);
\r
236 }catch(OutOfMemoryError error)
\r
237 { System.err.println("Out of memory when trying to calculate the overview window image!"); }
\r
240 av.setRenderGaps(oldRenderGaps);
\r
246 public void setBoxPosition()
\r
248 boxX = (int) (av.getStartRes() * av.getCharWidth() * scalew);
\r
249 boxY = (int) (av.getStartSeq() * av.getCharHeight() * scaleh);
\r
250 boxWidth = (int) ((av.getEndRes()-av.getStartRes()+1)* av.getCharWidth() * scalew) ;
\r
251 boxHeight = (int) (av.getEndSeq() * av.getCharHeight() * scaleh) - boxY;
\r
255 public void update(Graphics g)
\r
260 public void paint(Graphics g)
\r
264 g.setColor(Color.white);
\r
265 g.fillRect(0, 0, getSize().width, getSize().height);
\r
266 g.setColor(Color.black);
\r
268 g.setFont(new Font("Verdana", Font.BOLD, 15));
\r
269 g.drawString("Recalculating", 5, sequencesHeight/2);
\r
270 g.drawString("Overview.....", 5, sequencesHeight/2 +20);
\r
275 g.drawImage(miniMe, 0,0,this);
\r
277 g.setColor(Color.red);
\r
278 g.drawRect(boxX, boxY, boxWidth, boxHeight);
\r
279 g.drawRect(boxX+1, boxY+1, boxWidth-2, boxHeight-2);
\r