separated alignment annotation height calculation from panel height adjustment
authorjprocter <Jim Procter>
Thu, 21 Apr 2011 14:49:48 +0000 (14:49 +0000)
committerjprocter <Jim Procter>
Thu, 21 Apr 2011 14:49:48 +0000 (14:49 +0000)
src/jalview/gui/AlignmentPanel.java
src/jalview/gui/AnnotationPanel.java

index e50b522..3ea6496 100755 (executable)
@@ -393,9 +393,17 @@ public class AlignmentPanel extends GAlignmentPanel implements
     {
       System.out.println("NEEDS FIXING");
     }
-
+    validateAnnotationDimensions(true);
+    addNotify();
+    repaint();
+  }
+  /**
+   * calculate the annotation dimensions and refresh slider values accordingly.
+   * need to do repaints/notifys afterwards. 
+   */
+  protected void validateAnnotationDimensions(boolean adjustPanelHeight) {
     int height = annotationPanel.adjustPanelHeight();
-
+    
     if (hscroll.isVisible())
     {
       height += hscroll.getPreferredSize().height;
@@ -404,17 +412,20 @@ public class AlignmentPanel extends GAlignmentPanel implements
     {
       height = alignFrame.getHeight() / 2;
     }
-
+    if (!adjustPanelHeight)
+    {
+      // maintain same window layout whilst updating sliders
+      height=annotationScroller.getSize().height;
+    }
     hscroll.addNotify();
-
+    
     annotationScroller.setPreferredSize(new Dimension(annotationScroller
             .getWidth(), height));
 
     annotationSpaceFillerHolder.setPreferredSize(new Dimension(
             annotationSpaceFillerHolder.getWidth(), height));
     annotationScroller.validate();// repaint();
-    addNotify();
-    repaint();
+    annotationScroller.addNotify();
   }
 
   /**
index 01c933a..8a93f79 100755 (executable)
@@ -132,6 +132,24 @@ public class AnnotationPanel extends JPanel implements MouseListener,
    */
   public int adjustPanelHeight()
   {
+    int height=calcPanelHeight();
+    this.setPreferredSize(new Dimension(1, height));
+    if (ap != null)
+    {
+      // revalidate only when the alignment panel is fully constructed
+      ap.validate();
+    }
+
+    return height;
+  }
+
+  /**
+   * calculate the height for visible annotation, revalidating bounds where necessary
+   * ABSTRACT GUI METHOD
+   * @return total height of annotation
+   */
+  public int calcPanelHeight()
+  {
     // setHeight of panels
     AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
     int height = 0;
@@ -180,14 +198,6 @@ public class AnnotationPanel extends JPanel implements MouseListener,
       // set minimum
       height = 20;
     }
-
-    this.setPreferredSize(new Dimension(1, height));
-    if (ap != null)
-    {
-      // revalidate only when the alignment panel is fully constructed
-      ap.validate();
-    }
-
     return height;
   }