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

📄 lumaqqmodellistener.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.events;

import org.eclipse.swt.SWT;

import edu.tsinghua.lumaqq.models.ClusterModel;
import edu.tsinghua.lumaqq.models.FriendModel;
import edu.tsinghua.lumaqq.ui.MainShell;
import edu.tsinghua.lumaqq.ui.tool.HeadFactory;
import edu.tsinghua.swt.events.ModelEvent;
import edu.tsinghua.swt.events.ShutterModelEvent;
import edu.tsinghua.swt.events.ShutterModelListener;
import edu.tsinghua.swt.models.INode;
import edu.tsinghua.swt.widgets.CoolButton;

/**
 * model的事件监听器
 * 在添加了一个好友时,根据好友的属性设置view part的状态,比如会员用红字显示
 * 
 * @author 马若劼
 */
public class LumaQQModelListener implements ShutterModelListener {
	private MainShell main;
	
	/**
	 * 构造函数
	 * @param main
	 */
	public LumaQQModelListener(MainShell main) {
		this.main = main;
	}
	
	/* (non-Javadoc)
	 * @see edu.tsinghua.swt.events.ShutterModelListener#itemAdded(edu.tsinghua.swt.events.ShutterModelEvent)
	 */
	public void itemAdded(ShutterModelEvent e) {
		// 判断当前的model是否是ClusterModel,对于新添加的组,没有太多需要做的工作
		INode node = main.getModel().getItem(e.tabIndex, e.itemIndex);
		if(node instanceof ClusterModel) {
			ClusterModel c = (ClusterModel)node;
			CoolButton control = main.getShutter().getItemControl(e.tabIndex, e.itemIndex);			
			if(c.isPermanent())
				control.setForeground(main.getDisplay().getSystemColor(SWT.COLOR_RED));
		} else {
			// 如果不是ClusterModel,那肯定是FriendModel,继续
			FriendModel f = (FriendModel)node;
			CoolButton control = main.getShutter().getItemControl(e.tabIndex, e.itemIndex);
			if(control == null) return;
			// 判断是否会员
			boolean member = f.isMember();
			// 设置头像
			control.setImage(HeadFactory.getHeadByStatus(f));
			// 开始判断在线状态,是会员的颜色设成红的,等等
			if(f.isOnline()) {
				if(member)
					control.setForeground(main.getDisplay().getSystemColor(SWT.COLOR_RED));
			} else if(f.isAway()) {
				control.setForeground(main.getDisplay().getSystemColor(SWT.COLOR_BLUE));
			} else if(f.isHidden()) {
			    control.setForeground(main.getDisplay().getSystemColor(SWT.COLOR_GREEN));
			} else {
				if(member)
					control.setForeground(main.getDisplay().getSystemColor(SWT.COLOR_BLACK));
			}			
			
			// 如果这个好友是上线的,则上线好友数加1
			if(!f.isOffline())
			    main.increaseGroupOnlineUser(e.tabIndex);
		}
		
		// 总数加1
		main.increaseGroupUsers(e.tabIndex);
	}
	
	/* (non-Javadoc)
	 * @see edu.tsinghua.swt.events.ShutterModelListener#itemRemoved(edu.tsinghua.swt.events.ShutterModelEvent)
	 */
	public void itemRemoved(ShutterModelEvent e) {
	    main.decreaseGroupUser(e.tabIndex);
	    
	    INode node = e.getItem();
	    if(node instanceof FriendModel) {
	        FriendModel f = (FriendModel)node;
	        if(!f.isOffline())
	            main.decreaseGroupOnlineUser(e.tabIndex);
	    }
	}
	
	/* (non-Javadoc)
	 * @see edu.tsinghua.swt.events.ModelListener#modelAdded(edu.tsinghua.swt.events.ModelEvent)
	 */
	public void modelAdded(ModelEvent e) {
	    ShutterModelEvent event = (ShutterModelEvent)e;
	    main.setGroupOnlineUser(event.tabIndex, 0);
	}
	
	/* (non-Javadoc)
	 * @see edu.tsinghua.swt.events.ModelListener#modelRemoved(edu.tsinghua.swt.events.ModelEvent)
	 */
	public void modelRemoved(ModelEvent e) {
	    // 没有什么要做的
	}
}

⌨️ 快捷键说明

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