📄 smsresultdialog.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.ui.dialogs;
import java.util.Iterator;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
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.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import edu.tsinghua.lumaqq.IconHolder;
import edu.tsinghua.lumaqq.LumaQQ;
import edu.tsinghua.lumaqq.qq.QQ;
import edu.tsinghua.lumaqq.qq.packets.in.SendSMSReplyPacket;
/**
* <pre>
* 显示短消息发送结果的对话框
* </pre>
*
* @author 马若劼
*/
public class SMSResultDialog extends Dialog {
private Shell shell;
private Label lblResult;
private Text textReply;
private List reply;
/**
* 创建对话框
*
* @param parent
*/
public SMSResultDialog(Shell parent, List reply) {
super(parent);
this.reply = reply;
shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
shell.setText(LumaQQ.getString("sms.result.title"));
shell.setSize(300, 300);
shell.setImage(IconHolder.getInstance().getImage(IconHolder.icoMobile));
// 初始化界面
initLayout();
}
/**
* 初始化界面
*/
private void initLayout() {
shell.setLayout(new GridLayout());
Table table = new Table(shell, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.heightHint = 100;
table.setLayoutData(gd);
table.setHeaderVisible(false);
table.setLinesVisible(true);
TableColumn tc = new TableColumn(table, SWT.LEFT);
tc.setWidth(100);
tc = new TableColumn(table, SWT.LEFT);
tc.setWidth(200);
Iterator iter = reply.iterator();
for(int i = 1; iter.hasNext(); i++) {
SendSMSReplyPacket packet = (SendSMSReplyPacket)iter.next();
TableItem ti = new TableItem(table, SWT.NONE);
ti.setData(packet);
ti.setText(0, LumaQQ.getString("sms.result.msg", new Object[] { String.valueOf(i) }));
if((packet.toBindUser && packet.replyCode_1 == QQ.QQ_SMS_REPLY_OK_1) || (!packet.toBindUser && packet.replyCode_2 == QQ.QQ_SMS_REPLY_OK_2))
ti.setText(1, LumaQQ.getString("sms.result.ok"));
else
ti.setText(1, LumaQQ.getString("sms.result.fail"));
}
table.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
Table table = (Table)e.getSource();
int index = table.getSelectionIndex();
if(index != -1) {
TableItem ti = table.getItem(index);
SendSMSReplyPacket packet = (SendSMSReplyPacket)ti.getData();
lblResult.setText(ti.getText(1));
textReply.setText(packet.replyMessage);
}
}
});
lblResult = new Label(shell, SWT.LEFT);
lblResult.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
textReply = new Text(shell, SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.WRAP);
textReply.setLayoutData(new GridData(GridData.FILL_BOTH));
Button btnOK = new Button(shell, SWT.PUSH);
btnOK.setText(LumaQQ.getString("sms.result.button.ok"));
gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
gd.grabExcessHorizontalSpace = true;
btnOK.setLayoutData(gd);
btnOK.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
shell.close();
}
});
}
/**
* 打开对话框
*/
public void open() {
// Your code goes here (widget creation, set result, etc).
Display display = shell.getDisplay();
// 设置窗口位置
Rectangle rect = display.getClientArea();
Point size = shell.getSize();
shell.setLocation((rect.width - size.x) / 2, (rect.height - size.y) / 2);
shell.layout();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -