Rev 4 |
Blame |
Last modification |
View Log
| RSS feed
/**************************************************
*
* class to handle Editing of MK Params
*
* Author: Marcus -LiGi- Bueschleb
*
* see README for further Infos
*
*************************************************/
import javax.microedition.lcdui.*;
public class MKParamsEditor
implements MKParamDefinitions
{
private int act_tab=
0;
private int act_y=
0;
private int act_lcd_lines=
10;
MKMiniCanvas canvas
;
public String[] lcd_lines
;
public MKParamsEditor
(MKMiniCanvas _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
();
}
}