Bamboo test #13 AlignViewport resize and jscrollbar set
[jalview.git] / src / jalview / gui / AlignmentPanel.java
index f723794..c43e0b6 100644 (file)
@@ -56,6 +56,7 @@ import java.awt.event.AdjustmentEvent;
 import java.awt.event.AdjustmentListener;
 import java.awt.event.ComponentAdapter;
 import java.awt.event.ComponentEvent;
+import java.awt.image.BufferedImage;
 import java.awt.print.PageFormat;
 import java.awt.print.Printable;
 import java.awt.print.PrinterException;
@@ -66,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 $
@@ -136,7 +142,11 @@ public class AlignmentPanel extends GAlignmentPanel implements
 
     annotationScroller.setViewportView(getAnnotationPanel());
     annotationSpaceFillerHolder.add(getAlabels(), BorderLayout.CENTER);
-
+    if (!av.isShowAnnotation())
+    {
+      annotationScroller.setVisible(false);
+      annotationSpaceFillerHolder.setVisible(false);
+    }
     scalePanelHolder.add(getScalePanel(), BorderLayout.CENTER);
     seqPanelHolder.add(getSeqPanel(), BorderLayout.CENTER);
 
@@ -169,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";
         }
       }
 
@@ -580,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();
@@ -734,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
@@ -741,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();
@@ -790,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()
@@ -830,7 +849,6 @@ public class AlignmentPanel extends GAlignmentPanel implements
     }
     if (updateOverview)
     {
-
       if (overviewPanel != null)
       {
         overviewPanel.updateOverviewImage();
@@ -847,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();
@@ -1067,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())
     {
@@ -1091,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());
@@ -1104,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)
@@ -1117,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;
@@ -1835,4 +1859,43 @@ public class AlignmentPanel extends GAlignmentPanel implements
     return true;
   }
 
+  @Override
+  public void overviewDone(BufferedImage miniMe)
+  {
+    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();
+  }
+
 }