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

public class classicTheme extends windowTheme{
Image grad;
Vector v;
int r1,g1,b1,r2,g2,b2;
int offY;
int clox,cloy,minx,miny,maxx,maxy;
int rc,gc,bc;
int captionY;

public classicTheme(){
super();
loadConfig(z.getInput("config.cfg"));
try{
	grad = Image.createImage(1,1);
	min = Image.createImage(z.getInput("min.png"));
	max = Image.createImage(z.getInput("max.png"));
	clo = Image.createImage(z.getInput("clo.png"));
	lu = Image.createImage(2,2);
	ld = Image.createImage(2,2);
	ru = Image.createImage(2,2);
	rd = Image.createImage(2,2);
	d = Image.createImage(1,2);
	u = Image.createImage(1,2);
	l = Image.createImage(2,1);
	r = Image.createImage(2,1);
	Image formimg = Image.createImage(z.getInput("windowborder.png"));
	Graphics h = lu.getGraphics();
	h.drawRegion(formimg, 0, 0, 2, 2, Sprite.TRANS_NONE, 0, 0, 20);
	h = ru.getGraphics();
	h.drawRegion(formimg, 2, 0, 2, 2, Sprite.TRANS_NONE, 0, 0, 20);
	h = ld.getGraphics();
	h.drawRegion(formimg, 0, 2, 2, 2, Sprite.TRANS_NONE, 0, 0, 20);
	h = rd.getGraphics();
	h.drawRegion(formimg, 2, 2, 2, 2, Sprite.TRANS_NONE, 0, 0, 20);
	h = l.getGraphics();
	h.drawRegion(formimg, 0, 1, 2, 1, Sprite.TRANS_NONE, 0, 0, 20);
	h = r.getGraphics();
	h.drawRegion(formimg, 2, 1, 2, 1, Sprite.TRANS_NONE, 0, 0, 20);
	h = u.getGraphics();
	h.drawRegion(formimg, 1, 0, 1, 2, Sprite.TRANS_NONE, 0, 0, 20);
	h = d.getGraphics();
	h.drawRegion(formimg, 1, 2, 1, 2, Sprite.TRANS_NONE, 0, 0, 20);
} catch (Exception e){}
}

public void loadConfig(InputStream is){
v = getFile(is);
captionY = toInt(0);
minx = toInt(1);
miny = toInt(2);
maxx = toInt(3);
maxy = toInt(4);
clox = toInt(5);
cloy = toInt(6);
r1 = toInt(7);
g1 = toInt(8);
b1 = toInt(9);
r2 = toInt(10);
g2 = toInt(11);
b2 = toInt(12);
cw = toInt(13);
ch = toInt(14);
miw = toInt(15);
mih = toInt(16);
maw = toInt(17);
mah = toInt(18);
offsetX = toInt(19);
offsetY = toInt(20);
offY = toInt(21);
rc = toInt(22);
gc = toInt(23);
bc = toInt(24);
offsetXC = offsetX;
offsetYC = offsetY;
}

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 resize(int wid,int hei){
grad = Image.createImage(wid,offY);
Graphics g = grad.getGraphics();
ImageUtils.gradient(g,r1,g1,b1,r2,g2,b2,0,0,wid,offY);
u = ImageUtils.resize_image(u,wid,offsetX);
d = ImageUtils.resize_image(d,wid,offsetX);
l = ImageUtils.resize_image(l,offsetX,hei+offY);
r = ImageUtils.resize_image(r,offsetX,hei+offY);
}

public void drawBorder(Graphics g,int x,int y,int wid,int hei){
//ImageUtils.gradient(g,0,0,128,16,132,208,x+2,y+2,wid,18);
g.drawImage(grad,x+offsetX,y+2,20);
g.drawImage(lu,x,y,20);
g.drawImage(ru,x+wid+offsetX,y,20);
g.drawImage(rd,x+wid+offsetX,y+hei+offsetY,20);
g.drawImage(ld,x,y+hei+offsetY,20);
g.drawImage(u,x+offsetX,y,20);
g.drawImage(l,x,y+2,20);
g.drawImage(r,x+wid+offsetX,y+2,20);
g.drawImage(d,x+offsetX,y+hei+offsetY,20);
}

public void drawName(Graphics g,String name,int x,int y,int wid){
int neww = wid-(cw+miw+maw+9);
FC.setColor(255,rc,gc,bc);
FC.drawString(g,name,x+offsetX+12,y+captionY-3,x+neww+minx+offsetX,y+13);
}

public void drawIcon(Graphics g,int x,int y,int wid){
g.drawImage(ico,x+offsetX+2,y+captionY,20);
}

public void updateControlPos(int x,int y,int wid,int hei,Sprite min,Sprite max,Sprite clo){
int cpx = x+offsetX+wid-cw;
int mapx = cpx-(maw+2);
int mipx = mapx-(miw+1);
min.setPosition(mipx+minx,y+miny);
max.setPosition(mapx+maxx,y+maxy);
clo.setPosition(cpx+clox,y+cloy);
}

public int getClick(int x,int y,int wid,int hei){
if(y<=offsetY){
	int cpx = cw+offsetX;
	int mapx = cpx+(maw+2);
	int mipx = mapx+(miw+1);
	cpx+=clox;
	mapx+=maxx;
	mipx+=minx;
	if(x>=wid-mipx && x<=wid-(mipx-miw) && y>=miny && y<=miny+mih){
		return 3;
	}
	if(x>=wid-mapx && x<=wid-(mapx-maw) && y>=maxy && y<=maxy+mah){
		return 4;
	}
	if(x>=wid-cpx && x<=wid-(cpx-cw) && y>=cloy && y<=cloy+ch){
		return 5;
	}
	return 1;
}
if(y>=hei+(offsetY-(offsetX*2.5)) && x>=wid-(offsetX*2.5)){
	return 2;
}
if(x>=offsetX && y>=offsetY && x<=wid+offsetX && y<=hei+offsetY){
	return 6;
}
return 0;
}

public abcd getXYWHMax(int wid,int hei){
return new abcd(-1,-1,wid+offsetX,hei+offsetY-offsetX);
}

public point getXYClick(int x,int y){
return new point(x-offsetX,y-offsetY);
}

}