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:
035: import javax.swing.*;
036:
037: import de.ug2t.kernel.*;
038: import de.ug2t.unifiedGui.interfaces.*;
039:
040: public final class HoSwingCheckBox extends HoSwingComponent implements
041: IUnCheckBox, IUnSyncComponent {
042: protected JCheckBox pdm_swingButton = null;
043: private HoSwingImage pem_icon = null;
044:
045: public HoSwingCheckBox(String xValue, String xString,
046: IUnApplication xAppl) throws Exception {
047: super (xValue, xAppl);
048: this .pcmf_setLocalValue(xValue);
049:
050: if (xValue.equals(IUnCheckBox.NOTCHECKED))
051: pdm_swingButton = new JCheckBox(xString, false);
052: else
053: pdm_swingButton = new JCheckBox(xString, true);
054:
055: pdm_swingButton.setBorderPainted(true);
056: pdm_swingButton.setBorder(null);
057:
058: ((JComponent) this .pdm_swingButton).setOpaque(true);
059:
060: super .pdm_realSwingCmp = this .pdm_swingButton;
061: this .pdm_swingButton.setMinimumSize(this .pdm_swingButton
062: .getPreferredSize());
063: ((HoSwingClient) xAppl).pcmf_addKeyDispatcher(this );
064:
065: ActionListener l = new ActionListener() {
066: public void actionPerformed(ActionEvent ev) {
067: try {
068: String l_objName = HoSwingCheckBox.this
069: .pcmf_getObjName();
070: // Lokale Listener aufrufen
071: if (HoSwingCheckBox.this .pdm_swingButton
072: .isSelected())
073: HoSwingCheckBox.this
074: .pcmf_setValue(IUnCheckBox.CHECKED);
075: else
076: HoSwingCheckBox.this
077: .pcmf_setValue(IUnCheckBox.NOTCHECKED);
078:
079: HoSwingCheckBox.this .pcmf_setRefresh();
080: HoSwingCheckBox.this .pcmf_dispatchEvent();
081:
082: if (HoSwingCheckBox.this .pem_session
083: .pcmf_isDisabled())
084: return;
085:
086: // Werte setzen um diese zum Server zu übertragen
087: ((HoSwingPage) HoSwingCheckBox.this .pcmf_getAppl()
088: .pcmf_getActive()).pcmf_setSubmitValue(
089: l_objName, HoSwingCheckBox.this
090: .pcmf_getValue().toString());
091: HoSwingCheckBox.this .pcmf_addSyncedWidgets(
092: (HoSwingPage) HoSwingCheckBox.this
093: .pcmf_getAppl().pcmf_getActive(),
094: HoSwingCheckBox.this );
095: if (HoSwingCheckBox.this .pcmf_getUnComponent()
096: .pcmf_isSubmit() == true)
097: ((HoSwingPage) HoSwingCheckBox.this
098: .pcmf_getAppl().pcmf_getActive())
099: .pcmf_submit();
100: } catch (Exception e) {
101: KeLog.pcmf_logException("ug2t", this , e);
102: }
103: ;
104: };
105: };
106:
107: this .pdm_swingButton.addActionListener(l);
108:
109: return;
110: };
111:
112: public void pcmf_setValue(Object xValue) {
113: if (xValue.equals("CHECKED"))
114: this .pdm_swingButton.setSelected(true);
115: else
116: this .pdm_swingButton.setSelected(false);
117:
118: this .pcmf_setLocalValue(xValue);
119:
120: return;
121: };
122:
123: public void pcmf_setIcon(IUnImage xIcon) {
124: pem_icon = (HoSwingImage) xIcon;
125:
126: JCheckBox l_box = new JCheckBox();
127: l_box.setIcon(((JLabel) pem_icon.pcmf_getRealSwingObj())
128: .getIcon());
129: l_box.setSelectedIcon(l_box.getDisabledSelectedIcon());
130:
131: this .pdm_swingButton.setIcon(l_box.getDisabledIcon());
132: this .pdm_swingButton.setSelectedIcon(l_box.getIcon());
133:
134: l_box = null;
135: }
136:
137: public IUnImage pcmf_getIcon() {
138: return (pem_icon);
139: };
140:
141: public void pcmf_setReadOnly(boolean xReadOnly) {
142: this .pdm_swingButton.setEnabled(!xReadOnly);
143: }
144:
145: public boolean pcmf_isReadOnly() {
146: return (!this .pdm_swingButton.isEnabled());
147: }
148:
149: private int pem_syncCnt = 0;
150:
151: public Object pcmf_getValueToSync() {
152: if (this .pdm_swingButton.isSelected())
153: return ("CHECKED");
154: else
155: return ("NOTCHECKED");
156: }
157:
158: public void pcmf_setSynced() {
159: this .pem_syncCnt++;
160: }
161:
162: public void pcmf_unSync() {
163: this .pem_syncCnt--;
164: if (this .pem_syncCnt < 0)
165: this .pem_syncCnt = 0;
166: }
167:
168: public boolean pcmf_isSynced() {
169: if (this .pem_syncCnt == 0)
170: return (false);
171: else
172: return (true);
173: }
174:
175: public String pcmf_getLabel() {
176: return (this .pdm_swingButton.getText());
177: };
178:
179: public void pcmf_setLabel(String xLabel) {
180: this .pdm_swingButton.setText(xLabel);
181: };
182:
183: public void pcmf_setKeyAccess(int xKey) {
184: this .pdm_swingButton.setMnemonic(Character
185: .toString((char) xKey).toUpperCase().charAt(0));
186: };
187:
188: public int pcmf_getAccKey() {
189: return (this.pdm_swingButton.getMnemonic());
190: }
191: }
|