📄 sendfileaction.java
字号:
package net.sf.p2pim.action;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.io.File;import net.jxta.myjxta.plugins.filetransfer.FileSender;import net.jxta.myjxta.plugins.filetransfer.FileTransferPlugin;import net.jxta.myjxta.util.GroupNode;import net.jxta.myjxta.util.PeerNode;import net.jxta.peergroup.PeerGroup;import net.jxta.pipe.PipeID;import net.jxta.protocol.PipeAdvertisement;import net.sf.p2pim.BuddyListView;import org.eclipse.jface.action.IAction;import org.eclipse.jface.viewers.ISelection;import org.eclipse.swt.SWT;import org.eclipse.swt.widgets.FileDialog;import org.eclipse.ui.IWorkbenchWindow;import org.eclipse.ui.IWorkbenchWindowActionDelegate;public class SendFileAction implements IWorkbenchWindowActionDelegate, PropertyChangeListener { private static final String G_TRANSFER_ID = "TRANS"; private IWorkbenchWindow window; public void run() { } public void dispose() { } public void init(IWorkbenchWindow window) { this.window = window; } public void run(IAction action) { try { final FileDialog fd=new FileDialog(window.getShell(),SWT.OPEN); fd.setText("请选择要传送的文件"); String openFile = fd.open(); File file = openFile != null ?new File(openFile):null; if (file == null || !file.exists() || !file.canRead()) return; //取目标peer PeerNode currentPeer = (PeerNode) BuddyListView.getInstance().getCurrentPeer(); if(currentPeer == null) return; PipeID p_targetCommandPipeID = (PipeID) currentPeer.getPeer().getPipeAdvertisement().getID(); PeerGroup pg = ((GroupNode) currentPeer.getParent()).getGroup().getPeerGroup(); PipeAdvertisement socketAdv = FileTransferPlugin.getAdvertisment(pg, p_targetCommandPipeID + G_TRANSFER_ID); FileSender tmp = null; tmp = new FileSender(pg, (PipeID) socketAdv.getPipeID(), file); tmp.addPropertyChangeListener(this); tmp.start(); } catch (Exception e1) { e1.printStackTrace(); } } public void selectionChanged(IAction action, ISelection selection) { } public void propertyChange(PropertyChangeEvent evt) { System.out.println(evt.getPropertyName() + ":" + evt.getNewValue()); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -