2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4.0.b2)
3 * Copyright (C) 2009 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;
27 public class IdPanel extends Panel implements MouseListener,
31 protected IdCanvas idCanvas;
33 protected AlignViewport av;
35 protected AlignmentPanel alignPanel;
37 ScrollThread scrollThread = null;
45 boolean mouseDragging = false;
47 java.util.Vector links = new java.util.Vector();
49 public IdPanel(AlignViewport av, AlignmentPanel parent)
53 idCanvas = new IdCanvas(av);
54 setLayout(new BorderLayout());
55 add(idCanvas, BorderLayout.CENTER);
56 idCanvas.addMouseListener(this);
57 idCanvas.addMouseMotionListener(this);
60 if (av.applet != null)
62 for (int i = 1; i < 10; i++)
64 label = av.applet.getParameter("linkLabel_" + i);
65 url = av.applet.getParameter("linkURL_" + i);
67 if (label != null && url != null)
69 links.addElement(label + "|" + url);
76 links = new java.util.Vector();
78 .addElement("SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry");
84 public void mouseMoved(MouseEvent e)
86 int seq = alignPanel.seqPanel.findSeq(e);
88 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
90 if (sequence.getDescription() == null)
94 tooltip.setVisible(false);
102 tooltip = new Tooltip(sequence.getDisplayId(true) + "\n"
103 + sequence.getDescription(), idCanvas);
107 tooltip.setTip(sequence.getDisplayId(true) + "\n"
108 + sequence.getDescription());
112 public void mouseDragged(MouseEvent e)
114 mouseDragging = true;
116 int seq = Math.max(0, alignPanel.seqPanel.findSeq(e));
120 selectSeqs(lastid - 1, seq);
122 else if (seq > lastid)
124 selectSeqs(lastid + 1, seq);
128 alignPanel.paintAlignment(false);
131 public void mouseClicked(MouseEvent e)
133 if (e.getClickCount() < 2)
138 // DEFAULT LINK IS FIRST IN THE LINK LIST
139 int seq = alignPanel.seqPanel.findSeq(e);
140 String id = av.getAlignment().getSequenceAt(seq).getName();
142 String target = null;
145 while (url == null && i < links.size())
147 // DEFAULT LINK IS FIRST IN THE LINK LIST
148 // BUT IF ITS A REGEX AND DOES NOT MATCH THE NEXT ONE WILL BE TRIED
149 url = links.elementAt(i++).toString();
150 jalview.util.UrlLink urlLink = null;
153 urlLink = new UrlLink(url);
154 target = urlLink.getTarget();
155 } catch (Exception foo)
157 System.err.println("Exception for URLLink '" + url + "'");
158 foo.printStackTrace();
163 if (!urlLink.isValid())
165 System.err.println(urlLink.getInvalidMessage());
170 String urls[] = urlLink.makeUrls(id, true);
171 if (urls == null || urls[0] == null || urls[0].length() < 1)
176 // just take first URL made from regex
182 alignPanel.alignFrame.showURL(url, target);
183 } catch (Exception ex)
185 ex.printStackTrace();
189 public void mouseEntered(MouseEvent e)
191 if (scrollThread != null)
193 scrollThread.running = false;
197 public void mouseExited(MouseEvent e)
199 if (av.getWrapAlignment())
204 if (mouseDragging && e.getY() < 0 && av.getStartSeq() > 0)
206 scrollThread = new ScrollThread(true);
209 if (mouseDragging && e.getY() >= getSize().height
210 && av.alignment.getHeight() > av.getEndSeq())
212 scrollThread = new ScrollThread(false);
216 public void mousePressed(MouseEvent e)
218 if (e.getClickCount() > 1)
224 if (av.getWrapAlignment())
226 y -= 2 * av.charHeight;
229 int seq = alignPanel.seqPanel.findSeq(e);
231 if ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
233 APopupMenu popup = new APopupMenu(alignPanel, (Sequence) av
234 .getAlignment().getSequenceAt(seq), links);
236 popup.show(this, e.getX(), e.getY());
240 if ((av.getSelectionGroup() == null)
241 || ((!e.isControlDown() && !e.isShiftDown()) && av
242 .getSelectionGroup() != null))
244 av.setSelectionGroup(new SequenceGroup());
245 av.getSelectionGroup().setStartRes(0);
246 av.getSelectionGroup().setEndRes(av.alignment.getWidth() - 1);
249 if (e.isShiftDown() && lastid != -1)
251 selectSeqs(lastid, seq);
258 alignPanel.paintAlignment(false);
261 void selectSeq(int seq)
264 SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq);
265 av.getSelectionGroup().addOrRemove(pickedSeq, false);
268 void selectSeqs(int start, int end)
273 if (end >= av.getAlignment().getHeight())
275 end = av.getAlignment().getHeight() - 1;
286 for (int i = start; i <= end; i++)
288 av.getSelectionGroup().addSequence(
289 av.getAlignment().getSequenceAt(i), false);
294 public void mouseReleased(MouseEvent e)
296 if (scrollThread != null)
298 scrollThread.running = false;
301 if (av.getSelectionGroup() != null)
303 av.getSelectionGroup().recalcConservation();
306 mouseDragging = false;
307 PaintRefresher.Refresh(this, av.getSequenceSetId());
310 public void highlightSearchResults(java.util.Vector found)
312 idCanvas.setHighlighted(found);
319 int index = av.alignment.findIndex((SequenceI) found.elementAt(0));
321 // do we need to scroll the panel?
322 if (av.getStartSeq() > index || av.getEndSeq() < index)
324 alignPanel.setScrollValues(av.getStartRes(), index);
328 // this class allows scrolling off the bottom of the visible alignment
329 class ScrollThread extends Thread
331 boolean running = false;
335 public ScrollThread(boolean up)
341 public void stopScrolling()
351 if (alignPanel.scrollUp(up))
353 // scroll was ok, so add new sequence to selection
354 int seq = av.getStartSeq();
357 seq = av.getEndSeq();
362 selectSeqs(lastid - 1, seq);
364 else if (seq > lastid && seq < av.alignment.getHeight())
366 selectSeqs(lastid + 1, seq);
376 alignPanel.paintAlignment(true);
380 } catch (Exception ex)