2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
\r
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
\r
5 * This file is part of Jalview.
\r
7 * Jalview is free software: you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation, either version 3
\r
10 * of the License, or (at your option) any later version.
\r
12 * Jalview is distributed in the hope that it will be useful, but
\r
13 * WITHOUT ANY WARRANTY; without even the implied warranty
\r
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
\r
15 * PURPOSE. See the GNU General Public License for more details.
\r
17 * You should have received a copy of the GNU General Public License
\r
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
\r
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
\r
21 package jalview.appletgui;
\r
23 import jalview.datamodel.Sequence;
\r
24 import jalview.datamodel.SequenceFeature;
\r
25 import jalview.datamodel.SequenceGroup;
\r
26 import jalview.datamodel.SequenceI;
\r
27 import jalview.util.UrlLink;
\r
28 import jalview.viewmodel.AlignmentViewport;
\r
30 import java.awt.BorderLayout;
\r
31 import java.awt.Panel;
\r
32 import java.awt.event.InputEvent;
\r
33 import java.awt.event.MouseEvent;
\r
34 import java.awt.event.MouseListener;
\r
35 import java.awt.event.MouseMotionListener;
\r
36 import java.util.List;
\r
37 import java.util.Vector;
\r
39 public class IdPanel extends Panel implements MouseListener,
\r
43 protected IdCanvas idCanvas;
\r
45 protected AlignmentViewport av;
\r
47 protected AlignmentPanel alignPanel;
\r
49 ScrollThread scrollThread = null;
\r
53 boolean mouseDragging = false;
\r
55 java.util.Vector links = new java.util.Vector();
\r
57 public IdPanel(AlignViewport av, AlignmentPanel parent)
\r
60 alignPanel = parent;
\r
61 idCanvas = new IdCanvas(av);
\r
62 setLayout(new BorderLayout());
\r
63 add(idCanvas, BorderLayout.CENTER);
\r
64 idCanvas.addMouseListener(this);
\r
65 idCanvas.addMouseMotionListener(this);
\r
68 // TODO: add in group link parameter
\r
69 if (av.applet != null)
\r
71 for (int i = 1; i < 10; i++)
\r
73 label = av.applet.getParameter("linkLabel_" + i);
\r
74 url = av.applet.getParameter("linkURL_" + i);
\r
76 if (label != null && url != null)
\r
78 links.addElement(label + "|" + url);
\r
84 // upgrade old SRS link
\r
86 .indexOf("SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry");
\r
90 "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$",
\r
94 if (links.size() < 1)
\r
96 links = new java.util.Vector();
\r
97 links.addElement("EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$");
\r
103 public void mouseMoved(MouseEvent e)
\r
105 int seq = alignPanel.seqPanel.findSeq(e);
\r
107 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
\r
109 // look for non-pos features
\r
110 StringBuffer tooltiptext = new StringBuffer();
\r
111 if (sequence != null)
\r
113 if (sequence.getDescription() != null)
\r
115 tooltiptext.append(sequence.getDescription());
\r
116 tooltiptext.append("\n");
\r
119 SequenceFeature sf[] = sequence.getSequenceFeatures();
\r
120 for (int sl = 0; sf != null && sl < sf.length; sl++)
\r
122 if (sf[sl].begin == sf[sl].end && sf[sl].begin == 0)
\r
124 boolean nl = false;
\r
125 if (sf[sl].getFeatureGroup() != null)
\r
127 tooltiptext.append(sf[sl].getFeatureGroup());
\r
131 if (sf[sl].getType() != null)
\r
133 tooltiptext.append(" ");
\r
134 tooltiptext.append(sf[sl].getType());
\r
138 if (sf[sl].getDescription() != null)
\r
140 tooltiptext.append(" ");
\r
141 tooltiptext.append(sf[sl].getDescription());
\r
145 if (sf[sl].getScore() != Float.NaN && sf[sl].getScore() != 0f)
\r
147 tooltiptext.append(" Score = ");
\r
148 tooltiptext.append(sf[sl].getScore());
\r
152 if (sf[sl].getStatus() != null && sf[sl].getStatus().length() > 0)
\r
154 tooltiptext.append(" (");
\r
155 tooltiptext.append(sf[sl].getStatus());
\r
156 tooltiptext.append(")");
\r
162 tooltiptext.append("\n");
\r
167 if (tooltiptext.length() == 0)
\r
169 // nothing to display - so clear tooltip if one is visible
\r
170 if (tooltip != null)
\r
172 tooltip.setVisible(false);
\r
175 tooltiptext = null;
\r
178 if (tooltip == null)
\r
180 tooltip = new Tooltip(sequence.getDisplayId(true) + "\n"
\r
181 + tooltiptext.toString(), idCanvas);
\r
185 tooltip.setTip(sequence.getDisplayId(true) + "\n"
\r
186 + tooltiptext.toString());
\r
188 tooltiptext = null;
\r
191 public void mouseDragged(MouseEvent e)
\r
193 mouseDragging = true;
\r
195 int seq = Math.max(0, alignPanel.seqPanel.findSeq(e));
\r
199 selectSeqs(lastid - 1, seq);
\r
201 else if (seq > lastid)
\r
203 selectSeqs(lastid + 1, seq);
\r
207 alignPanel.paintAlignment(false);
\r
210 public void mouseClicked(MouseEvent e)
\r
212 if (e.getClickCount() < 2)
\r
217 // DEFAULT LINK IS FIRST IN THE LINK LIST
\r
218 int seq = alignPanel.seqPanel.findSeq(e);
\r
219 SequenceI sq = av.getAlignment().getSequenceAt(seq);
\r
224 String id = sq.getName();
\r
226 String target = null;
\r
229 while (url == null && i < links.size())
\r
231 // DEFAULT LINK IS FIRST IN THE LINK LIST
\r
232 // BUT IF ITS A REGEX AND DOES NOT MATCH THE NEXT ONE WILL BE TRIED
\r
233 url = links.elementAt(i++).toString();
\r
234 UrlLink urlLink = null;
\r
237 urlLink = new UrlLink(url);
\r
238 target = urlLink.getTarget();
\r
239 } catch (Exception foo)
\r
241 System.err.println("Exception for URLLink '" + url + "'");
\r
242 foo.printStackTrace();
\r
247 if (!urlLink.isValid())
\r
249 System.err.println(urlLink.getInvalidMessage());
\r
254 String urls[] = urlLink.makeUrls(id, true);
\r
255 if (urls == null || urls[0] == null || urls[0].length() < 1)
\r
260 // just take first URL made from regex
\r
266 alignPanel.alignFrame.showURL(url, target);
\r
267 } catch (Exception ex)
\r
269 ex.printStackTrace();
\r
273 public void mouseEntered(MouseEvent e)
\r
275 if (scrollThread != null)
\r
277 scrollThread.running = false;
\r
281 public void mouseExited(MouseEvent e)
\r
283 if (av.getWrapAlignment())
\r
288 if (mouseDragging && e.getY() < 0 && av.getStartSeq() > 0)
\r
290 scrollThread = new ScrollThread(true);
\r
293 if (mouseDragging && e.getY() >= getSize().height
\r
294 && av.getAlignment().getHeight() > av.getEndSeq())
\r
296 scrollThread = new ScrollThread(false);
\r
300 public void mousePressed(MouseEvent e)
\r
302 if (e.getClickCount() > 1)
\r
308 if (av.getWrapAlignment())
\r
310 y -= 2 * av.getCharHeight();
\r
313 int seq = alignPanel.seqPanel.findSeq(e);
\r
315 if ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
\r
317 Sequence sq = (Sequence) av.getAlignment().getSequenceAt(seq);
\r
319 // build a new links menu based on the current links + any non-positional
\r
321 Vector nlinks = new Vector();
\r
322 for (int l = 0, lSize = links.size(); l < lSize; l++)
\r
324 nlinks.addElement(links.elementAt(l));
\r
326 SequenceFeature sf[] = sq == null ? null : sq.getSequenceFeatures();
\r
327 for (int sl = 0; sf != null && sl < sf.length; sl++)
\r
329 if (sf[sl].begin == sf[sl].end && sf[sl].begin == 0)
\r
331 if (sf[sl].links != null && sf[sl].links.size() > 0)
\r
333 for (int l = 0, lSize = sf[sl].links.size(); l < lSize; l++)
\r
335 nlinks.addElement(sf[sl].links.elementAt(l));
\r
341 APopupMenu popup = new APopupMenu(alignPanel, sq, nlinks);
\r
343 popup.show(this, e.getX(), e.getY());
\r
347 if ((av.getSelectionGroup() == null)
\r
348 || ((!e.isControlDown() && !e.isShiftDown()) && av
\r
349 .getSelectionGroup() != null))
\r
351 av.setSelectionGroup(new SequenceGroup());
\r
352 av.getSelectionGroup().setStartRes(0);
\r
353 av.getSelectionGroup().setEndRes(av.getAlignment().getWidth() - 1);
\r
356 if (e.isShiftDown() && lastid != -1)
\r
358 selectSeqs(lastid, seq);
\r
365 alignPanel.paintAlignment(false);
\r
368 void selectSeq(int seq)
\r
371 SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq);
\r
372 av.getSelectionGroup().addOrRemove(pickedSeq, true);
\r
375 void selectSeqs(int start, int end)
\r
380 if (end >= av.getAlignment().getHeight())
\r
382 end = av.getAlignment().getHeight() - 1;
\r
392 if (av.getSelectionGroup() == null)
\r
394 av.setSelectionGroup(new SequenceGroup());
\r
396 for (int i = start; i <= end; i++)
\r
398 av.getSelectionGroup().addSequence(
\r
399 av.getAlignment().getSequenceAt(i), i == end);
\r
404 public void mouseReleased(MouseEvent e)
\r
406 if (scrollThread != null)
\r
408 scrollThread.running = false;
\r
411 if (av.getSelectionGroup() != null)
\r
413 av.getSelectionGroup().recalcConservation();
\r
416 mouseDragging = false;
\r
417 PaintRefresher.Refresh(this, av.getSequenceSetId());
\r
418 // always send selection message when mouse is released
\r
419 av.sendSelection();
\r
422 public void highlightSearchResults(List<SequenceI> list)
\r
424 idCanvas.setHighlighted(list);
\r
431 int index = av.getAlignment().findIndex(list.get(0));
\r
433 // do we need to scroll the panel?
\r
434 if (av.getStartSeq() > index || av.getEndSeq() < index)
\r
436 alignPanel.setScrollValues(av.getStartRes(), index);
\r
440 // this class allows scrolling off the bottom of the visible alignment
\r
441 class ScrollThread extends Thread
\r
443 boolean running = false;
\r
447 public ScrollThread(boolean up)
\r
453 public void stopScrolling()
\r
463 if (alignPanel.scrollUp(up))
\r
465 // scroll was ok, so add new sequence to selection
\r
466 int seq = av.getStartSeq();
\r
469 seq = av.getEndSeq();
\r
474 selectSeqs(lastid - 1, seq);
\r
476 else if (seq > lastid && seq < av.getAlignment().getHeight())
\r
478 selectSeqs(lastid + 1, seq);
\r
488 alignPanel.paintAlignment(true);
\r
492 } catch (Exception ex)
\r