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
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
187 if (av.showSequenceFeatures)
\r
189 fr.featureGroups = ap.seqPanel.seqCanvas.getFeatureRenderer().featureGroups;
\r
190 fr.featureColours = ap.seqPanel.seqCanvas.getFeatureRenderer().featureColours;
\r
195 if ( (getSize().width > 0) && (getSize().height > 0))
\r
197 width = getSize().width;
\r
198 sequencesHeight = getSize().height - graphHeight;
\r
200 setSize(new Dimension(width, sequencesHeight + graphHeight));
\r
203 Thread thread = new Thread(this);
\r
208 // This is set true if the user resizes whilst
\r
209 // the overview is being calculated
\r
210 boolean resizeAgain = false;
\r
215 int alwidth = av.alignment.getWidth();
\r
216 int alheight = av.alignment.getHeight();
\r
218 if (av.showSequenceFeatures)
\r
220 fr.renderOrder = ap.seqPanel.seqCanvas.getFeatureRenderer().renderOrder;
\r
221 fr.featureGroups = ap.seqPanel.seqCanvas.getFeatureRenderer().featureGroups;
\r
222 fr.featureColours = ap.seqPanel.seqCanvas.getFeatureRenderer().featureColours;
\r
223 fr.sequenceFeatures = ap.seqPanel.seqCanvas.getFeatureRenderer().sequenceFeatures;
\r
226 if (getSize().width > 0 && getSize().height > 0)
\r
228 width = getSize().width;
\r
229 sequencesHeight = getSize().height - graphHeight;
\r
232 setSize(new Dimension(width, sequencesHeight + graphHeight));
\r
234 int fullsizeWidth = alwidth * av.getCharWidth();
\r
235 int fullsizeHeight = alheight * av.getCharHeight();
\r
237 scalew = (float) width / (float) fullsizeWidth;
\r
238 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
\r
240 miniMe = nullFrame.createImage(width, sequencesHeight + graphHeight);
\r
242 Graphics mg = miniMe.getGraphics();
\r
243 float sampleCol = (float) alwidth / (float) width;
\r
244 float sampleRow = (float) alheight / (float) sequencesHeight;
\r
246 int lastcol=0, lastseq=0;
\r
247 int xstart=0, ystart=0;
\r
248 Color color = Color.yellow;
\r
249 int col, sameRow = 0, sameCol = 0;
\r
250 jalview.datamodel.SequenceI sequence;
\r
252 for (int row = 0; row <= sequencesHeight; row++)
\r
254 if((int)(row*sampleRow)==lastseq)
\r
260 sequence = av.getAlignment().getSequenceAt(lastseq);
\r
262 for (col = 0; col < width; col++)
\r
264 if((int)(col*sampleCol) == lastcol)
\r
270 lastcol = (int)(col*sampleCol);
\r
272 if(sequence.getLength()>lastcol)
\r
274 color = sr.findSequenceColour(sequence, lastcol);
\r
276 if (av.showSequenceFeatures)
\r
277 color = fr.findFeatureColour(color,
\r
282 color = color.white;
\r
284 mg.setColor(color);
\r
285 if (sameCol == 1 && sameRow == 1)
\r
286 mg.drawLine(xstart, ystart, xstart, ystart);
\r
288 mg.fillRect(xstart, ystart, sameCol, sameRow);
\r
295 lastseq = (int)(row*sampleRow);
\r
300 if (av.conservation != null)
\r
302 for (col = 0; col < width; col++)
\r
304 lastcol = (int) (col * sampleCol);
\r
306 mg.translate(col, sequencesHeight);
\r
307 ap.annotationPanel.drawGraph(mg, av.conservation,
\r
308 (int) (sampleCol) + 1,
\r
310 (int) (col * sampleCol),
\r
311 (int) (col * sampleCol) + 1);
\r
312 mg.translate( -col, -sequencesHeight);
\r
327 resizeAgain = false;
\r
328 updateOverviewImage();
\r
332 public void setBoxPosition()
\r
334 int fullsizeWidth = av.alignment.getWidth() * av.getCharWidth();
\r
335 int fullsizeHeight = av.alignment.getHeight() * av.getCharHeight();
\r
337 scalew = (float) width / (float) fullsizeWidth;
\r
338 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
\r
340 boxX = (int) (av.getStartRes() * av.getCharWidth() * scalew);
\r
341 boxY = (int) (av.getStartSeq() * av.getCharHeight() * scaleh);
\r
342 boxWidth = (int) ( (av.getEndRes() - av.getStartRes() + 1) *
\r
343 av.getCharWidth() * scalew);
\r
344 boxHeight = (int) (av.getEndSeq() * av.getCharHeight() * scaleh) - boxY;
\r
348 public void update(Graphics g)
\r
353 public void paint(Graphics g)
\r
355 if (miniMe != null)
\r
357 g.drawImage(miniMe, 0, 0, this);
\r
361 g.setColor(Color.white);
\r
362 g.fillRect(0, 0, getSize().width, getSize().height);
\r
363 g.setColor(Color.black);
\r
364 g.setFont(new Font("Verdana", Font.BOLD, 15));
\r
365 g.drawString("Recalculating", 5, sequencesHeight / 2);
\r
366 g.drawString("Overview.....", 5, (sequencesHeight / 2) + 20);
\r
369 g.setColor(Color.red);
\r
370 g.drawRect(boxX, boxY, boxWidth, boxHeight);
\r
371 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
\r