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
20 package jalview.gui;
\r
23 import java.awt.event.*;
\r
25 import jalview.datamodel.*;
\r
27 import javax.swing.*;
\r
29 public class IdPanel extends JPanel implements MouseListener, MouseMotionListener {
\r
31 protected IdCanvas idCanvas;
\r
32 protected AlignViewport av;
\r
33 protected AlignmentPanel alignPanel;
\r
34 ScrollThread scrollThread = null;
\r
39 boolean mouseDragging = false;
\r
41 public IdPanel(AlignViewport av, AlignmentPanel parent)
\r
44 alignPanel = parent;
\r
45 idCanvas = new IdCanvas(av);
\r
46 setLayout(new BorderLayout());
\r
47 add(idCanvas, BorderLayout.CENTER);
\r
48 addMouseListener(this);
\r
49 addMouseMotionListener(this);
\r
52 public void mouseMoved(MouseEvent e) {}
\r
55 public void mouseDragged(MouseEvent e) {
\r
56 mouseDragging = true;
\r
59 if(av.getWrapAlignment())
\r
61 int seq = av.getIndex(y);
\r
67 selectSeqs(lastid - 1, seq);
\r
68 else if (seq > lastid)
\r
69 selectSeqs(lastid + 1, seq);
\r
72 alignPanel.repaint();
\r
75 public void mouseClicked(MouseEvent e)
\r
77 if (e.getClickCount() == 2)
\r
80 if(av.getWrapAlignment())
\r
83 int seq = av.getIndex(y);
\r
84 String id = av.getAlignment().getSequenceAt(seq).getName();
\r
87 jalview.util.BrowserLauncher.openURL(
\r
88 "http://srs.ebi.ac.uk/srs7bin/cgi-bin/wgetz?-e+[swall-id:" + id +
\r
90 }catch(Exception ex){
\r
91 // TODO: JBPNote : state dependent error message for real browserLaunch problems rather than unix misconfiguration.
\r
93 ex.getMessage()+"\nUnixers: Try adding this jalview.browser property line \n"
\r
94 +"in your jalview.properties file (/usr/local/bin/firefox is an exanmple browser path):\n"
\r
95 +"jalview.browser=/usr/local/bin/firefox\n");
\r
96 //ex.printStackTrace();
\r
101 public void mouseEntered(MouseEvent e)
\r
103 if(scrollThread!=null)
\r
104 scrollThread.running = false;
\r
107 public void mouseExited (MouseEvent e)
\r
109 if(av.getWrapAlignment())
\r
112 if(mouseDragging && e.getY()<0 && av.getStartSeq()>0)
\r
114 scrollThread = new ScrollThread(true);
\r
117 if(mouseDragging && e.getY()>=getHeight() && av.alignment.getHeight()>av.getEndSeq())
\r
119 scrollThread = new ScrollThread(false);
\r
124 public void mousePressed(MouseEvent e) {
\r
125 if (e.getClickCount() == 2)
\r
129 if(av.getWrapAlignment())
\r
130 y-=2*av.charHeight;
\r
132 int seq = av.getIndex(y);
\r
136 if (javax.swing.SwingUtilities.isRightMouseButton(e))
\r
138 jalview.gui.PopupMenu pop = new jalview.gui.PopupMenu(alignPanel,
\r
139 (Sequence)av.getAlignment().getSequenceAt(seq));
\r
140 pop.show(this, e.getX(), y);
\r
144 if(!e.isControlDown() && !e.isShiftDown() && av.alignment.findGroup( av.alignment.getSequenceAt(seq))!=null)
\r
147 SequenceGroup selection = new SequenceGroup();
\r
148 SequenceGroup sg = av.alignment.findGroup(av.alignment.getSequenceAt(seq));
\r
149 selection.setStartRes(0);
\r
150 selection.setEndRes(av.alignment.getWidth()-1);
\r
151 for (int i =0; i< sg.getSize(); i++)
\r
152 selection.addSequence(sg.getSequenceAt(i));
\r
154 av.setSelectionGroup(selection);
\r
158 if(av.getSelectionGroup()==null || ( !e.isControlDown() && av.getSelectionGroup()!=null))
\r
159 av.setSelectionGroup(new SequenceGroup());
\r
161 av.getSelectionGroup().setStartRes(0);
\r
162 av.getSelectionGroup().setEndRes(av.alignment.getWidth()-1);
\r
164 if(e.isShiftDown() && lastid!=-1)
\r
165 selectSeqs(lastid, seq);
\r
169 alignPanel.repaint();
\r
172 void selectSeq(int seq)
\r
175 SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq);
\r
176 av.getSelectionGroup().addOrRemove(pickedSeq);
\r
179 void selectSeqs(int start, int end) {
\r
190 for (int i = start; i <= end; i++)
\r
191 av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i));
\r
196 public void mouseReleased(MouseEvent e)
\r
198 if(scrollThread!=null)
\r
199 scrollThread.running = false;
\r
201 mouseDragging = false;
\r
202 PaintRefresher.Refresh(this);
\r
205 public void highlightSearchResults( java.util.Vector found )
\r
207 idCanvas.setHighlighted( found );
\r
212 int index = av.alignment.findIndex( (SequenceI)found.get(0));
\r
214 // do we need to scroll the panel?
\r
215 if(av.getStartSeq()>index || av.getEndSeq()<index)
\r
216 alignPanel.setScrollValues( av.getStartRes(), index);
\r
219 // this class allows scrolling off the bottom of the visible alignment
\r
223 boolean running = false;
\r
225 public ScrollThread(boolean up)
\r
231 public void stopScrolling()
\r
241 if(alignPanel.scrollUp(up))
\r
243 // scroll was ok, so add new sequence to selection
\r
244 int seq = av.getStartSeq();
\r
246 seq = av.getEndSeq();
\r
249 selectSeqs(lastid - 1, seq);
\r
250 else if (seq > lastid)
\r
251 selectSeqs(lastid + 1, seq);
\r
258 alignPanel.repaint();
\r
263 catch (Exception ex)
\r