2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.gui;
\r
21 import jalview.datamodel.*;
\r
24 import java.awt.event.*;
\r
26 import javax.swing.*;
\r
33 * @version $Revision$
\r
35 public class IdPanel extends JPanel implements MouseListener,
\r
38 protected IdCanvas idCanvas;
\r
39 protected AlignViewport av;
\r
40 protected AlignmentPanel alignPanel;
\r
41 ScrollThread scrollThread = null;
\r
45 boolean mouseDragging = false;
\r
48 * Creates a new IdPanel object.
\r
50 * @param av DOCUMENT ME!
\r
51 * @param parent DOCUMENT ME!
\r
53 public IdPanel(AlignViewport av, AlignmentPanel parent)
\r
56 alignPanel = parent;
\r
57 idCanvas = new IdCanvas(av);
\r
58 setLayout(new BorderLayout());
\r
59 add(idCanvas, BorderLayout.CENTER);
\r
60 addMouseListener(this);
\r
61 addMouseMotionListener(this);
\r
62 ToolTipManager.sharedInstance().registerComponent(this);
\r
68 * @param e DOCUMENT ME!
\r
70 public void mouseMoved(MouseEvent e)
\r
74 if (av.getWrapAlignment())
\r
79 final int seq = av.getIndex(y);
\r
82 SequenceI sequence = av.alignment.getSequenceAt(seq);
\r
83 StringBuffer tip = new StringBuffer("<html>");
\r
84 tip.append(sequence.getDisplayId(true));
\r
85 if (av.alignment.getSequenceAt(seq).getDescription() != null)
\r
87 tip.append("<table width=250 border=0><tr><td><i>");
\r
88 tip.append(av.alignment.getSequenceAt(seq).getDescription());
\r
90 //ADD NON POSITIONAL SEQUENCE INFO
\r
91 SequenceFeature [] features = sequence.getDatasetSequence().getSequenceFeatures();
\r
94 for(int i=0; i<features.length; i++)
\r
96 if(features[i].begin == 0 && features[i].end ==0)
\r
98 tip.append("<br>"+features[i].featureGroup
\r
99 +" "+ features[i].getType()+" "+features[i].description);
\r
103 tip.append("</i></td></tr></table>");
\r
106 DBRefEntry[] dbrefs = sequence.getDatasetSequence().getDBRef();
\r
107 if (dbrefs != null)
\r
110 for (int i = 0; i < dbrefs.length; i++)
\r
112 tip.append("<br>");
\r
113 tip.append(dbrefs[i].getSource() + " "
\r
114 + dbrefs[i].getAccessionId());
\r
116 tip.append("</i>");
\r
119 tip.append("</html>");
\r
120 setToolTipText(tip.toString());
\r
125 int getWrappedY(int y)
\r
127 int hgap = av.charHeight;
\r
128 if (av.scaleAboveWrapped)
\r
129 hgap += av.charHeight;
\r
138 * @param e DOCUMENT ME!
\r
140 public void mouseDragged(MouseEvent e)
\r
142 mouseDragging = true;
\r
146 if (av.getWrapAlignment())
\r
148 y = getWrappedY(y);
\r
151 int seq = av.getIndex(y);
\r
160 selectSeqs(lastid - 1, seq);
\r
162 else if (seq > lastid)
\r
164 selectSeqs(lastid + 1, seq);
\r
168 alignPanel.repaint();
\r
175 * @param e DOCUMENT ME!
\r
177 public void mouseClicked(MouseEvent e)
\r
179 if (e.getClickCount() < 2)
\r
182 java.util.Vector links = Preferences.sequenceURLLinks;
\r
183 if (links == null || links.size() < 1)
\r
188 if (av.getWrapAlignment())
\r
190 y = getWrappedY(y);
\r
193 //DEFAULT LINK IS FIRST IN THE LINK LIST
\r
194 int seq = av.getIndex(y);
\r
198 String id = av.getAlignment().getSequenceAt(seq).getName();
\r
199 if (id.indexOf("|") > -1)
\r
200 id = id.substring(id.lastIndexOf("|") + 1);
\r
203 String url = links.elementAt(0).toString();
\r
204 url = url.substring(url.indexOf("|")+1);
\r
206 int index = url.indexOf("$SEQUENCE_ID$");
\r
207 url = url.substring(0, index)+ id + url.substring(index+13);
\r
211 jalview.util.BrowserLauncher.openURL(url);
\r
213 catch (Exception ex)
\r
215 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
216 "Unixers: Couldn't find default web browser."
\r
217 +"\nAdd the full path to your browser in Preferences.",
\r
218 "Web browser not found", JOptionPane.WARNING_MESSAGE );
\r
219 ex.printStackTrace();
\r
226 * @param e DOCUMENT ME!
\r
228 public void mouseEntered(MouseEvent e)
\r
230 if (scrollThread != null)
\r
232 scrollThread.running = false;
\r
239 * @param e DOCUMENT ME!
\r
241 public void mouseExited(MouseEvent e)
\r
243 if (av.getWrapAlignment())
\r
248 if (mouseDragging && (e.getY() < 0) && (av.getStartSeq() > 0))
\r
250 scrollThread = new ScrollThread(true);
\r
253 if (mouseDragging && (e.getY() >= getHeight()) &&
\r
254 (av.alignment.getHeight() > av.getEndSeq()))
\r
256 scrollThread = new ScrollThread(false);
\r
263 * @param e DOCUMENT ME!
\r
265 public void mousePressed(MouseEvent e)
\r
267 if (e.getClickCount() == 2)
\r
274 if (av.getWrapAlignment())
\r
276 y = getWrappedY(y);
\r
279 int seq = av.getIndex(y);
\r
286 if (javax.swing.SwingUtilities.isRightMouseButton(e))
\r
288 jalview.gui.PopupMenu pop = new jalview.gui.PopupMenu(alignPanel,
\r
289 (Sequence) av.getAlignment().getSequenceAt(seq),
\r
290 Preferences.sequenceURLLinks);
\r
291 pop.show(this, e.getX(), y);
\r
296 /* if (!e.isControlDown() && !e.isShiftDown() &&
\r
297 (av.alignment.findGroup(av.alignment.getSequenceAt(seq)) != null))
\r
299 System.out.println("no modifiers");
\r
300 SequenceGroup selection = new SequenceGroup();
\r
301 SequenceGroup sg = av.alignment.findGroup(av.alignment.getSequenceAt(
\r
303 selection.setStartRes(0);
\r
304 selection.setEndRes(av.alignment.getWidth() - 1);
\r
306 for (int i = 0; i < sg.getSize(); i++)
\r
308 selection.addSequence(sg.getSequenceAt(i), true);
\r
311 av.setSelectionGroup(selection);
\r
316 if ((av.getSelectionGroup() == null) ||
\r
317 ((!e.isControlDown() && !e.isShiftDown()) && av.getSelectionGroup() != null))
\r
319 av.setSelectionGroup(new SequenceGroup());
\r
320 av.getSelectionGroup().setStartRes(0);
\r
321 av.getSelectionGroup().setEndRes(av.alignment.getWidth() - 1);
\r
326 if (e.isShiftDown() && (lastid != -1))
\r
328 selectSeqs(lastid, seq);
\r
335 alignPanel.repaint();
\r
341 * @param seq DOCUMENT ME!
\r
343 void selectSeq(int seq)
\r
347 SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq);
\r
348 av.getSelectionGroup().addOrRemove(pickedSeq, true);
\r
354 * @param start DOCUMENT ME!
\r
355 * @param end DOCUMENT ME!
\r
357 void selectSeqs(int start, int end)
\r
359 if(av.getSelectionGroup()==null)
\r
372 for (int i = start; i <= end; i++)
\r
374 av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i),
\r
382 * @param e DOCUMENT ME!
\r
384 public void mouseReleased(MouseEvent e)
\r
386 if (scrollThread != null)
\r
388 scrollThread.running = false;
\r
391 mouseDragging = false;
\r
392 PaintRefresher.Refresh(av.alignment);
\r
398 * @param found DOCUMENT ME!
\r
400 public void highlightSearchResults(java.util.Vector found)
\r
402 idCanvas.setHighlighted(found);
\r
409 int index = av.alignment.findIndex((SequenceI) found.get(0));
\r
411 // do we need to scroll the panel?
\r
412 if ((av.getStartSeq() > index) || (av.getEndSeq() < index))
\r
414 alignPanel.setScrollValues(av.getStartRes(), index);
\r
418 // this class allows scrolling off the bottom of the visible alignment
\r
419 class ScrollThread extends Thread
\r
421 boolean running = false;
\r
424 public ScrollThread(boolean up)
\r
430 public void stopScrolling()
\r
441 if (alignPanel.scrollUp(up))
\r
443 // scroll was ok, so add new sequence to selection
\r
444 int seq = av.getStartSeq();
\r
448 seq = av.getEndSeq();
\r
453 selectSeqs(lastid - 1, seq);
\r
455 else if (seq > lastid)
\r
457 selectSeqs(lastid + 1, seq);
\r
467 alignPanel.repaint();
\r
473 catch (Exception ex)
\r