2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 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;
34 public class IdPanel extends JPanel implements MouseListener,
35 MouseMotionListener, MouseWheelListener
37 protected IdCanvas idCanvas;
39 protected AlignViewport av;
41 protected AlignmentPanel alignPanel;
43 ScrollThread scrollThread = null;
50 boolean mouseDragging = false;
53 * Creates a new IdPanel object.
60 public IdPanel(AlignViewport av, AlignmentPanel parent)
64 idCanvas = new IdCanvas(av);
65 setLayout(new BorderLayout());
66 add(idCanvas, BorderLayout.CENTER);
67 addMouseListener(this);
68 addMouseMotionListener(this);
69 addMouseWheelListener(this);
70 ToolTipManager.sharedInstance().registerComponent(this);
79 public void mouseMoved(MouseEvent e)
81 int seq = Math.max(0, alignPanel.seqPanel.findSeq(e));
83 if (seq > -1 && seq < av.alignment.getHeight())
85 SequenceI sequence = av.alignment.getSequenceAt(seq);
86 StringBuffer tip = new StringBuffer();
90 if (sequence.getDescription() != null)
92 tmp = sequence.getDescription();
93 tip.append("<br>" + tmp);
94 maxWidth = Math.max(maxWidth, tmp.length());
97 DBRefEntry[] dbrefs = sequence.getDatasetSequence().getDBRef();
100 for (int i = 0; i < dbrefs.length; i++)
103 tmp = dbrefs[i].getSource() + " " + dbrefs[i].getAccessionId();
105 maxWidth = Math.max(maxWidth, tmp.length());
109 // ADD NON POSITIONAL SEQUENCE INFO
110 SequenceFeature[] features = sequence.getDatasetSequence()
111 .getSequenceFeatures();
112 if (features != null)
114 for (int i = 0; i < features.length; i++)
116 if (features[i].begin == 0 && features[i].end == 0)
118 tmp = features[i].featureGroup + " " + features[i].getType()
119 + " " + features[i].description;
120 tip.append("<br>" + tmp);
121 maxWidth = Math.max(maxWidth, tmp.length());
128 tip.insert(0, "<table width=350 border=0><tr><td><i>");
129 tip.append("</i></td></tr></table>");
132 tip.append("</html>");
134 setToolTipText("<html>" + sequence.getDisplayId(true)
145 public void mouseDragged(MouseEvent e)
147 mouseDragging = true;
149 int seq = Math.max(0, alignPanel.seqPanel.findSeq(e));
153 selectSeqs(lastid - 1, seq);
155 else if (seq > lastid)
157 selectSeqs(lastid + 1, seq);
161 alignPanel.paintAlignment(true);
164 public void mouseWheelMoved(MouseWheelEvent e)
167 if (e.getWheelRotation() > 0)
169 alignPanel.scrollUp(false);
173 alignPanel.scrollUp(true);
183 public void mouseClicked(MouseEvent e)
185 if (e.getClickCount() < 2)
190 java.util.Vector links = Preferences.sequenceURLLinks;
191 if (links == null || links.size() < 1)
196 int seq = alignPanel.seqPanel.findSeq(e);
199 String id = av.getAlignment().getSequenceAt(seq).getName();
200 while (url == null && i < links.size())
202 // DEFAULT LINK IS FIRST IN THE LINK LIST
203 // BUT IF ITS A REGEX AND DOES NOT MATCH THE NEXT ONE WILL BE TRIED
204 url = links.elementAt(i++).toString();
205 jalview.util.UrlLink urlLink = null;
208 urlLink = new UrlLink(url);
209 } catch (Exception foo)
211 jalview.bin.Cache.log.error("Exception for URLLink '" + url + "'",
217 if (!urlLink.isValid())
219 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
224 String urls[] = urlLink.makeUrls(id, true);
225 if (urls == null || urls[0] == null || urls[0].length() < 4)
230 // just take first URL made from regex
235 jalview.util.BrowserLauncher.openURL(url);
236 } catch (Exception ex)
239 .showInternalMessageDialog(
241 "Unixers: Couldn't find default web browser."
242 + "\nAdd the full path to your browser in Preferences.",
243 "Web browser not found", JOptionPane.WARNING_MESSAGE);
244 ex.printStackTrace();
255 public void mouseEntered(MouseEvent e)
257 if (scrollThread != null)
259 scrollThread.running = false;
269 public void mouseExited(MouseEvent e)
271 if (av.getWrapAlignment())
276 if (mouseDragging && (e.getY() < 0) && (av.getStartSeq() > 0))
278 scrollThread = new ScrollThread(true);
281 if (mouseDragging && (e.getY() >= getHeight())
282 && (av.alignment.getHeight() > av.getEndSeq()))
284 scrollThread = new ScrollThread(false);
294 public void mousePressed(MouseEvent e)
296 if (e.getClickCount() == 2)
301 int seq = alignPanel.seqPanel.findSeq(e);
303 if (javax.swing.SwingUtilities.isRightMouseButton(e))
305 jalview.gui.PopupMenu pop = new jalview.gui.PopupMenu(alignPanel,
306 (Sequence) av.getAlignment().getSequenceAt(seq),
307 Preferences.sequenceURLLinks);
308 pop.show(this, e.getX(), e.getY());
313 if ((av.getSelectionGroup() == null)
314 || ((!e.isControlDown() && !e.isShiftDown()) && av
315 .getSelectionGroup() != null))
317 av.setSelectionGroup(new SequenceGroup());
318 av.getSelectionGroup().setStartRes(0);
319 av.getSelectionGroup().setEndRes(av.alignment.getWidth() - 1);
322 if (e.isShiftDown() && (lastid != -1))
324 selectSeqs(lastid, seq);
331 alignPanel.paintAlignment(true);
340 void selectSeq(int seq)
344 SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq);
345 av.getSelectionGroup().addOrRemove(pickedSeq, true);
356 void selectSeqs(int start, int end)
358 if (av.getSelectionGroup() == null)
363 if (end >= av.getAlignment().getHeight())
365 end = av.getAlignment().getHeight() - 1;
378 for (int i = start; i <= end; i++)
380 av.getSelectionGroup().addSequence(
381 av.getAlignment().getSequenceAt(i), true);
391 public void mouseReleased(MouseEvent e)
393 if (scrollThread != null)
395 scrollThread.running = false;
398 mouseDragging = false;
399 PaintRefresher.Refresh(this, av.getSequenceSetId());
408 public void highlightSearchResults(java.util.Vector found)
410 idCanvas.setHighlighted(found);
417 int index = av.alignment.findIndex((SequenceI) found.get(0));
419 // do we need to scroll the panel?
420 if ((av.getStartSeq() > index) || (av.getEndSeq() < index))
422 alignPanel.setScrollValues(av.getStartRes(), index);
426 // this class allows scrolling off the bottom of the visible alignment
427 class ScrollThread extends Thread
429 boolean running = false;
433 public ScrollThread(boolean up)
439 public void stopScrolling()
450 if (alignPanel.scrollUp(up))
452 // scroll was ok, so add new sequence to selection
453 int seq = av.getStartSeq();
457 seq = av.getEndSeq();
462 selectSeqs(lastid - 1, seq);
464 else if (seq > lastid)
466 selectSeqs(lastid + 1, seq);
476 alignPanel.paintAlignment(false);
481 } catch (Exception ex)