49 * the length of the arrays don't match |
51 * the length of the arrays don't match |
50 * @throws NullPointerException if the text elements array is null |
52 * @throws NullPointerException if the text elements array is null |
51 * @throws NullPointerException if any of the text elements is null |
53 * @throws NullPointerException if any of the text elements is null |
52 */ |
54 */ |
53 public ChoiceGroup(String label, int type, |
55 public ChoiceGroup(String label, int type, |
54 String[] textElements, |
56 String[] textElements, |
55 Image[] imgElements) { |
57 Image[] imgElements) |
56 switch (type) { |
58 { |
57 case Choice.EXCLUSIVE: |
59 switch(type) |
58 case Choice.POPUP: |
60 { |
59 choiceImpl = new ChoiceImpl(false); |
61 case Choice.EXCLUSIVE: |
60 break; |
62 case Choice.POPUP: |
61 case Choice.MULTIPLE: |
63 choiceImpl = new ChoiceImpl(false); |
62 choiceImpl = new ChoiceImpl(true); |
64 break; |
63 break; |
65 case Choice.MULTIPLE: |
64 default: |
66 choiceImpl = new ChoiceImpl(true); |
65 throw new IllegalArgumentException( |
67 break; |
66 MsgRepository.CHOICEGROUP_EXCEPTION_INVALID_TYPE); |
68 default: |
|
69 throw new IllegalArgumentException( |
|
70 MsgRepository.CHOICEGROUP_EXCEPTION_INVALID_TYPE); |
67 } |
71 } |
68 choiceImpl.check(textElements, imgElements); |
72 choiceImpl.check(textElements, imgElements); |
69 setLabel(label != null ? label : ""); |
73 setLabel(label != null ? label : ""); |
70 this.type = type; |
74 this.type = type; |
71 // append elements |
75 // append elements |
72 for (int i = 0; i < textElements.length; i++) { |
76 for(int i = 0; i < textElements.length; i++) |
|
77 { |
73 append(textElements[i], imgElements != null |
78 append(textElements[i], imgElements != null |
74 ? imgElements[i] : null); |
79 ? imgElements[i] : null); |
75 } |
80 } |
76 } |
81 } |
77 |
82 |
78 /** |
83 /** |
79 * Append item with specified text and image. |
84 * Append item with specified text and image. |
80 * |
85 * |
81 * @param text the text |
86 * @param text the text |
82 * @param img the image |
87 * @param img the image |
83 * @return index of added item |
88 * @return index of added item |
84 */ |
89 */ |
85 public int append(String text, Image img) { |
90 public int append(String text, Image img) |
|
91 { |
86 int ret = choiceImpl.append(text, img); |
92 int ret = choiceImpl.append(text, img); |
87 updateParent(UPDATE_SIZE_CHANGED); |
93 updateParent(UPDATE_SIZE_CHANGED); |
88 return ret; |
94 return ret; |
89 } |
95 } |
90 |
96 |
105 * |
112 * |
106 * @param position the item index |
113 * @param position the item index |
107 * @param text the text |
114 * @param text the text |
108 * @param img the image |
115 * @param img the image |
109 */ |
116 */ |
110 public void set(int position, String text, Image img) { |
117 public void set(int position, String text, Image img) |
|
118 { |
111 choiceImpl.set(position, text, img); |
119 choiceImpl.set(position, text, img); |
112 updateParent(UPDATE_CONTENT); |
120 updateParent(UPDATE_CONTENT); |
113 } |
121 } |
114 |
122 |
115 /** |
123 /** |
116 * Remove item at specified position. |
124 * Remove item at specified position. |
117 * |
125 * |
118 * @param position the item index |
126 * @param position the item index |
119 */ |
127 */ |
120 public void delete(int position) { |
128 public void delete(int position) |
|
129 { |
121 choiceImpl.delete(position); |
130 choiceImpl.delete(position); |
122 updateParent(UPDATE_SIZE_CHANGED); |
131 updateParent(UPDATE_SIZE_CHANGED); |
123 } |
132 } |
124 |
133 |
125 /** |
134 /** |
126 * Remove all items. |
135 * Remove all items. |
127 */ |
136 */ |
128 public void deleteAll() { |
137 public void deleteAll() |
|
138 { |
129 choiceImpl.deleteAll(); |
139 choiceImpl.deleteAll(); |
130 updateParent(UPDATE_SIZE_CHANGED); |
140 updateParent(UPDATE_SIZE_CHANGED); |
131 } |
141 } |
132 |
142 |
133 /** |
143 /** |
134 * Get the fit policy of this ChoiceGroup. |
144 * Get the fit policy of this ChoiceGroup. |
135 * |
145 * |
136 * @return the ChoiceGroup's fit policy |
146 * @return the ChoiceGroup's fit policy |
137 */ |
147 */ |
138 public int getFitPolicy() { |
148 public int getFitPolicy() |
|
149 { |
139 return choiceImpl.getFitPolicy(); |
150 return choiceImpl.getFitPolicy(); |
140 } |
151 } |
141 |
152 |
142 /** |
153 /** |
143 * Get the font used in a ChoiceGroup item. |
154 * Get the font used in a ChoiceGroup item. |
144 * |
155 * |
145 * @param position the index of the item |
156 * @param position the index of the item |
146 * @return the items font |
157 * @return the items font |
147 */ |
158 */ |
148 public Font getFont(int position) { |
159 public Font getFont(int position) |
|
160 { |
149 return choiceImpl.getFont(position); |
161 return choiceImpl.getFont(position); |
150 } |
162 } |
151 |
163 |
152 /** |
164 /** |
153 * Get the image part of a ChoiceGroup item. |
165 * Get the image part of a ChoiceGroup item. |
154 * |
166 * |
155 * @param position the index of the item |
167 * @param position the index of the item |
156 * @return the items image part |
168 * @return the items image part |
157 */ |
169 */ |
158 public Image getImage(int position) { |
170 public Image getImage(int position) |
|
171 { |
159 return choiceImpl.getImage(position); |
172 return choiceImpl.getImage(position); |
160 } |
173 } |
161 |
174 |
162 /** |
175 /** |
163 * Get the string part of a ChoiceGroup item. |
176 * Get the string part of a ChoiceGroup item. |
164 * |
177 * |
165 * @param position the index of the item |
178 * @param position the index of the item |
166 * @return the items string part |
179 * @return the items string part |
167 */ |
180 */ |
168 public String getString(int position) { |
181 public String getString(int position) |
|
182 { |
169 return choiceImpl.getString(position); |
183 return choiceImpl.getString(position); |
170 } |
184 } |
171 |
185 |
172 /** |
186 /** |
173 * Get selected flags. |
187 * Get selected flags. |
174 * |
188 * |
175 * @param selectedArray an array with selected items |
189 * @param selectedArray an array with selected items |
176 * @return selected flags |
190 * @return selected flags |
177 */ |
191 */ |
178 public int getSelectedFlags(boolean[] selectedArray) { |
192 public int getSelectedFlags(boolean[] selectedArray) |
|
193 { |
179 return choiceImpl.getSelectedFlags(selectedArray); |
194 return choiceImpl.getSelectedFlags(selectedArray); |
180 } |
195 } |
181 |
196 |
182 /** |
197 /** |
183 * Returns the selected item's index. |
198 * Returns the selected item's index. |
184 * |
199 * |
185 * @return the selected index |
200 * @return the selected index |
186 */ |
201 */ |
187 public int getSelectedIndex() { |
202 public int getSelectedIndex() |
|
203 { |
188 return choiceImpl.getSelectedIndex(); |
204 return choiceImpl.getSelectedIndex(); |
189 } |
205 } |
190 |
206 |
191 /** |
207 /** |
192 * Returns if the specified element is selected. |
208 * Returns if the specified element is selected. |
193 * |
209 * |
194 * @param position specified element index |
210 * @param position specified element index |
195 * @return true if its selected, false otherwise |
211 * @return true if its selected, false otherwise |
196 */ |
212 */ |
197 public boolean isSelected(int position) { |
213 public boolean isSelected(int position) |
|
214 { |
198 return choiceImpl.isSelected(position); |
215 return choiceImpl.isSelected(position); |
199 } |
216 } |
200 |
217 |
201 /** |
218 /** |
202 * Set the fit policy of this ChoiceGroup. |
219 * Set the fit policy of this ChoiceGroup. |
203 * |
220 * |
204 * @param newFitPolicy the new fit policy |
221 * @param newFitPolicy the new fit policy |
205 */ |
222 */ |
206 public void setFitPolicy(int newFitPolicy) { |
223 public void setFitPolicy(int newFitPolicy) |
|
224 { |
207 choiceImpl.setFitPolicy(newFitPolicy); |
225 choiceImpl.setFitPolicy(newFitPolicy); |
208 updateParent(UPDATE_SIZE_CHANGED); |
226 updateParent(UPDATE_SIZE_CHANGED); |
209 } |
227 } |
210 |
228 |
211 /** |
229 /** |
212 * Set the font of a ChoiceGroup item. |
230 * Set the font of a ChoiceGroup item. |
213 * |
231 * |
214 * @param position the index of the item |
232 * @param position the index of the item |
215 * @param font the desired font |
233 * @param font the desired font |
216 */ |
234 */ |
217 public void setFont(int position, Font font) { |
235 public void setFont(int position, Font font) |
|
236 { |
218 choiceImpl.setFont(position, font); |
237 choiceImpl.setFont(position, font); |
219 updateParent(UPDATE_SIZE_CHANGED); |
238 updateParent(UPDATE_SIZE_CHANGED); |
220 } |
239 } |
221 |
240 |
222 /** |
241 /** |
223 * Set selected flags. |
242 * Set selected flags. |
224 * |
243 * |
225 * @param selectedArray an array with selected items |
244 * @param selectedArray an array with selected items |
226 */ |
245 */ |
227 public void setSelectedFlags(boolean[] selectedArray) { |
246 public void setSelectedFlags(boolean[] selectedArray) |
|
247 { |
228 choiceImpl.setSelectedFlags(selectedArray); |
248 choiceImpl.setSelectedFlags(selectedArray); |
229 updateParent(UPDATE_CONTENT); |
249 updateParent(UPDATE_CONTENT); |
230 } |
250 } |
231 |
251 |
232 /** |
252 /** |
233 * Set selected index. |
253 * Set selected index. |
234 * |
254 * |
235 * @param position the index of the item |
255 * @param position the index of the item |
236 * @param select selected or not |
256 * @param select selected or not |
237 */ |
257 */ |
238 public void setSelectedIndex(int position, boolean select) { |
258 public void setSelectedIndex(int position, boolean select) |
|
259 { |
239 choiceImpl.setSelected(position, select); |
260 choiceImpl.setSelected(position, select); |
240 updateParent(UPDATE_CONTENT); |
261 updateParent(UPDATE_CONTENT); |
241 } |
262 } |
242 |
263 |
243 /** |
264 /** |
244 * Returns the size of the ChoiceGroup. |
265 * Returns the size of the ChoiceGroup. |
245 * |
266 * |
246 * @return the lists size |
267 * @return the lists size |
247 */ |
268 */ |
248 public int size() { |
269 public int size() |
|
270 { |
249 return choiceImpl.size(); |
271 return choiceImpl.size(); |
250 } |
272 } |
251 |
273 |
252 /** |
274 /** |
253 * Calculates minimum size of this item. |
275 * Calculates minimum size of this item. |
254 * |
276 * |
255 * @return Minimum size. |
277 * @return Minimum size. |
256 */ |
278 */ |
257 Point calculateMinimumSize() { |
279 Point calculateMinimumSize() |
|
280 { |
258 return ChoiceGroupLayouter.calculateMinimumBounds(this); |
281 return ChoiceGroupLayouter.calculateMinimumBounds(this); |
259 } |
282 } |
260 |
283 |
261 /** |
284 /** |
262 * Calculates preferred size of this item. |
285 * Calculates preferred size of this item. |
263 * |
286 * |
264 * @return Preferred size. |
287 * @return Preferred size. |
265 */ |
288 */ |
266 Point calculatePreferredSize() { |
289 Point calculatePreferredSize() |
|
290 { |
267 return ChoiceGroupLayouter.calculatePreferredBounds(this); |
291 return ChoiceGroupLayouter.calculatePreferredBounds(this); |
268 } |
292 } |
269 |
293 |
270 /** |
294 /** |
271 * Called by widget listeners to update Item value. |
295 * Called by widget listeners to update Item value. |
272 */ |
296 */ |
273 void internalSetSelectedIndex(int position, boolean select) { |
297 void internalSetSelectedIndex(int position, boolean select) |
|
298 { |
274 choiceImpl.setSelected(position, select); |
299 choiceImpl.setSelected(position, select); |
275 // notify item state listener |
300 // notify item state listener |
276 notifyStateChanged(); |
301 notifyStateChanged(); |
277 } |
302 } |
278 |
303 |
279 /** |
304 /** |
280 * Return layout with optional custom flags. |
305 * Return layout with optional custom flags. |
281 * |
306 * |
282 * @return layout directive |
307 * @return layout directive |
283 */ |
308 */ |
284 int internalGetLayout() { |
309 int internalGetLayout() |
|
310 { |
285 return super.internalGetLayout() | Item.LAYOUT_NEWLINE_BEFORE; |
311 return super.internalGetLayout() | Item.LAYOUT_NEWLINE_BEFORE; |
286 } |
312 } |
287 |
313 |
288 /** |
314 /** |
289 * Return the ChoiceGroup type. |
315 * Return the ChoiceGroup type. |
290 */ |
316 */ |
291 final int getType() { |
317 final int getType() |
|
318 { |
292 return type; |
319 return type; |
293 } |
320 } |
294 |
321 |
295 /* (non-Javadoc) |
322 /* (non-Javadoc) |
296 * @see javax.microedition.lcdui.Item#isFocusable() |
323 * @see javax.microedition.lcdui.Item#isFocusable() |
297 */ |
324 */ |
298 boolean isFocusable() { |
325 boolean isFocusable() |
|
326 { |
299 return true; |
327 return true; |
300 } |
328 } |
301 |
329 |
302 } |
330 } |