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.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.Dimension;
32 import java.awt.event.ActionEvent;
33 import java.awt.event.ActionListener;
34 import java.awt.event.ComponentAdapter;
35 import java.awt.event.ComponentEvent;
36 import java.awt.event.MouseAdapter;
37 import java.awt.event.MouseEvent;
38 import java.awt.event.MouseMotionAdapter;
39 import java.beans.PropertyChangeEvent;
41 import javax.swing.JCheckBoxMenuItem;
42 import javax.swing.JPanel;
43 import javax.swing.JPopupMenu;
44 import javax.swing.SwingUtilities;
47 * Panel displaying an overview of the full alignment, with an interactive box
48 * representing the viewport onto the alignment.
53 public class OverviewPanel extends JPanel implements Runnable,
56 private OverviewDimensions od;
58 private OverviewCanvas oviewCanvas;
60 private AlignViewport av;
62 private AlignmentPanel ap;
64 private JCheckBoxMenuItem displayToggle;
66 private boolean showHidden = true;
69 * Creates a new OverviewPanel object.
72 * The alignment panel which is shown in the overview panel
74 public OverviewPanel(AlignmentPanel alPanel)
79 od = new OverviewDimensionsShowHidden(av.getRanges(),
80 (av.isShowAnnotation() && av
81 .getAlignmentConservationAnnotation() != null));
83 setSize(od.getWidth(), od.getHeight());
85 oviewCanvas = new OverviewCanvas(od, av);
86 setLayout(new BorderLayout());
87 add(oviewCanvas, BorderLayout.CENTER);
89 av.getRanges().addPropertyChangeListener(this);
91 addComponentListener(new ComponentAdapter()
94 public void componentResized(ComponentEvent evt)
96 if ((getWidth() != od.getWidth())
97 || (getHeight() != (od.getHeight())))
99 updateOverviewImage();
105 addMouseMotionListener(new MouseMotionAdapter()
108 public void mouseDragged(MouseEvent evt)
110 if (!SwingUtilities.isRightMouseButton(evt))
112 od.updateViewportFromMouse(evt.getX(), evt.getY(), av
113 .getAlignment().getHiddenSequences(), av.getAlignment()
114 .getHiddenColumns());
119 addMouseListener(new MouseAdapter()
122 public void mousePressed(MouseEvent evt)
124 if (SwingUtilities.isRightMouseButton(evt))
126 if (!Platform.isAMac())
132 // if (!av.getWrapAlignment())
134 od.updateViewportFromMouse(evt.getX(), evt.getY(), av
135 .getAlignment().getHiddenSequences(), av.getAlignment()
136 .getHiddenColumns());
141 public void mouseClicked(MouseEvent evt)
143 if (SwingUtilities.isRightMouseButton(evt))
150 updateOverviewImage();
154 * Displays the popup menu and acts on user input
156 private void showPopupMenu(MouseEvent e)
158 JPopupMenu popup = new JPopupMenu();
159 ActionListener menuListener = new ActionListener()
162 public void actionPerformed(ActionEvent event)
164 // switch on/off the hidden columns view
165 toggleHiddenColumns();
166 displayToggle.setSelected(showHidden);
169 displayToggle = new JCheckBoxMenuItem(
170 MessageManager.getString("label.togglehidden"));
171 displayToggle.setEnabled(true);
172 displayToggle.setSelected(showHidden);
173 popup.add(displayToggle);
174 displayToggle.addActionListener(menuListener);
175 popup.show(this, e.getX(), e.getY());
179 * Toggle overview display between showing hidden columns and hiding hidden columns
181 private void toggleHiddenColumns()
186 od = new OverviewDimensionsHideHidden(av.getRanges(),
187 (av.isShowAnnotation() && av
188 .getAlignmentConservationAnnotation() != null));
193 od = new OverviewDimensionsShowHidden(av.getRanges(),
194 (av.isShowAnnotation() && av
195 .getAlignmentConservationAnnotation() != null));
197 oviewCanvas.resetOviewDims(od);
198 updateOverviewImage();
203 * Updates the overview image when the related alignment panel is updated
205 public void updateOverviewImage()
207 if (oviewCanvas == null)
210 * panel has been disposed
215 if ((getWidth() > 0) && (getHeight() > 0))
217 od.setWidth(getWidth());
218 od.setHeight(getHeight());
221 setPreferredSize(new Dimension(od.getWidth(), od.getHeight()));
223 if (oviewCanvas.restartDraw())
228 Thread thread = new Thread(this);
236 oviewCanvas.draw(av.isShowSequenceFeatures(),
237 (av.isShowAnnotation() && av
238 .getAlignmentConservationAnnotation() != null), ap
239 .getSeqPanel().seqCanvas.getFeatureRenderer());
244 * Update the overview panel box when the associated alignment panel is
248 private void setBoxPosition()
250 od.setBoxPosition(av.getAlignment().getHiddenSequences(), av
251 .getAlignment().getHiddenColumns());
256 public void propertyChange(PropertyChangeEvent evt)
262 * Removes this object as a property change listener, and nulls references
264 protected void dispose()
268 av.getRanges().removePropertyChangeListener(this);