JAL-845 restore SplitFrame size from project; enable Find in SplitFrame
[jalview.git] / src / jalview / gui / SplitFrame.java
index 6042efc..5c4e4d2 100644 (file)
@@ -1,13 +1,5 @@
 package jalview.gui;
 
-import jalview.api.SplitContainerI;
-import jalview.api.ViewStyleI;
-import jalview.datamodel.AlignmentI;
-import jalview.jbgui.GAlignFrame;
-import jalview.jbgui.GSplitFrame;
-import jalview.structure.StructureSelectionManager;
-import jalview.viewmodel.AlignmentViewport;
-
 import java.awt.Component;
 import java.awt.Toolkit;
 import java.awt.event.ActionEvent;
@@ -26,6 +18,14 @@ import javax.swing.KeyStroke;
 import javax.swing.event.InternalFrameAdapter;
 import javax.swing.event.InternalFrameEvent;
 
+import jalview.api.SplitContainerI;
+import jalview.api.ViewStyleI;
+import jalview.datamodel.AlignmentI;
+import jalview.jbgui.GAlignFrame;
+import jalview.jbgui.GSplitFrame;
+import jalview.structure.StructureSelectionManager;
+import jalview.viewmodel.AlignmentViewport;
+
 /**
  * An internal frame on the desktop that hosts a horizontally split view of
  * linked DNA and Protein alignments. Additional views can be created in linked
@@ -61,7 +61,13 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI
     ((AlignFrame) getTopFrame()).getViewport().setCodingComplement(
             ((AlignFrame) getBottomFrame()).getViewport());
 
-    setSize(AlignFrame.DEFAULT_WIDTH, Desktop.instance.getHeight() - 20);
+    int width = ((AlignFrame) getTopFrame()).getWidth();
+    // about 50 pixels for the SplitFrame's title bar etc
+    int height = ((AlignFrame) getTopFrame()).getHeight()
+            + ((AlignFrame) getBottomFrame()).getHeight() + 50;
+    height = Math.min(height, Desktop.instance.getHeight() - 20);
+    // setSize(AlignFrame.DEFAULT_WIDTH, Desktop.instance.getHeight() - 20);
+    setSize(width, height);
 
     adjustLayout();
 
@@ -263,6 +269,7 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI
    */
   protected void overrideImplementedKeyBindings()
   {
+    overrideFind();
     overrideNewView();
     overrideCloseView();
     overrideExpandViews();
@@ -600,5 +607,33 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI
     }
     super.setComplementVisible(alignFrame, show);
   }
+
+  /**
+   * Replace Cmd-F Find action with our version. This is necessary because the
+   * 'default' Finder searches in the first AlignFrame it finds. We need it to
+   * search in the half of the SplitFrame that has the mouse.
+   */
+  protected void overrideFind()
+  {
+    /*
+     * Ctrl-F / Cmd-F open Finder dialog, 'focused' on the right alignment
+     */
+    KeyStroke key_cmdF = KeyStroke.getKeyStroke(KeyEvent.VK_F, Toolkit
+            .getDefaultToolkit().getMenuShortcutKeyMask(), false);
+    AbstractAction action = new AbstractAction()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        Component c = getFrameAtMouse();
+        if (c != null && c instanceof AlignFrame)
+        {
+          AlignFrame af = (AlignFrame) c;
+          new Finder(af.viewport, af.alignPanel);
+        }
+      }
+    };
+    overrideKeyBinding(key_cmdF, action);
+  }
 }