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
104 tip.append("</i></td></tr></table>");
\r
106 tip.append("</html>");
\r
107 setToolTipText(tip.toString());
\r
112 int getWrappedY(int y)
\r
114 int hgap = av.charHeight;
\r
115 if (av.scaleAboveWrapped)
\r
116 hgap += av.charHeight;
\r
125 * @param e DOCUMENT ME!
\r
127 public void mouseDragged(MouseEvent e)
\r
129 mouseDragging = true;
\r
133 if (av.getWrapAlignment())
\r
135 y = getWrappedY(y);
\r
138 int seq = av.getIndex(y);
\r
147 selectSeqs(lastid - 1, seq);
\r
149 else if (seq > lastid)
\r
151 selectSeqs(lastid + 1, seq);
\r
155 alignPanel.repaint();
\r
162 * @param e DOCUMENT ME!
\r
164 public void mouseClicked(MouseEvent e)
\r
166 if (e.getClickCount() < 2)
\r
169 java.util.Vector links = Preferences.sequenceURLLinks;
\r
170 if (links == null || links.size() < 1)
\r
175 if (av.getWrapAlignment())
\r
177 y = getWrappedY(y);
\r
180 //DEFAULT LINK IS FIRST IN THE LINK LIST
\r
181 int seq = av.getIndex(y);
\r
185 String id = av.getAlignment().getSequenceAt(seq).getName();
\r
186 if (id.indexOf("|") > -1)
\r
187 id = id.substring(id.lastIndexOf("|") + 1);
\r
190 String url = links.elementAt(0).toString();
\r
191 url = url.substring(url.indexOf("|")+1);
\r
193 int index = url.indexOf("$SEQUENCE_ID$");
\r
194 url = url.substring(0, index)+ id + url.substring(index+13);
\r
198 jalview.util.BrowserLauncher.openURL(url);
\r
200 catch (Exception ex)
\r
202 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
203 "Unixers: Couldn't find default web browser."
\r
204 +"\nAdd the full path to your browser in Preferences.",
\r
205 "Web browser not found", JOptionPane.WARNING_MESSAGE );
\r
206 ex.printStackTrace();
\r
213 * @param e DOCUMENT ME!
\r
215 public void mouseEntered(MouseEvent e)
\r
217 if (scrollThread != null)
\r
219 scrollThread.running = false;
\r
226 * @param e DOCUMENT ME!
\r
228 public void mouseExited(MouseEvent e)
\r
230 if (av.getWrapAlignment())
\r
235 if (mouseDragging && (e.getY() < 0) && (av.getStartSeq() > 0))
\r
237 scrollThread = new ScrollThread(true);
\r
240 if (mouseDragging && (e.getY() >= getHeight()) &&
\r
241 (av.alignment.getHeight() > av.getEndSeq()))
\r
243 scrollThread = new ScrollThread(false);
\r
250 * @param e DOCUMENT ME!
\r
252 public void mousePressed(MouseEvent e)
\r
254 if (e.getClickCount() == 2)
\r
261 if (av.getWrapAlignment())
\r
263 y = getWrappedY(y);
\r
266 int seq = av.getIndex(y);
\r
273 if (javax.swing.SwingUtilities.isRightMouseButton(e))
\r
275 jalview.gui.PopupMenu pop = new jalview.gui.PopupMenu(alignPanel,
\r
276 (Sequence) av.getAlignment().getSequenceAt(seq),
\r
277 Preferences.sequenceURLLinks);
\r
278 pop.show(this, e.getX(), y);
\r
283 /* if (!e.isControlDown() && !e.isShiftDown() &&
\r
284 (av.alignment.findGroup(av.alignment.getSequenceAt(seq)) != null))
\r
286 System.out.println("no modifiers");
\r
287 SequenceGroup selection = new SequenceGroup();
\r
288 SequenceGroup sg = av.alignment.findGroup(av.alignment.getSequenceAt(
\r
290 selection.setStartRes(0);
\r
291 selection.setEndRes(av.alignment.getWidth() - 1);
\r
293 for (int i = 0; i < sg.getSize(); i++)
\r
295 selection.addSequence(sg.getSequenceAt(i), true);
\r
298 av.setSelectionGroup(selection);
\r
303 if ((av.getSelectionGroup() == null) ||
\r
304 ((!e.isControlDown() && !e.isShiftDown()) && av.getSelectionGroup() != null))
\r
306 av.setSelectionGroup(new SequenceGroup());
\r
307 av.getSelectionGroup().setStartRes(0);
\r
308 av.getSelectionGroup().setEndRes(av.alignment.getWidth() - 1);
\r
313 if (e.isShiftDown() && (lastid != -1))
\r
315 selectSeqs(lastid, seq);
\r
322 alignPanel.repaint();
\r
328 * @param seq DOCUMENT ME!
\r
330 void selectSeq(int seq)
\r
334 SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq);
\r
335 av.getSelectionGroup().addOrRemove(pickedSeq, true);
\r
341 * @param start DOCUMENT ME!
\r
342 * @param end DOCUMENT ME!
\r
344 void selectSeqs(int start, int end)
\r
346 if(av.getSelectionGroup()==null)
\r
359 for (int i = start; i <= end; i++)
\r
361 av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i),
\r
369 * @param e DOCUMENT ME!
\r
371 public void mouseReleased(MouseEvent e)
\r
373 if (scrollThread != null)
\r
375 scrollThread.running = false;
\r
378 mouseDragging = false;
\r
379 PaintRefresher.Refresh(av.alignment);
\r
385 * @param found DOCUMENT ME!
\r
387 public void highlightSearchResults(java.util.Vector found)
\r
389 idCanvas.setHighlighted(found);
\r
396 int index = av.alignment.findIndex((SequenceI) found.get(0));
\r
398 // do we need to scroll the panel?
\r
399 if ((av.getStartSeq() > index) || (av.getEndSeq() < index))
\r
401 alignPanel.setScrollValues(av.getStartRes(), index);
\r
405 // this class allows scrolling off the bottom of the visible alignment
\r
406 class ScrollThread extends Thread
\r
408 boolean running = false;
\r
411 public ScrollThread(boolean up)
\r
417 public void stopScrolling()
\r
428 if (alignPanel.scrollUp(up))
\r
430 // scroll was ok, so add new sequence to selection
\r
431 int seq = av.getStartSeq();
\r
435 seq = av.getEndSeq();
\r
440 selectSeqs(lastid - 1, seq);
\r
442 else if (seq > lastid)
\r
444 selectSeqs(lastid + 1, seq);
\r
454 alignPanel.repaint();
\r
460 catch (Exception ex)
\r