01: /*
02: ItsNat Java Web Application Framework
03: Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
04: Author: Jose Maria Arranz Santamaria
05:
06: This program is free software: you can redistribute it and/or modify
07: it under the terms of the GNU Affero General Public License as published by
08: the Free Software Foundation, either version 3 of the License, or
09: (at your option) any later version. See the GNU Affero General Public
10: License for more details. See the copy of the GNU Affero General Public License
11: included in this program. If not, see <http://www.gnu.org/licenses/>.
12: */
13:
14: package org.itsnat.impl.comp;
15:
16: import javax.swing.ButtonGroup;
17: import org.itsnat.comp.ItsNatButtonRadio;
18: import javax.swing.JToggleButton.ToggleButtonModel;
19: import org.itsnat.comp.ItsNatButtonGroup;
20: import org.itsnat.comp.ItsNatComponentManager;
21: import org.itsnat.comp.ui.ItsNatButtonRadioUI;
22:
23: /**
24: *
25: * @author jmarranz
26: */
27: public class ItsNatButtonRadioBasedSharedImpl {
28:
29: /**
30: * Creates a new instance of ItsNatButtonRadioBasedSharedImpl
31: */
32: public ItsNatButtonRadioBasedSharedImpl() {
33: }
34:
35: public static void syncWithDataModel(ItsNatButtonRadio comp) {
36: ToggleButtonModel dataModel = comp.getToggleButtonModel();
37: comp.setButtonGroup(dataModel.getGroup()); // Antes de nada y por si no se hubiera definido o hubiera cambiado (pues el cambio de grupo no se notifica con eventos)
38: }
39:
40: public static ItsNatButtonGroup setButtonGroup(
41: ItsNatButtonRadio comp, ItsNatButtonGroup currButtonGroup,
42: ButtonGroup group) {
43: // Tenemos la obligación de hacer que el radio button pertenezca al
44: // nuevo grupo si hay cambio
45: if (group == null) {
46: comp.setItsNatButtonGroup(null);
47: return null;
48: } else if ((currButtonGroup == null)
49: || currButtonGroup.getButtonGroup() != group) // O no hay actual o ha cambiado
50: {
51: ItsNatComponentManager componentMgr = comp
52: .getItsNatComponentManager();
53: ItsNatButtonGroup newButtonGroup = componentMgr
54: .getItsNatButtonGroup(group);
55: comp.setItsNatButtonGroup(newButtonGroup);
56: return newButtonGroup;
57: } else
58: return currButtonGroup; // No ha cambiado
59: }
60:
61: public static void setItsNatButtonGroup(
62: ItsNatButtonRadioInternal comp,
63: ItsNatButtonGroupImpl itsNatButtonGroup,
64: boolean addToGroup, boolean updateUI) {
65: ToggleButtonModel dataModel = comp
66: .getToggleButtonModelNoUpdateButtonGroup();
67: if (itsNatButtonGroup != null)
68: dataModel.setGroup(itsNatButtonGroup.getButtonGroup());
69: else
70: dataModel.setGroup(null);
71:
72: if (addToGroup && (itsNatButtonGroup != null))
73: itsNatButtonGroup.addButton(comp, false);
74:
75: if (updateUI) {
76: ItsNatButtonRadioUI compUI = comp.getItsNatButtonRadioUI();
77: compUI.setItsNatButtonGroup(itsNatButtonGroup);
78: }
79: }
80: }
|