JAL-2728 limit divider to ensure seqs visible (wip!)
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 15 Sep 2017 13:49:05 +0000 (14:49 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 15 Sep 2017 13:49:05 +0000 (14:49 +0100)
src/jalview/gui/AlignmentPanel.java
src/jalview/gui/SplitFrame.java

index 76368ed..c700635 100644 (file)
@@ -243,11 +243,6 @@ public class AlignmentPanel extends GAlignmentPanel implements
     getIdPanel().getIdCanvas().setPreferredSize(d);
     hscrollFillerPanel.setPreferredSize(d);
 
-    if (this.alignFrame.getSplitViewContainer() != null)
-    {
-      ((SplitFrame) this.alignFrame.getSplitViewContainer()).adjustLayout();
-    }
-
     repaint();
   }
 
index beb2d62..d28bb14 100644 (file)
@@ -201,8 +201,18 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI
    */
   protected void adjustDivider()
   {
-    final AlignViewport topViewport = ((AlignFrame) getTopFrame()).viewport;
-    final AlignViewport bottomViewport = ((AlignFrame) getBottomFrame()).viewport;
+    AlignFrame topFrame = (AlignFrame) getTopFrame();
+    AlignFrame bottomFrame = (AlignFrame) getBottomFrame();
+
+    /*
+     * recompute layout of top and bottom panels to reflect their
+     * actual (rather than requested) height
+     */
+    topFrame.alignPanel.adjustAnnotationHeight();
+    bottomFrame.alignPanel.adjustAnnotationHeight();
+
+    final AlignViewport topViewport = topFrame.viewport;
+    final AlignViewport bottomViewport = bottomFrame.viewport;
     final AlignmentI topAlignment = topViewport.getAlignment();
     final AlignmentI bottomAlignment = bottomViewport.getAlignment();
     boolean topAnnotations = topViewport.isShowAnnotation();
@@ -214,6 +224,33 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI
     int bottomCharHeight = bottomViewport.getViewStyle().getCharHeight();
 
     /*
+     * calculate the minimum ratio that leaves at least 
+     * two sequences visible in the top panel
+     */
+    int topPanelHeight = topFrame.getHeight();
+    int topSequencesHeight = topFrame.alignPanel.getSeqPanel().seqCanvas
+            .getHeight();
+    int topPanelMinHeight = topPanelHeight
+            - Math.max(0,
+                    topSequencesHeight - 2 * topViewport.getCharHeight());
+    int myHeight = getHeight();
+    double minRatio = topPanelMinHeight / (double) myHeight;
+
+    /*
+     * calculate the maximum ratio that leaves at least 
+     * two sequences visible in the bottom panel
+     */
+    int bottomPanelHeight = bottomFrame.getHeight();
+    int bottomSequencesHeight = bottomFrame.alignPanel.getSeqPanel().seqCanvas
+            .getHeight();
+    int bottomPanelMinHeight = bottomPanelHeight
+            - Math.max(
+                    0,
+                    bottomSequencesHeight - 2
+                            * bottomViewport.getCharHeight());
+    double maxRatio = (myHeight - bottomPanelMinHeight) / (double) myHeight;
+
+    /*
      * estimate ratio of (topFrameContent / bottomFrameContent)
      */
     int insets = Platform.isAMac() ? MAC_INSETS_HEIGHT
@@ -223,14 +260,15 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI
             + (topAnnotations ? topViewport.calcPanelHeight() : 0);
     int bottomHeight = insets + (3 + bottomCount) * bottomCharHeight
             + (bottomAnnotations ? bottomViewport.calcPanelHeight() : 0);
-    double ratio = ((double) topHeight) / (topHeight + bottomHeight);
+    double ratio = ((double) topHeight)
+            / (double) (topHeight + bottomHeight);
 
     /*
-     * limit to 0.2 <= ratio <= 0.8 to avoid concealing all sequences
+     * limit ratio to avoid concealing all sequences
      */
-    ratio = Math.min(ratio, 0.8d);
-    ratio = Math.max(ratio, 0.2d);
-    setRelativeDividerLocation(ratio);
+    ratio = Math.min(ratio, maxRatio);
+    ratio = Math.max(ratio, minRatio);
+    // setRelativeDividerLocation(ratio);
   }
 
   /**