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
20 package jalview.appletgui;
23 import java.awt.event.*;
25 import jalview.datamodel.*;
28 extends Panel implements MouseListener, MouseMotionListener
31 protected IdCanvas idCanvas;
32 protected AlignViewport av;
33 protected AlignmentPanel alignPanel;
34 ScrollThread scrollThread = null;
39 boolean mouseDragging = false;
40 java.util.Vector links = new java.util.Vector();
42 public IdPanel(AlignViewport av, AlignmentPanel parent)
46 idCanvas = new IdCanvas(av);
47 setLayout(new BorderLayout());
48 add(idCanvas, BorderLayout.CENTER);
49 idCanvas.addMouseListener(this);
50 idCanvas.addMouseMotionListener(this);
55 for (int i = 1; i < 10; i++)
57 label = av.applet.getParameter("linkLabel_" + i);
58 url = av.applet.getParameter("linkURL_" + i);
60 if (label != null && url != null)
61 links.addElement(label + "|" + url);
67 links = new java.util.Vector();
68 links.addElement("SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry");
73 public void mouseMoved(MouseEvent e)
75 int seq = alignPanel.seqPanel.findSeq(e);
77 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
79 if(sequence.getDescription()==null)
82 tooltip.setVisible(false);
88 tooltip = new Tooltip(
89 sequence.getDisplayId(true)
90 + "\n" + sequence.getDescription(), idCanvas);
92 tooltip.setTip(sequence.getDisplayId(true)
93 + "\n" + sequence.getDescription());
99 public void mouseDragged(MouseEvent e)
101 mouseDragging = true;
103 int seq = Math.max(0, alignPanel.seqPanel.findSeq(e));
107 selectSeqs(lastid - 1, seq);
109 else if (seq > lastid)
111 selectSeqs(lastid + 1, seq);
115 alignPanel.repaint();
118 public void mouseClicked(MouseEvent e)
120 if (e.getClickCount() < 2)
124 //DEFAULT LINK IS FIRST IN THE LINK LIST
125 int seq = alignPanel.seqPanel.findSeq(e);
126 String id = av.getAlignment().getSequenceAt(seq).getName();
127 if (id.indexOf("|") > -1)
128 id = id.substring(id.lastIndexOf("|") + 1);
130 String target = links.elementAt(0).toString();
131 target = target.substring(0, target.indexOf("|"));
132 String url = links.elementAt(0).toString();
133 url = url.substring(url.indexOf("|")+1);
135 int index = url.indexOf("$SEQUENCE_ID$");
136 url = url.substring(0, index)+ id + url.substring(index+13);
141 alignPanel.alignFrame.showURL(url, target);
145 ex.printStackTrace();
149 public void mouseEntered(MouseEvent e)
151 if (scrollThread != null)
153 scrollThread.running = false;
157 public void mouseExited(MouseEvent e)
159 if (av.getWrapAlignment())
164 if (mouseDragging && e.getY() < 0 && av.getStartSeq() > 0)
166 scrollThread = new ScrollThread(true);
169 if (mouseDragging && e.getY() >= getSize().height &&
170 av.alignment.getHeight() > av.getEndSeq())
172 scrollThread = new ScrollThread(false);
176 public void mousePressed(MouseEvent e)
178 if (e.getClickCount() >1 )
184 if (av.getWrapAlignment())
186 y -= 2 * av.charHeight;
189 int seq = alignPanel.seqPanel.findSeq(e);
191 if ( (e.getModifiers() & InputEvent.BUTTON3_MASK) ==
192 InputEvent.BUTTON3_MASK)
194 APopupMenu popup = new APopupMenu(alignPanel, (Sequence) av.getAlignment().getSequenceAt(seq), links);
196 popup.show(this, e.getX(), e.getY());
201 if ((av.getSelectionGroup() == null) ||
202 ((!e.isControlDown() && !e.isShiftDown()) && av.getSelectionGroup() != null))
204 av.setSelectionGroup(new SequenceGroup());
205 av.getSelectionGroup().setStartRes(0);
206 av.getSelectionGroup().setEndRes(av.alignment.getWidth() - 1);
210 if (e.isShiftDown() && lastid != -1)
212 selectSeqs(lastid, seq);
219 alignPanel.repaint();
222 void selectSeq(int seq)
225 SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq);
226 av.getSelectionGroup().addOrRemove(pickedSeq, false);
229 void selectSeqs(int start, int end)
241 for (int i = start; i <= end; i++)
243 av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i), false);
248 public void mouseReleased(MouseEvent e)
250 if (scrollThread != null)
252 scrollThread.running = false;
255 if(av.getSelectionGroup()!=null)
256 av.getSelectionGroup().recalcConservation();
258 mouseDragging = false;
259 PaintRefresher.Refresh(this, av.alignment);
262 public void highlightSearchResults(java.util.Vector found)
264 idCanvas.setHighlighted(found);
271 int index = av.alignment.findIndex( (SequenceI) found.elementAt(0));
273 // do we need to scroll the panel?
274 if (av.getStartSeq() > index || av.getEndSeq() < index)
276 alignPanel.setScrollValues(av.getStartRes(), index);
280 // this class allows scrolling off the bottom of the visible alignment
284 boolean running = false;
286 public ScrollThread(boolean up)
292 public void stopScrolling()
302 if (alignPanel.scrollUp(up))
304 // scroll was ok, so add new sequence to selection
305 int seq = av.getStartSeq();
308 seq = av.getEndSeq();
313 selectSeqs(lastid - 1, seq);
315 else if (seq > lastid && seq<av.alignment.getHeight())
317 selectSeqs(lastid + 1, seq);
328 alignPanel.repaint();