File: SidebarController.java

package info (click to toggle)
gpsprune 17-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,984 kB
  • ctags: 5,218
  • sloc: java: 39,403; sh: 25; makefile: 17; python: 15
file content (69 lines) | stat: -rw-r--r-- 1,764 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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();
					}
				}
			});
		}
	}
}