2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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;
24 import java.awt.event.*;
25 import java.util.List;
26 import java.util.Vector;
28 import jalview.datamodel.*;
29 import jalview.util.UrlLink;
31 public class IdPanel extends Panel implements MouseListener,
35 protected IdCanvas idCanvas;
37 protected AlignViewport av;
39 protected AlignmentPanel alignPanel;
41 ScrollThread scrollThread = null;
49 boolean mouseDragging = false;
51 java.util.Vector links = new java.util.Vector();
53 public IdPanel(AlignViewport av, AlignmentPanel parent)
57 idCanvas = new IdCanvas(av);
58 setLayout(new BorderLayout());
59 add(idCanvas, BorderLayout.CENTER);
60 idCanvas.addMouseListener(this);
61 idCanvas.addMouseMotionListener(this);
64 // TODO: add in group link parameter
65 if (av.applet != null)
67 for (int i = 1; i < 10; i++)
69 label = av.applet.getParameter("linkLabel_" + i);
70 url = av.applet.getParameter("linkURL_" + i);
72 if (label != null && url != null)
74 links.addElement(label + "|" + url);
80 // upgrade old SRS link
82 .indexOf("SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry");
86 "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$",
92 links = new java.util.Vector();
93 links.addElement("EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$");
99 public void mouseMoved(MouseEvent e)
101 int seq = alignPanel.seqPanel.findSeq(e);
103 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
105 // look for non-pos features
106 StringBuffer tooltiptext = new StringBuffer();
107 if (sequence != null)
109 if (sequence.getDescription() != null)
111 tooltiptext.append(sequence.getDescription());
112 tooltiptext.append("\n");
115 SequenceFeature sf[] = sequence.getSequenceFeatures();
116 for (int sl = 0; sf != null && sl < sf.length; sl++)
118 if (sf[sl].begin == sf[sl].end && sf[sl].begin == 0)
121 if (sf[sl].getFeatureGroup() != null)
123 tooltiptext.append(sf[sl].getFeatureGroup());
127 if (sf[sl].getType() != null)
129 tooltiptext.append(" ");
130 tooltiptext.append(sf[sl].getType());
134 if (sf[sl].getDescription() != null)
136 tooltiptext.append(" ");
137 tooltiptext.append(sf[sl].getDescription());
141 if (sf[sl].getScore() != Float.NaN && sf[sl].getScore() != 0f)
143 tooltiptext.append(" Score = ");
144 tooltiptext.append(sf[sl].getScore());
148 if (sf[sl].getStatus() != null && sf[sl].getStatus().length() > 0)
150 tooltiptext.append(" (");
151 tooltiptext.append(sf[sl].getStatus());
152 tooltiptext.append(")");
158 tooltiptext.append("\n");
163 if (tooltiptext.length() == 0)
165 // nothing to display - so clear tooltip if one is visible
168 tooltip.setVisible(false);
176 tooltip = new Tooltip(sequence.getDisplayId(true) + "\n"
177 + tooltiptext.toString(), idCanvas);
181 tooltip.setTip(sequence.getDisplayId(true) + "\n"
182 + tooltiptext.toString());
187 public void mouseDragged(MouseEvent e)
189 mouseDragging = true;
191 int seq = Math.max(0, alignPanel.seqPanel.findSeq(e));
195 selectSeqs(lastid - 1, seq);
197 else if (seq > lastid)
199 selectSeqs(lastid + 1, seq);
203 alignPanel.paintAlignment(false);
206 public void mouseClicked(MouseEvent e)
208 if (e.getClickCount() < 2)
213 // DEFAULT LINK IS FIRST IN THE LINK LIST
214 int seq = alignPanel.seqPanel.findSeq(e);
215 SequenceI sq = av.getAlignment().getSequenceAt(seq);
220 String id = sq.getName();
222 String target = null;
225 while (url == null && i < links.size())
227 // DEFAULT LINK IS FIRST IN THE LINK LIST
228 // BUT IF ITS A REGEX AND DOES NOT MATCH THE NEXT ONE WILL BE TRIED
229 url = links.elementAt(i++).toString();
230 jalview.util.UrlLink urlLink = null;
233 urlLink = new UrlLink(url);
234 target = urlLink.getTarget();
235 } catch (Exception foo)
237 System.err.println("Exception for URLLink '" + url + "'");
238 foo.printStackTrace();
243 if (!urlLink.isValid())
245 System.err.println(urlLink.getInvalidMessage());
250 String urls[] = urlLink.makeUrls(id, true);
251 if (urls == null || urls[0] == null || urls[0].length() < 1)
256 // just take first URL made from regex
262 alignPanel.alignFrame.showURL(url, target);
263 } catch (Exception ex)
265 ex.printStackTrace();
269 public void mouseEntered(MouseEvent e)
271 if (scrollThread != null)
273 scrollThread.running = false;
277 public void mouseExited(MouseEvent e)
279 if (av.getWrapAlignment())
284 if (mouseDragging && e.getY() < 0 && av.getStartSeq() > 0)
286 scrollThread = new ScrollThread(true);
289 if (mouseDragging && e.getY() >= getSize().height
290 && av.getAlignment().getHeight() > av.getEndSeq())
292 scrollThread = new ScrollThread(false);
296 public void mousePressed(MouseEvent e)
298 if (e.getClickCount() > 1)
304 if (av.getWrapAlignment())
306 y -= 2 * av.charHeight;
309 int seq = alignPanel.seqPanel.findSeq(e);
311 if ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
313 Sequence sq = (Sequence) av.getAlignment().getSequenceAt(seq);
315 // build a new links menu based on the current links + any non-positional
317 Vector nlinks = new Vector();
318 for (int l = 0, lSize = links.size(); l < lSize; l++)
320 nlinks.addElement(links.elementAt(l));
322 SequenceFeature sf[] = sq == null ? null : sq.getSequenceFeatures();
323 for (int sl = 0; sf != null && sl < sf.length; sl++)
325 if (sf[sl].begin == sf[sl].end && sf[sl].begin == 0)
327 if (sf[sl].links != null && sf[sl].links.size() > 0)
329 for (int l = 0, lSize = sf[sl].links.size(); l < lSize; l++)
331 nlinks.addElement(sf[sl].links.elementAt(l));
337 APopupMenu popup = new APopupMenu(alignPanel, sq, nlinks);
339 popup.show(this, e.getX(), e.getY());
343 if ((av.getSelectionGroup() == null)
344 || ((!e.isControlDown() && !e.isShiftDown()) && av
345 .getSelectionGroup() != null))
347 av.setSelectionGroup(new SequenceGroup());
348 av.getSelectionGroup().setStartRes(0);
349 av.getSelectionGroup().setEndRes(av.getAlignment().getWidth() - 1);
352 if (e.isShiftDown() && lastid != -1)
354 selectSeqs(lastid, seq);
361 alignPanel.paintAlignment(false);
364 void selectSeq(int seq)
367 SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq);
368 av.getSelectionGroup().addOrRemove(pickedSeq, true);
371 void selectSeqs(int start, int end)
376 if (end >= av.getAlignment().getHeight())
378 end = av.getAlignment().getHeight() - 1;
388 if (av.getSelectionGroup() == null)
390 av.setSelectionGroup(new SequenceGroup());
392 for (int i = start; i <= end; i++)
394 av.getSelectionGroup().addSequence(
395 av.getAlignment().getSequenceAt(i), i == end);
400 public void mouseReleased(MouseEvent e)
402 if (scrollThread != null)
404 scrollThread.running = false;
407 if (av.getSelectionGroup() != null)
409 av.getSelectionGroup().recalcConservation();
412 mouseDragging = false;
413 PaintRefresher.Refresh(this, av.getSequenceSetId());
414 // always send selection message when mouse is released
418 public void highlightSearchResults(List<SequenceI> list)
420 idCanvas.setHighlighted(list);
427 int index = av.getAlignment().findIndex(list.get(0));
429 // do we need to scroll the panel?
430 if (av.getStartSeq() > index || av.getEndSeq() < index)
432 alignPanel.setScrollValues(av.getStartRes(), index);
436 // this class allows scrolling off the bottom of the visible alignment
437 class ScrollThread extends Thread
439 boolean running = false;
443 public ScrollThread(boolean up)
449 public void stopScrolling()
459 if (alignPanel.scrollUp(up))
461 // scroll was ok, so add new sequence to selection
462 int seq = av.getStartSeq();
465 seq = av.getEndSeq();
470 selectSeqs(lastid - 1, seq);
472 else if (seq > lastid && seq < av.getAlignment().getHeight())
474 selectSeqs(lastid + 1, seq);
484 alignPanel.paintAlignment(true);
488 } catch (Exception ex)