📄 normalimcontainer.java
字号:
});
}
// 表情
ti = new ToolItem(tb, SWT.NONE);
ti.setImage(res.getImage(Resources.icoSmiley));
ti.setToolTipText(tooltip_button_face);
ti.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
ToolBar toolbar = ((ToolItem)e.widget).getParent();
Rectangle bound = toolbar.getBounds();
openImageSelectionShell(toolbar.getParent().toDisplay(bound.x, bound.y + bound.height));
}
});
// 动画状态
ti = new ToolItem(tb, SWT.CHECK);
ti.setImage(res.getImage(Resources.icoStop));
ti.setToolTipText(tooltip_button_disable_animation);
ti.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
ToolItem item = (ToolItem)e.widget;
outputBox.setForbiddenAnimation(item.getSelection());
inputBox.setForbiddenAnimation(item.getSelection());
item.setToolTipText(item.getSelection() ? tooltip_button_animation : tooltip_button_disable_animation);
}
});
// input form
inputForm.setTopLeft(tb);
inputForm.setBackground(Colors.VIEWFORM_BANNER_BACKGROUND);
inputBox = new RichBox(inputForm);
inputBox.setBackground(Colors.WHITE);
inputForm.setContent(inputBox);
addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
for(LineStyle style : styleCache) {
if(style.foreground != null)
style.foreground.dispose();
if(style.background != null)
style.background.dispose();
}
}
});
}
public Image getHead() {
FaceRegistry reg = FaceRegistry.getInstance();
if(user.hasCustomHead && reg.hasFace(reg.getMd5ById(user.customHeadId)))
return res.getSmallCustomHead(user.customHeadId, false);
else
return res.getSmallHead(user.headId);
}
public int getUnreadCount() {
return unread;
}
public String getDisplayedName() {
return user.displayName;
}
public int getId() {
return user.qq;
}
public Model getModel() {
return user;
}
public void putMessage(ReceiveIMPacket packet) {
appendMessage(user, packet.normalIM, packet.normalHeader);
if(!active)
unread++;
}
public String getIPText() {
if(ip.equals(""))
return place;
else
return ip + " - " + place;
}
public void setModel(Model model) {
user = (User)model;
if(main != null) {
resolveIPLocation(user);
lblIp.setText(getIPText());
lblIp.setToolTipText(lblIp.getText());
}
FaceRegistry reg = FaceRegistry.getInstance();
if(user.hasCustomHead && reg.hasFace(reg.getMd5ById(user.customHeadId)))
lblName.setImage(res.getSmallCustomHead(user.customHeadId, false));
else
lblName.setImage(HeadFactory.getSmallHeadByStatus(user));
lblName.setText(user.displayName + " (" + user.qq + ')');
lblName.getParent().layout();
}
public void setMainShell(MainShell main) {
this.main = main;
if(ip == null) {
resolveIPLocation(user);
lblIp.setText(getIPText());
lblIp.setToolTipText(lblIp.getText());
}
// 初始化按键事件
initKeyAction();
setUseEnter(main.getOptionHelper().isUseEnterInTalkMode());
}
/**
* 打开表情选择窗口
*/
private void openImageSelectionShell(Point loc) {
ImageSelector fss = new ImageSelector(parent.getShell(), new FaceImageAdvisor(main));
fss.setListener(new IFaceSelectionListener() {
public void faceSelected(IImageSelectorAdvisor provider, int group, int sequence) {
if(group == 0) {
int index = res.getFaceCode(sequence);
if(index != -1)
inputBox.insertImage(IRichContent.DEFAULT_FACE_TAG, index);
} else {
MessageDialog.openInformation(parent.getShell(), message_box_common_info_title, message_box_face_to_user);
/*
* 暂时还不支持向单个用户发送自定义表情,注释掉这些代码
*/
// FaceUtil util = FaceUtil.getInstance();
// Face face = util.getFace(group - 1, sequence);
// if(face == null)
// return;
// int id = Util.getInt(face.getId(), -1);
// if(id == -1)
// return;
// inputBox.insertImage(IRichContent.CUSTOM_FACE_TAG, id);
}
}
});
fss.setLocation(loc);
fss.open();
}
public void setActive(boolean active) {
this.active = active;
if(active)
unread = 0;
}
/**
* @param c
* 群model
* @param im
* 群消息结构
* @param header
* @param me
* true表示是我自己
*/
public void appendMessage(User f, NormalIM im, NormalIMHeader header) {
outputBox.appendText('(' + DefaultFace.escapeFaces(f.displayName) + ") " + DateTool.format(header.sendTime), otherStyle);
LineStyle style = getLineStyle(im.fontStyle);
outputBox.appendText(im.message, style);
}
/**
* 往输出框追加消息
*
* @param entry
* RecordEntry
*/
private void appendMessage(RecordEntry entry) {
outputBox.appendText('(' + DefaultFace.escapeFaces(main.getMyModel().displayName) + ") " + DateTool.format(entry.time), myStyle);
outputBox.appendText(entry.message, getLineStyle(main.getDefaultStyle()));
}
/**
* 得到行样式
*
* @param fs
* @return
*/
private LineStyle getLineStyle(FontStyle fs) {
int fontStyle = 0;
if(fs.isBold())
fontStyle |= SWT.BOLD;
if(fs.isItalic())
fontStyle |= SWT.ITALIC;
if(fontStyle == 0)
fontStyle = SWT.NORMAL;
return getLineStyle(fs.getFontName(),
fontStyle,
fs.getFontSize(),
fs.getRed(),
fs.getGreen(),
fs.getBlue());
}
/**
* 根据一个现有的style,在cache里面查找一个相同的style,没有则新建一个
*
* @param style
* @return
*/
private LineStyle getLineStyle(LineStyle ls) {
int size = styleCache.size();
for(int i = 0; i < size; i++) {
LineStyle style = styleCache.get(i);
if(style.equals(ls))
return style;
}
LineStyle style = (LineStyle)ls.clone();
styleCache.add(style);
return style;
}
/**
* 根据具体的样式信息查找style
*
* @param fontName
* @param fontStyle
* @param fontSize
* @param red
* @param green
* @param blue
* @return
*/
private LineStyle getLineStyle(String fontName, int fontStyle, int fontSize, int red, int green, int blue) {
int size = styleCache.size();
for(int i = 0; i < size; i++) {
LineStyle style = styleCache.get(i);
if(!style.fontName.equals(fontName))
continue;
if(style.fontSize != fontSize)
continue;
if(style.fontStyle != fontStyle)
continue;
// TODO add underline here
if(style.foreground.getRed() != red)
continue;
if(style.foreground.getGreen() != green)
continue;
if(style.foreground.getBlue() != blue)
continue;
return style;
}
LineStyle style = new LineStyle(new Color(main.getDisplay(), red, green, blue), null, fontName, fontStyle, fontSize);
styleCache.add(style);
return style;
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.ui.IIMContainer#send()
*/
public void send() {
// 检查消息是否为空
String s = inputBox.getText();
if(s.length() == 0) {
MessageDialog.openWarning(getShell(), message_box_common_warning_title, message_box_cannot_send_empty_message);
return;
}
// 判断用户是否登录
if(main.getClient().getUser().isLoggedIn()) {
message = s;
// 保存到聊天记录中
RecordEntry key = new RecordEntry();
key.owner = user.qq;
key.sender = main.getMyModel().qq;
key.senderParent = 0;
key.receiver = user.qq;
key.time = System.currentTimeMillis();
key.type = IKeyConstants.NORMAL;
key.message = message;
main.getRecordManager().addRecord(key);
// 把发送的消息显示到输出框中
appendMessage(key);
// 清空发送框
inputBox.clear();
// TODO 检查是否包含自定义表情,转换发送消息到QQ格式,启动自定义表情发送任务
// 启动普通消息发送任务
main.getIMJobQueue().addJob(new SendNormalIMJob(message, (User)getModel()));
} else {
MessageDialog.openWarning(getShell(), message_box_common_warning_title, message_box_please_login_first);
}
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.ui.IIMContainer#setUseEnter(boolean)
*/
public void setUseEnter(boolean useEnter) {
if(useEnter) {
inputBox.removeUserKeyAction(SWT.MOD1 | SWT.CR);
inputBox.setUserKeyAction(SWT.CR, sendAction);
inputBox.setKeyBinding(SWT.MOD1 | SWT.CR, RichBox.NEW_LINE);
} else {
inputBox.removeUserKeyAction(SWT.CR);
inputBox.setUserKeyAction(SWT.MOD1 | SWT.CR, sendAction);
inputBox.setKeyBinding(SWT.CR, RichBox.NEW_LINE);
}
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.ui.IIMContainer#getComposite()
*/
public Composite getComposite() {
return this;
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.qq.events.IQQListener#qqEvent(edu.tsinghua.lumaqq.qq.events.QQEvent)
*/
public void qqEvent(QQEvent e) {
}
public void setKeyHandler(IContainerKeyHandler ka) {
keyHandler = ka;
}
public void setText(String text) {
inputBox.setText(text);
}
public void release() {
dispose();
}
public void setKeyboardFocus() {
inputBox.setFocus();
}
public void init() {
inputBox.setDefaultStyle(main.getDefaultStyle());
}
public boolean isActiveContainer() {
return active;
}
public void appendText(String text) {
inputBox.appendText(text, main.getDefaultStyle());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -