package omaTable;

import java.awt.*;

public class TableEvent extends AWTEvent
{

    public static final int TABLE_ID_MASK = 2000;
    public static final int SELECTED = 0;
    public static final int DESELECTED = 1;
    public static final int DOUBLE_CLICK = 2;
    public static final int RIGHT_CLICK = 3;
    private Object fields[];
    private int column;
    private int rowPos;
    private int rowIndex;
    private int selectionType;
    static String version;
    static boolean evaluation = false;
    static Frame f;

    public int getColumn()
    {
        return column;
    }

    public Object getSelectedCell()
    {
        if(fields != null && column >= 0 && column < fields.length)
            return fields[column];
        else
            return null;
    }

    static void showEvaluation(Component component)
    {
        if(f == null)
        {
            f = new Frame("ObjectPlanet Evaluation");
            f.setLayout(new GridLayout(0, 1));
            f.setBackground(Color.yellow.brighter());
            f.add(new Label("ObjectPlanet's Table Component v" + version, 1));
            f.add(new Label("Copyright by ObjectPlanet 1999-2001", 1));
            f.add(new Label("Unregistered evaluation version", 1));
            f.add(new Label("This window removed with purchase", 1));
            f.add(new Label("Purchase at http://objectplanet.com/purchase.html", 1));
        }
        if(!f.isShowing())
        {
            while(!component.isShowing())
                try
                {
                    Thread.sleep(50L);
                }
                catch(InterruptedException _ex) { }
            f.pack();
            f.setVisible(true);
            component.requestFocus();
        }
    }

    public String toString()
    {
        Object obj = getSelectedCell();
        String s = rowIndex + " ";
        if(obj instanceof String)
            s += obj + " ";
        s += "row: " + rowPos + ", column: " + column + ", ";
        switch(selectionType)
        {
        case 0: // '\0'
            s += "SELECTED";
            break;

        case 1: // '\001'
            s += "DESELECTED";
            break;

        case 2: // '\002'
            s += "DOUBLE_CLICK";
            break;

        case 3: // '\003'
            s += "RIGHT_CLICK";
            break;
        }
        return s;
    }

    public TableEvent(Object obj, Object aobj[], int i, int j, int k, int l)
    {
        super(obj, 2000);
        fields = aobj;
        selectionType = i;
        column = j;
        rowPos = k;
        rowIndex = l;
    }

    public TableEvent(Object obj,int rivi)
    {
        super(obj, 2000);
        rowIndex = rivi;
    }
    public int getRowPos()
    {
        return rowPos;
    }

    public int getRowIndex()
    {
        return rowIndex;
    }

    static void closeEvaluation()
    {
        f.setVisible(false);
        f.dispose();
    }

    public int getSelectionType()
    {
        return selectionType;
    }

}
