3 import jalview.api.SplitContainerI;
4 import jalview.util.Platform;
6 import java.awt.Component;
7 import java.awt.MouseInfo;
9 import java.awt.Rectangle;
11 import javax.swing.JInternalFrame;
12 import javax.swing.JSplitPane;
13 import javax.swing.plaf.basic.BasicInternalFrameUI;
15 public class GSplitFrame extends JInternalFrame implements SplitContainerI
17 private static final long serialVersionUID = 1L;
19 private GAlignFrame topFrame;
21 private GAlignFrame bottomFrame;
23 private JSplitPane splitPane;
31 public GSplitFrame(GAlignFrame top, GAlignFrame bottom)
34 this.bottomFrame = bottom;
42 * Create and add the split pane containing the top and bottom components.
44 protected void addSplitPane()
46 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topFrame,
48 splitPane.setVisible(true);
49 splitPane.setDividerLocation(0.5d);
50 splitPane.setResizeWeight(0.5d);
51 splitPane.setDividerSize(0);
56 * Try to hide the title bars as a waste of precious space.
59 * ://stackoverflow.com/questions/7218971/java-method-works-on-windows
60 * -but-not-macintosh -java
62 protected void hideTitleBars()
64 if (new Platform().isAMac())
66 // this saves some space - but doesn't hide the title bar
67 topFrame.putClientProperty("JInternalFrame.isPalette", true);
68 // topFrame.getRootPane().putClientProperty("Window.style", "small");
69 bottomFrame.putClientProperty("JInternalFrame.isPalette", true);
73 ((BasicInternalFrameUI) topFrame.getUI()).setNorthPane(null);
74 ((BasicInternalFrameUI) bottomFrame.getUI()).setNorthPane(null);
78 public GAlignFrame getTopFrame()
83 public GAlignFrame getBottomFrame()
89 * Returns the split pane component the mouse is in, or null if neither.
93 protected GAlignFrame getFrameAtMouse()
95 Point loc = MouseInfo.getPointerInfo().getLocation();
97 if (isIn(loc, splitPane.getTopComponent()))
101 else if (isIn(loc, splitPane.getBottomComponent()))
103 return getBottomFrame();
108 private boolean isIn(Point loc, Component comp)
110 if (!comp.isVisible())
114 Point p = comp.getLocationOnScreen();
115 Rectangle r = new Rectangle(p.x, p.y, comp.getWidth(), comp.getHeight());
116 return r.contains(loc);
120 * Make the complement of the specified split component visible or hidden,
121 * 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 splitPane.setDividerLocation(0.5d);