Rev 223 | Rev 245 | 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; |
91 | case PARAMTYPE_BYTE: |
||
223 | ligi | 92 | lcd_lines[1+2*i]=" "+edit_source.get_field_from_act(edit_source.field_positions[act_tab][i]); |
220 | ligi | 93 | 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)) |
94 | lcd_lines[2+2*i]+="[Poti"+(edit_source.get_field_from_act(edit_source.field_positions[act_tab][i])-250) +"]"; break; |
||
206 | ligi | 95 | |
96 | |||
220 | ligi | 97 | case PARAMTYPE_KEY: |
221 | ligi | 98 | if (edit_source.get_field_from_act(edit_source.field_positions[act_tab][i])==-4242) |
99 | lcd_lines[1+2*i]="none"; |
||
100 | else |
||
223 | ligi | 101 | lcd_lines[1+2*i]=" "+edit_source.get_field_from_act(edit_source.field_positions[act_tab][i]); |
221 | ligi | 102 | break; |
220 | ligi | 103 | case PARAMTYPE_STICK: |
223 | ligi | 104 | lcd_lines[1+2*i]=" "+edit_source.get_field_from_act(edit_source.field_positions[act_tab][i]); |
220 | ligi | 105 | break; |
106 | |||
107 | default: |
||
223 | ligi | 108 | 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 | 109 | } |
110 | |||
111 | } |
||
112 | |||
113 | lcd_lines[act_lcd_lines-1]="back"; |
||
114 | |||
115 | canvas.lcd_lines=new String[act_lcd_lines]; |
||
116 | for ( int i=0;i<act_lcd_lines;i++) |
||
117 | { |
||
118 | lcd_lines[i]=(act_y==i?"#":" ")+lcd_lines[i]; |
||
119 | while(lcd_lines[i].length()<20) |
||
120 | lcd_lines[i]+=" "; |
||
206 | ligi | 121 | |
220 | ligi | 122 | canvas.lcd_lines[i]=lcd_lines[i]; |
123 | } |
||
206 | ligi | 124 | |
220 | ligi | 125 | } |
206 | ligi | 126 | |
220 | ligi | 127 | catch (Exception e){} |
128 | |||
129 | // for(int i=0;i<act_lcd_lines;i++) |
||
206 | ligi | 130 | |
220 | ligi | 131 | /* |
206 | ligi | 132 | } |
133 | else |
||
134 | { |
||
135 | canvas.lcd_lines=new String[1]; |
||
136 | canvas.lcd_lines[0]="reading params"; |
||
137 | } |
||
220 | ligi | 138 | */ |
206 | ligi | 139 | } |
140 | |||
141 | |||
142 | public final static int KEYCODE_CLEAR=-8; |
||
143 | |||
144 | public boolean editing_number=false; |
||
145 | |||
242 | ligi | 146 | public void pointer_press(int x,int row) |
147 | { |
||
148 | |||
149 | System.out.println("!!!!!!!!!!!!!!row:"+row); |
||
150 | if (select_mode) |
||
151 | { |
||
152 | canvas.act_menu_select=row; |
||
153 | keypress (-4242,Canvas.FIRE); |
||
154 | |||
155 | } |
||
156 | else |
||
157 | { |
||
158 | if ((row%2)==0) |
||
159 | act_y=row+1; |
||
160 | else |
||
161 | { |
||
162 | act_y=row; |
||
163 | |||
164 | if (act_y==(canvas.lcd_lines.length-1)) |
||
165 | keypress (-4242,Canvas.FIRE); |
||
166 | else |
||
167 | { |
||
168 | if (x<(canvas.canvas_width/2)) |
||
169 | keypress (-4242,Canvas.LEFT); |
||
170 | else |
||
171 | keypress (-4242,Canvas.RIGHT); |
||
172 | } |
||
173 | } |
||
174 | } |
||
175 | } |
||
176 | |||
177 | |||
206 | ligi | 178 | public void keypress (int keyCode,int action) |
179 | { |
||
180 | |||
220 | ligi | 181 | if (select_mode) |
206 | ligi | 182 | { |
220 | ligi | 183 | if (action== Canvas.FIRE) |
206 | ligi | 184 | { |
220 | ligi | 185 | |
186 | if (canvas.act_menu_select==(menu_items.length-1)) |
||
187 | canvas.chg_state(nextstate); |
||
188 | else |
||
189 | |||
206 | ligi | 190 | { |
220 | ligi | 191 | act_tab=canvas.act_menu_select; |
192 | select_mode=false; |
||
193 | act_y=1; |
||
206 | ligi | 194 | } |
195 | } |
||
220 | ligi | 196 | else |
197 | canvas.menu_keypress(keyCode); |
||
206 | ligi | 198 | } |
220 | ligi | 199 | else |
206 | ligi | 200 | { |
201 | |||
202 | |||
220 | ligi | 203 | if ((act_y!=(act_lcd_lines-1))&&(((keyCode >= Canvas.KEY_NUM0) && (keyCode <= Canvas.KEY_NUM9))|| ( keyCode==KEYCODE_CLEAR))) |
204 | { |
||
205 | int act_pos=act_y/2; |
||
206 | if((edit_source.field_types[act_tab][act_pos]==edit_source.PARAMTYPE_BYTE)) |
||
207 | { |
||
208 | if ((keyCode >= Canvas.KEY_NUM0) && (keyCode <= Canvas.KEY_NUM9)) |
||
209 | { |
||
210 | 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)) |
||
211 | 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)); |
||
212 | else |
||
213 | edit_source.set_field_from_act(edit_source.field_positions[act_tab][act_pos] , (keyCode - Canvas.KEY_NUM0)); |
||
214 | editing_number=true; |
||
215 | return; |
||
216 | } |
||
217 | else |
||
218 | if ( keyCode==KEYCODE_CLEAR) |
||
219 | edit_source.set_field_from_act(edit_source.field_positions[act_tab][act_pos],0); |
||
220 | } |
||
221 | editing_number=false; |
||
222 | |||
223 | } |
||
206 | ligi | 224 | |
220 | ligi | 225 | switch (action) |
226 | { |
||
227 | |||
228 | case Canvas.DOWN: |
||
229 | if (act_y<(act_lcd_lines-2)) act_y+=2; |
||
230 | else act_y=1; |
||
231 | break; |
||
232 | |||
233 | case Canvas.UP: |
||
234 | if (act_y!=1) act_y-=2; |
||
235 | else act_y=act_lcd_lines-1; |
||
236 | break; |
||
237 | |||
238 | default: |
||
206 | ligi | 239 | |
240 | |||
220 | ligi | 241 | |
242 | if (act_y!=(act_lcd_lines-1)) |
||
243 | { |
||
244 | |||
245 | // |
||
246 | |||
247 | int act_pos=act_y/2; |
||
248 | |||
249 | if((edit_source.field_types[act_tab][act_pos]==edit_source.PARAMTYPE_KEY)) |
||
250 | edit_source.set_field_from_act(edit_source.field_positions[act_tab][act_pos],keyCode); |
||
251 | |||
252 | switch (action) |
||
253 | { |
||
254 | |||
255 | case Canvas.RIGHT: |
||
256 | switch(edit_source.field_types[act_tab][act_pos]) |
||
257 | { |
||
258 | case PARAMTYPE_BITSWITCH: |
||
259 | |||
260 | 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)); |
||
261 | break; |
||
262 | |||
263 | |||
264 | case PARAMTYPE_BYTE: |
||
265 | case PARAMTYPE_STICK: |
||
266 | |||
267 | edit_source.field_from_act_add(edit_source.field_positions[act_tab][act_pos],1); |
||
268 | break; |
||
269 | |||
270 | default: |
||
271 | 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); |
||
272 | break; |
||
273 | } |
||
274 | break; |
||
275 | |||
276 | case Canvas.LEFT: |
||
277 | switch(edit_source.field_types[act_tab][act_pos]) |
||
278 | { |
||
279 | case PARAMTYPE_BITSWITCH: |
||
280 | 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)); |
||
281 | |||
282 | break; |
||
283 | case PARAMTYPE_BYTE: |
||
284 | case PARAMTYPE_STICK: |
||
285 | edit_source.field_from_act_add(edit_source.field_positions[act_tab][act_pos],-1); |
||
286 | break; |
||
287 | default: |
||
288 | 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); |
||
289 | break; |
||
290 | } |
||
291 | |||
292 | |||
293 | break; |
||
294 | } |
||
295 | |||
296 | } |
||
297 | else |
||
298 | if (action== Canvas.FIRE) |
||
299 | { |
||
300 | act_y=1; |
||
242 | ligi | 301 | // canvas.act_menu_select=0; |
220 | ligi | 302 | canvas.menu_items[0]=""; |
303 | select_mode=true; |
||
304 | |||
305 | } |
||
306 | } |
||
307 | |||
308 | |||
309 | // if (!select_mode)refresh_lcd(); |
||
310 | |||
311 | } |
||
312 | } // keypress |
||
206 | ligi | 313 | } |
314 |