File: ComponentHider.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 (59 lines) | stat: -rw-r--r-- 1,425 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
package tim.prune.load;

import java.awt.Component;
import java.util.ArrayList;

import tim.prune.data.Field;

/**
 * Class to hold a list of Components and fields,
 * and then enable or disable them (setEnabled) according
 * to whether those fields are available or not
 */
public class ComponentHider
{
	/**
	 * Inner class to hold each Component and its Field
	 */
	static class ComponentPair
	{
		public Component _component = null;
		public Field     _field     = null;
		/** Constructor */
		public ComponentPair(Component inComponent, Field inField)
		{
			_component = inComponent;
			_field     = inField;
		}
	}

	/** list itself */
	private ArrayList<ComponentPair> _componentList = new ArrayList<ComponentPair>(20);

	/**
	 * Add a new component to be controlled
	 * @param inComponent component to enable/disable
	 * @param inField associated field
	 */
	public void addComponent(Component inComponent, Field inField)
	{
		if (inComponent != null && inField != null) {
			_componentList.add(new ComponentPair(inComponent, inField));
		}
	}

	/**
	 * Enable or disable the components for the given field
	 * @param inField field
	 * @param inEnabled true for enabled, false for disabled
	 */
	public void enableComponents(Field inField, boolean inEnabled)
	{
		for (ComponentPair pair : _componentList)
		{
			if (pair != null && pair._field == inField) {
				pair._component.setEnabled(inEnabled);
			}
		}
	}
}