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 public class OverviewPanel extends Panel implements Runnable,
48 MouseMotionListener, MouseListener, ViewportListenerI
50 private OverviewDimensions od;
52 private OverviewCanvas oviewCanvas;
54 private AlignViewport av;
56 private AlignmentPanel ap;
58 private boolean showHidden = true;
60 private boolean updateRunning = false;
62 private boolean draggingBox = false;
64 public OverviewPanel(AlignmentPanel alPanel)
70 od = new OverviewDimensionsShowHidden(av.getRanges(),
71 (av.isShowAnnotation()
72 && av.getSequenceConsensusHash() != null));
74 oviewCanvas = new OverviewCanvas(od, av);
75 setLayout(new BorderLayout());
76 add(oviewCanvas, BorderLayout.CENTER);
78 setSize(new Dimension(od.getWidth(), od.getHeight()));
80 av.getRanges().addPropertyChangeListener(this);
82 addComponentListener(new ComponentAdapter()
86 public void componentResized(ComponentEvent evt)
88 if ((getWidth() != od.getWidth())
89 || (getHeight() != (od.getHeight())))
91 updateOverviewImage();
96 addMouseMotionListener(this);
98 addMouseListener(this);
100 updateOverviewImage();
105 public void mouseEntered(MouseEvent evt)
110 public void mouseExited(MouseEvent evt)
115 public void mouseClicked(MouseEvent evt)
117 if ((evt.getModifiers()
118 & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
125 public void mouseMoved(MouseEvent evt)
127 if (od.isPositionInBox(evt.getX(), evt.getY()))
129 // display drag cursor at mouse position
130 setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
135 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
140 public void mousePressed(MouseEvent evt)
142 if ((evt.getModifiers()
143 & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
145 if (!Platform.isAMac())
152 // don't do anything if the mouse press is in the overview's box
153 // (wait to see if it's a drag instead)
154 // otherwise update the viewport
155 if (!od.isPositionInBox(evt.getX(), evt.getY()))
159 // display drag cursor at mouse position
160 setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
162 od.updateViewportFromMouse(evt.getX(), evt.getY(),
163 av.getAlignment().getHiddenSequences(),
164 av.getAlignment().getHiddenColumns());
169 od.setDragPoint(evt.getX(), evt.getY(),
170 av.getAlignment().getHiddenSequences(),
171 av.getAlignment().getHiddenColumns());
177 public void mouseReleased(MouseEvent evt)
183 public void mouseDragged(MouseEvent evt)
185 if ((evt.getModifiers()
186 & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
188 if (!Platform.isAMac())
197 // set the mouse position as a fixed point in the box
198 // and drag relative to that position
199 od.adjustViewportFromMouse(evt.getX(), evt.getY(),
200 av.getAlignment().getHiddenSequences(),
201 av.getAlignment().getHiddenColumns());
205 od.updateViewportFromMouse(evt.getX(), evt.getY(),
206 av.getAlignment().getHiddenSequences(),
207 av.getAlignment().getHiddenColumns());
209 ap.paintAlignment(false, false);
214 * Updates the overview image when the related alignment panel is updated
216 public void updateOverviewImage()
218 if (oviewCanvas == null)
221 * panel has been disposed
226 if ((getSize().width > 0) && (getSize().height > 0))
228 od.setWidth(getSize().width);
229 od.setHeight(getSize().height);
231 setSize(new Dimension(od.getWidth(), od.getHeight()));
237 oviewCanvas.restartDraw();
241 updateRunning = true;
243 Thread thread = new Thread(this);
246 updateRunning = false;
252 oviewCanvas.draw(av.isShowSequenceFeatures(),
253 (av.isShowAnnotation()
254 && av.getAlignmentConservationAnnotation() != null),
255 ap.seqPanel.seqCanvas.getFeatureRenderer());
260 * Update the overview panel box when the associated alignment panel is
264 private void setBoxPosition()
266 od.setBoxPosition(av.getAlignment().getHiddenSequences(),
267 av.getAlignment().getHiddenColumns());
272 * Displays the popup menu and acts on user input
274 private void showPopupMenu(MouseEvent e)
276 PopupMenu popup = new PopupMenu();
277 ItemListener menuListener = new ItemListener()
280 public void itemStateChanged(ItemEvent e)
282 toggleHiddenColumns();
285 CheckboxMenuItem item = new CheckboxMenuItem(
286 MessageManager.getString("label.togglehidden"));
287 item.setState(showHidden);
289 item.addItemListener(menuListener);
291 popup.show(this, e.getX(), e.getY());
295 public void propertyChange(PropertyChangeEvent evt)
301 * Toggle overview display between showing hidden columns and hiding hidden columns
303 private void toggleHiddenColumns()
308 od = new OverviewDimensionsHideHidden(av.getRanges(),
309 (av.isShowAnnotation()
310 && av.getAlignmentConservationAnnotation() != null));
315 od = new OverviewDimensionsShowHidden(av.getRanges(),
316 (av.isShowAnnotation()
317 && av.getAlignmentConservationAnnotation() != null));
319 oviewCanvas.resetOviewDims(od);
320 updateOverviewImage();
324 * Removes this object as a property change listener, and nulls references
326 protected void dispose()
330 av.getRanges().removePropertyChangeListener(this);
331 Frame parent = (Frame) getParent();
333 parent.setVisible(false);