JAL-3383 JAL-3253-applet ScalePanel bug -- should not have to cause an
[jalview.git] / src / jalview / gui / ScalePanel.java
index 8f49c6c..aa58a88 100755 (executable)
@@ -48,13 +48,13 @@ import java.util.List;
 import javax.swing.JMenuItem;
 import javax.swing.JPanel;
 import javax.swing.JPopupMenu;
-import javax.swing.SwingUtilities;
 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
 {
@@ -123,8 +123,9 @@ public class ScalePanel extends JPanel
     if (evt.isPopupTrigger()) // Mac: mousePressed
     {
       rightMouseButtonPressed(evt, res);
+      return;
     }
-    else if (SwingUtilities.isRightMouseButton(evt) && !Platform.isAMac())
+    if (Platform.isWinRightButton(evt))
     {
       /*
        * defer right-mouse click handling to mouse up on Windows
@@ -133,10 +134,7 @@ public class ScalePanel extends JPanel
        */
       return;
     }
-    else
-    {
-      leftMouseButtonPressed(evt, res);
-    }
+    leftMouseButtonPressed(evt, res);
   }
 
   /**
@@ -190,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,10 +286,10 @@ 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();
+    int res = (xCords / av.getCharWidth()) + ranges.getStartRes();
     res = Math.min(res, ranges.getEndRes());
     if (av.hasHiddenColumns())
     {
@@ -376,6 +375,7 @@ public class ScalePanel extends JPanel
   {
     if (mouseDragging)
     {
+      mouseDragging = false;
       ap.getSeqPanel().stopScrolling();
     }
   }
@@ -436,7 +436,8 @@ public class ScalePanel extends JPanel
   @Override
   public void paintComponent(Graphics g)
   {
-    super.paintComponent(g);
+
+    // super.paintComponent(g); // BH 2019
 
     /*
      * shouldn't get called in wrapped mode as the scale above is
@@ -524,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);
         }
       }
     }
@@ -573,17 +575,32 @@ public class ScalePanel extends JPanel
     // 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();
+      // 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?
+
+      // 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();
+      System.out.println("ScalePanel propertyChange disabled "
+              + evt.getPropertyName());
+      break;
     }
   }
 
+  public boolean isMouseDragging()
+  {
+    return mouseDragging;
+  }
+
 }