JAL-3132 set status message when over sequence id or annotation label
[jalview.git] / src / jalview / gui / SeqPanel.java
index d0859b8..a53edb9 100644 (file)
@@ -274,23 +274,9 @@ public class SeqPanel extends JPanel
     {
       seqCanvas.calculateWrappedGeometry(seqCanvas.getWidth(),
               seqCanvas.getHeight());
-      // int gapHeight = charHeight;
-      // if (av.getScaleAboveWrapped())
-      // {
-      // gapHeight += charHeight;
-      // }
-      //
-      // final int alignmentHeightPixels = gapHeight
-      // + alignmentHeight * charHeight;
-      // int cHeight = alignmentHeightPixels;
-      // if (av.isShowAnnotation())
-      // {
-      // cHeight += (seqCanvas.getAnnotationHeight() +
-      // SeqCanvas.SEQS_ANNOTATION_GAP);
-      // }
 
       /*
-       * yPos modulo repeating width height
+       * yPos modulo height of repeating width
        */
       int yOffsetPx = y % seqCanvas.wrappedRepeatHeightPx;
 
@@ -345,7 +331,9 @@ public class SeqPanel extends JPanel
     int res = 0;
     int x = evt.getX();
 
-    int startRes = av.getRanges().getStartRes();
+    final int startRes = av.getRanges().getStartRes();
+    final int charWidth = av.getCharWidth();
+
     if (av.getWrapAlignment())
     {
       int hgap = av.getCharHeight();
@@ -359,20 +347,30 @@ public class SeqPanel extends JPanel
 
       int y = evt.getY();
       y = Math.max(0, y - hgap);
-      x = Math.max(0, x - seqCanvas.getLabelWidthWest());
+      x -= seqCanvas.getLabelWidthWest();
+      if (x < 0)
+      {
+        // mouse is over left scale
+        return -1;
+      }
 
       int cwidth = seqCanvas.getWrappedCanvasWidth(this.getWidth());
       if (cwidth < 1)
       {
         return 0;
       }
+      if (x >= cwidth * charWidth)
+      {
+        // mouse is over right scale
+        return -1;
+      }
 
       wrappedBlock = y / cHeight;
       wrappedBlock += startRes / cwidth;
       // allow for wrapped view scrolled right (possible from Overview)
       int startOffset = startRes % cwidth;
       res = wrappedBlock * cwidth + startOffset
-              + Math.min(cwidth - 1, x / av.getCharWidth());
+              + Math.min(cwidth - 1, x / charWidth);
     }
     else
     {
@@ -381,7 +379,7 @@ public class SeqPanel extends JPanel
        * rather than right-hand gutter
        */
       x = Math.min(x, seqCanvas.getX() + seqCanvas.getWidth());
-      res = (x / av.getCharWidth()) + startRes;
+      res = (x / charWidth) + startRes;
       res = Math.min(res, av.getRanges().getEndRes());
     }
 
@@ -728,9 +726,8 @@ public class SeqPanel extends JPanel
   public void mouseReleased(MouseEvent evt)
   {
     MousePos pos = findMousePosition(evt);
-    if (pos.annotationIndex != -1)
+    if (pos.isOverAnnotation() || pos.seqIndex == -1 || pos.column == -1)
     {
-      // mouse is over annotation row in wrapped mode
       return;
     }
 
@@ -765,9 +762,8 @@ public class SeqPanel extends JPanel
   {
     lastMousePress = evt.getPoint();
     MousePos pos = findMousePosition(evt);
-    if (pos.annotationIndex != -1)
+    if (pos.isOverAnnotation() || pos.seqIndex == -1 || pos.column == -1)
     {
-      // mouse is over an annotation row in wrapped mode
       return;
     }
 
@@ -795,11 +791,6 @@ public class SeqPanel extends JPanel
     int seq = pos.seqIndex;
     int res = pos.column;
 
-    if (seq < 0 || res < 0)
-    {
-      return;
-    }
-
     if ((seq < av.getAlignment().getHeight())
             && (res < av.getAlignment().getSequenceAt(seq).getLength()))
     {
@@ -923,7 +914,7 @@ public class SeqPanel extends JPanel
       lastMousePosition = null;
       setToolTipText(null);
       lastTooltip = null;
-      ap.alignFrame.statusBar.setText("");
+      ap.alignFrame.setStatus("");
       return;
     }
 
@@ -1015,7 +1006,8 @@ public class SeqPanel extends JPanel
     final int column = pos.column;
     final int rowIndex = pos.annotationIndex;
 
-    if (!av.getWrapAlignment() || !av.isShowAnnotation() || rowIndex < 0)
+    if (column < 0 || !av.getWrapAlignment() || !av.isShowAnnotation()
+            || rowIndex < 0)
     {
       return;
     }
@@ -1028,7 +1020,7 @@ public class SeqPanel extends JPanel
 
     String msg = AnnotationPanel.getStatusMessage(av.getAlignment(), column,
             anns[rowIndex]);
-    ap.alignFrame.statusBar.setText(msg);
+    ap.alignFrame.setStatus(msg);
   }
 
   private Point lastp = null;
@@ -1163,7 +1155,7 @@ public class SeqPanel extends JPanel
 
       text.append(" (").append(Integer.toString(residuePos)).append(")");
     }
-    ap.alignFrame.statusBar.setText(text.toString());
+    ap.alignFrame.setStatus(text.toString());
   }
 
   /**
@@ -1206,9 +1198,8 @@ public class SeqPanel extends JPanel
   public void mouseDragged(MouseEvent evt)
   {
     MousePos pos = findMousePosition(evt);
-    if (pos.isOverAnnotation())
+    if (pos.isOverAnnotation() || pos.column == -1)
     {
-      // mouse is over annotation row in wrapped mode
       return;
     }
 
@@ -1307,7 +1298,7 @@ public class SeqPanel extends JPanel
 
     if (!editingSeqs)
     {
-      doMouseDraggedDefineMode(evt);
+      dragStretchGroup(evt);
       return;
     }
 
@@ -1397,7 +1388,7 @@ public class SeqPanel extends JPanel
     }
 
     message.append(Math.abs(startres - lastres) + " gaps.");
-    ap.alignFrame.statusBar.setText(message.toString());
+    ap.alignFrame.setStatus(message.toString());
 
     // Are we editing within a selection group?
     if (groupEditing || (sg != null
@@ -1777,6 +1768,7 @@ public class SeqPanel extends JPanel
   @Override
   public void mouseExited(MouseEvent e)
   {
+    ap.alignFrame.setStatus(" ");
     if (av.getWrapAlignment())
     {
       return;
@@ -1798,9 +1790,8 @@ public class SeqPanel extends JPanel
   {
     SequenceGroup sg = null;
     MousePos pos = findMousePosition(evt);
-    if (pos.isOverAnnotation())
+    if (pos.isOverAnnotation() || pos.seqIndex == -1 || pos.column == -1)
     {
-      // mouse is over annotation label in wrapped mode
       return;
     }
 
@@ -1819,7 +1810,7 @@ public class SeqPanel extends JPanel
        * find features at the position (if not gapped), or straddling
        * the position (if at a gap)
        */
-      SequenceI sequence = av.getAlignment().getSequenceAt(pos.seqIndex);// findSeq(evt));
+      SequenceI sequence = av.getAlignment().getSequenceAt(pos.seqIndex);
       List<SequenceFeature> features = seqCanvas.getFeatureRenderer()
               .findFeaturesAtColumn(sequence, column + 1);
 
@@ -1891,13 +1882,8 @@ public class SeqPanel extends JPanel
    */
   protected void doMousePressedDefineMode(MouseEvent evt, MousePos pos)
   {
-    if (pos.isOverAnnotation())
+    if (pos.isOverAnnotation() || pos.seqIndex == -1 || pos.column == -1)
     {
-      // JvOptionPane.showInternalMessageDialog(Desktop.desktop,
-      // MessageManager.getString(
-      // "label.cannot_edit_annotations_in_wrapped_view"),
-      // MessageManager.getString("label.wrapped_view_no_edit"),
-      // JvOptionPane.WARNING_MESSAGE);
       return;
     }
 
@@ -1908,11 +1894,6 @@ public class SeqPanel extends JPanel
 
     startWrapBlock = wrappedBlock;
 
-    if (seq < 0 || res < 0)
-    {
-      return;
-    }
-
     SequenceI sequence = av.getAlignment().getSequenceAt(seq);
 
     if ((sequence == null) || (res > sequence.getLength()))
@@ -2035,7 +2016,8 @@ public class SeqPanel extends JPanel
    *          true if this event is happening after a mouse drag (rather than a
    *          mouse down)
    */
-  public void doMouseReleasedDefineMode(MouseEvent evt, boolean afterDrag)
+  protected void doMouseReleasedDefineMode(MouseEvent evt,
+          boolean afterDrag)
   {
     if (stretchGroup == null)
     {
@@ -2078,17 +2060,21 @@ public class SeqPanel extends JPanel
   }
 
   /**
-   * DOCUMENT ME!
+   * Resizes the borders of a selection group depending on the direction of
+   * mouse drag
    * 
    * @param evt
-   *          DOCUMENT ME!
    */
-  public void doMouseDraggedDefineMode(MouseEvent evt)
+  protected void dragStretchGroup(MouseEvent evt)
   {
+    if (stretchGroup == null)
+    {
+      return;
+    }
+
     MousePos pos = findMousePosition(evt);
-    if (pos.isOverAnnotation())
+    if (pos.isOverAnnotation() || pos.column == -1 || pos.seqIndex == -1)
     {
-      // mouse is over annotation in wrapped mode
       return;
     }
 
@@ -2100,11 +2086,6 @@ public class SeqPanel extends JPanel
       return;
     }
 
-    if (stretchGroup == null)
-    {
-      return;
-    }
-
     if (res >= av.getAlignment().getWidth())
     {
       res = av.getAlignment().getWidth() - 1;