📄 friendmodel.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.Iterator;
import org.eclipse.swt.graphics.Image;
import edu.tsinghua.swt.models.AbstractNode;
/**
* <pre>
* 代表一个好友,扩展自AbstractGeneralNode,位于Group之下的元素
* 好友有一下属性
* qq: qq号,Integer类型
* name: 显示名,这个名称可能是昵称,也可能是备注中的真实姓名,name和image
* 是Shutter组件的两个缺省属性,那么用于显示名称,image用于显示图像
* nick: 好友昵称
* realName: 真实姓名
* image: 好友头像,Image类型
* face: 好友头像序号,Integer类型
* contact: ContactInfo类,包含了好友的通讯信息
* member: 是否是QQ会员,true或者false
* status: 在线状态,online,offline,away,或者hidden
* ip:是ip地址,byte[]类型
* port: 端口号
* loginTime: 登陆时间
* talkMode: 当前是否是聊天模式,true或者false
* locationX: 好友消息窗口的X坐标,Integer类型,为-1表示使用缺省值
* locationY: 好友消息窗口的Y坐标,Integer类型,为-1表示使用缺省值
* temp: 临时属性,可以放任何东西,目前用在了消息提示中,在其他情况下,这个属性保留给程序员内部使用
*
* 以下属性只在组是一个群组时才会存在
* parent: 表示了这个friend model的父model,为ClusterModel类型,目前还没有用到这个属性
* </pre>
*
* @author 马若劼
*/
public class FriendModel extends AbstractNode {
/**
* 构造函数
* @param qq
*/
public FriendModel(Integer qq) {
super();
addProperty("name", qq.toString());
addProperty("nick", qq.toString());
addProperty("qq", qq);
}
/**
* @param qq
*/
public FriendModel(int qq) {
super();
addProperty("name", String.valueOf(qq));
addProperty("nick", String.valueOf(qq));
addProperty("qq", new Integer(qq));
}
/**
* @param qq
*/
public FriendModel(String qq) {
super();
addProperty("name", qq);
addProperty("nick", qq);
addProperty("qq", new Integer(qq));
}
/**
* 构造函数
*/
public FriendModel(String name, Image image) {
super();
addProperty("name", name);
addProperty("nick", name);
addProperty("image", image);
addProperty("qq", new Integer(-1));
}
/**
* 私有构造函数,用于克隆中
*/
private FriendModel() {
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
if(obj instanceof FriendModel)
return ((Integer)getProperty("qq")).equals(((FriendModel)obj).getProperty("qq"));
else if(obj instanceof Integer)
return ((Integer)getProperty("qq")).equals(obj);
else
return false;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return getQQ();
}
/**
* 复制所有properties到一个新创建的FriendModel中
*/
public FriendModel cloneProperties() {
FriendModel f = new FriendModel();
Iterator iter = properties.keySet().iterator();
while(iter.hasNext()) {
String key = (String)iter.next();
f.addProperty(key, properties.get(key));
}
return f;
}
/**
* @return 头像ID,如果没有,返回一个缺省值
*/
public int getFaceId() {
if(hasProperty("face"))
return ((Integer)getProperty("face")).intValue();
else
return 0;
}
/**
* @return 用户的QQ号
*/
public int getQQ() {
return ((Integer)getProperty("qq")).intValue();
}
/**
* @return true表示正处于聊天模式
*/
public boolean isTalkMode() {
if(hasProperty("talkMode"))
return "true".equals(getProperty("talkMode"));
else
return false;
}
/**
* @return true表示是会员
*/
public boolean isMember() {
if(hasProperty("member"))
return "true".equals(getProperty("member"));
else
return false;
}
/**
* @return 发送消息框的X位置
*/
public int getLocationX() {
if(hasProperty("locationX"))
return ((Integer)getProperty("locationX")).intValue();
else
return -1;
}
/**
* @return 发送消息框的Y位置
*/
public int getLocationY() {
if(hasProperty("locationY"))
return ((Integer)getProperty("locationY")).intValue();
else
return -1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -