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