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.
23 import jalview.renderer.OverviewRenderer;
24 import jalview.util.MessageManager;
25 import jalview.util.Platform;
26 import jalview.viewmodel.OverviewDimensions;
27 import jalview.viewmodel.OverviewDimensionsHideHidden;
28 import jalview.viewmodel.OverviewDimensionsShowHidden;
29 import jalview.viewmodel.ViewportListenerI;
31 import java.awt.BorderLayout;
32 import java.awt.Cursor;
33 import java.awt.Dimension;
34 import java.awt.event.ActionEvent;
35 import java.awt.event.ActionListener;
36 import java.awt.event.ComponentAdapter;
37 import java.awt.event.ComponentEvent;
38 import java.awt.event.MouseAdapter;
39 import java.awt.event.MouseEvent;
40 import java.awt.event.MouseMotionAdapter;
41 import java.beans.PropertyChangeEvent;
43 import javax.swing.JCheckBoxMenuItem;
44 import javax.swing.JPanel;
45 import javax.swing.JPopupMenu;
46 import javax.swing.SwingUtilities;
49 * Panel displaying an overview of the full alignment, with an interactive box
50 * representing the viewport onto the alignment.
55 public class OverviewPanel extends JPanel implements Runnable,
58 private OverviewDimensions od;
60 private OverviewCanvas oviewCanvas;
62 private AlignViewport av;
64 private AlignmentPanel ap;
66 private JCheckBoxMenuItem displayToggle;
68 private boolean showHidden = true;
70 private boolean draggingBox = false;
72 private ProgressPanel progressPanel;
74 boolean resizing = false;
77 * Creates a new OverviewPanel object.
80 * The alignment panel which is shown in the overview panel
82 public OverviewPanel(AlignmentPanel alPanel)
87 od = new OverviewDimensionsShowHidden(av.getRanges(),
88 (av.isShowAnnotation() && av
89 .getAlignmentConservationAnnotation() != null));
91 setLayout(new BorderLayout());
92 progressPanel = new ProgressPanel(OverviewRenderer.UPDATE,
93 MessageManager.getString("label.oview_calc"));
94 this.add(progressPanel, BorderLayout.SOUTH);
95 oviewCanvas = new OverviewCanvas(od, av, progressPanel);
97 add(oviewCanvas, BorderLayout.CENTER);
99 av.getRanges().addPropertyChangeListener(this);
101 // without this the overview window does not size to fit the overview canvas
102 setPreferredSize(new Dimension(od.getWidth(), od.getHeight()));
104 addComponentListener(new ComponentAdapter()
107 public void componentResized(ComponentEvent evt)
109 // Resize is called on the initial display of the overview.
110 // This code adjusts sizes to account for the progress bar if it has not
111 // already been accounted for, which triggers another resize call for
112 // the correct sizing, at which point the overview image is updated.
113 // (This avoids a double recalculation of the image.)
114 if (getWidth() == od.getWidth() && getHeight() == od.getHeight()
115 + progressPanel.getHeight())
117 updateOverviewImage();
121 if ((getWidth() > 0) && (getHeight() > 0))
123 od.setWidth(getWidth());
124 od.setHeight(getHeight() - progressPanel.getHeight());
127 setPreferredSize(new Dimension(od.getWidth(),
128 od.getHeight() + progressPanel.getHeight()));
134 addMouseMotionListener(new MouseMotionAdapter()
137 public void mouseDragged(MouseEvent evt)
139 if (!SwingUtilities.isRightMouseButton(evt))
143 // set the mouse position as a fixed point in the box
144 // and drag relative to that position
145 od.adjustViewportFromMouse(evt.getX(),
146 evt.getY(), av.getAlignment().getHiddenSequences(),
147 av.getAlignment().getHiddenColumns());
151 od.updateViewportFromMouse(evt.getX(), evt.getY(), av
152 .getAlignment().getHiddenSequences(), av.getAlignment()
153 .getHiddenColumns());
159 public void mouseMoved(MouseEvent evt)
161 if (od.isPositionInBox(evt.getX(), evt.getY()))
163 // display drag cursor at mouse position
164 setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
169 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
174 addMouseListener(new MouseAdapter()
177 public void mousePressed(MouseEvent evt)
179 if (SwingUtilities.isRightMouseButton(evt))
181 if (!Platform.isAMac())
188 if (!od.isPositionInBox(evt.getX(), evt.getY()))
190 // don't do anything if the mouse press is in the overview's box
191 // (wait to see if it's a drag instead)
192 // otherwise update the viewport
193 od.updateViewportFromMouse(evt.getX(), evt.getY(),
194 av.getAlignment().getHiddenSequences(),
195 av.getAlignment().getHiddenColumns());
200 od.setDragPoint(evt.getX(), evt.getY(),
201 av.getAlignment().getHiddenSequences(),
202 av.getAlignment().getHiddenColumns());
208 public void mouseReleased(MouseEvent evt)
217 public void mouseClicked(MouseEvent evt)
219 if (SwingUtilities.isRightMouseButton(evt))
228 * Displays the popup menu and acts on user input
230 private void showPopupMenu(MouseEvent e)
232 JPopupMenu popup = new JPopupMenu();
233 ActionListener menuListener = new ActionListener()
236 public void actionPerformed(ActionEvent event)
238 // switch on/off the hidden columns view
239 toggleHiddenColumns();
240 displayToggle.setSelected(showHidden);
243 displayToggle = new JCheckBoxMenuItem(
244 MessageManager.getString("label.togglehidden"));
245 displayToggle.setEnabled(true);
246 displayToggle.setSelected(showHidden);
247 popup.add(displayToggle);
248 displayToggle.addActionListener(menuListener);
249 popup.show(this, e.getX(), e.getY());
253 * Toggle overview display between showing hidden columns and hiding hidden columns
255 private void toggleHiddenColumns()
260 od = new OverviewDimensionsHideHidden(av.getRanges(),
261 (av.isShowAnnotation() && av
262 .getAlignmentConservationAnnotation() != null));
267 od = new OverviewDimensionsShowHidden(av.getRanges(),
268 (av.isShowAnnotation() && av
269 .getAlignmentConservationAnnotation() != null));
271 oviewCanvas.resetOviewDims(od);
272 updateOverviewImage();
277 * Updates the overview image when the related alignment panel is updated
279 public void updateOverviewImage()
281 if (oviewCanvas == null)
284 * panel has been disposed
289 if ((getWidth() > 0) && (getHeight() > 0))
291 od.setWidth(getWidth());
292 od.setHeight(getHeight() - progressPanel.getHeight());
295 setPreferredSize(new Dimension(od.getWidth(),
296 od.getHeight() + progressPanel.getHeight()));
298 if (oviewCanvas.restartDraw())
303 Thread thread = new Thread(this);
313 oviewCanvas.draw(av.isShowSequenceFeatures(),
314 (av.isShowAnnotation() && av
315 .getAlignmentConservationAnnotation() != null), ap
316 .getSeqPanel().seqCanvas.getFeatureRenderer());
321 * Update the overview panel box when the associated alignment panel is
325 private void setBoxPosition()
327 od.setBoxPosition(av.getAlignment().getHiddenSequences(), av
328 .getAlignment().getHiddenColumns());
333 public void propertyChange(PropertyChangeEvent evt)
339 * Removes this object as a property change listener, and nulls references
341 protected void dispose()
345 av.getRanges().removePropertyChangeListener(this);
348 progressPanel = null;