Bamboo test #13
[jalview.git] / src / jalview / gui / AlignmentPanel.java
index c43e0b6..a553e65 100644 (file)
@@ -67,6 +67,8 @@ import java.io.FileWriter;
 import java.io.PrintWriter;
 import java.util.List;
 
+import javax.swing.JScrollBar;
+
 /**
  * The main panel of an AlignFrame, containing holders for the IdPanel,
  * SeqPanel, AnnotationLabels (a JPanel), and AnnotationPanel.
@@ -155,11 +157,13 @@ public class AlignmentPanel extends GAlignmentPanel implements
     hscroll.addAdjustmentListener(this);
     vscroll.addAdjustmentListener(this);
 
+
     addComponentListener(new ComponentAdapter()
     {
       @Override
       public void componentResized(ComponentEvent evt)
       {
+        System.out.println("AlignmentPanel resized " + evt);
         // reset the viewport ranges when the alignment panel is resized
         // in particular, this initialises the end residue value when Jalview
         // is initialised
@@ -178,10 +182,10 @@ public class AlignmentPanel extends GAlignmentPanel implements
                   / av.getCharHeight();
 
           ranges.setViewportWidth(widthInRes);
-          ranges.setViewportHeight(heightInSeq);
           ViewportRanges.sTest += "AP.resize chht=" + av.getCharHeight()
                   + "canvHt=" + getSeqPanel().seqCanvas.getHeight() + " "
                   + heightInSeq + "\n";
+          ranges.setViewportHeight(heightInSeq);
         }
       }
 
@@ -209,6 +213,46 @@ public class AlignmentPanel extends GAlignmentPanel implements
   }
 
   @Override
+  public void setBounds(int x, int y, int width, int height)
+  {
+    System.out.println("?AlignmentPanel.setBounds " + this.getX() + " "
+            + this.getY() + " " + this.getWidth() + " " + getHeight() + " "
+            + x + " " + y + " " + width + " " + height);
+    // BH 2020.03.23 when the Desktop changes its progress bar it re-lays out
+    // all
+    // its
+    // children, for unclear reasons. Maybe because they could be tiled?
+    if (x == this.getX() && y == this.getY() && width == this.getWidth()
+            && height == this.getHeight())
+    {
+      return;
+    }
+    System.out.println("!AlignmentPanel.setBounds " + this.getX() + " "
+            + this.getY() + " " + this.getWidth() + " " + getHeight() + " "
+            + x + " " + y + " " + width + " " + height);
+    super.setBounds(x, y, width, height);
+  }
+
+  // @Override
+  // public void reshape(int x, int y, int width, int height)
+  // {
+  // // BH 2020.03.23 when the Desktop changes its progress bar it relays out
+  // all its
+  // // children, for unclear reasons. Maybe because they could be tiled?
+  // if (x == this.getX() && y == this.getY() && width == this.getWidth()
+  // && height == this.getHeight())
+  // {
+  // return;
+  // }
+  //
+  // System.out.println("AlignmentPanel.reshape " + this.getX() + " "
+  // + this.getY() + " " + this.getWidth() + " " + getHeight() + " "
+  // + x
+  // + " " + y + " " + width + " " + height);
+  // super.reshape(x, y, width, height);
+  // }
+
+  @Override
   public AlignViewportI getAlignViewport()
   {
     return av;
@@ -646,64 +690,87 @@ public class AlignmentPanel extends GAlignmentPanel implements
    *          visible column to scroll to
    * @param y
    *          visible row to scroll to
+   *          
+   * @return true if scrollbars will fire property changes
    * 
    */
-  public void setScrollValues(int xpos, int ypos)
+  public boolean setScrollValues(int xpos, int ypos)
   {
     int x = xpos;
     int y = ypos;
 
     if (av == null || av.getAlignment() == null)
     {
-      return;
+      return false;
     }
 
     if (av.getWrapAlignment())
     {
-      setScrollingForWrappedPanel(x);
+      return setScrollingForWrappedPanel(x);
     }
-    else
+    int width = av.getAlignment().getVisibleWidth();
+    int height = av.getAlignment().getHeight();
+
+    hextent = getSeqPanel().seqCanvas.getWidth() / av.getCharWidth();
+    vextent = getSeqPanel().seqCanvas.getHeight() / av.getCharHeight();
+
+    if (hextent > width)
     {
-      int width = av.getAlignment().getVisibleWidth();
-      int height = av.getAlignment().getHeight();
+      hextent = width;
+    }
 
-      hextent = getSeqPanel().seqCanvas.getWidth() / av.getCharWidth();
-      vextent = getSeqPanel().seqCanvas.getHeight() / av.getCharHeight();
+    if (vextent > height)
+    {
+      vextent = height;
+    }
 
-      if (hextent > width)
-      {
-        hextent = width;
-      }
+    if ((hextent + x) > width)
+    {
+      x = width - hextent;
+    }
 
-      if (vextent > height)
-      {
-        vextent = height;
-      }
+    if ((vextent + y) > height)
+    {
+      y = height - vextent;
+    }
 
-      if ((hextent + x) > width)
-      {
-        x = width - hextent;
-      }
+    if (y < 0)
+    {
+      y = 0;
+    }
 
-      if ((vextent + y) > height)
-      {
-        y = height - vextent;
-      }
+    if (x < 0)
+    {
+      x = 0;
+    }
 
-      if (y < 0)
-      {
-        y = 0;
-      }
+    // update the scroll values and return true if they changed
 
-      if (x < 0)
-      {
-        x = 0;
-      }
+    return (setIfChanged(hscroll, x, hextent, 0, width)
+            + setIfChanged(vscroll, y, vextent, 0, height) != 0);
 
-      // update the scroll values
-      hscroll.setValues(x, hextent, 0, width);
-      vscroll.setValues(y, vextent, 0, height);
+  }
+
+  /**
+   * Update a horizontal or vertical scrollbar and indicate if it is actually changed
+   * (and so will be firing an AdjustmentChangedEvent)
+   * @param sb
+   * @param val
+   * @param extent
+   * @param min
+   * @praam max
+   * @return 1 if JScrollBar is changed; 0 if not
+   */
+  private int setIfChanged(JScrollBar sb, int val, int extent, int min,
+          int max)
+  {
+    if (sb.getValue() == val && sb.getModel().getExtent() == extent
+            && sb.getMinimum() == min && sb.getMaximum() == max)
+    {
+      return 0;
     }
+    sb.setValues(val, extent, min, max);
+    return 1;
   }
 
   /**
@@ -756,8 +823,8 @@ public class AlignmentPanel extends GAlignmentPanel implements
         return;
       }
 
-      ViewportRanges.sTest += "AP.valChanged chht=" + av.getCharHeight()
-              + "canvHt=" + getSeqPanel().seqCanvas.getHeight() + " "
+      ViewportRanges.sTest += "AP.adjvalChanged chht=" + av.getCharHeight()
+              + "canvHt=" + getSeqPanel().seqCanvas.getHeight() + " newHt="
               + height + "\n";
 
       ranges.setViewportStartAndHeight(y, height);
@@ -856,6 +923,20 @@ public class AlignmentPanel extends GAlignmentPanel implements
     }
   }
 
+  @Override
+  public void invalidate()
+  {
+    System.out.println("AlignmentPanel invalidate");
+    super.invalidate();
+  }
+
+  @Override
+  public void validate()
+  {
+    System.out.println("AlignmentPanel validate");
+    super.validate();
+  }
+
   /**
    * DOCUMENT ME!
    * 
@@ -866,6 +947,8 @@ public class AlignmentPanel extends GAlignmentPanel implements
   public void paintComponent(Graphics g)
   {
 
+    System.out.println("AlignmentPanel paintComponent");
+
     invalidate(); // needed so that the id width adjuster works correctly
 
     Dimension d = getIdPanel().getIdCanvas().getPreferredSize();
@@ -879,7 +962,10 @@ public class AlignmentPanel extends GAlignmentPanel implements
      * though I still think this call should be elsewhere.
      */
     ViewportRanges ranges = av.getRanges();
-    setScrollValues(ranges.getStartRes(), ranges.getStartSeq());
+    if (!setScrollValues(ranges.getStartRes(), ranges.getStartSeq()))
+    {
+      // super.paintComponent(g);
+    }
     super.paintComponent(g);
   }
 
@@ -890,7 +976,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
    * @param topLeftColumn
    *          the column position at top left (0..)
    */
-  private void setScrollingForWrappedPanel(int topLeftColumn)
+  private boolean setScrollingForWrappedPanel(int topLeftColumn)
   {
     ViewportRanges ranges = av.getRanges();
     int scrollPosition = ranges.getWrappedScrollPosition(topLeftColumn);
@@ -901,7 +987,8 @@ public class AlignmentPanel extends GAlignmentPanel implements
      * so we add extent (1) to the maxScroll value
      */
     vscroll.setUnitIncrement(1);
-    vscroll.setValues(scrollPosition, 1, 0, maxScroll + 1);
+    return (setIfChanged(vscroll, scrollPosition, 1, 0,
+            maxScroll + 1) != 0);
   }
 
   /**