📄 taskmodel.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package mymp3.downloader;/** * * @author huliqing */public class TaskModel { public static final int COLUMN_STATE = 0; public static final int COLUMN_NAME = 1; public static final int COLUMN_SIZE = 2; public static final int COLUMN_PROCESS = 3; public static final int COLUMN_LOADED = 4; public static final int COLUMN_SPEED = 5; public static final int COLUMN_LEAVE_TIME = 6; public static final String[] COLUMN_HEAD = { "", "文件名", "大小", "进度", "已下载", "速度", "剩余时间" }; public static final int TOTAL_COLUMNS = 7; private String state; private String name; // 文件名称 private int size; // 大小 //private int process; // 进度 //private long loaded; // 已经下载数 //private long speed; // 速度 //private long leaveTime; // 剩余时间 private String url; // 文件地址 public TaskModel(String name, String url) { this.name = name; this.url = url; this.downloader = new Downloader(this); // 添加下载任务 } public Object getColumnValue(int column) { switch (column) { case COLUMN_STATE: // 反回状态 if (downloader.isStopped()) { state = "Stop"; } else if (downloader.isPaused()) { state = "Pause"; } else { state = "Run"; } return state; case COLUMN_NAME: // 返回文件名 return name; case COLUMN_SIZE: // 返回文件大小 size = downloader.getTotalBytes(); if (size >= (1024 * 1024)) { return (size / 1024 / 1024) + " M"; } else if (size >= 1024) { return (size / 1024) + " K"; } else if (size <= 0) { return ""; } else { return size + " B"; } case COLUMN_PROCESS: // 返回下载进度 if (size <= 0) return 0; return (downloader.getReadBytes() * 100 / size); case COLUMN_LOADED: // 返回已下载数 long loaded = downloader.getReadBytes(); if (loaded >= (1024 * 1024)) { return (loaded / 1024 / 1024) + " M"; } else if (loaded >= 1024) { return (loaded / 1024) + " K"; } return loaded; case COLUMN_SPEED: // 返回下载速度 long speed = downloader.getSpeed(); return speed >= 0 ? (speed + " k/s") : "0 k/s"; case COLUMN_LEAVE_TIME: // 返回剩余时间 return downloader.getLeaveTime(); default: return null; } } public String getName() { return name; } public String getUrl() { return url; } /** 判断任务是否已经完成 */ public boolean isOk() { return downloader.isOk(); } // -------------------------------------------------- 下载任务 private Downloader downloader; /** 开始任务 */ public void toStart() { downloader.toStart(); } /** 暂停任务 */ public void toPause() { downloader.toPause(); } /** 停止任务 */ public void toStop() { downloader.stopDownload(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -