Expand|Select|Wrap|Line Numbers
- // Notify observers that this download's status has changed.
- public void stateChanged() {
- setChanged();
- notifyObservers();
- }
Expand|Select|Wrap|Line Numbers
- import java.util.*;
- import javax.swing.*;
- import javax.swing.table.*;
- import downloadmanager.controller.DownloadManagerSystem;
- import downloadmanager.model.Download;
- // This class manages the download table's data.
- class DownloadsTableModel extends AbstractTableModel
- implements Observer {
- // These are the names for the table's columns.
- private static final String[] columnNames = {"URL", "Name",
- "Size", "Progress %","Status","Time Left","Transfer Rate","Date"};
- // These are the classes for each column's values.
- private static final Class[] columnClasses = {String.class,
- String.class, String.class,JProgressBar.class, String.class, String.class,String.class,Date.class};
- // Add a new download to the table.
- public void addDownloadToTable(Download download) {
- download.addObserver(this);
- // Fire table row insertion notification to table.
- fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1);
- }
- // Get a download for the specified row.
- public Download getDownload(int row) {
- return (Download) DownloadManagerSystem.getArrayList().get(row);
- }
- // Remove a download from the list.
- public void clearDownload(int row) {
- DownloadManagerSystem.getArrayList().remove(row);
- // Fire table row deletion notification to table.
- fireTableRowsDeleted(row, row);
- }
- // Get table's column count.
- public int getColumnCount() {
- return columnNames.length;
- }
- // Get a column's name.
- public String getColumnName(int col) {
- return columnNames[col];
- }
- // Get a column's class.
- public Class getColumnClass(int col) {
- return columnClasses[col];
- }
- // Get table's row count.
- public int getRowCount() {
- return DownloadManagerSystem.getArrayList().size();
- }
- // Get value for a specific row and column combination.
- public Object getValueAt(int row, int col) {
- Download download = (Download)DownloadManagerSystem.getArrayList().get(row);
- switch (col) {
- case 0: // URL
- return download.getUrl();
- case 1: // Name
- return download.getName();
- case 2: // Size
- int size = download.getSize();
- return (size == -1) ? "" : Integer.toString(size);
- case 3: // Progress
- return new Float(download.getProgress());
- case 4://Status
- return Download.STATUSES[download.getStatus()];
- case 5: //TimeLeft
- return download.getTimeLeft();
- case 6://TransferRate
- return download.getSpeed();
- case 7:// Date
- return download.getDate();
- }
- return "";
- }
- /* Update is called when a Download notifies its
- observers of any changes */
- public void update(Observable o, Object arg) {
- int index = DownloadManagerSystem.getArrayList().indexOf(o);
- // Fire table row update notification to table.
- fireTableRowsUpdated(index, index);
- }
- }
Before model I created the list and I made the adding to list process in view and It was working.But now I must do the project in the MVC structure, so I only created the list in the Model.Now, I cannot see any updated data about the downloads why is it so?I also uploaded my project zip.Please help.