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
19 package jalview.gui;
\r
22 import java.awt.event.*;
\r
23 import java.awt.image.*;
\r
25 import javax.swing.*;
\r
32 * @version $Revision$
\r
34 public class OverviewPanel extends JPanel implements Runnable
\r
36 BufferedImage miniMe;
\r
42 int sequencesHeight;
\r
43 int graphHeight = 20;
\r
48 boolean resizing = false;
\r
50 // Can set different properties in this seqCanvas than
\r
51 // main visible SeqCanvas
\r
52 SequenceRenderer sr;
\r
56 * Creates a new OverviewPanel object.
\r
58 * @param ap DOCUMENT ME!
\r
60 public OverviewPanel(AlignmentPanel ap)
\r
66 sr = new SequenceRenderer(av);
\r
67 sr.renderGaps( false );
\r
68 fr = new FeatureRenderer(av);
\r
69 fr.transparency = ap.seqPanel.seqCanvas.getFeatureRenderer().transparency;
\r
71 // scale the initial size of overviewpanel to shape of alignment
\r
72 float initialScale = (float) av.alignment.getWidth() / (float) av.alignment.getHeight();
\r
74 if(av.conservation==null)
\r
78 if (av.alignment.getWidth() > av.alignment.getHeight())
\r
82 sequencesHeight = (int) (400f / initialScale);
\r
83 if(sequencesHeight<40)
\r
84 sequencesHeight = 40;
\r
89 width = (int) (400f * initialScale);
\r
90 sequencesHeight = 300;
\r
98 addComponentListener(new ComponentAdapter()
\r
100 public void componentResized(ComponentEvent evt)
\r
102 if ((getWidth() != width) ||
\r
103 (getHeight() != (sequencesHeight + graphHeight)))
\r
105 updateOverviewImage();
\r
110 addMouseMotionListener(new MouseMotionAdapter()
\r
112 public void mouseDragged(MouseEvent evt)
\r
114 if(!av.wrapAlignment)
\r
115 doMouseDragged(evt);
\r
119 addMouseListener(new MouseAdapter()
\r
121 public void mousePressed(MouseEvent evt)
\r
123 if(!av.wrapAlignment)
\r
124 doMousePressed(evt);
\r
127 public void mouseReleased(MouseEvent evt)
\r
129 if(!av.wrapAlignment)
\r
130 doMouseReleased(evt);
\r
134 updateOverviewImage();
\r
140 * @param evt DOCUMENT ME!
\r
142 public void doMousePressed(MouseEvent evt)
\r
154 * @param evt DOCUMENT ME!
\r
156 public void doMouseReleased(MouseEvent evt)
\r
162 ap.setScrollValues((int) (boxX / scalew / av.getCharWidth()),
\r
163 (int) (boxY / scaleh / av.getCharHeight()));
\r
169 * @param evt DOCUMENT ME!
\r
171 public void doMouseDragged(MouseEvent evt)
\r
177 ap.setScrollValues( (int) (boxX / scalew / av.getCharWidth()),
\r
178 (int) (boxY / scaleh / av.getCharHeight()));
\r
192 if (boxY > (sequencesHeight - boxHeight))
\r
194 boxY = sequencesHeight - boxHeight + 1;
\r
202 if (boxX > (width - boxWidth))
\r
204 boxX = width - boxWidth;
\r
211 public void updateOverviewImage()
\r
215 resizeAgain = true;
\r
221 if ( (getWidth() > 0) && (getHeight() > 0))
\r
223 width = getWidth();
\r
224 sequencesHeight = getHeight() - graphHeight;
\r
227 setPreferredSize(new Dimension(width, sequencesHeight + graphHeight));
\r
230 Thread thread = new Thread(this);
\r
235 // This is set true if the user resizes whilst
\r
236 // the overview is being calculated
\r
237 boolean resizeAgain = false;
\r
246 int alwidth = av.alignment.getWidth();
\r
247 int alheight = av.alignment.getHeight();
\r
249 setPreferredSize(new Dimension(width, sequencesHeight + graphHeight));
\r
251 int fullsizeWidth = alwidth * av.getCharWidth();
\r
252 int fullsizeHeight = alheight * av.getCharHeight();
\r
254 scalew = (float) width / (float) fullsizeWidth;
\r
255 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
\r
257 miniMe = new BufferedImage(width, sequencesHeight + graphHeight,
\r
258 BufferedImage.TYPE_INT_RGB);
\r
261 Graphics mg = miniMe.getGraphics();
\r
262 mg.setColor(Color.orange);
\r
263 mg.fillRect(0,0,width, miniMe.getHeight());
\r
265 float sampleCol = (float) alwidth / (float) width;
\r
266 float sampleRow = (float) alheight / (float) sequencesHeight;
\r
268 int lastcol=-1, lastrow=-1;
\r
269 Color color = Color.white;
\r
270 for (int col = 0; col < width; col++)
\r
272 for (int row = 0; row < sequencesHeight; row++)
\r
274 if((int)(col*sampleCol) == lastcol && (int)(row*sampleRow)==lastrow)
\r
276 miniMe.setRGB(col,row,color.getRGB());
\r
280 lastrow = (int)(row*sampleRow);
\r
281 lastcol = (int)(col*sampleCol);
\r
283 if(av.alignment.getSequenceAt(lastrow).getLength()>lastcol)
\r
285 color = sr.getResidueBoxColour(
\r
286 av.alignment.getSequenceAt(lastrow), lastcol);
\r
288 if(av.showSequenceFeatures)
\r
289 color = fr.findFeatureColour(color, av.alignment.getSequenceAt(lastrow),
\r
294 miniMe.setRGB(col,row,color.getRGB());
\r
296 if (av.conservation != null)
\r
298 mg.translate(col, sequencesHeight);
\r
299 ap.annotationPanel.drawGraph(mg, av.conservation,
\r
300 (int) (sampleCol) + 1,
\r
302 (int) (col * sampleCol),
\r
303 (int) (col * sampleCol) + 1);
\r
304 mg.translate(-col, -sequencesHeight);
\r
317 resizeAgain = false;
\r
318 updateOverviewImage();
\r
325 public void setBoxPosition()
\r
327 int fullsizeWidth = av.alignment.getWidth() * av.getCharWidth();
\r
328 int fullsizeHeight = av.alignment.getHeight() * av.getCharHeight();
\r
330 scalew = (float) width / (float) fullsizeWidth;
\r
331 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
\r
333 boxX = (int) (av.getStartRes() * av.getCharWidth() * scalew);
\r
334 boxY = (int) (av.getStartSeq() * av.getCharHeight() * scaleh);
\r
335 boxWidth = (int) ((av.getEndRes() - av.getStartRes() + 1) * av.getCharWidth() * scalew);
\r
336 boxHeight = (int) (av.getEndSeq() * av.getCharHeight() * scaleh) -
\r
344 * @param g DOCUMENT ME!
\r
346 public void paintComponent(Graphics g)
\r
348 if (miniMe != null && !resizing)
\r
350 g.drawImage(miniMe, 0, 0, this);
\r
354 g.setColor(Color.white);
\r
355 g.fillRect(0, 0, getWidth(), getHeight());
\r
356 g.setColor(Color.black);
\r
357 g.setFont(new Font("Verdana", Font.BOLD, 15));
\r
358 g.drawString("Recalculating", 5, sequencesHeight / 2);
\r
359 g.drawString("Overview.....", 5, (sequencesHeight / 2) + 20);
\r
363 g.setColor(Color.red);
\r
364 g.drawRect(boxX, boxY, boxWidth, boxHeight);
\r
365 g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
\r