JAL-845 fix bug in 3-to-1 scaling of protein from cDNA
[jalview.git] / src / jalview / gui / SplitFrame.java
index 81a6ddc..6042efc 100644 (file)
@@ -1,5 +1,6 @@
 package jalview.gui;
 
+import jalview.api.SplitContainerI;
 import jalview.api.ViewStyleI;
 import jalview.datamodel.AlignmentI;
 import jalview.jbgui.GAlignFrame;
@@ -37,7 +38,7 @@ import javax.swing.event.InternalFrameEvent;
  * @author gmcarstairs
  *
  */
-public class SplitFrame extends GSplitFrame
+public class SplitFrame extends GSplitFrame implements SplitContainerI
 {
   private static final long serialVersionUID = 1L;
 
@@ -90,7 +91,7 @@ public class SplitFrame extends GSplitFrame
   /**
    * Do any tweaking and twerking of the layout wanted.
    */
-  private void adjustLayout()
+  public void adjustLayout()
   {
     /*
      * Ensure sequence ids are the same width for good alignment.
@@ -110,19 +111,24 @@ public class SplitFrame extends GSplitFrame
     /*
      * Set the character width for protein to 3 times that for dna.
      */
-    final AlignViewport topViewport = ((AlignFrame) getTopFrame()).viewport;
-    final AlignViewport bottomViewport = ((AlignFrame) getBottomFrame()).viewport;
-    final AlignmentI topAlignment = topViewport.getAlignment();
-    final AlignmentI bottomAlignment = bottomViewport.getAlignment();
-    AlignmentViewport cdna = topAlignment.isNucleotide() ? topViewport
-            : (bottomAlignment.isNucleotide() ? bottomViewport : null);
-    AlignmentViewport protein = !topAlignment.isNucleotide() ? topViewport
-            : (!bottomAlignment.isNucleotide() ? bottomViewport : null);
-    if (protein != null && cdna != null)
+    boolean scaleThreeToOne = true; // TODO a new Preference option?
+    if (scaleThreeToOne)
     {
-      ViewStyleI vs = cdna.getViewStyle();
-      vs.setCharWidth(3 * vs.getCharWidth());
-      protein.setViewStyle(vs);
+      final AlignViewport topViewport = ((AlignFrame) getTopFrame()).viewport;
+      final AlignViewport bottomViewport = ((AlignFrame) getBottomFrame()).viewport;
+      final AlignmentI topAlignment = topViewport.getAlignment();
+      final AlignmentI bottomAlignment = bottomViewport.getAlignment();
+      AlignmentViewport cdna = topAlignment.isNucleotide() ? topViewport
+              : (bottomAlignment.isNucleotide() ? bottomViewport : null);
+      AlignmentViewport protein = !topAlignment.isNucleotide() ? topViewport
+              : (!bottomAlignment.isNucleotide() ? bottomViewport : null);
+      if (protein != null && cdna != null)
+      {
+        ViewStyleI vs = cdna.getViewStyle();
+        ViewStyleI vs2 = protein.getViewStyle();
+        vs2.setCharWidth(3 * vs.getCharWidth());
+        protein.setViewStyle(vs2);
+      }
     }
   }
 
@@ -540,4 +546,59 @@ public class SplitFrame extends GSplitFrame
   {
     Desktop.instance.gatherViews(this);
   }
+
+  /**
+   * Returns the alignment in the complementary frame to the one given.
+   */
+  @Override
+  public AlignmentI getComplement(Object alignFrame)
+  {
+    if (alignFrame == this.getTopFrame())
+    {
+      return ((AlignFrame) getBottomFrame()).viewport.getAlignment();
+    }
+    else if (alignFrame == this.getBottomFrame())
+    {
+      return ((AlignFrame) getTopFrame()).viewport.getAlignment();
+    }
+    return null;
+  }
+
+  /**
+   * Returns the title of the complementary frame to the one given.
+   */
+  @Override
+  public String getComplementTitle(Object alignFrame)
+  {
+    if (alignFrame == this.getTopFrame())
+    {
+      return ((AlignFrame) getBottomFrame()).getTitle();
+    }
+    else if (alignFrame == this.getBottomFrame())
+    {
+      return ((AlignFrame) getTopFrame()).getTitle();
+    }
+    return null;
+  }
+
+  /**
+   * Set the 'other half' to hidden / revealed.
+   */
+  @Override
+  public void setComplementVisible(Object alignFrame, boolean show)
+  {
+    /*
+     * Hiding the AlignPanel suppresses unnecessary repaints
+     */
+    if (alignFrame == getTopFrame())
+    {
+      ((AlignFrame) getBottomFrame()).alignPanel.setVisible(show);
+    }
+    else if (alignFrame == getBottomFrame())
+    {
+      ((AlignFrame) getTopFrame()).alignPanel.setVisible(show);
+    }
+    super.setComplementVisible(alignFrame, show);
+  }
 }
+