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