Rev 221 | Rev 242 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 221 | Rev 223 | ||
---|---|---|---|
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 | 145 | ||
146 | public void keypress (int keyCode,int action) |
146 | public void keypress (int keyCode,int action) |
147 | { |
147 | { |
148 | 148 | ||
149 | if (select_mode) |
149 | if (select_mode) |
150 | { |
150 | { |
151 | if (action== Canvas.FIRE) |
151 | if (action== Canvas.FIRE) |
152 | { |
152 | { |
153 | 153 | ||
154 | if (canvas.act_menu_select==(menu_items.length-1)) |
154 | if (canvas.act_menu_select==(menu_items.length-1)) |
155 | canvas.chg_state(nextstate); |
155 | canvas.chg_state(nextstate); |
156 | else |
156 | else |
157 | 157 | ||
158 | { |
158 | { |
159 | act_tab=canvas.act_menu_select; |
159 | act_tab=canvas.act_menu_select; |
160 | select_mode=false; |
160 | select_mode=false; |
161 | act_y=1; |
161 | act_y=1; |
162 | } |
162 | } |
163 | } |
163 | } |
164 | else |
164 | else |
165 | canvas.menu_keypress(keyCode); |
165 | canvas.menu_keypress(keyCode); |
166 | } |
166 | } |
167 | else |
167 | else |
168 | { |
168 | { |
169 | 169 | ||
170 | 170 | ||
171 | if ((act_y!=(act_lcd_lines-1))&&(((keyCode >= Canvas.KEY_NUM0) && (keyCode <= Canvas.KEY_NUM9))|| ( keyCode==KEYCODE_CLEAR))) |
171 | if ((act_y!=(act_lcd_lines-1))&&(((keyCode >= Canvas.KEY_NUM0) && (keyCode <= Canvas.KEY_NUM9))|| ( keyCode==KEYCODE_CLEAR))) |
172 | { |
172 | { |
173 | int act_pos=act_y/2; |
173 | int act_pos=act_y/2; |
174 | if((edit_source.field_types[act_tab][act_pos]==edit_source.PARAMTYPE_BYTE)) |
174 | if((edit_source.field_types[act_tab][act_pos]==edit_source.PARAMTYPE_BYTE)) |
175 | { |
175 | { |
176 | if ((keyCode >= Canvas.KEY_NUM0) && (keyCode <= Canvas.KEY_NUM9)) |
176 | if ((keyCode >= Canvas.KEY_NUM0) && (keyCode <= Canvas.KEY_NUM9)) |
177 | { |
177 | { |
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)) |
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)) |
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)); |
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)); |
180 | else |
180 | else |
181 | edit_source.set_field_from_act(edit_source.field_positions[act_tab][act_pos] , (keyCode - Canvas.KEY_NUM0)); |
181 | edit_source.set_field_from_act(edit_source.field_positions[act_tab][act_pos] , (keyCode - Canvas.KEY_NUM0)); |
182 | editing_number=true; |
182 | editing_number=true; |
183 | return; |
183 | return; |
184 | } |
184 | } |
185 | else |
185 | else |
186 | if ( keyCode==KEYCODE_CLEAR) |
186 | if ( keyCode==KEYCODE_CLEAR) |
187 | edit_source.set_field_from_act(edit_source.field_positions[act_tab][act_pos],0); |
187 | edit_source.set_field_from_act(edit_source.field_positions[act_tab][act_pos],0); |
188 | } |
188 | } |
189 | editing_number=false; |
189 | editing_number=false; |
190 | 190 | ||
191 | } |
191 | } |
192 | 192 | ||
193 | switch (action) |
193 | switch (action) |
194 | { |
194 | { |
195 | 195 | ||
196 | case Canvas.DOWN: |
196 | case Canvas.DOWN: |
197 | if (act_y<(act_lcd_lines-2)) act_y+=2; |
197 | if (act_y<(act_lcd_lines-2)) act_y+=2; |
198 | else act_y=1; |
198 | else act_y=1; |
199 | break; |
199 | break; |
200 | 200 | ||
201 | case Canvas.UP: |
201 | case Canvas.UP: |
202 | if (act_y!=1) act_y-=2; |
202 | if (act_y!=1) act_y-=2; |
203 | else act_y=act_lcd_lines-1; |
203 | else act_y=act_lcd_lines-1; |
204 | break; |
204 | break; |
205 | 205 | ||
206 | default: |
206 | default: |
207 | 207 | ||
208 | 208 | ||
209 | 209 | ||
210 | if (act_y!=(act_lcd_lines-1)) |
210 | if (act_y!=(act_lcd_lines-1)) |
211 | { |
211 | { |
212 | 212 | ||
213 | // |
213 | // |
214 | 214 | ||
215 | int act_pos=act_y/2; |
215 | int act_pos=act_y/2; |
216 | 216 | ||
217 | if((edit_source.field_types[act_tab][act_pos]==edit_source.PARAMTYPE_KEY)) |
217 | 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); |
218 | edit_source.set_field_from_act(edit_source.field_positions[act_tab][act_pos],keyCode); |
219 | 219 | ||
220 | switch (action) |
220 | switch (action) |
221 | { |
221 | { |
222 | 222 | ||
223 | case Canvas.RIGHT: |
223 | case Canvas.RIGHT: |
224 | switch(edit_source.field_types[act_tab][act_pos]) |
224 | switch(edit_source.field_types[act_tab][act_pos]) |
225 | { |
225 | { |
226 | case PARAMTYPE_BITSWITCH: |
226 | case PARAMTYPE_BITSWITCH: |
227 | 227 | ||
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)); |
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)); |
229 | break; |
229 | break; |
230 | 230 | ||
231 | 231 | ||
232 | case PARAMTYPE_BYTE: |
232 | case PARAMTYPE_BYTE: |
233 | case PARAMTYPE_STICK: |
233 | case PARAMTYPE_STICK: |
234 | 234 | ||
235 | edit_source.field_from_act_add(edit_source.field_positions[act_tab][act_pos],1); |
235 | edit_source.field_from_act_add(edit_source.field_positions[act_tab][act_pos],1); |
236 | break; |
236 | break; |
237 | 237 | ||
238 | default: |
238 | 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); |
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); |
240 | break; |
240 | break; |
241 | } |
241 | } |
242 | break; |
242 | break; |
243 | 243 | ||
244 | case Canvas.LEFT: |
244 | case Canvas.LEFT: |
245 | switch(edit_source.field_types[act_tab][act_pos]) |
245 | switch(edit_source.field_types[act_tab][act_pos]) |
246 | { |
246 | { |
247 | case PARAMTYPE_BITSWITCH: |
247 | 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)); |
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)); |
249 | 249 | ||
250 | break; |
250 | break; |
251 | case PARAMTYPE_BYTE: |
251 | case PARAMTYPE_BYTE: |
252 | case PARAMTYPE_STICK: |
252 | case PARAMTYPE_STICK: |
253 | edit_source.field_from_act_add(edit_source.field_positions[act_tab][act_pos],-1); |
253 | edit_source.field_from_act_add(edit_source.field_positions[act_tab][act_pos],-1); |
254 | break; |
254 | break; |
255 | default: |
255 | 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); |
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); |
257 | break; |
257 | break; |
258 | } |
258 | } |
259 | 259 | ||
260 | 260 | ||
261 | break; |
261 | break; |
262 | } |
262 | } |
263 | 263 | ||
264 | } |
264 | } |
265 | else |
265 | else |
266 | if (action== Canvas.FIRE) |
266 | if (action== Canvas.FIRE) |
267 | { |
267 | { |
268 | act_y=1; |
268 | act_y=1; |
269 | canvas.menu_items[0]=""; |
269 | canvas.menu_items[0]=""; |
270 | select_mode=true; |
270 | select_mode=true; |
271 | 271 | ||
272 | } |
272 | } |
273 | } |
273 | } |
274 | 274 | ||
275 | 275 | ||
276 | // if (!select_mode)refresh_lcd(); |
276 | // if (!select_mode)refresh_lcd(); |
277 | 277 | ||
278 | } |
278 | } |
279 | } // keypress |
279 | } // keypress |
280 | } |
280 | } |
281 | 281 | ||
282 | 282 |