📄 sendclusterimwindow.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.ui;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.ViewForm;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.MenuAdapter;
import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.events.ShellListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.ColorDialog;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.FontDialog;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Sash;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import edu.tsinghua.lumaqq.Colors;
import edu.tsinghua.lumaqq.IconHolder;
import edu.tsinghua.lumaqq.LumaQQ;
import edu.tsinghua.lumaqq.events.IFaceSelectionListener;
import edu.tsinghua.lumaqq.models.ClusterModel;
import edu.tsinghua.lumaqq.models.FriendModel;
import edu.tsinghua.lumaqq.models.GroupModel;
import edu.tsinghua.lumaqq.models.ModelSorter;
import edu.tsinghua.lumaqq.qq.Util;
import edu.tsinghua.lumaqq.qq.beans.ClusterIM;
import edu.tsinghua.lumaqq.qq.events.IQQListener;
import edu.tsinghua.lumaqq.qq.events.QQEvent;
import edu.tsinghua.lumaqq.qq.packets.in.ClusterCommandReplyPacket;
import edu.tsinghua.lumaqq.ui.config.user.UserInfoWindow;
import edu.tsinghua.lumaqq.ui.tool.HeadFactory;
import edu.tsinghua.lumaqq.ui.tool.MapValueContentProvider;
import edu.tsinghua.lumaqq.utils.FaceUtil;
import edu.tsinghua.lumaqq.utils.OptionUtil;
import edu.tsinghua.lumaqq.widgets.ClusterMessageExporter;
import edu.tsinghua.lumaqq.widgets.ClusterMessageFormatter;
import edu.tsinghua.lumaqq.widgets.FaceImageProvider;
import edu.tsinghua.lumaqq.widgets.FriendMessageExporter;
import edu.tsinghua.lumaqq.widgets.IImageProvider;
import edu.tsinghua.lumaqq.widgets.ImageSelector;
import edu.tsinghua.lumaqq.widgets.QButton;
import edu.tsinghua.lumaqq.widgets.RecordViewer;
import edu.tsinghua.lumaqq.widgets.rich.IRichContent;
import edu.tsinghua.lumaqq.widgets.rich.LineStyle;
import edu.tsinghua.lumaqq.widgets.rich.RichBox;
import edu.tsinghua.lumaqq.xml.faces.Face;
import edu.tsinghua.swt.models.INode;
/**
* 发送群消息窗口
*
* @author luma
*/
public class SendClusterIMWindow extends Window implements IQQListener, ShellListener, IFaceSelectionListener, IIMSender {
/**
* <pre>
* 闪烁图标
* </pre>
*
* @author 马若劼
*/
private class Blink implements Runnable {
private boolean flag;
private volatile boolean stop;
private Image blinkImage;
public Blink() {
stop = true;
}
public void setBlinkImage(Image image) {
blinkImage = image;
stop = false;
flag = true;
}
public void run() {
try {
if(flag)
getShell().setImage(blinkImage);
else
getShell().setImage(icons.getImage(IconHolder.icoBlank));
flag = !flag;
if(!stop)
main.getDisplay().timerExec(500, this);
else
getShell().setImage(icons.getSmallClusterHead(model.getFaceId()));
} catch (SWTException e) {
// 这个操作可能会抛出SWTException,如果组件已经dispose的话,
// 所以我们需要捕捉这个异常,不然程序可能崩溃
}
}
public void setStop(boolean stop) {
this.stop = stop;
}
public boolean isStop() {
return stop;
}
}
/**
* 成员列表的label provider
*
* @author luma
*/
private class FriendModelLabelProvider extends LabelProvider implements
ITableLabelProvider {
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
*/
public Image getColumnImage(Object element, int columnIndex) {
return HeadFactory.getSmallHeadByStatus(((FriendModel)element));
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
*/
public String getColumnText(Object element, int columnIndex) {
FriendModel f = (FriendModel)element;
return f.getName() + '(' + f.getQQ() + ')';
}
}
/**
* 往输出框追加提示信息
*
* @author luma
*/
private class AppendRunnable implements Runnable {
public String hint;
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
appendHint('\n' + hint + "\n\n", hintStyle);
}
}
private ClusterModel model;
private MainShell main;
private IconHolder icons;
// 表示当前窗口是否是active的
private boolean active;
private CLabel lblName;
private CLabel lblList;
private RichBox outputBox, inputBox;
private Composite sideContainer;
private RecordViewer viewer;
private Menu enterMenu, memberMenu;
private TableViewer listViewer;
private Cursor handCursor;
private Blink blinkRunnable;
private AppendRunnable appendRunnable;
private ViewForm inputForm;
// 用作临时用途
private Date date = new Date();
private DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// style样式表缓冲区
private List styleCache;
// 消息流程封装类
private ClusterIMDelegate workflow;
// 提示信息的样式
private static final LineStyle hintStyle = new LineStyle(null, null, "宋体", SWT.NORMAL, 9);
// 缺省的用户名称提示样式
private static final LineStyle myStyle = new LineStyle(Colors.MY_HINT_COLOR, null, "宋体", SWT.NORMAL, 9);
private static final LineStyle otherStyle = new LineStyle(Colors.BLUE, null, "宋体", SWT.NORMAL, 9);
// 关闭窗口action
private Runnable closeAction = new Runnable() {
public void run() {
if(inputBox.isReadonly()) {
if(!MessageDialog.openQuestion(getShell(), LumaQQ.getString("message.box.common.question.title"), LumaQQ.getString("message.box.abort.sending")))
return;
}
getShell().close();
}
};
// 查看记录的action
private Runnable showRecordAction = new Runnable() {
public void run() {
showRecord();
}
};
// 发送消息的action
private Runnable sendAction = new Runnable() {
public void run() {
if(!inputBox.isReadonly())
sendMessage(inputBox.getText());
}
};
//设置输入框为可输入
private Runnable enableRunnable = new Runnable() {
public void run() {
inputBox.setReadonly(false);
inputBox.setBackground(Colors.WHITE);
}
};
// 系统平台
private static boolean IS_GTK;
private static boolean IS_MOTIF;
static {
String platform = SWT.getPlatform();
IS_GTK = "gtk".equals(platform);
IS_MOTIF = "motif".equals(platform);
}
/**
* @param parentShell
*/
public SendClusterIMWindow(MainShell main, ClusterModel c) {
super(main.getShell());
this.main = main;
this.model = c;
this.icons = IconHolder.getInstance();
blinkRunnable = new Blink();
blinkRunnable.setBlinkImage(model.getImage());
appendRunnable = new AppendRunnable();
styleCache = new ArrayList();
workflow = new ClusterIMDelegate(main.getClient());
workflow.setSender(this);
handCursor = main.getDisplay().getSystemCursor(SWT.CURSOR_HAND);
setBlockOnOpen(false);
}
/**
* 得到行样式
*
* @param im
* @return
*/
private LineStyle getLineStyle(ClusterIM im) {
int fontStyle = 0;
if(im.bold)
fontStyle |= SWT.BOLD;
if(im.italic)
fontStyle |= SWT.ITALIC;
if(fontStyle == 0)
fontStyle = SWT.NORMAL;
return getLineStyle(im.fontName, fontStyle, im.fontSize, im.red, im.green, im.blue);
}
/**
* 根据一个现有的style,在cache里面查找一个相同的style,没有则新建一个
*
* @param style
* @return
*/
private LineStyle getLineStyle(LineStyle ls) {
int size = styleCache.size();
for(int i = 0; i < size; i++) {
LineStyle style = (LineStyle)styleCache.get(i);
if(style.equals(ls))
return style;
}
LineStyle style = (LineStyle)ls.clone();
styleCache.add(style);
return style;
}
/**
* 根据具体的样式信息查找style
*
* @param fontName
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -