2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 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
22 import java.awt.event.*;
25 import jalview.datamodel.*;
26 import jalview.util.UrlLink;
35 extends JPanel implements MouseListener,
36 MouseMotionListener, MouseWheelListener
38 protected IdCanvas idCanvas;
39 protected AlignViewport av;
40 protected AlignmentPanel alignPanel;
41 ScrollThread scrollThread = null;
45 boolean mouseDragging = false;
48 * Creates a new IdPanel object.
50 * @param av DOCUMENT ME!
51 * @param parent DOCUMENT ME!
53 public IdPanel(AlignViewport av, AlignmentPanel parent)
57 idCanvas = new IdCanvas(av);
58 setLayout(new BorderLayout());
59 add(idCanvas, BorderLayout.CENTER);
60 addMouseListener(this);
61 addMouseMotionListener(this);
62 addMouseWheelListener(this);
63 ToolTipManager.sharedInstance().registerComponent(this);
69 * @param e DOCUMENT ME!
71 public void mouseMoved(MouseEvent e)
73 int seq = Math.max(0, alignPanel.seqPanel.findSeq(e));
75 if (seq > -1 && seq < av.alignment.getHeight())
77 SequenceI sequence = av.alignment.getSequenceAt(seq);
78 StringBuffer tip = new StringBuffer();
82 if (sequence.getDescription() != null)
84 tmp = sequence.getDescription();
85 tip.append("<br>"+tmp);
86 maxWidth = Math.max(maxWidth, tmp.length());
89 DBRefEntry[] dbrefs = sequence.getDatasetSequence().getDBRef();
92 for (int i = 0; i < dbrefs.length; i++)
95 tmp = dbrefs[i].getSource() + " " + dbrefs[i].getAccessionId();
97 maxWidth = Math.max(maxWidth, tmp.length());
102 //ADD NON POSITIONAL SEQUENCE INFO
103 SequenceFeature[] features = sequence.getDatasetSequence().
104 getSequenceFeatures();
105 if (features != null)
107 for (int i = 0; i < features.length; i++)
109 if (features[i].begin == 0 && features[i].end == 0)
111 tmp = features[i].featureGroup
112 + " " + features[i].getType() + " " +
113 features[i].description;
114 tip.append("<br>" + tmp);
115 maxWidth = Math.max(maxWidth, tmp.length());
122 tip.insert(0, "<table width=350 border=0><tr><td><i>");
123 tip.append("</i></td></tr></table>");
126 tip.append("</html>");
128 setToolTipText("<html>"+sequence.getDisplayId(true)+tip.toString());
135 * @param e DOCUMENT ME!
137 public void mouseDragged(MouseEvent e)
139 mouseDragging = true;
141 int seq = Math.max(0, alignPanel.seqPanel.findSeq(e));
145 selectSeqs(lastid - 1, seq);
147 else if (seq > lastid)
149 selectSeqs(lastid + 1, seq);
153 alignPanel.paintAlignment(true);
156 public void mouseWheelMoved(MouseWheelEvent e)
159 if (e.getWheelRotation() > 0)
161 alignPanel.scrollUp(false);
165 alignPanel.scrollUp(true);
172 * @param e DOCUMENT ME!
174 public void mouseClicked(MouseEvent e)
176 if (e.getClickCount() < 2)
181 java.util.Vector links = Preferences.sequenceURLLinks;
182 if (links == null || links.size() < 1)
187 int seq = alignPanel.seqPanel.findSeq(e);
190 String id = av.getAlignment().getSequenceAt(seq).getName();
191 while (url == null && i < links.size())
193 // DEFAULT LINK IS FIRST IN THE LINK LIST
194 // BUT IF ITS A REGEX AND DOES NOT MATCH THE NEXT ONE WILL BE TRIED
195 url = links.elementAt(i++).toString();
196 jalview.util.UrlLink urlLink = null;
199 urlLink = new UrlLink(url);
200 } catch (Exception foo)
202 jalview.bin.Cache.log.error("Exception for URLLink '" + url + "'",
208 if (!urlLink.isValid())
210 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
215 String urls[] = urlLink.makeUrls(id, true);
216 if (urls == null || urls[0]==null || urls[0].length()<4)
221 // just take first URL made from regex
226 jalview.util.BrowserLauncher.openURL(url);
230 JOptionPane.showInternalMessageDialog(Desktop.desktop,
231 "Unixers: Couldn't find default web browser."
233 "\nAdd the full path to your browser in Preferences.",
234 "Web browser not found",
235 JOptionPane.WARNING_MESSAGE);
236 ex.printStackTrace();
244 * @param e DOCUMENT ME!
246 public void mouseEntered(MouseEvent e)
248 if (scrollThread != null)
250 scrollThread.running = false;
257 * @param e DOCUMENT ME!
259 public void mouseExited(MouseEvent e)
261 if (av.getWrapAlignment())
266 if (mouseDragging && (e.getY() < 0) && (av.getStartSeq() > 0))
268 scrollThread = new ScrollThread(true);
271 if (mouseDragging && (e.getY() >= getHeight()) &&
272 (av.alignment.getHeight() > av.getEndSeq()))
274 scrollThread = new ScrollThread(false);
281 * @param e DOCUMENT ME!
283 public void mousePressed(MouseEvent e)
285 if (e.getClickCount() == 2)
290 int seq = alignPanel.seqPanel.findSeq(e);
292 if (javax.swing.SwingUtilities.isRightMouseButton(e))
294 jalview.gui.PopupMenu pop = new jalview.gui.PopupMenu(alignPanel,
295 (Sequence) av.getAlignment().getSequenceAt(seq),
296 Preferences.sequenceURLLinks);
297 pop.show(this, e.getX(), e.getY());
302 if ( (av.getSelectionGroup() == null) ||
303 ( (!e.isControlDown() && !e.isShiftDown()) && av.getSelectionGroup() != null))
305 av.setSelectionGroup(new SequenceGroup());
306 av.getSelectionGroup().setStartRes(0);
307 av.getSelectionGroup().setEndRes(av.alignment.getWidth() - 1);
310 if (e.isShiftDown() && (lastid != -1))
312 selectSeqs(lastid, seq);
319 alignPanel.paintAlignment(true);
325 * @param seq DOCUMENT ME!
327 void selectSeq(int seq)
331 SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq);
332 av.getSelectionGroup().addOrRemove(pickedSeq, true);
338 * @param start DOCUMENT ME!
339 * @param end DOCUMENT ME!
341 void selectSeqs(int start, int end)
343 if (av.getSelectionGroup() == null)
348 if (end >= av.getAlignment().getHeight())
350 end = av.getAlignment().getHeight() - 1;
363 for (int i = start; i <= end; i++)
365 av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i),
373 * @param e DOCUMENT ME!
375 public void mouseReleased(MouseEvent e)
377 if (scrollThread != null)
379 scrollThread.running = false;
382 mouseDragging = false;
383 PaintRefresher.Refresh(this, av.getSequenceSetId());
389 * @param found DOCUMENT ME!
391 public void highlightSearchResults(java.util.Vector found)
393 idCanvas.setHighlighted(found);
400 int index = av.alignment.findIndex( (SequenceI) found.get(0));
402 // do we need to scroll the panel?
403 if ( (av.getStartSeq() > index) || (av.getEndSeq() < index))
405 alignPanel.setScrollValues(av.getStartRes(), index);
409 // this class allows scrolling off the bottom of the visible alignment
413 boolean running = false;
416 public ScrollThread(boolean up)
422 public void stopScrolling()
433 if (alignPanel.scrollUp(up))
435 // scroll was ok, so add new sequence to selection
436 int seq = av.getStartSeq();
440 seq = av.getEndSeq();
445 selectSeqs(lastid - 1, seq);
447 else if (seq > lastid)
449 selectSeqs(lastid + 1, seq);
459 alignPanel.paintAlignment(false);