// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   TableComponent.java

import java.awt.*;

public class TableComponent extends RoundedLedComponent
{

    TableComponent(int i, int j, int k, int l, Connection connection)
    {
        super(i, j, 501, 24, k);
        tableNumber = l;
        alreadyEntered = false;
        alreadyStarted = false;
        alreadyFinished = false;
        con = connection;
        num = new Label(l + ".", 1);
        num.setBackground(RoundedComponent.col[k]);
        num.reshape(93, 0, 20, 22);
        add(num);
        b = new Button(_German.JOIN);
        b.disable();
        b.reshape(0, 0, 64, 21);
        b.setBackground(Color.lightGray);
        add(b);
        pid = new int[4];
        PName = new Label[4];
        for(int i1 = 0; i1 < 4; i1++)
        {
            PName[i1] = new Label("  -");
            PName[i1].setBackground(RoundedComponent.col[k]);
            PName[i1].reshape(115 + 96 * i1, 0, 94, 22);
            add(PName[i1]);
        }

        nop = 0;
    }

    public boolean action(Event event, Object obj)
    {
        if(event.target == b)
        {
            b.disable();
            if(!alreadyStarted)
                con._joinTable(tableNumber);
            return true;
        } else
        {
            return false;
        }
    }

    void addPlayer(String s, int i)
    {
        if(!alreadyStarted && nop < 4)
        {
            pid[nop] = i;
            PName[nop].setText("  " + s);
            nop++;
            if(con.pid == i)
            {
                alreadyEntered = true;
                b.disable();
                setActiveState(2);
            } else
            if(!alreadyEntered)
                if(nop == 1)
                {
                    b.enable();
                    setActiveState(2);
                } else
                if(nop == 4)
                    b.disable();
        }
    }

    void finishedGame()
    {
        alreadyFinished = true;
        setActiveState(3);
    }

    public void paint(Graphics g)
    {
        if(currentRnd != null)
            g.drawImage(currentRnd, 70, 0, this);
        if(currentLed != null)
            g.drawImage(currentLed, 70, 0, this);
    }

    void removePlayer(int i)
    {
        if(pid[i] == con.pid)
        {
            alreadyEntered = false;
            if(!alreadyStarted)
                b.enable();
        } else
        if(!alreadyEntered && !alreadyStarted)
            b.enable();
        if(alreadyStarted)
        {
            PName[i].setText("  ** " + PName[i].getText().substring(2));
        } else
        {
            for(int j = i; j < nop - 1; j++)
            {
                PName[j].setText(PName[j + 1].getText());
                pid[j] = pid[j + 1];
            }

            nop--;
            PName[nop].setText("  -");
            pid[nop] = 0;
            if(nop == 0)
            {
                b.disable();
                setActiveState(0);
            }
        }
    }

    void setStatus(int i, int j, String as[])
    {
        alreadyStarted = j > 0;
        alreadyFinished = j > 1;
        nop = as.length;
        for(int k = 0; k < nop; k++)
            PName[k].setText(as[k]);

        num.setText(i + ".");
        if(!alreadyStarted && nop < 4 && nop > 0)
            b.enable();
        else
            b.disable();
        if(nop > 0)
            if(!alreadyStarted)
                setActiveState(2);
            else
            if(!alreadyFinished)
                setActiveState(1);
            else
                setActiveState(3);
    }

    void startGame()
    {
        alreadyStarted = true;
        b.disable();
        setActiveState(1);
    }

    void stopGame()
    {
        for(int i = 0; i < nop; i++)
            PName[i].setText("  -");

        alreadyEntered = false;
        alreadyStarted = false;
        alreadyFinished = false;
        nop = 0;
        setActiveState(0);
    }

    public void update(Graphics g)
    {
        paint(g);
    }

    static final int cHeight = 22;
    static final int ofs = 95;
    static final int wPName = 94;
    Label PName[];
    Label num;
    Button b;
    boolean alreadyEntered;
    boolean alreadyStarted;
    boolean alreadyFinished;
    int nop;
    int tableNumber;
    int pid[];
    Connection con;
}
