001 /*
002 * SimuCS - Simulator to use with Classifier Systems
003 * MSc project - Oxford University
004 * by Benoit Isaac - Summer 2005
005 */
006
007 package simuLCS;
008 import javax.swing.AbstractAction;
009 import javax.swing.JCheckBox;
010
011 import simuLCS.graphics.*;
012
013 /**
014 * A set of bits inside a classifier grouped because they share the same meaning.
015 * This class is used to generate the GUI for those sets of bits
016 * @author Benoit
017 *
018 */
019 public class ClassifierComponent {
020
021
022 protected String name ;
023
024 /**
025 * Static : can be determined at the creation of the classifier
026 * non Static (dynamic) : must be determine during run-time //finally not implemented
027 */
028 protected boolean isStatic ;
029
030 /**
031 * type = 0 : Yes / No condition -> Checkbox
032 * type = 1 : Value -> Slider // not implemented
033 * type = 2 : Combox box (list)
034 */
035 protected int type ;
036
037 /**
038 * is there an editable text field associated ?
039 */
040 protected boolean isWithText ;
041
042 // for a Slider
043 protected int max ;
044 protected int min ;
045 protected int init ;
046 protected int nbBits ;
047
048 // for a Combo Box
049 protected String[] listOfValues ;
050 protected boolean isEditable ;
051
052 protected G_ClassifierComponent ui = null ;
053
054
055 /**
056 * Default constructor : for a Yes / No Component (type=0)
057 */
058 public ClassifierComponent(String n, boolean iS)
059 {
060 name = n; isStatic = iS;
061 type = 0; nbBits = 1 ;
062 }
063
064 /**
065 * Extended constructor, for other types
066 */
067 public ClassifierComponent(String n, boolean iS, int t, int mn, int mx, int i, int nb)
068 {
069 name = n ; isStatic = iS ; type = t ;
070 max = mx ; min = mn ; init = i ;
071 nbBits = nb ;
072 }
073
074 /**
075 * Extended constructor, for list of values
076 */
077 public ClassifierComponent(String n, boolean iS, boolean isTxt,
078 String[] list, int nb, boolean isEdit)
079 {
080 type = 2 ; // for combo box
081 name = n ; isStatic = iS ;
082 isWithText = isTxt ;
083 listOfValues = list ;
084 nbBits = nb ;
085 isEditable = isEdit ;
086 }
087
088 /**
089 * Get the GUI Component associated with this group of bits
090 * @param a the Action to link with the GUI component
091 * @return
092 */
093 public G_Panel getUICondition(AbstractAction a)
094 {
095 G_Panel p;
096 switch(type){
097 case 0: /* checkbox */
098 p = new G_Panel();
099 JCheckBox j = new JCheckBox(a);
100 p.add(j);
101 j.setLabel(name);
102 break;
103 default:
104 p = new G_Panel();
105 }
106 return p;
107 }
108
109 public G_ClassifierComponent getUIWithListener(int position, int which,
110 boolean withText)
111 {
112 G_ClassifierComponent p ;
113 switch(type){
114 case 0: /* checkbox */
115 p = new G_ClassifierCheckBox(this,name,position,which);
116 break;
117 case 1: /* TODO slider */
118 p = null ; //new G_SliderPanel(name,min,max,init,nbBits);
119 break;
120 case 2: /* Combo box */
121 // System.out.println("getUIwith list of Values[0]:"+listOfValues[0]);
122 p = new G_ClassifierComboBox(this,name,position,nbBits,which);
123 break;
124 default:
125 p = new G_ClassifierCheckBox(this,"Error, default.",0,0);
126 }
127 ui = p ;
128 return p;
129 }
130
131 public G_ClassifierComponent getPointerUI()
132 {
133 return ui;
134 }
135
136
137 public int getNbBits() {
138 return nbBits;
139 }
140
141
142 public boolean isEditable() {
143 return isEditable;
144 }
145
146
147 public int getInit() {
148 return init;
149 }
150
151
152 public boolean isStatic() {
153 return isStatic;
154 }
155
156
157 public boolean isWithText() {
158 return isWithText;
159 }
160
161
162 public String[] getListOfValues() {
163 return listOfValues;
164 }
165
166
167 public int getMax() {
168 return max;
169 }
170
171
172 public int getMin() {
173 return min;
174 }
175
176
177 public String getName() {
178 return name;
179 }
180
181
182 public int getType() {
183 return type;
184 }
185
186
187 public G_ClassifierComponent getUi() {
188 return ui;
189 }
190
191
192 public void setisEditable(boolean b) {
193 isEditable = b;
194 }
195
196
197 public void setInit(int i) {
198 init = i;
199 }
200
201
202 public void setStatic(boolean b) {
203 isStatic = b;
204 }
205
206
207 public void setWithText(boolean b) {
208 isWithText = b;
209 }
210
211
212 public void setListOfValues(String[] strings) {
213 listOfValues = strings;
214 }
215
216
217 public void setMax(int i) {
218 max = i;
219 }
220
221
222 public void setMin(int i) {
223 min = i;
224 }
225
226
227 public void setName(String string) {
228 name = string;
229 }
230
231
232 public void setNbBits(int i) {
233 nbBits = i;
234 }
235
236
237 public void setType(int i) {
238 type = i;
239 }
240
241 /**
242 * @param component
243 */
244 public void setUi(G_ClassifierComponent component) {
245 ui = component;
246 }
247
248 }