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.api.AlignViewportI;
24 import jalview.api.AlignmentViewPanel;
25 import jalview.bin.Cache;
26 import jalview.renderer.OverviewRenderer;
27 import jalview.util.MessageManager;
28 import jalview.util.Platform;
29 import jalview.viewmodel.OverviewDimensions;
30 import jalview.viewmodel.OverviewDimensionsHideHidden;
31 import jalview.viewmodel.OverviewDimensionsShowHidden;
32 import jalview.viewmodel.ViewportListenerI;
34 import java.awt.BorderLayout;
35 import java.awt.Cursor;
36 import java.awt.Dimension;
37 import java.awt.event.ActionEvent;
38 import java.awt.event.ActionListener;
39 import java.awt.event.ComponentAdapter;
40 import java.awt.event.ComponentEvent;
41 import java.awt.event.MouseAdapter;
42 import java.awt.event.MouseEvent;
43 import java.awt.event.MouseMotionAdapter;
44 import java.beans.PropertyChangeEvent;
45 import java.beans.PropertyVetoException;
47 import javax.swing.JCheckBoxMenuItem;
48 import javax.swing.JInternalFrame;
49 import javax.swing.JPanel;
50 import javax.swing.JPopupMenu;
51 import javax.swing.SwingUtilities;
54 * Panel displaying an overview of the full alignment, with an interactive box
55 * representing the viewport onto the alignment.
60 @SuppressWarnings("serial")
61 public class OverviewPanel extends JPanel
62 implements Runnable, ViewportListenerI
64 protected OverviewDimensions od;
66 OverviewCanvas canvas;
68 protected AlignViewportI av;
70 AlignmentViewPanel ap;
72 protected JCheckBoxMenuItem displayToggle;
74 protected boolean showHidden = true;
76 protected boolean draggingBox = false;
78 protected ProgressPanel progressPanel;
80 private Dimension dim;
82 private boolean showProgress = !Platform.isJS();
85 * Creates a new OverviewPanel object.
88 * The alignment panel which is shown in the overview panel
90 public OverviewPanel(AlignmentViewPanel alPanel, Dimension dim)
92 this.av = alPanel.getAlignViewport();
96 showHidden = Cache.getDefault(Preferences.SHOW_OV_HIDDEN_AT_START,
98 createOverviewDimensions();
99 setLayout(new BorderLayout());
100 progressPanel = new ProgressPanel(OverviewRenderer.UPDATE,
101 MessageManager.getString("label.oview_calc"), getWidth());
102 if (showProgress) // BH 2019
104 add(progressPanel, BorderLayout.SOUTH);
106 canvas = new OverviewCanvas(this, od, av,
107 showProgress ? progressPanel : null);
108 canvas.setPreferredSize(canvas.getSize());
109 add(canvas, BorderLayout.CENTER);
111 av.getRanges().addPropertyChangeListener(this);
113 addComponentListener(new ComponentAdapter()
116 public void componentResized(ComponentEvent evt)
122 addMouseMotionListener(new MouseMotionAdapter()
125 public void mouseDragged(MouseEvent evt)
127 if (!SwingUtilities.isRightMouseButton(evt))
131 // set the mouse position as a fixed point in the box
132 // and drag relative to that position
133 od.adjustViewportFromMouse(evt.getX(), evt.getY(),
134 av.getAlignment().getHiddenSequences(),
135 av.getAlignment().getHiddenColumns());
139 od.updateViewportFromMouse(evt.getX(), evt.getY(),
140 av.getAlignment().getHiddenSequences(),
141 av.getAlignment().getHiddenColumns());
147 public void mouseMoved(MouseEvent evt)
149 if (od.isPositionInBox(evt.getX(), evt.getY()))
152 * using HAND_CURSOR rather than DRAG_CURSOR
153 * as the latter is not supported on Mac
155 getParent().setCursor(
156 Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
161 getParent().setCursor(
162 Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
167 addMouseListener(new MouseAdapter()
170 public void mousePressed(MouseEvent evt)
172 if (Platform.isWinRightButton(evt))
177 if (SwingUtilities.isRightMouseButton(evt))
181 // don't do anything if the mouse press is in the overview's box
182 // (wait to see if it's a drag instead)
183 // otherwise update the viewport
184 if (!od.isPositionInBox(evt.getX(), evt.getY()))
188 // display drag cursor at mouse position
189 setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
191 od.updateViewportFromMouse(evt.getX(), evt.getY(),
192 av.getAlignment().getHiddenSequences(),
193 av.getAlignment().getHiddenColumns());
194 getParent().setCursor(
195 Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
200 od.setDragPoint(evt.getX(), evt.getY(),
201 av.getAlignment().getHiddenSequences(),
202 av.getAlignment().getHiddenColumns());
207 public void mouseClicked(MouseEvent evt)
209 if (SwingUtilities.isRightMouseButton(evt))
216 public void mouseReleased(MouseEvent evt)
224 * Resize is called on the initial display of the Overview. This code adjusts
225 * sizes to account for the progress bar if it has not already been accounted
226 * for, which triggers another resize call for the correct sizing, at which
227 * point the overview image is updated. (This avoids a double recalculation of
230 protected void resizePanel()
232 int ph = (progressPanel.getParent() == null ? 0
233 : progressPanel.getHeight());
234 if (getWidth() == od.getWidth() && getHeight() == od.getHeight() + ph)
236 if (canvas.lastMiniMe == null)
238 updateOverviewImage();
245 if ((w > 0) && (h > 0))
249 dim.setSize(w, h - ph);
252 od.setHeight(h - ph);
253 updateOverviewImage();
259 * Creates the appropriate type of OverviewDimensions, with the desired size
261 private void createOverviewDimensions()
263 boolean showAnnotation = (av.isShowAnnotation()
264 && av.getAlignmentConservationAnnotation() != null);
267 od = new OverviewDimensionsShowHidden(av.getRanges(), showAnnotation,
272 od = new OverviewDimensionsHideHidden(av.getRanges(), showAnnotation,
278 * Displays the popup menu and acts on user input
280 protected void showPopupMenu(MouseEvent e)
282 JPopupMenu popup = new JPopupMenu();
283 ActionListener menuListener = new ActionListener()
286 public void actionPerformed(ActionEvent event)
288 // switch on/off the hidden columns view
289 toggleHiddenColumns();
290 displayToggle.setSelected(showHidden);
293 displayToggle = new JCheckBoxMenuItem(
294 MessageManager.getString("label.togglehidden"));
295 displayToggle.setEnabled(true);
296 displayToggle.setSelected(showHidden);
297 popup.add(displayToggle);
298 displayToggle.addActionListener(menuListener);
299 popup.show(this, e.getX(), e.getY());
303 * Toggle overview display between showing hidden columns and hiding hidden
306 protected void toggleHiddenColumns()
308 showHidden = !showHidden;
309 createOverviewDimensions();
310 canvas.resetOviewDims(od);
311 updateOverviewImage();
316 * Updates the overview image when the related alignment panel is updated
318 public void updateOverviewImage()
323 * panel has been disposed
328 int ph = (progressPanel.getParent() == null ? 0
329 : progressPanel.getHeight());
331 if ((getWidth() > 0) && (getHeight() > 0))
333 od.setWidth(getWidth());
334 od.setHeight(getHeight() - ph);
337 setPreferredSize(new Dimension(od.getWidth(), od.getHeight() + ph));
339 if (canvas.restartDraw())
344 Thread thread = new Thread(this);
354 canvas.draw(av.isShowSequenceFeatures(),
355 (av.isShowAnnotation()
356 && av.getAlignmentConservationAnnotation() != null),
357 ap.getFeatureRenderer());
362 * Update the overview panel box when the associated alignment panel is
365 private void setBoxPositionOnly()
370 int oldX = od.getBoxX();
371 int oldY = od.getBoxY();
372 int oldWidth = od.getBoxWidth();
373 int oldHeight = od.getBoxHeight();
374 od.setBoxPosition(av.getAlignment().getHiddenSequences(),
375 av.getAlignment().getHiddenColumns());
376 repaint(oldX - 1, oldY - 1, oldWidth + 2, oldHeight + 2);
377 repaint(od.getBoxX(), od.getBoxY(), od.getBoxWidth(),
382 private void setBoxPosition()
386 od.setBoxPosition(av.getAlignment().getHiddenSequences(),
387 av.getAlignment().getHiddenColumns());
393 public void propertyChange(PropertyChangeEvent evt)
395 setBoxPositionOnly();
399 * Removes this object as a property change listener, and nulls references
401 protected void dispose()
407 av.getRanges().removePropertyChangeListener(this);
413 * close the parent frame (which also removes it from the
414 * Desktop Windows menu)
416 ((JInternalFrame) SwingUtilities
417 .getAncestorOfClass(JInternalFrame.class, (this)))
419 } catch (PropertyVetoException e)
424 progressPanel = null;