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
112 * @param e DOCUMENT ME!
\r
114 public void mouseClicked(MouseEvent e)
\r
116 if (e.getClickCount() == 2)
\r
120 if (av.getWrapAlignment())
\r
122 y -= (2 * av.charHeight);
\r
125 int seq = av.getIndex(y);
\r
126 String id = av.getAlignment().getSequenceAt(seq).getName();
\r
130 jalview.util.BrowserLauncher.openURL(
\r
131 "http://srs.ebi.ac.uk/srs7bin/cgi-bin/wgetz?-e+[uniprot-all:" +
\r
134 catch (Exception ex)
\r
136 // TODO: JBPNote : state dependent error message for real browserLaunch problems rather than unix misconfiguration.
\r
137 System.err.println(ex.getMessage() +
\r
138 "\nUnixers: Try adding this jalview.browser property line \n" +
\r
139 "in your jalview.properties file (/usr/local/bin/firefox is an exanmple browser path):\n" +
\r
140 "jalview.browser=/usr/local/bin/firefox\n");
\r
142 //ex.printStackTrace();
\r
150 * @param e DOCUMENT ME!
\r
152 public void mouseEntered(MouseEvent e)
\r
154 if (scrollThread != null)
\r
156 scrollThread.running = false;
\r
163 * @param e DOCUMENT ME!
\r
165 public void mouseExited(MouseEvent e)
\r
167 if (av.getWrapAlignment())
\r
172 if (mouseDragging && (e.getY() < 0) && (av.getStartSeq() > 0))
\r
174 scrollThread = new ScrollThread(true);
\r
177 if (mouseDragging && (e.getY() >= getHeight()) &&
\r
178 (av.alignment.getHeight() > av.getEndSeq()))
\r
180 scrollThread = new ScrollThread(false);
\r
187 * @param e DOCUMENT ME!
\r
189 public void mousePressed(MouseEvent e)
\r
191 if (e.getClickCount() == 2)
\r
198 if (av.getWrapAlignment())
\r
200 y -= (2 * av.charHeight);
\r
203 int seq = av.getIndex(y);
\r
210 if (javax.swing.SwingUtilities.isRightMouseButton(e))
\r
212 jalview.gui.PopupMenu pop = new jalview.gui.PopupMenu(alignPanel,
\r
213 (Sequence) av.getAlignment().getSequenceAt(seq));
\r
214 pop.show(this, e.getX(), y);
\r
219 if (!e.isControlDown() && !e.isShiftDown() &&
\r
220 (av.alignment.findGroup(av.alignment.getSequenceAt(seq)) != null))
\r
222 SequenceGroup selection = new SequenceGroup();
\r
223 SequenceGroup sg = av.alignment.findGroup(av.alignment.getSequenceAt(
\r
225 selection.setStartRes(0);
\r
226 selection.setEndRes(av.alignment.getWidth() - 1);
\r
228 for (int i = 0; i < sg.getSize(); i++)
\r
230 selection.addSequence(sg.getSequenceAt(i), true);
\r
233 av.setSelectionGroup(selection);
\r
238 if ((av.getSelectionGroup() == null) ||
\r
239 (!e.isControlDown() && (av.getSelectionGroup() != null)))
\r
241 av.setSelectionGroup(new SequenceGroup());
\r
244 av.getSelectionGroup().setStartRes(0);
\r
245 av.getSelectionGroup().setEndRes(av.alignment.getWidth() - 1);
\r
247 if (e.isShiftDown() && (lastid != -1))
\r
249 selectSeqs(lastid, seq);
\r
256 alignPanel.repaint();
\r
262 * @param seq DOCUMENT ME!
\r
264 void selectSeq(int seq)
\r
268 SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq);
\r
269 av.getSelectionGroup().addOrRemove(pickedSeq, true);
\r
275 * @param start DOCUMENT ME!
\r
276 * @param end DOCUMENT ME!
\r
278 void selectSeqs(int start, int end)
\r
290 for (int i = start; i <= end; i++)
\r
292 av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i),
\r
300 * @param e DOCUMENT ME!
\r
302 public void mouseReleased(MouseEvent e)
\r
304 if (scrollThread != null)
\r
306 scrollThread.running = false;
\r
309 mouseDragging = false;
\r
310 PaintRefresher.Refresh(av.alignment);
\r
316 * @param found DOCUMENT ME!
\r
318 public void highlightSearchResults(java.util.Vector found)
\r
320 idCanvas.setHighlighted(found);
\r
327 int index = av.alignment.findIndex((SequenceI) found.get(0));
\r
329 // do we need to scroll the panel?
\r
330 if ((av.getStartSeq() > index) || (av.getEndSeq() < index))
\r
332 alignPanel.setScrollValues(av.getStartRes(), index);
\r
336 // this class allows scrolling off the bottom of the visible alignment
\r
337 class ScrollThread extends Thread
\r
339 boolean running = false;
\r
342 public ScrollThread(boolean up)
\r
348 public void stopScrolling()
\r
359 if (alignPanel.scrollUp(up))
\r
361 // scroll was ok, so add new sequence to selection
\r
362 int seq = av.getStartSeq();
\r
366 seq = av.getEndSeq();
\r
371 selectSeqs(lastid - 1, seq);
\r
373 else if (seq > lastid)
\r
375 selectSeqs(lastid + 1, seq);
\r
385 alignPanel.repaint();
\r
391 catch (Exception ex)
\r