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

package Main.panels;

import Main.data.*;


import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
import java.awt.*;
//import javax.table.*;

public class RezultsComparingPanel extends JPanel implements TableModelListener
{
	private JTable mTable;
	private TableModel mData;
	private String[] mColumns= {"N.","X", "Y","X0-X", "Y0-Y"};
	public RezultsComparingPanel()
	{
		setLayout(new BorderLayout());
		mTable= new JTable();
		mTable.setAutoCreateColumnsFromModel(false);
		mTable.setPreferredScrollableViewportSize(new Dimension(300, 200));
		setData(null);
				
		for (int k = 0; k < mData.getColumnCount(); k++)
        {
            TableColumn column;      

            JTextField t= new JTextField("");
            
		   
		   	if(k == 0)
		   	{
				column = new TableColumn(k, 
				20, new DefaultTableCellRenderer(), 
				null );                
				column.setMinWidth(20);
		   	}
		   	else
		   	{
				column = new TableColumn(k, 
				40, new FormatedRenderer(), 
				null );                
				column.setMinWidth(40);
			}
			column.setHeaderValue(mData.getColumnName(k));			
			mTable.addColumn(column);
        }
            
  

	
		JScrollPane ps = new JScrollPane();
		ps.setSize(230, 250);
		JTableHeader header = mTable.getTableHeader();
		
		JViewport hv = new JViewport();
		hv.setLayout(new BoxLayout(hv, BoxLayout.X_AXIS));
		hv.add(header);
		ps.setColumnHeader(hv);
		ps.getViewport().add(mTable);
		
		header.setUpdateTableInRealTime(false);
		add(ps, BorderLayout.CENTER);
		mData.addTableModelListener(this);
		mTable.setVisible(true);
		


		
	}
	
	public void setData(Object[][] data)
	{
		if(data == null)
		{
			mData= new DefaultTableModel(new Object[][]{}, mColumns); 
		}
		else
		{
			mData= new DefaultTableModel(data, mColumns);
		}
		mTable.setModel(mData);
	}
	
	public void tableChanged(TableModelEvent e)
	{
		Object obj= e.getSource();
		/*if(obj instanceof TableModel)
		System.out.println("Value changed");*/	    
	}
	
	public TableModel getModel()
	{
		return mData;
	}
	
	/*public OutputDataModelXY getOutputModel()
	{
		return mData;
	}*/
	
}

