/*
 *  Panel for calendar of events
 *
 *  2004 - 2011 Frantisek Zboril jr.
 *  Faculty of Information Technology
 *  zborilf@fit.vutbr.cz
 *  http://www.fit.vutbr.cz/~zborilf
 *
 * (C) Brno University of Technology
 * Freeware licence VUT v Brně
 * https://wis.fit.vutbr.cz/FIT/db/dir.php/dr/VZ2007/externiInformace/softwareNaWebu/Priloha2_rozh23.pdf

 */

package jTGUI;

import jTMass.TMass;
import jTMass.core.jTMassSimulator.jTCalendar.TCalendarEvent;
import java.util.LinkedList;
import java.util.Vector;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;

public class TCalendarPanel extends javax.swing.JPanel {

    LinkedList<TCalendarEvent> PEventList;
    
    public void setCalendar(){

        if(!TMass.PRunning){
            Vector header=new Vector();
            header.add("ExecTime");
            header.add("Element");
            header.add("ExecType");
            header.add("Generator");
            header.add("GenTime");
            TableModel newDataModel=new TMassTableModel(header,PEventList.size());

            int i=0;
            if(PEventList!=null)
            for(TCalendarEvent event:PEventList){
                newDataModel.setValueAt(event.getFireTimeS(),i,0);
                newDataModel.setValueAt(event.getElementS(),i,1);
                newDataModel.setValueAt(event.getEventTypeS(),i,2);
                newDataModel.setValueAt(event.getGeneratedBy(),i,3);
                newDataModel.setValueAt(event.getGenTimeS(),i,4);
                i++;
            }

            TCalendarTable.setModel(newDataModel);
            TCalendarTable.setAutoCreateRowSorter(true);
            TableColumn col = TCalendarTable.getColumnModel().getColumn(0);
            col.setPreferredWidth(55);
            col.setMinWidth(30);
            col.setMaxWidth(200);
            col = TCalendarTable.getColumnModel().getColumn(4);
            col.setPreferredWidth(55);
            col.setMinWidth(30);
            col.setMaxWidth(200);
        }
    }


    /** Creates new form TCalendarPanel */
    public TCalendarPanel(LinkedList<TCalendarEvent> list){
        initComponents();
        PEventList=list;
        setCalendar();
    }

    /** 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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        TCalendarTable = new javax.swing.JTable();

        setBackground(java.awt.SystemColor.activeCaption);

        TCalendarTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        TCalendarTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_LAST_COLUMN);
        TCalendarTable.setName("TCalendarTable"); // NOI18N
        jScrollPane1.setViewportView(TCalendarTable);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 355, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents


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

}
