?? contentdownload.java
字號(hào):
package connex.plugins.filesharing;
import net.jxta.share.client.GetContentRequest;
import net.jxta.share.ContentAdvertisement;
import java.io.File;
import net.jxta.peergroup.PeerGroup;
import java.lang.reflect.InvocationTargetException;
import javax.swing.ImageIcon;
import connex.plugins.filesharing.model.DownloadRow;
import connex.plugins.filesharing.ui.DownloadPanel;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author Hisham Khalil
* @version 1.0*/
public class ContentDownload
extends GetContentRequest {
private ContentAdvertisement searchResult = null;
private DownloadRow myRow;
private ImageIcon down = new ImageIcon(ContentDownload.class.getResource("downloading_small.png"));
private ImageIcon complete = new ImageIcon(ContentDownload.class.getResource("ok.png"));
private ImageIcon close = new ImageIcon(ContentDownload.class.getResource("delete_small.png"));
private ImageIcon cancel = new ImageIcon(ContentDownload.class.getResource("delete_small.png"));
private long curTime, newTime;
private long oSize;
/**
* @directed
* @link aggregationByValue
*/
private DownloadMonitor dm;
public ContentDownload(PeerGroup pg, ContentAdvertisement[] res) throws
InvocationTargetException {
this(pg, res, new File(res[0].getName()));
}
public ContentDownload(PeerGroup pg, ContentAdvertisement[] res,
File tmpFile) throws InvocationTargetException {
super(pg, res, tmpFile);
this.searchResult = res[0];
this.myRow = new DownloadRow(searchResult.getName(),
searchResult.getContentId().toString());
curTime = System.currentTimeMillis();
init();
dm = new DownloadMonitor(myRow, this.getFile(), getOriginalLength());
dm.start();
}
private void init() {
down.setDescription("Downloading");
complete.setDescription("Download Completed");
close.setDescription("Download failur");
cancel.setDescription("Canceled");
myRow.setState("0", down);
}
public ContentAdvertisement getContentAdvertisement() {
return searchResult;
}
public long getOriginalLength() {
return searchResult.getLength();
}
public void notifyDone() {
newTime = System.currentTimeMillis();
int m = (int) (newTime - curTime);
try {
dm.interrupt();
dm.join();
}
catch (InterruptedException ex) {
}
myRow.setState("Total time " + restTime(m), complete);
myRow.setFinished(true);
if (DownloadPanel.getInstance().isFinishedToClear()) {
myRow.remove();
myRow.clear();
myRow = null;
}
FilesharingService.getInstance().shareContent(new ShareFile(this.getFile().getAbsolutePath()));
//dm.stopit() ;
}
public void notifyFailure() {
dm.stopit();
dm.interrupt();
myRow.setFailed(true);
myRow.setState("0", close);
if (DownloadPanel.getInstance().isFailedToClear()) {
myRow.remove();
myRow.clear();
myRow = null;
}
}
public void cancel() {
if (myRow.isDownloaded() || myRow.isFailed()) {
return;
}
super.cancel();
dm.stopit();
dm.interrupt();
myRow.setCancel(true);
myRow.setState("0", cancel);
//myRow.remove();
if (DownloadPanel.getInstance().isCanceledToClear()) {
myRow.remove();
myRow.clear();
myRow = null;
}
}
public void notifyUpdate(int per) {
}
private String restTime(int t) {
t /= 1000;
String rest = t + " sec";
if ( (t >= 60) && (t < 3600)) {
rest = (t / 60) + " min ";
int sec = t % 60;
rest += sec + " sec";
}
if (t >= 3600) {
rest = (t / 3600) + " h ";
int min = t % 3600;
rest += (min / 60) + " min ";
int sec = min % 60;
rest += sec + " sec";
}
return rest;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -