JAL-845 SplitFrame for "show product" and after aligning from SplitFrame
[jalview.git] / src / jalview / gui / SplitFrame.java
index e441371..81a6ddc 100644 (file)
@@ -52,6 +52,14 @@ public class SplitFrame extends GSplitFrame
    */
   protected void init()
   {
+    getTopFrame().setSplitFrame(this);
+    getBottomFrame().setSplitFrame(this);
+    getTopFrame().setVisible(true);
+    getBottomFrame().setVisible(true);
+
+    ((AlignFrame) getTopFrame()).getViewport().setCodingComplement(
+            ((AlignFrame) getBottomFrame()).getViewport());
+
     setSize(AlignFrame.DEFAULT_WIDTH, Desktop.instance.getHeight() - 20);
 
     adjustLayout();
@@ -61,6 +69,22 @@ public class SplitFrame extends GSplitFrame
     addKeyListener();
 
     addKeyBindings();
+
+    addCommandListeners();
+  }
+
+  /**
+   * Set the top and bottom frames to listen to each others Commands (e.g. Edit,
+   * Order).
+   */
+  protected void addCommandListeners()
+  {
+    // TODO if CommandListener is only ever 1:1 for complementary views,
+    // may change broadcast pattern to direct messaging (more efficient)
+    final StructureSelectionManager ssm = StructureSelectionManager
+            .getStructureSelectionManager(Desktop.instance);
+    ssm.addCommandListener(((AlignFrame) getTopFrame()).getViewport());
+    ssm.addCommandListener(((AlignFrame) getBottomFrame()).getViewport());
   }
 
   /**
@@ -74,8 +98,14 @@ public class SplitFrame extends GSplitFrame
     int w1 = ((AlignFrame) getTopFrame()).getViewport().getIdWidth();
     int w2 = ((AlignFrame) getBottomFrame()).getViewport().getIdWidth();
     int w3 = Math.max(w1, w2);
-    ((AlignFrame) getTopFrame()).getViewport().setIdWidth(w3);
-    ((AlignFrame) getBottomFrame()).getViewport().setIdWidth(w3);
+    if (w1 != w3)
+    {
+      ((AlignFrame) getTopFrame()).getViewport().setIdWidth(w3);
+    }
+    if (w2 != w3)
+    {
+      ((AlignFrame) getBottomFrame()).getViewport().setIdWidth(w3);
+    }
 
     /*
      * Set the character width for protein to 3 times that for dna.