3 import java.awt.Component;
4 import java.awt.MouseInfo;
6 import java.awt.Rectangle;
8 import javax.swing.JInternalFrame;
9 import javax.swing.JSplitPane;
10 import javax.swing.plaf.basic.BasicInternalFrameUI;
12 import jalview.util.Platform;
14 public class GSplitFrame extends JInternalFrame
16 private static final long serialVersionUID = 1L;
18 private GAlignFrame topFrame;
20 private GAlignFrame bottomFrame;
22 private JSplitPane splitPane;
30 public GSplitFrame(GAlignFrame top, GAlignFrame bottom)
33 this.bottomFrame = bottom;
41 * Create and add the split pane containing the top and bottom components.
43 protected void addSplitPane()
45 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topFrame,
47 splitPane.setVisible(true);
48 final double ratio = topFrame.getHeight()
49 / (double) (topFrame.getHeight() + bottomFrame.getHeight());
50 splitPane.setDividerLocation(ratio);
51 splitPane.setResizeWeight(ratio);
52 splitPane.setDividerSize(5);
57 * Try to hide the title bars as a waste of precious space.
60 * ://stackoverflow.com/questions/7218971/java-method-works-on-windows
61 * -but-not-macintosh -java
63 protected void hideTitleBars()
65 if (new Platform().isAMac())
67 // this saves some space - but doesn't hide the title bar
68 topFrame.putClientProperty("JInternalFrame.isPalette", true);
69 // topFrame.getRootPane().putClientProperty("Window.style", "small");
70 bottomFrame.putClientProperty("JInternalFrame.isPalette", true);
74 ((BasicInternalFrameUI) topFrame.getUI()).setNorthPane(null);
75 ((BasicInternalFrameUI) bottomFrame.getUI()).setNorthPane(null);
79 public GAlignFrame getTopFrame()
84 public GAlignFrame getBottomFrame()
90 * Returns the split pane component the mouse is in, or null if neither.
94 protected GAlignFrame getFrameAtMouse()
96 Point loc = MouseInfo.getPointerInfo().getLocation();
98 if (isIn(loc, splitPane.getTopComponent()))
100 return getTopFrame();
102 else if (isIn(loc, splitPane.getBottomComponent()))
104 return getBottomFrame();
109 private boolean isIn(Point loc, Component comp)
111 if (!comp.isVisible())
115 Point p = comp.getLocationOnScreen();
116 Rectangle r = new Rectangle(p.x, p.y, comp.getWidth(), comp.getHeight());
117 return r.contains(loc);
121 * Make the complement of the specified split component visible or hidden,
122 * adjusting the position of the split divide.
124 public void setComplementVisible(Object alignFrame, boolean show)
126 if (alignFrame == this.topFrame)
128 this.bottomFrame.setVisible(show);
130 else if (alignFrame == this.bottomFrame)
132 this.topFrame.setVisible(show);
136 // SplitPane needs nudging to restore 50-50 split
137 // TODO save/restore other ratios
138 splitPane.setDividerLocation(0.5d);