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

📄 clusterinfoshell.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.Hashtable;
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.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
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.SelectionListener;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
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.layout.GridLayout;
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.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.ClusterModel;
import edu.tsinghua.lumaqq.models.FriendModel;
import edu.tsinghua.lumaqq.models.GroupModel;
import edu.tsinghua.lumaqq.qq.QQ;
import edu.tsinghua.lumaqq.qq.beans.ClusterInfo;
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.swt.widgets.MySWT;
import edu.tsinghua.swt.widgets.ShutterLabel;

/**
 * <pre>
 * 用于显示群信息的Shell
 * </pre>
 * 
 * @author 马若劼
 */
public class ClusterInfoShell extends ShellAdapter implements DisposeListener, FriendSelectionListener, QQListener {
    // 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 class FacePanelListener extends ShellAdapter {
		public void shellClosed(ShellEvent e) {
			int code = iss.getSelectedImageCode();
			if(code != -1)
				face = code;
			btnFace.setImage(icons.getClusterFace(face));
			c.addProperty("face", new Integer(face));
		}
	}
	
	protected static Log log = LogFactory.getLog(UserInfoShell.class);
    private IconHolder icons = IconHolder.getInstance();
    
	private ShutterLabel[] buttons;
	private Composite[] composites;
	private ShutterLabel prevButton;	
	private Composite prevComposite;
	private int prevPanel;
	private static final int PANEL_NUM = 3;
	private static final int BASIC = 0;
	private static final int MEMBER = 1;
	private static final int MESSAGE = 2;
	
	private Display display;
    private MainShell main;
	private Shell shell;
	// 颜色
    private Color switchButtonColor, controlBackground, bannerBackground, panelBackground, commonButtonColor;
    // model
    private ClusterModel c;
    // 认证类型
    private byte authType;
    // 头像号
    private int face;
    // 消息设定
    private String messageOption;
    // 界面控件
    private ShutterLabel btnUpdate, btnModify, btnFace;
    private Label basicBanner;
    private Text textId, textCreator, textName, textNotice, textDescription;
    private CCombo comboCategory;
    private Group authGroup;
    private Button radioNoAuth, radioNeedAuth, radioNoAdd;
    private Button radioAccept, radioEject, radioRecord, radioBlock;
    private Button btnRemoveMember, btnSetMember, btnAddFriend;
    private Table table;
    private ImageSelectShell iss;
    private FriendSelectShell fss;
	
	/**
	 * @param parent
	 */
	public ClusterInfoShell(MainShell main) {
		this.main = main;
		this.display = main.display;
		shell = new Shell(this.display, SWT.TITLE | SWT.CLOSE | SWT.MIN);
		shell.setSize(450, 410);
		shell.setText(LumaQQ.getResourceString("cluster.info.title"));
		shell.setImage(icons.getResource(IconHolder.icoQQ));
		// 设置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 btnBasic = new ShutterLabel(shell, MySWT.FLAT | MySWT.HOVER | SWT.CENTER, LumaQQ.getResourceString("cluster.info.button.basic"), icons.getResource(IconHolder.icoArrow));
        btnBasic.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
        btnBasic.setBackground(switchButtonColor);
		FormData fd = new FormData();
		fd.left = fd.top = new FormAttachment(0, 5);
		fd.right = new FormAttachment(0, 105);
		btnBasic.setLayoutData(fd);
        prevPanel = BASIC;
		prevButton = btnBasic;
		btnBasic.addMouseListener(
			new MouseAdapter() {
				public void mouseDown(MouseEvent e) {
					showPanel(BASIC);
					btnUpdate.setText(LumaQQ.getResourceString("cluster.info.button.update"));
				}
			}
		);
		// 成员列表按钮
        ShutterLabel btnMember = new ShutterLabel(shell, MySWT.FLAT | MySWT.HOVER | SWT.CENTER, LumaQQ.getResourceString("cluster.info.button.member"), null);
        btnMember.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
        btnMember.setBackground(switchButtonColor);
		fd = new FormData();
		fd.left = new FormAttachment(0, 5);
		fd.top = new FormAttachment(btnBasic, 0, SWT.BOTTOM);
		fd.right = new FormAttachment(0, 105);
		btnMember.setLayoutData(fd);
		btnMember.addMouseListener(
			new MouseAdapter() {
				public void mouseDown(MouseEvent e) {
					showPanel(MEMBER);
					btnUpdate.setText(LumaQQ.getResourceString("cluster.info.button.update"));
				}
			}
		);
		// 消息设定按钮
        ShutterLabel btnMessage = new ShutterLabel(shell, MySWT.FLAT | MySWT.HOVER | SWT.CENTER, LumaQQ.getResourceString("cluster.info.button.message"), null);
        btnMessage.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
        btnMessage.setBackground(switchButtonColor);
		fd = new FormData();
		fd.left = new FormAttachment(0, 5);
		fd.top = new FormAttachment(btnMember, 0, SWT.BOTTOM);
		fd.right = new FormAttachment(0, 105);
		btnMessage.setLayoutData(fd);
		btnMessage.addMouseListener(
			new MouseAdapter() {
				public void mouseDown(MouseEvent e) {
					showPanel(MESSAGE);
					btnUpdate.setText(LumaQQ.getResourceString("cluster.info.button.modify"));
				}
			}
		);
		// 加入按钮到数组中
		buttons[BASIC] = btnBasic;
		buttons[MEMBER] = btnMember;
		buttons[MESSAGE] = btnMessage;
		// 初始化基本资料面板
		initBasicPanel();
		// 初始化成员列表面板
		initMemberPanel();
		// 初始化消息设定面板
		initMessagePanel();
		// 关闭按钮
		ShutterLabel btnClose = new ShutterLabel(shell, MySWT.HOVER | SWT.CENTER, LumaQQ.getResourceString("cluster.info.button.close"), null);
		btnClose.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);
		btnClose.setLayoutData(fd);
		btnClose.addMouseListener(
			new MouseAdapter() {
				public void mouseUp(MouseEvent e) {
					close();
				}
			}
		);
		// 更新按钮
		btnUpdate = new ShutterLabel(shell, MySWT.HOVER | SWT.CENTER, LumaQQ.getResourceString("cluster.info.button.update"), null);
		btnUpdate.setBackground(commonButtonColor);
		fd = new FormData();
		fd.right = new FormAttachment(btnClose, -10, SWT.LEFT);
		fd.left = new FormAttachment(btnClose, -70, SWT.LEFT);
		fd.top = new FormAttachment(btnClose, 0, SWT.TOP);
		btnUpdate.setLayoutData(fd);
		btnUpdate.addMouseListener(
			new MouseAdapter() {
				public void mouseUp(MouseEvent e) {
					// 如果处于消息设定面板,则修改消息设定
					if(composites[MESSAGE].isVisible()) {
						c.addProperty("message", messageOption);
						MessageBox box = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
						box.setText(LumaQQ.getResourceString("message.box.common.success.title"));
						box.setMessage(LumaQQ.getResourceString("message.box.cluster.message.option.modified"));
						box.open();
					} else
						updateClusterInfo();
				}
			}
		);		
		// 修改按钮
		btnModify = new ShutterLabel(shell, MySWT.HOVER | SWT.CENTER, LumaQQ.getResourceString("cluster.info.button.modify"), null);
		btnModify.setBackground(commonButtonColor);
		fd = new FormData();
		fd.right = new FormAttachment(btnClose, -10, SWT.LEFT);
		fd.left = new FormAttachment(btnClose, -70, SWT.LEFT);
		fd.top = new FormAttachment(btnClose, 0, SWT.TOP);
		btnModify.setLayoutData(fd);
		btnModify.addMouseListener(
			new MouseAdapter() {
				public void mouseUp(MouseEvent e) {
					// 如果处于消息设定面板,则修改消息设定
					if(composites[MESSAGE].isVisible()) {
						c.addProperty("message", messageOption);
						c.addProperty("message", messageOption);
						MessageBox box = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
						box.setText(LumaQQ.getResourceString("message.box.common.success.title"));
						box.setMessage(LumaQQ.getResourceString("message.box.cluster.message.option.modified"));
						box.open();
					} else
						modifyClusterInfo();
				}
			}
		);
	}	
	
	// 更新群的信息
	protected void updateClusterInfo() {
		ClusterInfo info = (ClusterInfo)c.getProperty("info");
		main.client.getClusterInfo(info.clusterId);
	}

	// 修改群的资料
	protected void modifyClusterInfo() {
		// 得到成员QQ号数组
		TableItem[] tis = table.getItems();
		int[] members = new int[tis.length];
		for(int i = 0; i < tis.length; i++) {
			FriendModel f = (FriendModel)tis[i].getData();
			members[i] = f.getQQ();
		}
		// 得到info对象
		ClusterInfo info = (ClusterInfo)c.getProperty("info");
		// 判断群类型,调用不同的函数
		if(c.isPermanent())
			main.client.modifyPermanentClusterInfo(info.clusterId, textName.getText(), textNotice.getText(), textDescription.getText(), members, comboCategory.getSelectionIndex(), authType);
		else
			main.client.modifyTemporaryClusterInfo(info.clusterId, textName.getText(), textNotice.getText(), textDescription.getText(), members, comboCategory.getSelectionIndex());
	}

	// 创建一个面板
	private Composite createPanel() {
		Composite comp = new Composite(shell, SWT.NONE);
		comp.setBackground(panelBackground);
		FormData fd = new FormData();
		fd.left = new FormAttachment(buttons[0], 5, SWT.RIGHT);
		fd.right = new FormAttachment(100, -5);
		fd.top = new FormAttachment(0, 5);
		fd.bottom = new FormAttachment(100, -36);
		comp.setLayoutData(fd);
		comp.setLayout(new FormLayout());
		return comp;
	}
	
	/**
	 * 初始化基本资料面板
	 */
	private void initBasicPanel() {
		Composite basic = createPanel();
		prevComposite = basic;
		composites[BASIC] = basic;
		// banner
		basicBanner = new Label(basic, SWT.NONE);

⌨️ 快捷键说明

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