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.util.MessageManager;
24 import jalview.util.Platform;
25 import jalview.viewmodel.OverviewDimensions;
26 import jalview.viewmodel.OverviewDimensionsHideHidden;
27 import jalview.viewmodel.OverviewDimensionsShowHidden;
28 import jalview.viewmodel.ViewportListenerI;
30 import java.awt.BorderLayout;
31 import java.awt.CheckboxMenuItem;
32 import java.awt.Cursor;
33 import java.awt.Dimension;
34 import java.awt.Frame;
35 import java.awt.Panel;
36 import java.awt.PopupMenu;
37 import java.awt.event.ComponentAdapter;
38 import java.awt.event.ComponentEvent;
39 import java.awt.event.InputEvent;
40 import java.awt.event.ItemEvent;
41 import java.awt.event.ItemListener;
42 import java.awt.event.MouseEvent;
43 import java.awt.event.MouseListener;
44 import java.awt.event.MouseMotionListener;
45 import java.beans.PropertyChangeEvent;
47 import javax.swing.SwingUtilities;
49 public class OverviewPanel extends Panel implements Runnable,
50 MouseMotionListener, MouseListener, ViewportListenerI
52 private OverviewDimensions od;
54 private OverviewCanvas oviewCanvas;
56 private AlignViewport av;
58 private AlignmentPanel ap;
60 private boolean showHidden = true;
62 private boolean updateRunning = false;
64 private boolean draggingBox = false;
66 public OverviewPanel(AlignmentPanel alPanel)
72 od = new OverviewDimensionsShowHidden(av.getRanges(),
73 (av.isShowAnnotation()
74 && av.getSequenceConsensusHash() != null));
76 oviewCanvas = new OverviewCanvas(od, av);
77 setLayout(new BorderLayout());
78 add(oviewCanvas, BorderLayout.CENTER);
80 setSize(new Dimension(od.getWidth(), od.getHeight()));
82 av.getRanges().addPropertyChangeListener(this);
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)
119 if ((evt.getModifiersEx()
120 & InputEvent.BUTTON3_DOWN_MASK) == InputEvent.BUTTON3_DOWN_MASK)
127 public void mouseMoved(MouseEvent evt)
129 if (od.isPositionInBox(evt.getX(), evt.getY()))
132 .setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
138 Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
143 public void mousePressed(MouseEvent evt)
145 if ((evt.getModifiersEx()
146 & InputEvent.BUTTON3_DOWN_MASK) == InputEvent.BUTTON3_DOWN_MASK)
148 if (!Platform.isMac()) // BH was excluding JavaScript
155 // don't do anything if the mouse press is in the overview's box
156 // (wait to see if it's a drag instead)
157 // otherwise update the viewport
158 if (!od.isPositionInBox(evt.getX(), evt.getY()))
162 // display drag cursor at mouse position
163 setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
165 od.updateViewportFromMouse(evt.getX(), evt.getY(),
166 av.getAlignment().getHiddenSequences(),
167 av.getAlignment().getHiddenColumns());
169 .setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
174 od.setDragPoint(evt.getX(), evt.getY(),
175 av.getAlignment().getHiddenSequences(),
176 av.getAlignment().getHiddenColumns());
182 public void mouseReleased(MouseEvent evt)
188 public void mouseDragged(MouseEvent evt)
190 if (Platform.isWinRightButton(evt))
196 if (SwingUtilities.isRightMouseButton(evt))
203 // set the mouse position as a fixed point in the box
204 // and drag relative to that position
205 od.adjustViewportFromMouse(evt.getX(), evt.getY(),
206 av.getAlignment().getHiddenSequences(),
207 av.getAlignment().getHiddenColumns());
211 od.updateViewportFromMouse(evt.getX(), evt.getY(),
212 av.getAlignment().getHiddenSequences(),
213 av.getAlignment().getHiddenColumns());
215 ap.paintAlignment(false, false);
219 * Updates the overview image when the related alignment panel is updated
221 public void updateOverviewImage()
223 if (oviewCanvas == null)
226 * panel has been disposed
231 if ((getSize().width > 0) && (getSize().height > 0))
233 od.setWidth(getSize().width);
234 od.setHeight(getSize().height);
236 setSize(new Dimension(od.getWidth(), od.getHeight()));
242 oviewCanvas.restartDraw();
246 updateRunning = true;
248 Thread thread = new Thread(this);
251 updateRunning = false;
257 oviewCanvas.draw(av.isShowSequenceFeatures(),
258 (av.isShowAnnotation()
259 && av.getAlignmentConservationAnnotation() != null),
260 ap.seqPanel.seqCanvas.getFeatureRenderer());
265 * Update the overview panel box when the associated alignment panel is
269 private void setBoxPosition()
271 od.setBoxPosition(av.getAlignment().getHiddenSequences(),
272 av.getAlignment().getHiddenColumns());
277 * Displays the popup menu and acts on user input
279 private void showPopupMenu(MouseEvent e)
281 PopupMenu popup = new PopupMenu();
282 ItemListener menuListener = new ItemListener()
285 public void itemStateChanged(ItemEvent e)
287 toggleHiddenColumns();
290 CheckboxMenuItem item = new CheckboxMenuItem(
291 MessageManager.getString("label.togglehidden"));
292 item.setState(showHidden);
294 item.addItemListener(menuListener);
296 popup.show(this, e.getX(), e.getY());
300 public void propertyChange(PropertyChangeEvent evt)
306 * Toggle overview display between showing hidden columns and hiding hidden columns
308 private void toggleHiddenColumns()
313 od = new OverviewDimensionsHideHidden(av.getRanges(),
314 (av.isShowAnnotation()
315 && av.getAlignmentConservationAnnotation() != null));
320 od = new OverviewDimensionsShowHidden(av.getRanges(),
321 (av.isShowAnnotation()
322 && av.getAlignmentConservationAnnotation() != null));
324 oviewCanvas.resetOviewDims(od);
325 updateOverviewImage();
329 * Removes this object as a property change listener, and nulls references
331 protected void dispose()
335 av.getRanges().removePropertyChangeListener(this);
336 Frame parent = (Frame) getParent();
338 parent.setVisible(false);
342 if (oviewCanvas != null)
344 oviewCanvas.dispose();