252 /** 253 * Returns the index of the first column in the <code>tableColumns</code> 254 * array whose identifier is equal to <code>identifier</code>, 255 * when compared using <code>equals</code>. 256 * 257 * @param identifier the identifier object 258 * @return the index of the first column in the 259 * <code>tableColumns</code> array whose identifier 260 * is equal to <code>identifier</code> 261 * @exception IllegalArgumentException if <code>identifier</code> 262 * is <code>null</code>, or if no 263 * <code>TableColumn</code> has this 264 * <code>identifier</code> 265 * @see #getColumn 266 */ 267 public int getColumnIndex(Object identifier) { 268 if (identifier == null) { 269 throw new IllegalArgumentException("Identifier is null"); 270 } 271 272 Enumeration enumeration = getColumns(); 273 TableColumn aColumn; 274 int index = 0; 275 276 while (enumeration.hasMoreElements()) { 277 aColumn = (TableColumn)enumeration.nextElement(); 278 // Compare them this way in case the column's identifier is null. 279 if (identifier.equals(aColumn.getIdentifier())) 280 return index; 281 index++; 282 } 283 throw new IllegalArgumentException("Identifier not found"); 284 } 285 286 /** 287 * Returns the <code>TableColumn</code> object for the column 288 * at <code>columnIndex</code>. 289 * 290 * @param columnIndex the index of the column desired 291 * @return the <code>TableColumn</code> object for the column 292 * at <code>columnIndex</code> 293 */ 294 public TableColumn getColumn(int columnIndex) { 295 return tableColumns.elementAt(columnIndex); 296 } 297 709 public void valueChanged(ListSelectionEvent e) { 710 fireColumnSelectionChanged(e); 711 } 712 713 // 714 // Protected Methods 715 // 716 717 /** 718 * Creates a new default list selection model. 719 */ 720 protected ListSelectionModel createSelectionModel() { 721 return new DefaultListSelectionModel(); 722 } 723 724 /** 725 * Recalculates the total combined width of all columns. Updates the 726 * <code>totalColumnWidth</code> property. 727 */ 728 protected void recalcWidthCache() { 729 Enumeration enumeration = getColumns(); 730 totalColumnWidth = 0; 731 while (enumeration.hasMoreElements()) { 732 totalColumnWidth += ((TableColumn)enumeration.nextElement()).getWidth(); 733 } 734 } 735 736 private void invalidateWidthCache() { 737 totalColumnWidth = -1; 738 } 739 740 } // End of class DefaultTableColumnModel | 252 /** 253 * Returns the index of the first column in the <code>tableColumns</code> 254 * array whose identifier is equal to <code>identifier</code>, 255 * when compared using <code>equals</code>. 256 * 257 * @param identifier the identifier object 258 * @return the index of the first column in the 259 * <code>tableColumns</code> array whose identifier 260 * is equal to <code>identifier</code> 261 * @exception IllegalArgumentException if <code>identifier</code> 262 * is <code>null</code>, or if no 263 * <code>TableColumn</code> has this 264 * <code>identifier</code> 265 * @see #getColumn 266 */ 267 public int getColumnIndex(Object identifier) { 268 if (identifier == null) { 269 throw new IllegalArgumentException("Identifier is null"); 270 } 271 272 Enumeration<TableColumn> enumeration = getColumns(); 273 TableColumn aColumn; 274 int index = 0; 275 276 while (enumeration.hasMoreElements()) { 277 aColumn = enumeration.nextElement(); 278 // Compare them this way in case the column's identifier is null. 279 if (identifier.equals(aColumn.getIdentifier())) 280 return index; 281 index++; 282 } 283 throw new IllegalArgumentException("Identifier not found"); 284 } 285 286 /** 287 * Returns the <code>TableColumn</code> object for the column 288 * at <code>columnIndex</code>. 289 * 290 * @param columnIndex the index of the column desired 291 * @return the <code>TableColumn</code> object for the column 292 * at <code>columnIndex</code> 293 */ 294 public TableColumn getColumn(int columnIndex) { 295 return tableColumns.elementAt(columnIndex); 296 } 297 709 public void valueChanged(ListSelectionEvent e) { 710 fireColumnSelectionChanged(e); 711 } 712 713 // 714 // Protected Methods 715 // 716 717 /** 718 * Creates a new default list selection model. 719 */ 720 protected ListSelectionModel createSelectionModel() { 721 return new DefaultListSelectionModel(); 722 } 723 724 /** 725 * Recalculates the total combined width of all columns. Updates the 726 * <code>totalColumnWidth</code> property. 727 */ 728 protected void recalcWidthCache() { 729 Enumeration<TableColumn> enumeration = getColumns(); 730 totalColumnWidth = 0; 731 while (enumeration.hasMoreElements()) { 732 totalColumnWidth += enumeration.nextElement().getWidth(); 733 } 734 } 735 736 private void invalidateWidthCache() { 737 totalColumnWidth = -1; 738 } 739 740 } // End of class DefaultTableColumnModel |