diff options
author | David Gilbert <david.gilbert@object-refinery.com> | 2006-04-24 20:56:04 +0000 |
---|---|---|
committer | David Gilbert <david.gilbert@object-refinery.com> | 2006-04-24 20:56:04 +0000 |
commit | 60b22928a165697f31ff5cd3c3046480e09ffde7 (patch) | |
tree | 6c82248a6c623de299884b126bc19a7e3878a267 | |
parent | 208075f825b74d966af22a424ffd305e9be07506 (diff) | |
download | classpath-60b22928a165697f31ff5cd3c3046480e09ffde7.tar.gz |
2006-04-24 David Gilbert <david.gilbert@object-refinery.com>
* javax/swing/table/DefaultTableColumnModel.java
(DefaultTableColumnModel): Set selection model field and add 'this' as
listener directly,
(addColumn): Add 'this' as a PropertyChangeListener,
(removeColumn): Remove column before firing event, and remove 'this' as
a PropertyChangeListener,
(setSelectionModel): Remove 'this' as a listener from old model,
(propertyChange): Check for 'width' property rather than
TableColumn.COLUMN_WIDTH_PROPERTY.
----------------------------------------------------------------------
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | javax/swing/table/DefaultTableColumnModel.java | 41 |
2 files changed, 36 insertions, 17 deletions
@@ -1,3 +1,15 @@ +2006-04-24 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/table/DefaultTableColumnModel.java + (DefaultTableColumnModel): Set selection model field and add 'this' as + listener directly, + (addColumn): Add 'this' as a PropertyChangeListener, + (removeColumn): Remove column before firing event, and remove 'this' as + a PropertyChangeListener, + (setSelectionModel): Remove 'this' as a listener from old model, + (propertyChange): Check for 'width' property rather than + TableColumn.COLUMN_WIDTH_PROPERTY. + 2006-04-24 Chris Burdess <dog@gnu.org> Fixes PR 27262 diff --git a/javax/swing/table/DefaultTableColumnModel.java b/javax/swing/table/DefaultTableColumnModel.java index 32a9b94e7..cb140345f 100644 --- a/javax/swing/table/DefaultTableColumnModel.java +++ b/javax/swing/table/DefaultTableColumnModel.java @@ -114,26 +114,30 @@ public class DefaultTableColumnModel public DefaultTableColumnModel() { tableColumns = new Vector(); - setSelectionModel(createSelectionModel()); + selectionModel = createSelectionModel(); + selectionModel.addListSelectionListener(this); columnMargin = 1; columnSelectionAllowed = false; } /** * Adds a column to the model and sends a {@link TableColumnModelEvent} to - * all registered listeners. + * all registered listeners. The model registers itself with the column as a + * {@link PropertyChangeListener} so that changes to the column width will + * invalidate the cached {@link #totalColumnWidth} value. * - * @param col the column (<code>null</code> not permitted). + * @param column the column (<code>null</code> not permitted). * * @throws IllegalArgumentException if <code>col</code> is <code>null</code>. * * @see #removeColumn(TableColumn) */ - public void addColumn(TableColumn col) + public void addColumn(TableColumn column) { - if (col == null) + if (column == null) throw new IllegalArgumentException("Null 'col' argument."); - tableColumns.add(col); + tableColumns.add(column); + column.addPropertyChangeListener(this); invalidateWidthCache(); fireColumnAdded(new TableColumnModelEvent(this, 0, tableColumns.size() - 1)); @@ -144,17 +148,18 @@ public class DefaultTableColumnModel * to all registered listeners. If the specified column is <code>null</code> * or does not belong to the model, this method does nothing. * - * @param col the column to be removed (<code>null</code> permitted). + * @param column the column to be removed (<code>null</code> permitted). * * @see #addColumn(TableColumn) */ - public void removeColumn(TableColumn col) + public void removeColumn(TableColumn column) { - int index = this.tableColumns.indexOf(col); + int index = this.tableColumns.indexOf(column); if (index < 0) return; + tableColumns.remove(column); fireColumnRemoved(new TableColumnModelEvent(this, index, 0)); - tableColumns.remove(col); + column.removePropertyChangeListener(this); invalidateWidthCache(); } @@ -313,14 +318,15 @@ public class DefaultTableColumnModel * * @throws IllegalArgumentException if <code>model</code> is * <code>null</code>. + * + * @see #getSelectionModel() */ public void setSelectionModel(ListSelectionModel model) { if (model == null) throw new IllegalArgumentException(); - // FIXME: we are registered as a listener with the existing model, - // so we should remove that before updating the model... + selectionModel.removeListSelectionListener(this); selectionModel = model; selectionModel.addListSelectionListener(this); } @@ -570,14 +576,15 @@ public class DefaultTableColumnModel } /** - * propertyChange handles changes occuring in the properties of the - * model's columns. + * Receives notification of property changes for the columns in the model. + * If the <code>width</code> property for any column changes, we invalidate + * the {@link #totalColumnWidth} value here. * - * @param evt PropertyChangeEvent + * @param event the event. */ - public void propertyChange(PropertyChangeEvent evt) + public void propertyChange(PropertyChangeEvent event) { - if (evt.getPropertyName().equals(TableColumn.COLUMN_WIDTH_PROPERTY)) + if (event.getPropertyName().equals("width")) invalidateWidthCache(); } |