2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 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
20 package jalview.appletgui;
23 import java.awt.event.*;
25 import jalview.datamodel.*;
26 import jalview.util.UrlLink;
29 extends Panel implements MouseListener, MouseMotionListener
32 protected IdCanvas idCanvas;
33 protected AlignViewport av;
34 protected AlignmentPanel alignPanel;
35 ScrollThread scrollThread = null;
40 boolean mouseDragging = false;
41 java.util.Vector links = new java.util.Vector();
43 public IdPanel(AlignViewport av, AlignmentPanel parent)
47 idCanvas = new IdCanvas(av);
48 setLayout(new BorderLayout());
49 add(idCanvas, BorderLayout.CENTER);
50 idCanvas.addMouseListener(this);
51 idCanvas.addMouseMotionListener(this);
54 if (av.applet != null)
56 for (int i = 1; i < 10; i++)
58 label = av.applet.getParameter("linkLabel_" + i);
59 url = av.applet.getParameter("linkURL_" + i);
61 if (label != null && url != null)
63 links.addElement(label + "|" + url);
70 links = new java.util.Vector();
71 links.addElement("SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry");
76 public void mouseMoved(MouseEvent e)
78 int seq = alignPanel.seqPanel.findSeq(e);
80 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
82 if (sequence.getDescription() == null)
86 tooltip.setVisible(false);
94 tooltip = new Tooltip(
95 sequence.getDisplayId(true)
96 + "\n" + sequence.getDescription(), idCanvas);
100 tooltip.setTip(sequence.getDisplayId(true)
101 + "\n" + sequence.getDescription());
105 public void mouseDragged(MouseEvent e)
107 mouseDragging = true;
109 int seq = Math.max(0, alignPanel.seqPanel.findSeq(e));
113 selectSeqs(lastid - 1, seq);
115 else if (seq > lastid)
117 selectSeqs(lastid + 1, seq);
121 alignPanel.paintAlignment(false);
124 public void mouseClicked(MouseEvent e)
126 if (e.getClickCount() < 2)
131 //DEFAULT LINK IS FIRST IN THE LINK LIST
132 int seq = alignPanel.seqPanel.findSeq(e);
133 String id = av.getAlignment().getSequenceAt(seq).getName();
135 String target = null;
138 while (url == null && i < links.size())
140 // DEFAULT LINK IS FIRST IN THE LINK LIST
141 // BUT IF ITS A REGEX AND DOES NOT MATCH THE NEXT ONE WILL BE TRIED
142 url = links.elementAt(i++).toString();
143 jalview.util.UrlLink urlLink = null;
146 urlLink = new UrlLink(url);
147 target = urlLink.getTarget();
148 } catch (Exception foo)
150 System.err.println("Exception for URLLink '" + url + "'");
151 foo.printStackTrace();
156 if (!urlLink.isValid())
158 System.err.println(urlLink.getInvalidMessage());
163 String urls[] = urlLink.makeUrls(id, true);
164 if (urls == null || urls[0]==null || urls[0].length()<1)
169 // just take first URL made from regex
175 alignPanel.alignFrame.showURL(url, target);
179 ex.printStackTrace();
183 public void mouseEntered(MouseEvent e)
185 if (scrollThread != null)
187 scrollThread.running = false;
191 public void mouseExited(MouseEvent e)
193 if (av.getWrapAlignment())
198 if (mouseDragging && e.getY() < 0 && av.getStartSeq() > 0)
200 scrollThread = new ScrollThread(true);
203 if (mouseDragging && e.getY() >= getSize().height &&
204 av.alignment.getHeight() > av.getEndSeq())
206 scrollThread = new ScrollThread(false);
210 public void mousePressed(MouseEvent e)
212 if (e.getClickCount() > 1)
218 if (av.getWrapAlignment())
220 y -= 2 * av.charHeight;
223 int seq = alignPanel.seqPanel.findSeq(e);
225 if ( (e.getModifiers() & InputEvent.BUTTON3_MASK) ==
226 InputEvent.BUTTON3_MASK)
228 APopupMenu popup = new APopupMenu(alignPanel,
229 (Sequence) av.getAlignment().
230 getSequenceAt(seq), links);
232 popup.show(this, e.getX(), e.getY());
236 if ( (av.getSelectionGroup() == null) ||
237 ( (!e.isControlDown() && !e.isShiftDown()) && av.getSelectionGroup() != null))
239 av.setSelectionGroup(new SequenceGroup());
240 av.getSelectionGroup().setStartRes(0);
241 av.getSelectionGroup().setEndRes(av.alignment.getWidth() - 1);
244 if (e.isShiftDown() && lastid != -1)
246 selectSeqs(lastid, seq);
253 alignPanel.paintAlignment(false);
256 void selectSeq(int seq)
259 SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq);
260 av.getSelectionGroup().addOrRemove(pickedSeq, false);
263 void selectSeqs(int start, int end)
268 if (end >= av.getAlignment().getHeight())
270 end = av.getAlignment().getHeight() - 1;
281 for (int i = start; i <= end; i++)
283 av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i), false);
288 public void mouseReleased(MouseEvent e)
290 if (scrollThread != null)
292 scrollThread.running = false;
295 if (av.getSelectionGroup() != null)
297 av.getSelectionGroup().recalcConservation();
300 mouseDragging = false;
301 PaintRefresher.Refresh(this, av.getSequenceSetId());
304 public void highlightSearchResults(java.util.Vector found)
306 idCanvas.setHighlighted(found);
313 int index = av.alignment.findIndex( (SequenceI) found.elementAt(0));
315 // do we need to scroll the panel?
316 if (av.getStartSeq() > index || av.getEndSeq() < index)
318 alignPanel.setScrollValues(av.getStartRes(), index);
322 // this class allows scrolling off the bottom of the visible alignment
326 boolean running = false;
328 public ScrollThread(boolean up)
334 public void stopScrolling()
344 if (alignPanel.scrollUp(up))
346 // scroll was ok, so add new sequence to selection
347 int seq = av.getStartSeq();
350 seq = av.getEndSeq();
355 selectSeqs(lastid - 1, seq);
357 else if (seq > lastid && seq < av.alignment.getHeight())
359 selectSeqs(lastid + 1, seq);
369 alignPanel.paintAlignment(true);