Merge branch 'bug/JAL-3212columnSelectionWithHidden' into develop
[jalview.git] / src / jalview / gui / ScalePanel.java
index 714a5aa..833cd54 100755 (executable)
@@ -109,6 +109,7 @@ public class ScalePanel extends JPanel
   public void mousePressed(MouseEvent evt)
   {
     final int res = av.getAbsoluteColumn(evt.getX());
+
     min = res;
     max = res;
 
@@ -141,10 +142,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)
@@ -182,9 +200,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"));
@@ -206,8 +224,8 @@ public class ScalePanel extends JPanel
         }
       });
       pop.add(item);
-      pop.show(this, evt.getX(), evt.getY());
     }
+    return pop;
   }
 
   /**