JAL-4345 patch and release notes
[jalview.git] / src / jalview / gui / ScalePanel.java
index a6b4b49..4a42861 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.
@@ -107,14 +107,7 @@ public class ScalePanel extends JPanel
   @Override
   public void mousePressed(MouseEvent evt)
   {
-    int x = (evt.getX() / av.getCharWidth()) + av.getRanges().getStartRes();
-    final int res;
-
-    if (av.hasHiddenColumns())
-    {
-      x = av.getAlignment().getHiddenColumns().visibleToAbsoluteColumn(x);
-    }
-    res = Math.min(x, av.getAlignment().getWidth() - 1);
+    int res = ap.getSeqPanel().findAlignmentColumn(evt);
 
     min = res;
     max = res;
@@ -187,7 +180,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()
@@ -268,6 +262,7 @@ public class ScalePanel extends JPanel
     }
     av.setSelectionGroup(sg);
     ap.paintAlignment(false, false);
+    PaintRefresher.Refresh(this, av.getSequenceSetId());
     av.sendSelection();
   }
 
@@ -284,18 +279,7 @@ public class ScalePanel extends JPanel
     mouseDragging = false;
     ap.getSeqPanel().stopScrolling();
 
-    // 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();
-    res = Math.min(res, ranges.getEndRes());
-    if (av.hasHiddenColumns())
-    {
-      res = av.getAlignment().getHiddenColumns()
-              .visibleToAbsoluteColumn(res);
-    }
-    res = Math.max(0, res);
+    int res = ap.getSeqPanel().findAlignmentColumn(evt);
 
     if (!stretchingGroup)
     {
@@ -333,6 +317,7 @@ public class ScalePanel extends JPanel
     ap.paintAlignment(false, false);
     av.isSelectionGroupChanged(true);
     av.isColSelChanged(true);
+    PaintRefresher.Refresh(ap, av.getSequenceSetId());
     av.sendSelection();
   }
 
@@ -349,14 +334,10 @@ public class ScalePanel extends JPanel
   public void mouseDragged(MouseEvent evt)
   {
     mouseDragging = true;
+    int res = ap.getSeqPanel().findAlignmentColumn(evt);
+
     ColumnSelection cs = av.getColumnSelection();
-    HiddenColumns hidden = av.getAlignment().getHiddenColumns();
 
-    int res = (evt.getX() / av.getCharWidth())
-            + av.getRanges().getStartRes();
-    res = Math.max(0, res);
-    res = hidden.visibleToAbsoluteColumn(res);
-    res = Math.min(res, av.getAlignment().getWidth() - 1);
     min = Math.min(res, min);
     max = Math.max(res, max);
 
@@ -366,6 +347,7 @@ public class ScalePanel extends JPanel
       stretchingGroup = true;
       cs.stretchGroup(res, sg, min, max);
       ap.paintAlignment(false, false);
+      PaintRefresher.Refresh(ap, av.getSequenceSetId());
     }
   }
 
@@ -407,25 +389,34 @@ public class ScalePanel extends JPanel
   {
     this.setToolTipText(null);
     reveal = null;
+    final int res = ap.getSeqPanel().findAlignmentColumn(evt);
+
+    highlightAllStructPos(res);
     if (!av.hasHiddenColumns())
     {
       return;
     }
-
-    int res = (evt.getX() / av.getCharWidth())
-            + av.getRanges().getStartRes();
-
     reveal = av.getAlignment().getHiddenColumns()
-            .getRegionWithEdgeAtRes(res);
-
-    res = av.getAlignment().getHiddenColumns().visibleToAbsoluteColumn(res);
-
+            .getRegionWithEdgeAtRes(av.getAlignment().getHiddenColumns()
+                    .absoluteToVisibleColumn(res));
+    if (reveal == null)
+    {
+      return;
+    }
     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!
    * 
@@ -435,7 +426,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
@@ -523,10 +514,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);
         }
       }
     }
@@ -577,10 +569,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();
     }
   }