2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.jbgui;
23 import jalview.util.Platform;
25 import java.awt.Component;
26 import java.awt.MouseInfo;
27 import java.awt.Point;
28 import java.awt.Rectangle;
30 import javax.swing.JInternalFrame;
31 import javax.swing.JSplitPane;
32 import javax.swing.plaf.basic.BasicInternalFrameUI;
34 public class GSplitFrame extends JInternalFrame
36 protected static final int DIVIDER_SIZE = 5;
38 private static final long serialVersionUID = 1L;
40 private GAlignFrame topFrame;
42 private GAlignFrame bottomFrame;
44 private JSplitPane splitPane;
47 * proportional position of split divider; saving this allows it to be
48 * restored after hiding one half and resizing
50 private double dividerRatio;
58 public GSplitFrame(GAlignFrame top, GAlignFrame bottom)
61 this.bottomFrame = bottom;
69 * Create and add the split pane containing the top and bottom components.
71 protected void addSplitPane()
73 splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topFrame,
75 splitPane.setVisible(true);
78 * set divider split at 50:50, or restore saved split if loading from
81 int topFrameHeight = topFrame.getHeight();
83 * TODO SplitFrame.setDividerLocation
88 splitPane.setDividerSize(DIVIDER_SIZE);
89 if (topFrameHeight == 0)
91 setRelativeDividerLocation(0.5d); // as a proportion
95 int dividerPosition = topFrameHeight + DIVIDER_SIZE / 2;
96 splitPane.setDividerLocation(dividerPosition); // absolute position
98 splitPane.setResizeWeight(0.5d);
104 * Try to hide the title bars as a waste of precious space.
107 * ://stackoverflow.com/questions/7218971/java-method-works-on-windows
108 * -but-not-macintosh -java
110 protected void hideTitleBars()
112 if (Platform.isAMacAndNotJS())
114 // this saves some space - but doesn't hide the title bar
115 topFrame.putClientProperty("JInternalFrame.isPalette", true);
116 // topFrame.getRootPane().putClientProperty("Window.style", "small");
117 bottomFrame.putClientProperty("JInternalFrame.isPalette", true);
121 ((BasicInternalFrameUI) topFrame.getUI()).setNorthPane(null);
122 ((BasicInternalFrameUI) bottomFrame.getUI()).setNorthPane(null);
126 public GAlignFrame getTopFrame()
131 public GAlignFrame getBottomFrame()
137 * Returns the split pane component the mouse is in, or null if neither.
141 protected GAlignFrame getFrameAtMouse()
143 Point loc = MouseInfo.getPointerInfo().getLocation();
145 if (isIn(loc, splitPane.getTopComponent()))
147 return getTopFrame();
149 else if (isIn(loc, splitPane.getBottomComponent()))
151 return getBottomFrame();
156 private boolean isIn(Point loc, Component comp)
158 if (!comp.isVisible())
162 Point p = comp.getLocationOnScreen();
163 Rectangle r = new Rectangle(p.x, p.y, comp.getWidth(),
165 return r.contains(loc);
169 * Makes the complement of the specified split component visible or hidden,
170 * restoring or saving the position of the split divide.
172 public void setComplementVisible(Object alignFrame, boolean show)
175 * save divider ratio on hide, restore on show
179 setRelativeDividerLocation(dividerRatio);
183 this.dividerRatio = splitPane.getDividerLocation()
184 / (double) (splitPane.getHeight()
185 - splitPane.getDividerSize());
188 if (alignFrame == this.topFrame)
190 this.bottomFrame.setVisible(show);
192 else if (alignFrame == this.bottomFrame)
194 this.topFrame.setVisible(show);
201 * Set the divider location as a proportion (0 <= r <= 1) of the height <br>
202 * Warning: this overloads setDividerLocation(int), and getDividerLocation()
203 * returns the int (pixel count) value
207 public void setRelativeDividerLocation(double r)
209 this.dividerRatio = r;
214 splitPane.setDividerLocation(r);
219 * Sets the divider location (in pixels from top)
223 protected void setDividerLocation(int p)
229 splitPane.setDividerLocation(p);
234 * Returns the divider location (in pixels from top)
238 protected int getDividerLocation()
240 return splitPane.getDividerLocation();