📄 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.ui.dialogs;
import java.io.File;
import java.io.IOException;
import java.util.Calendar;
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.custom.CCombo;
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.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 starlight.util.Base64;
import edu.tsinghua.lumaqq.Colors;
import edu.tsinghua.lumaqq.IconHolder;
import edu.tsinghua.lumaqq.LumaQQ;
import edu.tsinghua.lumaqq.qq.Util;
import edu.tsinghua.lumaqq.ui.helper.ConfigHelper;
import edu.tsinghua.lumaqq.ui.tool.AroundBorderPaintListener;
import edu.tsinghua.lumaqq.ui.tool.UITool;
import edu.tsinghua.lumaqq.widgets.QButton;
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.QQNumberComparator;
/**
* 登陆对话框
*
* @author 马若劼
*/
public class LoginDialog extends Dialog {
// 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 QButton btnLogin, btnCancel, btnClear;
private Button chkRemember, chkHidden;
private Text text;
private CCombo 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) {
GridLayout layout = new GridLayout();
layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0;
dialog.setLayout(layout);
dialog.setBackground(Colors.LOGIN_BACKGROUP);
UITool.setDefaultBackground(Colors.LOGIN_BACKGROUP);
// logo
Label lblLogo = UITool.createLabel(dialog, "", SWT.CENTER);
setLogo(lblLogo);
layout = new GridLayout(3, false);
layout.marginHeight = layout.marginWidth = 25;
layout.verticalSpacing = 14;
layout.horizontalSpacing = 10;
Composite c = UITool.createContainer(dialog, new GridData(GridData.FILL_BOTH), layout);
c.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
Rectangle rect = ((Composite)e.getSource()).getClientArea();
rect.x = rect.y = 5;
rect.width -= 10;
rect.height -= 10;
e.gc.setForeground(Colors.PAGE_CONTROL_BORDER);
e.gc.drawRectangle(rect);
}
});
c.addPaintListener(new AroundBorderPaintListener(new Class[] { Text.class, CCombo.class }, Colors.PAGE_CONTROL_BORDER));
// 号码
UITool.createLabel(c, LumaQQ.getString("login.qq.number"));
// 号码下拉框
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan = 2;
gd.heightHint = 18;
combo = UITool.createCCombo(c, gd, SWT.FLAT);
combo.setBackground(Colors.WHITE);
// 密码
UITool.createLabel(c, LumaQQ.getString("login.qq.password"));
// 密码框
gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan = 2;
gd.heightHint = 18;
text = UITool.createSingleText(c, gd, SWT.SINGLE | SWT.PASSWORD);
text.setBackground(Colors.WHITE);
text.setEchoChar('*');
// placeholder
UITool.createLabel(c, "");
// 记住密码checkbox
chkRemember = UITool.createCheckbox(c, LumaQQ.getString("login.remember.password"));
// 隐身登陆checkbox
chkHidden = UITool.createCheckbox(c, LumaQQ.getString("login.hidden"), new GridData(GridData.HORIZONTAL_ALIGN_END));
// 按钮区容器
layout = new GridLayout(2, false);
layout.horizontalSpacing = 10;
c = UITool.createContainer(dialog, new GridData(GridData.FILL_HORIZONTAL), layout);
// 登录
gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
gd.grabExcessHorizontalSpace = true;
gd.widthHint = 70;
btnLogin = UITool.createQButton(c, LumaQQ.getString("login.login"), gd);
// 取消
gd = new GridData();
gd.widthHint = 70;
btnCancel = UITool.createQButton(c, LumaQQ.getString("login.cancel"), gd);
}
/**
* 初始化监听器
*/
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();
}
});
// 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 = ConfigHelper.findLogin(logins, combo.getText());
if(login == null) {
log.error("登陆历史信息文件有错误");
return;
}
setInitValue(login);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -