JAL-244 testing without AlignFrame for --wrap
[jalview.git] / src / jalview / gui / AnnotationLabels.java
index 26276ae..afee3d0 100755 (executable)
@@ -1195,35 +1195,39 @@ public class AnnotationLabels extends JPanel
   public void drawComponent(Graphics g, boolean clip, int givenWidth)
   {
     int width = givenWidth;
-    IdwidthAdjuster iwa = ap.idwidthAdjuster;
-    if ((Cache.getDefault(ADJUST_ANNOTATION_LABELS_WIDTH_PREF, true)
-            || Jalview.isHeadlessMode()))
+    IdwidthAdjuster iwa = null;
+    if (ap != null)
     {
-      Graphics2D g2d = (Graphics2D) g;
-      Graphics dummy = g2d.create();
-      int newAnnotationIdWidth = drawLabels(dummy, clip, width, false,
-              null);
-      Dimension d = ap.calculateDefaultAlignmentIdWidth();
-      int alignmentIdWidth = d.width;
-      if (!iwa.manuallyAdjusted())
+      iwa = ap.idwidthAdjuster;
+      if ((Cache.getDefault(ADJUST_ANNOTATION_LABELS_WIDTH_PREF, true)
+              || Jalview.isHeadlessMode()))
       {
-        // If no manual adjustment to ID column with has been made then adjust
-        // width match widest of alignment or annotation id widths
-        width = Math.max(alignmentIdWidth, newAnnotationIdWidth);
-      }
-      else if (newAnnotationIdWidth != annotationIdWidth
-              && newAnnotationIdWidth > givenWidth
-              && newAnnotationIdWidth > alignmentIdWidth)
-      {
-        // otherwise if the annotation id width has become larger than the
-        // current id width, increase
-        width = newAnnotationIdWidth;
-        annotationIdWidth = newAnnotationIdWidth;
-      }
-      // set the width if it's changed
-      if (width != ap.av.getIdWidth())
-      {
-        iwa.setWidth(width);
+        Graphics2D g2d = (Graphics2D) g;
+        Graphics dummy = g2d.create();
+        int newAnnotationIdWidth = drawLabels(dummy, clip, width, false,
+                null);
+        Dimension d = ap.calculateDefaultAlignmentIdWidth();
+        int alignmentIdWidth = d.width;
+        if (iwa != null && !iwa.manuallyAdjusted())
+        {
+          // If no manual adjustment to ID column with has been made then adjust
+          // width match widest of alignment or annotation id widths
+          width = Math.max(alignmentIdWidth, newAnnotationIdWidth);
+        }
+        else if (newAnnotationIdWidth != annotationIdWidth
+                && newAnnotationIdWidth > givenWidth
+                && newAnnotationIdWidth > alignmentIdWidth)
+        {
+          // otherwise if the annotation id width has become larger than the
+          // current id width, increase
+          width = newAnnotationIdWidth;
+          annotationIdWidth = newAnnotationIdWidth;
+        }
+        // set the width if it's changed
+        if (width != ap.av.getIdWidth())
+        {
+          iwa.setWidth(width);
+        }
       }
     }
     drawLabels(g, clip, width, true, null);