// file: BugTable.java
//

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

/**
 * Handles the bug table functionalities, an extension of JPanel
 */
public class BugTable extends JPanel {


    // ---------------------------------------------------
    //
    // declare class member data
    //
    // ---------------------------------------------------

    /**
     * JTable table for displaying the bugs
     */
    JTable table = null;

    /**
     * ReadOnlyTable used for displaying table
     */

    ReadOnlyTable readOnlyTable = null;

    /**
     * JScrollPane used in tables
     */
    JScrollPane scrollPane = null;


    // ---------------------------------------------------
    //
    // declare class constructors
    //
    // ---------------------------------------------------
    
    /**
     * default class constructor
     *
     * @param varmint VarmintPanel parameter used to initialize bug table
     * @param data Vector of data to be in bug table
     */
    public BugTable(VarmintPanel varmint, Vector data) {


	// make sure that some data was given
	//
	if (data != null) {

	  
	    // create the read only table
	    //
	    readOnlyTable = new ReadOnlyTable(data);


	    // use these column headings
	    //
	    String[] columnNames = {"Created", 
				    "Modified", 
				    "Stat", 
				    "Num",
				    "DBase",
				    "Pri",
				    "Sev",
				    "Owner",
				    "Title"};
	    
	    // set those items as the column headers
	    //
	    readOnlyTable.setColumnIdentifiers(columnNames);


	    // add sorting capabilities to the table
	    //
	    TableSorter sorter = new TableSorter(readOnlyTable);
	    table = new JTable(sorter);
	    sorter.addMouseListenerToHeaderInTable(table);

	    // set the preferred viewable size of the table.  There 
	    // is no minimum size.
	    //
	    table.setPreferredScrollableViewportSize(new Dimension(790, 375));
	    

	    // create the scroll pane to hold the table
	    //
	    scrollPane = new 
		JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, 
			    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
	    
	    // set the minimum size of the scroll pane
	    //
	    scrollPane.setMinimumSize(new Dimension(100, 100));


	    // put the table into the correct mode of operation for this 
	    // application (selection of one row at a time)
	    //
	    table.setRowSelectionAllowed(true);
	    table.setColumnSelectionAllowed(false);
	    table.addNotify();
	    
	    // add the mouselistener so the user can click to get to a bug
	    //
	    table.addMouseListener(varmint);
	    
	    // set the sizes of all the columns
	    //
	    TableColumn column = table.getColumn("Stat");
	    column.setMaxWidth(33);
	    
	    
	    column = table.getColumn("Created");
	    column.setMaxWidth(150);
	    
	    column = table.getColumn("Modified");
	    column.setMaxWidth(150);	    
	    
	    column = table.getColumn("Num");
	    column.setMaxWidth(50);
	    
	    column = table.getColumn("Stat");
	    column.setMaxWidth(33);
	    	    
	    column = table.getColumn("Pri");
	    column.setMaxWidth(33);
	    	    
	    column = table.getColumn("Sev");
	    column.setMaxWidth(33);
	    	    
	    column = table.getColumn("Owner");
	    column.setMaxWidth(80);
	    
	    column = table.getColumn("DBase");
	    column.setMaxWidth(50);
	    	    
	    column = table.getColumn("Title");
	    column.setPreferredWidth(400);
	    
	    
	    //this.add(scrollPane);
	}
    }
}





