📄 startwindow.java
字号:
package com.cn.darkblue.window;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import net.jxta.document.MimeMediaType;
import net.jxta.id.IDFactory;
import net.jxta.peergroup.PeerGroup;
import net.jxta.platform.NetworkManager;
import net.jxta.protocol.PeerAdvertisement;
import net.jxta.rendezvous.RendezVousService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
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.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.cn.darkblue.helper.GroupHelper;
import com.cn.darkblue.helper.IPGResource;
import com.cn.darkblue.helper.PGResource;
import com.cn.darkblue.listener.CFRDVListener;
import com.cn.darkblue.util.CFResource;
import com.cn.darkblue.util.CFUtil;
import com.cn.darkblue.util.SysUtil;
import com.swtdesigner.SWTResourceManager;
public class StartWindow extends Dialog {
private Button cbClr;
private Button cbProx;
private Button cbSuper;
private Button cbAuto;
private Button cbRelay;
private Button cbEDV;
private Button cbEDEG;
private Text text;
private static final Log log = LogFactory.getLog(StartWindow.class);
private Text userPsw;
private Text userName;
/**
* Create the dialog
* @param parentShell
*/
public StartWindow(Shell parentShell) {
super(parentShell);
}
/**
* Create contents of the dialog
* @param parent
*/
protected Control createDialogArea(Composite parent) {
Composite container = (Composite) super.createDialogArea(parent);
final GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
container.setLayout(gridLayout);
final Label label = new Label(container, SWT.NONE);
label.setFont(SWTResourceManager.getFont("", 16, SWT.NONE));
label.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 2, 1));
label.setText(" 欢迎使用CoolFace P2P家园 ");
final Label label_4 = new Label(container, SWT.NONE);
label_4.setText(" 家园名 ");
text = new Text(container, SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
final Label label_1 = new Label(container, SWT.NONE);
label_1.setText(" 用户名 ");
userName = new Text(container, SWT.BORDER);
final GridData gd_userName = new GridData(SWT.FILL, SWT.CENTER, true, false);
userName.setLayoutData(gd_userName);
final Label label_2 = new Label(container, SWT.NONE);
label_2.setText(" 密码 ");
userPsw = new Text(container, SWT.BORDER);
final GridData gd_userPsw = new GridData(SWT.FILL, SWT.CENTER, true, false);
userPsw.setLayoutData(gd_userPsw);
final Group group = new Group(container, SWT.NONE);
group.setLayout(new FillLayout());
group.setText(" 启动模式 ");
group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
final Composite composite = new Composite(group, SWT.NONE);
final GridLayout gridLayout_1 = new GridLayout();
gridLayout_1.numColumns = 5;
composite.setLayout(gridLayout_1);
cbEDEG = new Button(composite, SWT.CHECK);
cbEDEG.setText(" 使用默认集合点 ");
cbEDV = new Button(composite, SWT.CHECK);
cbEDV.setText(" 集合点 ");
cbRelay = new Button(composite, SWT.CHECK);
cbRelay.setText(" 中继点 ");
final Label label_3 = new Label(composite, SWT.NONE);
label_3.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
cbAuto = new Button(composite, SWT.CHECK);
cbAuto.setText(" 自动选择 ");
cbSuper = new Button(composite, SWT.CHECK);
cbSuper.setText(" 超级点 ");
cbProx = new Button(composite, SWT.CHECK);
final GridData gd_cbProx = new GridData();
cbProx.setLayoutData(gd_cbProx);
cbProx.setText(" 代理点 ");
final Label label_5 = new Label(composite, SWT.NONE);
label_5.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
cbClr = new Button(composite, SWT.CHECK | SWT.RIGHT);
final GridData gd_cbClr = new GridData(SWT.RIGHT, SWT.CENTER, false, false);
cbClr.setLayoutData(gd_cbClr);
cbClr.setText(" 清空平台 ");
//
getLocalInfo();
return container;
}
/**
* Create contents of the button bar
* @param parent
*/
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, IDialogConstants.OK_ID, " 确定 ",
true);
createButton(parent, IDialogConstants.CANCEL_ID,
" 退出 ", false);
}
private void checkSet(){
RendezVousService rdv;
rdv = CFResource.getInstance().getWorldGroup().getRendezVousService();
rdv.addListener(new CFRDVListener());
if(cbEDV.getSelection()){
rdv.startRendezVous();
}
}
private void useDefaultSeeds(){
if(cbEDEG.getSelection()){
CFResource.getInstance().getManager().setUseDefaultSeeds(true);
}
//System.out.println(cbEDEG.getSelection());
}
private void getLocalInfo(){
InetAddress addr = null;
try{
addr = InetAddress.getLocalHost();
}catch(Exception e){
log.error(e.getMessage());
}
String ip = "127.0.0.1";
String name = "unkown";
if(addr!=null){
ip = addr.getHostAddress().toString();//获得本机IP
name = addr.getHostName().toString();//获得本机名称
}
CFResource.getInstance().setLMName(name);
CFResource.getInstance().setLMIPAddress(ip);
text.setText(name);
}
/**
* Return the initial size of the dialog
*/
protected Point getInitialSize() {
return new Point(390, 248);
}
protected void buttonPressed(int buttonId) {
if (buttonId == IDialogConstants.OK_ID) {
String fcName = text.getText();
if(fcName==null||"".equals(fcName)){
MessageDialog.openInformation(SysUtil.getSysShell()," 温馨提示 "," 请输入您的家园名 ");
text.setFocus();
return;
}
//清空平台缓存
CFUtil.clearPlatform(cbClr.getSelection(),fcName);
String user = userName.getText();
String psw = userPsw.getText();
NetworkManager manager = CFUtil.startJxta(fcName, user, psw);
if(manager==null){
MessageDialog.openInformation(SysUtil.getSysShell()," 温馨提示 ��ܰ��ʾ "," 无法初始化平台,程序即将退出,详情请查看日志文件 ");
SysUtil.colseApplication();
}else{
CFResource.getInstance().setManager(manager);
//manager.
try{
useDefaultSeeds();
//manager.setUseDefaultSeeds(true);
//manager
manager.startNetwork();
//manager.getConfigurator().
}catch(Exception ec){
MessageDialog.openInformation(SysUtil.getSysShell(), " 温馨提示 ��ܰ��ʾ ", " ��������无法启动网络: "+ec.getMessage());
log.error(ec.getMessage());
}
PeerGroup wpg = manager.getNetPeerGroup();
CFResource.getInstance().setWorldGroup(wpg);
//PeerAdvertisement adv = (PeerAdvertisement) CFUtil.loadAdvertisement(SysUtil.getRoot()+"/WAYKE.xml");
//CFUtil.conSpacRDV(wpg, adv);
System.out.println("local Peer is:\n"+wpg.getPeerAdvertisement().getDocument(MimeMediaType.XMLUTF8).toString());
try{
System.out.println("local Peer is:\n"+wpg.getAllPurposePeerGroupImplAdvertisement().getDocument(MimeMediaType.XMLUTF8).toString());
}catch(Exception e){
e.printStackTrace();
}
//不允许用户直接操作世界组
CFResource.getInstance().getGroupCache().add(wpg);
IPGResource pgres = new PGResource();
CFResource.getInstance().getJoinPGMap().put(wpg, pgres);
//////////////////////////////////
//平台初始设定
checkSet();
}
}
super.buttonPressed(buttonId);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -