From 657698cc9d7f3216a1c6db6902cea4911b8c24b2 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 23 Mar 2015 14:39:24 +0000 Subject: [PATCH] JAL-845 restore SplitFrame size from project; enable Find in SplitFrame --- src/jalview/gui/Jalview2XML.java | 99 +++++++++++++++++------------------- src/jalview/gui/SplitFrame.java | 53 +++++++++++++++---- src/jalview/jbgui/GSplitFrame.java | 11 ++-- 3 files changed, 99 insertions(+), 64 deletions(-) diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index ad10f5e..8beb26f 100644 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -20,6 +20,44 @@ */ package jalview.gui; +import java.awt.Rectangle; +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.IdentityHashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.StringTokenizer; +import java.util.Vector; +import java.util.jar.JarEntry; +import java.util.jar.JarInputStream; +import java.util.jar.JarOutputStream; + +import javax.swing.JInternalFrame; +import javax.swing.JOptionPane; +import javax.swing.SwingUtilities; + +import org.exolab.castor.xml.Unmarshaller; + import jalview.api.structures.JalviewStructureDisplayI; import jalview.bin.Cache; import jalview.datamodel.AlignedCodonFrame; @@ -83,44 +121,6 @@ import jalview.ws.params.ArgumentI; import jalview.ws.params.AutoCalcSetting; import jalview.ws.params.WsParamSetI; -import java.awt.Rectangle; -import java.io.BufferedReader; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.lang.reflect.InvocationTargetException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Hashtable; -import java.util.IdentityHashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.StringTokenizer; -import java.util.Vector; -import java.util.jar.JarEntry; -import java.util.jar.JarInputStream; -import java.util.jar.JarOutputStream; - -import javax.swing.JInternalFrame; -import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; - -import org.exolab.castor.xml.Unmarshaller; - /** * Write out the current jalview desktop state as a Jalview XML stream. * @@ -1056,20 +1056,14 @@ public class Jalview2XML view.setGatheredViews(av.isGatherViewsHere()); Rectangle position = ap.av.getExplodedGeometry(); - if (position != null) - { - view.setXpos(position.x); - view.setYpos(position.y); - view.setWidth(position.width); - view.setHeight(position.height); - } - else + if (position == null) { - view.setXpos(ap.alignFrame.getBounds().x); - view.setYpos(ap.alignFrame.getBounds().y); - view.setWidth(ap.alignFrame.getBounds().width); - view.setHeight(ap.alignFrame.getBounds().height); + position = ap.alignFrame.getBounds(); } + view.setXpos(position.x); + view.setYpos(position.y); + view.setWidth(position.width); + view.setHeight(position.height); view.setStartRes(av.startRes); view.setStartSeq(av.startSeq); @@ -2265,7 +2259,10 @@ public class Jalview2XML { SplitFrame splitFrame = new SplitFrame(dnaFrame, proteinFrame); String title = MessageManager.getString("label.linked_view_title"); - Desktop.addInternalFrame(splitFrame, title, -1, -1); + int width = (int) dnaFrame.getBounds().getWidth(); + int height = (int) (dnaFrame.getBounds().getHeight() + + proteinFrame.getBounds().getHeight() + 50); + Desktop.addInternalFrame(splitFrame, title, width, height); return splitFrame; } diff --git a/src/jalview/gui/SplitFrame.java b/src/jalview/gui/SplitFrame.java index 6042efc..5c4e4d2 100644 --- a/src/jalview/gui/SplitFrame.java +++ b/src/jalview/gui/SplitFrame.java @@ -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); + } } diff --git a/src/jalview/jbgui/GSplitFrame.java b/src/jalview/jbgui/GSplitFrame.java index 374972c..a377571 100644 --- a/src/jalview/jbgui/GSplitFrame.java +++ b/src/jalview/jbgui/GSplitFrame.java @@ -1,7 +1,5 @@ package jalview.jbgui; -import jalview.util.Platform; - import java.awt.Component; import java.awt.MouseInfo; import java.awt.Point; @@ -11,6 +9,8 @@ import javax.swing.JInternalFrame; import javax.swing.JSplitPane; import javax.swing.plaf.basic.BasicInternalFrameUI; +import jalview.util.Platform; + public class GSplitFrame extends JInternalFrame { private static final long serialVersionUID = 1L; @@ -45,8 +45,10 @@ public class GSplitFrame extends JInternalFrame splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topFrame, bottomFrame); splitPane.setVisible(true); - splitPane.setDividerLocation(0.5d); - splitPane.setResizeWeight(0.5d); + final double ratio = topFrame.getHeight() + / (double) (topFrame.getHeight() + bottomFrame.getHeight()); + splitPane.setDividerLocation(ratio); + splitPane.setResizeWeight(ratio); splitPane.setDividerSize(5); add(splitPane); } @@ -132,6 +134,7 @@ public class GSplitFrame extends JInternalFrame if (show) { // SplitPane needs nudging to restore 50-50 split + // TODO save/restore other ratios splitPane.setDividerLocation(0.5d); } validate(); -- 1.7.10.2