JAL-4047 - proof of concept for JAL-4048 - display columns of info in sequence ID...
[jalview.git] / src / jalview / gui / IdPanel.java
index 7b491e4..fdca723 100755 (executable)
@@ -46,6 +46,9 @@ import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.viewmodel.AlignmentViewport;
 import jalview.viewmodel.ViewportRanges;
+import jalview.viewmodel.seqfeatures.IdColumn;
+import jalview.viewmodel.seqfeatures.IdColumns;
+import jalview.viewmodel.seqfeatures.IdColumns.ColumnCell;
 
 /**
  * This panel hosts alignment sequence ids and responds to mouse clicks on them,
@@ -125,8 +128,17 @@ public class IdPanel extends JPanel
         SequenceI sequence = av.getAlignment().getSequenceAt(seq);
         StringBuilder tip = new StringBuilder(64);
         tip.append(sequence.getDisplayId(true)).append(" ");
-        seqAnnotReport.createTooltipAnnotationReport(tip, sequence,
-                av.isShowDBRefs(), av.isShowNPFeats(), sp.seqCanvas.fr);
+        IdColumn col = locateColumnFor(e);
+        if (col != null)
+        {
+          // tooltip for column
+          tip.append(getTooltipFor(col, sequence));
+        }
+        else
+        {
+          seqAnnotReport.createTooltipAnnotationReport(tip, sequence,
+                  av.isShowDBRefs(), av.isShowNPFeats(), sp.seqCanvas.fr);
+        }
         setToolTipText(JvSwingUtils.wrapTooltip(true, tip.toString()));
 
         StringBuilder text = new StringBuilder();
@@ -137,6 +149,40 @@ public class IdPanel extends JPanel
     }
   }
 
+  private Object getTooltipFor(IdColumn col, SequenceI seq)
+  {
+    ColumnCell cell = av.getIdColumns().getCellFor(seq, col);
+    if (cell != null)
+    {
+      return "" + col.getLabel() + ": " + cell.label;
+    }
+    return "";
+  }
+
+  private IdColumn locateColumnFor(MouseEvent e)
+  {
+    // TODO COMBINE SAME CODE IN IDCANVAS!!!
+
+    IdColumns id_cols = av.getIdColumns();
+    List<IdColumn> visible = id_cols.getVisible();
+    /**
+     * width of an idColumn
+     */
+    int colWid = 20;
+    int panelWidth = Math.max(idCanvas.getWidth() / 2,
+            idCanvas.getWidth() - (colWid * visible.size()));
+    int p = 0;
+    while (panelWidth < idCanvas.getWidth() && p < visible.size())
+    {
+
+      if (e.getX() >= panelWidth && e.getX() < panelWidth + colWid)
+        return visible.get(p);
+      p++;
+      panelWidth += colWid;
+    }
+    return null;
+  }
+
   /**
    * Responds to a mouse drag by selecting the sequences under the dragged
    * region.