/*\r
* Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\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
*/\r
package jalview.gui;\r
\r
-import jalview.datamodel.*;\r
-\r
import java.awt.*;\r
import java.awt.event.*;\r
-\r
import javax.swing.*;\r
\r
+import jalview.datamodel.*;\r
\r
/**\r
* DOCUMENT ME!\r
* @author $author$\r
* @version $Revision$\r
*/\r
-public class IdPanel extends JPanel implements MouseListener,\r
- MouseMotionListener\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
- 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
+ protected IdCanvas idCanvas;\r
+ protected AlignViewport av;\r
+ protected AlignmentPanel alignPanel;\r
+ ScrollThread scrollThread = null;\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
+ 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
+ /**\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
- 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
- ToolTipManager.sharedInstance().registerComponent(this);\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void mouseMoved(MouseEvent e)\r
- {\r
- int y = e.getY();\r
-\r
- if (av.getWrapAlignment())\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
- y = getWrappedY(y);\r
- }\r
+ tip.append("<table width=250 border=0><tr><td><i>");\r
+ tip.append(sequence.getDescription());\r
\r
- final int seq = av.getIndex(y);\r
- if(seq!=-1)\r
- {\r
- SequenceI sequence = av.alignment.getSequenceAt(seq);\r
- StringBuffer tip = new StringBuffer("<html>");\r
- tip.append(sequence.getDisplayId(true));\r
- if (av.alignment.getSequenceAt(seq).getDescription() != null)\r
+ //ADD NON POSITIONAL SEQUENCE INFO\r
+ SequenceFeature[] features = sequence.getDatasetSequence().\r
+ getSequenceFeatures();\r
+ if (features != null)\r
{\r
- tip.append("<table width=250 border=0><tr><td><i>");\r
- tip.append(av.alignment.getSequenceAt(seq).getDescription());\r
-\r
- //ADD NON POSITIONAL SEQUENCE INFO\r
- SequenceFeature [] features = sequence.getDatasetSequence().getSequenceFeatures();\r
- if(features!=null)\r
+ for (int i = 0; i < features.length; i++)\r
{\r
- for(int i=0; i<features.length; i++)\r
+ if (features[i].begin == 0 && features[i].end == 0)\r
{\r
- if(features[i].begin == 0 && features[i].end ==0)\r
- {\r
- tip.append("<br>"+features[i].featureGroup\r
- +" "+ features[i].getType()+" "+features[i].description);\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
- tip.append("</html>");\r
- setToolTipText(tip.toString());\r
+ tip.append("</i></td></tr></table>");\r
}\r
- }\r
-\r
-\r
- int getWrappedY(int y)\r
- {\r
- int hgap = av.charHeight;\r
- if (av.scaleAboveWrapped)\r
- hgap += av.charHeight;\r
-\r
- return y - hgap;\r
- }\r
\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void mouseDragged(MouseEvent e)\r
- {\r
- mouseDragging = true;\r
-\r
- int y = e.getY();\r
-\r
- if (av.getWrapAlignment())\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
- y = getWrappedY(y);\r
+ tip.append("<br>");\r
+ tip.append(dbrefs[i].getSource() + " "\r
+ + dbrefs[i].getAccessionId());\r
}\r
+ tip.append("</i>");\r
+ }\r
\r
- int seq = av.getIndex(y);\r
+ tip.append("</html>");\r
+ setToolTipText(tip.toString());\r
+ }\r
+ }\r
\r
- if (seq < 0)\r
- {\r
- return;\r
- }\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void mouseDragged(MouseEvent e)\r
+ {\r
+ mouseDragging = true;\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
+ int seq = Math.max(0, alignPanel.seqPanel.findSeq(e));\r
\r
- lastid = seq;\r
- alignPanel.repaint();\r
+ if (seq < lastid)\r
+ {\r
+ selectSeqs(lastid - 1, seq);\r
}\r
-\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void mouseClicked(MouseEvent e)\r
+ else if (seq > lastid)\r
{\r
- if (e.getClickCount() < 2)\r
- return;\r
-\r
- java.util.Vector links = Preferences.sequenceURLLinks;\r
- if (links == null || links.size() < 1)\r
- return;\r
-\r
- int y = e.getY();\r
-\r
- if (av.getWrapAlignment())\r
- {\r
- y = getWrappedY(y);\r
- }\r
-\r
- //DEFAULT LINK IS FIRST IN THE LINK LIST\r
- int seq = av.getIndex(y);\r
- if(seq==-1)\r
- return;\r
-\r
- String id = av.getAlignment().getSequenceAt(seq).getName();\r
- if (id.indexOf("|") > -1)\r
- id = id.substring(id.lastIndexOf("|") + 1);\r
-\r
-\r
- String url = links.elementAt(0).toString();\r
- url = url.substring(url.indexOf("|")+1);\r
+ selectSeqs(lastid + 1, seq);\r
+ }\r
\r
- int index = url.indexOf("$SEQUENCE_ID$");\r
- url = url.substring(0, index)+ id + url.substring(index+13);\r
+ lastid = seq;\r
+ alignPanel.paintAlignment(true);\r
+ }\r
\r
- try\r
+ public void mouseWheelMoved(MouseWheelEvent e)\r
+ {\r
+ e.consume();\r
+ if (e.getWheelRotation() > 0)\r
{\r
- jalview.util.BrowserLauncher.openURL(url);\r
+ alignPanel.scrollUp(false);\r
}\r
- catch (Exception ex)\r
+ else\r
{\r
- JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
- "Unixers: Couldn't find default web browser."\r
- +"\nAdd the full path to your browser in Preferences.",\r
- "Web browser not found", JOptionPane.WARNING_MESSAGE );\r
- ex.printStackTrace();\r
+ alignPanel.scrollUp(true);\r
}\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void mouseEntered(MouseEvent e)\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
{\r
- if (scrollThread != null)\r
- {\r
- scrollThread.running = false;\r
- }\r
+ return;\r
}\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void mouseExited(MouseEvent e)\r
+ java.util.Vector links = Preferences.sequenceURLLinks;\r
+ if (links == null || links.size() < 1)\r
{\r
- if (av.getWrapAlignment())\r
- {\r
- return;\r
- }\r
+ return;\r
+ }\r
\r
- if (mouseDragging && (e.getY() < 0) && (av.getStartSeq() > 0))\r
- {\r
- scrollThread = new ScrollThread(true);\r
- }\r
+ int seq = alignPanel.seqPanel.findSeq(e);\r
\r
- if (mouseDragging && (e.getY() >= getHeight()) &&\r
- (av.alignment.getHeight() > av.getEndSeq()))\r
- {\r
- scrollThread = new ScrollThread(false);\r
- }\r
- }\r
+ //DEFAULT LINK IS FIRST IN THE LINK LIST\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void mousePressed(MouseEvent e)\r
+ String id = av.getAlignment().getSequenceAt(seq).getName();\r
+ if (id.indexOf("|") > -1)\r
{\r
- if (e.getClickCount() == 2)\r
- {\r
- return;\r
- }\r
+ id = id.substring(id.lastIndexOf("|") + 1);\r
+ }\r
\r
- int y = e.getY();\r
+ String url = links.elementAt(0).toString();\r
+ url = url.substring(url.indexOf("|") + 1);\r
\r
- if (av.getWrapAlignment())\r
- {\r
- y = getWrappedY(y);\r
- }\r
+ int index = url.indexOf("$SEQUENCE_ID$");\r
+ url = url.substring(0, index) + id + url.substring(index + 13);\r
\r
- int seq = av.getIndex(y);\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
+ {\r
+ scrollThread.running = false;\r
+ }\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void mouseExited(MouseEvent e)\r
+ {\r
+ if (av.getWrapAlignment())\r
+ {\r
+ return;\r
+ }\r
\r
- if (seq == -1)\r
- {\r
- return;\r
- }\r
+ if (mouseDragging && (e.getY() < 0) && (av.getStartSeq() > 0))\r
+ {\r
+ scrollThread = new ScrollThread(true);\r
+ }\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
- Preferences.sequenceURLLinks);\r
- pop.show(this, e.getX(), y);\r
+ if (mouseDragging && (e.getY() >= getHeight()) &&\r
+ (av.alignment.getHeight() > av.getEndSeq()))\r
+ {\r
+ scrollThread = new ScrollThread(false);\r
+ }\r
+ }\r
+\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
- return;\r
- }\r
+ int seq = alignPanel.seqPanel.findSeq(e);\r
\r
- /* if (!e.isControlDown() && !e.isShiftDown() &&\r
- (av.alignment.findGroup(av.alignment.getSequenceAt(seq)) != null))\r
- {\r
- System.out.println("no modifiers");\r
- SequenceGroup selection = new SequenceGroup();\r
- SequenceGroup sg = av.alignment.findGroup(av.alignment.getSequenceAt(\r
- seq));\r
- selection.setStartRes(0);\r
- selection.setEndRes(av.alignment.getWidth() - 1);\r
-\r
- for (int i = 0; i < sg.getSize(); i++)\r
- {\r
- selection.addSequence(sg.getSequenceAt(i), true);\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
+ Preferences.sequenceURLLinks);\r
+ pop.show(this, e.getX(), e.getY());\r
\r
- av.setSelectionGroup(selection);\r
+ return;\r
+ }\r
\r
- return;\r
- }*/\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
- 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
+ if (e.isShiftDown() && (lastid != -1))\r
+ {\r
+ selectSeqs(lastid, seq);\r
+ }\r
+ else\r
+ {\r
+ selectSeq(seq);\r
+ }\r
\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, true);\r
+ }\r
+\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
+ if (end >= av.getAlignment().getHeight())\r
+ {\r
+ end = av.getAlignment().getHeight() - 1;\r
+ }\r
\r
- if (e.isShiftDown() && (lastid != -1))\r
- {\r
- selectSeqs(lastid, seq);\r
- }\r
- else\r
- {\r
- selectSeq(seq);\r
- }\r
+ lastid = start;\r
\r
- alignPanel.repaint();\r
+ if (end < start)\r
+ {\r
+ int tmp = start;\r
+ start = end;\r
+ end = tmp;\r
+ lastid = end;\r
}\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param seq DOCUMENT ME!\r
- */\r
- void selectSeq(int seq)\r
+ for (int i = start; i <= end; i++)\r
{\r
- lastid = seq;\r
-\r
- SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq);\r
- av.getSelectionGroup().addOrRemove(pickedSeq, true);\r
+ av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i),\r
+ true);\r
}\r
-\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
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void mouseReleased(MouseEvent e)\r
+ {\r
+ if (scrollThread != null)\r
{\r
- if(av.getSelectionGroup()==null)\r
- return;\r
+ scrollThread.running = false;\r
+ }\r
\r
- lastid = start;\r
+ mouseDragging = false;\r
+ PaintRefresher.Refresh(this, av.getSequenceSetId());\r
+ }\r
\r
- if (end < start)\r
- {\r
- int tmp = start;\r
- start = end;\r
- end = tmp;\r
- lastid = end;\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
- for (int i = start; i <= end; i++)\r
- {\r
- av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i),\r
- true);\r
- }\r
+ if (found == null)\r
+ {\r
+ return;\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
- {\r
- scrollThread.running = false;\r
- }\r
+ int index = av.alignment.findIndex( (SequenceI) found.get(0));\r
\r
- mouseDragging = false;\r
- PaintRefresher.Refresh(av.alignment);\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
+ class ScrollThread\r
+ extends Thread\r
+ {\r
+ boolean running = false;\r
+ boolean up = true;\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param found DOCUMENT ME!\r
- */\r
- public void highlightSearchResults(java.util.Vector found)\r
+ public ScrollThread(boolean up)\r
{\r
- idCanvas.setHighlighted(found);\r
+ this.up = up;\r
+ start();\r
+ }\r
\r
- if (found == null)\r
- {\r
- return;\r
- }\r
+ public void stopScrolling()\r
+ {\r
+ running = false;\r
+ }\r
\r
- int index = av.alignment.findIndex((SequenceI) found.get(0));\r
+ public void run()\r
+ {\r
+ running = true;\r
\r
- // do we need to scroll the panel?\r
- if ((av.getStartSeq() > index) || (av.getEndSeq() < index))\r
+ while (running)\r
+ {\r
+ if (alignPanel.scrollUp(up))\r
{\r
- alignPanel.setScrollValues(av.getStartRes(), index);\r
- }\r
- }\r
+ // scroll was ok, so add new sequence to selection\r
+ int seq = av.getStartSeq();\r
\r
- // this class allows scrolling off the bottom of the visible alignment\r
- class ScrollThread extends Thread\r
- {\r
- boolean running = false;\r
- boolean up = true;\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
- public ScrollThread(boolean up)\r
+ lastid = seq;\r
+ }\r
+ else\r
{\r
- this.up = up;\r
- start();\r
+ running = false;\r
}\r
\r
- public void stopScrolling()\r
+ alignPanel.paintAlignment(true);\r
+\r
+ try\r
{\r
- running = false;\r
+ Thread.sleep(100);\r
}\r
-\r
- public void run()\r
+ catch (Exception ex)\r
{\r
- running = true;\r
-\r
- while (running)\r
- {\r
- if (alignPanel.scrollUp(up))\r
- {\r
- // scroll was ok, so add new sequence to selection\r
- int seq = av.getStartSeq();\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.repaint();\r
-\r
- try\r
- {\r
- Thread.sleep(100);\r
- }\r
- catch (Exception ex)\r
- {\r
- }\r
- }\r
}\r
+ }\r
}\r
+ }\r
}\r