Bamboo test #13 AlignViewport resize and jscrollbar set
[jalview.git] / src / jalview / gui / AlignmentPanel.java
index d305183..c43e0b6 100644 (file)
@@ -67,10 +67,15 @@ import java.io.FileWriter;
 import java.io.PrintWriter;
 import java.util.List;
 
-import javax.swing.SwingUtilities;
-
 /**
- * DOCUMENT ME!
+ * The main panel of an AlignFrame, containing holders for the IdPanel,
+ * SeqPanel, AnnotationLabels (a JPanel), and AnnotationPanel.
+ * 
+ * Additional holders contain an IdPanelWidthAdjuster space above the idPanel,
+ * AnnotationScroller (JScrollPane for AnnotationPanel), and vertical and
+ * horizontal scrollbars.
+ * 
+ * 
  * 
  * @author $author$
  * @version $Revision: 1.161 $
@@ -174,6 +179,9 @@ public class AlignmentPanel extends GAlignmentPanel implements
 
           ranges.setViewportWidth(widthInRes);
           ranges.setViewportHeight(heightInSeq);
+          ViewportRanges.sTest += "AP.resize chht=" + av.getCharHeight()
+                  + "canvHt=" + getSeqPanel().seqCanvas.getHeight() + " "
+                  + heightInSeq + "\n";
         }
       }
 
@@ -585,7 +593,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
    */
   public void updateLayout()
   {
-    fontChanged();
+    fontChanged(); // fires repaint
     setAnnotationVisible(av.isShowAnnotation());
     boolean wrap = av.getWrapAlignment();
     ViewportRanges ranges = av.getRanges();
@@ -739,6 +747,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
       int y = vscroll.getValue();
       int height = getSeqPanel().seqCanvas.getHeight() / av.getCharHeight();
 
+
       // if we're scrolling to the position we're already at, stop
       // this prevents infinite recursion of events when the scroll/viewport
       // ranges values are the same
@@ -746,6 +755,11 @@ public class AlignmentPanel extends GAlignmentPanel implements
       {
         return;
       }
+
+      ViewportRanges.sTest += "AP.valChanged chht=" + av.getCharHeight()
+              + "canvHt=" + getSeqPanel().seqCanvas.getHeight() + " "
+              + height + "\n";
+
       ranges.setViewportStartAndHeight(y, height);
     }
     repaint();
@@ -795,7 +809,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
       // This is only called if file loaded is a jar file that
       // was wrapped when saved and user has wrap alignment true
       // as preference setting
-      SwingUtilities.invokeLater(new Runnable()
+      Jalview.execRunnable(new Runnable()
       {
         @Override
         public void run()
@@ -835,7 +849,6 @@ public class AlignmentPanel extends GAlignmentPanel implements
     }
     if (updateOverview)
     {
-
       if (overviewPanel != null)
       {
         overviewPanel.updateOverviewImage();
@@ -852,6 +865,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
   @Override
   public void paintComponent(Graphics g)
   {
+
     invalidate(); // needed so that the id width adjuster works correctly
 
     Dimension d = getIdPanel().getIdCanvas().getPreferredSize();
@@ -1072,6 +1086,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
   public int printWrappedAlignment(int pageWidth, int pageHeight, int pageNumber,
           Graphics g) throws PrinterException
   {
+
     int annotationHeight = 0;
     if (av.isShowAnnotation())
     {
@@ -1096,6 +1111,8 @@ public class AlignmentPanel extends GAlignmentPanel implements
 
     int totalHeight = cHeight * (maxwidth / resWidth + 1);
 
+    g = g.create();
+
     g.setColor(Color.white);
     g.fillRect(0, 0, pageWidth, pageHeight);
     g.setFont(av.getFont());
@@ -1109,7 +1126,8 @@ public class AlignmentPanel extends GAlignmentPanel implements
      */
     g.translate(0, -pageNumber * pageHeight);
 
-    g.setClip(0, pageNumber * pageHeight, pageWidth, pageHeight);
+    // BH 2020.03.19 avoiding g.setClip
+    g.clipRect(0, pageNumber * pageHeight, pageWidth, pageHeight);
 
     /*
      * draw sequence ids and annotation labels (if shown)
@@ -1122,6 +1140,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
     getSeqPanel().seqCanvas.drawWrappedPanelForPrinting(g, pageWidth - idWidth,
             totalHeight, 0);
 
+    g.dispose();
     if ((pageNumber * pageHeight) < totalHeight)
     {
       return Printable.PAGE_EXISTS;
@@ -1846,4 +1865,37 @@ public class AlignmentPanel extends GAlignmentPanel implements
     overviewPanel.canvas.finalizeDraw(miniMe);
   }
 
+
+  private boolean holdRepaint = false;
+
+  public boolean getHoldRepaint()
+  {
+    return holdRepaint;
+  }
+
+  public void setHoldRepaint(boolean b)
+  {
+    if (holdRepaint == b)
+    {
+      return;
+    }
+    holdRepaint = b;
+    if (!b)
+    {
+      repaint();
+    }
+  }
+
+  @Override
+  public void repaint()
+  {
+    if (holdRepaint)
+    {
+      // System.out.println("AP repaint holding");
+      // Platform.stackTrace();
+      return;
+    }
+    super.repaint();
+  }
+
 }