Rev 266 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
206 | ligi | 1 | /******************************************************** |
2 | * |
||
3 | * class to handle Editing of MK Params via MIDP / J2ME |
||
4 | * |
||
5 | * Author: Marcus -LiGi- Bueschleb |
||
6 | * |
||
7 | ********************************************************/ |
||
8 | |||
9 | import javax.microedition.lcdui.*; |
||
10 | |||
11 | public class MKParamsEditor |
||
255 | ligi | 12 | implements org.ligi.ufo.MKParamDefinitions, org.ligi.ufo.DUBwiseLangDefs |
206 | ligi | 13 | { |
14 | |||
220 | ligi | 15 | public byte nextstate; |
206 | ligi | 16 | |
17 | private int act_tab=0; |
||
220 | ligi | 18 | public int act_y=1; |
206 | ligi | 19 | private int act_lcd_lines=10; |
20 | |||
21 | DUBwiseCanvas canvas; |
||
22 | |||
220 | ligi | 23 | public String[] lcd_lines; |
206 | ligi | 24 | |
220 | ligi | 25 | public String[] menu_items; |
206 | ligi | 26 | |
220 | ligi | 27 | org.ligi.ufo.ParamsClass edit_source; |
206 | ligi | 28 | |
382 | ligi | 29 | boolean select_mode; |
220 | ligi | 30 | |
382 | ligi | 31 | |
32 | |||
220 | ligi | 33 | public MKParamsEditor(DUBwiseCanvas _canvas,org.ligi.ufo.ParamsClass _edit_source,byte _nextstate) |
206 | ligi | 34 | { |
220 | ligi | 35 | nextstate=_nextstate; |
36 | edit_source=_edit_source; |
||
37 | |||
206 | ligi | 38 | canvas=_canvas; |
39 | lcd_lines=new String[40]; |
||
382 | ligi | 40 | |
41 | |||
42 | System.out.println("initing params_editor"); |
||
43 | select_mode=(edit_source.tab_stringids!=null); |
||
206 | ligi | 44 | // refresh_lcd(); |
45 | } |
||
46 | |||
220 | ligi | 47 | |
48 | |||
206 | ligi | 49 | public void paint ( Graphics g) |
50 | { |
||
220 | ligi | 51 | if (select_mode) |
52 | { |
||
266 | ligi | 53 | if ((canvas.menu_items[0]!=canvas.lcd_lines[0])||(canvas.menu_items[0]!=canvas.l(edit_source.tab_stringids[0])||((canvas.menu_items.length!=edit_source.tab_stringids.length+1)))) // usefull? |
220 | ligi | 54 | { |
55 | act_y=1; |
||
255 | ligi | 56 | menu_items=new String[edit_source.tab_stringids.length+1]; |
57 | for(int p=0;p<edit_source.tab_stringids.length;p++) |
||
58 | menu_items[p]=canvas.l(edit_source.tab_stringids[p]); |
||
59 | menu_items[edit_source.tab_stringids.length]=canvas.l(STRINGID_BACK); |
||
220 | ligi | 60 | canvas.setup_menu(menu_items,null); |
61 | } |
||
62 | canvas.paint_menu(g); |
||
63 | } |
||
64 | |||
65 | else |
||
66 | { |
||
67 | refresh_lcd(); |
||
68 | // canvas.paint_lcd(g,false); |
||
221 | ligi | 69 | canvas.paint_lcd(g); |
220 | ligi | 70 | } |
206 | ligi | 71 | } |
72 | |||
73 | |||
74 | public void refresh_lcd() |
||
75 | { |
||
76 | |||
220 | ligi | 77 | try { |
382 | ligi | 78 | act_lcd_lines=edit_source.field_types[act_tab].length*2+2; |
220 | ligi | 79 | |
80 | for ( int i=0;i<act_lcd_lines;i++) |
||
81 | lcd_lines[i]=""; |
||
82 | |||
83 | |||
84 | |||
255 | ligi | 85 | // lcd_lines[0]=(act_tab==0?" ":"< ") + edit_source.tab_stringids[act_tab] + (act_tab==(edit_source.tab_stringids.length-1)?" ":" >"); |
220 | ligi | 86 | |
382 | ligi | 87 | for (int i=0;i<edit_source.field_types[act_tab].length;i++) |
220 | ligi | 88 | { |
382 | ligi | 89 | if (edit_source.field_stringids!=null) |
90 | lcd_lines[2*i]=canvas.l(edit_source.field_stringids[act_tab][i]); |
||
91 | else |
||
92 | lcd_lines[2*i]=edit_source.field_strings[act_tab][i]; |
||
220 | ligi | 93 | switch(edit_source.field_types[act_tab][i]) |
94 | { |
||
95 | case PARAMTYPE_BITSWITCH: |
||
258 | ligi | 96 | lcd_lines[1+2*i]=" " + (((edit_source.get_field_from_act(edit_source.field_positions[act_tab][i]/8)&(1<<edit_source.field_positions[act_tab][i]%8))==0)?canvas.l(STRINGID_OFF):canvas.l(STRINGID_ON) ) ; |
220 | ligi | 97 | break; |
245 | ligi | 98 | |
220 | ligi | 99 | case PARAMTYPE_BYTE: |
223 | ligi | 100 | lcd_lines[1+2*i]=" "+edit_source.get_field_from_act(edit_source.field_positions[act_tab][i]); |
245 | ligi | 101 | |
102 | break; |
||
103 | |||
104 | case PARAMTYPE_BITMASK: |
||
105 | lcd_lines[1+2*i]=" "+edit_source.get_field_from_act(edit_source.field_positions[act_tab][i]); |
||
220 | ligi | 106 | if ((edit_source.get_field_from_act(edit_source.field_positions[act_tab][i])>250)&&(edit_source.get_field_from_act(edit_source.field_positions[act_tab][i])<256)) |
245 | ligi | 107 | lcd_lines[1+2*i]+="[Poti"+(edit_source.get_field_from_act(edit_source.field_positions[act_tab][i])-250) +"]"; |
108 | else |
||
109 | { |
||
110 | lcd_lines[1+2*i]+=" ["; |
||
111 | for (int bit=0;bit<8;bit++) |
||
112 | lcd_lines[1+2*i]+=((edit_source.get_field_from_act(edit_source.field_positions[act_tab][i]) & ( 1<<bit)) !=0)?"+":"-"; |
||
113 | lcd_lines[1+2*i]+="]"; |
||
114 | } |
||
115 | |||
116 | break; |
||
206 | ligi | 117 | |
245 | ligi | 118 | case PARAMTYPE_MKBYTE: |
119 | lcd_lines[1+2*i]=" "+edit_source.get_field_from_act(edit_source.field_positions[act_tab][i]); |
||
120 | if ((edit_source.get_field_from_act(edit_source.field_positions[act_tab][i])>250)&&(edit_source.get_field_from_act(edit_source.field_positions[act_tab][i])<256)) |
||
121 | lcd_lines[1+2*i]+=" [Poti"+(edit_source.get_field_from_act(edit_source.field_positions[act_tab][i])-250) +"]"; |
||
122 | break; |
||
206 | ligi | 123 | |
245 | ligi | 124 | |
220 | ligi | 125 | case PARAMTYPE_KEY: |
221 | ligi | 126 | if (edit_source.get_field_from_act(edit_source.field_positions[act_tab][i])==-4242) |
258 | ligi | 127 | lcd_lines[1+2*i]=canvas.l(STRINGID_NONE_ASSIGNED); |
221 | ligi | 128 | else |
223 | ligi | 129 | lcd_lines[1+2*i]=" "+edit_source.get_field_from_act(edit_source.field_positions[act_tab][i]); |
221 | ligi | 130 | break; |
220 | ligi | 131 | case PARAMTYPE_STICK: |
223 | ligi | 132 | lcd_lines[1+2*i]=" "+edit_source.get_field_from_act(edit_source.field_positions[act_tab][i]); |
220 | ligi | 133 | break; |
134 | |||
135 | default: |
||
258 | ligi | 136 | lcd_lines[1+2*i]=" "+canvas.l(edit_source.choice_stringids[edit_source.field_types[act_tab][i]-PARAMTYPE_CHOICE][edit_source.get_field_from_act(edit_source.field_positions[act_tab][i])]); |
220 | ligi | 137 | } |
138 | |||
139 | } |
||
140 | |||
255 | ligi | 141 | lcd_lines[act_lcd_lines-1]=canvas.l(STRINGID_BACK); |
220 | ligi | 142 | |
143 | canvas.lcd_lines=new String[act_lcd_lines]; |
||
144 | for ( int i=0;i<act_lcd_lines;i++) |
||
145 | { |
||
146 | lcd_lines[i]=(act_y==i?"#":" ")+lcd_lines[i]; |
||
147 | while(lcd_lines[i].length()<20) |
||
148 | lcd_lines[i]+=" "; |
||
206 | ligi | 149 | |
220 | ligi | 150 | canvas.lcd_lines[i]=lcd_lines[i]; |
151 | } |
||
206 | ligi | 152 | |
220 | ligi | 153 | } |
206 | ligi | 154 | |
220 | ligi | 155 | catch (Exception e){} |
156 | |||
157 | // for(int i=0;i<act_lcd_lines;i++) |
||
206 | ligi | 158 | |
220 | ligi | 159 | /* |
206 | ligi | 160 | } |
161 | else |
||
162 | { |
||
163 | canvas.lcd_lines=new String[1]; |
||
164 | canvas.lcd_lines[0]="reading params"; |
||
165 | } |
||
220 | ligi | 166 | */ |
206 | ligi | 167 | } |
168 | |||
169 | |||
170 | public final static int KEYCODE_CLEAR=-8; |
||
171 | |||
172 | public boolean editing_number=false; |
||
173 | |||
382 | ligi | 174 | public void pointer_press(int x,byte row) |
242 | ligi | 175 | { |
382 | ligi | 176 | |
177 | |||
178 | |||
179 | System.out.println("pointer row " + row + " lcd_off" + canvas.lcd_off); |
||
242 | ligi | 180 | if (select_mode) |
181 | { |
||
382 | ligi | 182 | if (canvas.act_menu_select!=row) |
183 | canvas.act_menu_select=row; |
||
184 | else |
||
185 | keypress (-4242,Canvas.FIRE); |
||
242 | ligi | 186 | |
187 | } |
||
188 | else |
||
189 | { |
||
190 | if ((row%2)==0) |
||
191 | act_y=row+1; |
||
192 | else |
||
193 | { |
||
194 | act_y=row; |
||
195 | |||
382 | ligi | 196 | System.out.println("y:" + act_y); |
242 | ligi | 197 | if (act_y==(canvas.lcd_lines.length-1)) |
198 | keypress (-4242,Canvas.FIRE); |
||
199 | else |
||
200 | { |
||
201 | if (x<(canvas.canvas_width/2)) |
||
202 | keypress (-4242,Canvas.LEFT); |
||
203 | else |
||
204 | keypress (-4242,Canvas.RIGHT); |
||
205 | } |
||
206 | } |
||
207 | } |
||
208 | } |
||
209 | |||
210 | |||
206 | ligi | 211 | public void keypress (int keyCode,int action) |
212 | { |
||
220 | ligi | 213 | if (select_mode) |
206 | ligi | 214 | { |
220 | ligi | 215 | if (action== Canvas.FIRE) |
206 | ligi | 216 | { |
220 | ligi | 217 | |
218 | if (canvas.act_menu_select==(menu_items.length-1)) |
||
219 | canvas.chg_state(nextstate); |
||
220 | else |
||
221 | |||
206 | ligi | 222 | { |
220 | ligi | 223 | act_tab=canvas.act_menu_select; |
224 | select_mode=false; |
||
225 | act_y=1; |
||
206 | ligi | 226 | } |
227 | } |
||
220 | ligi | 228 | else |
229 | canvas.menu_keypress(keyCode); |
||
206 | ligi | 230 | } |
220 | ligi | 231 | else |
206 | ligi | 232 | { |
233 | |||
234 | |||
220 | ligi | 235 | if ((act_y!=(act_lcd_lines-1))&&(((keyCode >= Canvas.KEY_NUM0) && (keyCode <= Canvas.KEY_NUM9))|| ( keyCode==KEYCODE_CLEAR))) |
236 | { |
||
237 | int act_pos=act_y/2; |
||
245 | ligi | 238 | if((edit_source.field_types[act_tab][act_pos]==edit_source.PARAMTYPE_BYTE)||(edit_source.field_types[act_tab][act_pos]==edit_source.PARAMTYPE_MKBYTE) ||(edit_source.field_types[act_tab][act_pos]==edit_source.PARAMTYPE_BITMASK)) |
220 | ligi | 239 | { |
240 | if ((keyCode >= Canvas.KEY_NUM0) && (keyCode <= Canvas.KEY_NUM9)) |
||
241 | { |
||
242 | if((editing_number)&&( Math.abs(edit_source.get_field_from_act(edit_source.field_positions[act_tab][act_pos]))*10+(keyCode - Canvas.KEY_NUM0)<1000)) |
||
243 | edit_source.set_field_from_act(edit_source.field_positions[act_tab][act_pos] , Math.abs(edit_source.get_field_from_act(edit_source.field_positions[act_tab][act_pos]))*10+(keyCode - Canvas.KEY_NUM0)); |
||
244 | else |
||
245 | edit_source.set_field_from_act(edit_source.field_positions[act_tab][act_pos] , (keyCode - Canvas.KEY_NUM0)); |
||
246 | editing_number=true; |
||
247 | return; |
||
248 | } |
||
249 | else |
||
250 | if ( keyCode==KEYCODE_CLEAR) |
||
251 | edit_source.set_field_from_act(edit_source.field_positions[act_tab][act_pos],0); |
||
252 | } |
||
253 | editing_number=false; |
||
254 | |||
255 | } |
||
206 | ligi | 256 | |
220 | ligi | 257 | switch (action) |
258 | { |
||
259 | |||
260 | case Canvas.DOWN: |
||
261 | if (act_y<(act_lcd_lines-2)) act_y+=2; |
||
262 | else act_y=1; |
||
263 | break; |
||
264 | |||
265 | case Canvas.UP: |
||
266 | if (act_y!=1) act_y-=2; |
||
267 | else act_y=act_lcd_lines-1; |
||
268 | break; |
||
269 | |||
270 | default: |
||
206 | ligi | 271 | |
272 | |||
220 | ligi | 273 | |
274 | if (act_y!=(act_lcd_lines-1)) |
||
275 | { |
||
276 | |||
277 | // |
||
278 | |||
279 | int act_pos=act_y/2; |
||
280 | |||
281 | if((edit_source.field_types[act_tab][act_pos]==edit_source.PARAMTYPE_KEY)) |
||
282 | edit_source.set_field_from_act(edit_source.field_positions[act_tab][act_pos],keyCode); |
||
283 | |||
284 | switch (action) |
||
285 | { |
||
286 | |||
287 | case Canvas.RIGHT: |
||
288 | switch(edit_source.field_types[act_tab][act_pos]) |
||
289 | { |
||
290 | case PARAMTYPE_BITSWITCH: |
||
291 | |||
292 | edit_source.field_from_act_xor((edit_source.field_positions[act_tab][act_pos]/8),1<<(edit_source.field_positions[act_tab][act_pos]%8)); |
||
293 | break; |
||
294 | |||
245 | ligi | 295 | case PARAMTYPE_BITMASK: |
296 | case PARAMTYPE_MKBYTE: |
||
220 | ligi | 297 | case PARAMTYPE_BYTE: |
245 | ligi | 298 | |
220 | ligi | 299 | |
245 | ligi | 300 | edit_source.field_from_act_add_min_max(edit_source.field_positions[act_tab][act_pos],1,0,255); |
220 | ligi | 301 | break; |
245 | ligi | 302 | case PARAMTYPE_STICK: |
303 | edit_source.field_from_act_add_min_max(edit_source.field_positions[act_tab][act_pos],1,0,10); |
||
304 | break; |
||
220 | ligi | 305 | |
306 | default: |
||
258 | ligi | 307 | edit_source.field_from_act_add_mod(edit_source.field_positions[act_tab][act_pos],1,edit_source.choice_stringids[edit_source.field_types[act_tab][act_pos]-PARAMTYPE_CHOICE].length); |
220 | ligi | 308 | break; |
309 | } |
||
310 | break; |
||
311 | |||
312 | case Canvas.LEFT: |
||
313 | switch(edit_source.field_types[act_tab][act_pos]) |
||
314 | { |
||
315 | case PARAMTYPE_BITSWITCH: |
||
316 | edit_source.field_from_act_xor((edit_source.field_positions[act_tab][act_pos]/8),1<<(edit_source.field_positions[act_tab][act_pos]%8)); |
||
317 | |||
318 | break; |
||
245 | ligi | 319 | case PARAMTYPE_BITMASK: |
320 | case PARAMTYPE_MKBYTE: |
||
220 | ligi | 321 | case PARAMTYPE_BYTE: |
245 | ligi | 322 | edit_source.field_from_act_add_min_max(edit_source.field_positions[act_tab][act_pos],-1,0,255); |
323 | break; |
||
220 | ligi | 324 | case PARAMTYPE_STICK: |
245 | ligi | 325 | edit_source.field_from_act_add_min_max(edit_source.field_positions[act_tab][act_pos],-1,0,10); |
220 | ligi | 326 | break; |
327 | default: |
||
258 | ligi | 328 | edit_source.field_from_act_add_mod(edit_source.field_positions[act_tab][act_pos],1,edit_source.choice_stringids[edit_source.field_types[act_tab][act_pos]-PARAMTYPE_CHOICE].length); |
220 | ligi | 329 | break; |
330 | } |
||
331 | |||
332 | |||
333 | break; |
||
334 | } |
||
335 | |||
336 | } |
||
337 | else |
||
338 | if (action== Canvas.FIRE) |
||
339 | { |
||
340 | act_y=1; |
||
242 | ligi | 341 | // canvas.act_menu_select=0; |
220 | ligi | 342 | canvas.menu_items[0]=""; |
343 | |||
382 | ligi | 344 | if (edit_source.tab_stringids==null) |
345 | canvas.chg_state(nextstate); |
||
346 | else |
||
347 | select_mode=true; |
||
220 | ligi | 348 | } |
349 | } |
||
350 | |||
351 | |||
352 | // if (!select_mode)refresh_lcd(); |
||
353 | |||
354 | } |
||
355 | } // keypress |
||
206 | ligi | 356 | } |
357 |