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

package Main.panels;

import java.text.*;

import Main.data.*;


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

public class RezultsPanel extends JPanel implements TableModelListener
{
	private JTable mTable;
	private OutputDataModelXY mData;
	public RezultsPanel()
	{
		setLayout(new BorderLayout());
		mTable= new JTable();
		mTable.setAutoCreateColumnsFromModel(false);
		mTable.setPreferredScrollableViewportSize(new Dimension(300, 200));
		mData= new OutputDataModelXY();
		mTable.setModel(mData);
		
		for (int k = 0; k < OutputDataModelXY.NUM_COLUMNS; k++)
        {
            TableColumn column;      

            JTextField t= new JTextField("");
            
		   
		   	if(k == 0)
		   	{
				column = new TableColumn(k, 
				OutputDataModelXY.initLengths[k], new DefaultTableCellRenderer(), 
				null );                
				column.setMinWidth(40);
		   	}
		   	else
		   	{
				column = new TableColumn(k, 
				OutputDataModelXY.initLengths[k], new FormatedRenderer(), 
				new DefaultCellEditor(t) );                
				column.setMinWidth(40);
			}
			column.setHeaderValue(OutputDataModelXY.columns[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 tableChanged(TableModelEvent e)
	{
		Object obj= e.getSource();
		/*if(obj instanceof TableModel)
		System.out.println("Value changed");*/	    
	}				
	
	public OutputDataModelXY getOutputModel()
	{
		return mData;
	}
	
}

