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

📄 clustermessageformatter.java

📁 用java实现的
💻 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.widgets;

import java.text.DateFormat;
import java.util.Date;
import java.util.Hashtable;

import edu.tsinghua.lumaqq.MessageEntry;
import edu.tsinghua.lumaqq.models.ClusterModel;
import edu.tsinghua.lumaqq.models.FriendModel;

/**
 * <pre>
 * 群消息的格式化器
 * </pre>
 * 
 * @author 马若劼
 */
public class ClusterMessageFormatter implements IRecordFormatter {
	private Date date;
	private DateFormat shortDateFormat;
	private ClusterModel c;
	
	/**
	 * 构造函数
	 */
	public ClusterMessageFormatter(ClusterModel c) {
		date = new Date();
		shortDateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);	
		this.c = c;
	}
	
	/* (non-Javadoc)
	 * @see edu.tsinghua.lumaqq.IRecordFormatter#format(edu.tsinghua.lumaqq.MessageEntry)
	 */
	public String[] format(MessageEntry me) {
		// 得到成员哈希表
		Hashtable members = (Hashtable)c.getProperty("members");
		// 创建要返回的字符串数组
		String[] ret = new String[3];
		// 得到发送者model
		FriendModel f = (FriendModel)members.get(new Integer(me.getSender()));
		// 设置发送者昵称
		ret[0] = (f == null) ? String.valueOf(me.getSender()) : ((String)f.getProperty("name"));
		// 设置收到时间
		date.setTime((long)me.getTime() * 1000L);
		ret[1] = shortDateFormat.format(date);
		// 设置消息内容
		ret[2] = me.getMessage();
		// 返回
		return ret;
	}

	/* (non-Javadoc)
	 * @see edu.tsinghua.lumaqq.IRecordFormatter#copy(edu.tsinghua.lumaqq.MessageEntry)
	 */
	public String copy(MessageEntry me) {
		return me.getMessage();
	}
}

⌨️ 快捷键说明

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