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
105 .getColumnSelection(), 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
127 .getColumnSelection(), 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();
162 popup.add(item = new JMenuItem(MessageManager
163 .getString("label.togglehidden")));
164 item.addActionListener(menuListener);
165 popup.show(this, e.getX(), e.getY());
168 private void toggleHiddenColumns()
173 od = new OverviewDimensionsAllVisible(av.getRanges(),
174 (av.isShowAnnotation() && av
175 .getAlignmentConservationAnnotation() != null));
180 od = new OverviewDimensionsWithHidden(av.getRanges(),
181 (av.isShowAnnotation() && av
182 .getAlignmentConservationAnnotation() != null));
184 oviewCanvas.resetOviewDims(od);
185 updateOverviewImage();
189 * Updates the overview image when the related alignment panel is updated
191 public void updateOverviewImage()
193 if ((getWidth() > 0) && (getHeight() > 0))
195 od.setWidth(getWidth());
196 od.setHeight(getHeight());
199 setPreferredSize(new Dimension(od.getWidth(), od.getHeight()));
201 if (oviewCanvas.restartDraw())
206 Thread thread = new Thread(this);
215 oviewCanvas.draw(av.isShowSequenceFeatures(),
216 (av.isShowAnnotation() && av
217 .getAlignmentConservationAnnotation() != null), ap
218 .getSeqPanel().seqCanvas.getFeatureRenderer());
223 * Update the overview panel box when the associated alignment panel is
227 public void setBoxPosition()
229 od.setBoxPosition(av.getAlignment()
230 .getHiddenSequences(), av.getColumnSelection(), av.getRanges());