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

📄 downloadlist.java

📁 JMule是一个基于Java开发
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			boolean contain_stopped = false;			for(DownloadSession session : getSelectedObjects()) {				if (session.isStarted())					contain_started = true;								if (!session.isStarted())					contain_stopped = true;								if ((contain_started)&&(contain_stopped))					break;			}						if ((contain_started)&&(!contain_stopped))				return DownloadListStatus.MULTIPLE_STARTED_DOWNLOADS_SELECTED;						if ((!contain_started)&&(contain_stopped))				return DownloadListStatus.MULTIPLE_STOPPED_DOWNLOADS_SELECTED;						return DownloadListStatus.MULTIPLE_MISC_DOWNLOADS_SELECTED;		}				return DownloadListStatus.NO_DOWNLOADS;	}	protected Menu getPopUpMenu() {		DownloadListStatus status =  getSelectionStatus();				switch (status) {				case NO_DOWNLOADS_SELECTED : return no_downloads_menu;				case STARTED_DOWNLOAD_SELECTED : {			set_download_status.setImage(SWTImageRepository.getImage("stop_download.png"));			set_download_status.setText(_._("mainwindow.transferstab.downloads.popupmenu.stop_download"));			return single_download_selected;		}				case STOPPED_DOWNLOAD_SELECTED : {			set_download_status.setImage(SWTImageRepository.getImage("start_download.png"));			set_download_status.setText(_._("mainwindow.transferstab.downloads.popupmenu.start_download"));			return single_download_selected;		}				case MULTIPLE_STARTED_DOWNLOADS_SELECTED : {			multiple_start_download.setEnabled(false);			multiple_stop_download.setEnabled(true);			return multiple_downloads_selected;		}				case MULTIPLE_STOPPED_DOWNLOADS_SELECTED : {			multiple_start_download.setEnabled(true);			multiple_stop_download.setEnabled(false);			return multiple_downloads_selected;		}				case MULTIPLE_MISC_DOWNLOADS_SELECTED : {			multiple_start_download.setEnabled(true);			multiple_stop_download.setEnabled(true);			return multiple_downloads_selected;		}				default : return no_downloads_menu;		}	}		protected int compareObjects(DownloadSession object1,			DownloadSession object2, int columnID, boolean order) {				if (columnID == SWTConstants.DOWNLOAD_LIST_FILE_NAME_COLUMN_ID) {			return Misc.compareAllObjects(object1, object2, "getSharingName", order);		}		if (columnID == SWTConstants.DOWNLOAD_LIST_SIZE_COLUMN_ID) {			return Misc.compareAllObjects(object1, object2, "getFileSize", order);		}				if (columnID == SWTConstants.DOWNLOAD_LIST_TRANSFERRED_COLUMN_ID) {			return Misc.compareAllObjects(object1, object2, "getTransferredBytes", order);		}				if (columnID == SWTConstants.DOWNLOAD_LIST_DOWNLOAD_SPEED_COLUMN_ID) {			return Misc.compareAllObjects(object1, object2, "getSpeed", order);		}				if (columnID == SWTConstants.DOWNLOAD_LIST_PROGRESS_COLUMN_ID) {			return Misc.compareAllObjects(object1, object2, "getPercentCompleted", order);		}				if (columnID == SWTConstants.DOWNLOAD_LIST_COMPLETED_COLUMN_ID) {			return Misc.compareAllObjects(object1, object2, "getPercentCompleted", order);		}				if (columnID == SWTConstants.DOWNLOAD_LIST_SOURCES_COLUMN_ID) {			return Misc.compareAllObjects(object1, object2, "getPeersCount", order);		}				if (columnID == SWTConstants.DOWNLOAD_LIST_COMPLETE_SOURCES_COLUMN_ID) {			return Misc.compareAllObjects(object1, object2, "getCompletedSources", order);		}				if (columnID == SWTConstants.DOWNLOAD_LIST_PARTIAL_SOURCES_COLUMN_ID) {			return Misc.compareAllObjects(object1, object2, "getPartialSources", order);		}				if (columnID == SWTConstants.DOWNLOAD_LIST_REMAINING_COLUMN_ID) {			return Misc.compareAllObjects(object1, object2, "getETA", order);		}				if (columnID == SWTConstants.DOWNLOAD_LIST_STATUS_COLUMN_ID) {			return Misc.compareAllObjects(object1, object2, "getStatus", order);		}				return 0;	}	public void updateRow(DownloadSession session) {		String file_name = session.getSharingName();		Image image = SWTImageRepository.getIconByExtension(file_name);		setRowImage(session, SWTConstants.DOWNLOAD_LIST_FILE_NAME_COLUMN_ID, image);		setRowText(session,  SWTConstants.DOWNLOAD_LIST_FILE_NAME_COLUMN_ID, file_name);		setRowText(session,  SWTConstants.DOWNLOAD_LIST_SIZE_COLUMN_ID, FileFormatter.formatFileSize(session.getFileSize()));		setRowText(session,  SWTConstants.DOWNLOAD_LIST_TRANSFERRED_COLUMN_ID, FileFormatter.formatFileSize(session.getTransferredBytes()));				DecimalFormat formatter = new DecimalFormat("0.00");		setRowText(session,  SWTConstants.DOWNLOAD_LIST_COMPLETED_COLUMN_ID, formatter.format(session.getPercentCompleted())+"%");				String speed = SpeedFormatter.formatSpeed(session.getSpeed());		setRowText(session,  SWTConstants.DOWNLOAD_LIST_DOWNLOAD_SPEED_COLUMN_ID,speed);				FileHash file_hash = session.getFileHash();		float upload_speed = 0;		if (upload_manager.hasUpload(file_hash)) 			upload_speed = upload_manager.getUpload(file_hash).getSpeed();				setRowText(session,  SWTConstants.DOWNLOAD_LIST_UPLOAD_SPEED_COLUMN_ID,SpeedFormatter.formatSpeed(upload_speed));				int peerCount = session.getPeersCount();		UploadSession upload_session = upload_manager.getUpload(session.getFileHash());		if (upload_session != null)			peerCount += upload_session.getPeersCount();		setRowText(session, SWTConstants.DOWNLOAD_LIST_SOURCES_COLUMN_ID,peerCount+"");		setRowText(session, SWTConstants.DOWNLOAD_LIST_COMPLETE_SOURCES_COLUMN_ID, session.getCompletedSources()+"");		int partialSources = session.getPartialSources();		if (upload_session != null)			partialSources += upload_session.getPeersCount();		setRowText(session, SWTConstants.DOWNLOAD_LIST_PARTIAL_SOURCES_COLUMN_ID, partialSources+"");						String time = TimeFormatter.formatColon(session.getETA());		setRowText(session, SWTConstants.DOWNLOAD_LIST_REMAINING_COLUMN_ID,time);		String status;		if (session.getStatus() == DownloadSession.STATUS_STARTED)			status = _._("mainwindow.transferstab.downloads.column.status.started");		else			status = _._("mainwindow.transferstab.downloads.column.status.stopped");		setRowText(session, SWTConstants.DOWNLOAD_LIST_STATUS_COLUMN_ID,status);	}		public void addDownlaodSession(DownloadSession session) {		addRow(session);		GapListPainter gap_list_painter = new GapListPainter(session.getGapList(),session.getFileSize());				TableItemGapList painter = new TableItemGapList(SWTPreferences.getDefaultColumnOrder(SWTConstants.DOWNLOAD_LIST_PROGRESS_COLUMN_ID),gap_list_painter);				addCustumControl(getItemCount()-1, painter);	}	public void refresh() {		if (isDisposed()) return ;		redraw();		for(DownloadSession session : download_manager.getDownloads()) {			if (!hasObject(session)) continue;			if (getRow(session).isVisible())				updateRow(session);		}	}		private void startSelectedDownloads() {		if (_core.getServerManager().getConnectedServer()==null) {			Utils.showWarningMessage(getShell(), _._("mainwindow.transferstab.downloads.not_connected.title"), _._("mainwindow.transferstab.downloads.not_connected"));			return ;		}		List<DownloadSession> list = getSelectedObjects();		for(DownloadSession downloadSession : list)			if (downloadSession.getStatus() == DownloadSession.STATUS_STOPPED)				download_manager.startDownload(downloadSession.getFileHash());	}		private void stopSelectedDownloads() {		List<DownloadSession> list = getSelectedObjects();		for(DownloadSession downloadSession : list)			if (downloadSession.getStatus() == DownloadSession.STATUS_STARTED)				download_manager.stopDownload(downloadSession.getFileHash());	}		public void cancelSelectedDownloads() {		boolean result;		List<DownloadSession> list = getSelectedObjects();		if (list.size()==1)			result = Utils.showConfirmMessage(getShell(),_._("mainwindow.transferstab.downloads.confirm_cancel.title"), _._("mainwindow.transferstab.downloads.confirm_cancel"));		else			result = Utils.showConfirmMessage(getShell(), _._("mainwindow.transferstab.downloads.confirm_cancel.title") , _._("mainwindow.transferstab.downloads.confirm_cancel_multi"));		if (result)			for(DownloadSession downloadSession : list)				download_manager.removeDownload(downloadSession.getFileHash());	}		private void pasteED2KLink() {		String clipboard_text = Utils.getClipboardText();		List<ED2KFileLink> links = ED2KFileLink.extractLinks(clipboard_text);				String failed ="";		for(ED2KFileLink link : links) {			if (!download_manager.hasDownload(link.getFileHash()))					download_manager.addDownload(link);			else				failed+=link.getFileName()+"\n";		}		if (failed.length()!=0)			Utils.showWarningMessage(getShell(), _._("mainwindow.transferstab.downloads.ed2k_paste_failed_already_exist.title"),_._("mainwindow.transferstab.downloads.ed2k_paste_failed_already_exist")+" : \n"+failed);			}	private void copyED2KLink() {		List<DownloadSession> selected_sessions = getSelectedObjects();		String ed2k_links = "";		for(DownloadSession session : selected_sessions)			ed2k_links+=session.getED2KLink() + System.getProperty("line.separator"); 		Utils.setClipBoardText(ed2k_links);	}		public void downloadAdded(final FileHash fileHash) {		SWTThread.getDisplay().asyncExec(new JMRunnable() {			public void JMRun() {				DownloadSession session = download_manager.getDownload(fileHash);				addDownlaodSession(session);				MainWindow.getLogger().fine(_._("mainwindow.logtab.message_download_added",session.getSharingName()));			}		});			}	public void downloadRemoved(final FileHash fileHash) {		SWTThread.getDisplay().asyncExec(new JMRunnable() {			public void JMRun() {				DownloadSession session = null;								for(BufferedTableRow s : line_list) {					DownloadSession x = (DownloadSession) s.getData(SWTConstants.ROW_OBJECT_KEY);					if (x.getFileHash().equals(fileHash)) { 						session = x;						break;					}				}				if (session == null) return ;				removeRow(session);				refresh();				if (session.getPercentCompleted()!=100)					MainWindow.getLogger().fine(_._("mainwindow.logtab.message_download_removed",session.getSharingName()));				else					MainWindow.getLogger().fine(_._("mainwindow.logtab.message_download_finished",session.getSharingName()));			}		});	}	public void downloadStarted(final FileHash fileHash) {		SWTThread.getDisplay().asyncExec(new JMRunnable() {			public void JMRun() {				DownloadSession downloadSession = download_manager.getDownload(fileHash);				updateRow(downloadSession);				MainWindow.getLogger().fine(_._("mainwindow.logtab.message_download_started",downloadSession.getSharingName()));		}});			}	public void downloadStopped(final FileHash fileHash) {		SWTThread.getDisplay().asyncExec(new JMRunnable() {			public void JMRun() {				DownloadSession downloadSession = download_manager.getDownload(fileHash);				updateRow(downloadSession);				MainWindow.getLogger().fine(_._("mainwindow.logtab.message_download_stopped",downloadSession.getSharingName()));		}});	}}

⌨️ 快捷键说明

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