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, MouseMotionListener, MouseListener
\r
34 public int width, sequencesHeight;
\r
35 int graphHeight = 20;
\r
36 int boxX = -1, boxY = -1, boxWidth = -1, boxHeight = -1;
\r
38 boolean resizing = false;
\r
40 // Can set different properties in this seqCanvas than
\r
41 // main visible SeqCanvas
\r
42 SequenceRenderer sr;
\r
48 public OverviewPanel(AlignmentPanel ap)
\r
53 nullFrame = new Frame();
\r
54 nullFrame.addNotify();
\r
57 sr = new SequenceRenderer(av);
\r
58 sr.graphics = nullFrame.getGraphics();
\r
59 sr.renderGaps( false );
\r
60 fr = new FeatureRenderer(av);
\r
61 fr.transparency = ap.seqPanel.seqCanvas.getFeatureRenderer().transparency;
\r
62 fr.featuresDisplayed = ap.seqPanel.seqCanvas.getFeatureRenderer().featuresDisplayed;
\r
65 // scale the initial size of overviewpanel to shape of alignment
\r
66 float initialScale = (float) av.alignment.getWidth() /
\r
67 (float) av.alignment.getHeight();
\r
69 if(av.vconsensus==null)
\r
72 if (av.alignment.getWidth() > av.alignment.getHeight())
\r
76 sequencesHeight = (int) (400f / initialScale);
\r
77 if(sequencesHeight<40)
\r
78 sequencesHeight = 40;
\r
83 width = (int) (400f * initialScale);
\r
84 sequencesHeight = 300;
\r
91 setSize(new Dimension(width, sequencesHeight + graphHeight));
\r
92 addComponentListener(new ComponentAdapter()
\r
95 public void componentResized(ComponentEvent evt)
\r
97 if (getSize().width != width ||
\r
98 getSize().height != sequencesHeight + graphHeight)
\r
100 updateOverviewImage();
\r
105 addMouseMotionListener(this);
\r
107 addMouseListener(this);
\r
109 updateOverviewImage();
\r
114 public void mouseEntered(MouseEvent evt)
\r
116 public void mouseExited(MouseEvent evt)
\r
118 public void mouseClicked(MouseEvent evt)
\r
120 public void mouseMoved(MouseEvent evt)
\r
122 public void mousePressed(MouseEvent evt)
\r
131 public void mouseReleased(MouseEvent evt)
\r
136 ap.setScrollValues( (int) (boxX / scalew / av.getCharWidth()),
\r
137 (int) (boxY / scaleh / av.getCharHeight()));
\r
140 public void mouseDragged(MouseEvent evt)
\r
145 ap.setScrollValues( (int) (boxX / scalew / av.getCharWidth()),
\r
146 (int) (boxY / scaleh / av.getCharHeight()));
\r
159 if (boxY > sequencesHeight - boxHeight)
\r
161 boxY = sequencesHeight - boxHeight + 1;
\r
169 if (boxX > width - boxWidth)
\r
171 boxX = width - boxWidth;
\r
178 public void updateOverviewImage()
\r
182 resizeAgain = true;
\r
188 if ( (getSize().width > 0) && (getSize().height > 0))
\r
190 width = getSize().width;
\r
191 sequencesHeight = getSize().height - graphHeight;
\r
193 setSize(new Dimension(width, sequencesHeight + graphHeight));
\r
196 Thread thread = new Thread(this);
\r
201 // This is set true if the user resizes whilst
\r
202 // the overview is being calculated
\r
203 boolean resizeAgain = false;
\r
208 int alwidth = av.alignment.getWidth();
\r
209 int alheight = av.alignment.getHeight();
\r
211 if (getSize().width > 0 && getSize().height > 0)
\r
213 width = getSize().width;
\r
214 sequencesHeight = getSize().height - graphHeight;
\r
217 setSize(new Dimension(width, sequencesHeight + graphHeight));
\r
219 int fullsizeWidth = alwidth * av.getCharWidth();
\r
220 int fullsizeHeight = alheight * av.getCharHeight();
\r
222 scalew = (float) width / (float) fullsizeWidth;
\r
223 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
\r
225 miniMe = nullFrame.createImage(width, sequencesHeight + graphHeight);
\r
227 Graphics mg = miniMe.getGraphics();
\r
228 float sampleCol = (float) alwidth / (float) width;
\r
229 float sampleRow = (float) alheight / (float) sequencesHeight;
\r
231 int lastcol=-1, lastrow=-1;
\r
232 Color color = Color.white;
\r
233 for (int col = 0; col < width; col++)
\r
235 for (int row = 0; row < sequencesHeight; row++)
\r
237 if((int)(col*sampleCol) == lastcol && (int)(row*sampleRow)==lastrow)
\r
239 mg.setColor(color);
\r
240 mg.fillRect(col,row,1,1);
\r
244 lastrow = (int)(row*sampleRow);
\r
245 lastcol = (int)(col*sampleCol);
\r
247 if(av.alignment.getSequenceAt(lastrow).getLength()>lastcol)
\r
249 color = sr.findSequenceColour(av.alignment.getSequenceAt(lastrow), lastcol);
\r
251 if (av.showSequenceFeatures)
\r
252 color = fr.findFeatureColour(color,
\r
253 av.alignment.getSequenceAt(lastrow),
\r
258 mg.setColor(color);
\r
259 mg.fillRect(col,row,1,1);
\r
261 if (av.conservation != null)
\r
263 mg.translate(col, sequencesHeight);
\r
264 ap.annotationPanel.drawGraph(mg, av.conservation,
\r
265 (int) (sampleCol) + 1,
\r
267 (int) (col * sampleCol),
\r
268 (int) (col * sampleCol) + 1);
\r
269 mg.translate(-col, -sequencesHeight);
\r
282 resizeAgain = false;
\r
283 updateOverviewImage();
\r
287 public void setBoxPosition()
\r
289 int fullsizeWidth = av.alignment.getWidth() * av.getCharWidth();
\r
290 int fullsizeHeight = av.alignment.getHeight() * av.getCharHeight();
\r
292 scalew = (float) width / (float) fullsizeWidth;
\r
293 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
\r
295 boxX = (int) (av.getStartRes() * av.getCharWidth() * scalew);
\r
296 boxY = (int) (av.getStartSeq() * av.getCharHeight() * scaleh);
\r
297 boxWidth = (int) ( (av.getEndRes() - av.getStartRes() + 1) *
\r
298 av.getCharWidth() * scalew);
\r
299 boxHeight = (int) (av.getEndSeq() * av.getCharHeight() * scaleh) - boxY;
\r
303 public void update(Graphics g)
\r
308 public void paint(Graphics g)
\r
310 if (miniMe != null)
\r
312 g.drawImage(miniMe, 0, 0, this);
\r
316 g.setColor(Color.white);
\r
317 g.fillRect(0, 0, getSize().width, getSize().height);
\r
318 g.setColor(Color.black);
\r
319 g.setFont(new Font("Verdana", Font.BOLD, 15));
\r
320 g.drawString("Recalculating", 5, sequencesHeight / 2);
\r
321 g.drawString("Overview.....", 5, (sequencesHeight / 2) + 20);
\r
324 g.setColor(Color.red);
\r
325 g.drawRect(boxX, boxY, boxWidth, boxHeight);
\r
326 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
\r