Merge branch 'bug/JAL-2934proportionalScrolling' into develop
[jalview.git] / src / jalview / gui / AlignmentPanel.java
index c5c7ae9..8e7c745 100644 (file)
@@ -42,6 +42,7 @@ import java.io.FileWriter;
 import java.io.PrintWriter;
 import java.util.List;
 
+import javax.swing.BoundedRangeModel;
 import javax.swing.SwingUtilities;
 
 import jalview.analysis.AnnotationSorter;
@@ -298,8 +299,10 @@ public class AlignmentPanel extends GAlignmentPanel implements
   {
     return calculateIdWidth(-1, false, false);
   }
+
   /**
    * pre 2.11.3 Id width calculation - used when importing old projects only
+   * 
    * @return
    */
   public int getLegacyIdWidth()
@@ -313,7 +316,11 @@ public class AlignmentPanel extends GAlignmentPanel implements
 
   /**
    * Calculate the width of the alignment labels based on the displayed names
-   * and any bounds on label width set in preferences.
+   * and any bounds on label width set in preferences. Also includes annotations
+   * not actually visible.
+   * 
+   * FIXME JAL-244 JAL-4091 - doesn't include sequence associated annotation
+   * label decorators and only called during tests
    * 
    * @param maxwidth
    *          -1 or maximum width allowed for IdWidth
@@ -331,20 +338,27 @@ public class AlignmentPanel extends GAlignmentPanel implements
    * 
    * @param maxwidth
    *          -1 or maximum width allowed for IdWidth
-   * @param includeAnnotations - when true, annotation label widths are also accounted for
-   * @param visibleOnly - when true, ignore label widths for hidden annotation rows 
+   * @param includeAnnotations
+   *          - when true includes width of any additional marks in annotation
+   *          id panel
+   * @param visibleOnly
+   *          - when true, ignore label widths for hidden annotation rows
    * @return Dimension giving the maximum width of the alignment label panel
    *         that should be used.
    */
   public Dimension calculateIdWidth(int maxwidth,
           boolean includeAnnotations, boolean visibleOnly)
   {
-    return calculateIdWidthOrLegacy(false, maxwidth, includeAnnotations, visibleOnly);
+    return calculateIdWidthOrLegacy(false, maxwidth, includeAnnotations,
+            visibleOnly);
   }
-  
+
   /**
    * legacy mode or post 2.11.3 ID width calculation
-   * @param legacy - uses annotation labels, not rendered label width (excludes additional decorators)
+   * 
+   * @param legacy
+   *          - uses annotation labels, not rendered label width (excludes
+   *          additional decorators)
    * @param maxwidth
    * @param includeAnnotations
    * @param visibleOnly
@@ -379,7 +393,8 @@ public class AlignmentPanel extends GAlignmentPanel implements
       if (!legacy || Jalview.isHeadlessMode())
       {
         AnnotationLabels aal = getAlabels();
-        int stringWidth = aal.drawLabels(null, false, idWidth, false, false, fm);
+        int stringWidth = aal.drawLabels(null, false, idWidth, false, false,
+                fm, !visibleOnly);
         idWidth = Math.max(idWidth, stringWidth);
       }
       else
@@ -602,7 +617,8 @@ public class AlignmentPanel extends GAlignmentPanel implements
     // this is called after loading new annotation onto alignment
     if (alignFrame.getHeight() == 0)
     {
-      jalview.bin.Console.error("adjustAnnotationHeight called with zero height alignment window");
+      jalview.bin.Console.error(
+              "adjustAnnotationHeight called with zero height alignment window");
     }
     validateAnnotationDimensions(true);
     addNotify();
@@ -774,6 +790,22 @@ public class AlignmentPanel extends GAlignmentPanel implements
   }
 
   /**
+   * Answers true if the panel has no horizontal scrollbar, or the scrollbar is
+   * at its rightmost position, else false.
+   * 
+   * @return
+   */
+  boolean isScrolledFullyRight()
+  {
+    if (hscroll == null)
+    {
+      return true;
+    }
+    BoundedRangeModel model = hscroll.getModel();
+    return (model.getExtent() + model.getValue() >= model.getMaximum());
+  }
+
+  /**
    * Respond to adjustment event when horizontal or vertical scrollbar is
    * changed
    * 
@@ -1033,8 +1065,16 @@ public class AlignmentPanel extends GAlignmentPanel implements
           Graphics idGraphics, Graphics alignmentGraphics)
           throws PrinterException
   {
-    final int idWidth = getVisibleIdWidth(false);
-
+    final int idWidth, idWidthForGui;
+    // otherwise calculate it
+    idWidth = getVisibleIdWidth(false);
+    // if (getIdPanel()!=null && getIdPanel().getWidth()>0)
+    // {
+    // // use the current IdPanel's width, if its set and non-zero
+    // idWidthForGui = getIdPanel().getWidth();
+    // } else {
+    // idWidthForGui=0;
+    // }
     /*
      * Get the horizontal offset to where we draw the sequences.
      * This is idWidth if using a single Graphics context, else zero.
@@ -1083,6 +1123,9 @@ public class AlignmentPanel extends GAlignmentPanel implements
     }
     final int alignmentDrawnHeight = (endSeq - startSeq) * charHeight + 3;
 
+    alignmentGraphics.setColor(Color.white);
+    alignmentGraphics.fillRect(0, 0, pageWidth, pageHeight + scaleHeight);
+
     /*
      * draw the Scale at horizontal offset, then reset to top left (0, 0)
      */
@@ -1099,8 +1142,9 @@ public class AlignmentPanel extends GAlignmentPanel implements
     IdCanvas idCanvas = getIdPanel().getIdCanvas();
     List<SequenceI> selection = av.getSelectionGroup() == null ? null
             : av.getSelectionGroup().getSequences(null);
+
     idCanvas.drawIds((Graphics2D) idGraphics, av, startSeq, endSeq - 1,
-            selection, false);
+            selection, false, idWidth);
 
     idGraphics.setFont(av.getFont());
     idGraphics.translate(0, -scaleHeight);
@@ -1247,7 +1291,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
     // see if rendering offscreen - check preferences and calc width accordingly
     if (!onscreen && Cache.getDefault("FIGURE_AUTOIDWIDTH", false))
     {
-      return calculateIdWidth(-1).width;
+      return calculateIdWidth(-1, true, true).width;
     }
     Integer idwidth = onscreen ? null
             : Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH");
@@ -1265,7 +1309,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
           throws ImageOutputException
   {
     makeAlignmentImage(type, file, renderer,
-            BitmapImageSizing.nullBitmapImageSizing());
+            BitmapImageSizing.defaultBitmapImageSizing());
   }
 
   /**