JAL-244 Allow adjusting Id column width in wrap mode. Set Id column width in gui...
[jalview.git] / src / jalview / gui / IdCanvas.java
index c94dee0..d9997a0 100755 (executable)
@@ -22,6 +22,7 @@ package jalview.gui;
 
 import java.awt.BorderLayout;
 import java.awt.Color;
+import java.awt.Dimension;
 import java.awt.Font;
 import java.awt.FontMetrics;
 import java.awt.Graphics;
@@ -382,6 +383,12 @@ public class IdCanvas extends JPanel implements ViewportListenerI
   void drawIdsWrapped(Graphics2D g, AlignViewport alignViewport,
           int startSeq, int pageHeight)
   {
+    drawIdsWrapped(g, alignViewport, startSeq, pageHeight, -1);
+  }
+
+  void drawIdsWrapped(Graphics2D g, AlignViewport alignViewport,
+          int startSeq, int pageHeight, int idWidth)
+  {
     int alignmentWidth = alignViewport.getAlignment().getWidth();
     final int alheight = alignViewport.getAlignment().getHeight();
 
@@ -429,7 +436,16 @@ public class IdCanvas extends JPanel implements ViewportListenerI
       if (labels != null && alignViewport.isShowAnnotation())
       {
         g.translate(0, ypos + (alheight * charHeight));
-        labels.drawComponent(g, getWidth());
+        int getAnnotationsIdWidth = labels.drawLabels(g, false, -1, false,
+                null);
+        int thisIdWidth = idWidth < 0 ? getAnnotationsIdWidth : idWidth;
+        if (thisIdWidth > getWidth())
+        {
+          this.setPreferredSize(
+                  new Dimension(this.getHeight(), thisIdWidth));
+          this.repaint();
+        }
+        labels.drawComponent(g, false, thisIdWidth);
         g.translate(0, -ypos - (alheight * charHeight));
       }