JAL-244 Fixed idWidth labels in headless mode for non-wrap alignments
[jalview.git] / src / jalview / gui / AlignmentPanel.java
index 2396329..8a43a4a 100644 (file)
@@ -338,18 +338,27 @@ public class AlignmentPanel extends GAlignmentPanel implements
     // Also check annotation label widths
     if (includeAnnotations && al.getAlignmentAnnotation() != null)
     {
-      fm = c.getFontMetrics(getAlabels().getFont());
-
-      for (i = 0; i < al.getAlignmentAnnotation().length; i++)
+      if (Jalview.isHeadlessMode())
+      {
+        AnnotationLabels aal = this.getAlabels();
+        int stringWidth = aal.drawLabels(null, false, idWidth, false, fm);
+        idWidth = Math.max(idWidth, stringWidth);
+      }
+      else
       {
-        AlignmentAnnotation aa = al.getAlignmentAnnotation()[i];
-        if (visibleOnly && !aa.visible)
+        fm = c.getFontMetrics(getAlabels().getFont());
+
+        for (i = 0; i < al.getAlignmentAnnotation().length; i++)
         {
-          continue;
+          AlignmentAnnotation aa = al.getAlignmentAnnotation()[i];
+          if (visibleOnly && !aa.visible)
+          {
+            continue;
+          }
+          String label = aa.label;
+          int stringWidth = fm.stringWidth(label);
+          idWidth = Math.max(idWidth, stringWidth);
         }
-        String label = aa.label;
-        int stringWidth = fm.stringWidth(label);
-        idWidth = Math.max(idWidth, stringWidth);
       }
     }
 
@@ -581,9 +590,10 @@ public class AlignmentPanel extends GAlignmentPanel implements
     // not be called directly by programs.
     // I note that addNotify() is called in several areas of Jalview.
 
-    int annotationHeight = getAnnotationPanel().adjustPanelHeight();
-    annotationHeight = getAnnotationPanel()
-            .adjustForAlignFrame(adjustPanelHeight, annotationHeight);
+    AnnotationPanel ap = getAnnotationPanel();
+    int annotationHeight = ap.adjustPanelHeight();
+    annotationHeight = ap.adjustForAlignFrame(adjustPanelHeight,
+            annotationHeight);
 
     hscroll.addNotify();
     annotationScroller.setPreferredSize(
@@ -596,6 +606,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
             annotationSpaceFillerHolder.getWidth(), annotationHeight));
     annotationScroller.validate();
     annotationScroller.addNotify();
+    ap.validate();
   }
 
   /**
@@ -1186,6 +1197,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
     }
 
     int w = getIdPanel().getWidth();
+    w = this.calculateIdWidth(-1, true, true).width;
     return (w > 0 ? w : calculateIdWidth().width);
   }
 
@@ -1211,6 +1223,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
     final int borderBottomOffset = 5;
 
     AlignmentDimension aDimension = getAlignmentDimension();
+
     // todo use a lambda function in place of callback here?
     ImageWriterI writer = new ImageWriterI()
     {