📄 messagetipshell.java
字号:
FormData fd = new FormData();
fd.left = new FormAttachment(0, 5);
fd.right = new FormAttachment(100, -20);
fd.top = new FormAttachment(0, 13);
lblClusterInfo.setLayoutData(fd);
// 信息标签
lblUserInfo = new Label(shell, SWT.NONE);
lblUserInfo.setBackground(background);
lblUserInfo.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
fd = new FormData();
fd.left = new FormAttachment(0, 5);
fd.right = new FormAttachment(100, -20);
fd.top = new FormAttachment(lblClusterInfo, 3, SWT.BOTTOM);
lblUserInfo.setLayoutData(fd);
// 关闭标签
lblClose = new Label(shell, SWT.NONE);
lblClose.setBackground(background);
lblClose.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
fd = new FormData();
fd.right = new FormAttachment(100, -5);
fd.left = new FormAttachment(100, -12);
fd.top = new FormAttachment(0, 13);
fd.bottom = new FormAttachment(0, 20);
lblClose.setLayoutData(fd);
lblClose.setCursor(handCursor);
lblClose.addMouseTrackListener(new MouseTrackAdapter() {
public void mouseEnter(MouseEvent e) {
Control c = (Control)e.getSource();
c.setForeground(main.display.getSystemColor(SWT.COLOR_YELLOW));
c.redraw();
}
public void mouseExit(MouseEvent e) {
Control c = (Control)e.getSource();
c.setForeground(main.display.getSystemColor(SWT.COLOR_WHITE));
c.redraw();
}
});
lblClose.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
closeNow();
}
});
lblClose.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
Rectangle rect = lblClose.getBounds();
e.gc.drawLine(0, 0, rect.width - 1, rect.height - 1);
e.gc.drawLine(1, 0, rect.width - 1, rect.height - 2);
e.gc.drawLine(0, 1, rect.width - 2, rect.height - 1);
e.gc.drawLine(rect.width - 1, 0, 0, rect.height - 1);
e.gc.drawLine(rect.width - 2, 0, 0, rect.height - 2);
e.gc.drawLine(rect.width - 1, 1, 1, rect.height - 1);
}
});
// 头像显示,显示小头像
lblFace = new Label(shell, SWT.NONE);
lblFace.setBackground(background);
fd = new FormData();
fd.left = new FormAttachment(0, 5);
fd.right = new FormAttachment(0, 37);
fd.top = new FormAttachment(lblUserInfo, 3, SWT.BOTTOM);
fd.bottom = new FormAttachment(lblUserInfo, 45, SWT.BOTTOM);
lblFace.setLayoutData(fd);
// 设置标签
lblSetup = new Label(shell, SWT.NONE);
lblSetup.setBackground(background);
lblSetup.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
lblSetup.setCursor(handCursor);
lblSetup.setText(LumaQQ.getResourceString("message.tip.shell.label.setup"));
fd = new FormData();
fd.left = new FormAttachment(0, 5);
fd.bottom = new FormAttachment(100, -5);
lblSetup.setLayoutData(fd);
lblSetup.addMouseTrackListener(mtl);
lblSetup.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
closeNow();
main.openSystemOptionShell().showPanel(SystemOptionShell.GUI);
}
});
// 消息标签
lblMessage = new Label(shell, SWT.WRAP);
lblMessage.setBackground(background);
lblMessage.setCursor(handCursor);
fd = new FormData();
fd.left = new FormAttachment(lblFace, 5, SWT.RIGHT);
fd.right = new FormAttachment(100, -5);
fd.top = new FormAttachment(lblUserInfo, 5, SWT.BOTTOM);
fd.bottom = new FormAttachment(100, -5);
lblMessage.setLayoutData(fd);
lblMessage.addMouseTrackListener(mtl);
lblMessage.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
closeNow();
Object modelObj = shell.getData();
clearModel(modelObj);
if(modelObj instanceof FriendModel)
main.openNormalMessageShell((FriendModel)modelObj);
else
main.openClusterMessageShell((ClusterModel)modelObj);
}
});
// 专用伺候linux的代码
shell.layout();
}
/**
* 立刻关闭提示窗口
*/
private void closeNow() {
// 设置窗口为不可见
shell.setVisible(false);
}
/**
* 设置提示窗口的信息
* @return 设置成功则返回true,失败返回false,一般失败的情况是因为这个好友的消息已经被读取,不需要提示了
*/
private boolean setFriendModel(FriendModel f) {
// 得到好友QQ号
Integer qqNum = (Integer) f.getProperty("qq");
// 得到群消息包
ReceiveIMPacket packet = (ReceiveIMPacket)f.getProperty("temp");
// 判断是否为null,为null说明其实没有消息,不需要提示
if(packet != null) {
shell.setData(f);
// 设置好友信息
lblClusterInfo.setText(LumaQQ.getResourceString("message.tip.shell.label.from"));
lblUserInfo.setText(LumaQQ.getResourceString("message.tip.shell.label.user.info", new Object[] { f.getProperty("name"), qqNum.toString() } ));
// 设置消息内容
lblMessage.setText(packet.normalIM.message);
// 显示小头像
lblFace.setImage(main.getFriendFace(f));
return true;
} else
return false;
}
/**
* 设置提示窗口的信息
* @param c
* @return 设置成功则返回true,失败返回false,一般失败的情况是因为这个群的消息已经被读取,不需要提示了
*/
private boolean setClusterModel(ClusterModel c) {
// 得到群消息包
ReceiveIMPacket packet = (ReceiveIMPacket)c.getProperty("temp");
// 如果packet为null,说明实际没有消息,不需要提示
if(packet != null) {
shell.setData(c);
// 得到发送者的model
FriendModel f = c.getMember(packet.clusterIM.sender);
if(f == null) return false;
// 设置信息
lblClusterInfo.setText(LumaQQ.getResourceString("message.tip.shell.label.cluster.info", new Object[] { c.getProperty("name"), ((Integer)c.getProperty("clusterId")).toString() }));
lblUserInfo.setText(LumaQQ.getResourceString("message.tip.shell.label.user.info", new Object[] { f.getProperty("name"), String.valueOf(packet.clusterIM.sender) }));
// 设置消息内容
lblMessage.setText(packet.clusterIM.message);
// 设置群头像
lblFace.setImage(c.getImage());
return true;
} else
return false;
}
/**
* @return 下一个要显示的model,没有则返回null
*/
private Object getNextModel() {
synchronized(friendLink) {
if(friendLink.isEmpty())
return null;
else
return friendLink.removeFirst();
}
}
/**
* 移除和obj代码的model相同的元素
* @param modelObj
*/
private void clearModel(Object modelObj) {
synchronized(friendLink) {
ListIterator iter = friendLink.listIterator();
while(iter.hasNext()) {
Object obj = iter.next();
if(obj instanceof FriendModel) {
if(((FriendModel)obj).equals(modelObj))
iter.remove();
} else {
if(((ClusterModel)obj).equals(modelObj))
iter.remove();
}
}
}
}
/**
* 添加要显示消息的好友或者群Model
* @param f
*/
public void addModel(Object f) {
synchronized(friendLink) {
friendLink.addLast(f);
if(!on) {
on = true;
display.asyncExec(showRunnable);
}
}
}
/**
* @return true表示链表为空
*/
public boolean isEmpty() {
synchronized(friendLink) {
return friendLink.isEmpty();
}
}
/**
* 清楚所有未完成的消息提示
*/
public void clearAll() {
synchronized(friendLink) {
friendLink.clear();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -