JAL-3218 allow both Hide and Reveal in scale panel popup menu
[jalview.git] / src / jalview / gui / ScalePanel.java
index b392c8f..8f49c6c 100755 (executable)
@@ -115,15 +115,7 @@ public class ScalePanel extends JPanel
     {
       x = av.getAlignment().getHiddenColumns().visibleToAbsoluteColumn(x);
     }
-
-    if (x >= av.getAlignment().getWidth())
-    {
-      res = av.getAlignment().getWidth() - 1;
-    }
-    else
-    {
-      res = x;
-    }
+    res = Math.min(x, av.getAlignment().getWidth() - 1);
 
     min = res;
     max = res;
@@ -157,10 +149,27 @@ public class ScalePanel extends JPanel
    */
   protected void rightMouseButtonPressed(MouseEvent evt, final int res)
   {
+    JPopupMenu pop = buildPopupMenu(res);
+    if (pop.getSubElements().length > 0)
+    {
+      pop.show(this, evt.getX(), evt.getY());
+    }
+  }
+
+  /**
+   * Builds a popup menu with 'Hide' or 'Reveal' options, or both, or neither
+   * 
+   * @param res
+   *          column number (0..)
+   * @return
+   */
+  protected JPopupMenu buildPopupMenu(final int res)
+  {
     JPopupMenu pop = new JPopupMenu();
 
     /*
-     * grab the hidden range in case mouseMoved nulls it
+     * logic here depends on 'reveal', set in mouseMoved;
+     * grab the hidden range in case mouseMoved nulls it later
      */
     final int[] hiddenRange = reveal;
     if (hiddenRange != null)
@@ -198,9 +207,9 @@ public class ScalePanel extends JPanel
         });
         pop.add(item);
       }
-      pop.show(this, evt.getX(), evt.getY());
     }
-    else if (av.getColumnSelection().contains(res))
+
+    if (av.getColumnSelection().contains(res))
     {
       JMenuItem item = new JMenuItem(
               MessageManager.getString("label.hide_columns"));
@@ -222,8 +231,8 @@ public class ScalePanel extends JPanel
         }
       });
       pop.add(item);
-      pop.show(this, evt.getX(), evt.getY());
     }
+    return pop;
   }
 
   /**