From 16aae3d209b6d248f12c5d064273c33bcb5e0ce2 Mon Sep 17 00:00:00 2001 From: Michael Koch Date: Thu, 2 Oct 2003 09:37:04 +0000 Subject: [PATCH] 2003-10-02 Michael Koch * javax/swing/table/AbstractTableModel.java (findColumnName): Prevent from NullPointerException if argument columnName is null. 2003-10-02 Michael Koch * javax/swing/table/AbstractTableModel.java: This patch is based on a patch done by Arnaud Vandyck . (getColumnName): Fixed method documentation. (findColumn): Likewise. (getColumnClass): Likewise. (isCellEditable): Likewise. (setValueAt): Likewise. (addTableModelListener): Likewise. (removeTableModelListener): Likewise. (getTableModelListeners): New method. 2003-10-02 Michael Koch * javax/swing/table/AbstractTableModel.java: Reformated. From-SVN: r72019 --- libjava/ChangeLog | 25 + .../javax/swing/table/AbstractTableModel.java | 538 +++++++++--------- 2 files changed, 303 insertions(+), 260 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 2ab3393a77a..c11753b9a33 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,28 @@ +2003-10-02 Michael Koch + + * javax/swing/table/AbstractTableModel.java + (findColumnName): Prevent from NullPointerException if argument + columnName is null. + +2003-10-02 Michael Koch + + * javax/swing/table/AbstractTableModel.java: + This patch is based on a patch done by Arnaud Vandyck + . + (getColumnName): Fixed method documentation. + (findColumn): Likewise. + (getColumnClass): Likewise. + (isCellEditable): Likewise. + (setValueAt): Likewise. + (addTableModelListener): Likewise. + (removeTableModelListener): Likewise. + (getTableModelListeners): New method. + +2003-10-02 Michael Koch + + * javax/swing/table/AbstractTableModel.java: + Reformated. + 2003-10-01 Bryce McKinlay Fix PR libgcj/12475 diff --git a/libjava/javax/swing/table/AbstractTableModel.java b/libjava/javax/swing/table/AbstractTableModel.java index 2f7ce40ce87..64e4d12cff4 100644 --- a/libjava/javax/swing/table/AbstractTableModel.java +++ b/libjava/javax/swing/table/AbstractTableModel.java @@ -46,273 +46,291 @@ import javax.swing.event.TableModelListener; /** * AbstractTableModel + * * @author Andrew Selkirk */ public abstract class AbstractTableModel implements TableModel, Serializable { static final long serialVersionUID = -5798593159423650347L; - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- - - /** - * listenerList - */ - protected EventListenerList listenerList = new EventListenerList(); - - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - - /** - * Constructor AbstractTableModel - */ - public AbstractTableModel() { - // TODO - } // AbstractTableModel() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * getColumnName - * @param value0 TODO - * @returns String - */ - public String getColumnName(int columnIndex) { - - // Variables - int index; - int left; - int base; - int multiplier; - StringBuffer buffer; - boolean foundFirst; - - // Ok, this is not the best solution in the world - // and it does produce wrong answers starting 1378 - // but it's a start. I sure hope there is a more - // simple algorithm. I started with a base 10 to - // base 26 converter and later found that there - // were so many are exceptions that it has morphed - // into a pile of goop. + /** + * listenerList + */ + protected EventListenerList listenerList = new EventListenerList(); + + /** + * Constructor AbstractTableModel + */ + public AbstractTableModel() + { + // TODO + } + + /** + * Get the name of the column for this index. If you do not override + * this methode, you'll get something like: 0, A; 1, B; ...; AA; AB; + * ... + * + * @param columnIndex The index of the column. + * + * @return The name of the column. + */ + public String getColumnName (int columnIndex) + { + // Ok, this is not the best solution in the world + // and it does produce wrong answers starting 1378 + // but it's a start. I sure hope there is a more + // simple algorithm. I started with a base 10 to + // base 26 converter and later found that there + // were so many are exceptions that it has morphed + // into a pile of goop. - // NOTE2: I have a working algorithm which is much - // much simplier and works for all values...I'll - // be adding it soon... - - // Process Exponent levels - buffer = new StringBuffer(); - left = columnIndex; - foundFirst = false; - for (index = 6; index >= 0; index--) { - base = (int) (Math.pow(26, index)); - if (index > 1) { - base = base + (int) (Math.pow(26, index - 1)); - } - if (base <= left) { - multiplier = left / base; - if (foundFirst == false && index > 0) { - buffer.append((char) (multiplier + 64)); - } else { - buffer.append((char) (multiplier + 65)); - } - left = left - (base * multiplier); - foundFirst = true; - } else if (foundFirst == true || index == 0) { - buffer.append('A'); - } - } // for - - // Return Column Name - return buffer.toString(); - - } // getColumnName() - - /** - * findColumn - * @param value0 TODO - * @returns int - */ - public int findColumn(String columnName) { - - // Variables - int index; - String name; - int count; - - // Process Columns - count = getColumnCount(); - for (index = 0; index < count; index++) { - name = getColumnName(index); - if (columnName.equals(name) == true) { - return index; - } // if - } // for - - // Unable to Locate - return -1; - - } // findColumn() - - /** - * getColumnClass - * @param value0 TODO - * @returns Class - */ - public Class getColumnClass(int columnIndex) { - return Object.class; - } // getColumnClass() - - /** - * isCellEditable - * @param value0 TODO - * @param value1 TODO - * @returns boolean - */ - public boolean isCellEditable(int rowIndex, int columnIndex) { - return false; - } // isCellEditable() - - /** - * setValueAt - * @param value0 TODO - * @param value1 TODO - * @param value2 TODO - */ - public void setValueAt(Object value, int rowIndex, int columnIndex) { - // Do nothing... - } // setValueAt() - - /** - * addTableModelListener - * @param value0 TODO - */ - public void addTableModelListener(TableModelListener listener) { - listenerList.add(TableModelListener.class, listener); - } // addTableModelListener() - - /** - * removeTableModelListener - * @param value0 TODO - */ - public void removeTableModelListener(TableModelListener listener) { - listenerList.remove(TableModelListener.class, listener); - } // removeTableModelListener() - - /** - * fireTableDataChanged - */ - public void fireTableDataChanged() { - fireTableChanged(new TableModelEvent(this)); - } // fireTableDataChanged() - - /** - * fireTableStructureChanged - */ - public void fireTableStructureChanged() { - fireTableChanged(new TableModelEvent(this, - TableModelEvent.HEADER_ROW)); - } // fireTableStructureChanged() - - /** - * fireTableRowsInserted - * @param value0 TODO - * @param value1 TODO - */ - public void fireTableRowsInserted(int firstRow, int lastRow) { - fireTableChanged(new TableModelEvent(this, firstRow, lastRow, - TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); - } // fireTableRowsInserted() - - /** - * fireTableRowsUpdated - * @param value0 TODO - * @param value1 TODO - */ - public void fireTableRowsUpdated(int firstRow, int lastRow) { - fireTableChanged(new TableModelEvent(this, firstRow, lastRow, - TableModelEvent.ALL_COLUMNS, TableModelEvent.UPDATE)); - } // fireTableRowsUpdated() - - /** - * fireTableRowsDeleted - * @param value0 TODO - * @param value1 TODO - */ - public void fireTableRowsDeleted(int firstRow, int lastRow) { - fireTableChanged(new TableModelEvent(this, firstRow, lastRow, - TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE)); - } // fireTableRowsDeleted() - - /** - * fireTableCellUpdated - * @param value0 TODO - * @param value1 TODO - */ - public void fireTableCellUpdated(int row, int column) { - fireTableChanged(new TableModelEvent(this, row, row, column)); - } // fireTableCellUpdated() - - /** - * fireTableChanged - * @param value0 TODO - */ - public void fireTableChanged(TableModelEvent event) { - - // Variables - Object[] list; - int index; - TableModelListener listener; + // NOTE2: I have a working algorithm which is much + // much simplier and works for all values...I'll + // be adding it soon... + + StringBuffer buffer = new StringBuffer(); + int left = columnIndex; + boolean foundFirst = false; + + // Process Exponent levels. + for (int index = 6; index >= 0; index--) + { + int base = (int) (Math.pow (26, index)); + + if (index > 1) + { + base = base + (int) (Math.pow (26, index - 1)); + } + + if (base <= left) + { + int multiplier = left / base; + + if (foundFirst == false + && index > 0) + { + buffer.append ((char) (multiplier + 64)); + } + else + { + buffer.append ((char) (multiplier + 65)); + } + + left = left - (base * multiplier); + foundFirst = true; + } + else if (foundFirst == true + || index == 0) + { + buffer.append('A'); + } + } + + // Return column name. + return buffer.toString(); + } + + /** + * Return the index of the given name. + * + * @param columnName The name of the column. + * + * @return The index of the column, -1 if not found. + */ + public int findColumn (String columnName) + { + int count = getColumnCount(); + + for (int index = 0; index < count; index++) + { + String name = getColumnName (index); + + if (name.equals (columnName)) + return index; + } + + // Unable to locate. + return -1; + } + + /** + * Returns the class of a comlumn. + * + * @param columnIndex The index of the column. + * + * @return The class type of the column. + */ + public Class getColumnClass (int columnIndex) + { + return Object.class; + } + + /** + * Tells whether a cell is editable. + * + * @param rowIndex The row of the cell. + * @param columnIndex The index of the cell. + * + * @return True if cell is editable. + */ + public boolean isCellEditable (int rowIndex, int columnIndex) + { + return false; + } + + /** + * Sets a cell to a value. + * + * @param value New value of cell. + * @param rowIndex The row of the cell. + * @param columnIndex The column of the cell. + */ + public void setValueAt (Object value, int rowIndex, int columnIndex) + { + // Do nothing... + } + + /** + * Add a TableModelListener. + * + * @param listener The listener to add. + */ + public void addTableModelListener (TableModelListener listener) + { + listenerList.add (TableModelListener.class, listener); + } + + /** + * Removes a TableModelListener. + * + * @param listener The listener to remove. + */ + public void removeTableModelListener (TableModelListener listener) + { + listenerList.remove (TableModelListener.class, listener); + } + + /** + * Return all registered TableModelListener objects. + * + * @return Array of TableModelListener objects. + * + * @since 1.4 + */ + public TableModelListener[] getTableModelListeners() + { + return (TableModelListener[]) + listenerList.getListeners (TableModelListener.class); + } + + /** + * fireTableDataChanged + */ + public void fireTableDataChanged() + { + fireTableChanged (new TableModelEvent (this)); + } + + /** + * fireTableStructureChanged + */ + public void fireTableStructureChanged() + { + fireTableChanged (new TableModelEvent (this, TableModelEvent.HEADER_ROW)); + } + + /** + * fireTableRowsInserted + * @param value0 TODO + * @param value1 TODO + */ + public void fireTableRowsInserted (int firstRow, int lastRow) + { + fireTableChanged (new TableModelEvent (this, firstRow, lastRow, + TableModelEvent.ALL_COLUMNS, + TableModelEvent.INSERT)); + } + + /** + * fireTableRowsUpdated + * @param value0 TODO + * @param value1 TODO + */ + public void fireTableRowsUpdated (int firstRow, int lastRow) + { + fireTableChanged (new TableModelEvent (this, firstRow, lastRow, + TableModelEvent.ALL_COLUMNS, + TableModelEvent.UPDATE)); + } + + /** + * fireTableRowsDeleted + * @param value0 TODO + * @param value1 TODO + */ + public void fireTableRowsDeleted(int firstRow, int lastRow) + { + fireTableChanged (new TableModelEvent (this, firstRow, lastRow, + TableModelEvent.ALL_COLUMNS, + TableModelEvent.DELETE)); + } + + /** + * fireTableCellUpdated + * @param value0 TODO + * @param value1 TODO + */ + public void fireTableCellUpdated (int row, int column) + { + fireTableChanged (new TableModelEvent (this, row, row, column)); + } + + /** + * fireTableChanged + * @param value0 TODO + */ + public void fireTableChanged (TableModelEvent event) + { + int index; + TableModelListener listener; + Object[] list = listenerList.getListenerList(); - // Get Listener List - list = listenerList.getListenerList(); - - for (index = 0; index < list.length; index += 2) { - - // Get Listener - listener = (TableModelListener) list[index + 1]; - - // Notify Listener - listener.tableChanged(event); - - } // for: index - - } // fireTableChanged() - - /** - * getListeners - * @param value0 TODO - * @returns EventListener[] - */ - public EventListener[] getListeners(Class listenerType) { - return listenerList.getListeners(listenerType); - } // getListeners() - - /** - * getValueAt - * @param value0 TODO - * @param value1 TODO - * @returns Object - */ - public abstract Object getValueAt(int row, int column); - - /** - * getColumnCount - * @returns int - */ - public abstract int getColumnCount(); - - /** - * getRowCount - * @returns int - */ - public abstract int getRowCount(); - + for (index = 0; index < list.length; index += 2) + { + listener = (TableModelListener) list [index + 1]; + listener.tableChanged (event); + } + } + + /** + * getListeners + * @param value0 TODO + * @return EventListener[] + */ + public EventListener[] getListeners (Class listenerType) + { + return listenerList.getListeners (listenerType); + } + + /** + * getValueAt + * @param value0 TODO + * @param value1 TODO + * @return Object + */ + public abstract Object getValueAt (int row, int column); + + /** + * getColumnCount + * @return int + */ + public abstract int getColumnCount(); + + /** + * getRowCount + * @return int + */ + public abstract int getRowCount(); } // AbstractTableModel - -- 2.30.2