package jalview.jbgui;
+import jalview.util.Platform;
+
+import java.awt.Component;
+import java.awt.MouseInfo;
+import java.awt.Point;
+import java.awt.Rectangle;
+
import javax.swing.JInternalFrame;
import javax.swing.JSplitPane;
+import javax.swing.plaf.basic.BasicInternalFrameUI;
public class GSplitFrame extends JInternalFrame
{
private GAlignFrame bottomFrame;
+ private JSplitPane splitPane;
+
/**
* Constructor
*
{
this.topFrame = top;
this.bottomFrame = bottom;
- JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, top,
- bottom);
+
+ hideTitleBars();
+
+ addSplitPane();
+ }
+
+ /**
+ * Create and add the split pane containing the top and bottom components.
+ */
+ protected void addSplitPane()
+ {
+ splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topFrame,
+ bottomFrame);
splitPane.setVisible(true);
- add(splitPane);
splitPane.setDividerLocation(0.5d);
splitPane.setResizeWeight(0.5d);
splitPane.setDividerSize(0);
+ add(splitPane);
+ }
+
+ /**
+ * Try to hide the title bars as a waste of precious space.
+ *
+ * @see http
+ * ://stackoverflow.com/questions/7218971/java-method-works-on-windows
+ * -but-not-macintosh -java
+ */
+ protected void hideTitleBars()
+ {
+ if (new Platform().isAMac())
+ {
+ // this saves some space - but doesn't hide the title bar
+ topFrame.putClientProperty("JInternalFrame.isPalette", true);
+ // topFrame.getRootPane().putClientProperty("Window.style", "small");
+ bottomFrame.putClientProperty("JInternalFrame.isPalette", true);
+ }
+ else
+ {
+ ((BasicInternalFrameUI) topFrame.getUI()).setNorthPane(null);
+ ((BasicInternalFrameUI) bottomFrame.getUI()).setNorthPane(null);
+ }
}
public GAlignFrame getTopFrame()
{
return bottomFrame;
}
+
+ /**
+ * Returns the split pane component the mouse is in, or null if neither.
+ *
+ * @return
+ */
+ protected GAlignFrame getFrameAtMouse()
+ {
+ Point loc = MouseInfo.getPointerInfo().getLocation();
+
+ if (isIn(loc, splitPane.getTopComponent()))
+ {
+ return getTopFrame();
+ }
+ else if (isIn(loc, splitPane.getBottomComponent()))
+ {
+ return getBottomFrame();
+ }
+ return null;
+ }
+
+ private boolean isIn(Point loc, Component comp)
+ {
+ Point p = comp.getLocationOnScreen();
+ Rectangle r = new Rectangle(p.x, p.y, comp.getWidth(), comp.getHeight());
+ return r.contains(loc);
+ }
+
}