2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.appletgui;
23 import jalview.datamodel.SequenceI;
24 import jalview.viewmodel.OverviewDimensions;
26 import java.awt.Color;
27 import java.awt.Dimension;
28 import java.awt.Frame;
29 import java.awt.Graphics;
30 import java.awt.Image;
31 import java.awt.Panel;
32 import java.awt.event.ComponentAdapter;
33 import java.awt.event.ComponentEvent;
34 import java.awt.event.MouseEvent;
35 import java.awt.event.MouseListener;
36 import java.awt.event.MouseMotionListener;
38 public class OverviewPanel extends Panel implements Runnable,
39 MouseMotionListener, MouseListener
41 private OverviewDimensions od;
45 private Image offscreen;
47 private AlignViewport av;
49 private AlignmentPanel ap;
51 private boolean resizing = false;
53 // This is set true if the user resizes whilst
54 // the overview is being calculated
55 private boolean resizeAgain = false;
57 // Can set different properties in this seqCanvas than
58 // main visible SeqCanvas
59 private SequenceRenderer sr;
61 private FeatureRenderer fr;
63 private Frame nullFrame;
65 public OverviewPanel(AlignmentPanel alPanel)
70 nullFrame = new Frame();
71 nullFrame.addNotify();
73 sr = new SequenceRenderer(av);
74 sr.graphics = nullFrame.getGraphics();
75 sr.renderGaps = false;
76 sr.forOverview = true;
77 fr = new FeatureRenderer(av);
79 od = new OverviewDimensions(av.getPosProps(), av.isShowAnnotation());
81 setSize(new Dimension(od.getWidth(), od.getHeight()));
82 addComponentListener(new ComponentAdapter()
86 public void componentResized(ComponentEvent evt)
88 if ((getWidth() != od.getWidth())
89 || (getHeight() != (od.getHeight())))
91 updateOverviewImage();
96 addMouseMotionListener(this);
98 addMouseListener(this);
100 updateOverviewImage();
105 public void mouseEntered(MouseEvent evt)
110 public void mouseExited(MouseEvent evt)
115 public void mouseClicked(MouseEvent evt)
120 public void mouseMoved(MouseEvent evt)
125 public void mousePressed(MouseEvent evt)
131 public void mouseReleased(MouseEvent evt)
137 public void mouseDragged(MouseEvent evt)
142 private void mouseAction(MouseEvent evt)
144 od.updateViewportFromMouse(evt.getX(), evt.getY(), av.getAlignment()
145 .getHiddenSequences(), av.getColumnSelection(), av
147 ap.setScrollValues(od.getScrollCol(), od.getScrollRow());
148 ap.paintAlignment(false);
152 * Updates the overview image when the related alignment panel is updated
154 public void updateOverviewImage()
162 if (av.isShowSequenceFeatures())
164 fr.transferSettings(ap.seqPanel.seqCanvas.fr);
169 if ((getWidth() > 0) && (getHeight() > 0))
171 od.setWidth(getWidth());
172 od.setHeight(getHeight());
174 setSize(new Dimension(od.getWidth(), od.getHeight()));
176 Thread thread = new Thread(this);
186 if (av.isShowSequenceFeatures())
188 fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer());
191 if (getSize().width > 0 && getSize().height > 0)
193 od.setWidth(getSize().width);
194 od.setHeight(getSize().height - od.getGraphHeight());
197 setSize(new Dimension(od.getWidth(), od.getHeight()));
199 miniMe = nullFrame.createImage(od.getWidth(), od.getHeight());
200 offscreen = nullFrame.createImage(od.getWidth(), od.getHeight());
202 Graphics mg = miniMe.getGraphics();
204 int alwidth = av.getAlignment().getWidth();
205 int alheight = av.getAlignment().getAbsoluteHeight();
206 float sampleCol = alwidth / (float) od.getWidth();
207 float sampleRow = alheight / (float) od.getSequencesHeight();
209 buildImage(sampleRow, sampleCol, mg);
211 if (av.isShowAnnotation())
213 for (int col = 0; col < od.getWidth() && !resizeAgain; col++)
215 mg.translate(col, od.getSequencesHeight());
216 ap.annotationPanel.renderer.drawGraph(mg,
217 av.getAlignmentConservationAnnotation(),
218 av.getAlignmentConservationAnnotation().annotations,
219 (int) (sampleCol) + 1, od.getGraphHeight(),
220 (int) (col * sampleCol), (int) (col * sampleCol) + 1);
221 mg.translate(-col, -od.getSequencesHeight());
233 updateOverviewImage();
238 * Build the overview panel image
240 private void buildImage(float sampleRow, float sampleCol, Graphics mg)
246 Color color = Color.yellow;
250 SequenceI seq = null;
252 final boolean hasHiddenCols = av.hasHiddenColumns();
253 boolean hiddenRow = false;
255 for (int row = 0; row <= od.getSequencesHeight() && !resizeAgain; row++)
257 if ((int) (row * sampleRow) == lastrow)
263 // get the sequence which would be at alignment index 'lastrow' if no
264 // columns were hidden, and determine whether it is hidden or not
265 hiddenRow = av.getAlignment().isHidden(lastrow);
266 seq = av.getAlignment().getSequenceAtAbsoluteIndex(lastrow);
268 for (int col = 0; col < od.getWidth(); col++)
270 if ((int) (col * sampleCol) == lastcol
271 && (int) (row * sampleRow) == lastrow)
277 lastcol = (int) (col * sampleCol);
279 color = getColumnColourFromSequence(seq, hiddenRow,
280 hasHiddenCols, lastcol);
283 if (sameCol == 1 && sameRow == 1)
285 mg.drawLine(xstart, ystart, xstart, ystart);
289 mg.fillRect(xstart, ystart, sameCol, sameRow);
296 lastrow = (int) (row * sampleRow);
304 * Find the colour of a sequence at a specified column position
306 private Color getColumnColourFromSequence(
307 jalview.datamodel.SequenceI seq, boolean hiddenRow,
308 boolean hasHiddenCols, int lastcol)
311 if (seq.getLength() > lastcol)
313 color = sr.getResidueBoxColour(seq, lastcol);
315 if (av.isShowSequenceFeatures())
317 color = fr.findFeatureColour(color, seq, lastcol);
326 || (hasHiddenCols && !av.getColumnSelection()
327 .isVisible(lastcol)))
329 color = color.darker().darker();
335 * Update the overview panel box when the associated alignment panel is
339 public void setBoxPosition()
341 od.setBoxPosition(av.getAlignment()
342 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
347 public void update(Graphics g)
353 public void paint(Graphics g)
355 Graphics og = offscreen.getGraphics();
358 og.drawImage(miniMe, 0, 0, this);
359 og.setColor(Color.red);
361 g.drawImage(offscreen, 0, 0, this);