001 /* TableColumnModel.java -- 002 Copyright (C) 2002, 2004, 2005, 2006, Free Software Foundation, Inc. 003 004 This file is part of GNU Classpath. 005 006 GNU Classpath is free software; you can redistribute it and/or modify 007 it under the terms of the GNU General Public License as published by 008 the Free Software Foundation; either version 2, or (at your option) 009 any later version. 010 011 GNU Classpath is distributed in the hope that it will be useful, but 012 WITHOUT ANY WARRANTY; without even the implied warranty of 013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 General Public License for more details. 015 016 You should have received a copy of the GNU General Public License 017 along with GNU Classpath; see the file COPYING. If not, write to the 018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 019 02110-1301 USA. 020 021 Linking this library statically or dynamically with other modules is 022 making a combined work based on this library. Thus, the terms and 023 conditions of the GNU General Public License cover the whole 024 combination. 025 026 As a special exception, the copyright holders of this library give you 027 permission to link this library with independent modules to produce an 028 executable, regardless of the license terms of these independent 029 modules, and to copy and distribute the resulting executable under 030 terms of your choice, provided that you also meet, for each linked 031 independent module, the terms and conditions of the license of that 032 module. An independent module is a module which is not derived from 033 or based on this library. If you modify this library, you may extend 034 this exception to your version of the library, but you are not 035 obligated to do so. If you do not wish to do so, delete this 036 exception statement from your version. */ 037 038 039 package javax.swing.table; 040 041 import java.util.Enumeration; 042 043 import javax.swing.JTable; 044 import javax.swing.ListSelectionModel; 045 import javax.swing.event.ChangeEvent; 046 import javax.swing.event.TableColumnModelEvent; 047 import javax.swing.event.TableColumnModelListener; 048 049 /** 050 * The interface used by {@link JTable} to access the columns in the table 051 * view. 052 * 053 * @author Andrew Selkirk 054 */ 055 public interface TableColumnModel 056 { 057 /** 058 * Adds a column to the model. 059 * 060 * @param column the new column (<code>null</code> not permitted). 061 * 062 * @throws IllegalArgumentException if <code>column</code> is 063 * <code>null</code>. 064 */ 065 void addColumn(TableColumn column); 066 067 /** 068 * Removes a column from the model. If <code>column</code> is not defined 069 * in the model, this method does nothing. 070 * 071 * @param column TableColumn 072 */ 073 void removeColumn(TableColumn column); 074 075 /** 076 * Moves a column. 077 * 078 * @param columnIndex Index of column to move 079 * @param newIndex New index of column 080 */ 081 void moveColumn(int columnIndex, int newIndex); 082 083 /** 084 * Sets the column margin and sends a {@link ChangeEvent} to all registered 085 * {@link TableColumnModelListener}s registered with the model. 086 * 087 * @param margin the column margin. 088 * 089 * @see #getColumnMargin() 090 */ 091 void setColumnMargin(int margin); 092 093 /** 094 * Returns the number of columns in the model. 095 * 096 * @return The column count. 097 */ 098 int getColumnCount(); 099 100 /** 101 * Returns an enumeration of the columns in the model. 102 * 103 * @return An enumeration of the columns in the model. 104 */ 105 Enumeration<TableColumn> getColumns(); 106 107 /** 108 * Returns the index of the {@link TableColumn} with the given identifier. 109 * 110 * @param identifier the identifier (<code>null</code> not permitted). 111 * 112 * @return The index of the {@link TableColumn} with the given identifier. 113 * 114 * @throws IllegalArgumentException if <code>identifier</code> is 115 * <code>null</code> or there is no column with that identifier. 116 */ 117 int getColumnIndex(Object identifier); 118 119 /** 120 * Returns the <code>TableColumn</code> at the specified index. 121 * 122 * @param columnIndex the column index. 123 * 124 * @return The table column. 125 */ 126 TableColumn getColumn(int columnIndex); 127 128 /** 129 * Returns the column margin. 130 * 131 * @return The column margin. 132 * 133 * @see #setColumnMargin(int) 134 */ 135 int getColumnMargin(); 136 137 /** 138 * Returns the index of the column that contains the specified x-coordinate, 139 * assuming that: 140 * <ul> 141 * <li>column zero begins at position zero;</li> 142 * <li>all columns appear in order;</li> 143 * <li>individual column widths are taken into account, but the column margin 144 * is ignored.</li> 145 * </ul> 146 * If no column contains the specified position, this method returns 147 * <code>-1</code>. 148 * 149 * @param xPosition the x-position. 150 * 151 * @return The column index, or <code>-1</code>. 152 */ 153 int getColumnIndexAtX(int xPosition); 154 155 /** 156 * Returns total width of all the columns in the model, ignoring the 157 * column margin (see {@link #getColumnMargin()}). 158 * 159 * @return The total width of all the columns. 160 */ 161 int getTotalColumnWidth(); 162 163 /** 164 * Sets the flag that indicates whether or not column selection is allowed. 165 * 166 * @param allowed the new flag value. 167 * 168 * @see #getColumnSelectionAllowed() 169 */ 170 void setColumnSelectionAllowed(boolean allowed); 171 172 /** 173 * Returns <code>true</code> if column selection is allowed, and 174 * <code>false</code> if column selection is not allowed. 175 * 176 * @return A boolean. 177 * 178 * @see #setColumnSelectionAllowed(boolean) 179 */ 180 boolean getColumnSelectionAllowed(); 181 182 /** 183 * getSelectedColumns 184 * @return Selected columns 185 */ 186 int[] getSelectedColumns(); 187 188 /** 189 * Returns the number of selected columns in the model. 190 * 191 * @return The selected column count. 192 * 193 * @see #getSelectionModel() 194 */ 195 int getSelectedColumnCount(); 196 197 /** 198 * Sets the selection model that will be used to keep track of the selected 199 * columns. 200 * 201 * @param model the selection model (<code>null</code> not permitted). 202 * 203 * @throws IllegalArgumentException if <code>model</code> is 204 * <code>null</code>. 205 */ 206 void setSelectionModel(ListSelectionModel model); 207 208 /** 209 * Returns the selection model used to track table column selections. 210 * 211 * @return The selection model. 212 * 213 * @see #setSelectionModel(ListSelectionModel) 214 */ 215 ListSelectionModel getSelectionModel(); 216 217 /** 218 * Registers a listener with the model, so that it will receive 219 * {@link TableColumnModelEvent} notifications. 220 * 221 * @param listener the listener (<code>null</code> ignored). 222 */ 223 void addColumnModelListener(TableColumnModelListener listener); 224 225 /** 226 * Deregisters a listener, so that it will no longer receive 227 * {@link TableColumnModelEvent} notifications. 228 * 229 * @param listener the listener. 230 */ 231 void removeColumnModelListener(TableColumnModelListener listener); 232 }