+/*\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
-\r
- protected int offy;\r
- public int width;\r
- public int lastid;\r
-\r
-\r
-\r
- boolean mouseDown;\r
- boolean mouseUp;\r
-\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
+ 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
- public void selectSeqs(int start, int end) {\r
- if (end < start) {\r
- int tmp = start;\r
- start = end;\r
- end = tmp;\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
- for (int i = start; i <= end; i++) {\r
- SequenceI pickedSeq = av.getAlignment().getSequenceAt(i);\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
- if (av.getSelection().contains(pickedSeq)) {\r
- av.getSelection().removeElement(pickedSeq);\r
- } else {\r
- av.getSelection().addElement(pickedSeq);\r
- }\r
- }\r
+ tip.append("</html>");\r
+ setToolTipText(tip.toString());\r
+ }\r
+ }\r
\r
- repaint();\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void mouseDragged(MouseEvent e)\r
+ {\r
+ mouseDragging = true;\r
\r
- }\r
+ int seq = Math.max(0, alignPanel.seqPanel.findSeq(e));\r
\r
- public void mouseDragged(MouseEvent e) {\r
- int y = e.getY();\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
- int seq = av.getIndex(y);\r
+ lastid = seq;\r
+ alignPanel.paintAlignment(true);\r
+ }\r
\r
- if (mouseDown == true) {\r
- if (seq < lastid) {\r
- selectSeqs(lastid-1,seq);\r
- } else if (seq > lastid) {\r
- selectSeqs(lastid+1,seq);\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
- lastid = seq;\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
+ return;\r
+ }\r
+\r
+ java.util.Vector links = Preferences.sequenceURLLinks;\r
+ if (links == null || links.size() < 1)\r
+ {\r
+ return;\r
+ }\r
+\r
+ int seq = alignPanel.seqPanel.findSeq(e);\r
+\r
+ //DEFAULT LINK IS FIRST IN THE LINK LIST\r
+\r
+ String id = av.getAlignment().getSequenceAt(seq).getName();\r
+ if (id.indexOf("|") > -1)\r
+ {\r
+ id = id.substring(id.lastIndexOf("|") + 1);\r
}\r
\r
- return;\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
- public void mouseClicked(MouseEvent e) { }\r
- public void mouseEntered(MouseEvent e) { }\r
- public void mouseExited (MouseEvent e) { }\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
- public void mousePressed(MouseEvent e) {\r
- int x = e.getX();\r
- int y = e.getY();\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
- int seq = av.getIndex(y);\r
+ if (mouseDragging && (e.getY() < 0) && (av.getStartSeq() > 0))\r
+ {\r
+ scrollThread = new ScrollThread(true);\r
+ }\r
\r
- mouseDown = true;\r
+ if (mouseDragging && (e.getY() >= getHeight()) &&\r
+ (av.alignment.getHeight() > av.getEndSeq()))\r
+ {\r
+ scrollThread = new ScrollThread(false);\r
+ }\r
+ }\r
\r
- if( javax.swing.SwingUtilities.isRightMouseButton(e))\r
- {\r
- String id = av.getAlignment().getSequenceAt(seq).getName();\r
- String s = (String)JOptionPane.showInputDialog(\r
- this,\r
- "Edit sequence name",\r
- "Edit sequence name",\r
- JOptionPane.PLAIN_MESSAGE,\r
- null,\r
- null,\r
- id);\r
-\r
- if(s!=null)\r
- {\r
- av.getAlignment().getSequenceAt(seq).setName(s);\r
- alignPanel.RefreshPanels();\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
- }\r
- else\r
- {\r
- if (seq != -1)\r
- selectSeqs(seq,seq);\r
+ int seq = alignPanel.seqPanel.findSeq(e);\r
\r
- lastid = seq;\r
- }\r
- return;\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
+ return;\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
+\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
+ lastid = start;\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
+ {\r
+ scrollThread.running = false;\r
+ }\r
+\r
+ mouseDragging = false;\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
- public void mouseReleased(MouseEvent e) {\r
- lastid = -1;\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
+ public ScrollThread(boolean up)\r
+ {\r
+ this.up = up;\r
+ start();\r
+ }\r
+\r
+ public void stopScrolling()\r
+ {\r
+ running = false;\r
+ }\r
+\r
+ public void run()\r
+ {\r
+ running = true;\r
\r
- mouseDown = false;\r
- mouseUp = true;\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
- PaintRefresher.Refresh(this);\r
+ alignPanel.paintAlignment(true);\r
\r
+ try\r
+ {\r
+ Thread.sleep(100);\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ }\r
+ }\r
+ }\r
}\r
}\r