/*
 * OutputDataModelXY.java
 *
 * Created on Ketvirtadienis, 2007, Sausio 25, 17.13
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package Main.data;

import java.util.*;
import javax.swing.table.*;

public class OutputDataModelXY extends AbstractTableModel
{
	private Vector dataList;
	static final public String columns[] = {"N.","X0", "Y0"};
    static final public int initLengths[] = { 20, 40, 40 };
    static final public int NUM_COLUMNS = columns.length;
	
	
	public OutputDataModelXY()
	{
		super();
        setDefaultList();
	}
	
	public void setDefaultList()
    {
       	dataList= new Vector(100);
		/*for(int i= 0; i<20; i++)
		{
			dataList.addElement( new OutputDataSlotXY());
		}*/
    }
    	
	public Vector getData()
	{return dataList;}
    	
	public void setData(Vector data)
	{
		dataList= data;
		fireTableDataChanged();
	}
	
	public void setDataAsArray(double[][] matrixXY)
	{
		Vector data= new Vector();
		if(matrixXY != null)
		for(int i= 0;i<matrixXY.length;i++)
		{
			data.add(new OutputDataSlotXY( matrixXY[i][0],matrixXY[i][1])); // Cia sukeiciau X ir Y outputa vietomis
		}
		
		setData(data);
	}
    	
    public Object getValueAt(int row,int col)
	{
	        if (row < 0 || row>=getRowCount())
	            return "";
	        OutputDataSlotXY r = (OutputDataSlotXY)dataList.elementAt(row);
	        switch (col)
	        {
				case 0:
					return new Integer(row);
	            case 1:
	                return new Float(r.getX());
	            case 2:
	                return new Float(r.getY());
	        }
	        return "";
	    }
	
    public  void  setValueAt ( Object object, int row, int col )
    {
        if (row < 0 || row>=getRowCount())
            return;
        OutputDataSlotXY r = (OutputDataSlotXY)dataList.elementAt(row);
        switch (col)
        {
            case 1:
                r.setX(new Float((String)object).floatValue());
				break;
            case 2:
				r.setY(new Float((String)object).floatValue());
				break;

        }

	}

	public int getRowCount()
	{
		return dataList.size();
	}
	
	public int getColumnCount()
	{
		return NUM_COLUMNS; 
	}
	
	public  Object  getRow ( int index )
    {
        return dataList.elementAt(index);
    }
	
	public boolean isCellEditable(int row, int col)
    {
		return false;
    }
	
	public void setData(double[][] data)
	{
		for(int i= 0;i< data[0].length;i++)
		{
			OutputDataSlotXY temp= (OutputDataSlotXY)dataList.get(i);
			temp.setY(data[1][i]);
                        temp.setX(data[0][i]);
			
		}
	}
	
   	
    	
}