📄 netreceiverframe.java
字号:
/**
*
*/
package view.receiver;
import java.io.IOException;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import main.NetSender;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CBanner;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Text;
import thread.receiver.ConnectSession;
import thread.receiver.ReceiverThread;
import ThemeFrame.SAPWindowFrame;
public class NetReceiverFrame extends Composite {
private SashForm sashForm = null;
private Composite composite = null;
private Composite composite1 = null;
private NFR_BackPanel nftBackPanel;
private Text textArea = null;
private Composite composite2 = null;
private CBanner cBanner = null;
private Composite composite3 = null;
private CLabel cLabel = null;
private Composite composite5 = null;
private Button button1 = null;
private Button button2 = null;
private Socket socket = null;
private List packageList = null; // @jve:decl-index=0:
private ReceiverThread rThread; // @jve:decl-index=0:
private CLabel cLabel1 = null;
private SAPWindowFrame parent = null; // @jve:decl-index=0:
private EnvelopFrame ef;
private FillLayout fillLayout;
private DisposeListener disposeListenner; // @jve:decl-index=0:
public NetReceiverFrame(SAPWindowFrame parent, int style) {
super(parent.getShell(), style);
this.parent = parent;
initialize();
}
public NetReceiverFrame(SAPWindowFrame parent, int style, Socket socket ,List packageList) {
super(parent.getShell(), style);
this.parent = parent;
this.socket = socket;
this.packageList = packageList;
if (getParam(0).equals("T")) {
ef = new EnvelopFrame(this,SWT.NONE);
ef.setText(socket.getInetAddress().getHostAddress()+" ("+getParam(2)+")");
this.setSize(ef.getSize());
}
else{
initialize();
this.setSize(new org.eclipse.swt.graphics.Point(355,300));
}
}
public static List splitToken(String fs) {
StringTokenizer pt = new StringTokenizer(fs, "|");
List l = new ArrayList();
while (pt.hasMoreTokens()) {
l.add(pt.nextToken());
}
return l;
}
/*
* 从cmdList中根据Index的值判断是否与param相等。相等返回True,不相等返回False。
*/
public boolean equParam(int index, String param){
if (((String) packageList.get(index)).equals(param)) return true;
else return false;
}
/*
* 返回cmdList中Index项的值。
*/
public String getParam(int index){
return ((String) packageList.get(index));
}
public void initialize() {
fillLayout = new FillLayout();
fillLayout.marginHeight = 2;
fillLayout.spacing = 0;
fillLayout.marginWidth = 4;
this.setLayout(fillLayout);
createSashForm();
this.setSize(new org.eclipse.swt.graphics.Point(357,300));
this.parent.getShell().setSize(this.getSize().x, this.getSize().y+24);
disposeListenner = new DisposeListener(){
public void widgetDisposed(DisposeEvent e) {
try {
if (rThread!=null) {
rThread.writeUTF("Disconnect");
System.out.println("writeUTF(Disconnect)");
}
} catch (IOException e1) {
e1.printStackTrace();
}finally{
// thisDispose();
System.gc();
}
}
};
parent.getShell().addDisposeListener(disposeListenner);
// connectSession = new ConnectSession(13001);
// int cport = connectSession.getConnectPort();
int i = 2;
setHostInfo(getParam(i++)+" "+socket.getInetAddress().getHostAddress());
setMessage(getParam(i++));
while (i<packageList.size()){
if (equParam(i,"AddFile")){
i++;
int hashFile = Integer.valueOf(getParam(i++)).intValue();
String fileName = getParam(i++);
long fileSize = Long.valueOf(getParam(i++)).longValue();
NFR_FileHandleItem fhi = addNFR_FileHandleItem(hashFile, fileName, fileSize, "FILE");
fhi.setConnectPort(main.NetReceiver.TCPport);
ConnectSession.hashNTR.put(new Integer(fhi.hashCode()),fhi);
}else if(equParam(i,"AddFolder")){
i++;
int hashFile = Integer.valueOf(getParam(i++)).intValue();
String fileName = getParam(i++);
long fileSize = Long.valueOf(getParam(i++)).longValue();
NFR_FileHandleItem fhi = addNFR_FileHandleItem(hashFile, fileName, fileSize, "FOLDER");
fhi.setConnectPort(main.NetReceiver.TCPport);
ConnectSession.hashNTR.put(new Integer(fhi.hashCode()),fhi);
}
}
try {
this.rThread = new ReceiverThread(socket);
if (getParam(1).equals("T")) this.rThread.writeUTF("ConfirmEnd");
} catch (IOException e) {
e.printStackTrace();
}
this.packageList = null;
}
public NFR_FileHandleItem addNFR_FileHandleItem(int hashFile, String fileName, long fileSize, String type){
//FileHashCode, FileName, FileSize, Type of FILE or FOLDER
return(this.nftBackPanel.addNFR_FileHandleItem(hashFile, fileName, fileSize, type, socket));
}
public void setMessage(String message){
this.textArea.setText(message);
}
public void setHostInfo(String hostMessage){
this.cLabel.setText(this.cLabel.getText()+hostMessage);
this.cLabel.setToolTipText(hostMessage);
}
/**
* This method initializes sashForm
*
*/
private void createSashForm() {
sashForm = new SashForm(this, SWT.VERTICAL);
sashForm.setBackground(SAPWindowFrame.BACKGROUNDCOLOR);
createComposite();
createComposite1();
}
/**
* This method initializes composite
*
*/
private void createComposite() {
GridLayout gridLayout = new GridLayout();
gridLayout.horizontalSpacing = 0;
gridLayout.marginWidth = 0;
gridLayout.marginHeight = 0;
gridLayout.verticalSpacing = 0;
GridData gridData = new org.eclipse.swt.layout.GridData();
gridData.grabExcessHorizontalSpace = true;
gridData.verticalAlignment = org.eclipse.swt.layout.GridData.FILL;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalIndent = 0;
gridData.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
composite = new Composite(sashForm, SWT.BORDER);
composite.setLayout(gridLayout);
composite.setBackground(SAPWindowFrame.BACKGROUNDCOLOR);
textArea = new Text(composite, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
textArea.setFont(new Font(Display.getDefault(), "\u5b8b\u4f53", 11, SWT.NORMAL));
textArea.setEditable(false);
textArea.setLayoutData(gridData);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -