📄 mainframe.java
字号:
package com.code10.face;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Group;
import com.code10.access.ReadProperty;
import com.code10.basecomponent.UrlEntry;
import com.code10.basecomponent.UserInfo;
import com.code10.fetch.MainFetch;
public class MainFrame {
private static MainFrame mainFrame = null;
private Shell sShell = null;
private CenterComposite centerComposite = null;
private AlertComposite alertComposite = null;
private LoginComposite loginComposite = null;
private Menu menuBar = null;
private Group grpUserinfo = null;
private Group grpMailInfo = null;
private Group grpMsg = null;
private UserInfo userInfo = null;
private static Display display ;
private boolean fetching = false;
private MainFetch mainFetch;
public static MainFrame getInstance(){
if(mainFrame == null){
mainFrame = new MainFrame();
return mainFrame;
}
else{
return mainFrame;
}
}
/**
* This method initializes sShell
*
*/
private void createSShell() {
sShell = new Shell(SWT.BORDER | SWT.SHELL_TRIM);
sShell.setText("Mail Sender V1.0");
sShell.setImage(new Image(Display.getCurrent(), "index_register.JPG"));
createComposite();
createGrpUserinfo();
createGrpMailInfo();
createGrpMsg();
sShell.setSize(new org.eclipse.swt.graphics.Point(616,539));
sShell.setLocation(200,100);
menuBar = new Menu(sShell, SWT.BAR);
createMenuBar();
sShell.setMenuBar(menuBar);
init();
}
private void init(){
ReadProperty readProperty = ReadProperty.newInstance();
String strUrl = readProperty.getPara("startUrl");
int intLayer = readProperty.getPara("startLayer").charAt(0) - '0';
mainFetch = new MainFetch(strUrl,intLayer);
}
/**
* This method initializes composite
*
*/
private void createComposite() {
loginComposite = new LoginComposite(sShell, SWT.NONE);
loginComposite.setBounds(new org.eclipse.swt.graphics.Rectangle(15,25,570,25));
centerComposite = new CenterComposite(sShell, SWT.NONE);
centerComposite.setDisplay(display);
centerComposite.setBounds(new org.eclipse.swt.graphics.Rectangle(15,75,570,250));
alertComposite = new AlertComposite(sShell, SWT.NONE);
alertComposite.setBounds(new org.eclipse.swt.graphics.Rectangle(15,350,570,120));
}
/**
* This method initializes grpUserinfo
*
*/
private void createGrpUserinfo() {
grpUserinfo = new Group(sShell, SWT.NONE);
// grpUserinfo.setText("用户信息");
grpUserinfo.setText("login information");
grpUserinfo.setBounds(new org.eclipse.swt.graphics.Rectangle(5,10,586,44));
}
/**
* This method initializes grpMailInfo
*
*/
private void createGrpMailInfo() {
grpMailInfo = new Group(sShell, SWT.NONE);
// grpMailInfo.setText("邮件信息");
grpMailInfo.setText("Mail Information");
grpMailInfo.setBounds(new org.eclipse.swt.graphics.Rectangle(5,60,586,270));
}
/**
* This method initializes grpMsg
*
*/
private void createGrpMsg() {
grpMsg = new Group(sShell, SWT.NONE);
// grpMsg.setText("输出信息");
grpMsg.setText("Output Information");
grpMsg.setBounds(new org.eclipse.swt.graphics.Rectangle(6,333,586,141));
}
/**
*
*
*/
private void createMenuBar(){
MenuItem fileitem = new MenuItem(menuBar, SWT.CASCADE);
// fileitem.setText("&文件");
fileitem.setText("&File");
Menu filemenu = new Menu(sShell, SWT.DROP_DOWN);
fileitem.setMenu(filemenu);
MenuItem senditem = new MenuItem(filemenu, SWT.PUSH);
// senditem.setText("&发送");
senditem.setText("&Send");
MenuItem exititem = new MenuItem(filemenu, SWT.PUSH);
// exititem.setText("&退出");
exititem.setText("&Exit");
exititem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
MessageBox messagebox = new MessageBox(sShell, SWT.YES | SWT.NO);
messagebox.setText("退出");
messagebox.setMessage("确定退出程序吗?");
int val=messagebox.open();
if(val == SWT.YES)
{
sShell.close();
}
}
});
MenuItem operteritem = new MenuItem(menuBar, SWT.CASCADE);
// operteritem.setText("&操作");
operteritem.setText("&Operation");
Menu fetchmenu = new Menu(sShell, SWT.DROP_DOWN);
operteritem.setMenu(fetchmenu);
final MenuItem fetchitem = new MenuItem(fetchmenu, SWT.PUSH);
// fetchitem.setText("&从网页抓取");
fetchitem.setText("&Fetch from Webpage");
fetchitem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
if(!fetching){
mainFetch.start();
appendMsg("正在从" + UrlEntry.getStrHost() + "抓取......\n");
fetching = true;
fetchitem.setText("&停止抓取");
}else{
mainFetch.stopFetch();
fetching = false;
fetchitem.setText("&从网页抓取");
}
}
});
MenuItem settingitem = new MenuItem(menuBar, SWT.CASCADE);
// settingitem.setText("&设置");
settingitem.setText("&Setting");
Menu setingmenu = new Menu(sShell, SWT.DROP_DOWN);
settingitem.setMenu(setingmenu);
MenuItem startURLitem = new MenuItem(setingmenu, SWT.PUSH);
// startURLitem.setText("抓取参数设置");
startURLitem.setText("Fetch params");
startURLitem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
FetchInfoDailog fetchInfo = new FetchInfoDailog();
fetchInfo.open(display);}
});
MenuItem serveritem = new MenuItem(setingmenu, SWT.PUSH);
// serveritem.setText("用户信息设置");
serveritem.setText("Login params");
serveritem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
UserInfoDailog userInfo = new UserInfoDailog();
userInfo.open(display);}
});
}
public void appendMsg(String str){
alertComposite.appendMsg(str);
}
public static void main(String [] args){
MainFrame test = MainFrame.getInstance();
display = new Display();
test.createSShell();
test.sShell.open();
while (!test.sShell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
System.out.println("finishing...");
display.dispose();
System.exit(0);
}
public UserInfo getUserInfo() {
return userInfo;
}
public void setUserInfo(UserInfo userInfo) {
this.userInfo = userInfo;
}
public boolean getConnect(){
return loginComposite.isConnected();
}
public static Display getDisplay() {
return display;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -