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,273 +46,291 @@ import javax.swing.event.TableModelListener; ...@@ -46,273 +46,291 @@ 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
//------------------------------------------------------------- */
protected EventListenerList listenerList = new EventListenerList();
/**
* listenerList /**
*/ * Constructor AbstractTableModel
protected EventListenerList listenerList = new EventListenerList(); */
public AbstractTableModel()
{
//------------------------------------------------------------- // TODO
// Initialization --------------------------------------------- }
//-------------------------------------------------------------
/**
/** * Get the name of the column for this index. If you do not override
* Constructor AbstractTableModel * this methode, you'll get something like: 0, A; 1, B; ...; AA; AB;
*/ * ...
public AbstractTableModel() { *
// TODO * @param columnIndex The index of the column.
} // AbstractTableModel() *
* @return The name of the column.
*/
//------------------------------------------------------------- public String getColumnName (int columnIndex)
// Methods ---------------------------------------------------- {
//------------------------------------------------------------- // 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
* getColumnName // simple algorithm. I started with a base 10 to
* @param value0 TODO // base 26 converter and later found that there
* @returns String // were so many are exceptions that it has morphed
*/ // into a pile of goop.
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.
// NOTE2: I have a working algorithm which is much // NOTE2: I have a working algorithm which is much
// 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 (base <= left) { if (index > 1)
multiplier = left / base; {
if (foundFirst == false && index > 0) { base = base + (int) (Math.pow (26, index - 1));
buffer.append((char) (multiplier + 64)); }
} else {
buffer.append((char) (multiplier + 65)); if (base <= left)
} {
left = left - (base * multiplier); int multiplier = left / base;
foundFirst = true;
} else if (foundFirst == true || index == 0) { if (foundFirst == false
buffer.append('A'); && index > 0)
} {
} // for buffer.append ((char) (multiplier + 64));
}
// Return Column Name else
return buffer.toString(); {
buffer.append ((char) (multiplier + 65));
} // getColumnName() }
/** left = left - (base * multiplier);
* findColumn foundFirst = true;
* @param value0 TODO }
* @returns int else if (foundFirst == true
*/ || index == 0)
public int findColumn(String columnName) { {
buffer.append('A');
// Variables }
int index; }
String name;
int count; // Return column name.
return buffer.toString();
// Process Columns }
count = getColumnCount();
for (index = 0; index < count; index++) { /**
name = getColumnName(index); * Return the index of the given name.
if (columnName.equals(name) == true) { *
return index; * @param columnName The name of the column.
} // if *
} // for * @return The index of the column, -1 if not found.
*/
// Unable to Locate public int findColumn (String columnName)
return -1; {
int count = getColumnCount();
} // findColumn()
for (int index = 0; index < count; index++)
/** {
* getColumnClass String name = getColumnName (index);
* @param value0 TODO
* @returns Class if (name.equals (columnName))
*/ return index;
public Class getColumnClass(int columnIndex) { }
return Object.class;
} // getColumnClass() // Unable to locate.
return -1;
/** }
* isCellEditable
* @param value0 TODO /**
* @param value1 TODO * Returns the class of a comlumn.
* @returns boolean *
*/ * @param columnIndex The index of the column.
public boolean isCellEditable(int rowIndex, int columnIndex) { *
return false; * @return The class type of the column.
} // isCellEditable() */
public Class getColumnClass (int columnIndex)
/** {
* setValueAt return Object.class;
* @param value0 TODO }
* @param value1 TODO
* @param value2 TODO /**
*/ * Tells whether a cell is editable.
public void setValueAt(Object value, int rowIndex, int columnIndex) { *
// Do nothing... * @param rowIndex The row of the cell.
} // setValueAt() * @param columnIndex The index of the cell.
*
/** * @return True if cell is editable.
* addTableModelListener */
* @param value0 TODO public boolean isCellEditable (int rowIndex, int columnIndex)
*/ {
public void addTableModelListener(TableModelListener listener) { return false;
listenerList.add(TableModelListener.class, listener); }
} // addTableModelListener()
/**
/** * Sets a cell to a value.
* removeTableModelListener *
* @param value0 TODO * @param value New value of cell.
*/ * @param rowIndex The row of the cell.
public void removeTableModelListener(TableModelListener listener) { * @param columnIndex The column of the cell.
listenerList.remove(TableModelListener.class, listener); */
} // removeTableModelListener() public void setValueAt (Object value, int rowIndex, int columnIndex)
{
/** // Do nothing...
* fireTableDataChanged }
*/
public void fireTableDataChanged() { /**
fireTableChanged(new TableModelEvent(this)); * Add a TableModelListener.
} // fireTableDataChanged() *
* @param listener The listener to add.
/** */
* fireTableStructureChanged public void addTableModelListener (TableModelListener listener)
*/ {
public void fireTableStructureChanged() { listenerList.add (TableModelListener.class, listener);
fireTableChanged(new TableModelEvent(this, }
TableModelEvent.HEADER_ROW));
} // fireTableStructureChanged() /**
* Removes a TableModelListener.
/** *
* fireTableRowsInserted * @param listener The listener to remove.
* @param value0 TODO */
* @param value1 TODO public void removeTableModelListener (TableModelListener listener)
*/ {
public void fireTableRowsInserted(int firstRow, int lastRow) { listenerList.remove (TableModelListener.class, listener);
fireTableChanged(new TableModelEvent(this, firstRow, lastRow, }
TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
} // fireTableRowsInserted() /**
* Return all registered TableModelListener objects.
/** *
* fireTableRowsUpdated * @return Array of TableModelListener objects.
* @param value0 TODO *
* @param value1 TODO * @since 1.4
*/ */
public void fireTableRowsUpdated(int firstRow, int lastRow) { public TableModelListener[] getTableModelListeners()
fireTableChanged(new TableModelEvent(this, firstRow, lastRow, {
TableModelEvent.ALL_COLUMNS, TableModelEvent.UPDATE)); return (TableModelListener[])
} // fireTableRowsUpdated() listenerList.getListeners (TableModelListener.class);
}
/**
* fireTableRowsDeleted /**
* @param value0 TODO * fireTableDataChanged
* @param value1 TODO */
*/ public void fireTableDataChanged()
public void fireTableRowsDeleted(int firstRow, int lastRow) { {
fireTableChanged(new TableModelEvent(this, firstRow, lastRow, fireTableChanged (new TableModelEvent (this));
TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE)); }
} // fireTableRowsDeleted()
/**
/** * fireTableStructureChanged
* fireTableCellUpdated */
* @param value0 TODO public void fireTableStructureChanged()
* @param value1 TODO {
*/ fireTableChanged (new TableModelEvent (this, TableModelEvent.HEADER_ROW));
public void fireTableCellUpdated(int row, int column) { }
fireTableChanged(new TableModelEvent(this, row, row, column));
} // fireTableCellUpdated() /**
* fireTableRowsInserted
/** * @param value0 TODO
* fireTableChanged * @param value1 TODO
* @param value0 TODO */
*/ public void fireTableRowsInserted (int firstRow, int lastRow)
public void fireTableChanged(TableModelEvent event) { {
fireTableChanged (new TableModelEvent (this, firstRow, lastRow,
// Variables TableModelEvent.ALL_COLUMNS,
Object[] list; TableModelEvent.INSERT));
int index; }
TableModelListener listener;
/**
* 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 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 * getListeners
listener.tableChanged(event); * @param value0 TODO
* @return EventListener[]
} // for: index */
public EventListener[] getListeners (Class listenerType)
} // fireTableChanged() {
return listenerList.getListeners (listenerType);
/** }
* getListeners
* @param value0 TODO /**
* @returns EventListener[] * getValueAt
*/ * @param value0 TODO
public EventListener[] getListeners(Class listenerType) { * @param value1 TODO
return listenerList.getListeners(listenerType); * @return Object
} // getListeners() */
public abstract Object getValueAt (int row, int column);
/**
* getValueAt /**
* @param value0 TODO * getColumnCount
* @param value1 TODO * @return int
* @returns Object */
*/ public abstract int getColumnCount();
public abstract Object getValueAt(int row, int column);
/**
/** * getRowCount
* getColumnCount * @return int
* @returns int */
*/ public abstract int getRowCount();
public abstract int getColumnCount();
/**
* getRowCount
* @returns int
*/
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