📄 messagetipshell.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.shells;
import java.util.LinkedList;
import java.util.ListIterator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.MouseTrackListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import edu.tsinghua.lumaqq.IconHolder;
import edu.tsinghua.lumaqq.LumaQQ;
import edu.tsinghua.lumaqq.models.ClusterModel;
import edu.tsinghua.lumaqq.models.FriendModel;
import edu.tsinghua.lumaqq.qq.packets.in.ReceiveIMPacket;
/**
* <pre>
* 消息提示窗口,如果主窗口为最小化,且相应的聊天窗口没有打开,则显示提示
* 其他情况,不显示该窗口
* </pre>
*
* @author 马若劼
*/
public class MessageTipShell {
private Shell shell;
private Display display;
private Label lblFace;
private Label lblSetup, lblClusterInfo, lblUserInfo, lblClose, lblMessage;
private Color background;
private Cursor handCursor;
//需要显示的好友或者群model队列
private LinkedList friendLink;
// MainShell对象
private MainShell main;
// 鼠标按下时,设置此变量为true,表示处于移动窗口状态
private boolean isMove;
// 鼠标按下时的位置
private int downX, downY;
// 表示消息提示操作是否在进行中的标志
private boolean on;
// 执行检查需要显示的队列并显示的Runnable对象
private Runnable showRunnable = new Runnable() {
public void run() {
// model为null,说明没有更多的好友要显示,关闭窗口
if(isEmpty()) {
if(shell.isVisible()) {
Point p = display.getCursorLocation();
// 但是如果这个时候鼠标在窗口之上,不关闭
// 不在,则关闭
if(!shell.getBounds().contains(p)) {
closeNow();
on = false;
} else
display.timerExec(5000, this);
} else
on = false;
} else if(shell.isVisible()) {
// 如果这个时候鼠标在窗口上,不关闭,否则关闭
Point p = display.getCursorLocation();
if(!shell.getBounds().contains(p))
closeNow();
// 等五秒再调用自己一次
display.timerExec(500, this);
} else {
Object modelObj = null;
while((modelObj = getNextModel()) != null) {
if(setModel(modelObj)) break;
else continue;
}
if(modelObj == null) {
closeNow();
on = false;
} else {
show();
display.timerExec(5000, showRunnable);
}
}
}
};
/**
* 设置Model信息
* @param obj
* @return
*/
public boolean setModel(Object obj) {
if(obj instanceof FriendModel)
return setFriendModel((FriendModel)obj);
else
return setClusterModel((ClusterModel)obj);
}
// 鼠标移动到标签上时的事件处理器
private MouseTrackListener mtl = new MouseTrackAdapter() {
public void mouseEnter(MouseEvent e) {
Control c = (Control)e.getSource();
c.setForeground(main.display.getSystemColor(SWT.COLOR_YELLOW));
}
public void mouseExit(MouseEvent e) {
Control c = (Control)e.getSource();
c.setForeground(main.display.getSystemColor(SWT.COLOR_WHITE));
}
};
/**
* 构造函数
* @param main
*/
public MessageTipShell(MainShell main) {
// 初始化变量
this.main = main;
this.display = main.display;
background = new Color(display, 0x73, 0x8A, 0xEF);
handCursor = new Cursor(display, SWT.CURSOR_HAND);
isMove = false;
on = false;
friendLink = new LinkedList();
// 初始化窗口布局
initLayout();
}
/**
* 打开窗口
*/
public void show() {
if(!shell.isVisible()) {
// 得到上站通知的显示位置,-1表示缺省
int x = main.options.getMessageOnlineTipLocationX();
int y = main.options.getMessageOnlineTipLocationY();
// 得到屏幕客户区的大小,之所以是客户区是因为任务条之类的东西不计算在内
Rectangle displayRect = display.getClientArea();
Point size = shell.getSize();
// 如果有变量等于-1,采用缺省值
if(x == -1)
x = displayRect.width - size.x - 2;
if(y == -1)
y = displayRect.height - size.y - 2;
// 设置shell位置
shell.setLocation(x, y);
// 设置shell为可见
shell.setVisible(true);
// 这也是为了满足Linux,必须layout
shell.layout();
}
}
/**
* 初始化窗口布局
*/
private void initLayout() {
// 创建tip窗口
shell = new Shell(display, SWT.ON_TOP | SWT.NO_TRIM);
shell.setSize(200, 122);
shell.setLayout(new FormLayout());
shell.addShellListener(new ShellAdapter() {
public void shellClosed(ShellEvent e) {
background.dispose();
handCursor.dispose();
}
});
shell.addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent e) {
if (isMove) {
Point loc = shell.getLocation();
int x = loc.x + e.x - downX;
int y = loc.y + e.y - downY;
shell.setLocation(x, y);
main.options.setMessageTipLocationX(x);
main.options.setMessageTipLocationY(y);
}
}
});
shell.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
downX = e.x;
downY = e.y;
isMove = true;
}
public void mouseUp(MouseEvent e) {
isMove = false;
}
});
shell.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
e.gc.drawImage(main.icons.getResource(IconHolder.bmpMessageTipBackground), 0, 0);
}
});
// 群信息标签
lblClusterInfo = new Label(shell, SWT.NONE);
lblClusterInfo.setBackground(background);
lblClusterInfo.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -