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