001: // @@
002: // @@
003: /*
004: * Wi.Ser Framework
005: *
006: * LGPL Version: 1.8.1, 20-September-2007
007: * Copyright (C) 2005-2006 Dirk von der Weiden <dvdw@imail.de>
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library located in LGPL.txt in the
021: * license directory; if not, write to the
022: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
023: * Boston, MA 02111-1307, USA.
024: *
025: * If this agreement does not cover your requirements, please contact us
026: * via email to get detailed information about the commercial license
027: * or our service offerings!
028: *
029: */
030: // @@
031: package de.ug2t.channel.ho.client.swing;
032:
033: import java.awt.event.*;
034: import java.util.*;
035:
036: import javax.swing.*;
037:
038: import de.ug2t.kernel.*;
039: import de.ug2t.unifiedGui.*;
040: import de.ug2t.unifiedGui.interfaces.*;
041:
042: public final class HoSwingRadioButton extends HoSwingComponent
043: implements IUnRadioButton {
044: protected JRadioButton pdm_swingButton = null;
045: private HoSwingImage pem_icon = null;
046: private String pem_group = null;
047: private HashMap pem_groups = null;
048:
049: private static final String B_GROUPS = "MY_RADIO_GROUPS";
050:
051: public HoSwingRadioButton(String xValue, String xString,
052: String xGroup, IUnApplication xAppl) throws Exception {
053: super (xValue, xAppl);
054: this .pcmf_setLocalValue(xValue);
055:
056: pdm_swingButton = new JRadioButton(xString, false);
057: pdm_swingButton.setBorderPainted(true);
058: pdm_swingButton.setBorder(null);
059:
060: this .pem_groups = (HashMap) KeRegisteredObject
061: .pcmf_getObjByName(B_GROUPS);
062: if (this .pem_groups == null) {
063: this .pem_groups = new HashMap();
064: KeRegisteredObject.pcmf_register(B_GROUPS, this .pem_groups);
065: }
066:
067: ButtonGroup l_group = (ButtonGroup) pem_groups.get(xGroup);
068: if (l_group == null) {
069: l_group = new ButtonGroup();
070: pem_groups.put(xGroup, l_group);
071: }
072: l_group.add(pdm_swingButton);
073: this .pem_group = xGroup;
074:
075: ((JComponent) this .pdm_swingButton).setOpaque(true);
076:
077: super .pdm_realSwingCmp = this .pdm_swingButton;
078: this .pdm_swingButton.setMinimumSize(this .pdm_swingButton
079: .getPreferredSize());
080: ((HoSwingClient) xAppl).pcmf_addKeyDispatcher(this );
081:
082: ActionListener l = new ActionListener() {
083: public void actionPerformed(ActionEvent ev) {
084: try {
085: String l_objName = HoSwingRadioButton.this
086: .pcmf_getObjName();
087: // Lokale Listener aufrufen
088: if (HoSwingRadioButton.this .pdm_swingButton
089: .isSelected()) {
090: HoSwingRadioButton.this .pcmf_setRefresh();
091: HoSwingRadioButton.this .pcmf_dispatchEvent();
092:
093: if (HoSwingRadioButton.this .pem_session
094: .pcmf_isDisabled())
095: return;
096:
097: // Werte setzen um diese zum Server zu übertragen
098: ((HoSwingPage) HoSwingRadioButton.this
099: .pcmf_getAppl().pcmf_getActive())
100: .pcmf_setSubmitValue(
101: HoSwingRadioButton.this .pem_group,
102: HoSwingRadioButton.this
103: .pcmf_getValue()
104: .toString());
105: if (HoSwingRadioButton.this
106: .pcmf_getUnComponent().pcmf_isSubmit() == true)
107: ((HoSwingPage) HoSwingRadioButton.this
108: .pcmf_getAppl().pcmf_getActive())
109: .pcmf_submit();
110: }
111: } catch (Exception e) {
112: KeLog.pcmf_logException("ug2t", this , e);
113: }
114: ;
115: };
116: };
117:
118: this .pdm_swingButton.addActionListener(l);
119:
120: return;
121: };
122:
123: public void pcmf_setValue(Object xValue) {
124: if (xValue.equals(IUnRadioButton.CHECKED))
125: this .pdm_swingButton.setSelected(true);
126: else if (xValue.equals(IUnRadioButton.NOTCHECKED))
127: this .pdm_swingButton.setSelected(false);
128: else
129: this .pcmf_setLocalValue(xValue);
130:
131: return;
132: };
133:
134: public void pcmf_setIcon(IUnImage xIcon) {
135: pem_icon = (HoSwingImage) xIcon;
136:
137: JRadioButton l_box = new JRadioButton();
138: l_box.setIcon(((JLabel) pem_icon.pcmf_getRealSwingObj())
139: .getIcon());
140: l_box.setSelectedIcon(l_box.getDisabledSelectedIcon());
141:
142: this .pdm_swingButton.setIcon(l_box.getDisabledIcon());
143: this .pdm_swingButton.setSelectedIcon(l_box.getIcon());
144:
145: l_box = null;
146: }
147:
148: public IUnImage pcmf_getIcon() {
149: return (pem_icon);
150: };
151:
152: public void pcmf_setReadOnly(boolean xReadOnly) {
153: this .pdm_swingButton.setEnabled(!xReadOnly);
154: }
155:
156: public boolean pcmf_isReadOnly() {
157: return (!this .pdm_swingButton.isEnabled());
158: }
159:
160: public UnButtonGroup pcmf_getGroup() {
161: throw (new UnsupportedOperationException());
162: }
163:
164: public void pcmf_removeGroup(String xGroup) {
165: pem_groups.remove(xGroup);
166: }
167:
168: public void pcmf_setKeyAccess(int xKey) {
169: this .pdm_swingButton.setMnemonic(Character
170: .toString((char) xKey).toUpperCase().charAt(0));
171: };
172:
173: public int pcmf_getAccKey() {
174: return (this.pdm_swingButton.getMnemonic());
175: }
176: }
|