updated according to last changes in multi chatting

cusax-fix
Emil Ivov 19 years ago
parent 100e6b17e8
commit 06e7d6239e

@ -20,7 +20,7 @@
/**
* The <tt>ConferenceChatPanel</tt> is the chat panel corresponding to a
* multi user chat.
*
*
* @author Yana Stamcheva
*/
public class ConferenceChatPanel
@ -31,14 +31,14 @@ public class ConferenceChatPanel
ChatRoomParticipantStatusListener
{
private Logger logger = Logger.getLogger(ConferenceChatPanel.class);
private ChatRoom chatRoom;
private ChatWindowManager chatWindowManager;
/**
* Creates an instance of <tt>ConferenceChatPanel</tt>.
*
*
* @param chatWindow the <tt>ChatWindow</tt> that contains this chat panel
* @param chatRoom the <tt>ChatRoom</tt> object, which provides us the multi
* user chat functionality
@ -46,27 +46,28 @@ public class ConferenceChatPanel
public ConferenceChatPanel(ChatWindow chatWindow, ChatRoom chatRoom)
{
super(chatWindow);
this.chatWindowManager = chatWindow.getMainFrame().getChatWindowManager();
this.chatRoom = chatRoom;
List membersList = chatRoom.getMembers();
for (int i = 0; i < membersList.size(); i ++)
{
getChatContactListPanel().addContact((Contact)membersList.get(i));
}
this.chatRoom.addMessageListener(this);
this.chatRoom.addChatRoomPropertyChangeListener(this);
this.chatRoom.addLocalUserStatusListener(this);
this.chatRoom.addParticipantStatusListener(this);
/** @todo uncomment when the listener is fully implemented */
// this.chatRoom.addParticipantStatusListener(this);
}
/**
* Implements the <tt>ChatPanel.getChatName</tt> method.
*
*
* @return the name of the chat room.
*/
public String getChatName()
@ -76,7 +77,7 @@ public String getChatName()
/**
* Implements the <tt>ChatPanel.getChatIdentifier</tt> method.
*
*
* @return the <tt>ChatRoom</tt>
*/
public Object getChatIdentifier()
@ -86,7 +87,7 @@ public Object getChatIdentifier()
/**
* Implements the <tt>ChatPanel.getChatStatus</tt> method.
*
*
* @return the status of this chat room
*/
public PresenceStatus getChatStatus()
@ -96,28 +97,28 @@ public PresenceStatus getChatStatus()
/**
* Implements the <tt>ChatPanel.loadHistory</tt> method.
* <br>
* <br>
* Loads the history for this chat room.
*/
public void loadHistory()
{
}
/**
* Implements the <tt>ChatPanel.loadHistory(escapedMessageID)</tt> method.
* <br>
* <br>
* Loads the history for this chat room and escapes the last message
* received.
*/
public void loadHistory(String escapedMessageID)
{
// TODO Auto-generated method stub
// TODO Auto-generated method stub
}
/**
* Implements the <tt>ChatPanel.loadPreviousFromHistory</tt> method.
* <br>
* <br>
* Loads the previous "page" in the history.
*/
public void loadPreviousFromHistory()
@ -127,7 +128,7 @@ public void loadPreviousFromHistory()
/**
* Implements the <tt>ChatPanel.loadNextFromHistory</tt> method.
* <br>
* <br>
* Loads the next "page" in the history.
*/
public void loadNextFromHistory()
@ -137,25 +138,25 @@ public void loadNextFromHistory()
/**
* Implements the <tt>ChatPanel.sendMessage</tt> method.
* <br>
* <br>
* Sends a message to the chat room.
*/
protected void sendMessage()
{
{
}
/**
* Implements the <tt>ChatPanel.treatReceivedMessage</tt> method.
* <br>
* <br>
* Treats a received message from the given contact.
*/
public void treatReceivedMessage(Contact sourceContact)
{
{
}
/**
* Implements the <tt>ChatPanel.sendTypingNotification</tt> method.
* <br>
* <br>
* Sends a typing notification.
*/
public int sendTypingNotification(int typingState)
@ -181,75 +182,75 @@ public Date getLastHistoryMsgTimestamp()
/**
* Implements the <tt>ChatRoomMessageListener.messageReceived</tt> method.
* <br>
* <br>
* Obtains the corresponding <tt>ChatPanel</tt> and proccess the message
* there.
*/
public void messageReceived(ChatRoomMessageReceivedEvent evt)
{
ChatRoom sourceChatRoom = (ChatRoom) evt.getSource();
if(!sourceChatRoom.equals(chatRoom))
return;
logger.trace("MESSAGE RECEIVED from contact: "
+ evt.getSourceContact().getAddress());
Contact sourceContact = evt.getSourceContact();
Date date = evt.getTimestamp();
Message message = evt.getSourceMessage();
ChatRoom chatRoom = (ChatRoom) evt.getSource();
ChatPanel chatPanel = chatWindowManager.getChatRoom(chatRoom);
chatPanel.processMessage(
sourceContact.getDisplayName(), date,
Constants.INCOMING_MESSAGE, message.getContent());
Constants.INCOMING_MESSAGE, message.getContent());
chatWindowManager.openChat(chatPanel, false);
GuiActivator.getAudioNotifier()
.createAudio(Sounds.INCOMING_MESSAGE).play();
chatPanel.treatReceivedMessage(sourceContact);
}
/**
* Implements the <tt>ChatRoomMessageListener.messageDelivered</tt> method.
* <br>
* <br>
* Shows the message in the conversation area and clears the write message
* area.
*/
public void messageDelivered(ChatRoomMessageDeliveredEvent evt)
{
ChatRoom sourceChatRoom = (ChatRoom) evt.getSource();
if(!sourceChatRoom.equals(chatRoom))
return;
logger.trace("MESSAGE DELIVERED to contact: "
+ evt.getDestinationContact().getAddress());
Message msg = evt.getSourceMessage();
ChatPanel chatPanel = null;
if(chatWindowManager.isChatOpenedForChatRoom(sourceChatRoom))
chatPanel = chatWindowManager.getChatRoom(sourceChatRoom);
if (chatPanel != null)
{
ProtocolProviderService protocolProvider = evt
.getDestinationContact().getProtocolProvider();
logger.trace("MESSAGE DELIVERED: process message to chat for contact: "
+ evt.getDestinationContact().getAddress());
chatPanel.processMessage(getChatWindow().getMainFrame()
.getAccount(protocolProvider), evt.getTimestamp(),
Constants.OUTGOING_MESSAGE, msg.getContent());
chatPanel.refreshWriteArea();
}
}
@ -257,23 +258,23 @@ public void messageDelivered(ChatRoomMessageDeliveredEvent evt)
/**
* Implements the <tt>ChatRoomMessageListener.messageDeliveryFailed</tt>
* method.
* <br>
* <br>
* In the conversation area show an error message, explaining the problem.
*/
public void messageDeliveryFailed(ChatRoomMessageDeliveryFailedEvent evt)
{
ChatRoom sourceChatRoom = (ChatRoom) evt.getSource();
if(!sourceChatRoom.equals(chatRoom))
return;
String errorMsg = null;
Message sourceMessage = (Message) evt.getSource();
Contact sourceContact = evt.getDestinationContact();
if (evt.getErrorCode()
if (evt.getErrorCode()
== MessageDeliveryFailedEvent.OFFLINE_MESSAGES_NOT_SUPPORTED) {
errorMsg = Messages.getI18NString(
@ -281,7 +282,7 @@ public void messageDeliveryFailed(ChatRoomMessageDeliveryFailedEvent evt)
}
else if (evt.getErrorCode()
== MessageDeliveryFailedEvent.NETWORK_FAILURE) {
errorMsg = Messages.getI18NString("msgNotDelivered").getText();
}
else if (evt.getErrorCode()
@ -292,7 +293,7 @@ else if (evt.getErrorCode()
}
else if (evt.getErrorCode()
== MessageDeliveryFailedEvent.INTERNAL_ERROR) {
errorMsg = Messages.getI18NString(
"msgDeliveryInternalError").getText();
}
@ -300,24 +301,24 @@ else if (evt.getErrorCode()
errorMsg = Messages.getI18NString(
"msgDeliveryFailedUnknownError").getText();
}
ChatPanel chatPanel = chatWindowManager
.getChatRoom(chatRoom);
chatPanel.refreshWriteArea();
chatPanel.processMessage(
sourceContact.getDisplayName(),
new Date(System.currentTimeMillis()),
Constants.OUTGOING_MESSAGE,
sourceMessage.getContent());
chatPanel.processMessage(
sourceContact.getDisplayName(),
new Date(System.currentTimeMillis()),
Constants.ERROR_MESSAGE,
errorMsg);
chatWindowManager.openChat(chatPanel, false);
}
@ -327,11 +328,11 @@ public void chatRoomChanged(ChatRoomPropertyChangeEvent evt)
public void localUserStatusChanged(ChatRoomLocalUserStatusChangeEvent evt)
{
}
public void localUserStatusChanged(ChatRoomParticipantStatusChangeEvent evt)
{
}
}

@ -21,7 +21,7 @@
/**
* The <tt>ChatRoomsList</tt> is the list containing all chat rooms.
*
*
* @author Yana Stamcheva
*/
public class ChatRoomsList
@ -30,32 +30,32 @@ public class ChatRoomsList
MouseListener
{
private Logger logger = Logger.getLogger(ChatRoomsList.class);
private MainFrame mainFrame;
private DefaultListModel listModel = new DefaultListModel();
/**
* Creates an instance of the <tt>ChatRoomsList</tt>.
*
*
* @param mainFrame The main application window.
*/
public ChatRoomsList(MainFrame mainFrame)
{
this.mainFrame = mainFrame;
this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
this.setModel(listModel);
this.setCellRenderer(new ChatRoomsListCellRenderer());
this.addListSelectionListener(this);
this.addMouseListener(this);
}
/**
* Adds a chat server and all its existing chat rooms.
*
*
* @param pps the <tt>ProtocolProviderService</tt> corresponding to the chat
* server
* @param multiUserChatOperationSet the <tt>OperationSetMultiUserChat</tt>
@ -65,24 +65,30 @@ public void addChatServer(ProtocolProviderService pps,
OperationSetMultiUserChat multiUserChatOperationSet)
{
listModel.addElement(pps);
try
{
{
List existingChatRooms
= multiUserChatOperationSet.getExistingChatRooms();
if(existingChatRooms == null)
return;
Iterator i = existingChatRooms.iterator();
while(i.hasNext())
{
ChatRoom chatRoom = (ChatRoom) i.next();
listModel.addElement(chatRoom);
}
}
catch (OperationNotSupportedException ex)
{
logger.error(
"Failed to obtain existing chat rooms for the following server: "
+ pps.getAccountID().getService(), ex);
}
catch (OperationFailedException ex)
{
@ -90,21 +96,22 @@ public void addChatServer(ProtocolProviderService pps,
"Failed to obtain existing chat rooms for the following server: "
+ pps.getAccountID().getService(), ex);
}
}
/**
* Adds a chat room to this list.
*
*
* @param chatRoom the <tt>ChatRoom</tt> to add
*/
public void addChatRoom(ChatRoom chatRoom)
{
listModel.addElement(chatRoom);
listModel.addElement(chatRoom);
}
/**
*
*
* @param pps
* @return
*/
@ -119,16 +126,16 @@ public boolean isChatServerClosed(ProtocolProviderService pps)
public void valueChanged(ListSelectionEvent e)
{
Object o = this.getSelectedValue();
if(o instanceof ChatRoom)
{
{
ChatRoom chatRoom = (ChatRoom) o;
ChatWindowManager chatWindowManager = mainFrame.getChatWindowManager();
ChatPanel chatPanel = chatWindowManager.getChatRoom(chatRoom);
chatWindowManager.openChat(chatPanel, true);
}
}
}
public void mouseClicked(MouseEvent e)
@ -156,7 +163,7 @@ public void mousePressed(MouseEvent e)
{
ProtocolProviderService pps
= (ProtocolProviderService) selectedValue;
if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0)
{
ChatRoomServerRightButtonMenu rightButtonMenu
@ -168,7 +175,7 @@ public void mousePressed(MouseEvent e)
+ mainFrame.getX() + 5, e.getY() + mainFrame.getY()
+ 105);
rightButtonMenu.setVisible(true);
rightButtonMenu.setVisible(true);
}
}
}

@ -1,3 +1,9 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.chatroomslist;
import java.awt.*;
@ -9,104 +15,118 @@
import net.java.sip.communicator.impl.gui.i18n.*;
import net.java.sip.communicator.impl.gui.main.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.*;
public class JoinChannelDialog
extends SIPCommDialog
implements ActionListener
{
private static final Logger logger
= Logger.getLogger(JoinChannelDialog.class);
private JPanel mainPanel = new JPanel(new BorderLayout(5, 5));
private JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
private JPanel centerPanel = new JPanel(new BorderLayout(5, 5));
private JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
private JButton channelListButton
= new JButton(Messages.getI18NString("showChannelsList").getText());
private JLabel channelLabel
= new JLabel(Messages.getI18NString("joinChatRoom").getText() + ":");
private JTextField channelTextField = new JTextField();
private JButton okButton
= new JButton(Messages.getI18NString("ok").getText());
private JButton cancelButton
= new JButton(Messages.getI18NString("cancel").getText());
private MainFrame mainFrame;
private ProtocolProviderService protocolProvider;
public JoinChannelDialog (MainFrame mainFrame,
ProtocolProviderService protocolProvider)
{
super(mainFrame);
this.setSize(400, 300);
this.mainFrame = mainFrame;
this.protocolProvider = protocolProvider;
this.getContentPane().add(mainPanel, BorderLayout.CENTER);
this.getContentPane().add(buttonsPanel, BorderLayout.SOUTH);
buttonsPanel.add(okButton);
buttonsPanel.add(cancelButton);
mainPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
mainPanel.add(centerPanel, BorderLayout.NORTH);
mainPanel.add(southPanel, BorderLayout.CENTER);
centerPanel.add(channelLabel, BorderLayout.WEST);
centerPanel.add(channelTextField, BorderLayout.CENTER);
southPanel.add(channelListButton);
channelTextField.setText("#");
okButton.setName("ok");
cancelButton.setName("cancel");
channelListButton.setName("channelList");
okButton.addActionListener(this);
cancelButton.addActionListener(this);
channelListButton.addActionListener(this);
}
protected void close(boolean isEscaped)
{
{
}
public void actionPerformed(ActionEvent e)
{
JButton button = (JButton) e.getSource();
String buttonName = button.getName();
if(buttonName.equals("ok"))
{
OperationSetMultiUserChat multiChatOpSet
= (OperationSetMultiUserChat) protocolProvider.getOperationSet(
OperationSetMultiUserChat.class);
String chatRoomName = channelTextField.getText();
ChatRoom chatRoom = multiChatOpSet.findRoom(chatRoomName);
ChatRoom chatRoom = null;
try
{
chatRoom = multiChatOpSet.findRoom(chatRoomName);
}
catch (Exception ex)
{
/** @todo handle exceptions being thrown here. */
logger.error("Failed to find room " + chatRoomName
, ex);
}
if(chatRoom != null)
{
try
{
chatRoom.join();
mainFrame.getChatRoomsListPanel().getChatRoomsList()
.addChatRoom(chatRoom);
}
@ -132,11 +152,11 @@ public void actionPerformed(ActionEvent e)
}
else if(buttonName.equals("cancel"))
{
this.dispose();
this.dispose();
}
else if(buttonName.equals("channelList"))
{
}
}
}

Loading…
Cancel
Save