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

📄 groupdroptargetlistener.java

📁 类似于MSN
💻 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.shells.MainShell;
import edu.tsinghua.lumaqq.shells.ReceiveSystemMessageShell;
import edu.tsinghua.swt.widgets.ShutterLabel;

/**
 * 好友拖放到组上面的处理器,基本原则是如果目标组的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) {
		// 得到目的组索引
		ShutterLabel destViewPart = (ShutterLabel)((DropTarget)e.getSource()).getControl();
		int destIndex = main.shutter.indexOf(destViewPart);
		// 得到目的组的model
		GroupModel destModel = (GroupModel)main.model.getTab(destIndex);
		// 判断目的组是否是群组,如果是,返回,因为不允许对群组做拖放操作
		if(destModel.isCluster()) return;
		// 得到拖动源的QQ号
		int qqNum = new Integer((String)e.data).intValue();
		// 得到被拖动的好友的组索引和组内索引
		int[] indices = main.getFriendCoordinate(qqNum);
		// 得到好友model
		FriendModel f = main.getFriendModel(qqNum);
		// 比较源组和目的组是否一样,一样则返回
		if(indices[0] == destIndex) return;
		// 得到源组的model
		GroupModel srcModel = (GroupModel)main.model.getTab(indices[0]);
		// 判断组属性,做出相应操作
		boolean srcFriendly = srcModel.isFriendly();
		boolean destFriendly = destModel.isFriendly();
		boolean destBlacklist = destModel.isBlackList();
		if(srcFriendly == destFriendly) {
			/* 源与目的皆为好友组或皆非好友组,简单移动 */
			main.model.removeItem(indices[0], indices[1]);
			main.model.addItem(destIndex, f);
		} else if(srcFriendly && !destFriendly) {
			/* 源是好友组,目的不是,删除该好友 */
			MessageBox box = new MessageBox(main.getShell(), SWT.ICON_WARNING | SWT.YES | SWT.NO);
			box.setText(LumaQQ.getResourceString("message.box.common.waring.title"));
			if(destBlacklist)
				box.setMessage(LumaQQ.getResourceString("hint.delete.friend.and.remove.self", new Object[] { String.valueOf(qqNum) }));
			else
				box.setMessage(LumaQQ.getResourceString("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);
			}
		} else if(!srcFriendly && destFriendly) {
			/* 源不是好友组,目的是,添加该好友 */
			ReceiveSystemMessageShell rsms = new ReceiveSystemMessageShell(main);
			rsms.setFriendModel(f);
			rsms.open(ReceiveSystemMessageShell.ADD_MODE);
			main.addFriend(qqNum, destModel);
		}
		// 调整动画状态,因为可能在拖动的时候好友有消息,这个时候是有动画效果的,要注意这种情况
		main.adjustAnimateAfterDrag(qqNum, indices[0], destIndex, f);
	}
}

⌨️ 快捷键说明

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