X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Fgui%2FSidebarController.java;fp=src%2Ftim%2Fprune%2Fgui%2FSidebarController.java;h=252a3592ed24c94743504bd1993b23cb464ba670;hp=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465 diff --git a/src/tim/prune/gui/SidebarController.java b/src/tim/prune/gui/SidebarController.java new file mode 100644 index 0000000..252a359 --- /dev/null +++ b/src/tim/prune/gui/SidebarController.java @@ -0,0 +1,69 @@ +package tim.prune.gui; + +import java.awt.Component; + +import javax.swing.JSplitPane; +import javax.swing.SwingUtilities; + +/** + * Class to control the showing and hiding of the sidebars + * (left panel, right panel and profile display) + */ +public class SidebarController +{ + /** array of hideable components */ + private Component[] _components = null; + /** array of splitter panes */ + private JSplitPane[] _splitters = null; + /** array of splitter positions */ + private int[] _positions = null; + + + /** + * Constructor + * @param inComponents array of components to hide/show + * @param inSplitters array of splitter panes + */ + public SidebarController(Component[] inComponents, JSplitPane[] inSplitters) + { + _components = inComponents; + _splitters = inSplitters; + _positions = new int[inSplitters.length]; + } + + /** + * Toggle full screen mode on or off + */ + public void toggle() + { + if (_components != null && _components.length > 0) + { + boolean visible = _components[0].isVisible(); + if (visible) { + // Store divider locations + for (int i=0; i<_components.length; i++) { + _positions[i] = _splitters[i].getDividerLocation(); + } + } + // Set visibility of components + for (int i=0; i<_components.length; i++) { + _components[i].setVisible(!visible); + } + // Restore divider locations + for (int i=0; i<_components.length; i++) { + if (!visible) { + _splitters[i].setDividerLocation(_positions[i]); + } + } + // Hiding of panels has to occur in separate thread to update properly + if (visible) SwingUtilities.invokeLater(new Runnable() { + public void run() { + for (int i=0; i<_components.length; i++) { + _splitters[i].setDividerLocation(i==0?0.0:1.0); + _splitters[i].invalidate(); + } + } + }); + } + } +}