import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;

/**
 * A TableCellEditor that can for Course objects.
 * 
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class CourseCellEditor extends AbstractCellEditor implements TableCellEditor
{
  private static final long serialVersionUID = 1L;

  private CourseField     field;
  
  /**
   * Default Constructor.
   */
  public CourseCellEditor()
  {
    field = new CourseField();
  }
  
  /**
   * Get the value in the TableCellEditor.
   * 
   * @return Object  The value
   */
  public Object getCellEditorValue()
  {
    return field.getCourse();
  }

  /**
   * Get the Component to use when editing a cell
   * 
   * @param table  The JTable of interest
   * @param value  The value in the cell of interest
   * @param isSelected true if the cell of interest is selected
   * @param row The row of the cell of interest
   * @param column The column of the cell of interest
   * @return The Component to use for editing
   */
  public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,
      int row, int column)
  {
    // Initialize the CourseField
    if ((value != null) && (value instanceof Course))
    {
      field.setCourse((Course)value);
    }

    return field;
  }

}
