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