mirror of https://github.com/sipwise/jitsi.git
rename message package to chat and change the structure of classes in order to allow conference chatting
parent
5a140d2c02
commit
bb7cba9505
@ -0,0 +1,205 @@
|
||||
/*
|
||||
* 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.chat;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import net.java.sip.communicator.impl.gui.customcontrols.*;
|
||||
import net.java.sip.communicator.impl.gui.utils.*;
|
||||
import net.java.sip.communicator.service.contactlist.*;
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
|
||||
/**
|
||||
* The <tt>ChatContactListPanel</tt> is the panel added on the right of the
|
||||
* chat conversation area, containing information for all contacts
|
||||
* participating the chat. It contains a list of <tt>ChatContactPanel</tt>s.
|
||||
* Each of these panels is containing the name, status, etc. of only one
|
||||
* <tt>MetaContact</tt> or simple <tt>Contact</tt>. There is also a button,
|
||||
* which allows to add new contact to the chat.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class ChatContactListPanel
|
||||
extends JPanel
|
||||
{
|
||||
private JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
||||
|
||||
private JScrollPane contactsScrollPane = new JScrollPane();
|
||||
|
||||
private JPanel mainPanel = new JPanel(new BorderLayout());
|
||||
|
||||
private SIPCommButton addToChatButton = new SIPCommButton(
|
||||
ImageLoader.getImage(ImageLoader.ADD_TO_CHAT_BUTTON),
|
||||
ImageLoader.getImage(ImageLoader.ADD_TO_CHAT_ROLLOVER_BUTTON),
|
||||
ImageLoader.getImage(ImageLoader.ADD_TO_CHAT_ICON), null);
|
||||
|
||||
|
||||
private JPanel contactsPanel = new JPanel();
|
||||
|
||||
private Hashtable contacts = new Hashtable();
|
||||
|
||||
private ChatPanel chatPanel;
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>ChatContactListPanel</tt>.
|
||||
*/
|
||||
public ChatContactListPanel(ChatPanel chatPanel)
|
||||
{
|
||||
super(new BorderLayout(5, 5));
|
||||
|
||||
this.chatPanel = chatPanel;
|
||||
|
||||
this.contactsPanel.setLayout(
|
||||
new BoxLayout(contactsPanel, BoxLayout.Y_AXIS));
|
||||
|
||||
this.setMinimumSize(new Dimension(150, 100));
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a simple <tt>Contact</tt> to the list of contacts contained in the
|
||||
* chat.
|
||||
*
|
||||
* @param contact the <tt>Contact</tt> to be added
|
||||
*/
|
||||
public void addContact(Contact contact)
|
||||
{
|
||||
ChatContactPanel chatContactPanel = new ChatContactPanel(
|
||||
chatPanel, contact);
|
||||
|
||||
this.contactsPanel.add(chatContactPanel);
|
||||
|
||||
this.contacts.put(contact, chatContactPanel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a <tt>MetaContact</tt> to the list of contacts contained in the chat.
|
||||
*
|
||||
* @param metaContact the <tt>MetaContact</tt> to be added
|
||||
* @param contact the subcontact which is initially selected
|
||||
*/
|
||||
public void addContact(MetaContact metaContact, Contact contact)
|
||||
{
|
||||
ChatContactPanel chatContactPanel = new ChatContactPanel(
|
||||
chatPanel, metaContact, contact);
|
||||
|
||||
this.contactsPanel.add(chatContactPanel);
|
||||
|
||||
this.contacts.put(metaContact, chatContactPanel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the <tt>ChatContactListPanel</tt>.
|
||||
*/
|
||||
private void init()
|
||||
{
|
||||
this.contactsPanel.setLayout(new BoxLayout(this.contactsPanel,
|
||||
BoxLayout.Y_AXIS));
|
||||
|
||||
this.mainPanel.add(contactsPanel, BorderLayout.NORTH);
|
||||
this.contactsScrollPane.getViewport().add(this.mainPanel);
|
||||
|
||||
this.buttonPanel.add(addToChatButton);
|
||||
|
||||
this.add(contactsScrollPane, BorderLayout.CENTER);
|
||||
this.add(buttonPanel, BorderLayout.SOUTH);
|
||||
|
||||
// Disable all unused buttons.
|
||||
this.addToChatButton.setEnabled(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the status icon of the contact in this
|
||||
* <tt>ChatContactListPanel</tt>.
|
||||
* @param contact the <tt>Contact</tt>, which should be updated
|
||||
*/
|
||||
public void updateContactStatus(Contact contact)
|
||||
{
|
||||
ChatContactPanel chatContactPanel = null;
|
||||
if(contacts.containsKey(contact))
|
||||
{
|
||||
chatContactPanel = (ChatContactPanel)contacts.get(contact);
|
||||
|
||||
chatContactPanel.setStatusIcon(contact.getPresenceStatus());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the status icon of the contact in this
|
||||
* <tt>ChatContactListPanel</tt>.
|
||||
* @param metaContact the <tt>MetaContact</tt>, which should be updated
|
||||
*/
|
||||
public void updateContactStatus(MetaContact metaContact)
|
||||
{
|
||||
ChatContactPanel chatContactPanel = null;
|
||||
if(contacts.containsKey(metaContact))
|
||||
{
|
||||
chatContactPanel = (ChatContactPanel)contacts.get(metaContact);
|
||||
|
||||
chatContactPanel.setStatusIcon(
|
||||
metaContact.getDefaultContact().getPresenceStatus());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the given protocol contact chat panel in the list. Disables or
|
||||
* enable buttons, according to the functionalities supported by this
|
||||
* contact.
|
||||
*
|
||||
* @param contact the <tt>Contact</tt>, which chat contact panel to update
|
||||
*/
|
||||
public void updateProtocolContact(Contact contact)
|
||||
{
|
||||
ChatContactPanel chatContactPanel = null;
|
||||
if(contacts.containsKey(contact))
|
||||
{
|
||||
chatContactPanel = (ChatContactPanel)contacts.get(contact);
|
||||
|
||||
chatContactPanel.updateProtocolContact(contact);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* In the corresponding <tt>ChatContactPanel</tt> changes the name of the
|
||||
* given <tt>Contact</tt>.
|
||||
*
|
||||
* @param contact the <tt>Contact</tt>, which has been renamed
|
||||
*/
|
||||
public void renameContact(Contact contact)
|
||||
{
|
||||
ChatContactPanel chatContactPanel = null;
|
||||
if(contacts.containsKey(contact))
|
||||
{
|
||||
chatContactPanel = (ChatContactPanel)contacts.get(contact);
|
||||
|
||||
chatContactPanel.renameContact(contact.getDisplayName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* In the corresponding <tt>ChatContactPanel</tt> changes the name of the
|
||||
* given <tt>MetaContact</tt>.
|
||||
*
|
||||
* @param contact the <tt>MetaContact</tt>, which has been renamed
|
||||
*/
|
||||
public void renameContact(MetaContact contact)
|
||||
{
|
||||
ChatContactPanel chatContactPanel = null;
|
||||
if(contacts.containsKey(contact))
|
||||
{
|
||||
chatContactPanel = (ChatContactPanel)contacts.get(contact);
|
||||
|
||||
chatContactPanel.renameContact(contact.getDisplayName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* 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.chat;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public interface ChatConversationContainer
|
||||
{
|
||||
public Window getConversationContainerWindow();
|
||||
|
||||
public void setStatusMessage(String statusMessage);
|
||||
}
|
||||
@ -0,0 +1,166 @@
|
||||
/*
|
||||
* 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.chat;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import net.java.sip.communicator.impl.gui.i18n.*;
|
||||
import net.java.sip.communicator.impl.gui.utils.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
/**
|
||||
* The <tt>ChatSendPanel</tt> is the panel in the bottom of the chat. It
|
||||
* contains the send button, the status panel, where typing notifications are
|
||||
* shown and the selector box, where the protocol specific contact is choosen.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class ChatSendPanel
|
||||
extends JPanel
|
||||
implements ActionListener
|
||||
{
|
||||
private Logger logger = Logger.getLogger(ChatSendPanel.class);
|
||||
|
||||
private I18NString sendString = Messages.getI18NString("send");
|
||||
|
||||
private JButton sendButton = new JButton(sendString.getText());
|
||||
|
||||
private JPanel statusPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
|
||||
private JPanel sendPanel = new JPanel(new BorderLayout(3, 0));
|
||||
|
||||
private JLabel statusLabel = new JLabel();
|
||||
|
||||
private ChatPanel chatPanel;
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>ChatSendPanel</tt>.
|
||||
*
|
||||
* @param metaContact the meta contact that this chat panel is about
|
||||
* @param protocolContact the currently selected default protoco contact.
|
||||
* @param chatPanel The parent <tt>ChatPanel</tt>.
|
||||
*/
|
||||
public ChatSendPanel(ChatPanel chatPanel)
|
||||
{
|
||||
super(new BorderLayout(5, 5));
|
||||
|
||||
this.chatPanel = chatPanel;
|
||||
|
||||
this.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
|
||||
|
||||
this.statusPanel.add(statusLabel);
|
||||
|
||||
this.sendPanel.add(sendButton, BorderLayout.EAST);
|
||||
|
||||
this.add(statusPanel, BorderLayout.CENTER);
|
||||
this.add(sendPanel, BorderLayout.EAST);
|
||||
|
||||
this.sendButton.addActionListener(this);
|
||||
this.sendButton.setMnemonic(sendString.getMnemonic());
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines actions when send button is pressed.
|
||||
*
|
||||
* @param e The <tt>ActionEvent</tt> object.
|
||||
*/
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
if (!chatPanel.isWriteAreaEmpty())
|
||||
{
|
||||
chatPanel.sendMessage();
|
||||
}
|
||||
//make sure the focus goes back to the write area
|
||||
chatPanel.requestFocusInWriteArea();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the send button.
|
||||
*
|
||||
* @return The send button.
|
||||
*/
|
||||
public JButton getSendButton()
|
||||
{
|
||||
return sendButton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the message text to the status panel in the bottom of the chat
|
||||
* window. Used to show typing notification messages, links' hrefs, etc.
|
||||
*
|
||||
* @param statusMessage The message text to be displayed.
|
||||
*/
|
||||
public void setStatusMessage(String statusMessage)
|
||||
{
|
||||
int stringWidth = GuiUtils.getStringWidth(statusLabel, statusMessage);
|
||||
|
||||
while (stringWidth > statusPanel.getWidth() - 10) {
|
||||
if (statusMessage.endsWith("...")) {
|
||||
statusMessage = statusMessage.substring(0,
|
||||
statusMessage.indexOf("...") - 1).concat("...");
|
||||
}
|
||||
else {
|
||||
statusMessage = statusMessage.substring(0,
|
||||
statusMessage.length() - 3).concat("...");
|
||||
}
|
||||
stringWidth = GuiUtils.getStringWidth(statusLabel, statusMessage);
|
||||
}
|
||||
statusLabel.setText(statusMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the <code>javax.swing.JComponent.paint()</code> to provide a
|
||||
* new round border for the status panel.
|
||||
*
|
||||
* @param g The Graphics object.
|
||||
*/
|
||||
public void paint(Graphics g)
|
||||
{
|
||||
AntialiasingManager.activateAntialiasing(g);
|
||||
|
||||
super.paint(g);
|
||||
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
|
||||
g2.setColor(Constants.MOVER_START_COLOR);
|
||||
g2.setStroke(new BasicStroke(1f));
|
||||
|
||||
g2.drawRoundRect(3, 4, this.statusPanel.getWidth() - 2,
|
||||
this.statusPanel.getHeight() - 2, 8, 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the parent <tt>ChatPanel</tt>.
|
||||
* @return the parent <tt>ChatPanel</tt>
|
||||
*/
|
||||
public ChatPanel getChatPanel()
|
||||
{
|
||||
return chatPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the main container. Used by the single user chat panel to add
|
||||
* here the "send via" selector box.
|
||||
* @return the main container
|
||||
*/
|
||||
public JPanel getSendPanel()
|
||||
{
|
||||
return sendPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status panel contained in this panel.
|
||||
* @return the status panel contained in this panel
|
||||
*/
|
||||
public JPanel getStatusPanel()
|
||||
{
|
||||
return statusPanel;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,647 @@
|
||||
/*
|
||||
* 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.chat;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import net.java.sip.communicator.impl.gui.*;
|
||||
import net.java.sip.communicator.impl.gui.customcontrols.*;
|
||||
import net.java.sip.communicator.impl.gui.i18n.*;
|
||||
import net.java.sip.communicator.impl.gui.main.*;
|
||||
import net.java.sip.communicator.impl.gui.utils.*;
|
||||
import net.java.sip.communicator.service.contactlist.*;
|
||||
import net.java.sip.communicator.service.contactlist.event.*;
|
||||
import net.java.sip.communicator.service.msghistory.*;
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
import net.java.sip.communicator.service.protocol.event.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
/**
|
||||
* The <tt>MetaContactChatPanel</tt> is the single user chat <tt>ChatPanel</tt>.
|
||||
* It extends the <tt>ChatPanel</tt> in order to provide to it single user chat
|
||||
* functionalities
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class MetaContactChatPanel
|
||||
extends ChatPanel
|
||||
implements ContactPresenceStatusListener,
|
||||
MetaContactListListener
|
||||
{
|
||||
|
||||
private static final Logger logger = Logger
|
||||
.getLogger(MetaContactChatPanel.class.getName());
|
||||
|
||||
private MetaContact metaContact;
|
||||
|
||||
private Date firstHistoryMsgTimestamp;
|
||||
|
||||
private Date lastHistoryMsgTimestamp;
|
||||
|
||||
MessageHistoryService msgHistory
|
||||
= GuiActivator.getMsgHistoryService();
|
||||
|
||||
private JLabel sendViaLabel = new JLabel(
|
||||
Messages.getI18NString("sendVia").getText());
|
||||
|
||||
private ProtocolContactSelectorBox contactSelectorBox;
|
||||
|
||||
/**
|
||||
* Creates a <tt>MetaContactChatPanel</tt> which is added to the given chat
|
||||
* window.
|
||||
*
|
||||
* @param chatWindow The parent window of this chat panel.
|
||||
* @param metaContact the meta contact that this chat is about.
|
||||
* @param protocolContact The subContact which is selected ins
|
||||
* the chat.
|
||||
*/
|
||||
public MetaContactChatPanel( ChatWindow chatWindow,
|
||||
MetaContact metaContact,
|
||||
Contact protocolContact)
|
||||
{
|
||||
super(chatWindow);
|
||||
|
||||
this.metaContact = metaContact;
|
||||
|
||||
//Add the contact to the list of contacts contained in this panel
|
||||
getChatContactListPanel().addContact(metaContact, protocolContact);
|
||||
|
||||
//Load the history period, to initialize the firstMessageTimestamp and
|
||||
//the lastMessageTimeStamp variables. Used to disable/enable history
|
||||
//flash buttons in the chat window tool bar.
|
||||
new Thread(){
|
||||
public void run(){
|
||||
loadHistoryPeriod();
|
||||
}
|
||||
}.start();
|
||||
|
||||
//For each subcontact in the given MetaContact adds a
|
||||
//ContactPresenceStatusListener in order to have always the contact
|
||||
//current status in the chat panel
|
||||
Iterator protocolContacts = metaContact.getContacts();
|
||||
|
||||
while(protocolContacts.hasNext())
|
||||
{
|
||||
Contact subContact = (Contact) protocolContacts.next();
|
||||
|
||||
chatWindow.getMainFrame()
|
||||
.getProtocolPresenceOpSet(subContact.getProtocolProvider())
|
||||
.addContactPresenceStatusListener(this);
|
||||
}
|
||||
|
||||
//Obtains the MetaContactListService and adds itself to it as a
|
||||
//listener of all events concerning the contact list.
|
||||
chatWindow.getMainFrame().getContactList()
|
||||
.addMetaContactListListener(this);
|
||||
|
||||
//Initializes the "send via" selector box and adds it to the send panel
|
||||
contactSelectorBox = new ProtocolContactSelectorBox(
|
||||
this, metaContact, protocolContact);
|
||||
|
||||
getChatSendPanel().getSendPanel()
|
||||
.add(contactSelectorBox, BorderLayout.CENTER);
|
||||
getChatSendPanel().getSendPanel()
|
||||
.add(sendViaLabel, BorderLayout.WEST);
|
||||
|
||||
//Enables to change the protocol provider by simply pressing the Ctrl-P
|
||||
//key combination
|
||||
ActionMap amap = this.getActionMap();
|
||||
|
||||
amap.put("ChangeProtocol", new ChangeProtocolAction());
|
||||
|
||||
InputMap imap = this.getInputMap(
|
||||
JComponent.WHEN_IN_FOCUSED_WINDOW);
|
||||
|
||||
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_P,
|
||||
KeyEvent.CTRL_DOWN_MASK), "ChangeProtocol");
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads history for the chat meta contact in a separate thread. Implements
|
||||
* the <tt>ChatPanel.loadHistory</tt> method.
|
||||
*/
|
||||
public void loadHistory()
|
||||
{
|
||||
new Thread() {
|
||||
public void run() {
|
||||
Collection historyList = msgHistory.findLast(
|
||||
metaContact, Constants.CHAT_HISTORY_SIZE);
|
||||
|
||||
if(historyList.size() > 0) {
|
||||
class ProcessHistory implements Runnable {
|
||||
Collection historyList;
|
||||
ProcessHistory(Collection historyList)
|
||||
{
|
||||
this.historyList = historyList;
|
||||
}
|
||||
public void run()
|
||||
{
|
||||
processHistory(historyList, null);
|
||||
}
|
||||
}
|
||||
SwingUtilities.invokeLater(new ProcessHistory(historyList));
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads history messages ignoring the message given by the
|
||||
* escapedMessageID. Implements the
|
||||
* <tt>ChatPanel.loadHistory(String)</tt> method.
|
||||
*
|
||||
* @param escapedMessageID The id of the message that should be ignored.
|
||||
*/
|
||||
public void loadHistory(String escapedMessageID)
|
||||
{
|
||||
Collection historyList = msgHistory.findLast(
|
||||
metaContact, Constants.CHAT_HISTORY_SIZE);
|
||||
|
||||
processHistory(historyList, escapedMessageID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads history period dates for the current chat.
|
||||
*/
|
||||
private void loadHistoryPeriod()
|
||||
{
|
||||
MessageHistoryService msgHistory
|
||||
= GuiActivator.getMsgHistoryService();
|
||||
|
||||
Collection firstMessage = msgHistory
|
||||
.findFirstMessagesAfter(metaContact, new Date(0), 1);
|
||||
|
||||
if(firstMessage.size() > 0) {
|
||||
|
||||
Iterator i = firstMessage.iterator();
|
||||
|
||||
Object o = i.next();
|
||||
|
||||
if(o instanceof MessageDeliveredEvent) {
|
||||
MessageDeliveredEvent evt
|
||||
= (MessageDeliveredEvent)o;
|
||||
|
||||
this.firstHistoryMsgTimestamp = evt.getTimestamp();
|
||||
}
|
||||
else if(o instanceof MessageReceivedEvent) {
|
||||
MessageReceivedEvent evt = (MessageReceivedEvent)o;
|
||||
|
||||
this.firstHistoryMsgTimestamp = evt.getTimestamp();
|
||||
}
|
||||
|
||||
Collection lastMessage = msgHistory
|
||||
.findLastMessagesBefore(metaContact, new Date(Long.MAX_VALUE), 1);
|
||||
|
||||
Iterator i1 = lastMessage.iterator();
|
||||
|
||||
Object o1 = i1.next();
|
||||
|
||||
if(o1 instanceof MessageDeliveredEvent) {
|
||||
MessageDeliveredEvent evt
|
||||
= (MessageDeliveredEvent)o1;
|
||||
|
||||
this.lastHistoryMsgTimestamp = evt.getTimestamp();
|
||||
}
|
||||
else if(o1 instanceof MessageReceivedEvent) {
|
||||
MessageReceivedEvent evt = (MessageReceivedEvent)o1;
|
||||
|
||||
this.lastHistoryMsgTimestamp = evt.getTimestamp();
|
||||
}
|
||||
}
|
||||
|
||||
getChatWindow().getMainToolBar().changeHistoryButtonsState(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the datetime of the first message in history fot this chat.
|
||||
*/
|
||||
public Date getFirstHistoryMsgTimestamp()
|
||||
{
|
||||
return firstHistoryMsgTimestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the datetime of the last message in history fot this chat.
|
||||
*/
|
||||
public Date getLastHistoryMsgTimestamp()
|
||||
{
|
||||
return lastHistoryMsgTimestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of this chat.
|
||||
*/
|
||||
public String getChatName()
|
||||
{
|
||||
return metaContact.getDisplayName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the identifier of this chat.
|
||||
*/
|
||||
public Object getChatIdentifier()
|
||||
{
|
||||
return metaContact;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <tt>PresenceStatus</tt> of the default contact for this chat
|
||||
* panel. Implements the <tt>ChatPanel.getChatStatus()</tt>.
|
||||
*
|
||||
* @return the <tt>PresenceStatus</tt> of the default contact for this chat
|
||||
* panel.
|
||||
*/
|
||||
public PresenceStatus getChatStatus()
|
||||
{
|
||||
return this.metaContact.getDefaultContact().getPresenceStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the
|
||||
* <tt>ContactPresenceStatusListener.contactPresenceStatusChanged</tt>.
|
||||
* Updates all status related icons in this chat panel.
|
||||
*/
|
||||
public void contactPresenceStatusChanged(
|
||||
ContactPresenceStatusChangeEvent evt)
|
||||
{
|
||||
Contact sourceContact = evt.getSourceContact();
|
||||
|
||||
MainFrame mainFrame = getChatWindow().getMainFrame();
|
||||
|
||||
MetaContact sourceMetaContact = mainFrame
|
||||
.getContactList().findMetaContactByContact(sourceContact);
|
||||
|
||||
if (sourceMetaContact != null && metaContact.equals(sourceMetaContact))
|
||||
{
|
||||
contactSelectorBox.updateContactStatus(sourceContact);
|
||||
|
||||
PresenceStatus status = contactSelectorBox
|
||||
.getSelectedProtocolContact().getPresenceStatus();
|
||||
|
||||
getChatContactListPanel().updateContactStatus(metaContact);
|
||||
|
||||
String message = getChatConversationPanel().processMessage(
|
||||
this.metaContact.getDisplayName(),
|
||||
new Date(System.currentTimeMillis()),
|
||||
Constants.SYSTEM_MESSAGE,
|
||||
Messages.getI18NString("statusChangedChatMessage",
|
||||
new String[]{status.getStatusName()}).getText());
|
||||
|
||||
getChatConversationPanel().appendMessageToEnd(message);
|
||||
|
||||
if(Constants.TABBED_CHAT_WINDOW)
|
||||
{
|
||||
if (getChatWindow().getChatTabCount() > 0) {
|
||||
getChatWindow().setTabIcon(this,
|
||||
new ImageIcon(Constants.getStatusIcon(status)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <tt>ChatPanel.sendMessage</tt> method. Obtains the
|
||||
* appropriate operation set and sends the message, contained in the write
|
||||
* area, through it.
|
||||
*/
|
||||
protected void sendMessage()
|
||||
{
|
||||
Contact contact = (Contact) contactSelectorBox.getMenu()
|
||||
.getSelectedObject();
|
||||
|
||||
OperationSetBasicInstantMessaging im
|
||||
= (OperationSetBasicInstantMessaging) contact.getProtocolProvider()
|
||||
.getOperationSet(OperationSetBasicInstantMessaging.class);
|
||||
|
||||
OperationSetTypingNotifications tn
|
||||
= (OperationSetTypingNotifications) contact.getProtocolProvider()
|
||||
.getOperationSet(OperationSetTypingNotifications.class);
|
||||
|
||||
String body = this.getTextFromWriteArea();
|
||||
Message msg = im.createMessage(body);
|
||||
|
||||
if (tn != null)
|
||||
{
|
||||
// Send TYPING STOPPED event before sending the message
|
||||
getChatWritePanel().stopTypingTimer();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
im.sendInstantMessage(contact, msg);
|
||||
}
|
||||
catch (IllegalStateException ex)
|
||||
{
|
||||
logger.error("Failed to send message.", ex);
|
||||
|
||||
this.refreshWriteArea();
|
||||
|
||||
this.processMessage(
|
||||
contact.getDisplayName(),
|
||||
new Date(System.currentTimeMillis()),
|
||||
Constants.OUTGOING_MESSAGE,
|
||||
msg.getContent());
|
||||
|
||||
this.processMessage(
|
||||
contact.getDisplayName(),
|
||||
new Date(System.currentTimeMillis()),
|
||||
Constants.ERROR_MESSAGE,
|
||||
Messages.getI18NString("msgSendConnectionProblem")
|
||||
.getText());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.error("Failed to send message.", ex);
|
||||
|
||||
this.refreshWriteArea();
|
||||
|
||||
this.processMessage(
|
||||
contact.getDisplayName(),
|
||||
new Date(System.currentTimeMillis()),
|
||||
Constants.OUTGOING_MESSAGE,
|
||||
msg.getContent());
|
||||
|
||||
this.processMessage(
|
||||
contact.getDisplayName(),
|
||||
new Date(System.currentTimeMillis()),
|
||||
Constants.ERROR_MESSAGE,
|
||||
Messages.getI18NString("msgDeliveryInternalError")
|
||||
.getText());
|
||||
}
|
||||
}
|
||||
|
||||
public void metaContactAdded(MetaContactEvent evt)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Implements <tt>MetaContactListListener.metaContactRenamed</tt> method.
|
||||
* When a meta contact is renamed, updates all related labels in this
|
||||
* chat panel.
|
||||
*/
|
||||
public void metaContactRenamed(MetaContactRenamedEvent evt)
|
||||
{
|
||||
String newName = evt.getNewDisplayName();
|
||||
|
||||
if(evt.getSourceMetaContact().equals(metaContact))
|
||||
{
|
||||
getChatContactListPanel().renameContact(evt.getSourceMetaContact());
|
||||
|
||||
getChatWindow().setTabTitle(this, newName);
|
||||
|
||||
if( getChatWindow().getCurrentChatPanel() == this)
|
||||
{
|
||||
getChatWindow().setTitle(newName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements <tt>MetaContactListListener.protoContactAdded</tt> method.
|
||||
* When a proto contact is added, updates the "send via" selector box.
|
||||
*/
|
||||
public void protoContactAdded(ProtoContactEvent evt)
|
||||
{
|
||||
if (evt.getNewParent().equals(metaContact))
|
||||
{
|
||||
this.contactSelectorBox.addProtoContact(evt.getProtoContact());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements <tt>MetaContactListListener.protoContactRemoved</tt> method.
|
||||
* When a proto contact is removed, updates the "send via" selector box.
|
||||
*/
|
||||
public void protoContactRemoved(ProtoContactEvent evt)
|
||||
{
|
||||
if (evt.getOldParent().equals(metaContact))
|
||||
{
|
||||
contactSelectorBox.removeProtoContact(evt.getProtoContact());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements <tt>MetaContactListListener.protoContactMoved</tt> method.
|
||||
* When a proto contact is moved, updates the "send via" selector box.
|
||||
*/
|
||||
public void protoContactMoved(ProtoContactEvent evt)
|
||||
{
|
||||
if (evt.getOldParent().equals(metaContact))
|
||||
{
|
||||
contactSelectorBox.removeProtoContact(evt.getProtoContact());
|
||||
}
|
||||
|
||||
if (evt.getNewParent().equals(metaContact))
|
||||
{
|
||||
contactSelectorBox.addProtoContact(evt.getProtoContact());
|
||||
}
|
||||
}
|
||||
|
||||
public void metaContactRemoved(MetaContactEvent evt)
|
||||
{}
|
||||
|
||||
public void metaContactMoved(MetaContactMovedEvent evt)
|
||||
{}
|
||||
|
||||
public void metaContactGroupAdded(MetaContactGroupEvent evt)
|
||||
{}
|
||||
|
||||
public void metaContactGroupModified(MetaContactGroupEvent evt)
|
||||
{}
|
||||
|
||||
public void metaContactGroupRemoved(MetaContactGroupEvent evt)
|
||||
{}
|
||||
|
||||
public void childContactsReordered(MetaContactGroupEvent evt)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Implements the <tt>ChatPanel.sendTypingNotification</tt> method.
|
||||
* Obtains the typing notification's operation set and sends a typing
|
||||
* notification through it.
|
||||
*/
|
||||
public int sendTypingNotification(int typingState)
|
||||
{
|
||||
Contact protocolContact = contactSelectorBox.getSelectedProtocolContact();
|
||||
|
||||
OperationSetTypingNotifications tnOperationSet
|
||||
= (OperationSetTypingNotifications)
|
||||
protocolContact.getProtocolProvider()
|
||||
.getOperationSet(OperationSetTypingNotifications.class);
|
||||
|
||||
if(protocolContact.getProtocolProvider().isRegistered()
|
||||
&& tnOperationSet != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
tnOperationSet.sendTypingNotification(
|
||||
protocolContact, typingState);
|
||||
|
||||
return ChatPanel.TYPING_NOTIFICATION_SUCCESSFULLY_SENT;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.error("Failed to send typing notifications.", ex);
|
||||
|
||||
return ChatPanel.TYPING_NOTIFICATION_SEND_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
return ChatPanel.TYPING_NOTIFICATION_SEND_FAILED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <tt>ChatPanel.treatReceivedMessage</tt> method.
|
||||
* Selects the given contact in the "send via" selector box.
|
||||
*/
|
||||
public void treatReceivedMessage(Contact sourceContact)
|
||||
{
|
||||
if (!contactSelectorBox.getSelectedProtocolContact().getProtocolProvider()
|
||||
.equals(sourceContact.getProtocolProvider()))
|
||||
{
|
||||
contactSelectorBox.setSelected(sourceContact);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The <tt>ChangeProtocolAction</tt> is an <tt>AbstractAction</tt> that
|
||||
* opens the menu, containing all available protocol contacts.
|
||||
*/
|
||||
private class ChangeProtocolAction
|
||||
extends AbstractAction
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
/*
|
||||
* Opens the selector box containing the protocol contact icons.
|
||||
* This is the menu, where user could select the protocol specific
|
||||
* contact to communicate through.
|
||||
*/
|
||||
SIPCommMenu contactSelector = contactSelectorBox.getMenu();
|
||||
contactSelector.doClick();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements <tt>ChatPanel.loadPreviousFromHistory</tt>.
|
||||
* Loads previous page from history.
|
||||
*/
|
||||
public void loadPreviousFromHistory()
|
||||
{
|
||||
new Thread() {
|
||||
public void run()
|
||||
{
|
||||
MessageHistoryService msgHistory
|
||||
= GuiActivator.getMsgHistoryService();
|
||||
|
||||
ChatConversationPanel conversationPanel
|
||||
= getChatConversationPanel();
|
||||
|
||||
Collection c = msgHistory.findLastMessagesBefore(
|
||||
metaContact,
|
||||
conversationPanel.getPageFirstMsgTimestamp(),
|
||||
MESSAGES_PER_PAGE);
|
||||
|
||||
if(c.size() > 0)
|
||||
{
|
||||
SwingUtilities.invokeLater(
|
||||
new HistoryMessagesLoader(c));
|
||||
|
||||
//Save the last before the last page
|
||||
Iterator i = c.iterator();
|
||||
Object lastMessageObject = null;
|
||||
Date lastMessageTimeStamp = null;
|
||||
|
||||
while(i.hasNext()) {
|
||||
Object o = i.next();
|
||||
|
||||
if(!i.hasNext()) {
|
||||
lastMessageObject = o;
|
||||
}
|
||||
}
|
||||
|
||||
if(lastMessageObject instanceof MessageDeliveredEvent) {
|
||||
MessageDeliveredEvent evt
|
||||
= (MessageDeliveredEvent)lastMessageObject;
|
||||
|
||||
lastMessageTimeStamp = evt.getTimestamp();
|
||||
}
|
||||
else if(lastMessageObject instanceof MessageReceivedEvent) {
|
||||
MessageReceivedEvent evt
|
||||
= (MessageReceivedEvent) lastMessageObject;
|
||||
|
||||
lastMessageTimeStamp = evt.getTimestamp();
|
||||
}
|
||||
|
||||
if(getBeginLastPageTimeStamp() == null)
|
||||
setBeginLastPageTimeStamp(lastMessageTimeStamp);
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements <tt>ChatPanel.loadNextFromHistory</tt>.
|
||||
* Loads next page from history.
|
||||
*/
|
||||
public void loadNextFromHistory()
|
||||
{
|
||||
new Thread() {
|
||||
public void run(){
|
||||
MessageHistoryService msgHistory
|
||||
= GuiActivator.getMsgHistoryService();
|
||||
|
||||
Collection c;
|
||||
if(getBeginLastPageTimeStamp().compareTo(
|
||||
getChatConversationPanel().getPageLastMsgTimestamp()) == 0)
|
||||
{
|
||||
c = msgHistory.findByPeriod(
|
||||
metaContact,
|
||||
getBeginLastPageTimeStamp(),
|
||||
new Date(System.currentTimeMillis()));
|
||||
}
|
||||
else
|
||||
{
|
||||
c = msgHistory.findFirstMessagesAfter(
|
||||
metaContact,
|
||||
getChatConversationPanel().getPageLastMsgTimestamp(),
|
||||
MESSAGES_PER_PAGE);
|
||||
}
|
||||
|
||||
if(c.size() > 0)
|
||||
SwingUtilities.invokeLater(
|
||||
new HistoryMessagesLoader(c));
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* From a given collection of messages shows the history in the chat window.
|
||||
*/
|
||||
private class HistoryMessagesLoader implements Runnable
|
||||
{
|
||||
private Collection msgHistory;
|
||||
|
||||
public HistoryMessagesLoader(Collection msgHistory)
|
||||
{
|
||||
this.msgHistory = msgHistory;
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
getChatConversationPanel().clear();
|
||||
|
||||
processHistory(msgHistory, "");
|
||||
|
||||
getChatConversationPanel().setDefaultContent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,336 @@
|
||||
/*
|
||||
* 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.chat.conference;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.java.sip.communicator.impl.gui.*;
|
||||
import net.java.sip.communicator.impl.gui.i18n.*;
|
||||
import net.java.sip.communicator.impl.gui.main.chat.*;
|
||||
import net.java.sip.communicator.impl.gui.utils.*;
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
import net.java.sip.communicator.service.protocol.event.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
/**
|
||||
* The <tt>ConferenceChatPanel</tt> is the chat panel corresponding to a
|
||||
* multi user chat.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class ConferenceChatPanel
|
||||
extends ChatPanel
|
||||
implements ChatRoomMessageListener,
|
||||
ChatRoomPropertyChangeListener,
|
||||
ChatRoomLocalUserStatusListener,
|
||||
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
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <tt>ChatPanel.getChatName</tt> method.
|
||||
*
|
||||
* @return the name of the chat room.
|
||||
*/
|
||||
public String getChatName()
|
||||
{
|
||||
return chatRoom.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <tt>ChatPanel.getChatIdentifier</tt> method.
|
||||
*
|
||||
* @return the <tt>ChatRoom</tt>
|
||||
*/
|
||||
public Object getChatIdentifier()
|
||||
{
|
||||
return chatRoom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <tt>ChatPanel.getChatStatus</tt> method.
|
||||
*
|
||||
* @return the status of this chat room
|
||||
*/
|
||||
public PresenceStatus getChatStatus()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <tt>ChatPanel.loadHistory</tt> method.
|
||||
* <br>
|
||||
* Loads the history for this chat room.
|
||||
*/
|
||||
public void loadHistory()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <tt>ChatPanel.loadHistory(escapedMessageID)</tt> method.
|
||||
* <br>
|
||||
* Loads the history for this chat room and escapes the last message
|
||||
* received.
|
||||
*/
|
||||
public void loadHistory(String escapedMessageID)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <tt>ChatPanel.loadPreviousFromHistory</tt> method.
|
||||
* <br>
|
||||
* Loads the previous "page" in the history.
|
||||
*/
|
||||
public void loadPreviousFromHistory()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <tt>ChatPanel.loadNextFromHistory</tt> method.
|
||||
* <br>
|
||||
* Loads the next "page" in the history.
|
||||
*/
|
||||
public void loadNextFromHistory()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <tt>ChatPanel.sendMessage</tt> method.
|
||||
* <br>
|
||||
* Sends a message to the chat room.
|
||||
*/
|
||||
protected void sendMessage()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <tt>ChatPanel.treatReceivedMessage</tt> method.
|
||||
* <br>
|
||||
* Treats a received message from the given contact.
|
||||
*/
|
||||
public void treatReceivedMessage(Contact sourceContact)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <tt>ChatPanel.sendTypingNotification</tt> method.
|
||||
* <br>
|
||||
* Sends a typing notification.
|
||||
*/
|
||||
public int sendTypingNotification(int typingState)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <tt>ChatPanel.getFirstHistoryMsgTimestamp</tt> method.
|
||||
*/
|
||||
public Date getFirstHistoryMsgTimestamp()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <tt>ChatPanel.getLastHistoryMsgTimestamp</tt> method.
|
||||
*/
|
||||
public Date getLastHistoryMsgTimestamp()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <tt>ChatRoomMessageListener.messageReceived</tt> method.
|
||||
* <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());
|
||||
|
||||
chatWindowManager.openChat(chatPanel, false);
|
||||
|
||||
GuiActivator.getAudioNotifier()
|
||||
.createAudio(Sounds.INCOMING_MESSAGE).play();
|
||||
|
||||
chatPanel.treatReceivedMessage(sourceContact);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <tt>ChatRoomMessageListener.messageDelivered</tt> method.
|
||||
* <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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <tt>ChatRoomMessageListener.messageDeliveryFailed</tt>
|
||||
* method.
|
||||
* <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()
|
||||
== MessageDeliveryFailedEvent.OFFLINE_MESSAGES_NOT_SUPPORTED) {
|
||||
|
||||
errorMsg = Messages.getI18NString(
|
||||
"msgDeliveryOfflineNotSupported").getText();
|
||||
}
|
||||
else if (evt.getErrorCode()
|
||||
== MessageDeliveryFailedEvent.NETWORK_FAILURE) {
|
||||
|
||||
errorMsg = Messages.getI18NString("msgNotDelivered").getText();
|
||||
}
|
||||
else if (evt.getErrorCode()
|
||||
== MessageDeliveryFailedEvent.PROVIDER_NOT_REGISTERED) {
|
||||
|
||||
errorMsg = Messages.getI18NString(
|
||||
"msgSendConnectionProblem").getText();
|
||||
}
|
||||
else if (evt.getErrorCode()
|
||||
== MessageDeliveryFailedEvent.INTERNAL_ERROR) {
|
||||
|
||||
errorMsg = Messages.getI18NString(
|
||||
"msgDeliveryInternalError").getText();
|
||||
}
|
||||
else {
|
||||
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);
|
||||
}
|
||||
|
||||
public void chatRoomChanged(ChatRoomPropertyChangeEvent evt)
|
||||
{
|
||||
}
|
||||
|
||||
public void localUserStatusChanged(ChatRoomLocalUserStatusChangeEvent evt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void localUserStatusChanged(ChatRoomParticipantStatusChangeEvent evt)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.chat.conference;
|
||||
|
||||
import net.java.sip.communicator.impl.gui.main.*;
|
||||
import net.java.sip.communicator.service.protocol.event.*;
|
||||
|
||||
/**
|
||||
* The <tt>MultiUserChatManager</tt> is the one that manages chat room
|
||||
* invitations.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class MultiUserChatManager
|
||||
implements InvitationListener,
|
||||
InvitationRejectionListener
|
||||
{
|
||||
private MainFrame mainFrame;
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>MultiUserChatManager</tt>, by passing to it
|
||||
* the main application window object.
|
||||
*
|
||||
* @param mainFrame the main application window
|
||||
*/
|
||||
public MultiUserChatManager(MainFrame mainFrame)
|
||||
{
|
||||
this.mainFrame = mainFrame;
|
||||
}
|
||||
|
||||
public void invitationReceived(InvitationReceivedEvent evt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void invitationRejected(InvitationRejectedEvent evt)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,129 @@
|
||||
/*
|
||||
* 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.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
|
||||
import net.java.sip.communicator.impl.gui.main.*;
|
||||
import net.java.sip.communicator.impl.gui.main.chat.*;
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
/**
|
||||
* The <tt>ChatRoomsList</tt> is the list containing all chat rooms.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class ChatRoomsList
|
||||
extends JList
|
||||
implements ListSelectionListener
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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>
|
||||
* from which we manage chat rooms
|
||||
*/
|
||||
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 (OperationFailedException ex)
|
||||
{
|
||||
logger.error(
|
||||
"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);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pps
|
||||
* @return
|
||||
*/
|
||||
public boolean isChatServerClosed(ProtocolProviderService pps)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* A chat room was selected. Opens the chat room in the chat window.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,166 @@
|
||||
/*
|
||||
* 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.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import net.java.sip.communicator.impl.gui.utils.*;
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
|
||||
/**
|
||||
* The <tt>ChatRoomsListCellRenderer</tt> is the custom cell renderer used in the
|
||||
* SIP-Communicator's <tt>ChatRoomsList</tt>. It extends JPanel instead of JLabel,
|
||||
* which allows adding different buttons and icons to the contact cell.
|
||||
* The cell border and background are repainted.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class ChatRoomsListCellRenderer extends JPanel
|
||||
implements ListCellRenderer {
|
||||
|
||||
private JLabel nameLabel = new JLabel();
|
||||
|
||||
private boolean isSelected = false;
|
||||
|
||||
private boolean isLeaf = true;
|
||||
|
||||
/**
|
||||
* Initialize the panel containing the node.
|
||||
*/
|
||||
public ChatRoomsListCellRenderer()
|
||||
{
|
||||
super(new BorderLayout());
|
||||
|
||||
this.setBackground(Color.WHITE);
|
||||
|
||||
this.setOpaque(true);
|
||||
|
||||
this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
|
||||
this.nameLabel.setIconTextGap(2);
|
||||
|
||||
this.nameLabel.setPreferredSize(new Dimension(10, 17));
|
||||
|
||||
this.add(nameLabel, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <tt>ListCellRenderer</tt> method.
|
||||
*
|
||||
* Returns this panel that has been configured to display the meta contact
|
||||
* and meta contact group cells.
|
||||
*/
|
||||
public Component getListCellRendererComponent(JList list, Object value,
|
||||
int index, boolean isSelected, boolean cellHasFocus) {
|
||||
|
||||
ChatRoomsList chatRoomsList = (ChatRoomsList) list;
|
||||
|
||||
String toolTipText = "<html>";
|
||||
|
||||
if (value instanceof ChatRoom) {
|
||||
|
||||
ChatRoom chatRoom = (ChatRoom) value;
|
||||
|
||||
toolTipText += "<b>"+chatRoom.getName()+"</b>";
|
||||
|
||||
this.nameLabel.setText(chatRoom.getName());
|
||||
|
||||
this.nameLabel.setIcon(new ImageIcon(ImageLoader
|
||||
.getImage(ImageLoader.CHAT_ROOM_16x16_ICON)));
|
||||
|
||||
this.nameLabel.setFont(this.getFont().deriveFont(Font.PLAIN));
|
||||
|
||||
this.setBorder(BorderFactory.createEmptyBorder(1, 8, 1, 1));
|
||||
|
||||
// We should set the bounds of the cell explicitely in order to
|
||||
// make getComponentAt work properly.
|
||||
this.setBounds(0, 0, list.getWidth() - 2, 17);
|
||||
|
||||
this.isLeaf = true;
|
||||
}
|
||||
else if (value instanceof ProtocolProviderService)
|
||||
{
|
||||
ProtocolProviderService pps = (ProtocolProviderService) value;
|
||||
|
||||
toolTipText += pps.getAccountID().getService();
|
||||
|
||||
this.nameLabel.setText(pps.getAccountID().getService()
|
||||
+ " (" + pps.getAccountID().getAccountAddress() + ")");
|
||||
|
||||
this.nameLabel.setIcon(new ImageIcon(ImageLoader
|
||||
.getImage(ImageLoader.CHAT_SERVER_16x16_ICON)));
|
||||
|
||||
this.nameLabel.setFont(this.getFont().deriveFont(Font.BOLD));
|
||||
|
||||
this.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
|
||||
|
||||
// We should set the bounds of the cell explicitely in order to
|
||||
// make getComponentAt work properly.
|
||||
this.setBounds(0, 0, list.getWidth() - 2, 20);
|
||||
|
||||
JLabel groupContentIndicator = new JLabel();
|
||||
|
||||
if(chatRoomsList.isChatServerClosed(pps))
|
||||
groupContentIndicator.setIcon(new ImageIcon(ImageLoader
|
||||
.getImage(ImageLoader.CLOSED_GROUP)));
|
||||
else
|
||||
groupContentIndicator.setIcon(new ImageIcon(ImageLoader
|
||||
.getImage(ImageLoader.OPENED_GROUP)));
|
||||
|
||||
//the width is fixed in
|
||||
//order all the icons to be with the same size
|
||||
groupContentIndicator.setBounds(0, 0, 12, 12);
|
||||
|
||||
this.isLeaf = false;
|
||||
}
|
||||
|
||||
toolTipText += "</html>";
|
||||
this.setToolTipText(toolTipText);
|
||||
|
||||
this.isSelected = isSelected;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Paint a background for all groups and a round blue border and background
|
||||
* when a cell is selected.
|
||||
*/
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
|
||||
AntialiasingManager.activateAntialiasing(g2);
|
||||
|
||||
if (!this.isLeaf) {
|
||||
|
||||
GradientPaint p = new GradientPaint(0, 0,
|
||||
Constants.SELECTED_END_COLOR,
|
||||
this.getWidth(),
|
||||
this.getHeight(),
|
||||
Constants.MOVER_END_COLOR);
|
||||
|
||||
g2.setPaint(p);
|
||||
g2.fillRoundRect(1, 1, this.getWidth(), this.getHeight() - 1, 7, 7);
|
||||
}
|
||||
|
||||
if (this.isSelected) {
|
||||
|
||||
g2.setColor(Constants.SELECTED_END_COLOR);
|
||||
g2.fillRoundRect(1, 0, this.getWidth(), this.getHeight(), 7, 7);
|
||||
|
||||
g2.setColor(Constants.BLUE_GRAY_BORDER_DARKER_COLOR);
|
||||
g2.setStroke(new BasicStroke(1.5f));
|
||||
g2.drawRoundRect(1, 0, this.getWidth() - 1, this.getHeight() - 1,
|
||||
7, 7);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import net.java.sip.communicator.impl.gui.main.*;
|
||||
|
||||
/**
|
||||
* The <tt>ChatRoomsListPanel</tt> is the panel that contains the
|
||||
* <tt>ChatRoomsList</tt>. It is situated in the second tab in the main
|
||||
* application window.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class ChatRoomsListPanel
|
||||
extends JScrollPane
|
||||
{
|
||||
private MainFrame mainFrame;
|
||||
|
||||
private ChatRoomsList chatRoomsList;
|
||||
|
||||
private JPanel treePanel = new JPanel(new BorderLayout());
|
||||
|
||||
private ChatRoomsListRightButtonMenu rightButtonMenu;
|
||||
|
||||
/**
|
||||
* Creates the scroll panel containing the chat rooms list.
|
||||
*
|
||||
* @param mainFrame the main application frame
|
||||
*/
|
||||
public ChatRoomsListPanel(MainFrame frame)
|
||||
{
|
||||
this.mainFrame = frame;
|
||||
|
||||
this.chatRoomsList = new ChatRoomsList(mainFrame);
|
||||
|
||||
this.treePanel.add(chatRoomsList, BorderLayout.NORTH);
|
||||
|
||||
this.treePanel.setBackground(Color.WHITE);
|
||||
|
||||
this.treePanel.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e)
|
||||
{
|
||||
if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0)
|
||||
{
|
||||
rightButtonMenu = new ChatRoomsListRightButtonMenu(mainFrame);
|
||||
|
||||
rightButtonMenu.setInvoker(treePanel);
|
||||
|
||||
rightButtonMenu.setLocation(e.getX()
|
||||
+ mainFrame.getX() + 5, e.getY() + mainFrame.getY()
|
||||
+ 105);
|
||||
|
||||
rightButtonMenu.setVisible(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.getViewport().add(treePanel);
|
||||
|
||||
this.setHorizontalScrollBarPolicy(
|
||||
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
|
||||
this.getVerticalScrollBar().setUnitIncrement(30);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <tt>ChatRoomsList</tt> component contained in this panel.
|
||||
*
|
||||
* @return the <tt>ChatRoomsList</tt> component contained in this panel
|
||||
*/
|
||||
public ChatRoomsList getChatRoomsList()
|
||||
{
|
||||
return chatRoomsList;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,153 @@
|
||||
/*
|
||||
* 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.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import net.java.sip.communicator.impl.gui.*;
|
||||
import net.java.sip.communicator.impl.gui.i18n.*;
|
||||
import net.java.sip.communicator.impl.gui.main.*;
|
||||
import net.java.sip.communicator.impl.gui.main.chatroomslist.chatroomwizard.*;
|
||||
import net.java.sip.communicator.impl.gui.utils.*;
|
||||
import net.java.sip.communicator.service.gui.*;
|
||||
import net.java.sip.communicator.service.gui.event.*;
|
||||
|
||||
/**
|
||||
* The <tt>ChatRoomsListRightButtonMenu</tt> is the menu, opened when user clicks
|
||||
* with the right mouse button on the chat rooms list panel. It's the one that
|
||||
* contains the create chat room item.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class ChatRoomsListRightButtonMenu
|
||||
extends JPopupMenu
|
||||
implements ActionListener,
|
||||
PluginComponentListener
|
||||
{
|
||||
private I18NString createChatRoomString
|
||||
= Messages.getI18NString("createChatRoom");
|
||||
|
||||
private I18NString searchForChatRoomsString
|
||||
= Messages.getI18NString("searchForChatRooms");
|
||||
|
||||
private JMenuItem createChatRoomItem = new JMenuItem(
|
||||
createChatRoomString.getText(),
|
||||
new ImageIcon(ImageLoader.getImage(ImageLoader.CHAT_ROOM_16x16_ICON)));
|
||||
|
||||
private JMenuItem searchForChatRoomsItem = new JMenuItem(
|
||||
searchForChatRoomsString.getText(),
|
||||
new ImageIcon(ImageLoader.getImage(ImageLoader.SEARCH_ICON_16x16)));
|
||||
|
||||
private MainFrame mainFrame;
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>ChatRoomsListRightButtonMenu</tt>.
|
||||
*/
|
||||
public ChatRoomsListRightButtonMenu(MainFrame mainFrame)
|
||||
{
|
||||
super();
|
||||
|
||||
this.mainFrame = mainFrame;
|
||||
|
||||
this.setLocation(getLocation());
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the menu, by adding all containing menu items.
|
||||
*/
|
||||
private void init()
|
||||
{
|
||||
this.add(createChatRoomItem);
|
||||
this.add(searchForChatRoomsItem);
|
||||
|
||||
this.initPluginComponents();
|
||||
|
||||
this.createChatRoomItem.setName("createChatRoom");
|
||||
this.searchForChatRoomsItem.setName("searchForChatRooms");
|
||||
|
||||
this.createChatRoomItem
|
||||
.setMnemonic(createChatRoomString.getMnemonic());
|
||||
this.searchForChatRoomsItem
|
||||
.setMnemonic(searchForChatRoomsString.getMnemonic());
|
||||
|
||||
this.createChatRoomItem.addActionListener(this);
|
||||
this.searchForChatRoomsItem.addActionListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all already registered plugin components to this menu.
|
||||
*/
|
||||
private void initPluginComponents()
|
||||
{
|
||||
Iterator pluginComponents = GuiActivator.getUIService()
|
||||
.getComponentsForContainer(
|
||||
UIService.CONTAINER_CONTACT_RIGHT_BUTTON_MENU);
|
||||
|
||||
if(pluginComponents.hasNext())
|
||||
this.addSeparator();
|
||||
|
||||
while (pluginComponents.hasNext())
|
||||
{
|
||||
Component o = (Component)pluginComponents.next();
|
||||
|
||||
this.add(o);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the <tt>ActionEvent</tt>. Determines which menu item was
|
||||
* selected and makes the appropriate operations.
|
||||
*/
|
||||
public void actionPerformed(ActionEvent e){
|
||||
|
||||
JMenuItem menuItem = (JMenuItem) e.getSource();
|
||||
String itemName = menuItem.getName();
|
||||
|
||||
if (itemName.equals("createChatRoom"))
|
||||
{
|
||||
CreateChatRoomWizard createChatRoomWizard
|
||||
= new CreateChatRoomWizard(mainFrame);
|
||||
|
||||
createChatRoomWizard.showDialog(false);
|
||||
}
|
||||
else if (itemName.equals("searchForChatRooms"))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <tt>PluginComponentListener.pluginComponentAdded</tt>
|
||||
* method, in order to add the given plugin component in this container.
|
||||
*/
|
||||
public void pluginComponentAdded(PluginComponentEvent event)
|
||||
{
|
||||
Component c = (Component) event.getSource();
|
||||
|
||||
this.add(c);
|
||||
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <tt>PluginComponentListener.pluginComponentRemoved</tt>
|
||||
* method, in order to remove the given component from this container.
|
||||
*/
|
||||
public void pluginComponentRemoved(PluginComponentEvent event)
|
||||
{
|
||||
Component c = (Component) event.getSource();
|
||||
|
||||
this.remove(c);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,134 @@
|
||||
/*
|
||||
* 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.chatroomwizard;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
|
||||
import net.java.sip.communicator.impl.gui.customcontrols.*;
|
||||
import net.java.sip.communicator.impl.gui.i18n.*;
|
||||
import net.java.sip.communicator.impl.gui.utils.*;
|
||||
import net.java.sip.communicator.service.gui.*;
|
||||
|
||||
/**
|
||||
* The <tt>ChatRoomNamePanel</tt> is the form, where we should enter the chat
|
||||
* room name.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class ChatRoomNamePanel
|
||||
extends JPanel
|
||||
implements DocumentListener
|
||||
{
|
||||
private JLabel nameLabel = new JLabel(
|
||||
Messages.getI18NString("chatRoomName").getText());
|
||||
|
||||
private JTextField textField = new JTextField();
|
||||
|
||||
private JPanel dataPanel = new JPanel(new BorderLayout(5, 5));
|
||||
|
||||
private SIPCommMsgTextArea infoLabel
|
||||
= new SIPCommMsgTextArea(
|
||||
Messages.getI18NString("chatRoomNameInfo").getText());
|
||||
|
||||
private JLabel infoTitleLabel = new JLabel(
|
||||
Messages.getI18NString("createChatRoom").getText());
|
||||
|
||||
private JLabel iconLabel = new JLabel(new ImageIcon(ImageLoader
|
||||
.getImage(ImageLoader.ADD_CONTACT_WIZARD_ICON)));
|
||||
|
||||
private JPanel labelsPanel = new JPanel(new GridLayout(0, 1));
|
||||
|
||||
private JPanel rightPanel = new JPanel(new BorderLayout());
|
||||
|
||||
private WizardContainer parentWizard;
|
||||
|
||||
/**
|
||||
* Creates and initializes the <tt>ChatRoomNamePanel</tt>.
|
||||
*/
|
||||
public ChatRoomNamePanel()
|
||||
{
|
||||
this(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and initializes the <tt>ChatRoomNamePanel</tt>.
|
||||
* @param wizard The parent wizard, where this panel will be added
|
||||
*/
|
||||
public ChatRoomNamePanel(WizardContainer wizard)
|
||||
{
|
||||
super(new BorderLayout());
|
||||
|
||||
this.parentWizard = wizard;
|
||||
|
||||
this.iconLabel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 10));
|
||||
|
||||
this.infoLabel.setEditable(false);
|
||||
|
||||
this.dataPanel.add(nameLabel, BorderLayout.WEST);
|
||||
|
||||
this.dataPanel.add(textField, BorderLayout.CENTER);
|
||||
|
||||
this.infoTitleLabel.setHorizontalAlignment(JLabel.CENTER);
|
||||
this.infoTitleLabel.setFont(Constants.FONT.deriveFont(Font.BOLD, 18));
|
||||
|
||||
this.labelsPanel.add(infoTitleLabel);
|
||||
this.labelsPanel.add(infoLabel);
|
||||
this.labelsPanel.add(dataPanel);
|
||||
|
||||
this.rightPanel.add(labelsPanel, BorderLayout.NORTH);
|
||||
|
||||
this.add(iconLabel, BorderLayout.WEST);
|
||||
this.add(rightPanel, BorderLayout.CENTER);
|
||||
|
||||
this.textField.getDocument().addDocumentListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the chat room name entered by user.
|
||||
* @return the chat room name entered by user
|
||||
*/
|
||||
public String getChatRoomName()
|
||||
{
|
||||
return textField.getText();
|
||||
}
|
||||
|
||||
public void requestFocusInField() {
|
||||
this.textField.requestFocus();
|
||||
}
|
||||
|
||||
public void changedUpdate(DocumentEvent e)
|
||||
{
|
||||
}
|
||||
|
||||
public void insertUpdate(DocumentEvent e)
|
||||
{
|
||||
this.setNextFinishButtonAccordingToUIN();
|
||||
}
|
||||
|
||||
public void removeUpdate(DocumentEvent e)
|
||||
{
|
||||
this.setNextFinishButtonAccordingToUIN();
|
||||
}
|
||||
|
||||
public void setNextFinishButtonAccordingToUIN()
|
||||
{
|
||||
if(parentWizard != null)
|
||||
{
|
||||
if(textField.getText() != null && textField.getText().length() > 0)
|
||||
{
|
||||
parentWizard.setNextFinishButtonEnabled(true);
|
||||
}
|
||||
else {
|
||||
parentWizard.setNextFinishButtonEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,133 @@
|
||||
/*
|
||||
* 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.chatroomwizard;
|
||||
|
||||
import net.java.sip.communicator.impl.gui.customcontrols.*;
|
||||
import net.java.sip.communicator.impl.gui.customcontrols.wizard.*;
|
||||
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.*;
|
||||
|
||||
/**
|
||||
* The <tt>CreateChatRoomWizard</tt> is the wizard through which the user could
|
||||
* create its own chat room.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class CreateChatRoomWizard
|
||||
extends Wizard
|
||||
implements WizardListener
|
||||
{
|
||||
private Logger logger
|
||||
= Logger.getLogger(CreateChatRoomWizard.class.getName());
|
||||
|
||||
private MainFrame mainFrame;
|
||||
|
||||
private NewChatRoom newChatRoom = new NewChatRoom();
|
||||
|
||||
private CreateChatRoomWizardPage1 page1;
|
||||
|
||||
private CreateChatRoomWizardPage2 page2;
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>CreateChatRoomWizard</tt>.
|
||||
*
|
||||
* @param mainFrame the main application window
|
||||
*/
|
||||
public CreateChatRoomWizard(MainFrame mainFrame)
|
||||
{
|
||||
super(mainFrame);
|
||||
|
||||
this.mainFrame = mainFrame;
|
||||
|
||||
super.addWizardListener(this);
|
||||
|
||||
this.setTitle(Messages.getI18NString("createChatRoomWizard").getText());
|
||||
|
||||
page1 = new CreateChatRoomWizardPage1(this, newChatRoom,
|
||||
mainFrame.getPProvidersSupportingMultiUserChat());
|
||||
|
||||
this.registerWizardPage(CreateChatRoomWizardPage1.IDENTIFIER, page1);
|
||||
|
||||
page2 = new CreateChatRoomWizardPage2(this, newChatRoom);
|
||||
|
||||
this.registerWizardPage(CreateChatRoomWizardPage2.IDENTIFIER, page2);
|
||||
|
||||
this.setCurrentPage(CreateChatRoomWizardPage1.IDENTIFIER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the Wizard.showModalDialog method.
|
||||
*/
|
||||
public void showDialog(boolean modal) {
|
||||
super.showDialog(modal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new chat room in a separate thread.
|
||||
*/
|
||||
private class CreateChatRoom extends Thread
|
||||
{
|
||||
NewChatRoom newChatRoom;
|
||||
|
||||
CreateChatRoom(NewChatRoom newChatRoom)
|
||||
{
|
||||
this.newChatRoom = newChatRoom;
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
ChatRoom chatRoom = null;
|
||||
try
|
||||
{
|
||||
chatRoom = mainFrame.getMultiUserChatOpSet(
|
||||
newChatRoom.getProtocolProvider()).createChatRoom(
|
||||
newChatRoom.getChatRoomName(), null);
|
||||
}
|
||||
catch (OperationFailedException ex)
|
||||
{
|
||||
logger.error("Failed to create chat room.", ex);
|
||||
|
||||
new ErrorDialog(mainFrame,
|
||||
Messages.getI18NString(
|
||||
"createChatRoomError",
|
||||
new String[]{newChatRoom.getChatRoomName()}).getText(),
|
||||
ex,
|
||||
Messages.getI18NString(
|
||||
"error").getText())
|
||||
.showDialog();
|
||||
}
|
||||
catch (OperationNotSupportedException ex)
|
||||
{
|
||||
logger.error("Failed to create chat room.", ex);
|
||||
|
||||
new ErrorDialog(mainFrame,
|
||||
Messages.getI18NString(
|
||||
"createChatRoomError",
|
||||
new String[]{newChatRoom.getChatRoomName()}).getText(),
|
||||
ex,
|
||||
Messages.getI18NString(
|
||||
"error").getText())
|
||||
.showDialog();
|
||||
}
|
||||
|
||||
if(chatRoom != null)
|
||||
mainFrame.getChatRoomsListPanel().getChatRoomsList()
|
||||
.addChatRoom(chatRoom);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the Wizard.wizardFinished method.
|
||||
*/
|
||||
public void wizardFinished(WizardEvent e)
|
||||
{
|
||||
if(e.getEventCode() == WizardEvent.SUCCESS)
|
||||
new CreateChatRoom(newChatRoom).start();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,142 @@
|
||||
/*
|
||||
* 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.chatroomwizard;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import javax.swing.event.*;
|
||||
|
||||
import net.java.sip.communicator.service.gui.*;
|
||||
|
||||
/**
|
||||
* The <tt>CreateChatRoomWizardPage1</tt> is the first page of the
|
||||
* "Create chat room" wizard. Contains the <tt>SelectAccountPanel</tt>, where
|
||||
* the user should select the account, for which the new chat room will be
|
||||
* created.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class CreateChatRoomWizardPage1
|
||||
implements WizardPage,
|
||||
CellEditorListener
|
||||
{
|
||||
public static final String IDENTIFIER = "SELECT_ACCOUNT_PANEL";
|
||||
|
||||
private SelectAccountPanel selectAccountPanel;
|
||||
|
||||
private WizardContainer wizard;
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>CreateChatRoomWizardPage1</tt>.
|
||||
* @param wizard the parent wizard container
|
||||
* @param newChatRoom the object that will collect the information through
|
||||
* the wizard
|
||||
* @param protocolProvidersList The list of available
|
||||
* <tt>ProtocolProviderServices</tt>, from which the user could select.
|
||||
*/
|
||||
public CreateChatRoomWizardPage1(WizardContainer wizard,
|
||||
NewChatRoom newChatRoom,
|
||||
Iterator protocolProvidersList)
|
||||
{
|
||||
this.wizard = wizard;
|
||||
|
||||
selectAccountPanel
|
||||
= new SelectAccountPanel(newChatRoom, protocolProvidersList);
|
||||
|
||||
selectAccountPanel.addCheckBoxCellListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Before the panel is displayed checks the selections and enables the
|
||||
* next button if a checkbox is already selected or disables it if
|
||||
* nothing is selected.
|
||||
*/
|
||||
public void pageShowing()
|
||||
{
|
||||
setNextButtonAccordingToCheckBox();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables the next button when the user makes a choise and disables it
|
||||
* if nothing is selected.
|
||||
*/
|
||||
private void setNextButtonAccordingToCheckBox()
|
||||
{
|
||||
if (selectAccountPanel.isRadioSelected())
|
||||
this.wizard.setNextFinishButtonEnabled(true);
|
||||
else
|
||||
this.wizard.setNextFinishButtonEnabled(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* When user canceled editing the next button is enabled or disabled
|
||||
* depending on if the user has selected a check box or not.
|
||||
*/
|
||||
public void editingCanceled(ChangeEvent e)
|
||||
{
|
||||
setNextButtonAccordingToCheckBox();
|
||||
}
|
||||
|
||||
/**
|
||||
* When user stopped editing the next button is enabled or disabled
|
||||
* depending on if the user has selected a check box or not.
|
||||
*/
|
||||
public void editingStopped(ChangeEvent e)
|
||||
{
|
||||
setNextButtonAccordingToCheckBox();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the identifier of this wizard page.
|
||||
*/
|
||||
public Object getIdentifier()
|
||||
{
|
||||
return IDENTIFIER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the identifier of the next wizard page.
|
||||
*/
|
||||
public Object getNextPageIdentifier()
|
||||
{
|
||||
return CreateChatRoomWizardPage2.IDENTIFIER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the identifier of the back wizard page.
|
||||
*/
|
||||
public Object getBackPageIdentifier()
|
||||
{
|
||||
return IDENTIFIER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the form contained in this wizard page. In this case
|
||||
*/
|
||||
public Object getWizardForm()
|
||||
{
|
||||
return selectAccountPanel;
|
||||
}
|
||||
|
||||
public void pageHiding()
|
||||
{
|
||||
}
|
||||
|
||||
public void pageShown()
|
||||
{
|
||||
}
|
||||
|
||||
public void pageNext()
|
||||
{
|
||||
selectAccountPanel.setSelectedAccount();
|
||||
}
|
||||
|
||||
public void pageBack()
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,109 @@
|
||||
/*
|
||||
* 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.chatroomwizard;
|
||||
|
||||
import net.java.sip.communicator.impl.gui.main.contactlist.addcontact.*;
|
||||
import net.java.sip.communicator.service.gui.*;
|
||||
|
||||
/**
|
||||
* The <tt>CreateChatRoomWizardPage2</tt> is the second page of the
|
||||
* "Create chat room" wizard. Contains the <tt>ChatRoomNamePanel</tt>, where
|
||||
* the user should enter the name of the chat room.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class CreateChatRoomWizardPage2
|
||||
implements WizardPage
|
||||
{
|
||||
public static final String IDENTIFIER = "NAME_PANEL";
|
||||
|
||||
private ChatRoomNamePanel namePanel;
|
||||
|
||||
private WizardContainer wizard;
|
||||
|
||||
private NewChatRoom newChatRoom;
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>CreateChatRoomWizardPage2</tt>.
|
||||
* @param wizard the parent wizard container
|
||||
* @param newChatRoom the object that collects all information for the
|
||||
* chat room, collected throughout the wizard
|
||||
*/
|
||||
public CreateChatRoomWizardPage2(WizardContainer wizard,
|
||||
NewChatRoom newChatRoom)
|
||||
{
|
||||
this.wizard = wizard;
|
||||
|
||||
this.newChatRoom = newChatRoom;
|
||||
|
||||
namePanel = new ChatRoomNamePanel(wizard);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <tt>WizardPanelDescriptor</tt> method to return the
|
||||
* identifier of the next wizard page.
|
||||
*/
|
||||
public Object getNextPageIdentifier()
|
||||
{
|
||||
return WizardPage.FINISH_PAGE_IDENTIFIER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <tt>WizardPanelDescriptor</tt> method to return the
|
||||
* identifier of the previous wizard page.
|
||||
*/
|
||||
public Object getBackPageIdentifier()
|
||||
{
|
||||
return AddContactWizardPage1.IDENTIFIER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Before finishing the wizard sets the identifier entered by the user
|
||||
* to the <tt>NewChatRoom</tt> object.
|
||||
*/
|
||||
public void pageHiding()
|
||||
{
|
||||
newChatRoom.setChatRoomName(namePanel.getChatRoomName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the <tt>WizardPanelDescriptor</tt> method to return the
|
||||
* identifier of this page.
|
||||
*/
|
||||
public Object getIdentifier()
|
||||
{
|
||||
return IDENTIFIER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the form contained in this wizard page. In this case it's the
|
||||
* <tt>ChatRoomNamePanel</tt>.
|
||||
*/
|
||||
public Object getWizardForm()
|
||||
{
|
||||
return namePanel;
|
||||
}
|
||||
|
||||
public void pageShown()
|
||||
{
|
||||
namePanel.requestFocusInField();
|
||||
}
|
||||
|
||||
public void pageShowing()
|
||||
{
|
||||
namePanel.setNextFinishButtonAccordingToUIN();
|
||||
}
|
||||
|
||||
public void pageNext()
|
||||
{
|
||||
}
|
||||
|
||||
public void pageBack()
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.chatroomwizard;
|
||||
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
|
||||
/**
|
||||
* The <tt>NewChatRoom</tt> is meant to be used from the
|
||||
* <tt>CreateChatRoomWizard</tt>, to collect information concerning the new chat
|
||||
* room.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class NewChatRoom
|
||||
{
|
||||
private ProtocolProviderService protocolProvider;
|
||||
|
||||
private String chatRoomName;
|
||||
|
||||
public String getChatRoomName()
|
||||
{
|
||||
return chatRoomName;
|
||||
}
|
||||
|
||||
public void setChatRoomName(String chatRoomName)
|
||||
{
|
||||
this.chatRoomName = chatRoomName;
|
||||
}
|
||||
|
||||
public ProtocolProviderService getProtocolProvider()
|
||||
{
|
||||
return protocolProvider;
|
||||
}
|
||||
|
||||
public void setProtocolProvider(ProtocolProviderService protocolProvider)
|
||||
{
|
||||
this.protocolProvider = protocolProvider;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,211 @@
|
||||
/*
|
||||
* 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.chatroomwizard;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
|
||||
import javax.imageio.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.table.*;
|
||||
|
||||
import net.java.sip.communicator.impl.gui.customcontrols.*;
|
||||
import net.java.sip.communicator.impl.gui.i18n.*;
|
||||
import net.java.sip.communicator.impl.gui.utils.*;
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
import net.java.sip.communicator.util.*;
|
||||
|
||||
/**
|
||||
* The <tt>SelectAccountPanel</tt> is where the user should select the account,
|
||||
* for which the new chat room will be created.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class SelectAccountPanel extends JPanel
|
||||
{
|
||||
private Logger logger = Logger.getLogger(SelectAccountPanel.class);
|
||||
|
||||
private JScrollPane tablePane = new JScrollPane();
|
||||
|
||||
private JTable accountsTable;
|
||||
|
||||
private DefaultTableModel tableModel = new DefaultTableModel();
|
||||
|
||||
private NewChatRoom newChatRoom;
|
||||
|
||||
private Iterator protocolProvidersList;
|
||||
|
||||
private JPanel labelsPanel = new JPanel(new GridLayout(0, 1));
|
||||
|
||||
private JPanel rightPanel = new JPanel(new BorderLayout(5, 5));
|
||||
|
||||
private JLabel iconLabel = new JLabel(new ImageIcon(ImageLoader
|
||||
.getImage(ImageLoader.ADD_CONTACT_WIZARD_ICON)));
|
||||
|
||||
private SIPCommMsgTextArea infoLabel = new SIPCommMsgTextArea(
|
||||
Messages.getI18NString("selectProvidersForChatRoom").getText());
|
||||
|
||||
private JLabel infoTitleLabel = new JLabel(
|
||||
Messages.getI18NString("selectAccount").getText(),
|
||||
JLabel.CENTER);
|
||||
|
||||
private ButtonGroup radioButtonGroup = new ButtonGroup();
|
||||
|
||||
/**
|
||||
* Creates and initializes the <tt>SelectAccountPanel</tt>.
|
||||
*
|
||||
* @param newChatRoom an object that collects all user choices through the
|
||||
* wizard
|
||||
* @param protocolProvidersList The list of available
|
||||
* <tt>ProtocolProviderServices</tt>, from which the user could select.
|
||||
*/
|
||||
public SelectAccountPanel(NewChatRoom newChatRoom,
|
||||
Iterator protocolProvidersList)
|
||||
{
|
||||
super(new BorderLayout());
|
||||
|
||||
this.setPreferredSize(new Dimension(600, 400));
|
||||
this.newChatRoom = newChatRoom;
|
||||
|
||||
this.protocolProvidersList = protocolProvidersList;
|
||||
|
||||
this.iconLabel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 10));
|
||||
|
||||
this.infoLabel.setEditable(false);
|
||||
|
||||
this.infoTitleLabel.setFont(Constants.FONT.deriveFont(Font.BOLD, 18));
|
||||
|
||||
this.labelsPanel.add(infoTitleLabel);
|
||||
this.labelsPanel.add(infoLabel);
|
||||
|
||||
this.rightPanel.add(labelsPanel, BorderLayout.NORTH);
|
||||
this.rightPanel.add(tablePane, BorderLayout.CENTER);
|
||||
|
||||
this.add(iconLabel, BorderLayout.WEST);
|
||||
|
||||
this.add(rightPanel, BorderLayout.CENTER);
|
||||
|
||||
this.tableInit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the accounts table.
|
||||
*/
|
||||
private void tableInit()
|
||||
{
|
||||
accountsTable = new JTable(tableModel)
|
||||
{
|
||||
public void tableChanged(TableModelEvent e) {
|
||||
super.tableChanged(e);
|
||||
repaint();
|
||||
}
|
||||
};
|
||||
|
||||
accountsTable.setPreferredScrollableViewportSize(new Dimension(500, 70));
|
||||
|
||||
tableModel.addColumn("");
|
||||
tableModel.addColumn(Messages.getI18NString("account").getText());
|
||||
tableModel.addColumn(Messages.getI18NString("protocol").getText());
|
||||
|
||||
while(protocolProvidersList.hasNext())
|
||||
{
|
||||
ProtocolProviderService pps
|
||||
= (ProtocolProviderService)protocolProvidersList.next();
|
||||
|
||||
String pName = pps.getProtocolName();
|
||||
|
||||
Image protocolImage = null;
|
||||
try
|
||||
{
|
||||
protocolImage = ImageIO.read(
|
||||
new ByteArrayInputStream(pps.getProtocolIcon()
|
||||
.getIcon(ProtocolIcon.ICON_SIZE_16x16)));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
logger.error("Could not read image.", e);
|
||||
}
|
||||
|
||||
JLabel protocolLabel = new JLabel();
|
||||
protocolLabel.setText(pName);
|
||||
protocolLabel.setIcon(new ImageIcon(protocolImage));
|
||||
|
||||
JRadioButton radioButton = new JRadioButton();
|
||||
|
||||
tableModel.addRow(new Object[]{radioButton,
|
||||
pps, protocolLabel});
|
||||
|
||||
radioButtonGroup.add(radioButton);
|
||||
}
|
||||
|
||||
accountsTable.setRowHeight(22);
|
||||
|
||||
accountsTable.getColumnModel().getColumn(0).setPreferredWidth(30);
|
||||
accountsTable.getColumnModel().getColumn(0).setCellRenderer(
|
||||
new RadioButtonTableCellRenderer());
|
||||
|
||||
accountsTable.getColumnModel().getColumn(0).setCellEditor(
|
||||
new RadioButtonCellEditor(new JCheckBox()));
|
||||
|
||||
accountsTable.getColumnModel().getColumn(2)
|
||||
.setCellRenderer(new LabelTableCellRenderer());
|
||||
accountsTable.getColumnModel().getColumn(1)
|
||||
.setCellRenderer(new LabelTableCellRenderer());
|
||||
|
||||
this.tablePane.getViewport().add(accountsTable);
|
||||
}
|
||||
|
||||
public void addCheckBoxCellListener(CellEditorListener l) {
|
||||
if(accountsTable.getModel().getRowCount() != 0) {
|
||||
accountsTable.getCellEditor(0, 0).addCellEditorListener(l);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether there is a selected radio button in the table.
|
||||
* @return <code>true</code> if any of the check boxes is selected,
|
||||
* <code>false</code> otherwise.
|
||||
*/
|
||||
public boolean isRadioSelected()
|
||||
{
|
||||
TableModel model = accountsTable.getModel();
|
||||
|
||||
for (int i = 0; i < accountsTable.getRowCount(); i ++) {
|
||||
Object value = model.getValueAt(i, 0);
|
||||
|
||||
if (value instanceof JRadioButton)
|
||||
{
|
||||
JRadioButton radioButton = (JRadioButton) value;
|
||||
|
||||
if(radioButton.isSelected())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setSelectedAccount()
|
||||
{
|
||||
TableModel model = accountsTable.getModel();
|
||||
|
||||
for (int i = 0; i < accountsTable.getRowCount(); i ++) {
|
||||
Object value = model.getValueAt(i, 0);
|
||||
|
||||
if (value instanceof JRadioButton) {
|
||||
JRadioButton radioButton = (JRadioButton)value;
|
||||
if(radioButton.isSelected()){
|
||||
newChatRoom.setProtocolProvider(
|
||||
(ProtocolProviderService)model.getValueAt(i, 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,108 +0,0 @@
|
||||
/*
|
||||
* 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.message;
|
||||
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
import net.java.sip.communicator.impl.gui.customcontrols.*;
|
||||
import net.java.sip.communicator.impl.gui.utils.*;
|
||||
import net.java.sip.communicator.service.contactlist.*;
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
|
||||
/**
|
||||
* The <tt>ChatConferencePanel</tt> is the panel added on the right of the
|
||||
* chat conversation area, containing information for all contacts
|
||||
* participating the chat. It contains a list of <tt>ChatContactPanel</tt>s.
|
||||
* Each of these panels is containing the name, status, etc. of only one
|
||||
* <tt>MetaContact</tt>. There is also a button, which allows to add new
|
||||
* contact to the chat. May be we will add another button to remove a contact
|
||||
* from the chat which will be disabled for protocols that doesn't allow that.
|
||||
* <p>
|
||||
* Note that at this moment the conference functionality is not yet implemented.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class ChatConferencePanel extends JPanel {
|
||||
|
||||
private JScrollPane contactsScrollPane = new JScrollPane();
|
||||
|
||||
private JPanel contactsPanel = new JPanel();
|
||||
|
||||
private JPanel mainPanel = new JPanel(new BorderLayout());
|
||||
|
||||
private SIPCommButton addToChatButton = new SIPCommButton(ImageLoader
|
||||
.getImage(ImageLoader.ADD_TO_CHAT_BUTTON), ImageLoader
|
||||
.getImage(ImageLoader.ADD_TO_CHAT_ROLLOVER_BUTTON), ImageLoader
|
||||
.getImage(ImageLoader.ADD_TO_CHAT_ICON), null);
|
||||
|
||||
private JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
||||
|
||||
private ChatContactPanel chatContactPanel;
|
||||
|
||||
private ChatPanel chatPanel;
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>ChatConferencePanel</tt>.
|
||||
*/
|
||||
public ChatConferencePanel(ChatPanel chatPanel,
|
||||
MetaContact metaContact, Contact protocolContact) {
|
||||
|
||||
super(new BorderLayout(5, 5));
|
||||
|
||||
this.chatPanel = chatPanel;
|
||||
|
||||
chatContactPanel = new ChatContactPanel(
|
||||
chatPanel, metaContact, protocolContact);
|
||||
|
||||
this.contactsPanel.add(chatContactPanel);
|
||||
|
||||
this.setMinimumSize(new Dimension(150, 100));
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the <tt>ChatConferencePanel</tt>.
|
||||
*/
|
||||
private void init() {
|
||||
this.contactsPanel.setLayout(new BoxLayout(this.contactsPanel,
|
||||
BoxLayout.Y_AXIS));
|
||||
|
||||
this.mainPanel.add(contactsPanel, BorderLayout.NORTH);
|
||||
this.contactsScrollPane.getViewport().add(this.mainPanel);
|
||||
|
||||
this.buttonPanel.add(addToChatButton);
|
||||
|
||||
this.add(contactsScrollPane, BorderLayout.CENTER);
|
||||
this.add(buttonPanel, BorderLayout.SOUTH);
|
||||
|
||||
// Disable all unused buttons.
|
||||
this.addToChatButton.setEnabled(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the status icon of the contact in this
|
||||
* <tt>ChatConferencePanel</tt>.
|
||||
* @param status The new <tt>PresenceStatus</tt>.
|
||||
*/
|
||||
public void updateContactStatus(PresenceStatus status)
|
||||
{
|
||||
this.chatContactPanel.setStatusIcon(status);
|
||||
}
|
||||
|
||||
public void updateProtocolContact(Contact contact)
|
||||
{
|
||||
this.chatContactPanel.updateProtocolContact(contact);
|
||||
}
|
||||
|
||||
public void renameContact(String newName)
|
||||
{
|
||||
this.chatContactPanel.renameContact(newName);
|
||||
}
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
/*
|
||||
* 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.message;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public interface ChatConversationContainer {
|
||||
|
||||
public void setStatusMessage(String message);
|
||||
|
||||
public Window getWindow();
|
||||
}
|
||||
Loading…
Reference in new issue