01: package fr.aliacom.form.swt.ui;
02:
03: import org.eclipse.swt.SWT;
04: import org.eclipse.swt.events.SelectionAdapter;
05: import org.eclipse.swt.events.SelectionEvent;
06: import org.eclipse.swt.widgets.Button;
07: import org.eclipse.swt.widgets.Composite;
08:
09: import fr.aliacom.common.ui.IRadioButton;
10: import fr.aliacom.form.common.events.IRadioSelectionListener;
11:
12: /**
13: * @author tom
14: *
15: * (C) 2001, 2003 Thomas Cataldo
16: */
17: public class SWTRadioButton implements IRadioButton {
18:
19: private Button radio;
20: private IRadioSelectionListener listener;
21: private String action;
22:
23: public SWTRadioButton(Composite parent, String text) {
24: radio = new Button(parent, SWT.RADIO);
25: radio.setText(text);
26: final IRadioButton self = this ;
27: radio.addSelectionListener(new SelectionAdapter() {
28: public void widgetSelected(SelectionEvent e) {
29: if (radio.getSelection()) {
30: listener.selected(self);
31: }
32: }
33: });
34: }
35:
36: /**
37: * @see fr.aliacom.common.ui.IRadioButton#setSelected(boolean)
38: */
39: public void setSelected(boolean selected) {
40: radio.setSelection(selected);
41: if (listener != null && selected) {
42: listener.selected(this );
43: }
44: }
45:
46: /**
47: * @see fr.aliacom.common.ui.IRadioButton#addSelectionListener(fr.aliacom.form.common.events.IRadioSelectionListener)
48: */
49: public void addSelectionListener(IRadioSelectionListener isl) {
50: listener = isl;
51: }
52:
53: /**
54: * @see fr.aliacom.form.common.IFormComponent#reset()
55: */
56: public void reset() {
57: }
58:
59: /**
60: * @see fr.aliacom.form.common.IFormComponent#setValueBean(java.lang.Object)
61: */
62: public void setValueBean(Object bean) {
63: }
64:
65: /**
66: * @see fr.aliacom.form.common.IFormComponent#getNativeWidget()
67: */
68: public Object getNativeWidget() {
69: return radio;
70: }
71:
72: /**
73: * Returns the action.
74: * @return String
75: */
76: public String getAction() {
77: return action;
78: }
79:
80: /**
81: * Sets the action.
82: * @param action The action to set
83: */
84: public void setAction(String action) {
85: this.action = action;
86: }
87:
88: }
|