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)
111 && !av.getWrapAlignment())
113 od.updateViewportFromMouse(evt.getX(), evt.getY(), av
114 .getAlignment().getHiddenSequences(), av.getAlignment()
115 .getHiddenColumns());
121 addMouseListener(new MouseAdapter()
124 public void mousePressed(MouseEvent evt)
126 if (SwingUtilities.isRightMouseButton(evt))
128 if (!Platform.isAMac())
133 else if (!av.getWrapAlignment())
135 od.updateViewportFromMouse(evt.getX(), evt.getY(), av
136 .getAlignment().getHiddenSequences(), av.getAlignment()
137 .getHiddenColumns());
142 public void mouseClicked(MouseEvent evt)
144 if (SwingUtilities.isRightMouseButton(evt))
152 updateOverviewImage();
156 * Displays the popup menu and acts on user input
158 private void showPopupMenu(MouseEvent e)
160 JPopupMenu popup = new JPopupMenu();
161 ActionListener menuListener = new ActionListener()
164 public void actionPerformed(ActionEvent event)
166 // switch on/off the hidden columns view
167 toggleHiddenColumns();
168 displayToggle.setSelected(showHidden);
171 displayToggle = new JCheckBoxMenuItem(
172 MessageManager.getString("label.togglehidden"));
173 displayToggle.setEnabled(true);
174 displayToggle.setSelected(showHidden);
175 popup.add(displayToggle);
176 displayToggle.addActionListener(menuListener);
177 popup.show(this, e.getX(), e.getY());
181 * Toggle overview display between showing hidden columns and hiding hidden columns
183 private void toggleHiddenColumns()
188 od = new OverviewDimensionsHideHidden(av.getRanges(),
189 (av.isShowAnnotation() && av
190 .getAlignmentConservationAnnotation() != null));
195 od = new OverviewDimensionsShowHidden(av.getRanges(),
196 (av.isShowAnnotation() && av
197 .getAlignmentConservationAnnotation() != null));
199 oviewCanvas.resetOviewDims(od);
200 updateOverviewImage();
205 * Updates the overview image when the related alignment panel is updated
207 public void updateOverviewImage()
209 if ((getWidth() > 0) && (getHeight() > 0))
211 od.setWidth(getWidth());
212 od.setHeight(getHeight());
215 setPreferredSize(new Dimension(od.getWidth(), od.getHeight()));
217 if (oviewCanvas.restartDraw())
222 Thread thread = new Thread(this);
231 oviewCanvas.draw(av.isShowSequenceFeatures(),
232 (av.isShowAnnotation() && av
233 .getAlignmentConservationAnnotation() != null), ap
234 .getSeqPanel().seqCanvas.getFeatureRenderer());
239 * Update the overview panel box when the associated alignment panel is
243 private void setBoxPosition()
245 od.setBoxPosition(av.getAlignment().getHiddenSequences(), av
246 .getAlignment().getHiddenColumns());
251 public void propertyChange(PropertyChangeEvent evt)