chatwindow.java
来自「java 开发的sip软电话 源码 jain sip」· Java 代码 · 共 230 行
JAVA
230 行
package net.java.mais.xmpp;
import java.io.File;
import net.java.mais.common.DateHour;
import net.java.mais.common.Utils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.events.ShellListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Shell;
import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.RosterEntry;
import org.jivesoftware.smack.packet.Message;
import softPhone.Interlocutor;
import softPhone.SoftPhonePlugin;
import com.docuverse.swt.flash.FlashPlayer;
import com.docuverse.swt.flash.FlashPlayerListener;
public class ChatWindow implements FlashPlayerListener, DisposeListener, ShellListener, ControlListener{
FlashPlayer player;
Shell shell = null;
Interlocutor interlocutor = null;
RosterEntry re = null;
public Chat chat = null;
public String jid = null;
private XMPPManager xmppManager = null;
private DateHour dh = new DateHour();
private String aux = null;
public void onFSCommand(String param, String value) {
if(param.equals("msg")){
sendMessage(value);
}else if(param.equals("dial")){
xmppManager.xmppListener.handleDialRequest(value);
}
System.out.println("\nFSCommand:\nParam = " + param + " Value = " + value);
}
public void onReadyStateChange(int arg) {
}
public void onProgress(int arg) {
}
private void createFlashApp() {
player = new FlashPlayer(shell, SWT.NONE, this);
// this line loads the flash movie from disk
player.loadMovie(0,(new File(System.getProperty("EXEPATH"))).getAbsolutePath()+Utils.getProperty("net.java.mais.flash.URL")+"chat.swf");
player.setSize(330, 280);
player.activate();
player.setVariable("_root.user",SoftPhonePlugin.userName);
if(re!=null){
player.setVariable("_root.nick",re.getName()!=null?re.getName():re.getUser());
player.setVariable("_root.otherUser",re.getUser());
}else{
player.setVariable("_root.nick",jid);
player.setVariable("_root.otherUser",jid);
}
}
public Shell open (Display display) {
shell = new Shell (display);//|SWT.TITLE|SWT.MIN|SWT.TOOL);
//shell.setImage(new Image(display,"C:\\Documents and Settings\\thiagoc\\workspace\\SoftPhone\\src\\Interface\\icon.bmp"));
//shell.setSize(255, 435);
if(re!=null)
shell.setText(re.getName()!=null?re.getName():re.getUser());
else
shell.setText(jid);
createFlashApp();
shell.setSize(400,320);
setSize();
final Image icon = new Image(display,Utils.getResourceAsStream("icon32.png"));//"C:\\icon.png");
shell.setImage(icon);
shell.open();
shell.addDisposeListener(this);
shell.addShellListener(this);
shell.addControlListener(this);
return shell;
}
public void close(){
shell.dispose();
}
public ChatWindow(Chat c, RosterEntry rEntry, XMPPManager xm){
xmppManager = xm;
re = rEntry;
jid = re.getUser();
chat = c;
System.out.println("CHAT");
SoftPhonePlugin.display.syncExec(
new Runnable() {
public void run(){
open(SoftPhonePlugin.display);
}
}
);
}
public ChatWindow(Chat c, String rEntry, XMPPManager xm){
xmppManager = xm;
re = null;
//rEntry;
jid = rEntry;
chat = c;
System.out.println("CHAT");
SoftPhonePlugin.display.syncExec(
new Runnable() {
public void run(){
open(SoftPhonePlugin.display);
}
}
);
}
public void receiveMessage(String msg){
aux = msg;
SoftPhonePlugin.display.syncExec(
new Runnable() {
public void run(){
try{
// shell.setEnabled(false);
System.out.println("BEFORE 1");
if(re!=null)
player.setVariable("_root.watcher.newmessage","["+ dh.getHour() + "] "+ "<B>"+(re.getName()!=null?re.getName():re.getUser().split("@")[0])+"</B>: "+aux);
else
player.setVariable("_root.watcher.newmessage","["+ dh.getHour() + "] "+ "<B>"+(jid)+"</B>: "+aux);
System.out.println("AFTER");
}catch(Exception e){
System.out.println("Erro Chat!!!");
}finally{
// shell.setEnabled(true);
shell.moveBelow(null);
shell.setVisible(true);
if(!xmppManager.getShow().equals("dnd"))
// shell.getDisplay().getActiveShell()
shell.forceActive();
shell.moveAbove(null);
// shell.forceFocus();
}
}
}
);
/*SoftPhonePlugin.display.syncExec(
new Runnable() {
public void run(){
shell.moveAbove(null);
shell.setVisible(true);
shell.forceActive();
}
}
);*/
}
public void sendMessage(String msg){
try{
chat.sendMessage(msg);
}catch(Exception e){
System.out.println("ERRO SM: " + e.toString());
}
}
public void sendMessage(Message msg){
try{
chat.sendMessage(msg);
}catch(Exception e){
System.out.println("ERRO SM: " + e.toString());
}
}
// DisposeListeners
public void widgetDisposed(DisposeEvent evt){
shell.setVisible(false);
return;
//xmppManager.removeChat(jid);
}
// ShellListeners
public void shellActivated(ShellEvent e){}
public void shellClosed(ShellEvent e){
e.doit=false;
shell.setVisible(false);
//xmppManager.removeChat(jid);
}
public void shellDeactivated(ShellEvent e){}
public void shellDeiconified(ShellEvent e){}
public void shellIconified(ShellEvent e){}
// ControlListeners
public void controlResized(ControlEvent e){
setSize();
}
public void setSize(){
player.setVariable("_root.watcher.newsize",String.valueOf(shell.getClientArea().width)+","+String.valueOf(shell.getClientArea().height));
player.setSize(shell.getClientArea().width,shell.getClientArea().height);
}
public void controlMoved(ControlEvent e){
}
// Key Listeners
public void keyPressed(KeyEvent e){
System.out.println("KEY: "+e.character);
}
public void keyReleased(KeyEvent e){
System.out.println("KEY: "+e.character);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?