1. /*
  2. * @(#)TableColumnModel.java 1.25 04/05/05
  3. *
  4. * Copyright 2004 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 table column model object suitable for
  14. * use with <code>JTable</code>.
  15. *
  16. * @version 1.25 05/05/04
  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 <code>aColumn</code> to the end of the
  28. * <code>tableColumns</code> array.
  29. * This method posts a <code>columnAdded</code>
  30. * event to its listeners.
  31. *
  32. * @param aColumn the <code>TableColumn</code> to be added
  33. * @see #removeColumn
  34. */
  35. public void addColumn(TableColumn aColumn);
  36. /**
  37. * Deletes the <code>TableColumn</code> <code>column</code> from the
  38. * <code>tableColumns</code> array. This method will do nothing if
  39. * <code>column</code> is not in the table's column list.
  40. * This method posts a <code>columnRemoved</code>
  41. * event to its listeners.
  42. *
  43. * @param column the <code>TableColumn</code> to be removed
  44. * @see #addColumn
  45. */
  46. public void removeColumn(TableColumn column);
  47. /**
  48. * Moves the column and its header at <code>columnIndex</code> to
  49. * <code>newIndex</code>. The old column at <code>columnIndex</code>
  50. * will now be found at <code>newIndex</code>. The column that used
  51. * to be at <code>newIndex</code> is shifted left or right
  52. * to make room. This will not move any columns if
  53. * <code>columnIndex</code> equals <code>newIndex</code>. This method
  54. * posts a <code>columnMoved</code> event to its listeners.
  55. *
  56. * @param columnIndex the index of column to be moved
  57. * @param newIndex index of the column's new location
  58. * @exception IllegalArgumentException if <code>columnIndex</code> or
  59. * <code>newIndex</code>
  60. * are not in the valid range
  61. */
  62. public void moveColumn(int columnIndex, int newIndex);
  63. /**
  64. * Sets the <code>TableColumn</code>'s column margin to
  65. * <code>newMargin</code>. This method posts
  66. * a <code>columnMarginChanged</code> event to its listeners.
  67. *
  68. * @param newMargin the width, in pixels, of the new column margins
  69. * @see #getColumnMargin
  70. */
  71. public void setColumnMargin(int newMargin);
  72. //
  73. // Querying the model
  74. //
  75. /**
  76. * Returns the number of columns in the model.
  77. * @return the number of columns in the model
  78. */
  79. public int getColumnCount();
  80. /**
  81. * Returns an <code>Enumeration</code> of all the columns in the model.
  82. * @return an <code>Enumeration</code> of all the columns in the model
  83. */
  84. public Enumeration<TableColumn> getColumns();
  85. /**
  86. * Returns the index of the first column in the table
  87. * whose identifier is equal to <code>identifier</code>,
  88. * when compared using <code>equals</code>.
  89. *
  90. * @param columnIdentifier the identifier object
  91. * @return the index of the first table column
  92. * whose identifier is equal to <code>identifier</code>
  93. * @exception IllegalArgumentException if <code>identifier</code>
  94. * is <code>null</code>, or no
  95. * <code>TableColumn</code> has this
  96. * <code>identifier</code>
  97. * @see #getColumn
  98. */
  99. public int getColumnIndex(Object columnIdentifier);
  100. /**
  101. * Returns the <code>TableColumn</code> object for the column at
  102. * <code>columnIndex</code>.
  103. *
  104. * @param columnIndex the index of the desired column
  105. * @return the <code>TableColumn</code> object for
  106. * the column at <code>columnIndex</code>
  107. */
  108. public TableColumn getColumn(int columnIndex);
  109. /**
  110. * Returns the width between the cells in each column.
  111. * @return the margin, in pixels, between the cells
  112. */
  113. public int getColumnMargin();
  114. /**
  115. * Returns the index of the column that lies on the
  116. * horizontal point, <code>xPosition</code>
  117. * or -1 if it lies outside the any of the column's bounds.
  118. *
  119. * In keeping with Swing's separable model architecture, a
  120. * TableColumnModel does not know how the table columns actually appear on
  121. * screen. The visual presentation of the columns is the responsibility
  122. * of the view/controller object using this model (typically JTable). The
  123. * view/controller need not display the columns sequentially from left to
  124. * right. For example, columns could be displayed from right to left to
  125. * accomodate a locale preference or some columns might be hidden at the
  126. * request of the user. Because the model does not know how the columns
  127. * are laid out on screen, the given <code>xPosition</code> should not be
  128. * considered to be a coordinate in 2D graphics space. Instead, it should
  129. * be considered to be a width from the start of the first column in the
  130. * model. If the column index for a given X coordinate in 2D space is
  131. * required, <code>JTable.columnAtPoint</code> can be used instead.
  132. *
  133. * @return the index of the column; or -1 if no column is found
  134. * @see javax.swing.JTable#columnAtPoint
  135. */
  136. public int getColumnIndexAtX(int xPosition);
  137. /**
  138. * Returns the total width of all the columns.
  139. * @return the total computed width of all columns
  140. */
  141. public int getTotalColumnWidth();
  142. //
  143. // Selection
  144. //
  145. /**
  146. * Sets whether the columns in this model may be selected.
  147. * @param flag true if columns may be selected; otherwise false
  148. * @see #getColumnSelectionAllowed
  149. */
  150. public void setColumnSelectionAllowed(boolean flag);
  151. /**
  152. * Returns true if columns may be selected.
  153. * @return true if columns may be selected
  154. * @see #setColumnSelectionAllowed
  155. */
  156. public boolean getColumnSelectionAllowed();
  157. /**
  158. * Returns an array of indicies of all selected columns.
  159. * @return an array of integers containing the indicies of all
  160. * selected columns; or an empty array if nothing is selected
  161. */
  162. public int[] getSelectedColumns();
  163. /**
  164. * Returns the number of selected columns.
  165. *
  166. * @return the number of selected columns; or 0 if no columns are selected
  167. */
  168. public int getSelectedColumnCount();
  169. /**
  170. * Sets the selection model.
  171. *
  172. * @param newModel a <code>ListSelectionModel</code> object
  173. * @see #getSelectionModel
  174. */
  175. public void setSelectionModel(ListSelectionModel newModel);
  176. /**
  177. * Returns the current selection model.
  178. *
  179. * @return a <code>ListSelectionModel</code> object
  180. * @see #setSelectionModel
  181. */
  182. public ListSelectionModel getSelectionModel();
  183. //
  184. // Listener
  185. //
  186. /**
  187. * Adds a listener for table column model events.
  188. *
  189. * @param x a <code>TableColumnModelListener</code> object
  190. */
  191. public void addColumnModelListener(TableColumnModelListener x);
  192. /**
  193. * Removes a listener for table column model events.
  194. *
  195. * @param x a <code>TableColumnModelListener</code> object
  196. */
  197. public void removeColumnModelListener(TableColumnModelListener x);
  198. }