📄 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
* hasMessage: 当前是否有未读消息存在,为true或者false
* ip:是ip地址,byte[]类型
* port: 端口号
* loginTime: 登陆时间
* talkMode: 当前是否是聊天模式,true或者false
* locationX: 好友消息窗口的X坐标,Integer类型,为-1表示使用缺省值
* locationY: 好友消息窗口的Y坐标,Integer类型,为-1表示使用缺省值
* temp: 临时属性,可以放任何东西,目前用在了消息提示中,在其他情况下,这个属性保留给程序员内部使用
* originalModel: 临时属性,如果一个model A是从model B克隆的,那么B就是originalModel
* original: 临时属性,为true或者false,用在最近联系人组中,用来表示最近联系人中的model不是原生
* model。在查找model时,会比较这个属性以区分好友model和最近联系人model
*
* 以下属性只在组是一个群组时才会存在
* parent: 表示了这个friend model的父model,为ClusterModel类型,目前还没有用到这个属性
* </pre>
*
* @author 马若劼
*/
public class FriendModel extends AbstractNode implements IQQNode {
/**
* 构造函数
* @param qq
*/
public FriendModel(Integer qq) {
super();
addProperty(NAME, qq.toString());
addProperty(NICK, qq.toString());
addProperty(QQ_NUMBER, qq);
}
/**
* @param qq
*/
public FriendModel(int qq) {
super();
addProperty(NAME, String.valueOf(qq));
addProperty(NICK, String.valueOf(qq));
addProperty(QQ_NUMBER, new Integer(qq));
}
/**
* @param qq
*/
public FriendModel(String qq) {
super();
addProperty(NAME, qq);
addProperty(NICK, qq);
addProperty(QQ_NUMBER, new Integer(qq));
}
/**
* 构造函数
*/
public FriendModel(String name, Image image) {
super();
if(name == null)
name = "";
addProperty(NAME, name);
addProperty(NICK, name);
addProperty(IMAGE, image);
addProperty(QQ_NUMBER, 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 ((FriendModel)obj).getQQ() == getQQ();
else if(obj instanceof Integer)
return ((Integer)obj).intValue() == getQQ();
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 getHeadId() {
if(hasProperty(HEAD))
return ((Integer)getProperty(HEAD)).intValue();
else
return 0;
}
/**
* @return
* 昵称
*/
public String getNick() {
if(hasProperty(NICK))
return (String)getProperty(NICK);
else
return "";
}
/**
* @return
* 备注名称
*/
public String getRealName() {
if(hasProperty(REAL_NAME))
return (String)getProperty(REAL_NAME);
else
return "";
}
/**
* @return 用户的QQ号
*/
public int getQQ() {
return ((Integer)getProperty(QQ_NUMBER)).intValue();
}
/**
* @return true表示正处于聊天模式
*/
public boolean isTalkMode() {
if(hasProperty(TALK_MODE))
return "true".equals(getProperty(TALK_MODE));
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(LOCATION_X))
return ((Integer)getProperty(LOCATION_X)).intValue();
else
return -1;
}
/**
* @return 发送消息框的Y位置
*/
public int getLocationY() {
if(hasProperty(LOCATION_Y))
return ((Integer)getProperty(LOCATION_Y)).intValue();
else
return -1;
}
/**
* @return 是否原生model,如果不存在这个属性,返回true,如果存在,返回比较结果
*/
public boolean isOriginal() {
if(hasProperty(ORIGINAL))
return "true".equals(getProperty(ORIGINAL));
else
return true;
}
/**
* @return true表示这个好友有未读消息
*/
public boolean hasMessage() {
if(hasProperty(HAS_MESSAGE))
return "true".equals(getProperty(HAS_MESSAGE));
else
return false;
}
/**
* @return
* true表示好友目前在线
*/
public boolean isOnline() {
if(hasProperty(STATUS))
return VALUE_ONLINE.equals(getProperty(STATUS));
else
return false;
}
/**
* @return
* 是否离开
*/
public boolean isAway() {
if(hasProperty(STATUS))
return VALUE_AWAY.equals(getProperty(STATUS));
else
return false;
}
/**
* @return
* 是否隐身
*/
public boolean isHidden() {
if(hasProperty(STATUS))
return VALUE_HIDDEN.equals(getProperty(STATUS));
else
return false;
}
/**
* @return
* 是否离线
*/
public boolean isOffline() {
if(hasProperty(STATUS))
return VALUE_OFFLINE.equals(getProperty(STATUS));
else
return true;
}
/**
* @return
* 好友名称
*/
public String getName() {
if(hasProperty(NAME))
return (String)getProperty(NAME);
else
return "";
}
/**
* @return
* 好友状态字符串
*/
public String getStatus() {
if(hasProperty(STATUS))
return (String)getProperty(STATUS);
else
return IQQNode.VALUE_OFFLINE;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -