Commit 16aae3d2 by Michael Koch Committed by Michael Koch

2003-10-02 Michael Koch <konqueror@gmx.de>

	* javax/swing/table/AbstractTableModel.java
	(findColumnName): Prevent from NullPointerException if argument
	columnName is null.

2003-10-02  Michael Koch  <konqueror@gmx.de>

	* javax/swing/table/AbstractTableModel.java:
	This patch is based on a patch done by Arnaud Vandyck
	<arnaud.vandyck@ulg.ac.be>.
	(getColumnName): Fixed method documentation.
	(findColumn): Likewise.
	(getColumnClass): Likewise.
	(isCellEditable): Likewise.
	(setValueAt): Likewise.
	(addTableModelListener): Likewise.
	(removeTableModelListener): Likewise.
	(getTableModelListeners): New method.

2003-10-02  Michael Koch  <konqueror@gmx.de>

	* javax/swing/table/AbstractTableModel.java:
	Reformated.

From-SVN: r72019
parent ffb344c1
2003-10-02 Michael Koch <konqueror@gmx.de>
* javax/swing/table/AbstractTableModel.java
(findColumnName): Prevent from NullPointerException if argument
columnName is null.
2003-10-02 Michael Koch <konqueror@gmx.de>
* javax/swing/table/AbstractTableModel.java:
This patch is based on a patch done by Arnaud Vandyck
<arnaud.vandyck@ulg.ac.be>.
(getColumnName): Fixed method documentation.
(findColumn): Likewise.
(getColumnClass): Likewise.
(isCellEditable): Likewise.
(setValueAt): Likewise.
(addTableModelListener): Likewise.
(removeTableModelListener): Likewise.
(getTableModelListeners): New method.
2003-10-02 Michael Koch <konqueror@gmx.de>
* javax/swing/table/AbstractTableModel.java:
Reformated.
2003-10-01 Bryce McKinlay <bryce@mckinlay.net.nz> 2003-10-01 Bryce McKinlay <bryce@mckinlay.net.nz>
Fix PR libgcj/12475 Fix PR libgcj/12475
......
...@@ -46,53 +46,37 @@ import javax.swing.event.TableModelListener; ...@@ -46,53 +46,37 @@ import javax.swing.event.TableModelListener;
/** /**
* AbstractTableModel * AbstractTableModel
*
* @author Andrew Selkirk * @author Andrew Selkirk
*/ */
public abstract class AbstractTableModel implements TableModel, Serializable public abstract class AbstractTableModel implements TableModel, Serializable
{ {
static final long serialVersionUID = -5798593159423650347L; static final long serialVersionUID = -5798593159423650347L;
//-------------------------------------------------------------
// Variables --------------------------------------------------
//-------------------------------------------------------------
/** /**
* listenerList * listenerList
*/ */
protected EventListenerList listenerList = new EventListenerList(); protected EventListenerList listenerList = new EventListenerList();
//-------------------------------------------------------------
// Initialization ---------------------------------------------
//-------------------------------------------------------------
/** /**
* Constructor AbstractTableModel * Constructor AbstractTableModel
*/ */
public AbstractTableModel() { public AbstractTableModel()
{
// TODO // TODO
} // AbstractTableModel() }
//-------------------------------------------------------------
// Methods ----------------------------------------------------
//-------------------------------------------------------------
/** /**
* getColumnName * Get the name of the column for this index. If you do not override
* @param value0 TODO * this methode, you'll get something like: 0, A; 1, B; ...; AA; AB;
* @returns String * ...
*
* @param columnIndex The index of the column.
*
* @return The name of the column.
*/ */
public String getColumnName(int columnIndex) { 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 // Ok, this is not the best solution in the world
// and it does produce wrong answers starting 1378 // and it does produce wrong answers starting 1378
// but it's a start. I sure hope there is a more // but it's a start. I sure hope there is a more
...@@ -105,214 +89,248 @@ public abstract class AbstractTableModel implements TableModel, Serializable ...@@ -105,214 +89,248 @@ public abstract class AbstractTableModel implements TableModel, Serializable
// much simplier and works for all values...I'll // much simplier and works for all values...I'll
// be adding it soon... // be adding it soon...
// Process Exponent levels StringBuffer buffer = new StringBuffer();
buffer = new StringBuffer(); int left = columnIndex;
left = columnIndex; boolean foundFirst = false;
foundFirst = false;
for (index = 6; index >= 0; index--) { // Process Exponent levels.
base = (int) (Math.pow(26, index)); for (int index = 6; index >= 0; index--)
if (index > 1) { {
base = base + (int) (Math.pow(26, index - 1)); 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));
} }
if (base <= left) { else
multiplier = left / base; {
if (foundFirst == false && index > 0) { buffer.append ((char) (multiplier + 65));
buffer.append((char) (multiplier + 64));
} else {
buffer.append((char) (multiplier + 65));
} }
left = left - (base * multiplier); left = left - (base * multiplier);
foundFirst = true; foundFirst = true;
} else if (foundFirst == true || index == 0) { }
else if (foundFirst == true
|| index == 0)
{
buffer.append('A'); buffer.append('A');
} }
} // for }
// Return Column Name // Return column name.
return buffer.toString(); return buffer.toString();
}
} // getColumnName()
/** /**
* findColumn * Return the index of the given name.
* @param value0 TODO *
* @returns int * @param columnName The name of the column.
*
* @return The index of the column, -1 if not found.
*/ */
public int findColumn(String columnName) { public int findColumn (String columnName)
{
int count = getColumnCount();
// Variables for (int index = 0; index < count; index++)
int index; {
String name; String name = getColumnName (index);
int count;
if (name.equals (columnName))
// Process Columns
count = getColumnCount();
for (index = 0; index < count; index++) {
name = getColumnName(index);
if (columnName.equals(name) == true) {
return index; return index;
} // if }
} // for
// Unable to Locate // Unable to locate.
return -1; return -1;
}
} // findColumn()
/** /**
* getColumnClass * Returns the class of a comlumn.
* @param value0 TODO *
* @returns Class * @param columnIndex The index of the column.
*
* @return The class type of the column.
*/ */
public Class getColumnClass(int columnIndex) { public Class getColumnClass (int columnIndex)
{
return Object.class; return Object.class;
} // getColumnClass() }
/** /**
* isCellEditable * Tells whether a cell is editable.
* @param value0 TODO *
* @param value1 TODO * @param rowIndex The row of the cell.
* @returns boolean * @param columnIndex The index of the cell.
*
* @return True if cell is editable.
*/ */
public boolean isCellEditable(int rowIndex, int columnIndex) { public boolean isCellEditable (int rowIndex, int columnIndex)
{
return false; return false;
} // isCellEditable() }
/** /**
* setValueAt * Sets a cell to a value.
* @param value0 TODO *
* @param value1 TODO * @param value New value of cell.
* @param value2 TODO * @param rowIndex The row of the cell.
* @param columnIndex The column of the cell.
*/ */
public void setValueAt(Object value, int rowIndex, int columnIndex) { public void setValueAt (Object value, int rowIndex, int columnIndex)
{
// Do nothing... // Do nothing...
} // setValueAt() }
/** /**
* addTableModelListener * Add a TableModelListener.
* @param value0 TODO *
* @param listener The listener to add.
*/ */
public void addTableModelListener(TableModelListener listener) { public void addTableModelListener (TableModelListener listener)
listenerList.add(TableModelListener.class, listener); {
} // addTableModelListener() listenerList.add (TableModelListener.class, listener);
}
/** /**
* removeTableModelListener * Removes a TableModelListener.
* @param value0 TODO *
* @param listener The listener to remove.
*/ */
public void removeTableModelListener(TableModelListener listener) { public void removeTableModelListener (TableModelListener listener)
listenerList.remove(TableModelListener.class, listener); {
} // removeTableModelListener() 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 * fireTableDataChanged
*/ */
public void fireTableDataChanged() { public void fireTableDataChanged()
fireTableChanged(new TableModelEvent(this)); {
} // fireTableDataChanged() fireTableChanged (new TableModelEvent (this));
}
/** /**
* fireTableStructureChanged * fireTableStructureChanged
*/ */
public void fireTableStructureChanged() { public void fireTableStructureChanged()
fireTableChanged(new TableModelEvent(this, {
TableModelEvent.HEADER_ROW)); fireTableChanged (new TableModelEvent (this, TableModelEvent.HEADER_ROW));
} // fireTableStructureChanged() }
/** /**
* fireTableRowsInserted * fireTableRowsInserted
* @param value0 TODO * @param value0 TODO
* @param value1 TODO * @param value1 TODO
*/ */
public void fireTableRowsInserted(int firstRow, int lastRow) { public void fireTableRowsInserted (int firstRow, int lastRow)
fireTableChanged(new TableModelEvent(this, firstRow, lastRow, {
TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); fireTableChanged (new TableModelEvent (this, firstRow, lastRow,
} // fireTableRowsInserted() TableModelEvent.ALL_COLUMNS,
TableModelEvent.INSERT));
}
/** /**
* fireTableRowsUpdated * fireTableRowsUpdated
* @param value0 TODO * @param value0 TODO
* @param value1 TODO * @param value1 TODO
*/ */
public void fireTableRowsUpdated(int firstRow, int lastRow) { public void fireTableRowsUpdated (int firstRow, int lastRow)
fireTableChanged(new TableModelEvent(this, firstRow, lastRow, {
TableModelEvent.ALL_COLUMNS, TableModelEvent.UPDATE)); fireTableChanged (new TableModelEvent (this, firstRow, lastRow,
} // fireTableRowsUpdated() TableModelEvent.ALL_COLUMNS,
TableModelEvent.UPDATE));
}
/** /**
* fireTableRowsDeleted * fireTableRowsDeleted
* @param value0 TODO * @param value0 TODO
* @param value1 TODO * @param value1 TODO
*/ */
public void fireTableRowsDeleted(int firstRow, int lastRow) { public void fireTableRowsDeleted(int firstRow, int lastRow)
fireTableChanged(new TableModelEvent(this, firstRow, lastRow, {
TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE)); fireTableChanged (new TableModelEvent (this, firstRow, lastRow,
} // fireTableRowsDeleted() TableModelEvent.ALL_COLUMNS,
TableModelEvent.DELETE));
}
/** /**
* fireTableCellUpdated * fireTableCellUpdated
* @param value0 TODO * @param value0 TODO
* @param value1 TODO * @param value1 TODO
*/ */
public void fireTableCellUpdated(int row, int column) { public void fireTableCellUpdated (int row, int column)
fireTableChanged(new TableModelEvent(this, row, row, column)); {
} // fireTableCellUpdated() fireTableChanged (new TableModelEvent (this, row, row, column));
}
/** /**
* fireTableChanged * fireTableChanged
* @param value0 TODO * @param value0 TODO
*/ */
public void fireTableChanged(TableModelEvent event) { public void fireTableChanged (TableModelEvent event)
{
// Variables
Object[] list;
int index; int index;
TableModelListener listener; TableModelListener listener;
Object[] list = listenerList.getListenerList();
// Get Listener List for (index = 0; index < list.length; index += 2)
list = listenerList.getListenerList(); {
listener = (TableModelListener) list [index + 1];
for (index = 0; index < list.length; index += 2) { listener.tableChanged (event);
}
// Get Listener }
listener = (TableModelListener) list[index + 1];
// Notify Listener
listener.tableChanged(event);
} // for: index
} // fireTableChanged()
/** /**
* getListeners * getListeners
* @param value0 TODO * @param value0 TODO
* @returns EventListener[] * @return EventListener[]
*/ */
public EventListener[] getListeners(Class listenerType) { public EventListener[] getListeners (Class listenerType)
return listenerList.getListeners(listenerType); {
} // getListeners() return listenerList.getListeners (listenerType);
}
/** /**
* getValueAt * getValueAt
* @param value0 TODO * @param value0 TODO
* @param value1 TODO * @param value1 TODO
* @returns Object * @return Object
*/ */
public abstract Object getValueAt(int row, int column); public abstract Object getValueAt (int row, int column);
/** /**
* getColumnCount * getColumnCount
* @returns int * @return int
*/ */
public abstract int getColumnCount(); public abstract int getColumnCount();
/** /**
* getRowCount * getRowCount
* @returns int * @return int
*/ */
public abstract int getRowCount(); public abstract int getRowCount();
} // AbstractTableModel } // AbstractTableModel
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment