01: package com.xoetrope.awt.survey;
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: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
12: * the GNU Public License (GPL), please see license.txt for more details. If
13: * you make commercial use of this software you must purchase a commercial
14: * license from Xoetrope.</p>
15: * <p>$Revision: 1.2 $</p>
16: */
17: public class XExclusiveGroup {
18: Vector objects;
19:
20: /**
21: * Creates a new group.
22: */
23: public XExclusiveGroup() {
24: objects = new Vector();
25: }
26:
27: /**
28: * Add another check to the group
29: * @param xc
30: */
31: public void add(XCheckbox xc) {
32: objects.addElement(xc);
33: }
34:
35: /**
36: * Sets the checked component. All other components in the group are unchecked.
37: *
38: * @param xc The checked component. It is assumed that this control is already
39: * checked and its state is not modified.
40: */
41: public void check(XCheckbox xc) {
42: int size = objects.size();
43: for (int i = 0; i < size; i++) {
44: XCheckbox xTarget = ((XCheckbox) objects.elementAt(i));
45:
46: if (xTarget != xc) {
47: xTarget.setState(false);
48: }
49: }
50: }
51: }
|