001 package util.swing; 002 003 import javax.swing.table.*; 004 005 import java.io.Serializable; 006 007 import java.util.Comparator; 008 009 /** 010 * Strategy that describes how individual records of an {@link util.swing.AbstractTableModel} are to be 011 * split up into columns of a table and how the individual cells are to be displayed and edited. 012 * 013 * <p>You should think of a TableEntryDescriptor as a device that is given a record and splits this 014 * record into individual values, that correspond to cells.</p> 015 * 016 * <p>When implementing this interface, you might want to subclass {@link AbstractTableEntryDescriptor}, that 017 * will already give you a head start with some of the more common tasks.</p> 018 * 019 * @see JAbstractTable 020 * 021 * @author Steffen Zschaler 022 * @version 2.0 27/07/1999 023 * @since v2.0 024 */ 025 public interface TableEntryDescriptor extends Serializable { 026 027 /** 028 * Return the number of columns each record will consist of. 029 * 030 * @return the number of columns each record will consist of. 031 * 032 * @override Always 033 */ 034 public int getColumnCount(); 035 036 /** 037 * Return the text to be printed in the header of the given column. 038 * 039 * @param nIdx the index of the column for which to return the header. Indices run from 0 to 040 * {@link #getColumnCount getColumnCount() - 1}. 041 * 042 * @return the text to be printed in the header of the given column. 043 * 044 * @override Always 045 */ 046 public String getColumnName(int nIdx); 047 048 /** 049 * Return the class of objects that make up the values of cells of the given column. This will be used to 050 * determine the cell renderer and editor unless you specify otherwise through {@link #getCellEditor} and 051 * {@link #getCellRenderer}. 052 * 053 * @param nIdx the index of the column for which to return the value class. Indices run from 0 to 054 * {@link #getColumnCount getColumnCount() - 1}. 055 * 056 * @return the class of objects that make up the values of cells of the given column. 057 * 058 * @override Always 059 */ 060 public Class getColumnClass(int nIdx); 061 062 /** 063 * Return the cell renderer to be used for cells in the given column. 064 * 065 * @param nIdx the index of the column for which to return the renderer. Indices run from 0 to 066 * {@link #getColumnCount getColumnCount() - 1}. 067 * 068 * @return the cell renderer to be used for cells in the given column. You can return <code>null</code> to 069 * indicate that the default cell renderer for the {@link #getColumnClass column class} should be used. 070 * 071 * @override Always 072 */ 073 public TableCellRenderer getCellRenderer(int nIdx); 074 075 /** 076 * Return the cell editor to be used for cells in the given column. This is only effective if 077 * {@link #isElementEditable} returns true for the column and a given record. 078 * 079 * @param nIdx the index of the column for which to return the editor. Indices run from 0 to 080 * {@link #getColumnCount getColumnCount() - 1}. 081 * 082 * @return the cell editor to be used for cells in the given column. You can return <code>null</code> to 083 * indicate that the default cell editor for the {@link #getColumnClass column class} should be used. 084 * 085 * @override Always 086 */ 087 public TableCellEditor getCellEditor(int nIdx); 088 089 /** 090 * Get the value to be printed in the given column for the given record. 091 * 092 * @param oRecord the record for which to determine the value. The actual class depends on the 093 * {@link util.swing.AbstractTableModel} you are working with. It will be declared in the documentation for 094 * the {@link util.swing.AbstractTableModel#getRecord} method of that class. 095 * @param nIdx the index of the column for which to return the cell value. Indices run from 0 to 096 * {@link #getColumnCount getColumnCount() - 1}. 097 * 098 * @return the value to be printed in the given column for the given record. The actual class must be 099 * a subclass of what was returned by {@link #getColumnClass} or that class itself. 100 * 101 * @override Always 102 */ 103 public Object getValueAt(Object oRecord, int nIdx); 104 105 /** 106 * Return whether a given column is editable for a given record. 107 * 108 * @param oRecord the record for which to determine editability. The actual class depends on the 109 * {@link util.swing.AbstractTableModel} you are working with. It will be declared in the documentation for 110 * the {@link util.swing.AbstractTableModel#getRecord} method of that class. 111 * @param nIdx the index of the column for which to determine editability. Indices run from 0 to 112 * {@link #getColumnCount getColumnCount() - 1}. 113 * 114 * @return whether the given column is editable for the given record. 115 * 116 * @override Always 117 */ 118 public boolean isElementEditable(Object oRecord, int nIdx); 119 120 /** 121 * Set the value of the given column for the given record. 122 * 123 * <p>This method will only be invoked if {@link #isElementEditable} returned true for the given cell and if 124 * the user actually edited the given cell.</p> 125 * 126 * <p>Note that changes will only become visible if they result in an event being fired to the JTable that 127 * uses the model.</p> 128 * 129 * @param oRecord the record for which to determine the value. The actual class depends on the 130 * {@link util.swing.AbstractTableModel} you are working with. It will be declared in the documentation for 131 * the {@link util.swing.AbstractTableModel#getRecord} method of that class. 132 * @param nIdx the index of the column for which to return the cell value. Indices run from 0 to 133 * {@link #getColumnCount getColumnCount() - 1}. 134 * @param oValue the value to become the new value of the cell. The class of this object depends on the 135 * editor used for editing the cell. Normally, this will be determined by {@link #getCellEditor}. 136 * 137 * @override Always 138 */ 139 public void setValueAt(Object oRecord, int nIdx, Object oValue); 140 141 /** 142 * Return true if the records can be sorted by the specified column. If true, {@link #getColumnOrder} 143 * must return a valid comparator for the specified column. 144 * 145 * @param nIdx the index of the column concerned. 146 * 147 * @return whether or not records can be sorted by the specified column. 148 * 149 * @override Always 150 * 151 * @since v3.0 12/14/2000 152 */ 153 public boolean canSortByColumn(int nIdx); 154 155 /** 156 * Return a comparator to be used when ordering records by the specified column. Depending on the 157 * specific TableModel, the comparator compares records or elements of records. 158 * 159 * @param nIdx the index of the column concerned. 160 * 161 * @override Always 162 * 163 * @since v3.0 12/14/2000 164 */ 165 public Comparator getColumnOrder(int nIdx); 166 }