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;
25 import jalview.datamodel.AlignmentI;
26 import jalview.renderer.seqfeatures.FeatureColourFinder;
28 import java.awt.Color;
29 import java.awt.Dimension;
30 import java.awt.Frame;
31 import java.awt.Graphics;
32 import java.awt.Image;
33 import java.awt.Panel;
34 import java.awt.event.ComponentAdapter;
35 import java.awt.event.ComponentEvent;
36 import java.awt.event.MouseEvent;
37 import java.awt.event.MouseListener;
38 import java.awt.event.MouseMotionListener;
40 public class OverviewPanel extends Panel implements Runnable,
41 MouseMotionListener, MouseListener
43 private OverviewDimensions od;
47 private Image offscreen;
49 private AlignViewport av;
51 private AlignmentPanel ap;
53 private boolean resizing = false;
55 // This is set true if the user resizes whilst
56 // the overview is being calculated
57 private boolean resizeAgain = false;
59 // Can set different properties in this seqCanvas than
60 // main visible SeqCanvas
61 private SequenceRenderer sr;
63 private FeatureRenderer fr;
65 private Frame nullFrame;
67 public OverviewPanel(AlignmentPanel alPanel)
72 nullFrame = new Frame();
73 nullFrame.addNotify();
75 sr = new SequenceRenderer(av);
76 sr.graphics = nullFrame.getGraphics();
77 sr.renderGaps = false;
78 sr.forOverview = true;
79 fr = new FeatureRenderer(av);
81 od = new OverviewDimensions(av.getRanges(), av.isShowAnnotation());
83 setSize(new Dimension(od.getWidth(), od.getHeight()));
84 addComponentListener(new ComponentAdapter()
88 public void componentResized(ComponentEvent evt)
90 if ((getWidth() != od.getWidth())
91 || (getHeight() != (od.getHeight())))
93 updateOverviewImage();
98 addMouseMotionListener(this);
100 addMouseListener(this);
102 updateOverviewImage();
107 public void mouseEntered(MouseEvent evt)
112 public void mouseExited(MouseEvent evt)
117 public void mouseClicked(MouseEvent evt)
122 public void mouseMoved(MouseEvent evt)
127 public void mousePressed(MouseEvent evt)
133 public void mouseReleased(MouseEvent evt)
139 public void mouseDragged(MouseEvent evt)
144 private void mouseAction(MouseEvent evt)
146 od.updateViewportFromMouse(evt.getX(), evt.getY(), av.getAlignment()
147 .getHiddenSequences(), av.getColumnSelection(), av
149 ap.setScrollValues(od.getScrollCol(), od.getScrollRow());
150 ap.paintAlignment(false);
154 * Updates the overview image when the related alignment panel is updated
156 public void updateOverviewImage()
164 if (av.isShowSequenceFeatures())
166 fr.transferSettings(ap.seqPanel.seqCanvas.fr);
171 if ((getSize().width > 0) && (getSize().height > 0))
173 od.setWidth(getSize().width);
174 od.setHeight(getSize().height);
176 setSize(new Dimension(od.getWidth(), od.getHeight()));
178 Thread thread = new Thread(this);
188 if (av.isShowSequenceFeatures())
190 fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer());
193 if (getSize().width > 0 && getSize().height > 0)
195 od.setWidth(getSize().width);
196 od.setHeight(getSize().height);
199 setSize(new Dimension(od.getWidth(), od.getHeight()));
201 miniMe = nullFrame.createImage(od.getWidth(), od.getHeight());
202 offscreen = nullFrame.createImage(od.getWidth(), od.getHeight());
204 Graphics mg = miniMe.getGraphics();
207 int alwidth = av.getAlignment().getWidth();
208 int alheight = av.getAlignment().getAbsoluteHeight();
209 float sampleCol = alwidth / (float) od.getWidth();
210 float sampleRow = alheight / (float) od.getSequencesHeight();
212 float sampleCol = (float) alwidth / (float) width;
213 float sampleRow = (float) alheight / (float) sequencesHeight;
215 int lastcol = 0, lastrow = 0;
216 int xstart = 0, ystart = 0;
217 Color color = Color.yellow;
218 int row, col, sameRow = 0, sameCol = 0;
219 jalview.datamodel.SequenceI seq;
220 final boolean hasHiddenRows = av.hasHiddenRows(), hasHiddenCols = av
222 boolean hiddenRow = false;
223 AlignmentI alignment = av.getAlignment();
225 FeatureColourFinder finder = new FeatureColourFinder(fr);
226 for (row = 0; row <= sequencesHeight; row++)
232 if ((int) (row * sampleRow) == lastrow)
241 seq = alignment.getHiddenSequences().getHiddenSequence(lastrow);
244 int index = alignment.getHiddenSequences()
245 .findIndexWithoutHiddenSeqs(lastrow);
247 seq = alignment.getSequenceAt(index);
256 seq = alignment.getSequenceAt(lastrow);
259 for (col = 0; col < width; col++)
261 if ((int) (col * sampleCol) == lastcol
262 && (int) (row * sampleRow) == lastrow)
268 lastcol = (int) (col * sampleCol);
270 if (seq.getLength() > lastcol)
272 color = sr.getResidueColour(seq, lastcol, finder);
280 || (hasHiddenCols && !av.getColumnSelection().isVisible(
283 color = color.darker().darker();
287 if (sameCol == 1 && sameRow == 1)
289 mg.drawLine(xstart, ystart, xstart, ystart);
293 mg.fillRect(xstart, ystart, sameCol, sameRow);
295 >>>>>>> bug/JAL-2436featureRendererThreading
297 buildImage(sampleRow, sampleCol, mg);
299 if (av.isShowAnnotation())
301 for (int col = 0; col < od.getWidth() && !resizeAgain; col++)
303 mg.translate(col, od.getSequencesHeight());
304 ap.annotationPanel.renderer.drawGraph(mg,
305 av.getAlignmentConservationAnnotation(),
306 av.getAlignmentConservationAnnotation().annotations,
307 (int) (sampleCol) + 1, od.getGraphHeight(),
308 (int) (col * sampleCol), (int) (col * sampleCol) + 1);
309 mg.translate(-col, -od.getSequencesHeight());
321 updateOverviewImage();
326 * Build the overview panel image
328 private void buildImage(float sampleRow, float sampleCol, Graphics mg)
334 Color color = Color.yellow;
338 SequenceI seq = null;
340 final boolean hasHiddenCols = av.hasHiddenColumns();
341 boolean hiddenRow = false;
343 for (int row = 0; row <= od.getSequencesHeight() && !resizeAgain; row++)
345 if ((int) (row * sampleRow) == lastrow)
351 // get the sequence which would be at alignment index 'lastrow' if no
352 // columns were hidden, and determine whether it is hidden or not
353 hiddenRow = av.getAlignment().isHidden(lastrow);
354 seq = av.getAlignment().getSequenceAtAbsoluteIndex(lastrow);
356 for (int col = 0; col < od.getWidth(); col++)
358 if ((int) (col * sampleCol) == lastcol
359 && (int) (row * sampleRow) == lastrow)
365 lastcol = (int) (col * sampleCol);
367 color = getColumnColourFromSequence(seq, hiddenRow,
368 hasHiddenCols, lastcol);
371 if (sameCol == 1 && sameRow == 1)
373 mg.drawLine(xstart, ystart, xstart, ystart);
377 mg.fillRect(xstart, ystart, sameCol, sameRow);
384 lastrow = (int) (row * sampleRow);
392 * Find the colour of a sequence at a specified column position
394 private Color getColumnColourFromSequence(
395 jalview.datamodel.SequenceI seq, boolean hiddenRow,
396 boolean hasHiddenCols, int lastcol)
399 if (seq.getLength() > lastcol)
401 color = sr.getResidueBoxColour(seq, lastcol);
403 if (av.isShowSequenceFeatures())
405 color = fr.findFeatureColour(color, seq, lastcol);
414 || (hasHiddenCols && !av.getColumnSelection()
415 .isVisible(lastcol)))
417 color = color.darker().darker();
423 * Update the overview panel box when the associated alignment panel is
427 public void setBoxPosition()
429 od.setBoxPosition(av.getAlignment()
430 .getHiddenSequences(), av.getColumnSelection(), av.getRanges());
435 public void update(Graphics g)
441 public void paint(Graphics g)
443 Graphics og = offscreen.getGraphics();
446 og.drawImage(miniMe, 0, 0, this);
447 og.setColor(Color.red);
449 g.drawImage(offscreen, 0, 0, this);