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 @SuppressWarnings("serial")
50 public class OverviewPanel extends Panel implements Runnable,
51 MouseMotionListener, MouseListener, ViewportListenerI
53 OverviewDimensions od;
55 OverviewCanvas canvas;
57 private AlignViewport av;
61 private boolean showHidden = true;
63 private boolean updateRunning = false;
65 private boolean draggingBox = false;
67 public OverviewPanel(AlignmentPanel alPanel)
73 od = new OverviewDimensionsShowHidden(av.getRanges(),
74 (av.isShowAnnotation()
75 && av.getSequenceConsensusHash() != null));
77 canvas = new OverviewCanvas(this, od, av);
78 setLayout(new BorderLayout());
79 add(canvas, BorderLayout.CENTER);
81 setSize(new Dimension(od.getWidth(), od.getHeight()));
83 av.getRanges().addPropertyChangeListener(this);
85 addComponentListener(new ComponentAdapter()
89 public void componentResized(ComponentEvent evt)
91 if ((getWidth() != od.getWidth())
92 || (getHeight() != (od.getHeight())))
94 updateOverviewImage();
99 addMouseMotionListener(this);
101 addMouseListener(this);
103 updateOverviewImage();
108 public void mouseEntered(MouseEvent evt)
113 public void mouseExited(MouseEvent evt)
118 public void mouseClicked(MouseEvent evt)
120 if ((evt.getModifiers()
121 & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
128 public void mouseMoved(MouseEvent evt)
130 if (od.isPositionInBox(evt.getX(), evt.getY()))
133 .setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
139 Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
144 public void mousePressed(MouseEvent evt)
146 if ((evt.getModifiers()
147 & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
149 if (!Platform.isMac()) // BH was excluding JavaScript
156 // don't do anything if the mouse press is in the overview's box
157 // (wait to see if it's a drag instead)
158 // otherwise update the viewport
159 if (!od.isPositionInBox(evt.getX(), evt.getY()))
163 // display drag cursor at mouse position
164 setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
166 od.updateViewportFromMouse(evt.getX(), evt.getY(),
167 av.getAlignment().getHiddenSequences(),
168 av.getAlignment().getHiddenColumns());
170 .setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
175 od.setDragPoint(evt.getX(), evt.getY(),
176 av.getAlignment().getHiddenSequences(),
177 av.getAlignment().getHiddenColumns());
183 public void mouseReleased(MouseEvent evt)
189 public void mouseDragged(MouseEvent evt)
191 if (Platform.isWinRightButton(evt))
197 if (SwingUtilities.isRightMouseButton(evt))
204 // set the mouse position as a fixed point in the box
205 // and drag relative to that position
206 od.adjustViewportFromMouse(evt.getX(), evt.getY(),
207 av.getAlignment().getHiddenSequences(),
208 av.getAlignment().getHiddenColumns());
212 od.updateViewportFromMouse(evt.getX(), evt.getY(),
213 av.getAlignment().getHiddenSequences(),
214 av.getAlignment().getHiddenColumns());
216 ap.paintAlignment(false, false);
220 * Updates the overview image when the related alignment panel is updated
222 public void updateOverviewImage()
227 * panel has been disposed
232 if ((getSize().width > 0) && (getSize().height > 0))
234 od.setWidth(getSize().width);
235 od.setHeight(getSize().height);
237 setSize(new Dimension(od.getWidth(), od.getHeight()));
243 canvas.restartDraw();
247 updateRunning = true;
249 Thread thread = new Thread(this);
252 updateRunning = false;
259 canvas.draw(av.isShowSequenceFeatures(),
260 (av.isShowAnnotation()
261 && av.getAlignmentConservationAnnotation() != null),
262 ap.seqPanel.seqCanvas.getFeatureRenderer());
266 * Update the overview panel box when the associated alignment panel is
270 private void setBoxPosition()
272 od.setBoxPosition(av.getAlignment().getHiddenSequences(),
273 av.getAlignment().getHiddenColumns());
278 * Displays the popup menu and acts on user input
280 private void showPopupMenu(MouseEvent e)
282 PopupMenu popup = new PopupMenu();
283 ItemListener menuListener = new ItemListener()
286 public void itemStateChanged(ItemEvent e)
288 toggleHiddenColumns();
291 CheckboxMenuItem item = new CheckboxMenuItem(
292 MessageManager.getString("label.togglehidden"));
293 item.setState(showHidden);
295 item.addItemListener(menuListener);
297 popup.show(this, e.getX(), e.getY());
301 public void propertyChange(PropertyChangeEvent evt)
307 * Toggle overview display between showing hidden columns and hiding hidden columns
309 private void toggleHiddenColumns()
314 od = new OverviewDimensionsHideHidden(av.getRanges(),
315 (av.isShowAnnotation()
316 && av.getAlignmentConservationAnnotation() != null));
321 od = new OverviewDimensionsShowHidden(av.getRanges(),
322 (av.isShowAnnotation()
323 && av.getAlignmentConservationAnnotation() != null));
325 canvas.resetOviewDims(od);
326 updateOverviewImage();
330 * Removes this object as a property change listener, and nulls references
332 protected void dispose()
336 av.getRanges().removePropertyChangeListener(this);
337 Frame parent = (Frame) getParent();
339 parent.setVisible(false);