scheduler.view
Class ListView

java.lang.Object
  extended by scheduler.view.ListView

public class ListView
extends java.lang.Object

The List View model class. This class filters the data from ViewSettings and passes it to its companion view class ListViewUI. This class contains a table model that serves as an adaptor between a schedule and a table object that is displayed.

Author:
Jason Mak

Nested Class Summary
(package private)  class ListView.ListViewRow
          The inner class ListViewRow is a container of a ScheduleItem and its form as row data in the list view table.
 
Field Summary
protected  javax.swing.table.TableColumn[] columns
          The columns of the table.
protected  FilterOptions filterOptions
          FilterOptions for the view.
protected  ListViewUI listViewUI
          The companion view object.
protected  java.util.ArrayList<ListView.ListViewRow> rows
          The rows of the table.
protected  Schedule schedule
          The Schedule to be drawn.
protected  javax.swing.JTable table
          The JTable to be displayed.
protected  javax.swing.table.DefaultTableModel tableModel
          The TableModel of viewable data.
 View view
          The parent view.
 
Constructor Summary
ListView(View view, Schedule schedule)
          Construct this class using its parent view object.
 
Method Summary
protected  void createColumns()
          Saves the column objects from the table
protected  void createRows()
          Creates rows for the Table Model using a Schedule's ScheduleItems.
protected  void defaultRowSort()
          Sets the default column to sort by.
 ListViewUI getListViewUI()
          Returns the companion View object.
 ScheduleItem getScheduleItemOf(java.lang.String courseName, int section)
          Returns the visible row with the given course name and section.
 javax.swing.JTable getTable()
          Returns the table of data.
protected  boolean unFiltered(ListView.ListViewRow row)
          Takes a list view and check if it has been filtered out based on its course, instructor, or location.
 void update()
          Redraws the entire JTable.
 void updateColumn(int col, boolean visible)
          Removes the column if it has been deselected in the filter options pane and turns on auto column resize if column is below 12, otherwise add the column and turns auto-column resize off if the column count has exceeded 11.
protected  void updateColumns()
          All columns have been created.
 void updateCourseFilter(CourseFilterObj cfo)
          updateCourseFilter finds all rows that have a course matching the course in the CourseFilterObj.
 void updateInstructorFilter(InstructorFilterObj ifo)
          updateInstructorFilter finds all rows that have a course matching the instructor in the InstructorFilterObj.
 void updateLocationFilter(LocationFilterObj lfo)
          updateCourseFilter finds all rows that have a location matching the location in the LocationFilterObj.
protected  void updateRows()
          Initializes table rows by adding all unfiltered rows to the table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

view

public View view
The parent view.


tableModel

protected javax.swing.table.DefaultTableModel tableModel
The TableModel of viewable data.


schedule

protected Schedule schedule
The Schedule to be drawn.


columns

protected javax.swing.table.TableColumn[] columns
The columns of the table.


rows

protected java.util.ArrayList<ListView.ListViewRow> rows
The rows of the table.


table

protected javax.swing.JTable table
The JTable to be displayed.


filterOptions

protected FilterOptions filterOptions
FilterOptions for the view.


listViewUI

protected ListViewUI listViewUI
The companion view object.

Constructor Detail

ListView

public ListView(View view,
                Schedule schedule)
         throws Instructor.NullUserIDException
Construct this class using its parent view object. Get settings from the view object and instantiate the table model.
 pre: ;

 post: this.view' == view && this.schedule' == schedule
        && this.filterOptions' == view.getViewSettings().getFilterOptions()
        && this.tableModel' != null && this.listViewUI' != null;

                                                                

Parameters:
view - the scheduler's view object
schedule - the schedule to be viewed
Throws:
Instructor.NullUserIDException - check instructor validity
Method Detail

createRows

protected void createRows()
                   throws Instructor.NullUserIDException
Creates rows for the Table Model using a Schedule's ScheduleItems.
 pre:;

 post: this.rows' != null &&
       forall (ScheduleItem s | s in schedule)
             exists (ListViewRow lvr)
                    (lvr in rows) && (lvr.schedulteItem == s)
                                                              

Throws:
Instructor.NullUserIDException - check instructor validity

createColumns

protected void createColumns()
Saves the column objects from the table
 pre: ;

 post: this.columns' != null &&
       forall (TableColumn tc | table)
       tc in columns;
                                                                 


defaultRowSort

protected void defaultRowSort()
Sets the default column to sort by. This depends on the active view type and view level. The defaults for sort order in list mode are noted in the specification requirements.
 pre: ;

 post: if (view.getViewSettings().getViewType() == ViewType.COURSE)
       then
           if (view.getViewSettings().getViewLevel().getLevel() ==
               ViewLevel.Level.WEEKLY)
           then for(int x = 0; x < table.getRowCount()-1; x++)
                    table.getValueAt(x, 20) <=  table.getValueAt(x + 1, 20)
           else for(int x = 0; x < table.getRowCount()-1; x++)
                    table.getValueAt(x, 1) <=  table.getValueAt(x + 1, 1)
        else if (view.getViewSettings().getViewType() == ViewType.INSTRUCTOR)
        then for(int x = 0; x < table.getRowCount()-1; x++)
                table.getValueAt(x, 8) <=  table.getValueAt(x + 1, 8)
        else
           if (view.getViewSettings().getViewLevel().getLevel() ==
               ViewLevel.Level.WEEKLY)
           then for(int x = 0; x < table.getRowCount()-1; x++)
                    table.getValueAt(x, 20) <=  table.getValueAt(x + 1, 20)
           else  for(int x = 0; x < table.getRowCount()-1; x++)
                    table.getValueAt(x, 13) <=  table.getValueAt(x + 1, 13);

                                                                    


unFiltered

protected boolean unFiltered(ListView.ListViewRow row)
Takes a list view and check if it has been filtered out based on its course, instructor, or location.
 pre: ;
 post: if (view.getViewSettings().getViewType() == ViewType.COURSE)
       then if (exists (CourseFilterObj x)
                     (x in courseFil ) &&
                     (x.getCourse.toString()
                       == row.scheduleItem.c.toString()) &&
                     (x.isSelected())
                 then return true
                 else return false
       else if (view.getViewSettings().getViewType() == ViewType.INSTRUCTOR)
            then if (exists (InstructorFilterObj x)
                     (x in instrFil ) &&
                     (x.getInstructor().getId() 
                       == row.scheduleItem.getInstructor().getId()) &&
                     (x.isSelected())
                 then return true
                 else return false
       else if (exists (LocationFilterObj x)
                (x in locationFil) &&
                (x.getLocation().getBuilding() == row.rowData[13]) &&
                (x.getLocation().getRoom() == row.rowData[14]) &&
                (x.isSelected())
            then return true
            else return false;
                                                                     

Parameters:
row - check if this row is filtered
Returns:
true if visible, false otherwise

updateRows

protected void updateRows()
Initializes table rows by adding all unfiltered rows to the table. The rows must not be filtered out by advanced filters or the view level.
 pre: ;

 post: forall (ListViewRow r | r in rows &&
               unFiltered(r) == true &&
               Time.isWithin(r.start, r.end, advancedFilters.start,
                             advancedFilters.end) &&
               ((weekly && r.days.semiEquals(advancedFilters.days)) ||
                (daily && r.day == daily.day)))
               r.rowData in table;
                                                                   


updateColumns

protected void updateColumns()
All columns have been created. This method filters out the ones that have been selected to be hidden. It also turns auto-column resize off if the column count has exceeded 11.
    pre:;

    post: forall (TableColumn c | c in columns && !filterOptionsArray[c.index])
              !(c in table)

          &&

          if (table.getColumnCount() >= 12)
          then table.autoResizeMode == JTable.AUTO_RESIZE_OFF
          else table.autoResizeMode == JTable.AUTO_RESIZE_LAST_COLUMN;

                                                         


updateColumn

public void updateColumn(int col,
                         boolean visible)
Removes the column if it has been deselected in the filter options pane and turns on auto column resize if column is below 12, otherwise add the column and turns auto-column resize off if the column count has exceeded 11.
 pre: ;

 post: if (visibile == true)
       then columns[col] in table
       else !(columns[col] in table)

       &&

       if (table.getColumnCount() >= 12)
       then table.autoResizeMode == JTable.AUTO_RESIZE_OFF
       else table.autoResizeMode == JTable.AUTO_RESIZE_LAST_COLUMN

                                                              

Parameters:
col - the column index to be added or removed
visible - boolean to determine whether column is added or removed

updateCourseFilter

public void updateCourseFilter(CourseFilterObj cfo)
updateCourseFilter finds all rows that have a course matching the course in the CourseFilterObj. If the boolean value in CourseFilterObj is true, the method adds the rows to the table, otherwise they are already in the table and are removed.
 pre: ;

 post: forall (ListViewRow r : r in rows && cfo.course == row.scheduleItem.course)
       if (cfo.isSelected())
        then r.rowData in table
        else !(r.rowData in table;

                                                               

Parameters:
cfo - course filter object to determine if course is hidden

updateInstructorFilter

public void updateInstructorFilter(InstructorFilterObj ifo)
updateInstructorFilter finds all rows that have a course matching the instructor in the InstructorFilterObj. If the boolean value in InstructorFilterObj is true, the method adds the rows to the table, otherwise they are already in the table and are removed.
 pre: ;

 post: forall (ListViewRow r : r in rows && ifo.instructor == row.scheduleItem.instructor)
       if (ifo.isSelected())
        then r.rowData in table
        else !(r.rowData in table;

                                                               

Parameters:
ifo - determine if instructor is hidden

updateLocationFilter

public void updateLocationFilter(LocationFilterObj lfo)
updateCourseFilter finds all rows that have a location matching the location in the LocationFilterObj. If the boolean value in LocationFilterObj is true, the method adds the rows to the table, otherwise they are already in the table and are removed.
 pre: ;

 post: forall (ListViewRow r : r in rows && lfo.location == row.scheduleItem.location)
       if (lfo.isSelected())
        then r.rowData in table
        else !(r.rowData in table;

                                                               

Parameters:
lfo - determine if location is hidden

update

public void update()
Redraws the entire JTable.
 pre:;
 
 post: this.tableModel' != null;
                                                               


getTable

public javax.swing.JTable getTable()
Returns the table of data.
 post: return == table;
                                                               

Returns:
the table of the list view

getScheduleItemOf

public ScheduleItem getScheduleItemOf(java.lang.String courseName,
                                      int section)
Returns the visible row with the given course name and section.
 pre: ;

 post: if exists (ListViewRow r)
       (r in rows) && (r.scheduleItem.c.courseName == courseName)
       && (r.scheduleItem.c.section == section)
       then return == r.scheduleItem
       else return == null

                                                               

Parameters:
courseName - name of the course in the table
section - section of the course in the table
Returns:
the schedule item that contains the course

getListViewUI

public ListViewUI getListViewUI()
Returns the companion View object.
 post: return == listViewUI;
                                                               

Returns:
the companion view