2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.appletgui;
22 import java.awt.event.*;
24 import jalview.datamodel.*;
25 import jalview.util.UrlLink;
28 extends Panel implements MouseListener, MouseMotionListener
31 protected IdCanvas idCanvas;
32 protected AlignViewport av;
33 protected AlignmentPanel alignPanel;
34 ScrollThread scrollThread = null;
39 boolean mouseDragging = false;
40 java.util.Vector links = new java.util.Vector();
42 public IdPanel(AlignViewport av, AlignmentPanel parent)
46 idCanvas = new IdCanvas(av);
47 setLayout(new BorderLayout());
48 add(idCanvas, BorderLayout.CENTER);
49 idCanvas.addMouseListener(this);
50 idCanvas.addMouseMotionListener(this);
53 if (av.applet != null)
55 for (int i = 1; i < 10; i++)
57 label = av.applet.getParameter("linkLabel_" + i);
58 url = av.applet.getParameter("linkURL_" + i);
60 if (label != null && url != null)
62 links.addElement(label + "|" + url);
69 links = new java.util.Vector();
70 links.addElement("SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry");
75 public void mouseMoved(MouseEvent e)
77 int seq = alignPanel.seqPanel.findSeq(e);
79 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
81 if (sequence.getDescription() == null)
85 tooltip.setVisible(false);
93 tooltip = new Tooltip(
94 sequence.getDisplayId(true)
95 + "\n" + sequence.getDescription(), idCanvas);
99 tooltip.setTip(sequence.getDisplayId(true)
100 + "\n" + sequence.getDescription());
104 public void mouseDragged(MouseEvent e)
106 mouseDragging = true;
108 int seq = Math.max(0, alignPanel.seqPanel.findSeq(e));
112 selectSeqs(lastid - 1, seq);
114 else if (seq > lastid)
116 selectSeqs(lastid + 1, seq);
120 alignPanel.paintAlignment(false);
123 public void mouseClicked(MouseEvent e)
125 if (e.getClickCount() < 2)
130 //DEFAULT LINK IS FIRST IN THE LINK LIST
131 int seq = alignPanel.seqPanel.findSeq(e);
132 String id = av.getAlignment().getSequenceAt(seq).getName();
134 String target = null;
137 while (url == null && i < links.size())
139 // DEFAULT LINK IS FIRST IN THE LINK LIST
140 // BUT IF ITS A REGEX AND DOES NOT MATCH THE NEXT ONE WILL BE TRIED
141 url = links.elementAt(i++).toString();
142 jalview.util.UrlLink urlLink = null;
145 urlLink = new UrlLink(url);
146 target = urlLink.getTarget();
147 } catch (Exception foo)
149 System.err.println("Exception for URLLink '" + url + "'");
150 foo.printStackTrace();
155 if (!urlLink.isValid())
157 System.err.println(urlLink.getInvalidMessage());
162 String urls[] = urlLink.makeUrls(id, true);
163 if (urls == null || urls[0]==null || urls[0].length()<1)
168 // just take first URL made from regex
174 alignPanel.alignFrame.showURL(url, target);
178 ex.printStackTrace();
182 public void mouseEntered(MouseEvent e)
184 if (scrollThread != null)
186 scrollThread.running = false;
190 public void mouseExited(MouseEvent e)
192 if (av.getWrapAlignment())
197 if (mouseDragging && e.getY() < 0 && av.getStartSeq() > 0)
199 scrollThread = new ScrollThread(true);
202 if (mouseDragging && e.getY() >= getSize().height &&
203 av.alignment.getHeight() > av.getEndSeq())
205 scrollThread = new ScrollThread(false);
209 public void mousePressed(MouseEvent e)
211 if (e.getClickCount() > 1)
217 if (av.getWrapAlignment())
219 y -= 2 * av.charHeight;
222 int seq = alignPanel.seqPanel.findSeq(e);
224 if ( (e.getModifiers() & InputEvent.BUTTON3_MASK) ==
225 InputEvent.BUTTON3_MASK)
227 APopupMenu popup = new APopupMenu(alignPanel,
228 (Sequence) av.getAlignment().
229 getSequenceAt(seq), links);
231 popup.show(this, e.getX(), e.getY());
235 if ( (av.getSelectionGroup() == null) ||
236 ( (!e.isControlDown() && !e.isShiftDown()) && av.getSelectionGroup() != null))
238 av.setSelectionGroup(new SequenceGroup());
239 av.getSelectionGroup().setStartRes(0);
240 av.getSelectionGroup().setEndRes(av.alignment.getWidth() - 1);
243 if (e.isShiftDown() && lastid != -1)
245 selectSeqs(lastid, seq);
252 alignPanel.paintAlignment(false);
255 void selectSeq(int seq)
258 SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq);
259 av.getSelectionGroup().addOrRemove(pickedSeq, false);
262 void selectSeqs(int start, int end)
267 if (end >= av.getAlignment().getHeight())
269 end = av.getAlignment().getHeight() - 1;
280 for (int i = start; i <= end; i++)
282 av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i), false);
287 public void mouseReleased(MouseEvent e)
289 if (scrollThread != null)
291 scrollThread.running = false;
294 if (av.getSelectionGroup() != null)
296 av.getSelectionGroup().recalcConservation();
299 mouseDragging = false;
300 PaintRefresher.Refresh(this, av.getSequenceSetId());
303 public void highlightSearchResults(java.util.Vector found)
305 idCanvas.setHighlighted(found);
312 int index = av.alignment.findIndex( (SequenceI) found.elementAt(0));
314 // do we need to scroll the panel?
315 if (av.getStartSeq() > index || av.getEndSeq() < index)
317 alignPanel.setScrollValues(av.getStartRes(), index);
321 // this class allows scrolling off the bottom of the visible alignment
325 boolean running = false;
327 public ScrollThread(boolean up)
333 public void stopScrolling()
343 if (alignPanel.scrollUp(up))
345 // scroll was ok, so add new sequence to selection
346 int seq = av.getStartSeq();
349 seq = av.getEndSeq();
354 selectSeqs(lastid - 1, seq);
356 else if (seq > lastid && seq < av.alignment.getHeight())
358 selectSeqs(lastid + 1, seq);
368 alignPanel.paintAlignment(true);