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.viewmodel.OverviewDimensions;
25 import java.awt.Color;
26 import java.awt.Dimension;
27 import java.awt.Frame;
28 import java.awt.Graphics;
29 import java.awt.Image;
30 import java.awt.Panel;
31 import java.awt.event.ComponentAdapter;
32 import java.awt.event.ComponentEvent;
33 import java.awt.event.MouseEvent;
34 import java.awt.event.MouseListener;
35 import java.awt.event.MouseMotionListener;
37 public class OverviewPanel extends Panel implements Runnable,
38 MouseMotionListener, MouseListener
40 private OverviewDimensions od;
44 private Image offscreen;
46 private AlignViewport av;
48 private AlignmentPanel ap;
50 private boolean resizing = false;
52 // This is set true if the user resizes whilst
53 // the overview is being calculated
54 private boolean resizeAgain = false;
56 // Can set different properties in this seqCanvas than
57 // main visible SeqCanvas
58 private SequenceRenderer sr;
60 private FeatureRenderer fr;
62 private Frame nullFrame;
64 public OverviewPanel(AlignmentPanel ap)
69 nullFrame = new Frame();
70 nullFrame.addNotify();
72 sr = new SequenceRenderer(av);
73 sr.graphics = nullFrame.getGraphics();
74 sr.renderGaps = false;
75 sr.forOverview = true;
76 fr = new FeatureRenderer(av);
78 boolean showAnnotation = false;
79 // TODO: in applet this was getSequenceConsensusHash()
80 // check if it makes any functional difference: hconsensus or conservation
81 if (av.getAlignmentConservationAnnotation() == null)
83 showAnnotation = true;
86 od = new OverviewDimensions(av, showAnnotation);
88 setSize(new Dimension(od.getWidth(), od.getHeight()));
89 addComponentListener(new ComponentAdapter()
93 public void componentResized(ComponentEvent evt)
95 if ((getWidth() != od.getWidth())
96 || (getHeight() != (od.getHeight())))
98 updateOverviewImage();
103 addMouseMotionListener(this);
105 addMouseListener(this);
107 updateOverviewImage();
112 public void mouseEntered(MouseEvent evt)
117 public void mouseExited(MouseEvent evt)
122 public void mouseClicked(MouseEvent evt)
127 public void mouseMoved(MouseEvent evt)
132 public void mousePressed(MouseEvent evt)
138 public void mouseReleased(MouseEvent evt)
144 public void mouseDragged(MouseEvent evt)
149 private void mouseAction(MouseEvent evt)
151 od.updateViewportFromMouse(evt.getX(), evt.getY());
152 ap.setScrollValues(od.getScrollCol(), od.getScrollRow());
153 ap.paintAlignment(false);
159 public void updateOverviewImage()
167 if (av.isShowSequenceFeatures())
169 fr.transferSettings(ap.seqPanel.seqCanvas.fr);
174 if ((getWidth() > 0) && (getHeight() > 0))
176 od.setWidth(getWidth()); // width = getWidth();
177 od.setHeight(getHeight()); // sequencesHeight = getHeight() - graphHeight;
179 setSize(new Dimension(od.getWidth(), od.getHeight()));
181 Thread thread = new Thread(this);
191 if (av.isShowSequenceFeatures())
193 fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer());
196 if (getSize().width > 0 && getSize().height > 0)
198 od.setWidth(getSize().width);
199 od.setHeight(getSize().height - od.getGraphHeight());
202 setSize(new Dimension(od.getWidth(), od.getHeight()));
204 miniMe = nullFrame.createImage(od.getWidth(), od.getHeight());
205 offscreen = nullFrame.createImage(od.getWidth(), od.getHeight());
207 Graphics mg = miniMe.getGraphics();
209 // od.updateScales();
211 int alwidth = av.getAlignment().getWidth();
212 int alheight = av.getAlignment().getAbsoluteHeight();
213 float sampleCol = alwidth / (float) od.getWidth();
214 float sampleRow = alheight / (float) od.getSequencesHeight();
216 buildImage(sampleRow, sampleCol, mg);
218 if (av.getAlignmentConservationAnnotation() != null)
220 for (int col = 0; col < od.getWidth() && !resizeAgain; col++)
222 mg.translate(col, od.getSequencesHeight());
223 ap.annotationPanel.renderer.drawGraph(mg,
224 av.getAlignmentConservationAnnotation(),
225 av.getAlignmentConservationAnnotation().annotations,
226 (int) (sampleCol) + 1, od.getGraphHeight(),
227 (int) (col * sampleCol), (int) (col * sampleCol) + 1);
228 mg.translate(-col, -od.getSequencesHeight());
240 updateOverviewImage();
244 private void buildImage(float sampleRow, float sampleCol, Graphics mg)
250 Color color = Color.yellow;
254 jalview.datamodel.SequenceI seq = null;
256 final boolean hasHiddenCols = av.hasHiddenColumns();
257 boolean hiddenRow = false;
259 for (int row = 0; row <= od.getSequencesHeight() && !resizeAgain; row++)
261 if ((int) (row * sampleRow) == lastrow)
267 // get the sequence which would be at alignment index 'lastrow' if no
268 // columns were hidden, and determine whether it is hidden or not
269 hiddenRow = av.getAlignment().isHidden(lastrow);
270 seq = av.getAlignment().getSequenceAtAbsoluteIndex(lastrow);
272 for (int col = 0; col < od.getWidth(); col++)
274 if ((int) (col * sampleCol) == lastcol
275 && (int) (row * sampleRow) == lastrow)
281 lastcol = (int) (col * sampleCol);
283 color = getColumnColourFromSequence(seq, hiddenRow,
284 hasHiddenCols, lastcol);
287 if (sameCol == 1 && sameRow == 1)
289 mg.drawLine(xstart, ystart, xstart, ystart);
293 mg.fillRect(xstart, ystart, sameCol, sameRow);
300 lastrow = (int) (row * sampleRow);
309 * Find the colour of a sequence at a specified column position
311 private Color getColumnColourFromSequence(
312 jalview.datamodel.SequenceI seq, boolean hiddenRow,
313 boolean hasHiddenCols, int lastcol)
316 if (seq.getLength() > lastcol)
318 color = sr.getResidueBoxColour(seq, lastcol);
320 if (av.isShowSequenceFeatures())
322 color = fr.findFeatureColour(color, seq, lastcol);
327 color = Color.white; // White
331 || (hasHiddenCols && !av.getColumnSelection()
332 .isVisible(lastcol)))
334 color = color.darker().darker();
340 * Update the overview panel box when the associated alignment panel is
344 public void setBoxPosition()
351 public void update(Graphics g)
357 public void paint(Graphics g)
359 Graphics og = offscreen.getGraphics();
362 og.drawImage(miniMe, 0, 0, this);
363 og.setColor(Color.red);
365 g.drawImage(offscreen, 0, 0, this);