001 /*
002 * Copyright 1997-2004 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.swing.table;
027
028 import java.util.Enumeration;
029 import javax.swing.event.ChangeEvent;
030 import javax.swing.event.*;
031 import javax.swing.*;
032
033 /**
034 * Defines the requirements for a table column model object suitable for
035 * use with <code>JTable</code>.
036 *
037 * @version 1.32 05/05/07
038 * @author Alan Chung
039 * @author Philip Milne
040 * @see DefaultTableColumnModel
041 */
042 public interface TableColumnModel {
043 //
044 // Modifying the model
045 //
046
047 /**
048 * Appends <code>aColumn</code> to the end of the
049 * <code>tableColumns</code> array.
050 * This method posts a <code>columnAdded</code>
051 * event to its listeners.
052 *
053 * @param aColumn the <code>TableColumn</code> to be added
054 * @see #removeColumn
055 */
056 public void addColumn(TableColumn aColumn);
057
058 /**
059 * Deletes the <code>TableColumn</code> <code>column</code> from the
060 * <code>tableColumns</code> array. This method will do nothing if
061 * <code>column</code> is not in the table's column list.
062 * This method posts a <code>columnRemoved</code>
063 * event to its listeners.
064 *
065 * @param column the <code>TableColumn</code> to be removed
066 * @see #addColumn
067 */
068 public void removeColumn(TableColumn column);
069
070 /**
071 * Moves the column and its header at <code>columnIndex</code> to
072 * <code>newIndex</code>. The old column at <code>columnIndex</code>
073 * will now be found at <code>newIndex</code>. The column that used
074 * to be at <code>newIndex</code> is shifted left or right
075 * to make room. This will not move any columns if
076 * <code>columnIndex</code> equals <code>newIndex</code>. This method
077 * posts a <code>columnMoved</code> event to its listeners.
078 *
079 * @param columnIndex the index of column to be moved
080 * @param newIndex index of the column's new location
081 * @exception IllegalArgumentException if <code>columnIndex</code> or
082 * <code>newIndex</code>
083 * are not in the valid range
084 */
085 public void moveColumn(int columnIndex, int newIndex);
086
087 /**
088 * Sets the <code>TableColumn</code>'s column margin to
089 * <code>newMargin</code>. This method posts
090 * a <code>columnMarginChanged</code> event to its listeners.
091 *
092 * @param newMargin the width, in pixels, of the new column margins
093 * @see #getColumnMargin
094 */
095 public void setColumnMargin(int newMargin);
096
097 //
098 // Querying the model
099 //
100
101 /**
102 * Returns the number of columns in the model.
103 * @return the number of columns in the model
104 */
105 public int getColumnCount();
106
107 /**
108 * Returns an <code>Enumeration</code> of all the columns in the model.
109 * @return an <code>Enumeration</code> of all the columns in the model
110 */
111 public Enumeration<TableColumn> getColumns();
112
113 /**
114 * Returns the index of the first column in the table
115 * whose identifier is equal to <code>identifier</code>,
116 * when compared using <code>equals</code>.
117 *
118 * @param columnIdentifier the identifier object
119 * @return the index of the first table column
120 * whose identifier is equal to <code>identifier</code>
121 * @exception IllegalArgumentException if <code>identifier</code>
122 * is <code>null</code>, or no
123 * <code>TableColumn</code> has this
124 * <code>identifier</code>
125 * @see #getColumn
126 */
127 public int getColumnIndex(Object columnIdentifier);
128
129 /**
130 * Returns the <code>TableColumn</code> object for the column at
131 * <code>columnIndex</code>.
132 *
133 * @param columnIndex the index of the desired column
134 * @return the <code>TableColumn</code> object for
135 * the column at <code>columnIndex</code>
136 */
137 public TableColumn getColumn(int columnIndex);
138
139 /**
140 * Returns the width between the cells in each column.
141 * @return the margin, in pixels, between the cells
142 */
143 public int getColumnMargin();
144
145 /**
146 * Returns the index of the column that lies on the
147 * horizontal point, <code>xPosition</code>;
148 * or -1 if it lies outside the any of the column's bounds.
149 *
150 * In keeping with Swing's separable model architecture, a
151 * TableColumnModel does not know how the table columns actually appear on
152 * screen. The visual presentation of the columns is the responsibility
153 * of the view/controller object using this model (typically JTable). The
154 * view/controller need not display the columns sequentially from left to
155 * right. For example, columns could be displayed from right to left to
156 * accomodate a locale preference or some columns might be hidden at the
157 * request of the user. Because the model does not know how the columns
158 * are laid out on screen, the given <code>xPosition</code> should not be
159 * considered to be a coordinate in 2D graphics space. Instead, it should
160 * be considered to be a width from the start of the first column in the
161 * model. If the column index for a given X coordinate in 2D space is
162 * required, <code>JTable.columnAtPoint</code> can be used instead.
163 *
164 * @return the index of the column; or -1 if no column is found
165 * @see javax.swing.JTable#columnAtPoint
166 */
167 public int getColumnIndexAtX(int xPosition);
168
169 /**
170 * Returns the total width of all the columns.
171 * @return the total computed width of all columns
172 */
173 public int getTotalColumnWidth();
174
175 //
176 // Selection
177 //
178
179 /**
180 * Sets whether the columns in this model may be selected.
181 * @param flag true if columns may be selected; otherwise false
182 * @see #getColumnSelectionAllowed
183 */
184 public void setColumnSelectionAllowed(boolean flag);
185
186 /**
187 * Returns true if columns may be selected.
188 * @return true if columns may be selected
189 * @see #setColumnSelectionAllowed
190 */
191 public boolean getColumnSelectionAllowed();
192
193 /**
194 * Returns an array of indicies of all selected columns.
195 * @return an array of integers containing the indicies of all
196 * selected columns; or an empty array if nothing is selected
197 */
198 public int[] getSelectedColumns();
199
200 /**
201 * Returns the number of selected columns.
202 *
203 * @return the number of selected columns; or 0 if no columns are selected
204 */
205 public int getSelectedColumnCount();
206
207 /**
208 * Sets the selection model.
209 *
210 * @param newModel a <code>ListSelectionModel</code> object
211 * @see #getSelectionModel
212 */
213 public void setSelectionModel(ListSelectionModel newModel);
214
215 /**
216 * Returns the current selection model.
217 *
218 * @return a <code>ListSelectionModel</code> object
219 * @see #setSelectionModel
220 */
221 public ListSelectionModel getSelectionModel();
222
223 //
224 // Listener
225 //
226
227 /**
228 * Adds a listener for table column model events.
229 *
230 * @param x a <code>TableColumnModelListener</code> object
231 */
232 public void addColumnModelListener(TableColumnModelListener x);
233
234 /**
235 * Removes a listener for table column model events.
236 *
237 * @param x a <code>TableColumnModelListener</code> object
238 */
239 public void removeColumnModelListener(TableColumnModelListener x);
240 }
|