JAL-3210 Improvements to eclipse detection. New src tree and SwingJS updated from...
[jalview.git] / src / jalview / gui / ScalePanel.java
index a6b4b49..b06647d 100755 (executable)
@@ -54,6 +54,7 @@ import javax.swing.ToolTipManager;
  * The panel containing the sequence ruler (when not in wrapped mode), and
  * supports a range of mouse operations to select, hide or reveal columns.
  */
+@SuppressWarnings("serial")
 public class ScalePanel extends JPanel
         implements MouseMotionListener, MouseListener, ViewportListenerI
 {
@@ -187,7 +188,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()
@@ -287,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())
     {
@@ -435,7 +436,8 @@ 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 +525,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);
         }
       }
     }
@@ -566,23 +569,36 @@ public class ScalePanel extends JPanel
   @Override
   public void propertyChange(PropertyChangeEvent evt)
   {
-    // Respond to viewport change events (e.g. alignment panel was scrolled)
-    // Both scrolling and resizing change viewport ranges: scrolling changes
-    // both start and end points, but resize only changes end values.
-    // Here we only want to fastpaint on a scroll, with resize using a normal
-    // paint, so scroll events are identified as changes to the horizontal or
-    // vertical start value.
-    if (evt.getPropertyName().equals(ViewportRanges.STARTRES)
-            || evt.getPropertyName().equals(ViewportRanges.STARTRESANDSEQ)
-            || evt.getPropertyName().equals(ViewportRanges.MOVE_VIEWPORT))
+    switch (evt.getPropertyName())
     {
+    case ViewportRanges.STARTRES:
+    case ViewportRanges.STARTRESANDSEQ:
+    case 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.
-      av.getAlignPanel().repaint();
+      // original comment:
+      // 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.
+
+      // TODO: check this?
+      // BH: This is actually quite strange. AlignmentPanel is taking care of
+      // all of this with fast paint, so why indirectly trigger a repaint from
+      // the ScalePanel? Where do we see this behavior necessary?
+      // I have set this to check for a trigger from some other ViewportRanges,
+      // but I don't actually think that is possible.
+
+      if (evt.getSource() != av.getRanges())
+      {
+        av.getAlignPanel().repaint();
+      }
+      break;
     }
   }
 
+  public boolean isMouseDragging()
+  {
+    return mouseDragging;
+  }
+
 }