JAL-1799 equivalent logic in applet
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 6 Jul 2015 08:01:52 +0000 (09:01 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 6 Jul 2015 08:01:52 +0000 (09:01 +0100)
src/jalview/appletgui/AlignFrame.java
src/jalview/appletgui/AlignmentPanel.java

index eaf93c2..075f0d2 100644 (file)
@@ -928,6 +928,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
         aa.visible = visible;
     }
     alignPanel.validateAnnotationDimensions(true);
+    validate();
+    repaint();
   }
 
   private void setAnnotationSortOrder(SequenceAnnotationOrder order)
index 0516533..f321581 100644 (file)
  */
 package jalview.appletgui;
 
+import jalview.analysis.AnnotationSorter;
+import jalview.api.AlignViewportI;
+import jalview.api.AlignmentViewPanel;
+import jalview.bin.JalviewLite;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SearchResults;
+import jalview.datamodel.SequenceI;
+import jalview.structure.StructureSelectionManager;
+
 import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Dimension;
@@ -34,15 +43,6 @@ import java.awt.event.ComponentAdapter;
 import java.awt.event.ComponentEvent;
 import java.util.List;
 
-import jalview.analysis.AnnotationSorter;
-import jalview.api.AlignViewportI;
-import jalview.api.AlignmentViewPanel;
-import jalview.bin.JalviewLite;
-import jalview.datamodel.AlignmentI;
-import jalview.datamodel.SearchResults;
-import jalview.datamodel.SequenceI;
-import jalview.structure.StructureSelectionManager;
-
 public class AlignmentPanel extends Panel implements AdjustmentListener,
         AlignmentViewPanel
 {
@@ -552,70 +552,64 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
   }
 
   /**
-   * calculate the annotation dimensions and refresh slider values accordingly.
-   * need to do repaints/notifys afterwards.
+   * Calculate the annotation dimensions and refresh slider values accordingly.
+   * Need to do repaints/notifys afterwards.
    */
   protected void validateAnnotationDimensions(boolean adjustPanelHeight)
   {
-    boolean modified = false;
-    int height = av.calcPanelHeight();
-    int minsize = 0;
+    int rowHeight = av.getCharHeight();
+    int alignmentHeight = rowHeight * av.getAlignment().getHeight();
+    int annotationHeight = av.calcPanelHeight();
+
+    int mheight = annotationHeight;
+    Dimension d = sequenceHolderPanel.getSize();
+
+    int availableHeight = d.height - scalePanelHolder.getSize().height;
     if (hscroll.isVisible())
     {
-      height += (minsize = hscroll.getPreferredSize().height);
-    }
-    if (apvscroll.isVisible())
-    {
-      minsize += apvscroll.getPreferredSize().height;
+      availableHeight -= hscroll.getPreferredSize().height;
     }
-    int mheight = height;
-    Dimension d = sequenceHolderPanel.getSize(), e = idPanel.getSize();
-    int seqandannot = d.height - scalePanelHolder.getSize().height;
 
     if (adjustPanelHeight)
     {
-      // NOTE: this logic is different in the application. Need a better
-      // algorithm to define behaviour
-      // sets initial preferred height
-      // try and set height according to alignment
-      float sscaling = (float) ((av.getCharHeight() * av.getAlignment()
-              .getHeight()) / (1.0 * mheight));
-      if (sscaling > 0.5)
-      {
-        // if the alignment is too big then
-        // default is 0.5 split
-        height = seqandannot / 2;
-      }
-      else
+      /*
+       * If not enough vertical space, maximize annotation height while keeping
+       * at least two rows of alignment visible
+       */
+      if (annotationHeight + alignmentHeight > availableHeight)
       {
-        // otherwise just set the panel so that one row of sequence is visible
-        height = -av.getCharHeight() * 1
-                + (int) (seqandannot * (1 - sscaling));
+        annotationHeight = Math.min(annotationHeight, availableHeight - 2
+                * rowHeight);
       }
     }
     else
     {
       // maintain same window layout whilst updating sliders
-      height = annotationPanelHolder.getSize().height;
+      annotationHeight = annotationPanelHolder.getSize().height;
     }
 
-    if (seqandannot - height < 5)
+    if (availableHeight - annotationHeight < 5)
     {
-      height = seqandannot;
+      annotationHeight = availableHeight;
     }
-    annotationPanel.setSize(new Dimension(d.width, height));
-    alabels.setSize(new Dimension(e.width, height));
-    annotationSpaceFillerHolder.setSize(new Dimension(e.width, height));
-    annotationPanelHolder.setSize(new Dimension(d.width, height));
+
+    annotationPanel.setSize(new Dimension(d.width, annotationHeight));
+    annotationPanelHolder.setSize(new Dimension(d.width, annotationHeight));
     // seqPanelHolder.setSize(d.width, seqandannot - height);
     seqPanel.seqCanvas
             .setSize(d.width, seqPanel.seqCanvas.getSize().height);
+
+    Dimension e = idPanel.getSize();
+    alabels.setSize(new Dimension(e.width, annotationHeight));
+    annotationSpaceFillerHolder.setSize(new Dimension(e.width,
+            annotationHeight));
+
     int s = apvscroll.getValue();
-    if (s > mheight - height)
+    if (s > mheight - annotationHeight)
     {
       s = 0;
     }
-    apvscroll.setValues(s, height, 0, mheight);
+    apvscroll.setValues(s, annotationHeight, 0, mheight);
     annotationPanel.setScrollOffset(apvscroll.getValue(), false);
     alabels.setScrollOffset(apvscroll.getValue(), false);
   }