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 sr.forOverview = true;
\r
61 fr = new FeatureRenderer(av);
\r
62 fr.drawText = false;
\r
67 // scale the initial size of overviewpanel to shape of alignment
\r
68 float initialScale = (float) av.alignment.getWidth() /
\r
69 (float) av.alignment.getHeight();
\r
71 if(av.vconsensus==null)
\r
74 if (av.alignment.getWidth() > av.alignment.getHeight())
\r
78 sequencesHeight = (int) (400f / initialScale);
\r
79 if(sequencesHeight<40)
\r
80 sequencesHeight = 40;
\r
85 width = (int) (400f * initialScale);
\r
86 sequencesHeight = 300;
\r
93 setSize(new Dimension(width, sequencesHeight + graphHeight));
\r
94 addComponentListener(new ComponentAdapter()
\r
97 public void componentResized(ComponentEvent evt)
\r
99 if (getSize().width != width ||
\r
100 getSize().height != sequencesHeight + graphHeight)
\r
102 updateOverviewImage();
\r
107 addMouseMotionListener(this);
\r
109 addMouseListener(this);
\r
111 updateOverviewImage();
\r
116 public void mouseEntered(MouseEvent evt)
\r
118 public void mouseExited(MouseEvent evt)
\r
120 public void mouseClicked(MouseEvent evt)
\r
122 public void mouseMoved(MouseEvent evt)
\r
124 public void mousePressed(MouseEvent evt)
\r
133 public void mouseReleased(MouseEvent evt)
\r
138 ap.setScrollValues( (int) (boxX / scalew / av.getCharWidth()),
\r
139 (int) (boxY / scaleh / av.getCharHeight()));
\r
142 public void mouseDragged(MouseEvent evt)
\r
147 ap.setScrollValues( (int) (boxX / scalew / av.getCharWidth()),
\r
148 (int) (boxY / scaleh / av.getCharHeight()));
\r
161 if (boxY > sequencesHeight - boxHeight)
\r
163 boxY = sequencesHeight - boxHeight + 1;
\r
171 if (boxX > width - boxWidth)
\r
173 boxX = width - boxWidth;
\r
180 public void updateOverviewImage()
\r
184 resizeAgain = true;
\r
188 if (av.showSequenceFeatures)
\r
190 fr.featureGroups = ap.seqPanel.seqCanvas.getFeatureRenderer().featureGroups;
\r
191 fr.featureColours = ap.seqPanel.seqCanvas.getFeatureRenderer().featureColours;
\r
192 fr.sequenceFeatures = ap.seqPanel.seqCanvas.getFeatureRenderer().sequenceFeatures;
\r
198 if ( (getSize().width > 0) && (getSize().height > 0))
\r
200 width = getSize().width;
\r
201 sequencesHeight = getSize().height - graphHeight;
\r
203 setSize(new Dimension(width, sequencesHeight + graphHeight));
\r
206 Thread thread = new Thread(this);
\r
211 // This is set true if the user resizes whilst
\r
212 // the overview is being calculated
\r
213 boolean resizeAgain = false;
\r
218 int alwidth = av.alignment.getWidth();
\r
219 int alheight = av.alignment.getHeight();
\r
221 if (getSize().width > 0 && getSize().height > 0)
\r
223 width = getSize().width;
\r
224 sequencesHeight = getSize().height - graphHeight;
\r
227 setSize(new Dimension(width, sequencesHeight + graphHeight));
\r
229 int fullsizeWidth = alwidth * av.getCharWidth();
\r
230 int fullsizeHeight = alheight * av.getCharHeight();
\r
232 scalew = (float) width / (float) fullsizeWidth;
\r
233 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
\r
235 miniMe = nullFrame.createImage(width, sequencesHeight + graphHeight);
\r
237 Graphics mg = miniMe.getGraphics();
\r
238 float sampleCol = (float) alwidth / (float) width;
\r
239 float sampleRow = (float) alheight / (float) sequencesHeight;
\r
241 int lastcol=-1, lastrow=0;
\r
242 Color color = Color.yellow;
\r
244 jalview.datamodel.SequenceI sequence;
\r
245 for (row = 0; row < sequencesHeight; row++)
\r
247 sequence = av.getAlignment().getSequenceAt(lastrow);
\r
248 for (col = 0; col < width; col++)
\r
250 if((int)(col*sampleCol) == lastcol && (int)(row*sampleRow)==lastrow)
\r
252 mg.drawLine(col, row, col, row);
\r
256 lastrow = (int)(row*sampleRow);
\r
257 lastcol = (int)(col*sampleCol);
\r
259 if(av.alignment.getSequenceAt(lastrow).getLength()>lastcol)
\r
262 color = sr.findSequenceColour(sequence, lastcol);
\r
264 if (av.showSequenceFeatures)
\r
265 color = fr.findFeatureColour(color,
\r
270 color = color.white;
\r
272 mg.setColor(color);
\r
273 mg.drawLine(col,row,col,row);
\r
278 if (av.conservation != null)
\r
280 for (col = 0; col < width; col++)
\r
282 lastcol = (int) (col * sampleCol);
\r
284 mg.translate(col, sequencesHeight);
\r
285 ap.annotationPanel.drawGraph(mg, av.conservation,
\r
286 (int) (sampleCol) + 1,
\r
288 (int) (col * sampleCol),
\r
289 (int) (col * sampleCol) + 1);
\r
290 mg.translate( -col, -sequencesHeight);
\r
305 resizeAgain = false;
\r
306 updateOverviewImage();
\r
310 public void setBoxPosition()
\r
312 int fullsizeWidth = av.alignment.getWidth() * av.getCharWidth();
\r
313 int fullsizeHeight = av.alignment.getHeight() * av.getCharHeight();
\r
315 scalew = (float) width / (float) fullsizeWidth;
\r
316 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
\r
318 boxX = (int) (av.getStartRes() * av.getCharWidth() * scalew);
\r
319 boxY = (int) (av.getStartSeq() * av.getCharHeight() * scaleh);
\r
320 boxWidth = (int) ( (av.getEndRes() - av.getStartRes() + 1) *
\r
321 av.getCharWidth() * scalew);
\r
322 boxHeight = (int) (av.getEndSeq() * av.getCharHeight() * scaleh) - boxY;
\r
326 public void update(Graphics g)
\r
331 public void paint(Graphics g)
\r
333 if (miniMe != null)
\r
335 g.drawImage(miniMe, 0, 0, this);
\r
339 g.setColor(Color.white);
\r
340 g.fillRect(0, 0, getSize().width, getSize().height);
\r
341 g.setColor(Color.black);
\r
342 g.setFont(new Font("Verdana", Font.BOLD, 15));
\r
343 g.drawString("Recalculating", 5, sequencesHeight / 2);
\r
344 g.drawString("Overview.....", 5, (sequencesHeight / 2) + 20);
\r
347 g.setColor(Color.red);
\r
348 g.drawRect(boxX, boxY, boxWidth, boxHeight);
\r
349 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
\r