📄 initialargumentdialog.java
字号:
/*
* LumaQQ - Java QQ Client
*
* Copyright (C) 2004 luma <stubma@163.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package edu.tsinghua.lumaqq.qq.debug;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
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.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import edu.tsinghua.lumaqq.qq.Util;
/**
* <pre>
* 调试参数对话框
* </pre>
*
* @author 马若劼
*/
class InitialArgumentDialog extends Dialog {
private InitialArgument arg;
// 界面控件
private Text textQQ, textPassword, textLoginReply;
private Font font;
/**
* @param parent
*/
public InitialArgumentDialog(Shell parent) {
super(parent);
}
/**
* 打开对话框
*
* @return 调试参数封装类
*/
public InitialArgument open() {
// 创建对话框
Shell parent = getParent();
Shell shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
shell.setSize(350, 250);
shell.setText("Input Debug Argument");
font = new Font(shell.getDisplay(), "Courier New", 9, SWT.NORMAL);
// 初始化界面布局
initLayout(shell);
// 打开对话框
Display display = parent.getDisplay();
Rectangle rect = display.getClientArea();
Point size = shell.getSize();
shell.layout();
shell.setLocation((rect.width - size.x) / 2, (rect.height - size.y) / 2);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
return arg;
}
/**
* 初始化界面布局
*
* @param shell
* 窗口对象
*/
private void initLayout(final Shell shell) {
// 设置layout
GridLayout layout = new GridLayout();
layout.numColumns = 2;
shell.setLayout(layout);
// QQ号
Label lblQQ = new Label(shell, SWT.RIGHT);
lblQQ.setText("QQ Number:");
lblQQ.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
textQQ = new Text(shell, SWT.SINGLE | SWT.BORDER);
textQQ.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
textQQ.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if(!Character.isDigit(e.character) && !Character.isISOControl(e.character))
e.doit = false;
}
});
// 密码
Label lblPassword = new Label(shell, SWT.RIGHT);
lblPassword.setText("Password:");
lblPassword.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
textPassword = new Text(shell, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD);
textPassword.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// 登录回复包
Label lblLoginReply = new Label(shell, SWT.RIGHT);
lblLoginReply.setText("Login Reply:");
lblLoginReply.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING));
textLoginReply = new Text(shell, SWT.MULTI | SWT.WRAP | SWT.BORDER);
textLoginReply.setLayoutData(new GridData(GridData.FILL_BOTH));
textLoginReply.setFont(font);
// composite
Composite comp = new Composite(shell, SWT.NONE);
layout = new GridLayout();
layout.numColumns = 2;
layout.horizontalSpacing = 20;
layout.makeColumnsEqualWidth = true;
comp.setLayout(layout);
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan = 2;
comp.setLayoutData(gd);
// 确定按钮
Button btnOK = new Button(comp, SWT.PUSH);
btnOK.setText("OK");
btnOK.setSize(100, 20);
btnOK.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
btnOK.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
arg = createDebugArgument();
if(arg == null)
MessageDialog.openWarning(shell, "Warning", "Some errors exist in your input, try again!");
else
shell.close();
}
});
// 取消按钮
Button btnCancel = new Button(comp, SWT.PUSH);
btnCancel.setText("Cancel");
btnCancel.setSize(100, 20);
btnCancel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
btnCancel.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
arg = null;
shell.close();
}
});
}
/**
* 创建调试参数bean
*
* @return
* 如果失败,返回null
*/
protected InitialArgument createDebugArgument() {
if(textQQ.getText().trim().equals(""))
return null;
byte[] reply = Util.convertHexStringToByte(textLoginReply.getText());
if(reply == null)
return null;
InitialArgument da = new InitialArgument();
da.setQQ(Integer.parseInt(textQQ.getText().trim()));
da.setPassword(textPassword.getText());
da.setLoginReply(reply);
return da;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -