2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.gui;
\r
21 import jalview.datamodel.*;
\r
24 import java.awt.event.*;
\r
26 import javax.swing.*;
\r
33 * @version $Revision$
\r
35 public class IdPanel extends JPanel implements MouseListener,
\r
38 protected IdCanvas idCanvas;
\r
39 protected AlignViewport av;
\r
40 protected AlignmentPanel alignPanel;
\r
41 ScrollThread scrollThread = null;
\r
45 boolean mouseDragging = false;
\r
48 * Creates a new IdPanel object.
\r
50 * @param av DOCUMENT ME!
\r
51 * @param parent DOCUMENT ME!
\r
53 public IdPanel(AlignViewport av, AlignmentPanel parent)
\r
56 alignPanel = parent;
\r
57 idCanvas = new IdCanvas(av);
\r
58 setLayout(new BorderLayout());
\r
59 add(idCanvas, BorderLayout.CENTER);
\r
60 addMouseListener(this);
\r
61 addMouseMotionListener(this);
\r
67 * @param e DOCUMENT ME!
\r
69 public void mouseMoved(MouseEvent e)
\r
76 * @param e DOCUMENT ME!
\r
78 public void mouseDragged(MouseEvent e)
\r
80 mouseDragging = true;
\r
84 if (av.getWrapAlignment())
\r
86 y -= (2 * av.charHeight);
\r
89 int seq = av.getIndex(y);
\r
98 selectSeqs(lastid - 1, seq);
\r
100 else if (seq > lastid)
\r
102 selectSeqs(lastid + 1, seq);
\r
106 alignPanel.repaint();
\r
113 * @param e DOCUMENT ME!
\r
115 public void mouseClicked(MouseEvent e)
\r
117 if (e.getClickCount() < 2)
\r
120 java.util.Vector links = Preferences.sequenceURLLinks;
\r
121 if (links == null || links.size() < 1)
\r
126 if (av.getWrapAlignment())
\r
128 y -= (2 * av.charHeight);
\r
131 //DEFAULT LINK IS FIRST IN THE LINK LIST
\r
132 int seq = av.getIndex(y);
\r
133 String id = av.getAlignment().getSequenceAt(seq).getName();
\r
135 String url = links.elementAt(0).toString();
\r
136 url = url.substring(url.indexOf("|")+1);
\r
138 int index = url.indexOf("$SEQUENCE_ID$");
\r
139 url = url.substring(0, index)+ id + url.substring(index+13);
\r
143 jalview.util.BrowserLauncher.openURL(url);
\r
145 catch (Exception ex)
\r
147 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
148 "Unixers: Couldn't find default web browser."
\r
149 +"\nAdd the full path to your browser in Preferences.",
\r
150 "Web browser not found", JOptionPane.WARNING_MESSAGE );
\r
151 ex.printStackTrace();
\r
158 * @param e DOCUMENT ME!
\r
160 public void mouseEntered(MouseEvent e)
\r
162 if (scrollThread != null)
\r
164 scrollThread.running = false;
\r
171 * @param e DOCUMENT ME!
\r
173 public void mouseExited(MouseEvent e)
\r
175 if (av.getWrapAlignment())
\r
180 if (mouseDragging && (e.getY() < 0) && (av.getStartSeq() > 0))
\r
182 scrollThread = new ScrollThread(true);
\r
185 if (mouseDragging && (e.getY() >= getHeight()) &&
\r
186 (av.alignment.getHeight() > av.getEndSeq()))
\r
188 scrollThread = new ScrollThread(false);
\r
195 * @param e DOCUMENT ME!
\r
197 public void mousePressed(MouseEvent e)
\r
199 if (e.getClickCount() == 2)
\r
206 if (av.getWrapAlignment())
\r
208 y -= (2 * av.charHeight);
\r
211 int seq = av.getIndex(y);
\r
218 if (javax.swing.SwingUtilities.isRightMouseButton(e))
\r
220 jalview.gui.PopupMenu pop = new jalview.gui.PopupMenu(alignPanel,
\r
221 (Sequence) av.getAlignment().getSequenceAt(seq));
\r
222 pop.show(this, e.getX(), y);
\r
227 if (!e.isControlDown() && !e.isShiftDown() &&
\r
228 (av.alignment.findGroup(av.alignment.getSequenceAt(seq)) != null))
\r
230 SequenceGroup selection = new SequenceGroup();
\r
231 SequenceGroup sg = av.alignment.findGroup(av.alignment.getSequenceAt(
\r
233 selection.setStartRes(0);
\r
234 selection.setEndRes(av.alignment.getWidth() - 1);
\r
236 for (int i = 0; i < sg.getSize(); i++)
\r
238 selection.addSequence(sg.getSequenceAt(i), true);
\r
241 av.setSelectionGroup(selection);
\r
246 if ((av.getSelectionGroup() == null) ||
\r
247 (!e.isControlDown() && (av.getSelectionGroup() != null)))
\r
249 av.setSelectionGroup(new SequenceGroup());
\r
252 av.getSelectionGroup().setStartRes(0);
\r
253 av.getSelectionGroup().setEndRes(av.alignment.getWidth() - 1);
\r
255 if (e.isShiftDown() && (lastid != -1))
\r
257 selectSeqs(lastid, seq);
\r
264 alignPanel.repaint();
\r
270 * @param seq DOCUMENT ME!
\r
272 void selectSeq(int seq)
\r
276 SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq);
\r
277 av.getSelectionGroup().addOrRemove(pickedSeq, true);
\r
283 * @param start DOCUMENT ME!
\r
284 * @param end DOCUMENT ME!
\r
286 void selectSeqs(int start, int end)
\r
298 for (int i = start; i <= end; i++)
\r
300 av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i),
\r
308 * @param e DOCUMENT ME!
\r
310 public void mouseReleased(MouseEvent e)
\r
312 if (scrollThread != null)
\r
314 scrollThread.running = false;
\r
317 mouseDragging = false;
\r
318 PaintRefresher.Refresh(av.alignment);
\r
324 * @param found DOCUMENT ME!
\r
326 public void highlightSearchResults(java.util.Vector found)
\r
328 idCanvas.setHighlighted(found);
\r
335 int index = av.alignment.findIndex((SequenceI) found.get(0));
\r
337 // do we need to scroll the panel?
\r
338 if ((av.getStartSeq() > index) || (av.getEndSeq() < index))
\r
340 alignPanel.setScrollValues(av.getStartRes(), index);
\r
344 // this class allows scrolling off the bottom of the visible alignment
\r
345 class ScrollThread extends Thread
\r
347 boolean running = false;
\r
350 public ScrollThread(boolean up)
\r
356 public void stopScrolling()
\r
367 if (alignPanel.scrollUp(up))
\r
369 // scroll was ok, so add new sequence to selection
\r
370 int seq = av.getStartSeq();
\r
374 seq = av.getEndSeq();
\r
379 selectSeqs(lastid - 1, seq);
\r
381 else if (seq > lastid)
\r
383 selectSeqs(lastid + 1, seq);
\r
393 alignPanel.repaint();
\r
399 catch (Exception ex)
\r