01: /*
02: * Javu WingS - Lightweight Java Component Set
03: * Copyright (c) 2005-2007 Krzysztof A. Sadlocha
04: * e-mail: ksadlocha@programics.com
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20:
21: package com.javujavu.javux.wings;
22:
23: /**
24: * The <code>RadioGroup</code> class is used to group together
25: * a set of <code>WingCheckBox</code> checkboxes.
26: * Exactly one checkbox in a <code>RadioGroup</code> can
27: * be selected at any given time. Pushing any
28: * checkbox sets its state to selected and forces any other button that
29: * is in the selected state into the unselected state.
30: * <br>
31: * <b>This class is thread safe.</b>
32: **/
33: public class RadioGroup {
34: private WingCheckBox selected = null;
35:
36: /**
37: * Adds the checkbox to the group.
38: * @param c the checkbox to be added
39: */
40: public void add(WingCheckBox c) {
41: if (c.isSelected()) {
42: if (selected == null)
43: selected = c;
44: else
45: c.setSelected(false);
46: }
47: c.group = this ;
48: }
49:
50: /**
51: * Sets selected state of the checkbox c.
52: * Only one checkbox in the group may be selected at a time.
53: * @param c the checkbox
54: * @param select <code>true</code> if this checkbox is to be
55: * selected, otherwise <code>false</code>
56: */
57: public void setSelected(WingCheckBox c, boolean select) {
58: WingCheckBox old = selected;
59: if (select) {
60: selected = c;
61: if (old != null && (c == null || c.isSelected())) {
62: old.setSelected(false);
63: }
64: } else if (old == c)
65: selected = null;
66: }
67: }
|