📄 friendpropertylistener.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 org.eclipse.swt.graphics.Color;
import edu.tsinghua.lumaqq.models.ClusterModel;
import edu.tsinghua.lumaqq.models.FriendModel;
import edu.tsinghua.lumaqq.models.IQQNode;
import edu.tsinghua.lumaqq.ui.*;
import edu.tsinghua.lumaqq.ui.tool.HeadFactory;
import edu.tsinghua.lumaqq.utils.OptionUtil;
import edu.tsinghua.swt.events.PropertyEvent;
import edu.tsinghua.swt.events.PropertyListener;
import edu.tsinghua.swt.widgets.CoolButton;
/**
* 监视好友的属性,比如好友的状态改变了等等,做出相应的处理
*
* @author 马若劼
*/
public class FriendPropertyListener implements PropertyListener {
private MainShell main;
/**
* 构造函数
* @param main
*/
public FriendPropertyListener(MainShell main) {
this.main = main;
}
/* (non-Javadoc)
* @see edu.tsinghua.swt.events.PropertyListener#propertyAdded(edu.tsinghua.swt.events.PropertyEvent)
*/
public void propertyAdded(PropertyEvent e) {
// 没有什么要做的
}
/* (non-Javadoc)
* @see edu.tsinghua.swt.events.PropertyListener#propertyRemoved(edu.tsinghua.swt.events.PropertyEvent)
*/
public void propertyRemoved(PropertyEvent e) {
// 没有什么要做的
}
/* (non-Javadoc)
* @see edu.tsinghua.swt.events.PropertyListener#propertyModified(edu.tsinghua.swt.events.PropertyEvent)
*/
public void propertyModified(PropertyEvent e) {
/*
* 如果一个属性改变了,那么我们就要判断是不是上线状态改变了,如果是,需要设置不同的头像
* 注意这里的属性也可能是tab的属性,所有control可能为null,对于这种情况我们直接返回
*/
// 如果不是status属性变了,那我们不关心
if(e.key.equals(IQQNode.STATUS)) {
// 首先我们得到相关的ShutterLabel对象
FriendModel f = (FriendModel)e.getSource();
CoolButton control = main.getShutter().getItemControl(f);
if(control == null) return;
// 得到包含这个好友的组索引
int[] cor = main.getMVCHelper().getFriendCoordinate(f.getQQ());
// 如果打开了最近联系人功能,检查一下是否最近联系人中也有它的view part
// 目前最近联系人中的model只是好友组中model的引用,所以这就导致了一个
// model可能有两个view part,在考虑之后,我觉得这个不是太大的问题,所以
// 就没有改动shutter控件的结构
CoolButton latestControl = main.getMVCHelper().getLatestViewPart(f);
// 判断是否会员
boolean member = f.isMember();
// 设置头像
control.setImage(HeadFactory.getHeadByStatus(f));
if(latestControl != null)
latestControl.setImage(HeadFactory.getHeadByStatus(f));
// 开始判断状态
if(e.newValue.equals(IQQNode.VALUE_ONLINE)) {
if(member)
setNameColor(control, latestControl, main.getDisplay().getSystemColor(SWT.COLOR_RED));
else
setNameColor(control, latestControl, main.getDisplay().getSystemColor(SWT.COLOR_BLACK));
// 如果当前处于只显示在线好友模式,则显示这个好友的view part
if(OptionUtil.getInstance().isShowOnlineOnly()) {
int[] temp = main.getMVCHelper().getFriendCoordinate(f.getQQ());
if(temp != null && temp.length > 0) {
main.getShutter().showItem(temp[0], temp[1], true);
}
}
// 组在线好友数加1
if(e.oldValue.equals(IQQNode.VALUE_OFFLINE) && f.isOriginal()) {
if(cor != null && cor.length > 0)
main.increaseGroupOnlineUser(cor[0]);
}
} else if(e.newValue.equals(IQQNode.VALUE_AWAY)) {
setNameColor(control, latestControl, main.getDisplay().getSystemColor(SWT.COLOR_BLUE));
// 如果当前处于只显示在线好友模式,则显示这个好友的view part
if(OptionUtil.getInstance().isShowOnlineOnly()) {
if(cor != null && cor.length > 0)
main.getShutter().showItem(cor[0], cor[1], true);
}
// 组在线好友数加1
if(e.oldValue.equals(IQQNode.VALUE_OFFLINE) && f.isOriginal()) {
if(cor != null && cor.length > 0)
main.increaseGroupOnlineUser(cor[0]);
}
} else if(e.newValue.equals(IQQNode.VALUE_HIDDEN)) {
setNameColor(control, latestControl, main.getDisplay().getSystemColor(SWT.COLOR_GREEN));
// 如果当前处于只显示在线好友模式,则显示这个好友的view part
if(OptionUtil.getInstance().isShowOnlineOnly()) {
if(cor != null && cor.length > 0)
main.getShutter().showItem(cor[0], cor[1], true);
}
// 组在线好友数加1
if(e.oldValue.equals(IQQNode.VALUE_OFFLINE) && f.isOriginal()) {
if(cor != null && cor.length > 0)
main.increaseGroupOnlineUser(cor[0]);
}
} else {
setNameColor(control, latestControl, main.getDisplay().getSystemColor(SWT.COLOR_BLACK));
// 如果当前处于只显示在线好友模式,则要隐藏这个好友的view part
if(OptionUtil.getInstance().isShowOnlineOnly()) {
if(cor != null && cor.length > 0)
main.getShutter().hideItem(cor[0], cor[1], true);
}
// 组在线好友数减1
if(cor != null && cor.length > 0 && f.isOriginal())
main.decreaseGroupOnlineUser(cor[0]);
}
} else if(IQQNode.MESSAGE_COUNT.equals(e.key)) {
ClusterModel c = (ClusterModel)e.getSource();
if(!IQQNode.VALUE_SHOW_NUMBER.equals(c.getMessageOption()))
return;
CoolButton viewPart = main.getMVCHelper().getClusterViewPart(c.getClusterId());
if(viewPart == null)
return;
if(c.getMessageCount() == 0)
viewPart.setText(c.getName());
else
viewPart.setText("(" + c.getMessageCount() + ") - " + c.getName());
} else if(IQQNode.MESSAGE.equals(e.key)) {
ClusterModel c = (ClusterModel)e.getSource();
if(e.oldValue == IQQNode.VALUE_SHOW_NUMBER) {
CoolButton viewPart = main.getMVCHelper().getClusterViewPart(c.getClusterId());
if(viewPart == null)
return;
viewPart.setText(c.getName());
}
}
}
private void setNameColor(CoolButton control, CoolButton latestControl, Color color) {
control.setForeground(color);
if(latestControl != null)
latestControl.setForeground(color);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -