package com.heyang.biz.server.view;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.AbstractAction;
import javax.swing.JTextPane;
import javax.swing.KeyStroke;
import javax.swing.event.UndoableEditEvent;
import javax.swing.event.UndoableEditListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.JTextComponent;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import javax.swing.text.TextAction;
import javax.swing.undo.CannotRedoException;
import javax.swing.undo.CannotUndoException;
import javax.swing.undo.UndoManager;
import com.heyang.util.DlgUtil;
/**
* 用户输入Sql及其它文本用的文本窗格
* 说明:
* 作者:heyang(heyang78@gmail.com)
* 创建时间:2010-5-2 上午11:45:09
* 修改时间:2010-5-2 上午11:45:09
*/
public class InputTextPane extends JTextPane{
private static final long serialVersionUID = -3120527751030350540L;
// 三种颜色的字体风格
public static final String RED_STYLE = "RedStyle";// 用于显示错误信息
public static final String BLACK_STYLE = "BlackStyle";// 用于显示正常文本
public static final String BLUE_STYLE = "BlueStyle";// 用于显示高亮文本
// 操作文本用的文档对象
protected StyledDocument doc;
// Undo管理器
private UndoManager undo ;
/**
* 构造函数
*/
public InputTextPane(){
super();
doc=(StyledDocument)this.getDocument();
initialStyles();
/*if(doc instanceof AbstractDocument){
AbstractDocument adoc=(AbstractDocument)doc;
adoc.setDocumentFilter(new HighLightFilter(this));
}*/
undo = new UndoManager();
doc.addUndoableEditListener(new UndoableEditListener() {
public void undoableEditHappened(UndoableEditEvent e) {
undo.addEdit(e.getEdit());
}
});
// 添加Undo,Redo,Shift+Tab的处理
//addActionMap();
}
/**
* 初始化各种字体风格
*
* 说明:
* 创建时间:2010-5-2 上午11:50:17
* 修改时间:2010-5-2 上午11:50:17
*/
private void initialStyles(){
Style BlueStyle = doc.addStyle(BLUE_STYLE, null);
StyleConstants.setForeground(BlueStyle, Color.blue);
Style BlackStyle = doc.addStyle(BLACK_STYLE, null);
StyleConstants.setForeground(BlackStyle, Color.black);
Style RedStyle = doc.addStyle(RED_STYLE, null);
StyleConstants.setForeground(RedStyle, Color.red);
}
/**
* 在头部添加黑色信息以显示送给客户端的resposne
*
* 说明:
* @param msg
* 创建时间:2010-5-2 上午11:49:17
* 修改时间:2010-5-2 上午11:49:17
*/
public void insertBlackMsg(String msg,String remoteIp){
try{
String text=getCurrTime()+"(Response to "+remoteIp+")\n"+msg+"\n\n";
doc.insertString(0, text, doc.getStyle(BLACK_STYLE));
}
catch(Exception ex){
DlgUtil.popupWarningDialog("不能将文本插入文本窗格的起始位置");
ex.printStackTrace();
}
}
/**
* 插入发送的消息
*
* 说明:
* @param msg
* @param toUser
* 创建时间:2010-12-30 下午11:47:38
*/
public void insertSendMsg(String msg,String toUser){
try{
String text=getCurrTime()+"(Send message to "+toUser+")\n"+msg+"\n\n";
doc.insertString(0, text, doc.getStyle(BLACK_STYLE));
}
catch(Exception ex){
DlgUtil.popupWarningDialog("不能将文本插入文本窗格的起始位置");
ex.printStackTrace();
}
}
/**
* 在头部添加红色文本以显示错误信息
*
* 说明:
* @param msg
* 创建时间:2010-5-3 下午01:45:04
* 修改时间:2010-5-3 下午01:45:04
*/
public void insertRedMsg(String msg,String remoteIp){
try{
String text=getCurrTime()+"(Error of "+remoteIp+")\n"+msg+"\n\n";
doc.insertString(0, text, doc.getStyle(RED_STYLE));
}
catch(Exception ex){
DlgUtil.popupWarningDialog("不能将文本插入文本窗格的起始位置");
ex.printStackTrace();
}
}
public void insertDispatchMsg(String msg,String remoteIp){
try{
String text=getCurrTime()+"(Dispatched by "+remoteIp+")\n"+msg+"\n\n";
doc.insertString(0, text, doc.getStyle(RED_STYLE));
}
catch(Exception ex){
DlgUtil.popupWarningDialog("不能将文本插入文本窗格的起始位置");
ex.printStackTrace();
}
}
/**
* 在头部添加蓝色信息以显示客户端送来的request
*
* 说明:
* @param msg
* 创建时间:2010-12-28 上午11:54:37
*/
public void insertBlueMsg(String msg,String remoteIp){
try{
String text=getCurrTime()+"(Request from "+remoteIp+")\n"+msg+"\n\n";
doc.insertString(0, text, doc.getStyle(BLUE_STYLE));
}
catch(Exception ex){
DlgUtil.popupWarningDialog("不能将文本插入文本窗格的起始位置");
ex.printStackTrace();
}
}
/**
*
* 插入收到的消息
* 说明:
* @param msg
* @param fromUser
* 创建时间:2010-12-30 下午11:49:22
*/
public void insertReceivedMsg(String msg,String fromUser){
try{
String text=getCurrTime()+"(Receive message from "+fromUser+")\n"+msg+"\n\n";
doc.insertString(0, text, doc.getStyle(BLUE_STYLE));
}
catch(Exception ex){
DlgUtil.popupWarningDialog("不能将文本插入文本窗格的起始位置");
ex.printStackTrace();
}
}
/**
* 取得当前日期时间
*/
private static String getCurrTime() {
Date date = new Date();
Format formatter = new SimpleDateFormat("HH:mm:ss>");
return formatter.format(date);
}
/**
* 添加Undo,Redo,Shift+Tab的处理
*
* 说明:
* 创建时间:2010-5-6 上午11:37:38
* 修改时间:2010-5-6 上午11:37:38
*/
public void addActionMap() {
/**
* Undo的处理
*/
String undoText="Undo";
getActionMap().put(undoText, new AbstractAction(undoText) {
private static final long serialVersionUID = -5768831351483901728L;
public void actionPerformed(ActionEvent evt) {
try {
if (undo.canUndo()) {
undo.undo();
}
} catch (CannotUndoException e) {
}
}
});
getInputMap().put(KeyStroke.getKeyStroke("control Z"), undoText);
/**
* Redo的处理
*/
String redoText="Redo";
getActionMap().put(redoText, new AbstractAction(redoText) {
private static final long serialVersionUID = -6920959884440395654L;
public void actionPerformed(ActionEvent evt) {
try {
if (undo.canRedo()) {
undo.redo();
}
} catch (CannotRedoException e) {
}
}
});
getInputMap().put(KeyStroke.getKeyStroke("control R"), redoText);
// 2009年1月23日8:12:13
// 缩退处理
String tabText = "Tab";
getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB,0), tabText);
// 设置缩退处理的动作
getActionMap().put(tabText,
new TextAction(tabText) {
private static final long serialVersionUID = -66324231604787553L;
public void actionPerformed(ActionEvent evt) {
tabSelection(getTextComponent(evt));
}
}
);
// 2009年1月23日8:29:41
// 缩进处理
String shiftTabText = "ShiftTab";
// 下面的1表示Shift键按下
getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB,1), shiftTabText);
// 设置缩进处理的动作
getActionMap().put(shiftTabText,
new TextAction(shiftTabText) {
private static final long serialVersionUID = 43544531604787553L;
public void actionPerformed(ActionEvent evt) {
shiftTabSelection(getTex
没有合适的资源?快使用搜索试试~ 我知道了~
java nio im(server+client)
共73个文件
java:56个
jar:7个
gif:4个
5星 · 超过95%的资源 需积分: 9 54 下载量 148 浏览量
2013-11-20
14:27:54
上传
评论 1
收藏 1.28MB RAR 举报
温馨提示
java基于nio的通信实例,带UML结构图及server、client源码。
资源推荐
资源详情
资源评论
收起资源包目录
IMSample1.00.rar (73个子文件)
IMSample
bin
res
server.gif 153B
users.xml 503B
xuanbutton_active.gif 2KB
xuanbutton_normal.gif 1KB
client.gif 609B
uml
Hybrid.sqd 73KB
HybridCompleted.sqd 76KB
.settings
org.hibernate.eclipse.console.prefs 118B
src
com
heyang
base
mvc
BaseCtrl.java 1KB
panel
BasePanel.java 3KB
dlg
BaseDialog.java 5KB
window
BaseWindow.java 4KB
biz
client
ClientUtil.java 4KB
register
main
ctrl
ClientCtrl.java 9KB
model
ClientModel.java 4KB
Receiver.java 3KB
view
ClientView.java 5KB
login
RegisterDialog.java 9KB
ProbeDialog.java 9KB
LoginDialog.java 9KB
server
ctrl
ServerCtrl.java 3KB
model
ServerModel.java 7KB
Communicator.java 9KB
DispatchMsgThread.java 3KB
LoginUser.java 1KB
test
TestClientSocket.java 11KB
view
ServerView.java 7KB
InputTextPane.java 11KB
common
cipher
IMMsgDecryptException.java 445B
IMMsgDecrypter.java 3KB
IMMsgEncrypter.java 2KB
IMMsgEncryptException.java 445B
code
AESSecurityCoder.java 3KB
Base64SecurityUtil.java 1KB
RSASecurityCoder.java 4KB
check
RegexCheckGroup.java 1KB
RegexConstants.java 3KB
CheckItem.java 2KB
gui
panel
PicturePanel.java 2KB
menu
BaseMenu.java 353B
dialog
TextDialog.java 2KB
intro
IntroPassword.java 2KB
IntroComboBox.java 6KB
IntroText.java 4KB
IntroLabel.java 3KB
area
CityComboBox.java 2KB
ProvinceComboBox.java 2KB
CountyComboBox.java 3KB
IntroBase.java 9KB
IntroTextArea.java 2KB
IntroPanel.java 1KB
button
XuanButton.java 4KB
network
NetworkInterfaceProber.java 4KB
RemotePortTestor.java 5KB
Pinger.java 3KB
LocalIPFetcher.java 2KB
ExternalIpAddressFetcher.java 4KB
RunServer.java 342B
RunClient.java 367B
util
DlgUtil.java 10KB
CommonUtil.java 523B
AESSecurityUtil.java 3KB
RSASecurityCoder.java 3KB
ResourceUtil.java 1KB
.project 384B
.classpath 714B
lib
log4j-1.2.14.jar 359KB
commons-logging-1.0.4.jar 37KB
dom4j-1.6.1.jar 307KB
jaxen-1.1-beta-9.jar 227KB
commons-codec-1.4.jar 57KB
commons-dbcp-1.2.2.jar 119KB
commons-lang-2.3.jar 240KB
共 73 条
- 1
资源评论
- ZhuiMengChun2014-06-11学习了,嘿嘿 NIO
- Joson52017-03-30功能很强大,学习了
zzkf2012
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功