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 = bottomFrame.getHeight() == 0 ? 0.5d : topFrame
50 / (double) (topFrame.getHeight() + bottomFrame.getHeight());
51 splitPane.setDividerLocation(ratio);
52 splitPane.setResizeWeight(ratio);
53 splitPane.setDividerSize(5);
58 * Try to hide the title bars as a waste of precious space.
61 * ://stackoverflow.com/questions/7218971/java-method-works-on-windows
62 * -but-not-macintosh -java
64 protected void hideTitleBars()
66 if (new Platform().isAMac())
68 // this saves some space - but doesn't hide the title bar
69 topFrame.putClientProperty("JInternalFrame.isPalette", true);
70 // topFrame.getRootPane().putClientProperty("Window.style", "small");
71 bottomFrame.putClientProperty("JInternalFrame.isPalette", true);
75 ((BasicInternalFrameUI) topFrame.getUI()).setNorthPane(null);
76 ((BasicInternalFrameUI) bottomFrame.getUI()).setNorthPane(null);
80 public GAlignFrame getTopFrame()
85 public GAlignFrame getBottomFrame()
91 * Returns the split pane component the mouse is in, or null if neither.
95 protected GAlignFrame getFrameAtMouse()
97 Point loc = MouseInfo.getPointerInfo().getLocation();
99 if (isIn(loc, splitPane.getTopComponent()))
101 return getTopFrame();
103 else if (isIn(loc, splitPane.getBottomComponent()))
105 return getBottomFrame();
110 private boolean isIn(Point loc, Component comp)
112 if (!comp.isVisible())
116 Point p = comp.getLocationOnScreen();
117 Rectangle r = new Rectangle(p.x, p.y, comp.getWidth(), comp.getHeight());
118 return r.contains(loc);
122 * Make the complement of the specified split component visible or hidden,
123 * adjusting the position of the split divide.
125 public void setComplementVisible(Object alignFrame, boolean show)
127 if (alignFrame == this.topFrame)
129 this.bottomFrame.setVisible(show);
131 else if (alignFrame == this.bottomFrame)
133 this.topFrame.setVisible(show);
137 // SplitPane needs nudging to restore 50-50 split
138 // TODO save/restore other ratios
139 splitPane.setDividerLocation(0.5d);