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