/** Creates a default table column model. */
  public DefaultTableColumnModel() {
    super();

    // Initialize local ivars to default
    tableColumns = new Vector<TableColumn>();
    setSelectionModel(createSelectionModel());
    setColumnMargin(1);
    invalidateWidthCache();
    setColumnSelectionAllowed(false);
  }
  /**
   * Property Change Listener change method. Used to track changes to the column width or preferred
   * column width.
   *
   * @param evt <code>PropertyChangeEvent</code>
   */
  public void propertyChange(PropertyChangeEvent evt) {
    String name = evt.getPropertyName();

    if (name == "width" || name == "preferredWidth") {
      invalidateWidthCache();
      // This is a misnomer, we're using this method
      // simply to cause a relayout.
      fireColumnMarginChanged();
    }
  }
  /**
   * Appends <code>aColumn</code> to the end of the <code>tableColumns</code> array. This method
   * also posts the <code>columnAdded</code> event to its listeners.
   *
   * @param aColumn the <code>TableColumn</code> to be added
   * @exception IllegalArgumentException if <code>aColumn</code> is <code>null</code>
   * @see #removeColumn
   */
  public void addColumn(TableColumn aColumn) {
    if (aColumn == null) {
      throw new IllegalArgumentException("Object is null");
    }

    tableColumns.addElement(aColumn);
    aColumn.addPropertyChangeListener(this);
    invalidateWidthCache();

    // Post columnAdded event notification
    fireColumnAdded(new TableColumnModelEvent(this, 0, getColumnCount() - 1));
  }
  /**
   * Deletes the <code>column</code> from the <code>tableColumns</code> array. This method will do
   * nothing if <code>column</code> is not in the table's columns list. <code>tile</code> is called
   * to resize both the header and table views. This method also posts a <code>columnRemoved</code>
   * event to its listeners.
   *
   * @param column the <code>TableColumn</code> to be removed
   * @see #addColumn
   */
  public void removeColumn(TableColumn column) {
    int columnIndex = tableColumns.indexOf(column);

    if (columnIndex != -1) {
      // Adjust for the selection
      if (selectionModel != null) {
        selectionModel.removeIndexInterval(columnIndex, columnIndex);
      }

      column.removePropertyChangeListener(this);
      tableColumns.removeElementAt(columnIndex);
      invalidateWidthCache();

      // Post columnAdded event notification.  (JTable and JTableHeader
      // listens so they can adjust size and redraw)
      fireColumnRemoved(new TableColumnModelEvent(this, columnIndex, 0));
    }
  }