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 StringBuffer tip = new StringBuffer("<html>");
\r
83 tip.append(av.alignment.getSequenceAt(seq).getDisplayId(true));
\r
84 if (av.alignment.getSequenceAt(seq).getDescription() != null)
\r
86 tip.append("<table width=250 border=0><tr><td><i>");
\r
87 tip.append(av.alignment.getSequenceAt(seq).getDescription());
\r
88 tip.append("</i></td></tr></table>");
\r
90 tip.append("</html>");
\r
91 setToolTipText(tip.toString());
\r
94 if(av.hasHiddenRows)
\r
96 if(av.adjustForHiddenSeqs(seq) -
\r
97 av.adjustForHiddenSeqs(seq-1)>1)
\r
99 JPopupMenu pop = new JPopupMenu();
\r
100 JMenuItem item = new JMenuItem("Reveal");
\r
101 item.addActionListener(new ActionListener()
\r
103 public void actionPerformed(ActionEvent e)
\r
105 av.showSequence(seq);
\r
106 alignPanel.repaint();
\r
107 if(alignPanel.overviewPanel!=null)
\r
108 alignPanel.overviewPanel.updateOverviewImage();
\r
112 pop.show(this, e.getX(), e.getY());
\r
118 int getWrappedY(int y)
\r
120 int hgap = av.charHeight;
\r
121 if (av.scaleAboveWrapped)
\r
122 hgap += av.charHeight;
\r
131 * @param e DOCUMENT ME!
\r
133 public void mouseDragged(MouseEvent e)
\r
135 mouseDragging = true;
\r
139 if (av.getWrapAlignment())
\r
141 y = getWrappedY(y);
\r
144 int seq = av.getIndex(y);
\r
153 selectSeqs(lastid - 1, seq);
\r
155 else if (seq > lastid)
\r
157 selectSeqs(lastid + 1, seq);
\r
161 alignPanel.repaint();
\r
168 * @param e DOCUMENT ME!
\r
170 public void mouseClicked(MouseEvent e)
\r
172 if (e.getClickCount() < 2)
\r
175 java.util.Vector links = Preferences.sequenceURLLinks;
\r
176 if (links == null || links.size() < 1)
\r
181 if (av.getWrapAlignment())
\r
183 y = getWrappedY(y);
\r
186 //DEFAULT LINK IS FIRST IN THE LINK LIST
\r
187 int seq = av.getIndex(y);
\r
191 String id = av.getAlignment().getSequenceAt(seq).getName();
\r
192 if (id.indexOf("|") > -1)
\r
193 id = id.substring(id.lastIndexOf("|") + 1);
\r
196 String url = links.elementAt(0).toString();
\r
197 url = url.substring(url.indexOf("|")+1);
\r
199 int index = url.indexOf("$SEQUENCE_ID$");
\r
200 url = url.substring(0, index)+ id + url.substring(index+13);
\r
204 jalview.util.BrowserLauncher.openURL(url);
\r
206 catch (Exception ex)
\r
208 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
209 "Unixers: Couldn't find default web browser."
\r
210 +"\nAdd the full path to your browser in Preferences.",
\r
211 "Web browser not found", JOptionPane.WARNING_MESSAGE );
\r
212 ex.printStackTrace();
\r
219 * @param e DOCUMENT ME!
\r
221 public void mouseEntered(MouseEvent e)
\r
223 if (scrollThread != null)
\r
225 scrollThread.running = false;
\r
232 * @param e DOCUMENT ME!
\r
234 public void mouseExited(MouseEvent e)
\r
236 if (av.getWrapAlignment())
\r
241 if (mouseDragging && (e.getY() < 0) && (av.getStartSeq() > 0))
\r
243 scrollThread = new ScrollThread(true);
\r
246 if (mouseDragging && (e.getY() >= getHeight()) &&
\r
247 (av.alignment.getHeight() > av.getEndSeq()))
\r
249 scrollThread = new ScrollThread(false);
\r
256 * @param e DOCUMENT ME!
\r
258 public void mousePressed(MouseEvent e)
\r
260 if (e.getClickCount() == 2)
\r
267 if (av.getWrapAlignment())
\r
269 y = getWrappedY(y);
\r
272 int seq = av.getIndex(y);
\r
279 if (javax.swing.SwingUtilities.isRightMouseButton(e))
\r
281 jalview.gui.PopupMenu pop = new jalview.gui.PopupMenu(alignPanel,
\r
282 (Sequence) av.getAlignment().getSequenceAt(seq));
\r
283 pop.show(this, e.getX(), y);
\r
288 /* if (!e.isControlDown() && !e.isShiftDown() &&
\r
289 (av.alignment.findGroup(av.alignment.getSequenceAt(seq)) != null))
\r
291 System.out.println("no modifiers");
\r
292 SequenceGroup selection = new SequenceGroup();
\r
293 SequenceGroup sg = av.alignment.findGroup(av.alignment.getSequenceAt(
\r
295 selection.setStartRes(0);
\r
296 selection.setEndRes(av.alignment.getWidth() - 1);
\r
298 for (int i = 0; i < sg.getSize(); i++)
\r
300 selection.addSequence(sg.getSequenceAt(i), true);
\r
303 av.setSelectionGroup(selection);
\r
308 if ((av.getSelectionGroup() == null) ||
\r
309 ((!e.isControlDown() && !e.isShiftDown()) && av.getSelectionGroup() != null))
\r
311 av.setSelectionGroup(new SequenceGroup());
\r
312 av.getSelectionGroup().setStartRes(0);
\r
313 av.getSelectionGroup().setEndRes(av.alignment.getWidth() - 1);
\r
318 if (e.isShiftDown() && (lastid != -1))
\r
320 selectSeqs(lastid, seq);
\r
327 alignPanel.repaint();
\r
333 * @param seq DOCUMENT ME!
\r
335 void selectSeq(int seq)
\r
339 SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq);
\r
340 av.getSelectionGroup().addOrRemove(pickedSeq, true);
\r
346 * @param start DOCUMENT ME!
\r
347 * @param end DOCUMENT ME!
\r
349 void selectSeqs(int start, int end)
\r
351 if(av.getSelectionGroup()==null)
\r
364 for (int i = start; i <= end; i++)
\r
366 av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i),
\r
374 * @param e DOCUMENT ME!
\r
376 public void mouseReleased(MouseEvent e)
\r
378 if (scrollThread != null)
\r
380 scrollThread.running = false;
\r
383 mouseDragging = false;
\r
384 PaintRefresher.Refresh(av.alignment);
\r
390 * @param found DOCUMENT ME!
\r
392 public void highlightSearchResults(java.util.Vector found)
\r
394 idCanvas.setHighlighted(found);
\r
401 int index = av.alignment.findIndex((SequenceI) found.get(0));
\r
403 // do we need to scroll the panel?
\r
404 if ((av.getStartSeq() > index) || (av.getEndSeq() < index))
\r
406 alignPanel.setScrollValues(av.getStartRes(), index);
\r
410 // this class allows scrolling off the bottom of the visible alignment
\r
411 class ScrollThread extends Thread
\r
413 boolean running = false;
\r
416 public ScrollThread(boolean up)
\r
422 public void stopScrolling()
\r
433 if (alignPanel.scrollUp(up))
\r
435 // scroll was ok, so add new sequence to selection
\r
436 int seq = av.getStartSeq();
\r
440 seq = av.getEndSeq();
\r
445 selectSeqs(lastid - 1, seq);
\r
447 else if (seq > lastid)
\r
449 selectSeqs(lastid + 1, seq);
\r
459 alignPanel.repaint();
\r
465 catch (Exception ex)
\r