Update ContactList with subtle actions.

git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@4868 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Derek DeMoro
2006-08-09 22:44:08 +00:00
committed by derek
parent cbb03659a5
commit a88eb81a9a
2 changed files with 89 additions and 62 deletions

View File

@ -10,10 +10,16 @@
package org.jivesoftware.spark;
import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.XMPPException;
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.util.StringUtils;
import org.jivesoftware.smackx.Form;
import org.jivesoftware.smackx.MessageEventNotificationListener;
import org.jivesoftware.smackx.muc.MultiUserChat;
import org.jivesoftware.spark.ui.ChatContainer;
import org.jivesoftware.spark.ui.ChatRoom;
@ -31,17 +37,20 @@ import org.jivesoftware.sparkimpl.preference.chat.ChatPreference;
import org.jivesoftware.sparkimpl.preference.chat.ChatPreferences;
import javax.swing.Icon;
import javax.swing.SwingUtilities;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
/**
* Handles the Chat Management of each individual <code>Workspace</code>. The ChatManager is responsible
* for creation and removal of chat rooms, transcripts, and transfers and room invitations.
*/
public class ChatManager {
public class ChatManager implements MessageEventNotificationListener {
private List<MessageFilter> messageFilters = new ArrayList<MessageFilter>();
private List<RoomInvitationListener> invitationListeners = new ArrayList<RoomInvitationListener>();
@ -51,11 +60,26 @@ public class ChatManager {
private List<ContactItemHandler> contactItemHandlers = new ArrayList<ContactItemHandler>();
private Set<String> customList = new HashSet<String>();
/**
* Create a new instance of ChatManager.
*/
public ChatManager() {
chatContainer = new ChatContainer();
// Add a Message Handler
SparkManager.getMessageEventManager().addMessageEventNotificationListener(this);
SparkManager.getConnection().addPacketListener(new PacketListener() {
public void processPacket(final Packet packet) {
if (customList.contains(StringUtils.parseBareAddress(packet.getFrom()))) {
cancelledNotification(packet.getFrom(), "");
}
}
}, new PacketTypeFilter(Message.class));
}
@ -164,7 +188,6 @@ public class ChatManager {
return chatRoom;
}
/**
* Creates a new public Conference Room.
*
@ -305,4 +328,60 @@ public class ChatManager {
return null;
}
// Implemenation of MessageEventListener
public void deliveredNotification(String from, String packetID) {
}
public void displayedNotification(String from, String packetID) {
}
public void composingNotification(final String from, String packetID) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
final ContactList contactList = SparkManager.getWorkspace().getContactList();
ChatRoom chatRoom = null;
try {
chatRoom = getChatContainer().getChatRoom(StringUtils.parseBareAddress(from));
if (chatRoom != null && chatRoom instanceof ChatRoomImpl) {
((ChatRoomImpl)chatRoom).showTyping(true);
}
}
catch (ChatRoomNotFoundException e) {
}
contactList.setIconFor(from, SparkRes.getImageIcon(SparkRes.SMALL_MESSAGE_EDIT_IMAGE));
customList.add(StringUtils.parseBareAddress(from));
}
});
}
public void offlineNotification(String from, String packetID) {
}
public void cancelledNotification(final String from, String packetID) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
ContactList contactList = SparkManager.getWorkspace().getContactList();
ChatRoom chatRoom = null;
try {
chatRoom = getChatContainer().getChatRoom(StringUtils.parseBareAddress(from));
if (chatRoom != null && chatRoom instanceof ChatRoomImpl) {
((ChatRoomImpl)chatRoom).showTyping(false);
}
}
catch (ChatRoomNotFoundException e) {
}
contactList.useDefaults(from);
customList.remove(StringUtils.parseBareAddress(from));
}
});
}
}

View File

@ -23,7 +23,6 @@ import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.MessageEventManager;
import org.jivesoftware.smackx.MessageEventNotificationListener;
import org.jivesoftware.smackx.MessageEventRequestListener;
import org.jivesoftware.smackx.packet.VCard;
import org.jivesoftware.spark.SparkManager;
@ -69,7 +68,6 @@ public class ChatRoomImpl extends ChatRoom {
private String tabTitle;
private String participantJID;
private String participantNickname;
private ChatRoomMessageManager messageManager;
private MessageEventRequestListener messageEventRequestListener;
boolean isOnline = true;
@ -122,9 +120,6 @@ public class ChatRoomImpl extends ChatRoom {
this.getSplitPane().setRightComponent(null);
getSplitPane().setDividerSize(0);
messageManager = new ChatRoomMessageManager();
SparkManager.getMessageEventManager().addMessageEventNotificationListener(messageManager);
roster = SparkManager.getConnection().getRoster();
presence = roster.getPresence(participantJID);
@ -264,8 +259,6 @@ public class ChatRoomImpl extends ChatRoom {
SparkManager.getChatManager().removeChat(this);
SparkManager.getMessageEventManager().removeMessageEventNotificationListener(messageManager);
SparkManager.getConnection().removePacketListener(this);
}
@ -431,7 +424,6 @@ public class ChatRoomImpl extends ChatRoom {
// Do something with the incoming packet here.
final Message message = (Message)packet;
if (message.getError() != null) {
SparkManager.getMessageEventManager().removeMessageEventNotificationListener(messageManager);
return;
}
@ -464,7 +456,7 @@ public class ChatRoomImpl extends ChatRoom {
participantJID = message.getFrom();
insertMessage(message);
clearTypingNotification();
showTyping(false);
}
}
}
@ -482,52 +474,6 @@ public class ChatRoomImpl extends ChatRoom {
}
/**
* Private implementation of the MessageEventNotificationListener.
*/
private class ChatRoomMessageManager implements MessageEventNotificationListener {
ChatRoomMessageManager() {
}
public void deliveredNotification(String from, String packetID) {
}
public void displayedNotification(String from, String packetID) {
}
public void composingNotification(final String from, String packetID) {
if (!from.startsWith(participantJID)) {
return;
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
String isTypingText = participantNickname + " is typing a message...";
getNotificationLabel().setText(isTypingText);
getNotificationLabel().setIcon(SparkRes.getImageIcon(SparkRes.SMALL_MESSAGE_EDIT_IMAGE));
showTyping(true);
}
});
}
public void offlineNotification(String from, String packetID) {
}
public void cancelledNotification(String from, String packetID) {
clearTypingNotification();
}
}
private void clearTypingNotification() {
// Remove is typing text.
getNotificationLabel().setText("");
getNotificationLabel().setIcon(SparkRes.getImageIcon(SparkRes.BLANK_IMAGE));
showTyping(false);
}
/**
* The current SendField has been updated somehow.
*
@ -611,14 +557,16 @@ public class ChatRoomImpl extends ChatRoom {
}
}
private void showTyping(boolean typing) {
final ContactList contactList = SparkManager.getWorkspace().getContactList();
public void showTyping(boolean typing) {
if (typing) {
contactList.setIconFor(getParticipantJID(), SparkRes.getImageIcon(SparkRes.SMALL_MESSAGE_EDIT_IMAGE));
String isTypingText = participantNickname + " is typing a message...";
getNotificationLabel().setText(isTypingText);
getNotificationLabel().setIcon(SparkRes.getImageIcon(SparkRes.SMALL_MESSAGE_EDIT_IMAGE));
}
else {
contactList.useDefaults(getParticipantJID());
// Remove is typing text.
getNotificationLabel().setText("");
getNotificationLabel().setIcon(SparkRes.getImageIcon(SparkRes.BLANK_IMAGE));
}
}