View Javadoc

1   package org.catacomb.druid.gui.edit;
2   
3   import java.awt.Color;
4   
5   import org.catacomb.druid.event.LabelActor;
6   import org.catacomb.druid.swing.DRadioButtons;
7   import org.catacomb.interlish.content.StringValue;
8   import org.catacomb.interlish.structure.*;
9   import org.catacomb.report.E;
10  
11  
12  
13  public class DruRadioButtons extends DruGCPanel implements LabelActor, Ablable, Choice,
14      StringValueEditor, ValueWatcher {
15  
16      static final long serialVersionUID = 1001;
17  
18      DRadioButtons dRadioButtons;
19  
20  
21      StringValue stringValue;
22  
23      public DruRadioButtons(String lab, String act, String layout) {
24  
25          setActionMethod(act);
26  
27          String[] sa = new String[0];
28          dRadioButtons = new DRadioButtons(sa, layout);
29  
30          addSingleDComponent(dRadioButtons);
31  
32          setStringValue(new StringValue());
33  
34          dRadioButtons.setLabelActor(this);
35      }
36  
37  
38  
39      public void setStringValue(StringValue bv) {
40          if (stringValue != null) {
41              stringValue.removeValueWatcher(this);
42          }
43          stringValue = bv;
44          if (stringValue == null) {
45              dRadioButtons.setEnabled(false);
46          } else {
47              dRadioButtons.setSelected(stringValue.getString());
48              stringValue.addValueWatcher(this);
49          }
50      }
51  
52  
53  
54      public void valueChangedBy(Value pv, Object src) {
55          if (src == this) {
56              valueChange(stringValue.getString());
57  
58          } else {
59              if (stringValue == pv) {
60                  if (stringValue == null) {
61                      dRadioButtons.setEnabled(false);
62                  } else {
63                      dRadioButtons.setSelected(stringValue.getString());
64                  }
65              } else {
66                  E.error("value changed by called with mismatched value");
67              }
68          }
69      }
70  
71  
72      public void postApply() {
73          dRadioButtons.setMouseActor(this);
74      }
75  
76  
77      public void able(boolean b) {
78          dRadioButtons.setEnabled(b);
79      }
80  
81  
82      public void setValue(String s) {
83          dRadioButtons.setSelected(s);
84      }
85  
86  
87      public void setOptions(String[] sa) {
88          dRadioButtons.setOptions(sa, sa);
89      }
90  
91  
92      public void setOptions(String[] sopts, String[] slabs) {
93          dRadioButtons.setOptions(sopts, slabs);
94  
95      }
96  
97  
98      public String getSelected() {
99          return dRadioButtons.getSelected();
100     }
101 
102 
103 
104     public void labelAction(String s, boolean b) {
105         //  E.info("rb setting string value to " + s);
106         stringValue.reportableSetString(s, this);
107 //	   valueChange(getSelected());
108     }
109 
110 
111     public void setStringValue(String s) {
112         setSelected(s);
113     }
114 
115 
116     public void setSelected(String s) {
117         dRadioButtons.setSelected(s);
118     }
119 
120 
121     public void unselect() {
122         setSelected(null);
123     }
124 
125 
126     public void setAutoSelect(int autoSelect) {
127         dRadioButtons.setSelectedIndex(autoSelect);
128     }
129 
130     public void setBg(Color c) {
131         dRadioButtons.setBg(c);
132     }
133     public void setFg(Color c) {
134         dRadioButtons.setFg(c);
135     }
136 
137 }