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
\r
28 extends Panel 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
40 java.util.Vector links = new java.util.Vector();
\r
42 public IdPanel(AlignViewport av, AlignmentPanel parent)
\r
45 alignPanel = parent;
\r
46 idCanvas = new IdCanvas(av);
\r
47 setLayout(new BorderLayout());
\r
48 add(idCanvas, BorderLayout.CENTER);
\r
49 idCanvas.addMouseListener(this);
\r
50 idCanvas.addMouseMotionListener(this);
\r
53 if(parent.alignFrame.applet!=null)
\r
55 for (int i = 1; i < 10; i++)
\r
57 label = parent.alignFrame.applet.getParameter("linkLabel_" + i);
\r
58 url = parent.alignFrame.applet.getParameter("linkURL_" + i);
\r
60 if (label != null && url != null)
\r
61 links.addElement(label + "|" + url);
\r
65 if (links.size() < 1)
\r
67 links = new java.util.Vector();
\r
68 links.addElement("SRS|http://srs.ebi.ac.uk/srs7bin/cgi-bin/wgetz?-e+[uniprot-all:$SEQUENCE_ID$]+-vn+2");
\r
73 public void mouseMoved(MouseEvent e)
\r
76 if (av.getWrapAlignment())
\r
78 y -= 2 * av.charHeight;
\r
81 int seq = av.getIndex(y);
\r
87 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
\r
89 if(sequence.getDescription()==null)
\r
92 tooltip.setVisible(false);
\r
97 if (tooltip == null)
\r
98 tooltip = new Tooltip(
\r
99 sequence.getDisplayId(true)
\r
100 + "\n" + sequence.getDescription(), idCanvas);
\r
102 tooltip.setTip(sequence.getDisplayId(true)
\r
103 + "\n" + sequence.getDescription());
\r
109 public void mouseDragged(MouseEvent e)
\r
111 mouseDragging = true;
\r
114 if (av.getWrapAlignment())
\r
116 y -= 2 * av.charHeight;
\r
118 int seq = av.getIndex(y);
\r
127 selectSeqs(lastid - 1, seq);
\r
129 else if (seq > lastid)
\r
131 selectSeqs(lastid + 1, seq);
\r
135 alignPanel.repaint();
\r
138 public void mouseClicked(MouseEvent e)
\r
140 if (e.getClickCount() < 2)
\r
145 if (av.getWrapAlignment())
\r
147 y -= (2 * av.charHeight);
\r
150 //DEFAULT LINK IS FIRST IN THE LINK LIST
\r
151 int seq = av.getIndex(y);
\r
152 String id = av.getAlignment().getSequenceAt(seq).getName();
\r
153 if (id.indexOf("|") > -1)
\r
154 id = id.substring(id.lastIndexOf("|") + 1);
\r
156 String target = links.elementAt(0).toString();
\r
157 target = target.substring(0, target.indexOf("|"));
\r
158 String url = links.elementAt(0).toString();
\r
159 url = url.substring(url.indexOf("|")+1);
\r
161 int index = url.indexOf("$SEQUENCE_ID$");
\r
162 url = url.substring(0, index)+ id + url.substring(index+13);
\r
167 alignPanel.alignFrame.showURL(url, target);
\r
169 catch (Exception ex)
\r
171 ex.printStackTrace();
\r
175 public void mouseEntered(MouseEvent e)
\r
177 if (scrollThread != null)
\r
179 scrollThread.running = false;
\r
183 public void mouseExited(MouseEvent e)
\r
185 if (av.getWrapAlignment())
\r
190 if (mouseDragging && e.getY() < 0 && av.getStartSeq() > 0)
\r
192 scrollThread = new ScrollThread(true);
\r
195 if (mouseDragging && e.getY() >= getSize().height &&
\r
196 av.alignment.getHeight() > av.getEndSeq())
\r
198 scrollThread = new ScrollThread(false);
\r
202 public void mousePressed(MouseEvent e)
\r
204 if (e.getClickCount() >1 )
\r
210 if (av.getWrapAlignment())
\r
212 y -= 2 * av.charHeight;
\r
215 int seq = av.getIndex(y);
\r
221 if ( (e.getModifiers() & InputEvent.BUTTON3_MASK) ==
\r
222 InputEvent.BUTTON3_MASK)
\r
224 APopupMenu popup = new APopupMenu(alignPanel, (Sequence) av.getAlignment().getSequenceAt(seq), links);
\r
226 popup.show(this, e.getX(), e.getY());
\r
231 if ((av.getSelectionGroup() == null) ||
\r
232 ((!e.isControlDown() && !e.isShiftDown()) && av.getSelectionGroup() != null))
\r
234 av.setSelectionGroup(new SequenceGroup());
\r
235 av.getSelectionGroup().setStartRes(0);
\r
236 av.getSelectionGroup().setEndRes(av.alignment.getWidth() - 1);
\r
240 if (e.isShiftDown() && lastid != -1)
\r
242 selectSeqs(lastid, seq);
\r
249 alignPanel.repaint();
\r
252 void selectSeq(int seq)
\r
255 SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq);
\r
256 av.getSelectionGroup().addOrRemove(pickedSeq, false);
\r
259 void selectSeqs(int start, int end)
\r
271 for (int i = start; i <= end; i++)
\r
273 av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i), false);
\r
278 public void mouseReleased(MouseEvent e)
\r
280 if (scrollThread != null)
\r
282 scrollThread.running = false;
\r
285 if(av.getSelectionGroup()!=null)
\r
286 av.getSelectionGroup().recalcConservation();
\r
288 mouseDragging = false;
\r
289 PaintRefresher.Refresh(this, av.alignment);
\r
292 public void highlightSearchResults(java.util.Vector found)
\r
294 idCanvas.setHighlighted(found);
\r
301 int index = av.alignment.findIndex( (SequenceI) found.elementAt(0));
\r
303 // do we need to scroll the panel?
\r
304 if (av.getStartSeq() > index || av.getEndSeq() < index)
\r
306 alignPanel.setScrollValues(av.getStartRes(), index);
\r
310 // this class allows scrolling off the bottom of the visible alignment
\r
314 boolean running = false;
\r
316 public ScrollThread(boolean up)
\r
322 public void stopScrolling()
\r
332 if (alignPanel.scrollUp(up))
\r
334 // scroll was ok, so add new sequence to selection
\r
335 int seq = av.getStartSeq();
\r
338 seq = av.getEndSeq();
\r
343 selectSeqs(lastid - 1, seq);
\r
345 else if (seq > lastid)
\r
347 selectSeqs(lastid + 1, seq);
\r
357 alignPanel.repaint();
\r
362 catch (Exception ex)
\r