2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.appletgui;
23 import jalview.datamodel.Sequence;
24 import jalview.datamodel.SequenceFeature;
25 import jalview.datamodel.SequenceGroup;
26 import jalview.datamodel.SequenceI;
27 import jalview.util.UrlLink;
28 import jalview.viewmodel.AlignmentViewport;
30 import java.awt.BorderLayout;
31 import java.awt.Panel;
32 import java.awt.event.InputEvent;
33 import java.awt.event.MouseEvent;
34 import java.awt.event.MouseListener;
35 import java.awt.event.MouseMotionListener;
36 import java.util.List;
37 import java.util.Vector;
39 public class IdPanel extends Panel implements MouseListener,
43 protected IdCanvas idCanvas;
45 protected AlignmentViewport av;
47 protected AlignmentPanel alignPanel;
49 ScrollThread scrollThread = null;
57 boolean mouseDragging = false;
59 java.util.Vector links = new java.util.Vector();
61 public IdPanel(AlignViewport av, AlignmentPanel parent)
65 idCanvas = new IdCanvas(av);
66 setLayout(new BorderLayout());
67 add(idCanvas, BorderLayout.CENTER);
68 idCanvas.addMouseListener(this);
69 idCanvas.addMouseMotionListener(this);
72 // TODO: add in group link parameter
73 if (av.applet != null)
75 for (int i = 1; i < 10; i++)
77 label = av.applet.getParameter("linkLabel_" + i);
78 url = av.applet.getParameter("linkURL_" + i);
80 if (label != null && url != null)
82 links.addElement(label + "|" + url);
88 // upgrade old SRS link
90 .indexOf("SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry");
94 "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$",
100 links = new java.util.Vector();
101 links.addElement("EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$");
107 public void mouseMoved(MouseEvent e)
109 int seq = alignPanel.seqPanel.findSeq(e);
111 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
113 // look for non-pos features
114 StringBuffer tooltiptext = new StringBuffer();
115 if (sequence != null)
117 if (sequence.getDescription() != null)
119 tooltiptext.append(sequence.getDescription());
120 tooltiptext.append("\n");
123 SequenceFeature sf[] = sequence.getSequenceFeatures();
124 for (int sl = 0; sf != null && sl < sf.length; sl++)
126 if (sf[sl].begin == sf[sl].end && sf[sl].begin == 0)
129 if (sf[sl].getFeatureGroup() != null)
131 tooltiptext.append(sf[sl].getFeatureGroup());
135 if (sf[sl].getType() != null)
137 tooltiptext.append(" ");
138 tooltiptext.append(sf[sl].getType());
142 if (sf[sl].getDescription() != null)
144 tooltiptext.append(" ");
145 tooltiptext.append(sf[sl].getDescription());
149 if (sf[sl].getScore() != Float.NaN && sf[sl].getScore() != 0f)
151 tooltiptext.append(" Score = ");
152 tooltiptext.append(sf[sl].getScore());
156 if (sf[sl].getStatus() != null && sf[sl].getStatus().length() > 0)
158 tooltiptext.append(" (");
159 tooltiptext.append(sf[sl].getStatus());
160 tooltiptext.append(")");
166 tooltiptext.append("\n");
171 if (tooltiptext.length() == 0)
173 // nothing to display - so clear tooltip if one is visible
176 tooltip.setVisible(false);
184 tooltip = new Tooltip(sequence.getDisplayId(true) + "\n"
185 + tooltiptext.toString(), idCanvas);
189 tooltip.setTip(sequence.getDisplayId(true) + "\n"
190 + tooltiptext.toString());
195 public void mouseDragged(MouseEvent e)
197 mouseDragging = true;
199 int seq = Math.max(0, alignPanel.seqPanel.findSeq(e));
203 selectSeqs(lastid - 1, seq);
205 else if (seq > lastid)
207 selectSeqs(lastid + 1, seq);
211 alignPanel.paintAlignment(false);
214 public void mouseClicked(MouseEvent e)
216 if (e.getClickCount() < 2)
221 // DEFAULT LINK IS FIRST IN THE LINK LIST
222 int seq = alignPanel.seqPanel.findSeq(e);
223 SequenceI sq = av.getAlignment().getSequenceAt(seq);
228 String id = sq.getName();
230 String target = null;
233 while (url == null && i < links.size())
235 // DEFAULT LINK IS FIRST IN THE LINK LIST
236 // BUT IF ITS A REGEX AND DOES NOT MATCH THE NEXT ONE WILL BE TRIED
237 url = links.elementAt(i++).toString();
238 jalview.util.UrlLink urlLink = null;
241 urlLink = new UrlLink(url);
242 target = urlLink.getTarget();
243 } catch (Exception foo)
245 System.err.println("Exception for URLLink '" + url + "'");
246 foo.printStackTrace();
251 if (!urlLink.isValid())
253 System.err.println(urlLink.getInvalidMessage());
258 String urls[] = urlLink.makeUrls(id, true);
259 if (urls == null || urls[0] == null || urls[0].length() < 1)
264 // just take first URL made from regex
270 alignPanel.alignFrame.showURL(url, target);
271 } catch (Exception ex)
273 ex.printStackTrace();
277 public void mouseEntered(MouseEvent e)
279 if (scrollThread != null)
281 scrollThread.running = false;
285 public void mouseExited(MouseEvent e)
287 if (av.getWrapAlignment())
292 if (mouseDragging && e.getY() < 0 && av.getStartSeq() > 0)
294 scrollThread = new ScrollThread(true);
297 if (mouseDragging && e.getY() >= getSize().height
298 && av.getAlignment().getHeight() > av.getEndSeq())
300 scrollThread = new ScrollThread(false);
304 public void mousePressed(MouseEvent e)
306 if (e.getClickCount() > 1)
312 if (av.getWrapAlignment())
314 y -= 2 * av.getCharHeight();
317 int seq = alignPanel.seqPanel.findSeq(e);
319 if ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
321 Sequence sq = (Sequence) av.getAlignment().getSequenceAt(seq);
323 // build a new links menu based on the current links + any non-positional
325 Vector nlinks = new Vector();
326 for (int l = 0, lSize = links.size(); l < lSize; l++)
328 nlinks.addElement(links.elementAt(l));
330 SequenceFeature sf[] = sq == null ? null : sq.getSequenceFeatures();
331 for (int sl = 0; sf != null && sl < sf.length; sl++)
333 if (sf[sl].begin == sf[sl].end && sf[sl].begin == 0)
335 if (sf[sl].links != null && sf[sl].links.size() > 0)
337 for (int l = 0, lSize = sf[sl].links.size(); l < lSize; l++)
339 nlinks.addElement(sf[sl].links.elementAt(l));
345 APopupMenu popup = new APopupMenu(alignPanel, sq, nlinks);
347 popup.show(this, e.getX(), e.getY());
351 if ((av.getSelectionGroup() == null)
352 || ((!e.isControlDown() && !e.isShiftDown()) && av
353 .getSelectionGroup() != null))
355 av.setSelectionGroup(new SequenceGroup());
356 av.getSelectionGroup().setStartRes(0);
357 av.getSelectionGroup().setEndRes(av.getAlignment().getWidth() - 1);
360 if (e.isShiftDown() && lastid != -1)
362 selectSeqs(lastid, seq);
369 alignPanel.paintAlignment(false);
372 void selectSeq(int seq)
375 SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq);
376 av.getSelectionGroup().addOrRemove(pickedSeq, true);
379 void selectSeqs(int start, int end)
384 if (end >= av.getAlignment().getHeight())
386 end = av.getAlignment().getHeight() - 1;
396 if (av.getSelectionGroup() == null)
398 av.setSelectionGroup(new SequenceGroup());
400 for (int i = start; i <= end; i++)
402 av.getSelectionGroup().addSequence(
403 av.getAlignment().getSequenceAt(i), i == end);
408 public void mouseReleased(MouseEvent e)
410 if (scrollThread != null)
412 scrollThread.running = false;
415 if (av.getSelectionGroup() != null)
417 av.getSelectionGroup().recalcConservation();
420 mouseDragging = false;
421 PaintRefresher.Refresh(this, av.getSequenceSetId());
422 // always send selection message when mouse is released
426 public void highlightSearchResults(List<SequenceI> list)
428 idCanvas.setHighlighted(list);
435 int index = av.getAlignment().findIndex(list.get(0));
437 // do we need to scroll the panel?
438 if (av.getStartSeq() > index || av.getEndSeq() < index)
440 alignPanel.setScrollValues(av.getStartRes(), index);
444 // this class allows scrolling off the bottom of the visible alignment
445 class ScrollThread extends Thread
447 boolean running = false;
451 public ScrollThread(boolean up)
457 public void stopScrolling()
467 if (alignPanel.scrollUp(up))
469 // scroll was ok, so add new sequence to selection
470 int seq = av.getStartSeq();
473 seq = av.getEndSeq();
478 selectSeqs(lastid - 1, seq);
480 else if (seq > lastid && seq < av.getAlignment().getHeight())
482 selectSeqs(lastid + 1, seq);
492 alignPanel.paintAlignment(true);
496 } catch (Exception ex)