⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 createclustershell.java

📁 类似于MSN
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
* 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.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.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
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.Image;
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.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.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
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.events.FriendSelectionEvent;
import edu.tsinghua.lumaqq.events.FriendSelectionListener;
import edu.tsinghua.lumaqq.models.FriendModel;
import edu.tsinghua.lumaqq.qq.QQ;
import edu.tsinghua.lumaqq.qq.beans.ContactInfo;
import edu.tsinghua.lumaqq.qq.events.QQEvent;
import edu.tsinghua.lumaqq.qq.events.QQListener;
import edu.tsinghua.lumaqq.qq.packets.in.ClusterCommandReplyPacket;
import edu.tsinghua.lumaqq.qq.packets.out.ClusterCommandPacket;
import edu.tsinghua.swt.widgets.MySWT;
import edu.tsinghua.swt.widgets.ShutterLabel;

/**
 * <pre>
 * 创建群的向导窗口
 * </pre>
 * 
 * @author 马若劼
 */
public class CreateClusterShell extends ShellAdapter implements QQListener, FriendSelectionListener {    
	// Log对象
    protected static Log log = LogFactory.getLog(CreateClusterShell.class);
    private MainShell main;
	private Shell shell;
	private Display display;
	private IconHolder icons = IconHolder.getInstance();
	private Composite prevPanel;
	// 界面控件
	private Label lblLogo, lblSeparator;
	private Label lblType, lblDescription, lblMember, lblMemberManage, lblMemberNumber, lblAlbum, lblOfflineMessage, lblAddressList, lblLeaveWord;
	private Label lblName, lblQQ, lblHint;
	private Composite first, basic, member, create;
	private ShutterLabel btnNext, btnPrevious, btnFace;
	private Text textName, textNotice, textDescription;
	private CCombo comboCategory;
	private Table table;
	private Button radioNoAuth, radioNeedAuth, radioNoAdd;
	private Group authGroup;
	private FriendSelectShell fss;
	// 要创建的群的类型
	private byte type;
	// 要创建的群的认证类型
	private byte authType;
	// 当前步数
	private int step;
	// 动画帧
	private Image[] frames;
	
	/**
	 * 构造函数
	 * @param main MainShell对象
	 */
	public CreateClusterShell(MainShell main) {
		this.main = main;
		this.display = main.display;
		shell = new Shell(main.display, SWT.TITLE | SWT.CLOSE | SWT.MIN);
		shell.setSize(450, 380);
		shell.setImage(icons.getResource(IconHolder.icoQQ));
		shell.setText(LumaQQ.getResourceString("create.cluster.title"));
		// 设置layout
		shell.setLayout(new FormLayout());
		// 添加事件监听器
		shell.addShellListener(this);
		
		// 初始化变量
		type = QQ.QQ_CLUSTER_TYPE_PERMANENT;
		authType = QQ.QQ_CLUSTER_NEED_AUTH;
		step = 1;
		frames = new Image[] { icons.getClusterFace(1), icons.getClusterFace(2), icons.getClusterFace(3) };
		
		initLayout();
	}	

	// 初始化其他控件
	private void initLayout() {
		// 旁边的logo
        lblLogo = new Label(shell, SWT.NONE);
        lblLogo.setImage(icons.getResource(IconHolder.bmpSearch));
        FormData fd = new FormData();
        fd.left = new FormAttachment(0, 15);
        fd.top = new FormAttachment(0, 30);
        fd.right = new FormAttachment(0, lblLogo.getImage().getBounds().width + 15);
        fd.bottom = new FormAttachment(0, lblLogo.getImage().getBounds().height + 30);
        lblLogo.setLayoutData(fd);
        // 最下面的水平separator
        lblSeparator = new Label(shell, SWT.HORIZONTAL | SWT.SEPARATOR);
        fd = new FormData();
        fd.left = new FormAttachment(0, 10);
        fd.top = new FormAttachment(100, -40);
        fd.right = new FormAttachment(100, -10);
        lblSeparator.setLayoutData(fd);
        // 取消按钮
        ShutterLabel btnCancel = new ShutterLabel(shell, MySWT.HOVER | SWT.CENTER, LumaQQ.getResourceString("create.cluster.button.cancel"), null);
        fd = new FormData();
        fd.left = new FormAttachment(100, -90);
        fd.right = new FormAttachment(100, -10);
        fd.top = new FormAttachment(100, -28);
        btnCancel.setLayoutData(fd);
        btnCancel.addMouseListener(
        	new MouseAdapter() {
        		public void mouseUp(MouseEvent e) {
        			close();
        		}
        	}
        );
        // 下一步按钮
        btnNext = new ShutterLabel(shell, MySWT.HOVER | SWT.CENTER, LumaQQ.getResourceString("create.cluster.button.next"), null);
        fd = new FormData();
        fd.left = new FormAttachment(btnCancel, -90, SWT.LEFT);
        fd.right = new FormAttachment(btnCancel, -10, SWT.LEFT);
        fd.top = new FormAttachment(100, -28);
        btnNext.setLayoutData(fd);
        btnNext.addMouseListener(
        	new MouseAdapter() {
        		public void mouseUp(MouseEvent e) {
        			navigateNext();
        		}
        	}
        );
        // 上一步按钮
        btnPrevious = new ShutterLabel(shell, MySWT.HOVER | SWT.CENTER, LumaQQ.getResourceString("create.cluster.button.previous"), null);
        btnPrevious.setEnabled(false);
        fd = new FormData();
        fd.left = new FormAttachment(btnNext, -80, SWT.LEFT);
        fd.right = new FormAttachment(btnNext, 0, SWT.LEFT);
        fd.top = new FormAttachment(100, -28);
        btnPrevious.setLayoutData(fd);    
        btnPrevious.addMouseListener(
        	new MouseAdapter() {
        		public void mouseUp(MouseEvent e) {
        			navigatePrevious();
        		}
        	}
        );
        // 初始化首面板,用户在这里选择创建哪种群
        initFirstPanel();
        // 初始化群信息填写面板,用户在这里填写群的基本信息
        initBasicPanel();
        // 初始化添加群成员面板,用户在这里选择群的成员
        initMemberPanel();
        // 初始化创建面板,用户在这里等待服务器返回应答
        initCreatePanel();
	}
	
	// 创建一个面板
	private Composite createPanel() {
		Composite comp = new Composite(shell, SWT.NONE);
		FormData fd = new FormData();
		fd.left = new FormAttachment(lblLogo, 15, SWT.RIGHT);
		fd.right = new FormAttachment(100, -10);
		fd.top = new FormAttachment(0, 10);
		fd.bottom = new FormAttachment(lblSeparator, -10, SWT.TOP);
		comp.setLayoutData(fd);
		comp.setLayout(new FormLayout());
		return comp;
	}
	
	/**
	 * 初始化创建面板
	 */
	private void initCreatePanel() {
		create = createPanel();
		create.setVisible(false);
		// 添加group
		Group regGroup = new Group(create, SWT.SHADOW_ETCHED_IN);
		regGroup.setText(LumaQQ.getResourceString("create.cluster.create.group.register"));
        FormData fd = new FormData();
        fd.left = new FormAttachment(0, 20);
        fd.right = new FormAttachment(100, -20);        
        fd.top = new FormAttachment(0, 15);
        fd.bottom = new FormAttachment(50, -5);
        regGroup.setLayoutData(fd);
        regGroup.setLayout(new GridLayout());
        // 头像按钮
        btnFace = new ShutterLabel(regGroup, MySWT.FLAT | MySWT.IMAGE_HOVER | SWT.BOTTOM, null, icons.getClusterFace(1));
        btnFace.setShowSmallImage(false);
        GridData gd = new GridData(GridData.FILL_BOTH);
        btnFace.setLayoutData(gd);
        // 群名称标签
        lblName = new Label(regGroup, SWT.CENTER);
        gd = new GridData(GridData.FILL_HORIZONTAL);
        lblName.setLayoutData(gd);
        // 等待组
        Group waitGroup = new Group(create, SWT.SHADOW_ETCHED_IN);
        waitGroup.setText(LumaQQ.getResourceString("create.cluster.create.group.wait"));
        fd = new FormData();
        fd.left = new FormAttachment(0, 20);
        fd.top = new FormAttachment(50, 0);
        fd.right = fd.bottom = new FormAttachment(100, -20);        
        waitGroup.setLayoutData(fd);
        waitGroup.setLayout(new GridLayout());
        // 等待标签,提示标签
        lblHint = new Label(waitGroup, SWT.WRAP);
        lblHint.setText(LumaQQ.getResourceString("create.cluster.create.processing"));
        lblHint.setLayoutData(new GridData(GridData.FILL_BOTH));
	}

	/**
	 * 创建选择成员面板
	 */
	private void initMemberPanel() {
		member = createPanel();
		member.setVisible(false);
		// 提示标签
		Label lblHint = new Label(member, SWT.NONE);
		lblHint.setText(LumaQQ.getResourceString("create.cluster.member.label.hint"));
		FormData fd = new FormData();
		fd.left = fd.top = new FormAttachment(0, 0);
		fd.right = new FormAttachment(100, 0);
		lblHint.setLayoutData(fd);
		// 成员列表
		table = new Table(member, SWT.FULL_SELECTION | SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
		fd = new FormData();
		fd.left = new FormAttachment(0, 0);
		fd.right = new FormAttachment(100, 0);
		fd.top = new FormAttachment(lblHint, 5, SWT.BOTTOM);
		fd.bottom = new FormAttachment(100, 0);
		table.setLayoutData(fd);
		// 表头
		// QQ
		TableColumn tc = new TableColumn(table, SWT.LEFT);
		tc.setText(LumaQQ.getResourceString("create.cluster.member.table.header.qq"));
		tc.setWidth(80);
		// 昵称
		tc = new TableColumn(table, SWT.CENTER);
		tc.setText(LumaQQ.getResourceString("create.cluster.member.table.header.nick"));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -