📄 systemoptionshell.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.net.InetSocketAddress;
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.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.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Point;
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.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.MessageBox;
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.IProxyHandler;
import edu.tsinghua.lumaqq.qq.ProxyVerifier;
import edu.tsinghua.lumaqq.qq.Utils;
import edu.tsinghua.lumaqq.utils.OptionUtils;
import edu.tsinghua.lumaqq.utils.ProxyUtils;
import edu.tsinghua.lumaqq.utils.ReplyUtils;
import edu.tsinghua.lumaqq.xml.proxies.HttpProxy;
import edu.tsinghua.lumaqq.xml.proxies.HttpProxyImpl;
import edu.tsinghua.lumaqq.xml.proxies.Socks5Proxy;
import edu.tsinghua.lumaqq.xml.proxies.Socks5ProxyImpl;
import edu.tsinghua.swt.widgets.MySWT;
import edu.tsinghua.swt.widgets.ShutterLabel;
/**
* 查看用户信息的对话框
*
* * @author 马若劼
*/
public class SystemOptionShell extends ShellAdapter implements DisposeListener, IProxyHandler {
// banner的paint事件监听器
private class BannerPaintListener implements PaintListener {
private String text;
public BannerPaintListener(String text) {
this.text = text;
}
public void paintControl(PaintEvent e) {
Control control = (Control)e.widget;
Rectangle ca = control.getBounds();
Point extent = e.gc.textExtent(text);
e.gc.drawString(text, (ca.width - extent.x) / 2, (ca.height - extent.y) / 2);
}
}
private Composite prevComposite;
private ShutterLabel prevButton;
private int prevPanel;
private ShutterLabel[] buttons;
private Composite[] composites;
private static final int PANEL_NUM = 5;
public static final int GUI = 0;
public static final int MESSAGE = 1;
public static final int REPLY = 2;
public static final int LOGIN = 3;
public static final int OTHER = 4;
// Log对象
protected static Log log = LogFactory.getLog(UserInfoShell.class);
// IconHolder实例
private IconHolder icons = IconHolder.getInstance();
// 配置工具类实例
private OptionUtils options = OptionUtils.getInstance();
// 回复信息工具类实例
private ReplyUtils replies = ReplyUtils.getInstance();
// 代理列表工具类实例
private ProxyUtils proxies = ProxyUtils.getInstance();
// 代理验证类
private ProxyVerifier verifier;
// 界面控件
private Color switchButtonColor, controlBackground, bannerBackground, panelBackground, commonButtonColor;
private MainShell main;
private Shell shell;
private Display display;
private CCombo comboMethod, comboServer, comboProxyType;
private Button chkUse2004, chkAutoSelect, chkAutoHide, chkShowTip, chkShowOnlineTip, chkShowMessageTip, chkAutoEject, chkRejectStranger, chkEnableSound;
private Button chkUseProxy, btnVerify;
private ShutterLabel btnAddQuick, btnRemoveQuick, btnAddAuto, btnRemoveAuto;
private Text textReply, textProxyAddress, textProxyPort, textProxyUsername, textProxyPassword, textBrowser;
private Table quickTable, autoTable;
private List proxyList;
/**
* @param parent
*/
public SystemOptionShell(MainShell main) {
this.main = main;
this.display = main.display;
shell = new Shell(display, SWT.TITLE | SWT.CLOSE | SWT.MIN);
shell.setSize(480, 390);
shell.setText(LumaQQ.getResourceString("sys.opt.title"));
shell.setImage(icons.getResource(IconHolder.icoSysOpt));
// 设置layout
shell.setLayout(new FormLayout());
// 添加事件监听器
shell.addDisposeListener(this);
shell.addShellListener(this);
// 初始化变量
panelBackground = new Color(display, 0xF3, 0xF3, 0xF3);
controlBackground = new Color(display, 0xF7, 0xE2, 0xF7);
bannerBackground = new Color(display, 0x5D, 0x83, 0xD4);
commonButtonColor = new Color(display, 0xC6, 0xD3, 0xF7);
switchButtonColor = bannerBackground;
buttons = new ShutterLabel[PANEL_NUM];
composites = new Composite[PANEL_NUM];
initLayout();
}
// 初始化控件布局
private void initLayout() {
// 左边的信息分类选择按钮列
// 界面设置按钮
ShutterLabel btnGUI = new ShutterLabel(shell, MySWT.FLAT | MySWT.HOVER | SWT.CENTER, LumaQQ.getResourceString("sys.opt.button.gui"), icons.getResource(IconHolder.icoArrow));
btnGUI.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
btnGUI.setBackground(switchButtonColor);
FormData fd = new FormData();
fd.left = fd.top = new FormAttachment(0, 5);
fd.right = new FormAttachment(0, 105);
btnGUI.setLayoutData(fd);
prevPanel = GUI;
prevButton = btnGUI;
btnGUI.addMouseListener(
new MouseAdapter() {
public void mouseDown(MouseEvent e) {
showPanel(GUI);
}
}
);
// 消息设置按钮
ShutterLabel btnMessage = new ShutterLabel(shell, MySWT.FLAT | MySWT.HOVER | SWT.CENTER, LumaQQ.getResourceString("sys.opt.button.message"), null);
btnMessage.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
btnMessage.setBackground(switchButtonColor);
fd = new FormData();
fd.left = new FormAttachment(btnGUI, 0, SWT.LEFT);
fd.top = new FormAttachment(btnGUI, 0, SWT.BOTTOM);
fd.right = new FormAttachment(btnGUI, 0, SWT.RIGHT);
btnMessage.setLayoutData(fd);
btnMessage.addMouseListener(
new MouseAdapter() {
public void mouseDown(MouseEvent e) {
showPanel(MESSAGE);
}
}
);
// 回复设置按钮
ShutterLabel btnReply = new ShutterLabel(shell, MySWT.FLAT | MySWT.HOVER | SWT.CENTER, LumaQQ.getResourceString("sys.opt.button.reply"), null);
btnReply.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
btnReply.setBackground(switchButtonColor);
fd = new FormData();
fd.left = new FormAttachment(btnMessage, 0, SWT.LEFT);
fd.top = new FormAttachment(btnMessage, 0, SWT.BOTTOM);
fd.right = new FormAttachment(btnMessage, 0, SWT.RIGHT);
btnReply.setLayoutData(fd);
btnReply.addMouseListener(
new MouseAdapter() {
public void mouseDown(MouseEvent e) {
showPanel(REPLY);
}
}
);
// 登陆设置按钮
ShutterLabel btnLogin = new ShutterLabel(shell, MySWT.FLAT | MySWT.HOVER | SWT.CENTER, LumaQQ.getResourceString("sys.opt.button.login"), null);
btnLogin.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
btnLogin.setBackground(switchButtonColor);
fd = new FormData();
fd.left = new FormAttachment(btnReply, 0, SWT.LEFT);
fd.top = new FormAttachment(btnReply, 0, SWT.BOTTOM);
fd.right = new FormAttachment(btnReply, 0, SWT.RIGHT);
btnLogin.setLayoutData(fd);
btnLogin.addMouseListener(
new MouseAdapter() {
public void mouseDown(MouseEvent e) {
showPanel(LOGIN);
}
}
);
// 其他设置按钮
ShutterLabel btnOther = new ShutterLabel(shell, MySWT.FLAT | MySWT.HOVER | SWT.CENTER, LumaQQ.getResourceString("sys.opt.button.other"), null);
btnOther.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
btnOther.setBackground(switchButtonColor);
fd = new FormData();
fd.left = new FormAttachment(btnLogin, 0, SWT.LEFT);
fd.top = new FormAttachment(btnLogin, 0, SWT.BOTTOM);
fd.right = new FormAttachment(btnLogin, 0, SWT.RIGHT);
btnOther.setLayoutData(fd);
btnOther.addMouseListener(
new MouseAdapter() {
public void mouseDown(MouseEvent e) {
showPanel(OTHER);
}
}
);
// 添加到数组中
buttons[GUI] = btnGUI;
buttons[MESSAGE] = btnMessage;
buttons[REPLY] = btnReply;
buttons[LOGIN] = btnLogin;
buttons[OTHER] = btnOther;
// 初始化界面设置面板
initGUIPanel();
// 初始化消息设置面板
initMessagePanel();
// 初始化回复设置面板
initReplyPanel();
// 初始化登陆设置面板
initLoginPanel();
// 初始化其他设置面板
initOtherPanel();
// 取消按钮
ShutterLabel btnCancel = new ShutterLabel(shell, MySWT.HOVER | SWT.CENTER, LumaQQ.getResourceString("sys.opt.button.cancel"), null);
btnCancel.setBackground(commonButtonColor);
fd = new FormData();
fd.right = new FormAttachment(100, -5);
fd.left = new FormAttachment(100, -65);
fd.top = new FormAttachment(composites[0], 8, SWT.BOTTOM);
btnCancel.setLayoutData(fd);
btnCancel.addMouseListener(
new MouseAdapter() {
public void mouseUp(MouseEvent e) {
close();
}
}
);
// 确定按钮
ShutterLabel btnOK = new ShutterLabel(shell, MySWT.HOVER | SWT.CENTER, LumaQQ.getResourceString("sys.opt.button.ok"), null);
btnOK.setBackground(commonButtonColor);
fd = new FormData();
fd.right = new FormAttachment(btnCancel, -10, SWT.LEFT);
fd.left = new FormAttachment(btnCancel, -70, SWT.LEFT);
fd.top = new FormAttachment(btnCancel, 0, SWT.TOP);
btnOK.setLayoutData(fd);
btnOK.addMouseListener(
new MouseAdapter() {
public void mouseUp(MouseEvent e) {
doOk();
}
}
);
}
/**
* 初始化其他设置面板
*/
private void initOtherPanel() {
Composite other = createPanel();
other.setVisible(false);
composites[OTHER] = other;
// banner
Label otherBanner = new Label(other, SWT.NONE);
otherBanner.setBackground(bannerBackground);
otherBanner.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
FormData fd = new FormData();
fd.left = fd.top = new FormAttachment(0, 0);
fd.right = new FormAttachment(100, 0);
fd.bottom = new FormAttachment(0, 24);
otherBanner.setLayoutData(fd);
otherBanner.addPaintListener(new BannerPaintListener(LumaQQ.getResourceString("sys.opt.banner.other")));
// 外部浏览器命令行标签
Label lblBrowser = new Label(other, SWT.NONE);
lblBrowser.setText(LumaQQ.getResourceString("sys.opt.other.label.browser"));
lblBrowser.setBackground(panelBackground);
fd = new FormData();
fd.left = new FormAttachment(0, 5);
fd.top = new FormAttachment(otherBanner, 5, SWT.BOTTOM);
lblBrowser.setLayoutData(fd);
// 选择按钮
Button btnSelect = new Button(other, SWT.PUSH);
btnSelect.setText(LumaQQ.getResourceString("sys.opt.other.button.select"));
fd = new FormData();
fd.right = new FormAttachment(100, -5);
fd.left = new FormAttachment(100, - 85);
fd.top = new FormAttachment(lblBrowser, 5, SWT.BOTTOM);
btnSelect.setLayoutData(fd);
btnSelect.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
FileDialog dialog = new FileDialog(shell, SWT.OPEN);
String browser = dialog.open();
if(browser != null) {
File file = new File(browser);
if(file.exists()) {
browser = file.getAbsolutePath() + " [URL]";
textBrowser.setText(browser);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -