01: package com.xoetrope.swing.util;
02:
03: import java.util.Vector;
04:
05: import net.xoetrope.awt.XCheckbox;
06:
07: /**
08: * A utility class for handling mutually exclusive XCheck components. Normally
09: * checkbox items are not mutually exclusive but sometimes they are used in that
10: * way as their visual impact and intent may be clearer than radio buttons.
11: *
12: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
13: * the GNU Public License (GPL), please see license.txt for more details. If
14: * you make commercial use of this software you must purchase a commercial
15: * license from Xoetrope.</p>
16: * <p> $Revision: 1.2 $</p>
17: */
18: public class XExclusiveGroup {
19: Vector objects;
20:
21: /**
22: * Creates a new group.
23: */
24: public XExclusiveGroup() {
25: objects = new Vector();
26: }
27:
28: /**
29: * Add another check to the group
30: * @param xc
31: */
32: public void add(XCheckbox xc) {
33: objects.addElement(xc);
34: }
35:
36: /**
37: * Sets the checked component. All other components in the group are unchecked.
38: *
39: * @param xc The checked component. It is assumed that this control is already
40: * checked and its state is not modified.
41: */
42: public void check(XCheckbox xc) {
43: int size = objects.size();
44: for (int i = 0; i < size; i++) {
45: XCheckbox xTarget = ((XCheckbox) objects.elementAt(i));
46:
47: if (xTarget != xc) {
48: xTarget.setState(false);
49: }
50: }
51: }
52: }
|