2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 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
72 int seq = Math.max(0, alignPanel.seqPanel.findSeq(e));
\r
73 if(seq>-1 && seq<av.alignment.getHeight())
\r
75 SequenceI sequence = av.alignment.getSequenceAt(seq);
\r
76 StringBuffer tip = new StringBuffer("<html>");
\r
77 tip.append(sequence.getDisplayId(true));
\r
78 if (av.alignment.getSequenceAt(seq).getDescription() != null)
\r
80 tip.append("<table width=250 border=0><tr><td><i>");
\r
81 tip.append(av.alignment.getSequenceAt(seq).getDescription());
\r
83 //ADD NON POSITIONAL SEQUENCE INFO
\r
84 SequenceFeature [] features = sequence.getDatasetSequence().getSequenceFeatures();
\r
87 for(int i=0; i<features.length; i++)
\r
89 if(features[i].begin == 0 && features[i].end ==0)
\r
91 tip.append("<br>"+features[i].featureGroup
\r
92 +" "+ features[i].getType()+" "+features[i].description);
\r
96 tip.append("</i></td></tr></table>");
\r
99 DBRefEntry[] dbrefs = sequence.getDatasetSequence().getDBRef();
\r
100 if (dbrefs != null)
\r
103 for (int i = 0; i < dbrefs.length; i++)
\r
105 tip.append("<br>");
\r
106 tip.append(dbrefs[i].getSource() + " "
\r
107 + dbrefs[i].getAccessionId());
\r
109 tip.append("</i>");
\r
112 tip.append("</html>");
\r
113 setToolTipText(tip.toString());
\r
121 * @param e DOCUMENT ME!
\r
123 public void mouseDragged(MouseEvent e)
\r
125 mouseDragging = true;
\r
127 int seq = Math.max(0, alignPanel.seqPanel.findSeq(e));
\r
131 selectSeqs(lastid - 1, seq);
\r
133 else if (seq > lastid)
\r
135 selectSeqs(lastid + 1, seq);
\r
139 alignPanel.repaint();
\r
146 * @param e DOCUMENT ME!
\r
148 public void mouseClicked(MouseEvent e)
\r
150 if (e.getClickCount() < 2)
\r
153 java.util.Vector links = Preferences.sequenceURLLinks;
\r
154 if (links == null || links.size() < 1)
\r
157 int seq = alignPanel.seqPanel.findSeq(e);
\r
159 //DEFAULT LINK IS FIRST IN THE LINK LIST
\r
161 String id = av.getAlignment().getSequenceAt(seq).getName();
\r
162 if (id.indexOf("|") > -1)
\r
163 id = id.substring(id.lastIndexOf("|") + 1);
\r
166 String url = links.elementAt(0).toString();
\r
167 url = url.substring(url.indexOf("|")+1);
\r
169 int index = url.indexOf("$SEQUENCE_ID$");
\r
170 url = url.substring(0, index)+ id + url.substring(index+13);
\r
174 jalview.util.BrowserLauncher.openURL(url);
\r
176 catch (Exception ex)
\r
178 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
179 "Unixers: Couldn't find default web browser."
\r
180 +"\nAdd the full path to your browser in Preferences.",
\r
181 "Web browser not found", JOptionPane.WARNING_MESSAGE );
\r
182 ex.printStackTrace();
\r
189 * @param e DOCUMENT ME!
\r
191 public void mouseEntered(MouseEvent e)
\r
193 if (scrollThread != null)
\r
195 scrollThread.running = false;
\r
202 * @param e DOCUMENT ME!
\r
204 public void mouseExited(MouseEvent e)
\r
206 if (av.getWrapAlignment())
\r
211 if (mouseDragging && (e.getY() < 0) && (av.getStartSeq() > 0))
\r
213 scrollThread = new ScrollThread(true);
\r
216 if (mouseDragging && (e.getY() >= getHeight()) &&
\r
217 (av.alignment.getHeight() > av.getEndSeq()))
\r
219 scrollThread = new ScrollThread(false);
\r
226 * @param e DOCUMENT ME!
\r
228 public void mousePressed(MouseEvent e)
\r
230 if (e.getClickCount() == 2)
\r
235 int seq = alignPanel.seqPanel.findSeq(e);
\r
238 if (javax.swing.SwingUtilities.isRightMouseButton(e))
\r
240 jalview.gui.PopupMenu pop = new jalview.gui.PopupMenu(alignPanel,
\r
241 (Sequence) av.getAlignment().getSequenceAt(seq),
\r
242 Preferences.sequenceURLLinks);
\r
243 pop.show(this, e.getX(), e.getY());
\r
250 if ((av.getSelectionGroup() == null) ||
\r
251 ((!e.isControlDown() && !e.isShiftDown()) && av.getSelectionGroup() != null))
\r
253 av.setSelectionGroup(new SequenceGroup());
\r
254 av.getSelectionGroup().setStartRes(0);
\r
255 av.getSelectionGroup().setEndRes(av.alignment.getWidth() - 1);
\r
259 if (e.isShiftDown() && (lastid != -1))
\r
261 selectSeqs(lastid, seq);
\r
268 alignPanel.repaint();
\r
274 * @param seq DOCUMENT ME!
\r
276 void selectSeq(int seq)
\r
280 SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq);
\r
281 av.getSelectionGroup().addOrRemove(pickedSeq, true);
\r
287 * @param start DOCUMENT ME!
\r
288 * @param end DOCUMENT ME!
\r
290 void selectSeqs(int start, int end)
\r
292 if(av.getSelectionGroup()==null)
\r
295 if (end >= av.getAlignment().getHeight())
\r
297 end = av.getAlignment().getHeight() - 1;
\r
310 for (int i = start; i <= end; i++)
\r
312 av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i),
\r
320 * @param e DOCUMENT ME!
\r
322 public void mouseReleased(MouseEvent e)
\r
324 if (scrollThread != null)
\r
326 scrollThread.running = false;
\r
329 mouseDragging = false;
\r
330 PaintRefresher.Refresh(this, av.getSequenceSetId());
\r
336 * @param found DOCUMENT ME!
\r
338 public void highlightSearchResults(java.util.Vector found)
\r
340 idCanvas.setHighlighted(found);
\r
347 int index = av.alignment.findIndex((SequenceI) found.get(0));
\r
349 // do we need to scroll the panel?
\r
350 if ((av.getStartSeq() > index) || (av.getEndSeq() < index))
\r
352 alignPanel.setScrollValues(av.getStartRes(), index);
\r
356 // this class allows scrolling off the bottom of the visible alignment
\r
357 class ScrollThread extends Thread
\r
359 boolean running = false;
\r
362 public ScrollThread(boolean up)
\r
368 public void stopScrolling()
\r
379 if (alignPanel.scrollUp(up))
\r
381 // scroll was ok, so add new sequence to selection
\r
382 int seq = av.getStartSeq();
\r
386 seq = av.getEndSeq();
\r
391 selectSeqs(lastid - 1, seq);
\r
393 else if (seq > lastid)
\r
395 selectSeqs(lastid + 1, seq);
\r
405 alignPanel.repaint();
\r
411 catch (Exception ex)
\r