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(); // Jalview.getInstance().getShowStatus()
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)
223 protected void resizePanel()
225 int ph = (progressPanel.getParent() == null ? 0
226 : progressPanel.getHeight());
227 // Resize is called on the initial display of the overview.
228 // This code adjusts sizes to account for the progress bar if it has not
229 // already been accounted for, which triggers another resize call for
230 // the correct sizing, at which point the overview image is updated.
231 // (This avoids a double recalculation of the image.)
232 if (getWidth() == od.getWidth() && getHeight() == od.getHeight() + ph)
234 if (canvas.lastMiniMe == null)
236 updateOverviewImage();
243 if ((w > 0) && (h > 0))
247 dim.setSize(w, h - ph);
250 od.setHeight(h - ph);
251 updateOverviewImage();
257 * Create the appropriate type of OverViewDimensions, with the desired size.
259 private void createOverviewDimensions()
261 boolean showAnnotation = (av.isShowAnnotation()
262 && av.getAlignmentConservationAnnotation() != null);
265 od = new OverviewDimensionsShowHidden(av.getRanges(), showAnnotation,
270 od = new OverviewDimensionsHideHidden(av.getRanges(), showAnnotation,
277 * Displays the popup menu and acts on user input
279 protected void showPopupMenu(MouseEvent e)
281 JPopupMenu popup = new JPopupMenu();
282 ActionListener menuListener = new ActionListener()
285 public void actionPerformed(ActionEvent event)
287 // switch on/off the hidden columns view
288 toggleHiddenColumns();
289 displayToggle.setSelected(showHidden);
292 displayToggle = new JCheckBoxMenuItem(
293 MessageManager.getString("label.togglehidden"));
294 displayToggle.setEnabled(true);
295 displayToggle.setSelected(showHidden);
296 popup.add(displayToggle);
297 displayToggle.addActionListener(menuListener);
298 popup.show(this, e.getX(), e.getY());
302 * Toggle overview display between showing hidden columns and hiding hidden
305 protected void toggleHiddenColumns()
307 showHidden = !showHidden;
308 createOverviewDimensions();
309 canvas.resetOviewDims(od);
310 updateOverviewImage();
315 * Updates the overview image when the related alignment panel is updated.
319 * AlignFrame.setFeatureGroupState
321 * AlignmentPanel.paintAlignment(true,...) (117 references)
323 * OverviewPanel..componentResized() OverviewPanel.toggleHiddenColumns()
325 * PopupMenu for action.reveal_sequences, action.reveal_all
327 * SliderPanel.mouseReleased()
330 public void updateOverviewImage()
335 * panel has been disposed
340 int ph = (progressPanel.getParent() == null ? 0
341 : progressPanel.getHeight());
343 if ((getWidth() > 0) && (getHeight() > 0))
345 od.setWidth(getWidth());
346 od.setHeight(getHeight() - ph);
349 setPreferredSize(new Dimension(od.getWidth(), od.getHeight() + ph));
351 if (canvas.restartDraw())
356 Thread thread = new Thread(this);
366 canvas.draw(av.isShowSequenceFeatures(),
367 (av.isShowAnnotation()
368 && av.getAlignmentConservationAnnotation() != null),
369 ap.getFeatureRenderer());
374 * Update the overview panel box when the associated alignment panel is
378 private void setBoxPositionOnly()
383 int oldX = od.getBoxX();
384 int oldY = od.getBoxY();
385 int oldWidth = od.getBoxWidth();
386 int oldHeight = od.getBoxHeight();
387 od.setBoxPosition(av.getAlignment().getHiddenSequences(),
388 av.getAlignment().getHiddenColumns());
389 repaint(oldX - 1, oldY - 1, oldWidth + 2, oldHeight + 2);
390 repaint(od.getBoxX(), od.getBoxY(), od.getBoxWidth(),
395 private void setBoxPosition()
399 od.setBoxPosition(av.getAlignment().getHiddenSequences(),
400 av.getAlignment().getHiddenColumns());
406 public void propertyChange(PropertyChangeEvent evt)
408 setBoxPositionOnly();
412 * Removes this object as a property change listener, and nulls references
414 protected void dispose()
420 av.getRanges().removePropertyChangeListener(this);
426 * close the parent frame (which also removes it from the
427 * Desktop Windows menu)
429 ((JInternalFrame) SwingUtilities
430 .getAncestorOfClass(JInternalFrame.class, (this)))
432 } catch (PropertyVetoException e)
437 progressPanel = null;