separated alignment annotation height calculation from panel height adjustment
[jalview.git] / src / jalview / gui / AlignmentPanel.java
index 74f6911..3ea6496 100755 (executable)
@@ -27,6 +27,7 @@ import java.awt.event.*;
 import java.awt.print.*;
 import javax.swing.*;
 
+import jalview.api.AlignmentViewPanel;
 import jalview.bin.Cache;
 import jalview.datamodel.*;
 import jalview.jbgui.*;
@@ -40,7 +41,7 @@ import jalview.structure.SelectionSource;
  * @version $Revision$
  */
 public class AlignmentPanel extends GAlignmentPanel implements
-        AdjustmentListener, Printable
+        AdjustmentListener, Printable, AlignmentViewPanel
 {
   public AlignViewport av;
 
@@ -366,10 +367,9 @@ public class AlignmentPanel extends GAlignmentPanel implements
   }
 
   /**
-   * DOCUMENT ME!
    * 
-   * @param b
-   *          DOCUMENT ME!
+   * @param b Hide or show annotation panel
+   *          
    */
   public void setAnnotationVisible(boolean b)
   {
@@ -381,6 +381,10 @@ public class AlignmentPanel extends GAlignmentPanel implements
     repaint();
   }
 
+  /**
+   * automatically adjust annotation panel height for new annotation
+   * whilst ensuring the alignment is still visible.
+   */
   public void adjustAnnotationHeight()
   {
     // TODO: display vertical annotation scrollbar if necessary
@@ -389,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;
@@ -400,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();
   }
 
   /**
@@ -1039,6 +1054,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
       if (System.getProperty("java.awt.headless") != null
               && System.getProperty("java.awt.headless").equals("true"))
       {
+        // TODO: JAL-244
         width = alignFrame.getWidth() - vscroll.getPreferredSize().width
                 - alignFrame.getInsets().left
                 - alignFrame.getInsets().right;
@@ -1398,4 +1414,35 @@ public class AlignmentPanel extends GAlignmentPanel implements
     oldrfs.clear();
     adjustAnnotationHeight();
   }
+
+  @Override
+  public AlignmentI getAlignment()
+  {
+    return av.alignment;
+  }
+
+  /**
+   * get the name for this view
+   * @return 
+   */
+  public String getViewName()
+  {
+    return av.viewName;
+  }
+
+  /**
+   * Make/Unmake this alignment panel the current input focus
+   * @param b
+   */
+  public void setSelected(boolean b)
+  {
+    try {
+      alignFrame.setSelected(b);
+      } catch (Exception ex) {};
+      
+    if (b)
+    {
+      alignFrame.setDisplayedView(this);
+    } 
+  }
 }