Rev 220 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/********************************************************
*
* class to handle Editing of MK Params via MIDP / J2ME
*
* Author: Marcus -LiGi- Bueschleb
*
********************************************************/
import javax.microedition.lcdui.*;
public class MKParamsEditor
implements org.
ligi.
ufo.
MKParamDefinitions
{
private int act_tab=
0;
public int act_y=
0;
private int act_lcd_lines=
10;
DUBwiseCanvas canvas
;
// org.ligi.ufo.MKCommunicator _mk;
public String[] lcd_lines
;
public MKParamsEditor
(DUBwiseCanvas _canvas
)
{
canvas=_canvas
;
lcd_lines=
new String[40];
// refresh_lcd();
}
public void paint
( Graphics g
)
{
refresh_lcd
();
canvas.
paint_lcd(g,
false);
}
public void refresh_lcd
()
{
if (canvas.
mk!=
null)
{
act_lcd_lines=canvas.
mk.
params.
field_names[act_tab
].
length*2+
1;
for ( int i=
0;i
<act_lcd_lines
;i++
)
lcd_lines
[i
]=
"";
try
{
lcd_lines
[0]=
(act_tab==
0?" ":
"< ") + canvas.
mk.
params.
tab_names[act_tab
] +
(act_tab==
(canvas.
mk.
params.
tab_names.
length-
1)?" ":
" >");
for (int i=
0;i
<canvas.
mk.
params.
field_names[act_tab
].
length;i++
)
{
lcd_lines
[1+
2*i
]=canvas.
mk.
params.
field_names[act_tab
][i
];
if (canvas.
mk.
params.
field_types[act_tab
][i
]== canvas.
mk.
params.
PARAMTYPE_BITSWITCH)
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" ) ;
if (canvas.
mk.
params.
field_types[act_tab
][i
]== canvas.
mk.
params.
PARAMTYPE_BYTE)
{
lcd_lines
[2+
2*i
]=
""+canvas.
mk.
params.
get_field_from_act(canvas.
mk.
params.
field_positions[act_tab
][i
]);
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))
lcd_lines
[2+
2*i
]+=
"[Poti"+
(canvas.
mk.
params.
get_field_from_act(canvas.
mk.
params.
field_positions[act_tab
][i
])-
250) +
"]";
}
if (canvas.
mk.
params.
field_types[act_tab
][i
]== canvas.
mk.
params.
PARAMTYPE_STICK)
{
lcd_lines
[2+
2*i
]=
""+canvas.
mk.
params.
get_field_from_act(canvas.
mk.
params.
field_positions[act_tab
][i
]);
}
}
for (int i=
0;i
<act_lcd_lines
;i++
)
{
lcd_lines
[i
]=
(act_y==i
?"#":
" ")+lcd_lines
[i
];
}
for ( int i=
0;i
<act_lcd_lines
;i++
)
while(lcd_lines
[i
].
length()<20)
{
lcd_lines
[i
]+=
" ";
}
}
catch (Exception e
){}
canvas.
lcd_lines=
new String[act_lcd_lines
];
for(int i=
0;i
<act_lcd_lines
;i++
)
canvas.
lcd_lines[i
]=lcd_lines
[i
];
}
else
{
canvas.
lcd_lines=
new String[1];
canvas.
lcd_lines[0]=
"reading params";
}
}
public final static int KEYCODE_CLEAR=-
8;
public boolean editing_number=
false;
public void keypress
(int keyCode,
int action
)
{
if (act_y==
0) switch (action
)
{
case Canvas.
RIGHT:
if (act_tab
<canvas.
mk.
params.
tab_names.
length-
1) act_tab++
;
break;
case Canvas.
LEFT:
if (act_tab
!=
0) act_tab--
;
break;
}
else
{
if(canvas.
mk.
params.
field_types[act_tab
][act_y/
2-
1]==canvas.
mk.
params.
PARAMTYPE_BYTE)
{
if ((keyCode
>=
Canvas.
KEY_NUM0) && (keyCode
<=
Canvas.
KEY_NUM9))
{
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))
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));
else
canvas.
mk.
params.
set_field_from_act(canvas.
mk.
params.
field_positions[act_tab
][act_y/
2-
1] ,
(keyCode -
Canvas.
KEY_NUM0));
editing_number=
true;
return;
}
else
if ( keyCode==KEYCODE_CLEAR
)
canvas.
mk.
params.
set_field_from_act(canvas.
mk.
params.
field_positions[act_tab
][act_y/
2-
1],
0);
}
editing_number=
false;
switch (action
)
{
case Canvas.
RIGHT:
switch(canvas.
mk.
params.
field_types[act_tab
][act_y/
2-
1])
{
case PARAMTYPE_BITSWITCH:
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
));
break;
case PARAMTYPE_BYTE:
case PARAMTYPE_STICK:
canvas.
mk.
params.
field_from_act_add(canvas.
mk.
params.
field_positions[act_tab
][act_y/
2-
1],
1);
break;
}
break;
case Canvas.
LEFT:
switch(canvas.
mk.
params.
field_types[act_tab
][act_y/
2-
1])
{
case PARAMTYPE_BITSWITCH:
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
));
break;
case PARAMTYPE_BYTE:
case PARAMTYPE_STICK:
canvas.
mk.
params.
field_from_act_add(canvas.
mk.
params.
field_positions[act_tab
][act_y/
2-
1],-
1);
break;
}
break;
}
}
switch (action
)
{
case Canvas.
DOWN:
if (act_y
<(act_lcd_lines-
2)) act_y+=
2;
else act_y=
0;
break;
case Canvas.
UP:
if (act_y
!=
0) act_y-=
2;
else act_y=act_lcd_lines-
1;
break;
}
refresh_lcd
();
}
}