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.*;
034: import java.awt.event.*;
035: import java.util.*;
036:
037: import javax.swing.*;
038:
039: import de.ug2t.kernel.*;
040: import de.ug2t.unifiedGui.*;
041: import de.ug2t.unifiedGui.interfaces.*;
042: import de.ug2t.unifiedGui.views.*;
043:
044: final class MyJRadioButton extends JRadioButton {
045: private HoSwingRadioPanel pem_myButton = null;
046: private String pem_sval = null;
047:
048: public MyJRadioButton(String xString, String xValue,
049: HoSwingRadioPanel xBut) {
050: super (xString);
051: this .pem_myButton = xBut;
052: this .pem_sval = xValue;
053: this .setOpaque(true);
054:
055: return;
056: }
057:
058: private JRadioButton pem_box = new JRadioButton();
059:
060: public void paint(Graphics g) {
061: KeTreeNode l_node = (KeTreeNode) this .pem_myButton
062: .pcmf_getSubNode(pem_sval);
063: boolean l_doValidate = false;
064: if (l_node != null) {
065: IKeView l_view = l_node.pcmf_getView();
066: if (l_view instanceof UnIconValueView) {
067: if (((UnIconValueView) l_view).pcmf_getBg() != null)
068: this
069: .setBackground(HoSwingComponent
070: .pcmf_createColor(((UnIconValueView) l_view)
071: .pcmf_getBg()));
072: if (((UnIconValueView) l_view).pcmf_getFg() != null)
073: this
074: .setForeground(HoSwingComponent
075: .pcmf_createColor(((UnIconValueView) l_view)
076: .pcmf_getFg()));
077:
078: if (((UnIconValueView) l_view).pcmf_getOpenIcon() != null
079: && ((UnIconValueView) l_view)
080: .pcmf_getOpenIcon() == ((UnIconValueView) l_view)
081: .pcmf_getCloseIcon()) {
082: Icon l_ico = ((JLabel) ((HoSwingImage) ((UnIconValueView) l_view)
083: .pcmf_getOpenIcon()).pcmf_getRealSwingObj())
084: .getIcon();
085:
086: pem_box.setIcon(l_ico);
087: pem_box.setSelectedIcon(pem_box
088: .getDisabledSelectedIcon());
089:
090: if (l_ico != this .getSelectedIcon()) {
091: this .setIcon(pem_box.getDisabledIcon());
092: this .setSelectedIcon(pem_box.getIcon());
093: this .setRolloverIcon(pem_box.getIcon());
094:
095: l_doValidate = true;
096: }
097: } else if (((UnIconValueView) l_view)
098: .pcmf_getOpenIcon() != null) {
099: Icon l_ico = ((JLabel) ((HoSwingImage) ((UnIconValueView) l_view)
100: .pcmf_getCloseIcon())
101: .pcmf_getRealSwingObj()).getIcon();
102: if (l_ico != this .getIcon()) {
103: this .setIcon(l_ico);
104: l_doValidate = true;
105: }
106:
107: l_ico = ((JLabel) ((HoSwingImage) ((UnIconValueView) l_view)
108: .pcmf_getOpenIcon()).pcmf_getRealSwingObj())
109: .getIcon();
110: if (l_ico != this .getSelectedIcon()) {
111: this .setSelectedIcon(l_ico);
112: this .setRolloverIcon(l_ico);
113: l_doValidate = true;
114: }
115: }
116: UnFontDescriptor l_font = ((UnIconValueView) l_view)
117: .pcmf_getFontDesc();
118: if (l_font != null) {
119: Font l_f = new Font(l_font.pcmf_getFontName(),
120: l_font.pcmf_getFontStyle(), l_font
121: .pcmf_getFontSize());
122: if (l_f.equals(this .getFont()) == false) {
123: this .setFont(l_f);
124: l_doValidate = true;
125: }
126: }
127: }
128: }
129: if (l_doValidate) {
130: Component l_parent = this .getParent();
131: while (l_parent != null) {
132: l_parent.validate();
133: l_parent = l_parent.getParent();
134: }
135: }
136: super .paint(g);
137: }
138: }
139:
140: public final class HoSwingRadioPanel extends HoSwingContainer implements
141: IUnRadioPanel {
142: protected HashMap pdm_buttons = new HashMap();
143:
144: private ButtonGroup pem_grp = null;
145: private HashMap pem_values = new HashMap();
146: private ActionListener pem_list = null;
147: private boolean pem_noDefaultColor = false;
148:
149: public HoSwingRadioPanel(String xName, String xValue,
150: String xString, IUnApplication xAppl) throws Exception {
151: super (xName, xAppl);
152:
153: this .pem_grp = new ButtonGroup();
154: this .pcmf_setLocalValue(xValue);
155:
156: pem_list = new ActionListener() {
157: public void actionPerformed(ActionEvent ev) {
158: try {
159: String l_objName = HoSwingRadioPanel.this
160: .pcmf_getObjName();
161:
162: // Lokale Listener aufrufen
163: HoSwingRadioPanel.this
164: .pcmf_setLocalValue(HoSwingRadioPanel.this .pdm_buttons
165: .get(ev.getSource()));
166: HoSwingRadioPanel.this .pcmf_setRefresh();
167: HoSwingRadioPanel.this .pcmf_dispatchEvent();
168:
169: if (HoSwingRadioPanel.this .pem_session
170: .pcmf_isDisabled())
171: return;
172:
173: // Werte setzen um diese zum Server zu übertragen
174: ((HoSwingPage) HoSwingRadioPanel.this
175: .pcmf_getAppl().pcmf_getActive())
176: .pcmf_setSubmitValue(l_objName,
177: HoSwingRadioPanel.this
178: .pcmf_getValue().toString());
179: HoSwingRadioPanel.this .pcmf_addSyncedWidgets(
180: (HoSwingPage) HoSwingRadioPanel.this
181: .pcmf_getAppl().pcmf_getActive(),
182: HoSwingRadioPanel.this );
183: if (HoSwingRadioPanel.this .pcmf_getUnComponent()
184: .pcmf_isSubmit() == true)
185: ((HoSwingPage) HoSwingRadioPanel.this
186: .pcmf_getAppl().pcmf_getActive())
187: .pcmf_submit();
188: } catch (Exception e) {
189: KeLog.pcmf_logException("ug2t", this , e);
190: }
191: ;
192: };
193: };
194:
195: if (xString.equals("") == false) {
196: MyJRadioButton l_but = new MyJRadioButton(xString, xValue,
197: this );
198: ((HoSwingClient) xAppl).pcmf_addKeyDispatcher(l_but);
199:
200: this .pdm_mainPanel.add(l_but);
201: this .pem_grp.add(l_but);
202:
203: pem_values.put(xValue, l_but);
204: pdm_buttons.put(l_but, xValue);
205:
206: l_but.addActionListener(pem_list);
207: }
208: ((HoSwingClient) xAppl).pcmf_addKeyDispatcher(this );
209:
210: return;
211: }
212:
213: public UnComponent pcmf_setPosition(String xName, int xPos,
214: int yPos, int xWidth, int xHeight, int xAlign) {
215: GridBagConstraints l_constr = null;
216: Component l_obj = null;
217:
218: l_obj = (Component) this .pem_values.get(xName);
219:
220: if (this .pdm_layout == null && l_obj != null) {
221: l_obj.setBounds(xPos, yPos, xWidth, xHeight);
222:
223: return (this );
224: }
225: ;
226:
227: if (l_obj != null) {
228: l_constr = new GridBagConstraints();
229: l_constr.gridx = xPos;
230: l_constr.gridy = yPos;
231: l_constr.gridheight = xHeight;
232: l_constr.gridwidth = xWidth;
233: l_constr.anchor = xAlign;
234:
235: l_constr.insets = new Insets(1, 0, 7, 10);
236:
237: this .pdm_layout.setConstraints(l_obj, l_constr);
238: }
239: ;
240:
241: return (this );
242: };
243:
244: public UnComponent pcmf_setPosition(KeTreeNode xObj, int xPos,
245: int yPos, int xWidth, int xHeight, int xAlign) {
246: GridBagConstraints l_constr = null;
247: Component l_obj = null;
248:
249: l_obj = (Component) this .pem_values.get(xObj.pcmf_getName());
250:
251: if (this .pdm_layout == null && l_obj != null) {
252: l_obj.setBounds(xPos, yPos, xWidth, xHeight);
253:
254: return (this );
255: }
256: ;
257:
258: if (l_obj != null) {
259: l_constr = new GridBagConstraints();
260: l_constr.gridx = xPos;
261: l_constr.gridy = yPos;
262: l_constr.gridheight = xHeight;
263: l_constr.gridwidth = xWidth;
264: l_constr.anchor = xAlign;
265:
266: l_constr.insets = new Insets(1, 0, 7, 10);
267:
268: this .pdm_layout.setConstraints(l_obj, l_constr);
269: }
270: ;
271:
272: return (this );
273: };
274:
275: public KeTreeNode pcmf_addValue(String xValue, String xString) {
276: MyJRadioButton l_but = new MyJRadioButton(xString, xValue, this );
277: ((HoSwingClient) this .pcmf_getAppl())
278: .pcmf_addKeyDispatcher(l_but);
279:
280: this .pdm_mainPanel.add(l_but);
281: this .pem_grp.add(l_but);
282: pem_values.put(xValue, l_but);
283: pdm_buttons.put(l_but, xValue);
284: l_but.addActionListener(pem_list);
285:
286: if (this .pem_noDefaultColor) {
287: try {
288: l_but.setForeground((Color) java.awt.Color.class
289: .getDeclaredField(this .pcmf_getFgColor()).get(
290: null));
291: l_but.setBackground((Color) java.awt.Color.class
292: .getDeclaredField(this .pcmf_getBgColor()).get(
293: null));
294: } catch (Exception e) {
295: KeLog.pcmf_logException("ug2t", this , e);
296: }
297: ;
298: }
299:
300: return (null);
301: };
302:
303: public void pcmf_removeValue(String xValue) {
304: Component l_cmp = (Component) pdm_buttons.remove(pem_values
305: .remove(xValue));
306: this .pdm_mainPanel.remove(l_cmp);
307: this .pem_grp.remove((AbstractButton) l_cmp);
308:
309: return;
310: };
311:
312: public void pcmf_removeAllValues() {
313: this .pem_values.clear();
314: this .pdm_buttons.clear();
315: this .pdm_mainPanel.removeAll();
316: this .pem_grp = new ButtonGroup();
317:
318: return;
319: };
320:
321: public HashMap pcmf_getValues() {
322: return (pem_values);
323: };
324:
325: public void pcmf_setValue(Object xValue) {
326: this .pcmf_setLocalValue(xValue);
327: ((AbstractButton) this .pem_values.get(xValue))
328: .setSelected(true);
329:
330: return;
331: };
332:
333: public void pcmf_disable() {
334: this .pdm_realSwingCmp.setEnabled(false);
335: Iterator it = this .pdm_buttons.keySet().iterator();
336:
337: while (it.hasNext())
338: ((AbstractButton) it.next()).setEnabled(false);
339:
340: super .pcmf_disable();
341:
342: return;
343: };
344:
345: public void pcmf_enable() {
346: this .pdm_realSwingCmp.setEnabled(true);
347: Iterator it = this .pdm_buttons.keySet().iterator();
348:
349: while (it.hasNext())
350: ((AbstractButton) it.next()).setEnabled(true);
351:
352: super .pcmf_disable();
353: return;
354: };
355:
356: public void pcmf_setFgColor(String xCol) {
357: pem_noDefaultColor = true;
358:
359: try {
360: Iterator it = this .pdm_buttons.keySet().iterator();
361:
362: while (it.hasNext())
363: ((AbstractButton) it.next())
364: .setForeground(HoSwingComponent
365: .pcmf_createColor(xCol));
366:
367: super .pcmf_setFgColor(xCol);
368: } catch (Exception e) {
369: KeLog.pcmf_logException("ug2t", this , e);
370: }
371: ;
372:
373: return;
374: };
375:
376: public void pcmf_setBgColor(String xCol) {
377: pem_noDefaultColor = true;
378:
379: try {
380: Iterator it = this .pdm_buttons.keySet().iterator();
381:
382: while (it.hasNext())
383: ((AbstractButton) it.next())
384: .setBackground((Color) java.awt.Color.class
385: .getDeclaredField(xCol).get(null));
386:
387: super .pcmf_setBgColor(xCol);
388: } catch (Exception e) {
389: KeLog.pcmf_logException("ug2t", this , e);
390: }
391: ;
392:
393: return;
394: };
395:
396: public void pcmf_setReadOnly(boolean xReadOnly) {
397: if (xReadOnly)
398: this .pcmf_disable();
399: else
400: this .pcmf_enable();
401: }
402:
403: public boolean pcmf_isReadOnly() {
404: return (!this.pcmf_isDisabled());
405: }
406: }
|