This method first registers itself with the new Download as an Observer interested in
receiving change notifications. Next, the Download is added to the internal list of downloads
being managed. Finally, a table row insertion event notification is fired to alert the table that
a new row has been added.
The clearDownload( ) Method
The clearDownload( ) method, shown next, removes a Download from the list of managed
downloads:
// Remove a download from the list.
public void clearDownload(int row) {
downloadList.remove(row);
// Fire table row deletion notification to table.
fireTableRowsDeleted(row, row);
}
After removing the Download from the internal list, a table row deleted event notification
is fired to alert the table that a row has been deleted.
The getColumnClass( ) Method
The getColumnClass( ) method, shown here, returns the class type for the data displayed
in the specified column:
// Get a column's class.
public Class getColumnClass(int col) {
return columnClasses[col];
}
All columns are displayed as text (that is, String objects) except for the Progress column,
which is displayed as a progress bar (which is an object of type JProgressBar).
The getValueAt( ) Method
The getValueAt( ) method, shown next, is called to get the current value that should be
displayed for each of the table's cells:
// Get value for a specific row and column combination.
public Object getValueAt(int row, int col) {
Download download = downloadList.get(row);
switch (col) {
case 0: // URL
return download.getUrl();
case 1: // Size
int size = download.getSize();
return (size == -1) ? "" : Integer.toString(size);
case 2: // Progress
return new Float(download.getProgress());
case 3: // Status
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home