Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 221 → Rev 220

/DUBwise/trunk/j2me/src/DUBwiseCanvas.java
13,7 → 13,15
import javax.microedition.media.control.*;
 
 
//#if fileapi=="on"
import javax.microedition.io.*;
import javax.microedition.midlet.*;
import javax.microedition.io.file.*;
 
import java.io.*;
import java.util.*;
//#endif
 
public class DUBwiseCanvas
extends Canvas
implements Runnable,org.ligi.ufo.DUBwiseDefinitions , DUBwiseUIDefinitions
20,7 → 28,23
{
 
//#if fileapi=="on"
DUBwiseFileAccess file_access;
public final static int MAX_FILELIST_LENGTH=100;
public final static int MAX_PATH_DEPTH=10;
 
byte act_path_depth=0;
String[] act_path_arr;
 
 
public String act_path()
{
String res="";
for (int i=0;i<act_path_depth;i++)
res+=act_path_arr[i];
return res;
}
 
String[] file_list;
int file_list_length=0;
//#endif
 
String act_input_str=" ";
41,6 → 65,8
int heading_offset=0;
int act_wp;
 
 
//#if bluetooth=="on"
private BTSearcher bt_scanner;
//#endif
82,8 → 108,7
public int[] graph_sources={0,1,2,3};
public String[] graph_names={"nick int","roll int","nick acc","roll acc"};
public int[][] graph_data;
public int graph_offset=0;
 
public int lcd_char_width=0;
public int lcd_char_height=0;
 
270,7 → 295,7
 
}
paint_lcd(g);
paint_lcd(g,true);
}
 
public void menu_keypress(int keyCode)
298,19 → 323,19
 
public boolean cam_condition()
{
return (mk.stick_data.stick[settings.remote_cam_stick]>100);
return (mk.stick_data.stick[5]>100);
}
 
// int lcd_top=25;
 
public void paint_lcd(Graphics g)
public void paint_lcd(Graphics g,boolean bottomup)
{
 
int y;
 
// int lcd_top= (state==STATEID_EDIT_PARAMS?0:25);
//int lcd_top= 25;
max_lines=(canvas_height-25/*lcd_top*/)/lcd_char_height;
int lcd_top= 25;
max_lines=(canvas_height-lcd_top)/lcd_char_height;
 
int spacer_left_right=(canvas_width-(20*(lcd_img.getWidth()/222)))/2;
// for(int i=0;i<lcd_lines.length;i++)
324,11 → 349,10
for(int i=0;i<display_lines;i++)
for (int pos=0;pos<20;pos++)
{
/*if (!bottomup)
if (bottomup)
y=canvas_height-(display_lines-i)*lcd_char_height;
else
y=i*lcd_char_height;
else*/
y=canvas_height-(display_lines-i)*lcd_char_height;
 
g.setClip((lcd_img.getWidth()/222)*pos+spacer_left_right,y,(lcd_img.getWidth()/222),lcd_img.getHeight());
g.drawImage(lcd_img,spacer_left_right+(lcd_img.getWidth()/222)*pos-((pos<lcd_lines[i+lcd_off].length()?lcd_lines[i+lcd_off].charAt(pos):' ')-' ')*(lcd_img.getWidth()/222),y,g.TOP | g.LEFT);
335,7 → 359,7
}
}
 
public void load_skin_images()
public void load_images()
{
try
{
347,37 → 371,39
{
case SKINID_DARK:
lcd_img=Image.createImage("/lcd_green.png");
if (settings.do_scrollbg) bg_img=Image.createImage("/starfield.jpg");
break;
if (settings.do_scrollbg) bg_img=Image.createImage("/starfield.jpg"); break;
 
case SKINID_LIGHT:
lcd_img=Image.createImage("/lcd_blue.png");
if (settings.do_scrollbg) bg_img=Image.createImage("/clouds.jpg");
break;
}
lcd_char_width=lcd_img.getWidth()/222;
lcd_char_height=lcd_img.getHeight();
}
 
catch (Exception e)
{
debug.err(e.toString());
}
 
}
public void load_global_images()
{
try
{
// bt_img=Image.createImage("/bt.png");
symbols_img=Image.createImage("/symbols.png");
// load_img=Image.createImage("/load.png");
 
lcd_char_width=lcd_img.getWidth()/222;
lcd_char_height=lcd_img.getHeight();
 
/* if (bg_img!=null)
 
if (bg_img!=null)
graph_data=new int[GRAPH_COUNT][bg_img.getWidth()];
else
*/
graph_data=new int[GRAPH_COUNT][this.getWidth()*2];
 
for (int c=0;c<graph_data[0].length;c++)
for (int d=0;d<GRAPH_COUNT;d++)
graph_data[d][c]=-1;
 
try {
err_img=null;
err_img=Image.createImage("/preflight.jpg");
}
catch (Exception e) { }
 
}
catch (Exception e)
387,12 → 413,12
}
 
// construct
public DUBwiseCanvas(DUBwise _root)
{
 
//#if fileapi=="on"
file_access=new DUBwiseFileAccess(this);
file_list= new String[MAX_FILELIST_LENGTH];
act_path_arr=new String[MAX_PATH_DEPTH];
//#endif
 
root=_root;
401,7 → 427,6
helper = new DUBwiseHelper();
settings = new DUBwiseSettings(this);
settings.load();
load_global_images();
debug = new DUBwiseDebug(this);
 
//#if bluetooth=="on"
409,30 → 434,37
//#endif
 
 
 
//#if voice_mode!="no_voice"
status_voice=new MKStatusVoice(mk,this);
//#endif
// load_images();
 
if (settings.connection_url!="")
connect_mk(settings.connection_url,settings.connection_name);
mk.gps_position.act_speed_format=settings.speed_format;
mk.gps_position.act_gps_format= settings.gps_format;
 
 
chg_state(STATEID_MAINMENU);
 
new Thread(this).start();
 
if (settings.connection_url!="")
connect_mk(settings.connection_url,settings.connection_name);
}
 
 
 
/****************************** Thread ******************/
// ticking runnable Section
public void run()
{
 
 
while(true)
{
try {
464,13 → 496,6
switch(state)
{
 
case STATEID_GRAPH:
graph_offset--;
if (graph_offset==-graph_data[0].length)
graph_offset=0;
break;
 
case STATEID_CAMMODE:
try
481,7 → 506,6
debug.log("get snap\n");
cam_raw = mVideoControl.getSnapshot(null);
try { Thread.sleep(4000); }
catch (Exception e)
{
488,12 → 512,11
debug.log("Problem Sleeping ");
}
cam_img = Image.createImage(cam_raw, 0, cam_raw.length);
}
else
{
if (cam_img==null)
;;
cam_img = Image.createImage(cam_raw, 0, cam_raw.length);
}
}
catch ( Exception e)
609,22 → 632,12
root.quit();
}
 
 
try {
//rescan=false;
 
if (bg_img!=null)
{
bg_offset--;
if (bg_offset==-bg_img.getWidth())
bg_offset=0;
}
 
 
 
bg_offset--;
if (bg_offset==-graph_data[0].length)
bg_offset=0;
//#if devicecontrol=="on"
 
try {
if (settings.keep_lighton) com.nokia.mid.ui.DeviceControl.setLights(0,100);
//#endif
}
734,7 → 747,7
 
 
//draw background
if (!settings.do_scrollbg)
if ((!settings.do_scrollbg) || (state==STATEID_EDIT_PARAMS))
{
g.setColor(0xdedfff);
g.fillRect(0,0,canvas_width,symbols_img.getHeight());
866,7 → 879,7
g.setClip(err_img_left,err_img_top,err_img.getWidth()/2,err_img.getHeight());
g.drawImage(err_img,err_img_left-err_img.getWidth()/2,err_img_top, g.TOP | g.LEFT);
}
paint_lcd(g);
paint_lcd(g,true);
 
break;
 
982,13 → 995,13
 
if (cam_img!=null)
g.drawImage(cam_img,0,0,g.TOP | g.LEFT);
g.drawString("condition: " + cam_condition() ,0,y_off,Graphics.TOP | Graphics.LEFT);
y_off+=spacer;
g.drawString("width " + cam_img.getWidth(),0,y_off,Graphics.TOP | Graphics.LEFT);
y_off+=spacer;
g.drawString("height " + cam_img.getHeight(),0,y_off,Graphics.TOP | Graphics.LEFT);
y_off+=spacer;
break;
g.drawString("condition: " + cam_condition() ,0,y_off,Graphics.TOP | Graphics.LEFT);
y_off+=spacer;
g.drawString("width " + cam_img.getWidth(),0,y_off,Graphics.TOP | Graphics.LEFT);
y_off+=spacer;
g.drawString("height " + cam_img.getHeight(),0,y_off,Graphics.TOP | Graphics.LEFT);
y_off+=spacer;
break;
 
case STATEID_STICKVIEW:
 
1052,7 → 1065,7
//#if fileapi=="on"
case STATEID_FILEOPEN:
y_off+=spacer;
g.drawString("act_path" + file_access.act_path() ,0,y_off,Graphics.TOP | Graphics.LEFT);
g.drawString("act_path" + act_path() ,0,y_off,Graphics.TOP | Graphics.LEFT);
paint_menu(g);
break;
//#endif
1059,17 → 1072,17
case STATEID_STRINGINPUT:
case STATEID_ABOUT:
case STATEID_IPINPUT:
paint_lcd(g);
paint_lcd(g,true);
break;
 
case STATEID_READ_PARAMS:
paint_lcd(g);
paint_lcd(g,true);
break;
 
 
//#if bluetooth=="on"
case STATEID_SCANNING:
paint_lcd(g);
paint_lcd(g,true);
break;
//#endif
case STATEID_RAWDEBUG:
1228,7 → 1241,7
 
g.setColor(graph_colors[gr]);
try {
graph_data[gr][-graph_offset]=mk.debug_data.analog[graph_sources[gr]];
graph_data[gr][-bg_offset]=mk.debug_data.analog[graph_sources[gr]];
}
catch (Exception e)
{
1240,7 → 1253,7
 
for ( int x=0;x<canvas_width;x++)
{
int p= (((-graph_offset+x-canvas_width-5)));
int p= (((-bg_offset+x-canvas_width-5)));
if (p<1)
p+=graph_data[0].length;
p%=(graph_data[0].length-1);
1321,7 → 1334,6
Player mPlayer;
VideoControl mVideoControl;
Image cam_img;
Image last_cam_img;
int cam_img_seq=0;
byte[] cam_raw;
 
1370,27 → 1382,11
{
settings_editor = null;
params_editor = null;
err_img=null;
graph_data=null;
 
 
if (next_state!=state)act_menu_select=0;
// prepare next state
switch(next_state)
{
case STATEID_NC_ERRORS:
lcd_lines=new String[1];
lcd_lines[0]=""+mk.error_str;
try
{
err_img=Image.createImage("/preflight.jpg");
}
catch (Exception e)
{
debug.log("problem loading error image");
}
break;
case STATEID_EDIT_PARAMS:
params_editor = new MKParamsEditor(this,mk.params,STATEID_HANDLE_PARAMS);
break;
1411,7 → 1407,64
 
//#if fileapi=="on"
case STATEID_FILEOPEN:
file_access.trigger();
if (act_path_depth==0)
{
Enumeration drives = FileSystemRegistry.listRoots();
int tmp_i=0;
while(drives.hasMoreElements())
{
file_list[tmp_i]= (String) drives.nextElement();
tmp_i++;
if (MAX_FILELIST_LENGTH<tmp_i)
break;
}
menu_items=new String[tmp_i];
lcd_lines=new String[tmp_i];
file_list_length=tmp_i;
for(tmp_i=0;tmp_i<file_list_length;tmp_i++)
menu_items[tmp_i]=file_list[tmp_i];
 
}
else
{
 
try {
FileConnection fc = (FileConnection) Connector.open("file:///"+act_path());
Enumeration filelist = fc.list("*", true);
int tmp_i=0;
while(filelist.hasMoreElements()) {
file_list[tmp_i] = (String) filelist.nextElement();
tmp_i++;
/* fc = (FileConnection)
Connector.open("file:///CFCard/" + fileName);
if(fc.isDirectory()) {
System.out.println("\tDirectory Name: " + fileName);
} else {
System.out.println
("\tFile Name: " + fileName +
"\tSize: "+fc.fileSize());
}*/
}
menu_items=new String[tmp_i+1];
lcd_lines=new String[tmp_i+1];
file_list_length=tmp_i+1;
menu_items[0]="..";
for(tmp_i=1;tmp_i<file_list_length;tmp_i++)
menu_items[tmp_i]=file_list[tmp_i-1];
 
 
fc.close();
} catch (IOException ioe) {
System.out.println(ioe.getMessage());
}
}
 
 
break;
//#endif
 
1432,6 → 1485,11
break;
 
 
case STATEID_NC_ERRORS:
lcd_lines=new String[1];
lcd_lines[0]=""+mk.error_str;
break;
 
case STATEID_ABOUT:
lcd_lines=credits;
lcd_lines[1]=" ufo-lib: " + mk.lib_version_str();
1440,11 → 1498,14
case STATEID_CONN_DETAILS:
setup_menu(conn_details_menu_items,conn_details_menu_actions);
break;
 
 
 
case STATEID_TRAFFIC:
setup_menu(onlyback_menu_items,back_to_conndetails_actions);
break;
case STATEID_CAMMODE:
mk.user_intent=USER_INTENT_RCDATA;
if (mVideoControl==null)
try
{
1566,13 → 1627,6
 
 
case STATEID_GRAPH:
graph_data=new int[GRAPH_COUNT][this.getWidth()*2];
for (int c=0;c<graph_data[0].length;c++)
for (int d=0;d<GRAPH_COUNT;d++)
graph_data[d][c]=-1;
mk.user_intent=USER_INTENT_GRAPH;
break;
 
1709,7 → 1763,7
debug.process_key(keyCode);
if ((keyCode==KEY_STAR) || (keyCode==settings.key_back) )//&&(state!= STATEID_STRINGINPUT))
if (((keyCode==KEY_STAR) || (keyCode==113) ))//&&(state!= STATEID_STRINGINPUT))
{
if (state==STATEID_EDIT_PARAMS)
{
1726,7 → 1780,7
}
 
 
if (((keyCode==KEY_POUND)||(keyCode==settings.key_fullscreen))&&(state!=STATEID_KEYCONTROL))
if ((keyCode==KEY_POUND)&&(state!=STATEID_KEYCONTROL))
{
settings.toggle_fullscreen();
 
2026,7 → 2080,24
case STATEID_FILEOPEN:
if ( getGameAction (keyCode)==FIRE )
{
file_access.fire();
if ((act_menu_select==0)&&(act_path_depth!=0))
{
act_path_depth--;
//act_path=act_path.substring(0,act_path.substring(0,act_path.length()-2).indexOf('/') );
 
//act_path=last_path;
}
else
{
//last_path=act_path;
if (act_path_depth==0)
act_path_arr[act_path_depth++]=file_list[act_menu_select];
else
act_path_arr[act_path_depth++]=file_list[act_menu_select-1];
}
act_menu_select=0;
chg_state(STATEID_FILEOPEN);
}
else
menu_keypress(keyCode);