📄 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 static edu.tsinghua.lumaqq.resource.Messages.*;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.window.Window;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
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.MouseTrackListener;
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.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
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.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import edu.tsinghua.lumaqq.LumaQQ;
import edu.tsinghua.lumaqq.ecore.face.Face;
import edu.tsinghua.lumaqq.events.IFaceSelectionListener;
import edu.tsinghua.lumaqq.models.Cluster;
import edu.tsinghua.lumaqq.models.ClusterType;
import edu.tsinghua.lumaqq.models.GroupType;
import edu.tsinghua.lumaqq.models.ModelRegistry;
import edu.tsinghua.lumaqq.models.User;
import edu.tsinghua.lumaqq.qq.beans.ClusterIM;
import edu.tsinghua.lumaqq.qq.beans.FontStyle;
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.record.IKeyConstants;
import edu.tsinghua.lumaqq.record.RecordEntry;
import edu.tsinghua.lumaqq.resource.Colors;
import edu.tsinghua.lumaqq.resource.DefaultFace;
import edu.tsinghua.lumaqq.resource.Resources;
import edu.tsinghua.lumaqq.ui.config.user.UserInfoWindow;
import edu.tsinghua.lumaqq.ui.helper.DateTool;
import edu.tsinghua.lumaqq.ui.helper.FaceRegistry;
import edu.tsinghua.lumaqq.ui.helper.ShellLauncher;
import edu.tsinghua.lumaqq.ui.provider.ClusterMemberLabelProvider;
import edu.tsinghua.lumaqq.ui.provider.MapValueContentProvider;
import edu.tsinghua.lumaqq.ui.sorter.ModelSorter;
import edu.tsinghua.lumaqq.widgets.FaceImageAdvisor;
import edu.tsinghua.lumaqq.widgets.IImageSelectorAdvisor;
import edu.tsinghua.lumaqq.widgets.ImageSelector;
import edu.tsinghua.lumaqq.widgets.qstyle.Slat;
import edu.tsinghua.lumaqq.widgets.record.ClusterRecordProvider;
import edu.tsinghua.lumaqq.widgets.record.RecordViewer;
import edu.tsinghua.lumaqq.widgets.rich.IRichContent;
import edu.tsinghua.lumaqq.widgets.rich.LineStyle;
import edu.tsinghua.lumaqq.widgets.rich.RichBox;
/**
* 发送群消息窗口
*
* @author luma
*/
public class SendClusterIMWindow extends Window implements IQQListener, ShellListener, IFaceSelectionListener, IIMSender {
/**
* <pre>
* 闪烁图标
* </pre>
*
* @author luma
*/
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);
if(LumaQQ.IS_GTK)
((BorderStyler)getShell().getData(BorderStyler.STYLER)).repaintTitleBar();
} else {
getShell().setImage(res.getImage(Resources.icoBlank));
if(LumaQQ.IS_GTK)
((BorderStyler)getShell().getData(BorderStyler.STYLER)).repaintTitleBar();
}
flag = !flag;
if(!stop)
main.getDisplay().timerExec(500, this);
else {
getShell().setImage(res.getSmallClusterHead(model.headId));
if(LumaQQ.IS_GTK)
((BorderStyler)getShell().getData(BorderStyler.STYLER)).repaintTitleBar();
}
} catch (Exception e) {
// 这个操作可能会抛出SWTException,如果组件已经dispose的话,
// 所以我们需要捕捉这个异常,不然程序可能崩溃
}
}
public void setStop(boolean stop) {
this.stop = stop;
}
public boolean isStop() {
return stop;
}
}
/**
* 往输出框追加提示信息
*
* @author luma
*/
private class AppendRunnable implements Runnable {
public String hint;
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
if(inputBox.isDisposed())
return;
appendHint('\n' + hint + "\n\n", hintStyle);
}
}
private Cluster model;
private MainShell main;
private Resources res;
// 表示当前窗口是否是active的
private boolean active;
private CLabel lblName;
private CLabel lblList;
private RichBox outputBox, inputBox;
private Composite sideContainer, chatContainer, noticeContainer;
private RecordViewer viewer;
private Menu enterMenu, memberMenu;
private TableViewer listViewer;
private Sash vSash;
private Cursor handCursor;
private Text textNotice;
private ToolBar infoBar;
private Blink blinkRunnable;
private AppendRunnable appendRunnable;
private ViewForm inputForm, infoForm;
// true表示群栏目收起
private boolean infoFormExpanded;
// style样式表缓冲区
private List<LineStyle> styleCache;
/**
* 在输出框中添加提示信息
*
* @param hint
* @param style
*/
private void appendHint(String hint, LineStyle style) {
outputBox.appendText(hint, style);
}
// 消息流程封装类
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(), message_box_common_question_title, 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() {
if(inputBox.isDisposed())
return;
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, Cluster c) {
super(main.getShell());
this.main = main;
this.model = c;
this.res = Resources.getInstance();
blinkRunnable = new Blink();
blinkRunnable.setBlinkImage(res.getClusterHead(model.headId));
appendRunnable = new AppendRunnable();
styleCache = new ArrayList<LineStyle>();
workflow = new ClusterIMDelegate(main.getClient());
workflow.setSender(this);
handCursor = main.getDisplay().getSystemCursor(SWT.CURSOR_HAND);
infoFormExpanded = true;
setBlockOnOpen(false);
}
/**
* 得到行样式
*
* @param im
* @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;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -