import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import mishin870.*;
import net.sf.zipme.*;
import java.util.*;
import java.io.*;

public class vistaDownTheme extends downTheme{
Image down;
Image st;
Vector v;
int soffX,soffY;
int poffX,poffY;
int asoffY;

public vistaDownTheme(int wid,int hei){
super();
loadConfig(Main.midlet.getInput("dconfig.cfg"),wid,hei);
try{
	st = Image.createImage(Main.midlet.getInput("start.png"));
	down = Image.createImage(Main.midlet.getInput("downbar.png"));
	down = ImageUtils.resize_image(down,wid,14);
} catch (Exception e){}
}

public void loadConfig(InputStream is,int wid,int hei){
v = getFile(is);
soffX = toInt(0);
soffY = toInt(1);
poffX = toInt(2);
poffY = toInt(3);
asoffY = (hei+soffY)-(hei-14);
}

int toInt(int num){
return Integer.parseInt((String) v.elementAt(num));
}

public Vector getFile(InputStream is){
DataInputStream dis = new DataInputStream(is);
StringBuffer sb = new StringBuffer();
Vector ret = new Vector();
try{
	int ch=0;
	while((ch = dis.read())!=-1) {
		if(ch!=13 && ch!=10){
			sb.append((char) ((ch >= 0xc0 && ch <= 0xFF) ? (ch + 0x350) : ch));
		} else {
			ch = dis.read();
			ret.addElement(sb.toString());
			sb = new StringBuffer();
		}
	}
	ret.addElement(sb.toString());
} catch (Exception e){}
return ret;
}

public void paint(Graphics g,int wid,int hei){
g.drawImage(down,0,hei-14,20);
g.drawImage(st,0,hei+soffY,20);
int x=poffX,y=hei+poffY;
for(int i=0;i<w.size();i++){
	DownBarItem temp = (DownBarItem)w.elementAt(i);
	temp.paint(g,x,y);
	x+=11;
}
}

public int checkClick(int cx,int cy){
if(cx>=soffX && cx<=soffX+st.getWidth() && cy>=14+soffY && cy<=14+soffY+st.getHeight()){
	return 1;
}
int x=poffX,y=14+poffY;
for(int i=0;i<w.size();i++){
	if(cx>=x && cy>=y && cx<=x+8 && cy<=y+8){
		return i+2;
	}
	x+=11;
}
return 0;
}

}