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

📄 torrentlistener.java

📁 这是一个基于java编写的torrent的P2P源码
💻 JAVA
字号:
package com.aelitis.azureus.ui.swt.browser.listener;

import java.net.URL;

import org.eclipse.swt.widgets.Shell;
import org.gudy.azureus2.core3.util.Debug;

import com.aelitis.azureus.core.AzureusCore;
import com.aelitis.azureus.core.AzureusCoreFactory;
import com.aelitis.azureus.ui.swt.browser.msg.AbstractMessageListener;
import com.aelitis.azureus.ui.swt.browser.msg.BrowserMessage;

public class TorrentListener extends AbstractMessageListener
{
    public static final String DEFAULT_LISTENER_ID = "torrent";

  	public static final String OP_LOAD_TORRENT_OLD = "loadTorrent";

  	public static final String OP_LOAD_TORRENT = "load-torrent";
	
    private AzureusCore core;
	private Shell shell;
	
	public TorrentListener(AzureusCore core) {
        this(DEFAULT_LISTENER_ID, core);
	}
	
    public TorrentListener(String id, AzureusCore core) {
        super(id);
        this.core = core;
    }
    
    /**
		 * 
		 */
		public TorrentListener() {
			this(AzureusCoreFactory.getSingleton());
		}

		public void setShell(Shell shell) {
		this.shell = shell;
	}


    public void handleMessage(BrowserMessage message) {
		if ( OP_LOAD_TORRENT.equals(message.getOperationId())
				|| OP_LOAD_TORRENT_OLD.equals(message.getOperationId()) ) {
            loadTorrent(message.getDecodedObject().getString("url"));
        }
        else {
            throw new IllegalArgumentException("Unknown operation: " + message.getOperationId());
        }
	}
	
	private void loadTorrent(String url) {
		try {
			core.getPluginManager().getDefaultPluginInterface().getDownloadManager().addDownload(new URL(url), true);
		} catch (Exception e) {
			Debug.out(e);
		}
	}
}

⌨️ 快捷键说明

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