Migrating.

git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@6231 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Derek DeMoro
2006-11-28 00:45:32 +00:00
committed by derek
parent 65023340f7
commit fb40a61f6e
4 changed files with 100 additions and 36 deletions

View File

@ -164,28 +164,6 @@ public final class SessionManager implements ConnectionListener {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Log.error("Connection closed on error.", ex);
String message = Res.getString("message.disconnected.error");
if (ex instanceof XMPPException) {
XMPPException xmppEx = (XMPPException)ex;
StreamError error = xmppEx.getStreamError();
String reason = error.getCode();
if ("conflict".equals(reason)) {
message = Res.getString("message.disconnected.conflict.error");
}
}
Collection rooms = SparkManager.getChatManager().getChatContainer().getChatRooms();
Iterator iter = rooms.iterator();
while (iter.hasNext()) {
ChatRoom chatRoom = (ChatRoom)iter.next();
chatRoom.getChatInputEditor().setEnabled(false);
chatRoom.getSendButton().setEnabled(false);
chatRoom.getTranscriptWindow().insertNotificationMessage(message);
}
}
});
}

View File

@ -13,6 +13,7 @@ package org.jivesoftware.spark.ui;
import org.jivesoftware.resource.Res;
import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smackx.debugger.EnhancedDebuggerWindow;
@ -62,7 +63,7 @@ import java.util.List;
/**
* The base implementation of all ChatRoom conversations. You would implement this class to have most types of Chat.
*/
public abstract class ChatRoom extends BackgroundPanel implements ActionListener, PacketListener, DocumentListener {
public abstract class ChatRoom extends BackgroundPanel implements ActionListener, PacketListener, DocumentListener, ConnectionListener {
private final JPanel chatPanel;
private final JSplitPane splitPane;
private final ChatAreaSendField chatAreaButton;
@ -230,6 +231,8 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
}
}
});
SparkManager.getConnection().addConnectionListener(this);
}
@ -829,6 +832,22 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
* @return the last time (in system milliseconds) that the room last recieved a message.
*/
public abstract long getLastActivity();
public void connectionClosed() {
}
public void connectionClosedOnError(Exception exception) {
}
public void reconnectingIn(int i) {
}
public void reconnectionSuccessful() {
}
public void reconnectionFailed(Exception exception) {
}
}

View File

@ -15,6 +15,7 @@ import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.RosterEntry;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.FromContainsFilter;
import org.jivesoftware.smack.filter.PacketFilter;
@ -22,6 +23,7 @@ import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.StreamError;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.MessageEventManager;
import org.jivesoftware.smackx.packet.MessageEvent;
@ -36,6 +38,11 @@ import org.jivesoftware.spark.util.ModelUtil;
import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.profile.VCardManager;
import javax.swing.Icon;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.event.DocumentEvent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
@ -46,11 +53,6 @@ import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.swing.Icon;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.event.DocumentEvent;
/**
* This is the Person to Person implementation of <code>ChatRoom</code>
* This room only allows for 1 to 1 conversations.
@ -534,8 +536,6 @@ public class ChatRoomImpl extends ChatRoom {
}
/**
* The last time this chat room sent or receieved a message.
*
@ -565,4 +565,42 @@ public class ChatRoomImpl extends ChatRoom {
public void setSendTypingNotification(boolean isSendTypingNotification) {
this.sendTypingNotification = isSendTypingNotification;
}
public void connectionClosed() {
handleDisconnect();
}
public void connectionClosedOnError(Exception ex) {
handleDisconnect();
String message = Res.getString("message.disconnected.error");
if (ex instanceof XMPPException) {
XMPPException xmppEx = (XMPPException)ex;
StreamError error = xmppEx.getStreamError();
String reason = error.getCode();
if ("conflict".equals(reason)) {
message = Res.getString("message.disconnected.conflict.error");
}
}
getTranscriptWindow().insertErrorMessage(message);
}
public void reconnectionSuccessful() {
Roster roster = SparkManager.getConnection().getRoster();
Presence p = roster.getPresence(getParticipantJID());
if (p != null) {
presence = p;
}
SparkManager.getChatManager().getChatContainer().useTabDefault(this);
}
private void handleDisconnect() {
presence = null;
getChatInputEditor().setEnabled(false);
getSendButton().setEnabled(false);
SparkManager.getChatManager().getChatContainer().useTabDefault(this);
}
}

View File

@ -20,6 +20,7 @@ import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.StreamError;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.MessageEventManager;
import org.jivesoftware.smackx.MessageEventNotificationListener;
@ -38,6 +39,12 @@ import org.jivesoftware.spark.ui.conferences.ConferenceRoomInfo;
import org.jivesoftware.spark.util.ModelUtil;
import org.jivesoftware.spark.util.log.Log;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.util.ArrayList;
@ -46,12 +53,6 @@ import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
/**
* GroupChatRoom is the conference chat room UI used to have Multi-User Chats.
*/
@ -984,4 +985,32 @@ public final class GroupChatRoom extends ChatRoom {
public long getLastActivity() {
return lastActivity;
}
public void connectionClosed() {
handleDisconnect();
}
public void connectionClosedOnError(Exception ex) {
handleDisconnect();
String message = Res.getString("message.disconnected.error");
if (ex instanceof XMPPException) {
XMPPException xmppEx = (XMPPException)ex;
StreamError error = xmppEx.getStreamError();
String reason = error.getCode();
if ("conflict".equals(reason)) {
message = Res.getString("message.disconnected.conflict.error");
}
}
getTranscriptWindow().insertErrorMessage(message);
}
private void handleDisconnect() {
getChatInputEditor().setEnabled(false);
getSendButton().setEnabled(false);
SparkManager.getChatManager().getChatContainer().useTabDefault(this);
}
}