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.OverviewDimensionsAllVisible;
27 import jalview.viewmodel.OverviewDimensionsWithHidden;
29 import java.awt.BorderLayout;
30 import java.awt.Dimension;
31 import java.awt.event.ActionEvent;
32 import java.awt.event.ActionListener;
33 import java.awt.event.ComponentAdapter;
34 import java.awt.event.ComponentEvent;
35 import java.awt.event.MouseAdapter;
36 import java.awt.event.MouseEvent;
37 import java.awt.event.MouseMotionAdapter;
39 import javax.swing.JMenuItem;
40 import javax.swing.JPanel;
41 import javax.swing.JPopupMenu;
42 import javax.swing.SwingUtilities;
45 * Panel displaying an overview of the full alignment, with an interactive box
46 * representing the viewport onto the alignment.
51 public class OverviewPanel extends JPanel implements Runnable
53 private OverviewDimensions od;
55 private OverviewCanvas oviewCanvas;
57 private AlignViewport av;
59 private AlignmentPanel ap;
61 private boolean showHidden = true;
64 * Creates a new OverviewPanel object.
67 * The alignment panel which is shown in the overview panel
69 public OverviewPanel(AlignmentPanel alPanel)
74 od = new OverviewDimensionsWithHidden(av.getRanges(),
75 (av.isShowAnnotation() && av
76 .getAlignmentConservationAnnotation() != null));
78 oviewCanvas = new OverviewCanvas(od, av);
79 setLayout(new BorderLayout());
80 add(oviewCanvas, BorderLayout.CENTER);
82 addComponentListener(new ComponentAdapter()
85 public void componentResized(ComponentEvent evt)
87 if ((getWidth() != od.getWidth())
88 || (getHeight() != (od.getHeight())))
90 updateOverviewImage();
95 addMouseMotionListener(new MouseMotionAdapter()
98 public void mouseDragged(MouseEvent evt)
100 if (!SwingUtilities.isRightMouseButton(evt)
101 && !av.getWrapAlignment())
103 od.updateViewportFromMouse(evt.getX(), evt.getY(), av
104 .getAlignment().getHiddenSequences(), av.getAlignment()
105 .getHiddenColumns(), av.getRanges());
106 ap.setScrollValues(od.getScrollCol(), od.getScrollRow());
111 addMouseListener(new MouseAdapter()
114 public void mousePressed(MouseEvent evt)
116 if (SwingUtilities.isRightMouseButton(evt))
118 if (!Platform.isAMac())
123 else if (!av.getWrapAlignment())
125 od.updateViewportFromMouse(evt.getX(), evt.getY(), av
126 .getAlignment().getHiddenSequences(), av.getAlignment()
127 .getHiddenColumns(), av.getRanges());
128 ap.setScrollValues(od.getScrollCol(), od.getScrollRow());
133 public void mouseClicked(MouseEvent evt)
135 if (SwingUtilities.isRightMouseButton(evt))
143 updateOverviewImage();
147 * Displays the popup menu and acts on user input
149 private void showPopupMenu(MouseEvent e)
151 JPopupMenu popup = new JPopupMenu();
152 ActionListener menuListener = new ActionListener()
155 public void actionPerformed(ActionEvent event)
157 // switch on/off the hidden columns view
158 toggleHiddenColumns();
161 JMenuItem item = new JMenuItem(
162 MessageManager.getString("label.togglehidden"));
164 item.addActionListener(menuListener);
165 popup.show(this, e.getX(), e.getY());
169 * Toggle overview display between showing hidden columns and hiding hidden columns
171 private void toggleHiddenColumns()
176 od = new OverviewDimensionsAllVisible(av.getRanges(),
177 (av.isShowAnnotation() && av
178 .getAlignmentConservationAnnotation() != null));
183 od = new OverviewDimensionsWithHidden(av.getRanges(),
184 (av.isShowAnnotation() && av
185 .getAlignmentConservationAnnotation() != null));
187 oviewCanvas.resetOviewDims(od);
188 updateOverviewImage();
192 * Updates the overview image when the related alignment panel is updated
194 public void updateOverviewImage()
196 if ((getWidth() > 0) && (getHeight() > 0))
198 od.setWidth(getWidth());
199 od.setHeight(getHeight());
202 setPreferredSize(new Dimension(od.getWidth(), od.getHeight()));
204 if (oviewCanvas.restartDraw())
209 Thread thread = new Thread(this);
218 oviewCanvas.draw(av.isShowSequenceFeatures(),
219 (av.isShowAnnotation() && av
220 .getAlignmentConservationAnnotation() != null), ap
221 .getSeqPanel().seqCanvas.getFeatureRenderer());
226 * Update the overview panel box when the associated alignment panel is
230 public void setBoxPosition()
232 od.setBoxPosition(av.getAlignment()
233 .getHiddenSequences(), av
234 .getAlignment().getHiddenColumns(), av.getRanges());