package view;

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

/****
 *
 * Class AppointmentsListDisplay is a quick prototype of an appointments list.
 * The display is a JTable.  The columns of the table are fixed, per the
 * requirements.  The default number of visible rows is 20.  The sample data
 * are longer than 20 rows, so a scroll bar is added by putting the table i a
 * ScrollPane.  The Java Swing tutorial explains how to used ScrollPanes,
 * though the simple example here should show you how to do things for the 308
 * prototype.
 *                                                                           <p>
 * The easiest way to populate a JTable is to build a DefaultTableModel, which
 * is a class provided by the Swing library.  Even though our prototype has no
 * actual model data, the way Swing displays collections of data is by
 * accessing an underlying data model.  So, what we do in the prototype is fill
 * the model with some sample data, then give it to the JTable to display.  The
 * Java Swing tutorial has good discussion of how this works.
 */
public class AppointmentsListDisplay extends JFrame {

    /**
     * Construct this with a local DefaultTableModel, to hold same sample
     * prototype data.
     */
    public AppointmentsListDisplay() {

        String[] columnNames = {
            "Title", "Date", "Time", "Duration", "Recurs?", "Category",
            "Location", "Security", "Priority"};

        localData = new DefaultTableModel(columnNames, 0);
        table = new JTable(localData);


        /*
         * Wrap the table in a scroll pane, which will have a scrollbar on the
         * right side.
         */
        JScrollPane scrollPane = new JScrollPane(table);

        /*
         * Set some table default values.
         */
        table.setPreferredScrollableViewportSize(new Dimension(
            700, 20 * table.getRowHeight()));
        table.setEnabled(false);
        table.setShowGrid(true);
        table.setShowHorizontalLines(true);
        table.setShowVerticalLines(true);

        /*
         * Put the scroll pane, including its table, in the content pane of
         * this JFrame.
         */
        setContentPane(scrollPane);
        setTitle("Appointments, sorted by Date");

        /*
         * Populate the data rows with the sample model data.
         */
        for (int i = 0; i < sampleList.length; i++) {
            localData.addRow(sampleList[i]);
        }

        /*
         * Don't forget this.
         */
        pack();
    } 

    /** An array of array of strings, holding sample list entries.  This was
     * generated by cut-paste-and-hack-a-bit from the requirements. */
    protected String[][] sampleList = {

        {"Racket Ball",
         "sep 17, 2007",
         "8 AM",
         "1 hr",
         "yes", 
         "personal",
         "Rec centre",
         "PublicTitle",
         "Optional"},

        {"Office Hours",
         "sep 21, 2007",
         "9 AM",
         "1 hr",
         "yes", 
         "classes",
         "14-210",
         "Public",
         "Must"},

        {"Data Structures Lecture",
         "sep 21, 2007",
         "10 AM",
         "1 hr",
         "yes", 
         "classes",
         "14-256",
         "Public",
         "Must"},

        {"Data Structures Lab",
         "sep 21, 2007",
         "11 AM",
         "1 hr",
         "yes", 
         "classes",
         "14-232",
         "Public",
         "Must"},

        {"Software Engineering Graduate Seminar",
         "sep 21, 2007",
         "3 PM",
         "2 hrs",
         "yes", 
         "classes",
         "14-301",
         "Public",
         "Must"},

        {"Racket Ball",
         "sep 22, 2007",
         "8 AM",
         "1 hr",
         "yes", 
         "personal",
         "Rec centre",
         "PublicTitle",
         "Optional"},

        {"Research",
         "sep 22, 2007",
         "9 AM",
         "8 hrs",
         "yes", 
         "research",
         "14-210",
         "Public",
         "Must"},

        {"Office Hours",
         "sep 23, 2007",
         "9 AM",
         "1 hr",
         "yes", 
         "classes",
         "14-210",
         "Public",
         "Must"},

        {"Data Structures Lecture",
         "sep 23, 2007",
         "10 AM",
         "1 hr",
         "yes", 
         "classes",
         "14-256",
         "Public",
         "Must"},

        {"Data Structures Lab",
         "sep 23, 2007",
         "11 AM",
         "1 hr",
         "yes", 
         "classes",
         "14-232",
         "Public",
         "Must"},

        {"Lunch with Microsoft",
         "sep 23, 2007",
         "12 PM",
         "1 hr 30 min",
         "no", 
         "department",
         "Staff dining",
         "Public",
         "Optional"},

        {"Racket Ball",
         "sep 24, 2007",
         "8 AM",
         "1 hr",
         "yes", 
         "personal",
         "Rec centre",
         "PublicTitle",
         "Optional"},

        {"Office Hours",
         "sep 24, 2007",
         "1:15 PM",
         "1 hr 45 min",
         "yes", 
         "classes",
         "14-210",
         "Public",
         "Must"},

        {"Software Engineering Graduate Seminar",
         "sep 24, 2007",
         "3 PM",
         "2 hr",
         "yes", 
         "classes",
         "14-301",
         "Public",
         "Must"},

        {"Dentist",
         "sep 25, 2007",
         "8 AM",
         "1 hr 30 min",
         "no", 
         "personal",
         "1342 Sycamore Dr",
         "PublicTitle",
         "Must"},

        {"Office Hours",
         "sep 25, 2007",
         "9 AM",
         "1 hr",
         "yes", 
         "classes",
         "14-210",
         "Public",
         "Must"},

        {"Data Structures Lecture",
         "sep 25, 2007",
         "10 AM",
         "1 hr",
         "yes", 
         "classes",
         "14-256",
         "Public",
         "Must"},

        {"Data Structures Lab",
         "sep 25, 2007",
         "11 AM",
         "1 hr",
         "yes", 
         "classes",
         "14-232",
         "Public",
         "Must"},

        {"Office Hours",
         "sep 28, 2007",
         "9 AM",
         "1 hr",
         "yes", 
         "classes",
         "14-210",
         "Public",
         "Must"},

        {"Data Structures Lecture",
         "sep 28, 2007",
         "10 AM",
         "1 hr",
         "yes", 
         "classes",
         "14-256",
         "Public",
         "Must"},

        {"Data Structures Lab",
         "sep 28, 2007",
         "11 AM",
         "1 hr",
         "yes", 
         "classes",
         "14-232",
         "Public",
         "Must"},

        {"Software Engineering Graduate Seminar",
         "sep 28, 2007",
         "3 PM",
         "2 hrs",
         "yes", 
         "classes",
         "14-301",
         "Public",
         "Must"},

        {"Racket Ball",
         "sep 29, 2007",
         "8 AM",
         "1 hr",
         "yes", 
         "personal",
         "Rec centre",
         "PublicTitle",
         "Optional"},

        {"Research",
         "sep 29, 2007",
         "9 AM",
         "8 hrs",
         "yes", 
         "research",
         "14-210",
         "Public",
         "Must"},

        {"Office Hours",
         "sep 30, 2007",
         "9 A",
         "1 hr",
         "yes", 
         "classes",
         "14-210",
         "Public",
         "Must"},

        {"Data Structures Lecture",
         "sep 30, 2007",
         "10 AM",
         "1 hr",
         "yes", 
         "classes",
         "14-256",
         "Public",
         "Must"},

        {"Data Structures Lab",
         "sep 30, 2007",
         "11 AM",
         "1 hr",
         "yes", 
         "classes",
         "14-232",
         "Public",
         "Must"},

        {"CAD Research Project Meeting",
         "sep 30, 2007",
         "2:30 PM",
         "2 hrs",
         "yes", 
         "research",
         "14-301",
         "Public",
         "Must"},

        {"Racket Ball",
         "oct 1, 2007",
         "8 AM",
         "1 hr",
         "yes", 
         "personal",
         "Rec centre",
         "PublicTitle",
         "Optional"},

        {"Office Hours",
         "oct 1, 2007",
         "1:15 PM",
         "1 hr",
         "yes", 
         "classes",
         "14-210",
         "Public",
         "Must"},

        {"Software Engineering Graduate Seminar",
         "oct 1, 2007",
         "3 PM",
         "2 hrs",
         "yes", 
         "classes",
         "14-301",
         "Public",
         "Must"},

        {"Office Hours",
         "oct 2, 2007",
         "9 AM",
         "1 hr",
         "yes", 
         "classes",
         "14-210",
         "Public",
         "Must"},

        {"Data Structures Lecture",
         "oct 2, 2007",
         "10 AM",
         "1 hr",
         "yes", 
         "classes",
         "14-256",
         "Public",
         "Must"},

        {"Data Structures Lab",
         "oct 2, 2007",
         "11 AM",
         "1 hr",
         "yes", 
         "classes",
         "14-232",
         "Public",
         "Must"},

        {"Office Hours",
         "oct 5, 2007",
         "9 AM",
         "1 hr",
         "yes", 
         "classes",
         "14-210",
         "Public",
         "Must"},

        {"Data Structures Lecture",
         "oct 5, 2007",
         "10 AM",
         "1 hr",
         "yes", 
         "classes",
         "14-256",
         "Public",
         "Must"},

        {"Data Structures Lab",
         "oct 5, 2007",
         "11 AM",
         "1 hr",
         "yes", 
         "classes",
         "14-232",
         "Public",
         "Must"},

        {"Software Engineering Graduate Seminar",
         "oct 5, 2007",
         "3 PM",
         "2 hrs",
         "yes", 
         "classes",
         "14-301",
         "Public",
         "Must"},

        {"Racket Ball",
         "oct 6, 2007",
         "8 AM",
         "1 hr",
         "yes", 
         "personal",
         "Rec centre",
         "PublicTitle",
         "Optional"},

        {"Research",
         "oct 6, 2007",
         "9 AM",
         "8 hr",
         "yes", 
         "research",
         "14-210",
         "Public",
         "Must"}
    };

    /** Local data model.  This is not the real data model, but rather a 
        GUI-specific table model that is filled with sample prototype data.
        In the real implementation, actual list data will be computed by
        searching the calendar. */
    protected DefaultTableModel localData;

    /** The display view */
    protected JTable table;

}