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

📄 clustermodel.java

📁 类似于MSN
💻 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.models;

import java.util.Hashtable;
import java.util.Iterator;

import org.eclipse.swt.graphics.Image;

import edu.tsinghua.lumaqq.qq.beans.ClusterInfo;
import edu.tsinghua.swt.models.AbstractNode;

/**
 * <pre>
 * 一个群的model对象,集成自AbstractGeneralNode,具有以下属性
 * clusterId: 群的号码,Integer类型
 * name: 群的名称
 * image: 群的头像,这个是本地头像,为了好看我自己加上的
 * face: 头像的代码,目前随便提供了18个头像,从1到18,Integer类型
 * info: ClusterInfo对象
 * permanent: 群的类型,固定还是临时,为true或者false
 * message: 对待消息的方式,可以是accept, eject, record, block
 *          accept = 接收并提示消息
 *          eject = 自动弹出消息
 *          record = 接收但不提示(只保存在聊天记录中)
 *          block = 阻止一切该群的消息
 * members: 群的成员列表,为Hashtable类型,其中的元素类型为FriendModel
 * temp: 临时属性,可以放任何东西,目前用在了消息提示中,这个属性保留给程序员内部使用
 * </pre>
 * 
 * @author 马若劼
 */
public class ClusterModel extends AbstractNode {
    /**
     * 私有构造函数
     */
    private ClusterModel() {        
        // 没有什么要做的
    }
    
	/**
	 * 构造函数,群名称将会设成群ID的字符串形式
	 * @param clusterId 群ID
	 */
	public ClusterModel(int clusterId) {
		this(new Integer(clusterId), String.valueOf(clusterId));
	}
	
	/**
	 * 构造函数
	 * @param clusterId 群ID
	 * @param name 群名称
	 */
	public ClusterModel(int clusterId, String name) {
		this(new Integer(clusterId), name);
	}
	
	/**
	 * 构造函数
	 * @param clusterId 群ID
	 * @param name 群名称
	 */
	public ClusterModel(Integer clusterId, String name) {
		super();
		addProperty("clusterId", clusterId);
		addProperty("name", name);
		addProperty("permanent", "true");
		addProperty("message", "accept");
		addProperty("members", new Hashtable());
	}
		
	/**
	 * 复制所有properties到一个新创建的FriendModel中
	 */
	public ClusterModel cloneProperties() {
		ClusterModel c = new ClusterModel();
		Iterator iter = properties.keySet().iterator();
		while(iter.hasNext()) {
			String key = (String)iter.next();
			c.addProperty(key, properties.get(key));
		}
		return c;
	}
	
	/**
	 * 构造函数
	 * @param clusterId 群ID
	 * @param name 群名称
	 * @param image 群头像
	 */
	public ClusterModel(Integer clusterId, String name, Image image) {
		super();
		addProperty("clusterId", clusterId);
		addProperty("name", name);
		addProperty("image", image);
		addProperty("permanent", "true");
		addProperty("message", "accept");
		addProperty("members", new Hashtable());
	}	
	
	/**
	 * 构造函数
	 * @param clusterId 群ID
	 * @param name 群名称
	 * @param image 群头像
	 */
	public ClusterModel(String clusterId, String name, Image image) {
		this(new Integer(clusterId), name, image);
	}
	
	/**
	 * 构造函数
	 * @param clusterId 群ID
	 * @param name 群名称
	 * @param image 群头像
	 */
	public ClusterModel(int clusterId, String name, Image image) {
		this(new Integer(clusterId), name, image);
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	public boolean equals(Object obj) {
		if(obj instanceof ClusterModel)
			return ((Integer)getProperty("clusterId")).equals(((ClusterModel)obj).getProperty("clusterId"));
		else if(obj instanceof Integer)
			return ((Integer)getProperty("qq")).equals(((FriendModel)obj).getProperty("qq"));
		else
			return false;
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return ((Integer)getProperty("clusterId")).intValue();
	}
	
	/**
	 * @return true表示其是一个固定群
	 */
	public boolean isPermanent() {
		return "true".equals(getProperty("permanent"));
	}
	
	/**
	 * 添加一个成员
	 * @param f
	 */
	public void addMember(FriendModel f) {
		Hashtable hash = (Hashtable)getProperty("members");
		hash.put(f, f);
	}
	
	/**
	 * 得到成员的model
	 * @param qqNum 成员的QQ号
	 * @return 成员的model,没有这个成员则返回null
	 */
	public FriendModel getMember(int qqNum) {
		Hashtable hash = (Hashtable)getProperty("members");
	    return (FriendModel)hash.get(new Integer(qqNum));
	}
	
	/**
	 * 除去一个成员
	 * @param f
	 * @return
	 */
	public FriendModel removeMember(FriendModel f) {
		Hashtable hash = (Hashtable)getProperty("members");
		return (FriendModel)hash.remove(f);
	}
	
	/**
	 * 除去一个成员
	 * @param qqNum
	 * @return
	 */
	public FriendModel removeMember(Integer qqNum) {
		Hashtable hash = (Hashtable)getProperty("members");
		return (FriendModel)hash.remove(qqNum);
	}
	
	/**
	 * 除去一个成员
	 * @param qqNum
	 * @return
	 */
	public FriendModel removeMember(int qqNum) {
		return removeMember(new Integer(qqNum));
	}
	
	/**
	 * 设置群的创建者QQ号
	 * @param qqNum
	 */
	public void setCreator(int qqNum) {
		ClusterInfo info = (ClusterInfo)getProperty("info");
		info.creator = qqNum;
	}
	
	/**
	 * 得到创建者的QQ号
	 * @return 创建者的QQ号
	 */
	public int getCreator() {
		if(hasProperty("info")) {				
			ClusterInfo info = (ClusterInfo)getProperty("info");
			return info.creator;			
		} else
			return -1;
	}
	
	/**
	 * @return 头像ID,如果没有,返回一个缺省值
	 */
	public int getFaceId() {
		if(hasProperty("face"))
			return ((Integer)getProperty("face")).intValue();
		else
			return 1;
	}
	
	/**
	 * @return 群的内部ID
	 */
	public int getClusterId() {
		return ((Integer)getProperty("clusterId")).intValue();
	}
	
	/**
	 * @return 群的头像
	 */
	public Image getImage() {
		return hasProperty("image") ? ((Image)getProperty("image")) : null;
	}
	
	/**
	 * @return 群的内部ID
	 */
	public int getExternalId() {
		if(hasProperty("info"))
			return ((ClusterInfo)getProperty("info")).externalId;
		else
			return 0;
	}
}

⌨️ 快捷键说明

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