2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 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
53 if (av.applet != null)
\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
62 links.addElement(label + "|" + url);
\r
67 if (links.size() < 1)
\r
69 links = new java.util.Vector();
\r
70 links.addElement("SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry");
\r
75 public void mouseMoved(MouseEvent e)
\r
77 int seq = alignPanel.seqPanel.findSeq(e);
\r
79 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
\r
81 if (sequence.getDescription() == null)
\r
83 if (tooltip != null)
\r
85 tooltip.setVisible(false);
\r
91 if (tooltip == null)
\r
93 tooltip = new Tooltip(
\r
94 sequence.getDisplayId(true)
\r
95 + "\n" + sequence.getDescription(), idCanvas);
\r
99 tooltip.setTip(sequence.getDisplayId(true)
\r
100 + "\n" + sequence.getDescription());
\r
104 public void mouseDragged(MouseEvent e)
\r
106 mouseDragging = true;
\r
108 int seq = Math.max(0, alignPanel.seqPanel.findSeq(e));
\r
112 selectSeqs(lastid - 1, seq);
\r
114 else if (seq > lastid)
\r
116 selectSeqs(lastid + 1, seq);
\r
120 alignPanel.paintAlignment(false);
\r
123 public void mouseClicked(MouseEvent e)
\r
125 if (e.getClickCount() < 2)
\r
130 //DEFAULT LINK IS FIRST IN THE LINK LIST
\r
131 int seq = alignPanel.seqPanel.findSeq(e);
\r
132 String id = av.getAlignment().getSequenceAt(seq).getName();
\r
133 if (id.indexOf("|") > -1)
\r
135 id = id.substring(id.lastIndexOf("|") + 1);
\r
138 String target = links.elementAt(0).toString();
\r
139 target = target.substring(0, target.indexOf("|"));
\r
140 String url = links.elementAt(0).toString();
\r
141 url = url.substring(url.indexOf("|") + 1);
\r
143 int index = url.indexOf("$SEQUENCE_ID$");
\r
144 url = url.substring(0, index) + id + url.substring(index + 13);
\r
149 alignPanel.alignFrame.showURL(url, target);
\r
151 catch (Exception ex)
\r
153 ex.printStackTrace();
\r
157 public void mouseEntered(MouseEvent e)
\r
159 if (scrollThread != null)
\r
161 scrollThread.running = false;
\r
165 public void mouseExited(MouseEvent e)
\r
167 if (av.getWrapAlignment())
\r
172 if (mouseDragging && e.getY() < 0 && av.getStartSeq() > 0)
\r
174 scrollThread = new ScrollThread(true);
\r
177 if (mouseDragging && e.getY() >= getSize().height &&
\r
178 av.alignment.getHeight() > av.getEndSeq())
\r
180 scrollThread = new ScrollThread(false);
\r
184 public void mousePressed(MouseEvent e)
\r
186 if (e.getClickCount() > 1)
\r
192 if (av.getWrapAlignment())
\r
194 y -= 2 * av.charHeight;
\r
197 int seq = alignPanel.seqPanel.findSeq(e);
\r
199 if ( (e.getModifiers() & InputEvent.BUTTON3_MASK) ==
\r
200 InputEvent.BUTTON3_MASK)
\r
202 APopupMenu popup = new APopupMenu(alignPanel,
\r
203 (Sequence) av.getAlignment().
\r
204 getSequenceAt(seq), links);
\r
206 popup.show(this, e.getX(), e.getY());
\r
210 if ( (av.getSelectionGroup() == null) ||
\r
211 ( (!e.isControlDown() && !e.isShiftDown()) && av.getSelectionGroup() != null))
\r
213 av.setSelectionGroup(new SequenceGroup());
\r
214 av.getSelectionGroup().setStartRes(0);
\r
215 av.getSelectionGroup().setEndRes(av.alignment.getWidth() - 1);
\r
218 if (e.isShiftDown() && lastid != -1)
\r
220 selectSeqs(lastid, seq);
\r
227 alignPanel.paintAlignment(false);
\r
230 void selectSeq(int seq)
\r
233 SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq);
\r
234 av.getSelectionGroup().addOrRemove(pickedSeq, false);
\r
237 void selectSeqs(int start, int end)
\r
242 if (end >= av.getAlignment().getHeight())
\r
244 end = av.getAlignment().getHeight() - 1;
\r
255 for (int i = start; i <= end; i++)
\r
257 av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i), false);
\r
262 public void mouseReleased(MouseEvent e)
\r
264 if (scrollThread != null)
\r
266 scrollThread.running = false;
\r
269 if (av.getSelectionGroup() != null)
\r
271 av.getSelectionGroup().recalcConservation();
\r
274 mouseDragging = false;
\r
275 PaintRefresher.Refresh(this, av.getSequenceSetId());
\r
278 public void highlightSearchResults(java.util.Vector found)
\r
280 idCanvas.setHighlighted(found);
\r
287 int index = av.alignment.findIndex( (SequenceI) found.elementAt(0));
\r
289 // do we need to scroll the panel?
\r
290 if (av.getStartSeq() > index || av.getEndSeq() < index)
\r
292 alignPanel.setScrollValues(av.getStartRes(), index);
\r
296 // this class allows scrolling off the bottom of the visible alignment
\r
300 boolean running = false;
\r
302 public ScrollThread(boolean up)
\r
308 public void stopScrolling()
\r
318 if (alignPanel.scrollUp(up))
\r
320 // scroll was ok, so add new sequence to selection
\r
321 int seq = av.getStartSeq();
\r
324 seq = av.getEndSeq();
\r
329 selectSeqs(lastid - 1, seq);
\r
331 else if (seq > lastid && seq < av.alignment.getHeight())
\r
333 selectSeqs(lastid + 1, seq);
\r
343 alignPanel.paintAlignment(true);
\r
348 catch (Exception ex)
\r