1. /*
  2. * @(#)TableModel.java 1.16 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 javax.swing.*;
  9. import javax.swing.event.*;
  10. /**
  11. * The <B>TableModel</B> interface ispecifies the methods the JTable
  12. * will use to interrogate a tabular data model. <p>
  13. *
  14. * The JTable can be set up to display any data model which implements the
  15. * TableModel interface with a couple of lines of code: <p>
  16. * <code>
  17. * TableModel myData = new MyTableModel();
  18. * JTable table = new JTable(myData);
  19. * </code><p>
  20. *
  21. * @version 1.16 11/29/01
  22. * @author Philip Milne
  23. * @author Alan Chung
  24. * @see JTable
  25. * @see AbstractTableModel
  26. */
  27. public interface TableModel
  28. {
  29. /**
  30. * Returns the number of records managed by the data source object. A
  31. * <B>JTable</B> uses this method to determine how many rows it
  32. * should create and display. This method should be quick, as it
  33. * is call by <B>JTable</B> quite frequently.
  34. *
  35. * @return the number or rows in the model
  36. * @see #getColumnCount
  37. */
  38. public int getRowCount();
  39. /**
  40. * Returns the number of columns managed by the data source object. A
  41. * <B>JTable</B> uses this method to determine how many columns it
  42. * should create and display on initialization.
  43. *
  44. * @return the number or columns in the model
  45. * @see #getRowCount
  46. */
  47. public int getColumnCount();
  48. /**
  49. * Returns the name of the column at <i>columnIndex</i>. This is used
  50. * to initialize the table's column header name. Note, this name does
  51. * not need to be unique. Two columns on a table can have the same name.
  52. *
  53. * @param columnIndex the index of column
  54. * @return the name of the column
  55. */
  56. public String getColumnName(int columnIndex);
  57. /**
  58. * Returns the lowest common denominator Class in the column. This is used
  59. * by the table to set up a default renderer and editor for the column.
  60. *
  61. * @return the common ancestor class of the object values in the model.
  62. */
  63. public Class getColumnClass(int columnIndex);
  64. /**
  65. * Returns true if the cell at <I>rowIndex</I> and <I>columnIndex</I>
  66. * is editable. Otherwise, setValueAt() on the cell will not change
  67. * the value of that cell.
  68. *
  69. * @param rowIndex the row whose value is to be looked up
  70. * @param columnIndex the column whose value is to be looked up
  71. * @return true if the cell is editable.
  72. * @see #setValueAt
  73. */
  74. public boolean isCellEditable(int rowIndex, int columnIndex);
  75. /**
  76. * Returns an attribute value for the cell at <I>columnIndex</I>
  77. * and <I>rowIndex</I>.
  78. *
  79. * @param rowIndex the row whose value is to be looked up
  80. * @param columnIndex the column whose value is to be looked up
  81. * @return the value Object at the specified cell
  82. */
  83. public Object getValueAt(int rowIndex, int columnIndex);
  84. /**
  85. * Sets an attribute value for the record in the cell at
  86. * <I>columnIndex</I> and <I>rowIndex</I>. <I>aValue</I> is
  87. * the new value.
  88. *
  89. * @param aValue the new value
  90. * @param rowIndex the row whose value is to be changed
  91. * @param columnIndex the column whose value is to be changed
  92. * @see #getValueAt
  93. * @see #isCellEditable
  94. */
  95. public void setValueAt(Object aValue, int rowIndex, int columnIndex);
  96. /**
  97. * Add a listener to the list that's notified each time a change
  98. * to the data model occurs.
  99. *
  100. * @param l the TableModelListener
  101. */
  102. public void addTableModelListener(TableModelListener l);
  103. /**
  104. * Remove a listener from the list that's notified each time a
  105. * change to the data model occurs.
  106. *
  107. * @param l the TableModelListener
  108. */
  109. public void removeTableModelListener(TableModelListener l);
  110. }