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