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.drawText = false;
\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
186 if (av.showSequenceFeatures)
\r
188 fr.featuresDisplayed = ap.seqPanel.seqCanvas.getFeatureRenderer().
\r
190 fr.featureGroups = ap.seqPanel.seqCanvas.getFeatureRenderer().featureGroups;
\r
191 fr.featureColours = ap.seqPanel.seqCanvas.getFeatureRenderer().featureColours;
\r
197 if ( (getSize().width > 0) && (getSize().height > 0))
\r
199 width = getSize().width;
\r
200 sequencesHeight = getSize().height - graphHeight;
\r
202 setSize(new Dimension(width, sequencesHeight + graphHeight));
\r
205 Thread thread = new Thread(this);
\r
210 // This is set true if the user resizes whilst
\r
211 // the overview is being calculated
\r
212 boolean resizeAgain = false;
\r
217 int alwidth = av.alignment.getWidth();
\r
218 int alheight = av.alignment.getHeight();
\r
220 if (getSize().width > 0 && getSize().height > 0)
\r
222 width = getSize().width;
\r
223 sequencesHeight = getSize().height - graphHeight;
\r
226 setSize(new Dimension(width, sequencesHeight + graphHeight));
\r
228 int fullsizeWidth = alwidth * av.getCharWidth();
\r
229 int fullsizeHeight = alheight * av.getCharHeight();
\r
231 scalew = (float) width / (float) fullsizeWidth;
\r
232 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
\r
234 miniMe = nullFrame.createImage(width, sequencesHeight + graphHeight);
\r
236 Graphics mg = miniMe.getGraphics();
\r
237 float sampleCol = (float) alwidth / (float) width;
\r
238 float sampleRow = (float) alheight / (float) sequencesHeight;
\r
240 int lastcol=-1, lastrow=-1;
\r
241 Color color = Color.yellow;
\r
243 for (col = 0; col < width; col++)
\r
245 for (row = 0; row < sequencesHeight; row++)
\r
247 if((int)(col*sampleCol) == lastcol && (int)(row*sampleRow)==lastrow)
\r
249 mg.drawLine(col, row, col, row);
\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
264 lastrow = (int)(row*sampleRow);
\r
265 lastcol = (int)(col*sampleCol);
\r
267 if(av.alignment.getSequenceAt(lastrow).getLength()>lastcol)
\r
269 color = sr.findSequenceColour(av.alignment.getSequenceAt(lastrow), lastcol);
\r
272 if (av.showSequenceFeatures)
\r
273 color = fr.findFeatureColour(color,
\r
274 av.alignment.getSequenceAt(lastrow),
\r
278 mg.setColor(color);
\r
279 mg.drawLine(col,row,col,row);
\r
293 resizeAgain = false;
\r
294 updateOverviewImage();
\r
298 public void setBoxPosition()
\r
300 int fullsizeWidth = av.alignment.getWidth() * av.getCharWidth();
\r
301 int fullsizeHeight = av.alignment.getHeight() * av.getCharHeight();
\r
303 scalew = (float) width / (float) fullsizeWidth;
\r
304 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
\r
306 boxX = (int) (av.getStartRes() * av.getCharWidth() * scalew);
\r
307 boxY = (int) (av.getStartSeq() * av.getCharHeight() * scaleh);
\r
308 boxWidth = (int) ( (av.getEndRes() - av.getStartRes() + 1) *
\r
309 av.getCharWidth() * scalew);
\r
310 boxHeight = (int) (av.getEndSeq() * av.getCharHeight() * scaleh) - boxY;
\r
314 public void update(Graphics g)
\r
319 public void paint(Graphics g)
\r
321 if (miniMe != null)
\r
323 g.drawImage(miniMe, 0, 0, this);
\r
327 g.setColor(Color.white);
\r
328 g.fillRect(0, 0, getSize().width, getSize().height);
\r
329 g.setColor(Color.black);
\r
330 g.setFont(new Font("Verdana", Font.BOLD, 15));
\r
331 g.drawString("Recalculating", 5, sequencesHeight / 2);
\r
332 g.drawString("Overview.....", 5, (sequencesHeight / 2) + 20);
\r
335 g.setColor(Color.red);
\r
336 g.drawRect(boxX, boxY, boxWidth, boxHeight);
\r
337 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
\r