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.appletgui;
\r
23 import java.awt.event.*;
\r
25 import jalview.datamodel.*;
\r
27 public class IdPanel extends Panel implements MouseListener, MouseMotionListener {
\r
29 protected IdCanvas idCanvas;
\r
30 protected AlignViewport av;
\r
31 protected AlignmentPanel alignPanel;
\r
32 ScrollThread scrollThread = null;
\r
37 boolean mouseDragging = false;
\r
39 public IdPanel(AlignViewport av, AlignmentPanel parent)
\r
42 alignPanel = parent;
\r
43 idCanvas = new IdCanvas(av);
\r
44 setLayout(new BorderLayout());
\r
45 add(idCanvas, BorderLayout.CENTER);
\r
46 idCanvas.addMouseListener(this);
\r
47 idCanvas.addMouseMotionListener(this);
\r
50 public void mouseMoved(MouseEvent e) {}
\r
53 public void mouseDragged(MouseEvent e) {
\r
54 mouseDragging = true;
\r
57 if(av.getWrapAlignment())
\r
59 int seq = av.getIndex(y);
\r
65 selectSeqs(lastid - 1, seq);
\r
66 else if (seq > lastid)
\r
67 selectSeqs(lastid + 1, seq);
\r
70 alignPanel.repaint();
\r
73 public void mouseClicked(MouseEvent e)
\r
75 if (e.getClickCount() == 2)
\r
78 if(av.getWrapAlignment())
\r
81 int seq = av.getIndex(y);
\r
82 String id = av.getAlignment().getSequenceAt(seq).getName();
\r
85 jalview.bin.JalviewLite.showURL(
\r
86 "http://srs.ebi.ac.uk/srs7bin/cgi-bin/wgetz?-e+[swall-id:" + id +
\r
88 }catch(Exception ex){ex.printStackTrace();}
\r
92 public void mouseEntered(MouseEvent e)
\r
94 if(scrollThread!=null)
\r
95 scrollThread.running = false;
\r
98 public void mouseExited (MouseEvent e)
\r
100 if(av.getWrapAlignment())
\r
103 if(mouseDragging && e.getY()<0 && av.getStartSeq()>0)
\r
105 scrollThread = new ScrollThread(true);
\r
108 if(mouseDragging && e.getY()>=getSize().height && av.alignment.getHeight()>av.getEndSeq())
\r
110 scrollThread = new ScrollThread(false);
\r
115 public void mousePressed(MouseEvent e) {
\r
116 if (e.getClickCount() == 2)
\r
120 if(av.getWrapAlignment())
\r
121 y-=2*av.charHeight;
\r
123 int seq = av.getIndex(y);
\r
127 if ( (e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
\r
129 APopupMenu popup = new APopupMenu(alignPanel, null);
\r
131 popup.show(this, e.getX(), e.getY());
\r
136 if(!e.isControlDown() && !e.isShiftDown() && av.alignment.findGroup( av.alignment.getSequenceAt(seq))!=null)
\r
139 SequenceGroup selection = new SequenceGroup();
\r
140 SequenceGroup sg = av.alignment.findGroup(av.alignment.getSequenceAt(seq));
\r
141 selection.setStartRes(0);
\r
142 selection.setEndRes(av.alignment.getWidth()-1);
\r
143 for (int i =0; i< sg.getSize(); i++)
\r
144 selection.addSequence(sg.getSequenceAt(i));
\r
146 av.setSelectionGroup(selection);
\r
150 if(av.getSelectionGroup()==null || ( !e.isControlDown() && av.getSelectionGroup()!=null))
\r
151 av.setSelectionGroup(new SequenceGroup());
\r
153 av.getSelectionGroup().setStartRes(0);
\r
154 av.getSelectionGroup().setEndRes(av.alignment.getWidth()-1);
\r
156 if(e.isShiftDown() && lastid!=-1)
\r
157 selectSeqs(lastid, seq);
\r
161 alignPanel.repaint();
\r
164 void selectSeq(int seq)
\r
167 SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq);
\r
168 av.getSelectionGroup().addOrRemove(pickedSeq);
\r
171 void selectSeqs(int start, int end) {
\r
182 for (int i = start; i <= end; i++)
\r
183 av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i));
\r
188 public void mouseReleased(MouseEvent e)
\r
190 if(scrollThread!=null)
\r
191 scrollThread.running = false;
\r
193 mouseDragging = false;
\r
194 PaintRefresher.Refresh(this);
\r
197 public void highlightSearchResults( java.util.Vector found )
\r
199 idCanvas.setHighlighted( found );
\r
204 int index = av.alignment.findIndex( (SequenceI)found.elementAt(0));
\r
206 // do we need to scroll the panel?
\r
207 if(av.getStartSeq()>index || av.getEndSeq()<index)
\r
208 alignPanel.setScrollValues( av.getStartRes(), index);
\r
211 // this class allows scrolling off the bottom of the visible alignment
\r
215 boolean running = false;
\r
217 public ScrollThread(boolean up)
\r
223 public void stopScrolling()
\r
233 if(alignPanel.scrollUp(up))
\r
235 // scroll was ok, so add new sequence to selection
\r
236 int seq = av.getStartSeq();
\r
238 seq = av.getEndSeq();
\r
241 selectSeqs(lastid - 1, seq);
\r
242 else if (seq > lastid)
\r
243 selectSeqs(lastid + 1, seq);
\r
250 alignPanel.repaint();
\r
255 catch (Exception ex)
\r