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>MenuRadioGroup</code> class is used to group together
25: * a set of <code>WingMenuItem</code> items.
26: * Exactly one check box item in a <code>MenuRadioGroup</code> can
27: * be selected at any given time. Pushing any
28: * item sets its state to selected and forces any other item 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 MenuRadioGroup {
34: private WingMenuItem selected = null;
35:
36: /**
37: * Adds the item to the group.
38: * @param mi the item to be added
39: */
40: public void add(WingMenuItem mi) {
41: if (mi.isSelected()) {
42: if (selected == null)
43: selected = mi;
44: else
45: mi.setSelected(false);
46: }
47: mi.group = this ;
48: }
49:
50: /**
51: * Sets selected state of the item mi.
52: * Only one item in the group may be selected at a time.
53: * @param mi the menu item
54: * @param select <code>true</code> if this item is to be
55: * selected, otherwise <code>false</code>
56: */
57: public void setSelected(WingMenuItem mi, boolean select) {
58: WingMenuItem old = selected;
59: if (select) {
60: selected = mi;
61: if (old != null && (mi == null || mi.isSelected())) {
62: old.setSelected(false);
63: }
64: } else if (old == mi)
65: selected = null;
66: }
67: }
|