JAL-4134 repaint the tree or alignment view(s) when column selections change
[jalview.git] / src / jalview / gui / ScalePanel.java
index bb15bd2..422601d 100755 (executable)
  */
 package jalview.gui;
 
-import jalview.datamodel.ColumnSelection;
-import jalview.datamodel.HiddenColumns;
-import jalview.datamodel.SequenceGroup;
-import jalview.renderer.ScaleRenderer;
-import jalview.renderer.ScaleRenderer.ScaleMark;
-import jalview.util.MessageManager;
-import jalview.util.Platform;
-import jalview.viewmodel.ViewportListenerI;
-import jalview.viewmodel.ViewportRanges;
-
 import java.awt.Color;
 import java.awt.FontMetrics;
 import java.awt.Graphics;
@@ -50,6 +40,16 @@ import javax.swing.JPanel;
 import javax.swing.JPopupMenu;
 import javax.swing.ToolTipManager;
 
+import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.HiddenColumns;
+import jalview.datamodel.SequenceGroup;
+import jalview.renderer.ScaleRenderer;
+import jalview.renderer.ScaleRenderer.ScaleMark;
+import jalview.util.MessageManager;
+import jalview.util.Platform;
+import jalview.viewmodel.ViewportListenerI;
+import jalview.viewmodel.ViewportRanges;
+
 /**
  * The panel containing the sequence ruler (when not in wrapped mode), and
  * supports a range of mouse operations to select, hide or reveal columns.
@@ -114,15 +114,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;
@@ -154,10 +146,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)
@@ -178,7 +187,8 @@ public class ScalePanel extends JPanel
       });
       pop.add(item);
 
-      if (av.getAlignment().getHiddenColumns().hasMultiHiddenColumnRegions())
+      if (av.getAlignment().getHiddenColumns()
+              .hasMultiHiddenColumnRegions())
       {
         item = new JMenuItem(MessageManager.getString("action.reveal_all"));
         item.addActionListener(new ActionListener()
@@ -195,9 +205,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"));
@@ -219,8 +229,8 @@ public class ScalePanel extends JPanel
         }
       });
       pop.add(item);
-      pop.show(this, evt.getX(), evt.getY());
     }
+    return pop;
   }
 
   /**
@@ -259,6 +269,7 @@ public class ScalePanel extends JPanel
     }
     av.setSelectionGroup(sg);
     ap.paintAlignment(false, false);
+    PaintRefresher.Refresh(this,av.getSequenceSetId());
     av.sendSelection();
   }
 
@@ -278,8 +289,7 @@ public class ScalePanel extends JPanel
     // todo res calculation should be a method on AlignViewport
     int xCords = Math.max(0, evt.getX()); // prevent negative X coordinates
     ViewportRanges ranges = av.getRanges();
-    int res = (xCords / av.getCharWidth())
-            + ranges.getStartRes();
+    int res = (xCords / av.getCharWidth()) + ranges.getStartRes();
     res = Math.min(res, ranges.getEndRes());
     if (av.hasHiddenColumns())
     {
@@ -324,6 +334,7 @@ public class ScalePanel extends JPanel
     ap.paintAlignment(false, false);
     av.isSelectionGroupChanged(true);
     av.isColSelChanged(true);
+    PaintRefresher.Refresh(ap, av.getSequenceSetId());
     av.sendSelection();
   }
 
@@ -357,6 +368,7 @@ public class ScalePanel extends JPanel
       stretchingGroup = true;
       cs.stretchGroup(res, sg, min, max);
       ap.paintAlignment(false, false);
+      PaintRefresher.Refresh(ap, av.getSequenceSetId());
     }
   }
 
@@ -400,6 +412,9 @@ public class ScalePanel extends JPanel
     reveal = null;
     if (!av.hasHiddenColumns())
     {
+      int res = (evt.getX() / av.getCharWidth())
+              + av.getRanges().getStartRes();
+      highlightAllStructPos(res);
       return;
     }
 
@@ -410,13 +425,21 @@ public class ScalePanel extends JPanel
             .getRegionWithEdgeAtRes(res);
 
     res = av.getAlignment().getHiddenColumns().visibleToAbsoluteColumn(res);
-
+    highlightAllStructPos(res);
     ToolTipManager.sharedInstance().registerComponent(this);
     this.setToolTipText(
             MessageManager.getString("label.reveal_hidden_columns"));
     repaint();
   }
 
+  public void highlightAllStructPos(int col)
+  {
+    ap.getStructureSelectionManager().highlightPositionsOnMany(
+            ap.av.getAlignment().getSequencesArray(), new int[]
+            { col, col }, ap);
+
+  }
+
   /**
    * DOCUMENT ME!
    * 
@@ -426,7 +449,7 @@ public class ScalePanel extends JPanel
   @Override
   public void paintComponent(Graphics g)
   {
-    //super.paintComponent(g);  // BH 2019
+    // super.paintComponent(g); // BH 2019
 
     /*
      * shouldn't get called in wrapped mode as the scale above is
@@ -514,10 +537,11 @@ public class ScalePanel extends JPanel
 
           gg.fillPolygon(
                   new int[]
-          { -1 + res * avCharWidth - avCharHeight / 4,
-              -1 + res * avCharWidth + avCharHeight / 4,
-              -1 + res * avCharWidth }, new int[]
-          { y, y, y + 2 * yOf }, 3);
+                  { -1 + res * avCharWidth - avCharHeight / 4,
+                      -1 + res * avCharWidth + avCharHeight / 4,
+                      -1 + res * avCharWidth },
+                  new int[]
+                  { y, y, y + 2 * yOf }, 3);
         }
       }
     }
@@ -568,10 +592,11 @@ public class ScalePanel extends JPanel
             || evt.getPropertyName().equals(ViewportRanges.MOVE_VIEWPORT))
     {
       // scroll event, repaint panel
-       
-       // Call repaint on alignment panel so that repaints from other alignment
-    // panel components can be aggregated. Otherwise performance of the overview
-    // window and others may be adversely affected.
+
+      // Call repaint on alignment panel so that repaints from other alignment
+      // panel components can be aggregated. Otherwise performance of the
+      // overview
+      // window and others may be adversely affected.
       av.getAlignPanel().repaint();
     }
   }