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.gui;
\r
22 import javax.swing.*;
\r
23 import java.awt.event.*;
\r
24 import java.awt.image.*;
\r
27 public class OverviewPanel extends JPanel implements Runnable
\r
29 BufferedImage miniMe;
\r
35 int width, sequencesHeight;
\r
37 int boxX=-1, boxY=-1, boxWidth=-1, boxHeight=-1;
\r
39 boolean resizing = false;
\r
41 public OverviewPanel(AlignmentPanel ap)
\r
47 // scale the initial size of overviewpanel to shape of alignment
\r
48 float initialScale = (float)av.alignment.getWidth()/(float)av.alignment.getHeight();
\r
49 if(av.alignment.getWidth() > av.alignment.getHeight())
\r
53 sequencesHeight = (int)(400f/initialScale);
\r
58 width = (int)(400f*initialScale);
\r
59 sequencesHeight = 300;
\r
64 addComponentListener(new ComponentAdapter()
\r
67 public void componentResized(ComponentEvent evt)
\r
69 if( getWidth()!=width || getHeight()!=sequencesHeight+graphHeight)
\r
71 updateOverviewImage();
\r
76 addMouseMotionListener(new MouseMotionAdapter()
\r
78 public void mouseDragged(MouseEvent evt)
\r
79 { doMouseDragged(evt);}
\r
82 addMouseListener(new MouseAdapter()
\r
84 public void mousePressed(MouseEvent evt)
\r
85 { doMousePressed(evt);}
\r
86 public void mouseReleased(MouseEvent evt)
\r
87 { doMouseReleased(evt);}
\r
90 updateOverviewImage();
\r
94 public void doMousePressed(MouseEvent evt)
\r
103 public void doMouseReleased(MouseEvent evt)
\r
109 ap.setScrollValues( (int)(boxX/scalew/av.getCharWidth()),
\r
110 (int)(boxY/scaleh/av.getCharHeight()) );
\r
113 public void doMouseDragged(MouseEvent evt)
\r
119 ap.setScrollValues( (int)(boxX/scalew/av.getCharWidth()),
\r
120 (int)(boxY/scaleh/av.getCharHeight()) );
\r
128 if (boxY > sequencesHeight - boxHeight)
\r
129 boxY = sequencesHeight - boxHeight+1;
\r
134 if (boxX > width - boxWidth)
\r
135 boxX = width - boxWidth;
\r
138 public void updateOverviewImage()
\r
146 Thread thread = new Thread(this);
\r
154 int alwidth = av.alignment.getWidth();
\r
155 int alheight = av.alignment.getHeight();
\r
157 if(getWidth()>0 && getHeight()>0)
\r
159 width = getWidth();
\r
160 sequencesHeight = getHeight() - graphHeight;
\r
163 setPreferredSize (new Dimension(width, sequencesHeight+graphHeight));
\r
165 int fullsizeWidth = alwidth * av.getCharWidth();
\r
166 int fullsizeHeight = alheight * av.getCharHeight();
\r
168 scalew = (float) width / (float) fullsizeWidth;
\r
169 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
\r
171 miniMe = new BufferedImage(width, sequencesHeight + graphHeight,
\r
172 BufferedImage.TYPE_INT_RGB);
\r
174 Graphics mg = miniMe.getGraphics();
\r
175 BufferedImage consensus = new BufferedImage(fullsizeWidth,
\r
177 BufferedImage.TYPE_3BYTE_BGR);
\r
178 Graphics g = consensus.getGraphics();
\r
179 ap.annotationPanel.drawGraph(g, av.conservation, fullsizeWidth, 60);
\r
180 mg.drawImage(consensus, 0, sequencesHeight, width,
\r
181 sequencesHeight + graphHeight, 0, 0, fullsizeWidth, 60, this);
\r
184 boolean oldRenderGaps = av.renderGaps;
\r
186 // We'll have to draw the full size alignment in chunks, as an image of the
\r
187 // whole alignment requires too much memory
\r
189 // Max size depends on the font size, the following is a
\r
190 // guess at a size which works
\r
191 int maxSize = 2000 / av.getFont().getSize();
\r
192 BufferedImage block;
\r
193 int blockx=0, blocky=0, blockw=0, blockh=0, eRes=0, eSeq=0;
\r
195 av.setRenderGaps(false);
\r
196 for(int sRes=0, chunkx=0; sRes<alwidth; sRes+=maxSize, chunkx++)
\r
203 for(int sSeq=0, chunky=0; sSeq<alheight; sSeq+=maxSize, chunky++)
\r
210 blockx = (int)((float)sRes/(float)alwidth * width);
\r
212 block = new BufferedImage((eRes-sRes)*av.charWidth,
\r
213 (eSeq-sSeq)*av.charHeight,
\r
214 BufferedImage.TYPE_3BYTE_BGR);
\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(),block.getHeight(), 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
256 public void paintComponent(Graphics g)
\r
258 g.setColor(Color.white);
\r
259 g.fillRect(0,0,getWidth(),getHeight());
\r
260 g.setColor(Color.black);
\r
264 g.setFont(new Font("Verdana", Font.BOLD, 15));
\r
265 g.drawString("Recalculating", 5, sequencesHeight/2);
\r
266 g.drawString("Overview.....", 5, sequencesHeight/2 +20);
\r
271 g.drawImage(miniMe, 0,0,this);
\r
273 g.setColor(Color.red);
\r
274 g.drawRect(boxX, boxY, boxWidth, boxHeight);
\r
275 g.drawRect(boxX+1, boxY+1, boxWidth-2, boxHeight-2);
\r