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

📄 clusterpage.java

📁 java写的qq代码实现qq的部分功能
💻 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.config.cluster;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Image;
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.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Text;

import edu.tsinghua.lumaqq.Colors;
import edu.tsinghua.lumaqq.IconHolder;
import edu.tsinghua.lumaqq.LumaQQ;
import edu.tsinghua.lumaqq.events.IFaceSelectionListener;
import edu.tsinghua.lumaqq.models.ClusterModel;
import edu.tsinghua.lumaqq.models.IQQNode;
import edu.tsinghua.lumaqq.qq.QQ;
import edu.tsinghua.lumaqq.qq.Util;
import edu.tsinghua.lumaqq.qq.beans.ClusterInfo;
import edu.tsinghua.lumaqq.ui.MainShell;
import edu.tsinghua.lumaqq.ui.config.AbstractPage;
import edu.tsinghua.lumaqq.ui.tool.AroundBorderPaintListener;
import edu.tsinghua.lumaqq.ui.tool.CenterBorderPaintListener;
import edu.tsinghua.lumaqq.ui.tool.UITool;
import edu.tsinghua.lumaqq.widgets.ClusterHeadImageProvider;
import edu.tsinghua.lumaqq.widgets.IImageProvider;
import edu.tsinghua.lumaqq.widgets.ImageSelector;

/**
 * 群基本资料页
 * 
 * @author luma
 */
public class ClusterPage extends AbstractPage implements IFaceSelectionListener {
    private Text textId, textCreator, textName, textNotice, textDescription;
    private CCombo comboCategory;
    private Group authGroup;
    private Button rdoNoAuth, rdoNeedAuth, rdoNoAdd;
    private CLabel lblFace;
    private Cursor handCursor;
    private ClusterModel model;
    private int faceId;
    private MainShell main;
    
    private static final int FACE = 0;
    
	/**
	 * @param parent
	 */
	public ClusterPage(Composite parent, MainShell main, ClusterModel model, int style) {
		super(parent, style);
		this.model = model;
		this.main = main;
	}
	
	/* (non-Javadoc)
     * @see edu.tsinghua.lumaqq.ui.config.AbstractPage#initialVariable()
     */
    protected void initialVariable() {
        handCursor = Display.getCurrent().getSystemCursor(SWT.CURSOR_HAND);
    }

	/* (non-Javadoc)
	 * @see edu.tsinghua.lumaqq.ui.config.AbstractPage#createContent(org.eclipse.swt.widgets.Composite)
	 */
	protected Control createContent(Composite parent) {
        Composite content = new Composite(parent, SWT.NONE);
        content.setBackground(Colors.PAGE_BACKGROUND);
        GridLayout layout = new GridLayout(4, false);
        layout.marginWidth = 15;
        layout.marginHeight = 8;
        content.setLayout(layout);
        content.addPaintListener(new CenterBorderPaintListener(new Class[] { Text.class, CCombo.class }, 18, Colors.PAGE_CONTROL_BORDER));
        content.addPaintListener(new AroundBorderPaintListener(new Class[] { CLabel.class }, Colors.PAGE_CONTROL_BORDER));
        
        // 设置使用缺省背景色
        UITool.setDefaultBackground(null);
        
        // 号码
        UITool.createLabel(content, LumaQQ.getString("cluster.info.basic.id"));
        GridData gd = new GridData();
        gd.widthHint = 120;
        textId = UITool.createSingleText(content, gd, SWT.SINGLE | SWT.READ_ONLY);        
        textId.setBackground(Colors.PAGE_READONLY_CONTROL_BACKGROUND);
        // 头像
        lblFace = new CLabel(content, SWT.CENTER);
        gd = new GridData(GridData.HORIZONTAL_ALIGN_CENTER | GridData.VERTICAL_ALIGN_BEGINNING);
        gd.heightHint = gd.widthHint = 40;
        gd.horizontalSpan = 2;
        gd.verticalSpan = 2;
        gd.horizontalIndent = 12;
        lblFace.setLayoutData(gd);
        lblFace.setCursor(handCursor);
        lblFace.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				Rectangle bound = lblFace.getBounds();
				openImageSelectionShell(lblFace.getParent().toDisplay(bound.x, bound.y + bound.height + 1));											
			}
		});
        // 创建人
        UITool.createLabel(content, LumaQQ.getString("cluster.info.basic.creator"));
        gd = new GridData();
        gd.widthHint = 120;
        textCreator = UITool.createSingleText(content, gd, SWT.SINGLE | SWT.READ_ONLY);
        textCreator.setBackground(Colors.PAGE_READONLY_CONTROL_BACKGROUND);
        // 名称
        UITool.createLabel(content, LumaQQ.getString("cluster.info.basic.name"));
        gd = new GridData();
        gd.widthHint = 120;        
        textName = UITool.createSingleText(content, gd, (style == ClusterInfoWindow.READ_ONLY) ? (SWT.READ_ONLY | SWT.SINGLE) : SWT.SINGLE);
        // 分类
        gd = new GridData();
        gd.horizontalIndent = 12;
        UITool.createLabel(content, LumaQQ.getString("cluster.info.basic.category"), gd);
        comboCategory = UITool.createCCombo(content, new GridData(GridData.FILL_HORIZONTAL));
        addCategory();
        // 群内公告
        gd = new GridData();
        gd.horizontalSpan = 4;
        UITool.createLabel(content, LumaQQ.getString("cluster.info.basic.notice"), gd);
        gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.horizontalSpan = 4;
        gd.heightHint = 40;
        textNotice = UITool.createMultiText(content, gd, (style == ClusterInfoWindow.READ_ONLY) ? (SWT.READ_ONLY | SWT.MULTI | SWT.WRAP) : (SWT.MULTI | SWT.WRAP));
        // 群的简介
        gd = new GridData();
        gd.horizontalSpan = 4;
        UITool.createLabel(content, LumaQQ.getString("cluster.info.basic.description"), gd);
        gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.horizontalSpan = 4;
        gd.heightHint = 40;
        textDescription = UITool.createMultiText(content, gd, (style == ClusterInfoWindow.READ_ONLY) ? (SWT.READ_ONLY | SWT.MULTI | SWT.WRAP) : (SWT.MULTI | SWT.WRAP));
        // 验证组
        gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.horizontalSpan = 4;
        authGroup = UITool.createGroup(content, LumaQQ.getString("cluster.info.basic.auth"), gd, new GridLayout());
        rdoNoAuth = UITool.createRadio(authGroup, LumaQQ.getString("cluster.info.basic.no.auth"));
        rdoNeedAuth = UITool.createRadio(authGroup, LumaQQ.getString("cluster.info.basic.need.auth"));
        rdoNoAdd = UITool.createRadio(authGroup, LumaQQ.getString("cluster.info.basic.no.add"));
        
        return content;
	}

    /**
     * 添加分类
     */
    private void addCategory() {
        int count = Util.getInt(LumaQQ.getString("permanent.category.number"), 0);
        for(int i = 1; i <= count; i++)
            comboCategory.add(LumaQQ.getString("permanent.category." + i));
        comboCategory.select(0);
    }
    
	/* (non-Javadoc)
	 * @see edu.tsinghua.lumaqq.ui.config.AbstractPage#saveDirtyProperty(int)
	 */
	protected void saveDirtyProperty(int propertyId) {
	    switch(propertyId) {
	        case FACE:
	            model.addProperty(IQQNode.HEAD, new Integer(faceId));
	            model.addProperty(IQQNode.IMAGE, IconHolder.getInstance().getClusterHead(faceId));
	            break;
	    }
	}

	/* (non-Javadoc)
	 * @see edu.tsinghua.lumaqq.ui.config.AbstractPage#initializeValues()
	 */
	protected void initializeValues() {
	    setOtherInfo();
	    setClusterFace();
	    disableControls();
	}
	
	/**
	 * 设置控件使能状态,如果是临时群或者只读方式,禁止修改
	 */
	private void disableControls() {
	    boolean disable = !model.isPermanent() || style == ClusterInfoWindow.READ_ONLY;	    
	    if(disable) {
		    textName.setBackground(Colors.PAGE_READONLY_CONTROL_BACKGROUND);
		    textNotice.setBackground(Colors.PAGE_READONLY_CONTROL_BACKGROUND);
		    textDescription.setBackground(Colors.PAGE_READONLY_CONTROL_BACKGROUND);	 
		    comboCategory.setEnabled(false);
		    comboCategory.setBackground(Colors.PAGE_READONLY_CONTROL_BACKGROUND);
		    authGroup.setEnabled(false);
		    rdoNeedAuth.setEnabled(false);
		    rdoNoAdd.setEnabled(false);
		    rdoNoAuth.setEnabled(false);
	    } else {
		    textName.setBackground(Colors.WHITE);
		    textNotice.setBackground(Colors.WHITE);
		    textDescription.setBackground(Colors.WHITE);	
	    }
	}
	
	/* (non-Javadoc)
     * @see edu.tsinghua.lumaqq.ui.config.AbstractPage#refreshValues()
     */
    public void refreshValues() {
        setOtherInfo();
    }
	
	/**
	 * 设置其他信息
	 */
	private void setOtherInfo() {
	    if(model.isPermanent())
	        textId.setText(String.valueOf(model.getExternalId()));
	    else
	        textId.setText(String.valueOf(model.getClusterId()));
	    textCreator.setText(String.valueOf(model.getCreator()));
	    textName.setText(model.getName());
        faceId = model.getFaceId();
	    ClusterInfo info = model.getClusterInfo();
	    if(info != null) {
	        comboCategory.select(info.category);
	        textNotice.setText(info.notice);
	        textDescription.setText(info.description);
	        switch(info.authType) {
	            case QQ.QQ_CLUSTER_NO_AUTH:
	                rdoNoAuth.setSelection(true);
	            	break;
	            case QQ.QQ_CLUSTER_NEED_AUTH:
	                rdoNeedAuth.setSelection(true);
	            	break;
	            case QQ.QQ_CLUSTER_NO_ADD:
	                rdoNoAdd.setSelection(true);
	            	break;
	        }
	    }
	}
	
	/**
	 * 设置群头像
	 */
	private void setClusterFace() {
        lblFace.setImage(model.getImage());
	}

	/* (non-Javadoc)
	 * @see edu.tsinghua.lumaqq.ui.config.AbstractPage#getImage()
	 */
	protected Image getImage() {
        return IconHolder.getInstance().getImage(IconHolder.icoViewPersonInfo24);
	}

	/* (non-Javadoc)
	 * @see edu.tsinghua.lumaqq.ui.config.AbstractPage#getTitle()
	 */
	protected String getTitle(int page) {
		return LumaQQ.getString("cluster.info.page.basic");
	}
	
	/**
	 * @return
	 * 		验证类型常量
	 */
	private byte getAuthType() {
	    if(rdoNoAuth.getSelection())
	        return QQ.QQ_CLUSTER_NO_AUTH;
	    else if(rdoNoAdd.getSelection())
	        return QQ.QQ_CLUSTER_NO_ADD;
	    else
	        return QQ.QQ_CLUSTER_NEED_AUTH;	        
	}
	
	/**
	 * 发送修改群信息请求包
	 * 
	 * @return
	 * 		包序号
	 */
	public char doModifyClusterInfo() {
	    return main.getClient().modifyClusterInfo(model.getClusterId(),
	            textName.getText(),
	            textNotice.getText(),
	            textDescription.getText(),
	            comboCategory.getSelectionIndex(),
	            getAuthType());
	}
	
    
    /**
     * 打开图片选择窗口
     */
    private void openImageSelectionShell(Point loc) {
    	ImageSelector fss = new ImageSelector(parentShell, new ClusterHeadImageProvider());
    	fss.setListener(this);
		fss.setLocation(loc);
		fss.open();	
    }

    /* (non-Javadoc)
     * @see edu.tsinghua.lumaqq.events.IFaceSelectionListener#faceSelected(edu.tsinghua.lumaqq.ui.IImageProvider, int, int)
     */
    public void faceSelected(IImageProvider provider, int group, int sequence) {
        int code = provider.getImageCode(group, sequence);
        if(code != -1) {
            faceId = code;
	        lblFace.setImage(provider.getImage(group, sequence));
	        makeDirty(FACE);
        }
    }
}

⌨️ 快捷键说明

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