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.*;
34 extends JPanel implements MouseListener,
35 MouseMotionListener, MouseWheelListener
37 protected IdCanvas idCanvas;
38 protected AlignViewport av;
39 protected AlignmentPanel alignPanel;
40 ScrollThread scrollThread = null;
44 boolean mouseDragging = false;
47 * Creates a new IdPanel object.
49 * @param av DOCUMENT ME!
50 * @param parent DOCUMENT ME!
52 public IdPanel(AlignViewport av, AlignmentPanel parent)
56 idCanvas = new IdCanvas(av);
57 setLayout(new BorderLayout());
58 add(idCanvas, BorderLayout.CENTER);
59 addMouseListener(this);
60 addMouseMotionListener(this);
61 addMouseWheelListener(this);
62 ToolTipManager.sharedInstance().registerComponent(this);
68 * @param e DOCUMENT ME!
70 public void mouseMoved(MouseEvent e)
72 int seq = Math.max(0, alignPanel.seqPanel.findSeq(e));
74 if (seq > -1 && seq < av.alignment.getHeight())
76 SequenceI sequence = av.alignment.getSequenceAt(seq);
77 StringBuffer tip = new StringBuffer();
81 if (sequence.getDescription() != null)
83 tmp = sequence.getDescription();
84 tip.append("<br>"+tmp);
85 maxWidth = Math.max(maxWidth, tmp.length());
88 DBRefEntry[] dbrefs = sequence.getDatasetSequence().getDBRef();
91 for (int i = 0; i < dbrefs.length; i++)
94 tmp = dbrefs[i].getSource() + " " + dbrefs[i].getAccessionId();
96 maxWidth = Math.max(maxWidth, tmp.length());
101 //ADD NON POSITIONAL SEQUENCE INFO
102 SequenceFeature[] features = sequence.getDatasetSequence().
103 getSequenceFeatures();
104 if (features != null)
106 for (int i = 0; i < features.length; i++)
108 if (features[i].begin == 0 && features[i].end == 0)
110 tmp = features[i].featureGroup
111 + " " + features[i].getType() + " " +
112 features[i].description;
113 tip.append("<br>" + tmp);
114 maxWidth = Math.max(maxWidth, tmp.length());
121 tip.insert(0, "<table width=350 border=0><tr><td><i>");
122 tip.append("</i></td></tr></table>");
125 tip.append("</html>");
127 setToolTipText("<html>"+sequence.getDisplayId(true)+tip.toString());
134 * @param e DOCUMENT ME!
136 public void mouseDragged(MouseEvent e)
138 mouseDragging = true;
140 int seq = Math.max(0, alignPanel.seqPanel.findSeq(e));
144 selectSeqs(lastid - 1, seq);
146 else if (seq > lastid)
148 selectSeqs(lastid + 1, seq);
152 alignPanel.paintAlignment(true);
155 public void mouseWheelMoved(MouseWheelEvent e)
158 if (e.getWheelRotation() > 0)
160 alignPanel.scrollUp(false);
164 alignPanel.scrollUp(true);
171 * @param e DOCUMENT ME!
173 public void mouseClicked(MouseEvent e)
175 if (e.getClickCount() < 2)
180 java.util.Vector links = Preferences.sequenceURLLinks;
181 if (links == null || links.size() < 1)
186 int seq = alignPanel.seqPanel.findSeq(e);
188 //DEFAULT LINK IS FIRST IN THE LINK LIST
190 String id = av.getAlignment().getSequenceAt(seq).getName();
191 if (id.indexOf("|") > -1)
193 id = id.substring(id.lastIndexOf("|") + 1);
196 String url = links.elementAt(0).toString();
197 url = url.substring(url.indexOf("|") + 1);
199 int index = url.indexOf("$SEQUENCE_ID$");
200 url = url.substring(0, index) + id + url.substring(index + 13);
204 jalview.util.BrowserLauncher.openURL(url);
208 JOptionPane.showInternalMessageDialog(Desktop.desktop,
209 "Unixers: Couldn't find default web browser."
211 "\nAdd the full path to your browser in Preferences.",
212 "Web browser not found",
213 JOptionPane.WARNING_MESSAGE);
214 ex.printStackTrace();
221 * @param e DOCUMENT ME!
223 public void mouseEntered(MouseEvent e)
225 if (scrollThread != null)
227 scrollThread.running = false;
234 * @param e DOCUMENT ME!
236 public void mouseExited(MouseEvent e)
238 if (av.getWrapAlignment())
243 if (mouseDragging && (e.getY() < 0) && (av.getStartSeq() > 0))
245 scrollThread = new ScrollThread(true);
248 if (mouseDragging && (e.getY() >= getHeight()) &&
249 (av.alignment.getHeight() > av.getEndSeq()))
251 scrollThread = new ScrollThread(false);
258 * @param e DOCUMENT ME!
260 public void mousePressed(MouseEvent e)
262 if (e.getClickCount() == 2)
267 int seq = alignPanel.seqPanel.findSeq(e);
269 if (javax.swing.SwingUtilities.isRightMouseButton(e))
271 jalview.gui.PopupMenu pop = new jalview.gui.PopupMenu(alignPanel,
272 (Sequence) av.getAlignment().getSequenceAt(seq),
273 Preferences.sequenceURLLinks);
274 pop.show(this, e.getX(), e.getY());
279 if ( (av.getSelectionGroup() == null) ||
280 ( (!e.isControlDown() && !e.isShiftDown()) && av.getSelectionGroup() != null))
282 av.setSelectionGroup(new SequenceGroup());
283 av.getSelectionGroup().setStartRes(0);
284 av.getSelectionGroup().setEndRes(av.alignment.getWidth() - 1);
287 if (e.isShiftDown() && (lastid != -1))
289 selectSeqs(lastid, seq);
296 alignPanel.paintAlignment(true);
302 * @param seq DOCUMENT ME!
304 void selectSeq(int seq)
308 SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq);
309 av.getSelectionGroup().addOrRemove(pickedSeq, true);
315 * @param start DOCUMENT ME!
316 * @param end DOCUMENT ME!
318 void selectSeqs(int start, int end)
320 if (av.getSelectionGroup() == null)
325 if (end >= av.getAlignment().getHeight())
327 end = av.getAlignment().getHeight() - 1;
340 for (int i = start; i <= end; i++)
342 av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i),
350 * @param e DOCUMENT ME!
352 public void mouseReleased(MouseEvent e)
354 if (scrollThread != null)
356 scrollThread.running = false;
359 mouseDragging = false;
360 PaintRefresher.Refresh(this, av.getSequenceSetId());
366 * @param found DOCUMENT ME!
368 public void highlightSearchResults(java.util.Vector found)
370 idCanvas.setHighlighted(found);
377 int index = av.alignment.findIndex( (SequenceI) found.get(0));
379 // do we need to scroll the panel?
380 if ( (av.getStartSeq() > index) || (av.getEndSeq() < index))
382 alignPanel.setScrollValues(av.getStartRes(), index);
386 // this class allows scrolling off the bottom of the visible alignment
390 boolean running = false;
393 public ScrollThread(boolean up)
399 public void stopScrolling()
410 if (alignPanel.scrollUp(up))
412 // scroll was ok, so add new sequence to selection
413 int seq = av.getStartSeq();
417 seq = av.getEndSeq();
422 selectSeqs(lastid - 1, seq);
424 else if (seq > lastid)
426 selectSeqs(lastid + 1, seq);
436 alignPanel.paintAlignment(false);