📄 logindialog.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.shells;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
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 starlight.util.Base64;
import edu.tsinghua.lumaqq.IconHolder;
import edu.tsinghua.lumaqq.LumaQQ;
import edu.tsinghua.lumaqq.ModelUtils;
import edu.tsinghua.lumaqq.qq.Utils;
import edu.tsinghua.lumaqq.xml.logins.Login;
import edu.tsinghua.lumaqq.xml.logins.LoginImpl;
import edu.tsinghua.lumaqq.xml.logins.Logins;
import edu.tsinghua.lumaqq.xml.logins.LoginsUnmarshaller;
import edu.tsinghua.lumaqq.xml.logins.QQNumberComparator;
import edu.tsinghua.swt.widgets.MySWT;
import edu.tsinghua.swt.widgets.ShutterLabel;
/**
* 登陆对话框
*
* @author 马若劼
*/
public class LoginDialog extends Dialog implements DisposeListener {
// Log对象
protected static Log log = LogFactory.getLog(LoginDialog.class);
// Shell
private Shell dialog;
// 是否记住密码
private boolean rememberPassword;
// 是否隐身登陆
private boolean loginHidden;
// 用户QQ号
private int qqNum;
// 密码的MD5形式
private byte[] md5pwd;
// 颜色
private Color color;
private Color loginButtonColor, cancelButtonColor;
// 所有组件
private ShutterLabel btnLogin, btnCancel;
private Button chkRemember, chkHidden;
private Text text;
private Combo combo;
// 用户是否点了登陆按钮
private boolean ok;
// 登陆历史信息文件根元素对象
private Logins logins;
// 用户这次是否修改了密码
private boolean changed;
// IconHolder实例
private IconHolder icons = IconHolder.getInstance();
/**
* @param shell
*/
public LoginDialog(Shell shell) {
super(shell);
}
/**
* @param shell
* @param style
*/
public LoginDialog(Shell shell, int style) {
super(shell, style);
}
/**
* @param dialog
*/
private void initLayout(Shell dialog) {
color = new Color(dialog.getDisplay(), 0xF7, 0xF3, 0xF7);
loginButtonColor = new Color(dialog.getDisplay(), 0xC6, 0xD3, 0xF7);
cancelButtonColor = new Color(dialog.getDisplay(), 0xEF, 0xEF, 0xF7);
dialog.setLayout(new FormLayout());
// 登陆图像条
Label bar = new Label(dialog, SWT.NONE);
bar.setImage(icons.getResource(IconHolder.bmpLogin));
FormData fd = new FormData();
fd.left = fd.top = new FormAttachment(0, 0);
fd.right = new FormAttachment(100, 0);
fd.bottom = new FormAttachment(0, bar.getImage().getBounds().height);
bar.setLayoutData(fd);
// 信息输入组件容器
Composite comp = new Composite(dialog, SWT.NONE);
comp.setBackground(color);
fd = new FormData();
fd.left = new FormAttachment(0, 10);
fd.right = new FormAttachment(100, -10);
fd.top = new FormAttachment(bar, 30, SWT.BOTTOM);
fd.bottom = new FormAttachment(100, -40);
comp.setLayoutData(fd);
comp.setLayout(new FormLayout());
comp.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
Composite c = (Composite)e.widget;
paintHoverBorder(e.gc, c.getClientArea(), true);
}
});
// 用户QQ号标签
Label lblQQ = new Label(comp, SWT.NONE);
lblQQ.setText(LumaQQ.getResourceString("login.qq.number"));
lblQQ.setBackground(color);
fd = new FormData();
fd.left = new FormAttachment(6, 0);
fd.top = new FormAttachment(20, 0);
lblQQ.setLayoutData(fd);
// QQ号下拉输入框
combo = new Combo(comp, SWT.DROP_DOWN);
fd = new FormData();
fd.left = new FormAttachment(25, 10);
fd.right = new FormAttachment(80, 0);
fd.top = new FormAttachment(20, 0);
combo.setLayoutData(fd);
// QQ密码标签
Label lblPwd = new Label(comp, SWT.NONE);
lblPwd.setText(LumaQQ.getResourceString("login.qq.password"));
lblPwd.setBackground(color);
fd = new FormData();
fd.left = new FormAttachment(6, 0);
fd.top = new FormAttachment(47, 0);
lblPwd.setLayoutData(fd);
// 密码输入框
text = new Text(comp, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD);
text.setEchoChar('*');
fd = new FormData();
fd.left = new FormAttachment(25, 10);
fd.right = new FormAttachment(80, 0);
fd.top = new FormAttachment(47, 0);
text.setLayoutData(fd);
// 记住密码checkbox
chkRemember = new Button(comp, SWT.CHECK);
chkRemember.setText(LumaQQ.getResourceString("login.remember.password"));
chkRemember.setBackground(color);
fd = new FormData();
fd.left = new FormAttachment(text, 0, SWT.LEFT);
fd.top = new FormAttachment(text, 7, SWT.BOTTOM);
chkRemember.setLayoutData(fd);
// 隐身登陆checkbox
chkHidden = new Button(comp, SWT.CHECK);
chkHidden.setText(LumaQQ.getResourceString("login.hidden"));
chkHidden.setBackground(color);
fd = new FormData();
fd.right = new FormAttachment(text, 0, SWT.RIGHT);
fd.top = new FormAttachment(text, 7, SWT.BOTTOM);
chkHidden.setLayoutData(fd);
// 登陆按钮
btnLogin = new ShutterLabel(dialog, MySWT.HOVER | SWT.CENTER, LumaQQ.getResourceString("login.login"), null);
btnLogin.setBackground(loginButtonColor);
fd = new FormData();
fd.left = new FormAttachment(comp, -150, SWT.RIGHT);
fd.right = new FormAttachment(comp, -80, SWT.RIGHT);
fd.top = new FormAttachment(comp, 10, SWT.BOTTOM);
btnLogin.setLayoutData(fd);
// 取消按钮
btnCancel = new ShutterLabel(dialog, MySWT.HOVER | SWT.CENTER, LumaQQ.getResourceString("login.cancel"), null);
btnCancel.setBackground(cancelButtonColor);
fd = new FormData();
fd.left = new FormAttachment(comp, -70, SWT.RIGHT);
fd.right = new FormAttachment(comp, 0, SWT.RIGHT);
fd.top = new FormAttachment(comp, 10, SWT.BOTTOM);
btnCancel.setLayoutData(fd);
// 设置对话框大小
dialog.setSize(bar.getImage().getBounds().width, 250);
}
/**
* 初始化监听器
*/
private void initListeners(final Shell dialog) {
// 取消按钮鼠标事件
btnCancel.addMouseListener(
new MouseAdapter() {
public void mouseUp(MouseEvent e) {
ok = false;
dialog.close();
}
}
);
// 登陆按钮鼠标事件
btnLogin.addMouseListener(
new MouseAdapter() {
public void mouseUp(MouseEvent e) {
doOk();
dialog.close();
}
}
);
// qq号输入框输入校验事件
combo.addKeyListener(
new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if(e.character < '0' || e.character > '9')
if(e.keyCode != SWT.DEL && e.keyCode != SWT.BS)
if(e.keyCode != SWT.ARROW_LEFT && e.keyCode != SWT.ARROW_RIGHT)
if(e.keyCode != SWT.HOME && e.keyCode != SWT.END)
e.doit = false;
}
}
);
// qq号输入框选择事件
combo.addSelectionListener(
new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
// 查找选择的号码的信息,重新设置控件的value
Login login = findLogin(combo.getText());
if(login == null) {
log.error("登陆历史信息文件有错误");
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -