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