mirror of
https://github.com/igniterealtime/Spark.git
synced 2025-12-01 12:27:58 +00:00
Update framework to handle message interception.
git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@4553 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
@ -23,6 +23,22 @@ import org.jivesoftware.spark.util.log.Log;
|
||||
import org.jivesoftware.sparkimpl.preference.chat.ChatPreference;
|
||||
import org.jivesoftware.sparkimpl.preference.chat.ChatPreferences;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Font;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JComponent;
|
||||
@ -38,21 +54,6 @@ import javax.swing.text.Style;
|
||||
import javax.swing.text.StyleConstants;
|
||||
import javax.swing.text.StyledDocument;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Font;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The <CODE>TranscriptWindow</CODE> class. Provides a default implementation
|
||||
* of a Chat Window. In general, extensions could override this class
|
||||
@ -60,6 +61,7 @@ import java.util.List;
|
||||
*/
|
||||
public class TranscriptWindow extends ChatArea {
|
||||
|
||||
private List<TranscriptWindowInterceptor> interceptors = new ArrayList<TranscriptWindowInterceptor>();
|
||||
|
||||
private ChatPreferences chatPref;
|
||||
private Date lastUpdated;
|
||||
@ -158,6 +160,16 @@ public class TranscriptWindow extends ChatArea {
|
||||
* @param message the message to insert.
|
||||
*/
|
||||
public void insertMessage(String userid, Message message) {
|
||||
|
||||
// Check interceptors.
|
||||
for (TranscriptWindowInterceptor interceptor : interceptors) {
|
||||
boolean handled = interceptor.handleInsertMessage(userid, message);
|
||||
if (handled) {
|
||||
// Do nothing.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String body = message.getBody();
|
||||
|
||||
try {
|
||||
@ -232,6 +244,15 @@ public class TranscriptWindow extends ChatArea {
|
||||
* @param message the message from the customer.
|
||||
*/
|
||||
public void insertOthersMessage(String userid, Message message) {
|
||||
// Check interceptors.
|
||||
for (TranscriptWindowInterceptor in : interceptors) {
|
||||
boolean handled = in.handleOtherMessage(userid, message);
|
||||
if (handled) {
|
||||
// Do nothing.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String body = message.getBody();
|
||||
|
||||
try {
|
||||
@ -499,7 +520,7 @@ public class TranscriptWindow extends ChatArea {
|
||||
writer.write(buf.toString());
|
||||
writer.close();
|
||||
JOptionPane.showMessageDialog(SparkManager.getMainWindow(), "Chat transcript has been saved.",
|
||||
"Chat Transcript Saved", JOptionPane.INFORMATION_MESSAGE);
|
||||
"Chat Transcript Saved", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
@ -517,4 +538,12 @@ public class TranscriptWindow extends ChatArea {
|
||||
return font;
|
||||
}
|
||||
|
||||
public void addTranscriptWindowInterceptor(TranscriptWindowInterceptor interceptor) {
|
||||
interceptors.add(interceptor);
|
||||
}
|
||||
|
||||
public void removeTranscriptWindowInterceptor(TranscriptWindowInterceptor interceptor) {
|
||||
interceptors.remove(interceptor);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user