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
43 //FeatureRenderer fr;
\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
66 // scale the initial size of overviewpanel to shape of alignment
\r
67 float initialScale = (float) av.alignment.getWidth() /
\r
68 (float) av.alignment.getHeight();
\r
70 if(av.vconsensus==null)
\r
73 if (av.alignment.getWidth() > av.alignment.getHeight())
\r
77 sequencesHeight = (int) (400f / initialScale);
\r
78 if(sequencesHeight<40)
\r
79 sequencesHeight = 40;
\r
84 width = (int) (400f * initialScale);
\r
85 sequencesHeight = 300;
\r
92 setSize(new Dimension(width, sequencesHeight + graphHeight));
\r
93 addComponentListener(new ComponentAdapter()
\r
96 public void componentResized(ComponentEvent evt)
\r
98 if (getSize().width != width ||
\r
99 getSize().height != sequencesHeight + graphHeight)
\r
101 updateOverviewImage();
\r
106 addMouseMotionListener(this);
\r
108 addMouseListener(this);
\r
110 updateOverviewImage();
\r
115 public void mouseEntered(MouseEvent evt)
\r
117 public void mouseExited(MouseEvent evt)
\r
119 public void mouseClicked(MouseEvent evt)
\r
121 public void mouseMoved(MouseEvent evt)
\r
123 public void mousePressed(MouseEvent evt)
\r
132 public void mouseReleased(MouseEvent evt)
\r
137 ap.setScrollValues( (int) (boxX / scalew / av.getCharWidth()),
\r
138 (int) (boxY / scaleh / av.getCharHeight()));
\r
141 public void mouseDragged(MouseEvent evt)
\r
146 ap.setScrollValues( (int) (boxX / scalew / av.getCharWidth()),
\r
147 (int) (boxY / scaleh / av.getCharHeight()));
\r
160 if (boxY > sequencesHeight - boxHeight)
\r
162 boxY = sequencesHeight - boxHeight + 1;
\r
170 if (boxX > width - boxWidth)
\r
172 boxX = width - boxWidth;
\r
179 public void updateOverviewImage()
\r
183 resizeAgain = true;
\r
189 if ( (getSize().width > 0) && (getSize().height > 0))
\r
191 width = getSize().width;
\r
192 sequencesHeight = getSize().height - graphHeight;
\r
194 setSize(new Dimension(width, sequencesHeight + graphHeight));
\r
197 Thread thread = new Thread(this);
\r
202 // This is set true if the user resizes whilst
\r
203 // the overview is being calculated
\r
204 boolean resizeAgain = false;
\r
209 int alwidth = av.alignment.getWidth();
\r
210 int alheight = av.alignment.getHeight();
\r
212 if (getSize().width > 0 && getSize().height > 0)
\r
214 width = getSize().width;
\r
215 sequencesHeight = getSize().height - graphHeight;
\r
218 setSize(new Dimension(width, sequencesHeight + graphHeight));
\r
220 int fullsizeWidth = alwidth * av.getCharWidth();
\r
221 int fullsizeHeight = alheight * av.getCharHeight();
\r
223 scalew = (float) width / (float) fullsizeWidth;
\r
224 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
\r
226 miniMe = nullFrame.createImage(width, sequencesHeight + graphHeight);
\r
228 Graphics mg = miniMe.getGraphics();
\r
229 float sampleCol = (float) alwidth / (float) width;
\r
230 float sampleRow = (float) alheight / (float) sequencesHeight;
\r
232 int lastcol=-1, lastrow=-1;
\r
233 Color color = Color.white;
\r
234 for (int col = 0; col < width; col++)
\r
236 for (int row = 0; row < sequencesHeight; row++)
\r
238 if((int)(col*sampleCol) == lastcol && (int)(row*sampleRow)==lastrow)
\r
240 mg.setColor(color);
\r
241 mg.fillRect(col,row,1,1);
\r
245 lastrow = (int)(row*sampleRow);
\r
246 lastcol = (int)(col*sampleCol);
\r
248 color = sr.findSequenceColour(av.alignment.getSequenceAt(lastrow), lastcol);
\r
250 mg.setColor(color);
\r
251 mg.fillRect(col,row,1,1);
\r
253 if (av.conservation != null)
\r
255 mg.translate(col, sequencesHeight);
\r
256 ap.annotationPanel.drawGraph(mg, av.conservation,
\r
257 (int) (sampleCol) + 1,
\r
259 (int) (col * sampleCol),
\r
260 (int) (col * sampleCol) + 1);
\r
261 mg.translate(-col, -sequencesHeight);
\r
274 resizeAgain = false;
\r
275 updateOverviewImage();
\r
279 public void setBoxPosition()
\r
281 int fullsizeWidth = av.alignment.getWidth() * av.getCharWidth();
\r
282 int fullsizeHeight = av.alignment.getHeight() * av.getCharHeight();
\r
284 scalew = (float) width / (float) fullsizeWidth;
\r
285 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
\r
287 boxX = (int) (av.getStartRes() * av.getCharWidth() * scalew);
\r
288 boxY = (int) (av.getStartSeq() * av.getCharHeight() * scaleh);
\r
289 boxWidth = (int) ( (av.getEndRes() - av.getStartRes() + 1) *
\r
290 av.getCharWidth() * scalew);
\r
291 boxHeight = (int) (av.getEndSeq() * av.getCharHeight() * scaleh) - boxY;
\r
295 public void update(Graphics g)
\r
300 public void paint(Graphics g)
\r
302 if (miniMe != null)
\r
304 g.drawImage(miniMe, 0, 0, this);
\r
308 g.setColor(Color.white);
\r
309 g.fillRect(0, 0, getSize().width, getSize().height);
\r
310 g.setColor(Color.black);
\r
311 g.setFont(new Font("Verdana", Font.BOLD, 15));
\r
312 g.drawString("Recalculating", 5, sequencesHeight / 2);
\r
313 g.drawString("Overview.....", 5, (sequencesHeight / 2) + 20);
\r
316 g.setColor(Color.red);
\r
317 g.drawRect(boxX, boxY, boxWidth, boxHeight);
\r
318 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
\r