1. /*
  2. * @(#)TableColumnModel.java 1.17 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing.table;
  8. import java.util.Enumeration;
  9. import javax.swing.event.ChangeEvent;
  10. import javax.swing.event.*;
  11. import javax.swing.*;
  12. /**
  13. * Defines the requirements for a model object suitable for
  14. * use with JTable.
  15. *
  16. * @version 1.17 11/29/01
  17. * @author Alan Chung
  18. * @author Philip Milne
  19. * @see DefaultTableColumnModel
  20. */
  21. public interface TableColumnModel
  22. {
  23. //
  24. // Modifying the model
  25. //
  26. /**
  27. * Appends <I>aColumn</I> to the end of the receiver's tableColumns array.
  28. * This method also posts the columnAdded() event to its listeners.
  29. *
  30. * @param aColumn The <B>TableColumn</B> to be added
  31. * @see #removeColumn
  32. */
  33. public void addColumn(TableColumn aColumn);
  34. /**
  35. * Deletes the <B>TableColumn</B> <I>column</I> from the
  36. * receiver's table columns array. This method will do nothing if
  37. * <I>column</I> is not in the table's columns list.
  38. * This method also posts the columnRemoved() event to its listeners.
  39. *
  40. * @param column The <B>TableColumn</B> to be removed
  41. * @see #addColumn
  42. */
  43. public void removeColumn(TableColumn column);
  44. /**
  45. * Moves the column and heading at <I>columnIndex</I> to <I>newIndex</I>.
  46. * The old column at <I>columnIndex</I> will now be found at <I>newIndex</I>,
  47. * The column that used to be at <I>newIndex</I> is shifted left or right
  48. * to make room.
  49. * This will not move any columns if <I>columnIndex</I> equals <I>newIndex</I>.
  50. * This method also posts the columnMoved() event to its listeners.
  51. *
  52. * @param columnIndex the index of column to be moved
  53. * @param newIndex New index to move the column
  54. * @exception IllegalArgumentException if <I>column</I> or
  55. * <I>newIndex</I>
  56. * are not in the valid range
  57. */
  58. public void moveColumn(int columnIndex, int newIndex);
  59. /**
  60. * Sets the <B>TableColumn's</B> column margin to <I>newMargin</I>.
  61. * This method also posts the columnMarginChanged() event to its
  62. * listeners.
  63. *
  64. * @param newMargin the width margin of the column
  65. * @see #getColumnMargin
  66. */
  67. public void setColumnMargin(int newMargin);
  68. //
  69. // Querying the model
  70. //
  71. /** Returns the number of columns in the model */
  72. public int getColumnCount();
  73. /** Returns an Enumeration of all the columns in the model */
  74. public Enumeration getColumns();
  75. /**
  76. * Returns the index of the first column in the receiver's
  77. * columns array whose identifier is equal to <I>identifier</I>,
  78. * when compared using <I>equals()</I>.
  79. *
  80. * @return the index of the first table column in the receiver's
  81. * tableColumns array whose identifier is equal to
  82. * <I>identifier</I>, when compared using equals().
  83. * @param identifier the identifier object
  84. * @exception IllegalArgumentException if <I>identifier</I> is null or no TableColumn has this identifier
  85. * @see #getColumn
  86. */
  87. public int getColumnIndex(Object columnIdentifier);
  88. /**
  89. * Returns the <B>TableColumn</B> object for the column at <I>columnIndex</I>
  90. *
  91. * @return the TableColumn object for the column at <I>columnIndex</I>
  92. * @param columnIndex the index of the column desired
  93. */
  94. public TableColumn getColumn(int columnIndex);
  95. /** Returns the width margin between each column */
  96. public int getColumnMargin();
  97. /**
  98. * Returns the index of the column that lies on the <I>xPosition</I>,
  99. * or -1 if it lies outside the any of the column's bounds.
  100. *
  101. * @return the index of the column or -1 if no column is found
  102. */
  103. public int getColumnIndexAtX(int xPosition);
  104. /** Returns the total width of all the columns. */
  105. public int getTotalColumnWidth();
  106. //
  107. // Selection
  108. //
  109. /**
  110. * Sets whether the columns in this model can be selected.
  111. * @see #getColumnSelectionAllowed
  112. */
  113. public void setColumnSelectionAllowed(boolean flag);
  114. /**
  115. * Returns true if columns can be selected.
  116. * @return true if columns can be selected
  117. * @see #setColumnSelectionAllowed
  118. */
  119. public boolean getColumnSelectionAllowed();
  120. /**
  121. * Returns an array of indexes for selected columns
  122. * @return an array of ints giving the indexes of all selected columns,
  123. * or an empty int array if no column is selected.
  124. */
  125. public int[] getSelectedColumns();
  126. /**
  127. * Returns the number of selected columns.
  128. *
  129. * @return the number of selected columns, or 0 if no columns are selected
  130. */
  131. public int getSelectedColumnCount();
  132. /**
  133. * Sets the selection model, which handles selections.
  134. *
  135. * @param newModel a ListSelectionModel object
  136. * @see #getSelectionModel
  137. */
  138. public void setSelectionModel(ListSelectionModel newModel);
  139. /**
  140. * Returns the current selection model.
  141. *
  142. * @return a ListSelectionModel object representing the selection model val
  143. * @see #setSelectionModel
  144. */
  145. public ListSelectionModel getSelectionModel();
  146. //
  147. // Listener
  148. //
  149. /**
  150. * Add a listener for table column model events.
  151. *
  152. * @param x a TableColumnModelListener object
  153. */
  154. public void addColumnModelListener(TableColumnModelListener x);
  155. /**
  156. * Remove a listener for table column model events.
  157. *
  158. * @param x a TableColumnModelListener object
  159. */
  160. public void removeColumnModelListener(TableColumnModelListener x);
  161. }