📄 sendclusterimwindow.java
字号:
* @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 = (LineStyle)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 org.eclipse.jface.window.Window#getParentShell()
*/
protected Shell getParentShell() {
return null;
}
/**
* 初始化成员菜单
*/
private void initMemberMenu() {
memberMenu = new Menu(getShell());
// 收发消息
MenuItem mi = new MenuItem(memberMenu, SWT.PUSH);
mi.setText(LumaQQ.getString("cluster.im.menu.member.send"));
mi.setImage(icons.getImage(IconHolder.icoSendReceiveMessage));
mi.addSelectionListener(
new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
openMemberMessageShell();
}
}
);
// 发送文件
mi = new MenuItem(memberMenu, SWT.PUSH);
mi.setText(LumaQQ.getString("cluster.im.menu.member.sendfile"));
mi.setImage(icons.getImage(IconHolder.icoSendFile));
mi.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
Object obj = openMemberMessageShell();
if(obj != null) {
while(obj instanceof ReceiveIMWindow)
obj = openMemberMessageShell();
SendIMWindow sms = (SendIMWindow)obj;
sms.requestSendFile();
}
}
});
mi = new MenuItem(memberMenu, SWT.SEPARATOR);
// 加为好友
mi = new MenuItem(memberMenu, SWT.PUSH);
mi.setText(LumaQQ.getString("cluster.im.menu.member.add"));
mi.setImage(icons.getImage(IconHolder.icoAddFriend));
mi.addSelectionListener(
new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
IStructuredSelection selection = (IStructuredSelection)listViewer.getSelection();
if(!selection.isEmpty()) {
FriendModel f = (FriendModel)selection.getFirstElement();
// 找到第一个好友组的model
GroupModel destModel = main.getMVCHelper().getFirstFriendlyGroupModel();
if(destModel != null) {
// 创建窗口
main.getShellLauncher().openAddReceiveSystemMessageShell(f);
main.getMVCHelper().addFriend(f.getQQ(), destModel);
}
}
}
}
);
// 查看资料
mi = new MenuItem(memberMenu, SWT.PUSH);
mi.setText(LumaQQ.getString("cluster.im.menu.member.viewinfo"));
mi.setImage(icons.getImage(IconHolder.icoPersonInfo));
mi.addSelectionListener(
new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
IStructuredSelection selection = (IStructuredSelection)listViewer.getSelection();
if(!selection.isEmpty()) {
FriendModel f = (FriendModel)selection.getFirstElement();
main.getShellLauncher().openUserInfoWindow(f, UserInfoWindow.READ_ONLY);
main.getClient().getUserInfo(f.getQQ());
}
}
}
);
// separator
mi = new MenuItem(memberMenu, SWT.SEPARATOR);
// 消息管理菜单
mi = new MenuItem(memberMenu, SWT.CASCADE);
mi.setText(LumaQQ.getString("cluster.im.menu.member.message"));
mi.setImage(icons.getImage(IconHolder.icoMessageManage));
Menu msgMenu = new Menu(mi);
mi.setMenu(msgMenu);
// 导出为文本文件菜单
mi = new MenuItem(msgMenu, SWT.PUSH);
mi.setText(LumaQQ.getString("cluster.im.menu.member.export"));
mi.setImage(icons.getImage(IconHolder.icoTxtFile));
mi.addSelectionListener(
new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
IStructuredSelection selection = (IStructuredSelection)listViewer.getSelection();
if(!selection.isEmpty()) {
FriendModel f = (FriendModel)selection.getFirstElement();
// 导出
main.getExportHelper().exportMessage(f.getQQ(), new FriendMessageExporter(main.getMyModel(), f));
}
}
}
);
// 添加菜单显示事件监听器
memberMenu.addMenuListener(
new MenuAdapter() {
public void menuShown(MenuEvent e) {
IStructuredSelection selection = (IStructuredSelection)listViewer.getSelection();
if(selection.isEmpty())
memberMenu.setVisible(false);
else {
FriendModel f = (FriendModel)selection.getFirstElement();
// 设置菜单的使能状态,对于好友,可以发消息,不是好友不能发
boolean b = main.getMVCHelper().isFriend(f);
memberMenu.getItem(0).setEnabled(b);
memberMenu.getItem(3).setEnabled(!b);
}
}
}
);
}
/**
* 初始化使用Enter键的菜单
*/
private void initEnterMenu() {
enterMenu = new Menu(getShell(), SWT.POP_UP);
// 使用Enter键菜单
MenuItem mi = new MenuItem(enterMenu, SWT.RADIO);
mi.setText(LumaQQ.getString("cluster.im.menu.use.enter"));
mi.addSelectionListener(
new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
inputBox.removeUserKeyAction(SWT.MOD1 | SWT.CR);
inputBox.setUserKeyAction(SWT.CR, sendAction);
inputBox.setKeyBinding(SWT.MOD1 | SWT.CR, RichBox.NEW_LINE);
OptionUtil.getInstance().setUseEnterInTalkMode(true);
}
}
);
// 使用Ctrl + Enter键菜单
mi = new MenuItem(enterMenu, SWT.RADIO);
mi.setText(LumaQQ.getString("cluster.im.menu.use.ctrl.enter"));
mi.addSelectionListener(
new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
inputBox.removeUserKeyAction(SWT.CR);
inputBox.setUserKeyAction(SWT.MOD1 | SWT.CR, sendAction);
inputBox.setKeyBinding(SWT.CR, RichBox.NEW_LINE);
OptionUtil.getInstance().setUseEnterInTalkMode(false);
}
}
);
// 添加菜单显示事件监听器
enterMenu.addMenuListener(
new MenuAdapter() {
public void menuShown(MenuEvent e) {
// 根据当前选项设置菜单项状态
boolean b = OptionUtil.getInstance().isUseEnterInTalkMode();
enterMenu.getItem(0).setSelection(b);
enterMenu.getItem(1).setSelection(!b);
}
}
);
}
/* (non-Javadoc)
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
*/
protected void configureShell(Shell newShell) {
newShell.setText(LumaQQ.getString("cluster.im.title", new Object[] { model.getName() }));
newShell.setImage(model.getImage());
newShell.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
int size = styleCache.size();
for(int i = 0; i < size; i++) {
LineStyle style = (LineStyle)styleCache.get(i);
if(style.foreground != null)
style.foreground.dispose();
if(style.background != null)
style.background.dispose();
}
workflow.dispose();
}
});
main.getShell().addShellListener(new ShellAdapter() {
public void shellClosed(ShellEvent e) {
inputBox.dispose();
outputBox.dispose();
}
});
}
/* (non-Javadoc)
* @see org.eclipse.jface.window.Window#getShellListener()
*/
protected ShellListener getShellListener() {
return this;
}
/* (non-Javadoc)
* @see org.eclipse.swt.events.ShellListener#shellActivated(org.eclipse.swt.events.ShellEvent)
*/
public void shellActivated(ShellEvent e) {
stopBlinkImage();
active = true;
}
/* (non-Javadoc)
* @see org.eclipse.swt.events.ShellListener#shellDeactivated(org.eclipse.swt.events.ShellEvent)
*/
public void shellDeactivated(ShellEvent e) {
active = false;
}
/* (non-Javadoc)
* @see org.eclipse.swt.events.ShellAdapter#shellClosed(org.eclipse.swt.events.ShellEvent)
*/
public void shellClosed(ShellEvent e) {
main.getClient().removeQQListener(this);
main.getShellRegistry().removeSendClusterIMWindow(model);
}
/* (non-Javadoc)
* @see org.eclipse.swt.events.ShellListener#shellDeiconified(org.eclipse.swt.events.ShellEvent)
*/
public void shellDeiconified(ShellEvent e) {
}
/* (non-Javadoc)
* @see org.eclipse.swt.events.ShellListener#shellIconified(org.eclipse.swt.events.ShellEvent)
*/
public void shellIconified(ShellEvent e) {
}
/* (non-Javadoc)
* @see org.eclipse.jface.window.Window#createContents(org.eclipse.swt.widgets.Composite)
*/
protected Control createContents(Composite parent) {
parent.setLayout(new FillLayout());
Composite container = (Composite)super.createContents(parent);
GridLayout layout = new GridLayout(3, false);
layout.horizontalSpacing = 0;
container.setLayout(layout);
container.setBackground(Colors.DIALOG_BACKGOUND);
// 聊天区
Composite chatContainer = new Composite(container, SWT.NONE);
chatContainer.setLayoutData(new GridData(GridData.FILL_BOTH));
layout = new GridLayout();
layout.marginHeight = layout.marginWidth = 1;
layout.horizontalSpacing = layout.verticalSpacing = 0;
chatContainer.setLayout(layout);
chatContainer.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
Composite c = (Composite)e.getSource();
Rectangle rect = c.getClientArea();
rect.width--;
rect.height--;
e.gc.setForeground(Colors.WIDGET_BORDER);
e.gc.drawRectangle(rect);
}
});
ViewForm outputForm = new ViewForm(chatContainer, SWT.FLAT);
outputForm.setLayoutData(new GridData(GridData.FILL_BOTH));
lblName = new CLabel(outputForm, SWT.LEFT);
lblName.setBackground(Colors.VIEWFORM_BANNER_BACKGROUP);
setClusterNameLabel();
lblName.setCursor(handCursor);
lblName.setForeground(Colors.WHITE);
lblName.addMouseListener(new MouseAdapter() {
public void mouseUp(MouseEvent e) {
main.getShellLauncher().openClusterInfoWindow(model);
}
});
lblName.addMouseTrackListener(new MouseTrackAdapter() {
public void mouseEnter(MouseEvent e) {
lblName.setForeground(Colors.YELLOW);
}
public void mouseExit(MouseEvent e) {
lblName.setForeground(Colors.WHITE);
}
});
outputForm.setTopLeft(lblName);
outputBox = new RichBox(outputForm);
outputBox.setReadonly(true);
outputBox.setBackground(Colors.WHITE);
outputForm.setContent(outputBox);
Sash sash = new Sash(chatContainer, SWT.HORIZONTAL);
sash.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
sash.setBackground(Colors.READONLY_BACKGROUND);
sash.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
GridData gd = (GridData)inputForm.getLayoutData();
gd.heightHint = inputForm.getParent().getClientArea().height - e.y;
inputForm.getParent().layout();
}
});
inputForm = new ViewForm(chatContainer, SWT.FLAT);
inputForm.setBackground(Colors.VIEWFORM_BANNER_BACKGROUP);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.heightHint = 100;
inputForm.setLayoutData(gd);
final ToolBar tb = new ToolBar(inputForm, SWT.FLAT);
tb.setBackground(Colors.VIEWFORM_BANNER_BACKGROUP);
// 字体
ToolItem tiFont = new ToolItem(tb, SWT.NONE);
tiFont.setImage(icons.getImage(IconHolder.icoFont));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -