📄 itemmousetracklistener.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.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import edu.tsinghua.lumaqq.models.ClusterModel;
import edu.tsinghua.lumaqq.models.FriendModel;
import edu.tsinghua.lumaqq.ui.FriendTipShell;
import edu.tsinghua.lumaqq.ui.MainShell;
import edu.tsinghua.lumaqq.utils.OptionUtil;
import edu.tsinghua.swt.widgets.CoolButton;
/**
* 好友的鼠标跟踪事件,用于显示一个tip窗口
*
* @author 马若劼
*/
public class ItemMouseTrackListener extends MouseTrackAdapter {
private MainShell main;
/**
* 构造函数
* @param main
*/
public ItemMouseTrackListener(MainShell main) {
this.main = main;
}
/* (non-Javadoc)
* @see org.eclipse.swt.events.MouseTrackListener#mouseExit(org.eclipse.swt.events.MouseEvent)
*/
public void mouseExit(MouseEvent e) {
// 如果当前设置了不显示tip,返回
OptionUtil options = OptionUtil.getInstance();
if(!options.isShowTip()) return;
// 设置在1.5秒后关闭提示窗口
if(main.getTipHelper().isFriendTipShellVisible())
main.getTipHelper().getFriendTipShell().setShouldClose(true);
}
/* (non-Javadoc)
* @see org.eclipse.swt.events.MouseTrackListener#mouseHover(org.eclipse.swt.events.MouseEvent)
*/
public void mouseHover(MouseEvent e) {
// 如果当前设置了不显示tip,返回
OptionUtil options = OptionUtil.getInstance();
if(!options.isShowTip()) return;
// 得到好友提示窗口
FriendTipShell tipShell = main.getTipHelper().getFriendTipShell();
// 设置关闭标志为false
tipShell.setShouldClose(false);
// 得到好友model
CoolButton viewPart = (CoolButton)e.getSource();
Object modelObj = viewPart.getData();
// 根据model是群还是好友,做出不同的动作
if(modelObj instanceof ClusterModel)
tipShell.setClusterTip((ClusterModel)modelObj);
else
tipShell.setFriendTip((FriendModel)modelObj);
// 添加model到tipShell的Data中
tipShell.setData(modelObj);
// 调整窗口的位置,然后显示
Point p = viewPart.toDisplay(e.x, e.y);
Rectangle mainBound = main.getShell().getBounds();
p.x = mainBound.x - 260;
if(p.x < 0)
p.x = mainBound.x + mainBound.width + 10;
tipShell.setLocation(p);
tipShell.setVisible(true);
// 这也是为了满足Linux,必须layout
tipShell.setSize(250, 160);
tipShell.layout();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -