Rev 206 | 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 | |||
15 | |||
16 | private int act_tab=0; |
||
17 | public int act_y=0; |
||
18 | private int act_lcd_lines=10; |
||
19 | |||
20 | DUBwiseCanvas canvas; |
||
21 | |||
22 | |||
23 | // org.ligi.ufo.MKCommunicator _mk; |
||
24 | |||
25 | public String[] lcd_lines; |
||
26 | |||
27 | |||
28 | public MKParamsEditor(DUBwiseCanvas _canvas) |
||
29 | { |
||
30 | canvas=_canvas; |
||
31 | lcd_lines=new String[40]; |
||
32 | // refresh_lcd(); |
||
33 | } |
||
34 | |||
35 | public void paint ( Graphics g) |
||
36 | { |
||
37 | refresh_lcd(); |
||
38 | canvas.paint_lcd(g,false); |
||
39 | } |
||
40 | |||
41 | |||
42 | public void refresh_lcd() |
||
43 | { |
||
44 | |||
45 | if (canvas.mk!=null) |
||
46 | { |
||
47 | act_lcd_lines=canvas.mk.params.field_names[act_tab].length*2+1; |
||
48 | for ( int i=0;i<act_lcd_lines;i++) |
||
49 | lcd_lines[i]=""; |
||
50 | |||
51 | |||
52 | try |
||
53 | { |
||
54 | |||
55 | lcd_lines[0]=(act_tab==0?" ":"< ") + canvas.mk.params.tab_names[act_tab] + (act_tab==(canvas.mk.params.tab_names.length-1)?" ":" >"); |
||
56 | |||
57 | for (int i=0;i<canvas.mk.params.field_names[act_tab].length;i++) |
||
58 | { |
||
59 | lcd_lines[1+2*i]=canvas.mk.params.field_names[act_tab][i]; |
||
60 | if (canvas.mk.params.field_types[act_tab][i]== canvas.mk.params.PARAMTYPE_BITSWITCH) |
||
61 | lcd_lines[2+2*i]=(((canvas.mk.params.get_field_from_act(canvas.mk.params.field_positions[act_tab][i]/8)&(1<<canvas.mk.params.field_positions[act_tab][i]%8))==0)?"off":"on" ) ; |
||
62 | if (canvas.mk.params.field_types[act_tab][i]== canvas.mk.params.PARAMTYPE_BYTE) |
||
63 | { |
||
64 | lcd_lines[2+2*i]=""+canvas.mk.params.get_field_from_act(canvas.mk.params.field_positions[act_tab][i]); |
||
65 | if ((canvas.mk.params.get_field_from_act(canvas.mk.params.field_positions[act_tab][i])>250)&&(canvas.mk.params.get_field_from_act(canvas.mk.params.field_positions[act_tab][i])<256)) |
||
66 | lcd_lines[2+2*i]+="[Poti"+(canvas.mk.params.get_field_from_act(canvas.mk.params.field_positions[act_tab][i])-250) +"]"; |
||
67 | } |
||
68 | |||
69 | if (canvas.mk.params.field_types[act_tab][i]== canvas.mk.params.PARAMTYPE_STICK) |
||
70 | { |
||
71 | lcd_lines[2+2*i]=""+canvas.mk.params.get_field_from_act(canvas.mk.params.field_positions[act_tab][i]); |
||
72 | } |
||
73 | |||
74 | |||
75 | |||
76 | } |
||
77 | |||
78 | for (int i=0;i<act_lcd_lines;i++) |
||
79 | { |
||
80 | lcd_lines[i]=(act_y==i?"#":" ")+lcd_lines[i]; |
||
81 | } |
||
82 | |||
83 | for ( int i=0;i<act_lcd_lines;i++) |
||
84 | while(lcd_lines[i].length()<20) |
||
85 | { |
||
86 | lcd_lines[i]+=" "; |
||
87 | } |
||
88 | } |
||
89 | catch (Exception e){} |
||
90 | canvas.lcd_lines=new String[act_lcd_lines]; |
||
91 | for(int i=0;i<act_lcd_lines;i++) |
||
92 | canvas.lcd_lines[i]=lcd_lines[i]; |
||
93 | |||
94 | } |
||
95 | else |
||
96 | { |
||
97 | canvas.lcd_lines=new String[1]; |
||
98 | canvas.lcd_lines[0]="reading params"; |
||
99 | } |
||
100 | |||
101 | } |
||
102 | |||
103 | |||
104 | public final static int KEYCODE_CLEAR=-8; |
||
105 | |||
106 | public boolean editing_number=false; |
||
107 | |||
108 | public void keypress (int keyCode,int action) |
||
109 | { |
||
110 | if (act_y==0) switch (action) |
||
111 | { |
||
112 | case Canvas.RIGHT: |
||
113 | if (act_tab<canvas.mk.params.tab_names.length-1) act_tab++; |
||
114 | break; |
||
115 | |||
116 | case Canvas.LEFT: |
||
117 | if (act_tab!=0) act_tab--; |
||
118 | break; |
||
119 | } |
||
120 | else |
||
121 | { |
||
122 | if(canvas.mk.params.field_types[act_tab][act_y/2-1]==canvas.mk.params.PARAMTYPE_BYTE) |
||
123 | { |
||
124 | if ((keyCode >= Canvas.KEY_NUM0) && (keyCode <= Canvas.KEY_NUM9)) |
||
125 | { |
||
126 | if((editing_number)&&( Math.abs(canvas.mk.params.get_field_from_act(canvas.mk.params.field_positions[act_tab][act_y/2-1]))*10+(keyCode - Canvas.KEY_NUM0)<1000)) |
||
127 | canvas.mk.params.set_field_from_act(canvas.mk.params.field_positions[act_tab][act_y/2-1] , Math.abs(canvas.mk.params.get_field_from_act(canvas.mk.params.field_positions[act_tab][act_y/2-1]))*10+(keyCode - Canvas.KEY_NUM0)); |
||
128 | else |
||
129 | canvas.mk.params.set_field_from_act(canvas.mk.params.field_positions[act_tab][act_y/2-1] , (keyCode - Canvas.KEY_NUM0)); |
||
130 | editing_number=true; |
||
131 | return; |
||
132 | } |
||
133 | else |
||
134 | if ( keyCode==KEYCODE_CLEAR) |
||
135 | canvas.mk.params.set_field_from_act(canvas.mk.params.field_positions[act_tab][act_y/2-1],0); |
||
136 | } |
||
137 | editing_number=false; |
||
138 | |||
139 | switch (action) |
||
140 | { |
||
141 | |||
142 | case Canvas.RIGHT: |
||
143 | switch(canvas.mk.params.field_types[act_tab][act_y/2-1]) |
||
144 | { |
||
145 | case PARAMTYPE_BITSWITCH: |
||
146 | |||
147 | canvas.mk.params.field_from_act_xor((canvas.mk.params.field_positions[act_tab][act_y/2-1]/8),1<<(canvas.mk.params.field_positions[act_tab][act_y/2-1]%8)); |
||
148 | break; |
||
149 | case PARAMTYPE_BYTE: |
||
150 | case PARAMTYPE_STICK: |
||
151 | |||
152 | canvas.mk.params.field_from_act_add(canvas.mk.params.field_positions[act_tab][act_y/2-1],1); |
||
153 | break; |
||
154 | } |
||
155 | break; |
||
156 | |||
157 | case Canvas.LEFT: |
||
158 | switch(canvas.mk.params.field_types[act_tab][act_y/2-1]) |
||
159 | { |
||
160 | case PARAMTYPE_BITSWITCH: |
||
161 | canvas.mk.params.field_from_act_xor((canvas.mk.params.field_positions[act_tab][act_y/2-1]/8),1<<(canvas.mk.params.field_positions[act_tab][act_y/2-1]%8)); |
||
162 | |||
163 | break; |
||
164 | case PARAMTYPE_BYTE: |
||
165 | case PARAMTYPE_STICK: |
||
166 | canvas.mk.params.field_from_act_add(canvas.mk.params.field_positions[act_tab][act_y/2-1],-1); |
||
167 | break; |
||
168 | } |
||
169 | |||
170 | |||
171 | break; |
||
172 | } |
||
173 | |||
174 | } |
||
175 | |||
176 | switch (action) |
||
177 | { |
||
178 | |||
179 | case Canvas.DOWN: |
||
180 | if (act_y<(act_lcd_lines-2)) act_y+=2; |
||
181 | else act_y=0; |
||
182 | break; |
||
183 | |||
184 | case Canvas.UP: |
||
185 | if (act_y!=0) act_y-=2; |
||
186 | else act_y=act_lcd_lines-1; |
||
187 | break; |
||
188 | |||
189 | } |
||
190 | |||
191 | refresh_lcd(); |
||
192 | |||
193 | |||
194 | } |
||
195 | } |
||
196 |