JAL-192 show reference sequence position and residue in ruler
[jalview.git] / src / jalview / gui / ScalePanel.java
index 41de58f..61f1b36 100755 (executable)
@@ -39,7 +39,6 @@ import java.awt.event.MouseMotionListener;
 import javax.swing.JMenuItem;
 import javax.swing.JPanel;
 import javax.swing.JPopupMenu;
-import javax.swing.SwingUtilities;
 import javax.swing.ToolTipManager;
 
 /**
@@ -107,7 +106,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
     min = res;
     max = res;
 
-    if (SwingUtilities.isRightMouseButton(evt))
+    if (evt.isPopupTrigger())
     {
       rightMouseButtonPressed(evt, res);
     }
@@ -504,14 +503,45 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
     }
 
     String string;
-    int maxX = 0;
-
+    boolean isrgap = false;
+    char rc;
+    int maxX = 0, refN, iadj;
+    SequenceI refSeq = av.getAlignment().getSeqrep();
+    int refSp = -1, refEp = -1;
+    if (refSeq != null)
+    {
+      refSp = refSeq.findIndex(refSeq.getStart()) - 1;
+      refEp = refSeq.findIndex(refSeq.getEnd()) - 1;
+    }
+    // todo: add a 'reference origin column' to set column number relative to
     for (int i = scalestartx; i < endx; i += 5)
     {
       if ((i % 10) == 0)
       {
-        string = String.valueOf(av.getColumnSelection()
-                .adjustForHiddenColumns(i));
+        iadj = av.getColumnSelection().adjustForHiddenColumns(i) - 1;
+        if (refSeq == null)
+        {
+          string = String.valueOf(iadj);
+        }
+        else
+        {
+          refN = refSeq.findPosition(iadj);
+          // TODO show bounds if position is a gap
+          // - ie L--R -> "1L|2R" for
+          // marker
+          if (iadj < refSp)
+          {
+            string = String.valueOf(iadj - refSp);
+          }
+          else if (iadj > refEp)
+          {
+            string = "+" + String.valueOf(iadj - refEp);
+          }
+          else
+          {
+            string = String.valueOf(refN) + refSeq.getCharAt(iadj);
+          }
+        }
         if ((i - startx - 1) * avCharWidth > maxX)
         {
           gg.drawString(string, (i - startx - 1) * avCharWidth, y);