package CITableTest;

import java.awt.Color;

/**
* @author  Somchai LIMSIRORATANA, Nuntiya LIMSIRORATANA(Yawai)
* @version 1.1
* @author Weerasak WITTAWASKUL
* 1MAY2003 Move setDefaultCellEditorRenderer to CellIndependentTable.java
*          Add toggleModel to support model switch between data1 and data2
*/
public class TestCITable extends javax.swing.JFrame {
    private boolean toggleModel = true;
    Object[][] data1 = {{"ID", new Integer(1234)},
                       {"Name", "Somchai"},
                       {"Family Name", "LIMSIRORATANA"},
                       {"Weight", new Float(62.8)},
                       {"Single", new Boolean(false)},
                       {"Hair Color", new Color(20, 0, 0)},
                       {"File", new FileName("C:\\TEMP\\Test.txt")}
                      };
    String[] colname1 = {"Properties","Value"};

    Object[][] data2 = {{"Student1", new Integer(12), new Float(1.45), new Color(0,0,0)},
                        {"Student2", new Long(4567890), new Color(0,0,0), new Boolean(true)},
                        {"Student3", new Double(123456), new FileName("C:\\TEMP\\Test1.dat"), new Integer(0)},
                        {"Student4", new Float(24.56), "Nothing" , new Boolean(false)}
                      };
    String[] colname2 = {"Name","Any", "Any", "Any"};

    CellIndependentTable table;
    /** Creates new form TestProperties */
    public TestCITable() {
        table = new CellIndependentTable(new CellIndependentTableModel(data1,colname1));
        initComponents();
    }

    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        jScrollPane1 = new javax.swing.JScrollPane();
        jButton1 = new javax.swing.JButton();

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });

        jScrollPane1.setViewportView(table);
        getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jButton1.setText("Change Data");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        getContentPane().add(jButton1, java.awt.BorderLayout.NORTH);

        pack();
    }//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        if (toggleModel)
            table.setModel(new CellIndependentTableModel(data2,colname2));
        else
            table.setModel(new CellIndependentTableModel(data1,colname1));
        toggleModel = !toggleModel;
    }//GEN-LAST:event_jButton1ActionPerformed

    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
        javax.swing.table.TableModel model = table.getModel();
        int nrow = model.getRowCount();
        int ncol = model.getColumnCount();
        for (int r=0; r<nrow; r++) {
            for (int c=0; c<ncol; c++) {
                Object value = model.getValueAt(r,c);
                System.out.print(value.toString()+",\t");
            }
            System.out.println();
        }
        System.exit(0);
    }//GEN-LAST:event_exitForm

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        new TestCITable().show();
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jButton1;
    // End of variables declaration//GEN-END:variables

}