JAL-3054 table tooltip follow mouse in a sensible manner
[jalview.git] / src / jalview / gui / FeatureSettings.java
index 01a7310..7fb3af9 100644 (file)
@@ -233,6 +233,21 @@ public class FeatureSettings extends JPanel
         }
         return tip;
       }
+
+      /**
+       * Position the tooltip at the bottom edge of, and half way across, the
+       * current cell
+       */
+      @Override
+      public Point getToolTipLocation(MouseEvent e)
+      {
+        Point point = e.getPoint();
+        int column = table.columnAtPoint(point);
+        int row = table.rowAtPoint(point);
+        Rectangle r = getCellRect(row, column, false);
+        Point loc = new Point(r.x + r.width / 2, r.y + r.height);
+        return loc;
+      }
     };
     table.getTableHeader().setFont(new Font("Verdana", Font.PLAIN, 12));
     table.setFont(new Font("Verdana", Font.PLAIN, 12));
@@ -1336,32 +1351,25 @@ public class FeatureSettings extends JPanel
   /**
    * Answers a suitable tooltip to show on the colour cell of the table
    * 
-   * @param gcol
+   * @param fcol
    * @return
    */
-  public String getColorTooltip(FeatureColourI gcol)
+  public static String getColorTooltip(FeatureColourI fcol)
   {
-    if (gcol.isSimpleColour())
+    if (fcol == null)
     {
-      return BASE_TOOLTIP;
+      return null;
     }
-    StringBuilder tt = new StringBuilder();
-    if (gcol.isAboveThreshold())
-    {
-      tt.append("Thresholded (Above ").append(gcol.getThreshold())
-              .append(")");
-    }
-    else if (gcol.isBelowThreshold())
+    if (fcol.isSimpleColour())
     {
-      tt.append("Thresholded (Below ").append(gcol.getThreshold())
-              .append(")");
-    }
-    else if (gcol.isColourByLabel())
-    {
-      tt.insert(0, "Coloured by label text ");
+      return BASE_TOOLTIP;
     }
-    tt.append("; ").append(BASE_TOOLTIP);
-    return tt.toString();
+    String description = fcol.getDescription();
+    description = description.replaceAll("<", "&lt;");
+    description = description.replaceAll(">", "&gt;");
+    StringBuilder tt = new StringBuilder(description);
+    tt.append("<br>").append(BASE_TOOLTIP).append("</br>");
+    return JvSwingUtils.wrapTooltip(true, tt.toString());
   }
 
   public static void renderGraduatedColor(JLabel comp, FeatureColourI gcol,
@@ -1859,7 +1867,6 @@ public class FeatureSettings extends JPanel
       button.setOpaque(true);
       button.setBackground(me.getBackground());
       button.setText(currentFilter.toString());
-      button.setToolTipText(currentFilter.toString());
       button.setIcon(null);
       return button;
     }