⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 downloadjoblist.java

📁 peeranha42是jxta的 p2p程序核心
💻 JAVA
字号:
package de.uni_bremen.informatik.p2p.plugins.filesharing.data;

import java.util.ArrayList;

import javax.swing.JProgressBar;
import javax.swing.table.AbstractTableModel;

import de.uni_bremen.informatik.p2p.plugins.filesharing.control.FormatUtilities;


/**
 * The DownloadJobList class represents a datastructur of all downloadjobs. The
 * class extends the functions of a AbstractTableModel to be the data class
 * behind a simple JTable.
 *
 * @author Lars Kordes, Philipp Hoheisel
 */
public class DownloadJobList
    extends AbstractTableModel {
    /** List of all downloadjobs. */
    private ArrayList list;

    /**
     * Classconstructor.
     */
    public DownloadJobList() {
        // create new ArrayList 
        list = new ArrayList();
    }

    /**
     * Classconstructor.
     *
     * @param list ArrayList with all downloadjobs of the filesharing plugin.
     */
    public DownloadJobList(ArrayList list) {
        if (list == null) {
            list = new ArrayList();
        }

        this.list = list;
    }

    //----------------- ABSTRACT TABLE MODEL CLASS -------------------// 

    /**
     * Returns the number of columns. There are 6 columns.
     *
     * @see javax.swing.table.TableModel#getColumnCount()
     */
    public int getColumnCount() {
        return 6;
    }

    /**
     * Returns the number of rows. The number equals the length of the
     * downloadjoblist.
     *
     * @see javax.swing.table.TableModel#getRowCount()
     */
    public int getRowCount() {
        return list.size();
    }

    /**
     * Returns the value at a specific tablecell.
     *
     * @see javax.swing.table.TableModel#getValueAt(int, int)
     */
    public Object getValueAt(int arg0,
                             int arg1) {
        if (list == null) {
            return null;
        }

        DownloadJob de = (DownloadJob) list.get(arg0);

        if (de == null) {
            return null;
        }

        switch (arg1) {
        case 0 :
            return de.filename;

        case 1 :
        	return de.getProgressBar();
        	
        case 2 :
        	return (de.progress < 1024 ? 1 : de.progress/1024) + "/" + (de.size < 1024 ? 1 : de.size/1024) + " (" + de.getProgressInPrecent() + "%)";

        case 3 :
        	if(de.getStatus() == DownloadJob.DOWNLOAD) return FormatUtilities.giveFormatedString(de.getDownloadRate());
        	else return "";
            
        case 4 :
        	return new Integer(de.sources.size());
        	
        case 5 :

            switch (de.getStatus()) {
            case DownloadJob.NO_CONNECTION :
                return new String("No connection");

            case DownloadJob.STOPPED :
                return new String("Stopped");

            case DownloadJob.CANCELT :
                return new String("Canceled");

            case DownloadJob.DOWNLOAD :
                return new String("Downloading...");

            case DownloadJob.FINISHED :
                return new String("Finished");
            
            case DownloadJob.QUEUED :
                return new String("Queued");
            
            }
        }

        return null;
    }

    /**
     * Method returns the names of the specific columns.
     *
     * @param arg0 Index of the column.
     *
     * @return Name of the specific column.
     */
    public String getColumnName(int arg0) {
        switch (arg0) {
        case 0 :
            return "Filename";

        case 1 :
            return "Progress (%)";

        case 2 :
         	return "Progress (kbytes)";
            
        case 3 :
            return "Downloadrate (kbytes/s)";
        
        case 4 :
        	return "Source(s)";
            
        case 5 :
            return "Status";
        }

        return null;
    }
    
    /**
     * Returns class of specified column.
     * 
     * @return Class of specified column.
     */
    public Class getColumnClass(int c) {
    	if(c == 1) return JProgressBar.class;
    	else return String.class;
    	//return getValueAt(0, c).getClass();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -