+/*\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
+ */\r
package jalview.gui;\r
\r
import java.awt.*;\r
import java.awt.event.*;\r
-\r
-import jalview.datamodel.*;\r
-\r
import javax.swing.*;\r
\r
-public class IdPanel extends JPanel implements MouseListener, MouseMotionListener {\r
+import jalview.datamodel.*;\r
\r
- protected IdCanvas idCanvas;\r
- protected AlignViewport av;\r
+/**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @author $author$\r
+ * @version $Revision$\r
+ */\r
+public class IdPanel\r
+ extends JPanel implements MouseListener,\r
+ MouseMotionListener, MouseWheelListener\r
+{\r
+ protected IdCanvas idCanvas;\r
+ protected AlignViewport av;\r
protected AlignmentPanel alignPanel;\r
ScrollThread scrollThread = null;\r
-\r
- int offy;\r
- int width;\r
+ int offy;\r
+ int width;\r
int lastid = -1;\r
boolean mouseDragging = false;\r
\r
+ /**\r
+ * Creates a new IdPanel object.\r
+ *\r
+ * @param av DOCUMENT ME!\r
+ * @param parent DOCUMENT ME!\r
+ */\r
public IdPanel(AlignViewport av, AlignmentPanel parent)\r
{\r
- this.av = av;\r
+ this.av = av;\r
alignPanel = parent;\r
idCanvas = new IdCanvas(av);\r
setLayout(new BorderLayout());\r
add(idCanvas, BorderLayout.CENTER);\r
addMouseListener(this);\r
addMouseMotionListener(this);\r
+ addMouseWheelListener(this);\r
+ ToolTipManager.sharedInstance().registerComponent(this);\r
}\r
\r
- public void mouseMoved(MouseEvent e) {}\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void mouseMoved(MouseEvent e)\r
+ {\r
+ int seq = Math.max(0, alignPanel.seqPanel.findSeq(e));\r
+ if (seq > -1 && seq < av.alignment.getHeight())\r
+ {\r
+ SequenceI sequence = av.alignment.getSequenceAt(seq);\r
+ StringBuffer tip = new StringBuffer("<html>");\r
+ tip.append(sequence.getDisplayId(true));\r
+ if (sequence.getDescription() != null)\r
+ {\r
+ tip.append("<table width=250 border=0><tr><td><i>");\r
+ tip.append(sequence.getDescription());\r
\r
+ //ADD NON POSITIONAL SEQUENCE INFO\r
+ SequenceFeature[] features = sequence.getDatasetSequence().\r
+ getSequenceFeatures();\r
+ if (features != null)\r
+ {\r
+ for (int i = 0; i < features.length; i++)\r
+ {\r
+ if (features[i].begin == 0 && features[i].end == 0)\r
+ {\r
+ tip.append("<br>" + features[i].featureGroup\r
+ + " " + features[i].getType() + " " +\r
+ features[i].description);\r
+ }\r
+ }\r
+ }\r
+ tip.append("</i></td></tr></table>");\r
+ }\r
\r
- public void mouseDragged(MouseEvent e) {\r
- mouseDragging = true;\r
+ DBRefEntry[] dbrefs = sequence.getDatasetSequence().getDBRef();\r
+ if (dbrefs != null)\r
+ {\r
+ tip.append("<i>");\r
+ for (int i = 0; i < dbrefs.length; i++)\r
+ {\r
+ tip.append("<br>");\r
+ tip.append(dbrefs[i].getSource() + " "\r
+ + dbrefs[i].getAccessionId());\r
+ }\r
+ tip.append("</i>");\r
+ }\r
\r
- int y = e.getY();\r
- if(av.getWrapAlignment())\r
- y-=2*av.charHeight;\r
- int seq = av.getIndex(y);\r
+ tip.append("</html>");\r
+ setToolTipText(tip.toString());\r
+ }\r
+ }\r
\r
- if(seq<0)\r
- return;\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void mouseDragged(MouseEvent e)\r
+ {\r
+ mouseDragging = true;\r
+\r
+ int seq = Math.max(0, alignPanel.seqPanel.findSeq(e));\r
\r
if (seq < lastid)\r
+ {\r
selectSeqs(lastid - 1, seq);\r
+ }\r
else if (seq > lastid)\r
+ {\r
selectSeqs(lastid + 1, seq);\r
+ }\r
\r
lastid = seq;\r
- alignPanel.repaint();\r
+ alignPanel.paintAlignment(true);\r
+ }\r
+\r
+ public void mouseWheelMoved(MouseWheelEvent e)\r
+ {\r
+ e.consume();\r
+ if (e.getWheelRotation() > 0)\r
+ {\r
+ alignPanel.scrollUp(false);\r
+ }\r
+ else\r
+ {\r
+ alignPanel.scrollUp(true);\r
+ }\r
}\r
\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
public void mouseClicked(MouseEvent e)\r
{\r
- if (e.getClickCount() == 2)\r
+ if (e.getClickCount() < 2)\r
+ {\r
+ return;\r
+ }\r
+\r
+ java.util.Vector links = Preferences.sequenceURLLinks;\r
+ if (links == null || links.size() < 1)\r
{\r
- int y = e.getY();\r
- if(av.getWrapAlignment())\r
- y-=2*av.charHeight;\r
+ return;\r
+ }\r
+\r
+ int seq = alignPanel.seqPanel.findSeq(e);\r
\r
- int seq = av.getIndex(y);\r
- String id = av.getAlignment().getSequenceAt(seq).getName();\r
+ //DEFAULT LINK IS FIRST IN THE LINK LIST\r
\r
- try{\r
- jalview.util.BrowserLauncher.openURL(\r
- "http://srs.ebi.ac.uk/srs7bin/cgi-bin/wgetz?-e+[swall-id:" + id +\r
- "]+-vn+2");\r
- }catch(Exception ex){ex.printStackTrace();}\r
+ String id = av.getAlignment().getSequenceAt(seq).getName();\r
+ if (id.indexOf("|") > -1)\r
+ {\r
+ id = id.substring(id.lastIndexOf("|") + 1);\r
}\r
\r
+ String url = links.elementAt(0).toString();\r
+ url = url.substring(url.indexOf("|") + 1);\r
+\r
+ int index = url.indexOf("$SEQUENCE_ID$");\r
+ url = url.substring(0, index) + id + url.substring(index + 13);\r
+\r
+ try\r
+ {\r
+ jalview.util.BrowserLauncher.openURL(url);\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
+ "Unixers: Couldn't find default web browser."\r
+ +\r
+ "\nAdd the full path to your browser in Preferences.",\r
+ "Web browser not found",\r
+ JOptionPane.WARNING_MESSAGE);\r
+ ex.printStackTrace();\r
+ }\r
}\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
public void mouseEntered(MouseEvent e)\r
{\r
- if(scrollThread!=null)\r
+ if (scrollThread != null)\r
+ {\r
scrollThread.running = false;\r
+ }\r
}\r
\r
- public void mouseExited (MouseEvent e)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void mouseExited(MouseEvent e)\r
{\r
- if(av.getWrapAlignment())\r
+ if (av.getWrapAlignment())\r
+ {\r
return;\r
+ }\r
\r
- if(mouseDragging && e.getY()<0 && av.getStartSeq()>0)\r
+ if (mouseDragging && (e.getY() < 0) && (av.getStartSeq() > 0))\r
{\r
scrollThread = new ScrollThread(true);\r
}\r
\r
- if(mouseDragging && e.getY()>=getHeight() && av.alignment.getHeight()>av.getEndSeq())\r
+ if (mouseDragging && (e.getY() >= getHeight()) &&\r
+ (av.alignment.getHeight() > av.getEndSeq()))\r
{\r
scrollThread = new ScrollThread(false);\r
}\r
}\r
\r
-\r
- public void mousePressed(MouseEvent e) {\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void mousePressed(MouseEvent e)\r
+ {\r
if (e.getClickCount() == 2)\r
+ {\r
return;\r
+ }\r
\r
- int y = e.getY();\r
- if(av.getWrapAlignment())\r
- y-=2*av.charHeight;\r
-\r
- int seq = av.getIndex(y);\r
- if (seq == -1)\r
- return;\r
+ int seq = alignPanel.seqPanel.findSeq(e);\r
\r
if (javax.swing.SwingUtilities.isRightMouseButton(e))\r
{\r
jalview.gui.PopupMenu pop = new jalview.gui.PopupMenu(alignPanel,\r
- (Sequence)av.getAlignment().getSequenceAt(seq));\r
- pop.show(this, e.getX(), y);\r
- return;\r
- }\r
-\r
- if(!e.isControlDown() && !e.isShiftDown() && av.alignment.findGroup( av.alignment.getSequenceAt(seq))!=null)\r
- {\r
+ (Sequence) av.getAlignment().getSequenceAt(seq),\r
+ Preferences.sequenceURLLinks);\r
+ pop.show(this, e.getX(), e.getY());\r
\r
- SequenceGroup selection = new SequenceGroup();\r
- SequenceGroup sg = av.alignment.findGroup(av.alignment.getSequenceAt(seq));\r
- selection.setStartRes(0);\r
- selection.setEndRes(av.alignment.getWidth());\r
- for (int i =0; i< sg.getSize(); i++)\r
- selection.addSequence(sg.getSequenceAt(i));\r
-\r
- av.setSelectionGroup(selection);\r
return;\r
}\r
\r
- if(av.getSelectionGroup()==null || ( !e.isControlDown() && av.getSelectionGroup()!=null))\r
+ if ( (av.getSelectionGroup() == null) ||\r
+ ( (!e.isControlDown() && !e.isShiftDown()) && av.getSelectionGroup() != null))\r
+ {\r
av.setSelectionGroup(new SequenceGroup());\r
+ av.getSelectionGroup().setStartRes(0);\r
+ av.getSelectionGroup().setEndRes(av.alignment.getWidth() - 1);\r
+ }\r
\r
- av.getSelectionGroup().setStartRes(0);\r
- av.getSelectionGroup().setEndRes(av.alignment.getWidth()-1);\r
-\r
- if(e.isShiftDown() && lastid!=-1)\r
+ if (e.isShiftDown() && (lastid != -1))\r
+ {\r
selectSeqs(lastid, seq);\r
+ }\r
else\r
+ {\r
selectSeq(seq);\r
+ }\r
\r
- alignPanel.seqPanel.seqCanvas.paintFlag=true;\r
- alignPanel.repaint();\r
- repaint();\r
+ alignPanel.paintAlignment(true);\r
}\r
\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param seq DOCUMENT ME!\r
+ */\r
void selectSeq(int seq)\r
{\r
lastid = seq;\r
+\r
SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq);\r
- av.getSelectionGroup().addOrRemove(pickedSeq);\r
+ av.getSelectionGroup().addOrRemove(pickedSeq, true);\r
}\r
\r
- void selectSeqs(int start, int end) {\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param start DOCUMENT ME!\r
+ * @param end DOCUMENT ME!\r
+ */\r
+ void selectSeqs(int start, int end)\r
+ {\r
+ if (av.getSelectionGroup() == null)\r
+ {\r
+ return;\r
+ }\r
\r
- lastid = start;\r
- if (end < start)\r
- {\r
- int tmp = start;\r
- start = end;\r
- end = tmp;\r
- lastid = end;\r
- }\r
+ if (end >= av.getAlignment().getHeight())\r
+ {\r
+ end = av.getAlignment().getHeight() - 1;\r
+ }\r
\r
- for (int i = start; i <= end; i++)\r
- av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i));\r
+ lastid = start;\r
\r
- }\r
+ if (end < start)\r
+ {\r
+ int tmp = start;\r
+ start = end;\r
+ end = tmp;\r
+ lastid = end;\r
+ }\r
\r
+ for (int i = start; i <= end; i++)\r
+ {\r
+ av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i),\r
+ true);\r
+ }\r
+ }\r
\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
public void mouseReleased(MouseEvent e)\r
{\r
- if(scrollThread!=null)\r
+ if (scrollThread != null)\r
+ {\r
scrollThread.running = false;\r
+ }\r
\r
mouseDragging = false;\r
- PaintRefresher.Refresh(this);\r
+ PaintRefresher.Refresh(this, av.getSequenceSetId());\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param found DOCUMENT ME!\r
+ */\r
+ public void highlightSearchResults(java.util.Vector found)\r
+ {\r
+ idCanvas.setHighlighted(found);\r
+\r
+ if (found == null)\r
+ {\r
+ return;\r
+ }\r
+\r
+ int index = av.alignment.findIndex( (SequenceI) found.get(0));\r
+\r
+ // do we need to scroll the panel?\r
+ if ( (av.getStartSeq() > index) || (av.getEndSeq() < index))\r
+ {\r
+ alignPanel.setScrollValues(av.getStartRes(), index);\r
+ }\r
}\r
\r
// this class allows scrolling off the bottom of the visible alignment\r
{\r
boolean running = false;\r
boolean up = true;\r
+\r
public ScrollThread(boolean up)\r
{\r
this.up = up;\r
public void run()\r
{\r
running = true;\r
+\r
while (running)\r
{\r
- if(alignPanel.scrollUp(up))\r
+ if (alignPanel.scrollUp(up))\r
{\r
// scroll was ok, so add new sequence to selection\r
int seq = av.getStartSeq();\r
- if(!up)\r
+\r
+ if (!up)\r
+ {\r
seq = av.getEndSeq();\r
+ }\r
\r
if (seq < lastid)\r
+ {\r
selectSeqs(lastid - 1, seq);\r
+ }\r
else if (seq > lastid)\r
+ {\r
selectSeqs(lastid + 1, seq);\r
+ }\r
\r
lastid = seq;\r
}\r
else\r
+ {\r
running = false;\r
+ }\r
+\r
+ alignPanel.paintAlignment(true);\r
\r
- alignPanel.repaint();\r
try\r
{\r
Thread.sleep(100);\r
}\r
catch (Exception ex)\r
- {}\r
+ {\r
+ }\r
}\r
}\r
-}\r
-\r
+ }\r
}\r