📄 groupdroptargetlistener.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.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DropTarget;
import org.eclipse.swt.dnd.DropTargetAdapter;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.widgets.MessageBox;
import edu.tsinghua.lumaqq.LumaQQ;
import edu.tsinghua.lumaqq.models.FriendModel;
import edu.tsinghua.lumaqq.models.GroupModel;
import edu.tsinghua.lumaqq.ui.MainShell;
import edu.tsinghua.lumaqq.ui.ReceiveSystemMessageShell;
import edu.tsinghua.swt.models.INode;
import edu.tsinghua.swt.widgets.CoolButton;
/**
* 好友拖放到组上面的处理器,基本原则是如果目标组的friendly属性是false,则删除这个好友
* 如果blacklist属性是true,则还要把自己从对方的好友中删除,如果以上皆非,简单的移动
* 好友到这个目的组。那么如果源组的friendly为false,而目的组的friendly为true,那就是
* 添加一个好友
*
* @author 马若劼
*/
public class GroupDropTargetListener extends DropTargetAdapter {
// Log对象
private static Log log = LogFactory.getLog(GroupDropTargetListener.class);
private MainShell main;
/**
* 构造函数
* @param main
*/
public GroupDropTargetListener(MainShell main) {
this.main = main;
}
/* (non-Javadoc)
* @see org.eclipse.swt.dnd.DropTargetListener#drop(org.eclipse.swt.dnd.DropTargetEvent)
*/
public void drop(DropTargetEvent e) {
// 得到目的组索引
CoolButton destViewPart = (CoolButton)((DropTarget)e.getSource()).getControl();
int destIndex = main.getShutter().indexOf(destViewPart);
// 得到目的组的model
GroupModel destModel = (GroupModel)main.getModel().getTab(destIndex);
// 如果目的组是最近联系人,返回
if(LumaQQ.getString("group.default.latest").equals(destModel.getProperty(INode.NAME)))
return;
// 判断目的组是否是群组,如果是,返回,因为不允许对群组做拖放操作
if(destModel.isCluster()) return;
// 得到拖动源的QQ号
int qqNum = new Integer((String)e.data).intValue();
// 得到被拖动的好友的组索引和组内索引
int[] indices = main.getMVCHelper().getFriendCoordinate(qqNum);
// 得到好友model
FriendModel f = main.getMVCHelper().getFriendModel(qqNum);
// 比较源组和目的组是否一样,一样则返回
if(indices[0] == destIndex) return;
// 得到源组的model
GroupModel srcModel = (GroupModel)main.getModel().getTab(indices[0]);
// 判断组属性,做出相应操作
boolean srcBlacklist = srcModel.isBlackList();
boolean srcFriendly = srcModel.isFriendly();
boolean destFriendly = destModel.isFriendly();
boolean destBlacklist = destModel.isBlackList();
if(srcFriendly == destFriendly && !srcBlacklist) {
/* 源与目的皆为好友组或皆非好友组,简单移动 */
// 如果目的组是黑名单组,把自己从对方那里删除
if(destBlacklist)
remove(destBlacklist, f, qqNum, destModel);
// 移动好友
main.getMVCHelper().moveFriend(indices[0], indices[1], destIndex, f);
// 如果是在好友组中简单移动,则刷新服务器端分组信息
// 这个功能不再使用,因为LumaQQ会允许不自动更新分组信息,所以,这里搞成自动的会带来问题
/*
if(srcFriendly)
main.getClient().addFriendToList(destIndex, f.getQQ());*/
} else if(srcFriendly && !destFriendly) {
/* 源是好友组,目的不是,删除该好友 */
remove(destBlacklist, f, qqNum, destModel);
} else if(!srcFriendly && destFriendly) {
/* 源不是好友组,目的是,添加该好友 */
main.getShellLauncher().openAddReceiveSystemMessageShell(f);
main.getMVCHelper().addFriend(qqNum, destModel);
}
// 调整动画状态,因为可能在拖动的时候好友有消息,这个时候是有动画效果的,要注意这种情况
main.getUIHelper().adjustAnimateAfterDrag(qqNum, indices[0], destIndex, f);
}
private void remove(boolean destBlacklist, FriendModel f, int qqNum, GroupModel destModel) {
MessageBox box = new MessageBox(main.getShell(), SWT.ICON_WARNING | SWT.YES | SWT.NO);
box.setText(LumaQQ.getString("message.box.common.waring.title"));
if(destBlacklist)
box.setMessage(LumaQQ.getString("hint.delete.friend.and.remove.self", new Object[] { String.valueOf(qqNum) }));
else
box.setMessage(LumaQQ.getString("hint.delete.friend", new Object[] { String.valueOf(qqNum) }));
if(box.open() == SWT.YES) {
ReceiveSystemMessageShell rsms = new ReceiveSystemMessageShell(main);
rsms.setFriendModel(f);
rsms.open(ReceiveSystemMessageShell.DELETE_MODE);
main.deleteFriendFromServer(qqNum, true, destBlacklist, destModel);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -