/* Copyright Andy C. Deck 1999 All rights reserved. */    
import java.awt.Event;

public class Item
{
   Item(){}
   Item(byte T,byte I,int P, int X, int Y, int R,int G,int B){
                type  = T;
                id    = I;
                press = (byte)P;
                x     = (short)X;
                y     = (short)Y;
                r     = (byte)R;
                g     = (byte)G;
                b     = (byte)B;
    }
    public byte id,type,press,r,g,b;
    public short x;
    public short y;

    public void basePoint(int x, int y){
        this.x = (short)x;
        this.y = (short)y;
        this.press = 0;
    }
}          

class itemList {
private byte[] buf = new byte[10000]; 
private int headsize = 12;

	public itemList(/* head size param?*/){}

	public int init(int x, int y, int wacomStat){
		buf[4] = (byte)(wacomStat!=Event.MOUSE_DOWN?-1:0);
		buf[5] = (byte)(x>>8);     //x hi
        	buf[6] = (byte)(x&0x00ff); //x lo
        	buf[7] = (byte)(y>>8);     //y hi
        	buf[8] = (byte)(y&0x00ff); //y lo  
		return headsize;
	}

	public void export(int cnt, connection con, Item i){
	   if(cnt<12){
		System.out.println("cnt less than 10:  "+cnt);
		con.close();
		return;
	   }
	   int dataLen = cnt - 2;
           buf[0] = (byte)(((int)dataLen>>8)&0x00ff);
           buf[1] = (byte)(dataLen&0x00ff);               
	   buf[2] = i.type;
	   buf[3] = i.id;
           buf[4] = (byte)(buf[4]==-1?-1:i.press);
	   buf[9]  = i.r;
           buf[10] = i.g;
           buf[11] = i.b;			
	   if(con!=null) con.sendStroke(buf,cnt);
	}

	public int addPoint(int cnt, int x, int y, int press){
	      if(cnt < (buf.length - 1))
	        buf[cnt++] = (byte) press;
	     return addPoint(cnt,x,y);
	}

	public int addPoint(int cnt, int x, int y){
	      if(cnt < (buf.length - 4)){
	 	buf[cnt++] = (byte)(x>>8);
        	buf[cnt++] = (byte)(x&0x00ff);
        	buf[cnt++] = (byte)(y>>8);
        	buf[cnt++] = (byte)(y&0x00ff);  
	      }
	      return cnt;
	}
}
