rename message package to chat and change the structure of classes in order to allow conference chatting

cusax-fix
Yana Stamcheva 20 years ago
parent 5a140d2c02
commit bb7cba9505

@ -19,9 +19,9 @@
import net.java.sip.communicator.impl.gui.main.MainFrame;
import net.java.sip.communicator.impl.gui.main.account.AccountRegWizardContainerImpl;
import net.java.sip.communicator.impl.gui.main.chat.*;
import net.java.sip.communicator.impl.gui.main.configforms.ConfigurationFrame;
import net.java.sip.communicator.impl.gui.main.contactlist.ContactListPanel;
import net.java.sip.communicator.impl.gui.main.message.*;
import net.java.sip.communicator.service.contactlist.MetaContact;
import net.java.sip.communicator.service.gui.AccountRegistrationWizardContainer;
import net.java.sip.communicator.service.gui.ApplicationWindow;

@ -19,10 +19,12 @@
import net.java.sip.communicator.impl.gui.customcontrols.*;
import net.java.sip.communicator.impl.gui.i18n.*;
import net.java.sip.communicator.impl.gui.main.call.*;
import net.java.sip.communicator.impl.gui.main.chat.*;
import net.java.sip.communicator.impl.gui.main.chat.conference.*;
import net.java.sip.communicator.impl.gui.main.chatroomslist.*;
import net.java.sip.communicator.impl.gui.main.contactlist.*;
import net.java.sip.communicator.impl.gui.main.login.*;
import net.java.sip.communicator.impl.gui.main.menus.*;
import net.java.sip.communicator.impl.gui.main.message.*;
import net.java.sip.communicator.impl.gui.main.presence.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.configuration.*;
@ -71,6 +73,8 @@ public class MainFrame
private Hashtable protocolProviders = new Hashtable();
private Hashtable webContactInfoOperationSets = new Hashtable();
private Hashtable multiUserChatOperationSets = new Hashtable();
private MetaContactListService contactList;
@ -78,6 +82,8 @@ public class MainFrame
private ChatWindowManager chatWindowManager;
private MultiUserChatManager multiChatManager;
/**
* Creates an instance of <tt>MainFrame</tt>.
*/
@ -86,6 +92,8 @@ public MainFrame()
this.chatWindowManager = new ChatWindowManager(this);
callManager = new CallManager(this);
multiChatManager = new MultiUserChatManager(this);
tabbedPane = new MainTabbedPane(this);
quickMenu = new QuickMenu(this);
statusPanel = new StatusPanel(this);
@ -206,6 +214,7 @@ public void addProtocolSupportedOperationSets(
.class.getName();
String pOpSetClassName = OperationSetPresence.class.getName();
// Obtain the presence operation set.
if (supportedOperationSets.containsKey(ppOpSetClassName)
|| supportedOperationSets.containsKey(pOpSetClassName)) {
@ -225,6 +234,7 @@ public void addProtocolSupportedOperationSets(
new GUIContactPresenceStatusListener());
}
// Obtain the basic instant messaging operation set.
String imOpSetClassName = OperationSetBasicInstantMessaging
.class.getName();
@ -240,6 +250,7 @@ public void addProtocolSupportedOperationSets(
im.addMessageListener(getContactListPanel());
}
// Obtain the typing notifications operation set.
String tnOpSetClassName = OperationSetTypingNotifications
.class.getName();
@ -255,6 +266,7 @@ public void addProtocolSupportedOperationSets(
tn.addTypingNotificationsListener(this.getContactListPanel());
}
// Obtain the web contact info operation set.
String wciOpSetClassName = OperationSetWebContactInfo.class.getName();
if (supportedOperationSets.containsKey(wciOpSetClassName)) {
@ -267,6 +279,7 @@ public void addProtocolSupportedOperationSets(
.put(protocolProvider, wContactInfo);
}
// Obtain the basic telephony operation set.
String telOpSetClassName = OperationSetBasicTelephony.class.getName();
if (supportedOperationSets.containsKey(telOpSetClassName)) {
@ -282,6 +295,25 @@ public void addProtocolSupportedOperationSets(
this.protocolTelephonySets.put(protocolProvider, telephony);
}
// Obtain the multi user chat operation set.
String multiChatClassName = OperationSetMultiUserChat.class.getName();
if (supportedOperationSets.containsKey(multiChatClassName))
{
OperationSetMultiUserChat multiUserChat
= (OperationSetMultiUserChat)
supportedOperationSets.get(multiChatClassName);
multiUserChat.addInvitationListener(multiChatManager);
multiUserChat.addInvitationRejectionListener(multiChatManager);
this.getChatRoomsListPanel()
.getChatRoomsList()
.addChatServer(protocolProvider, multiUserChat);
this.multiUserChatOperationSets.put(protocolProvider, multiUserChat);
}
}
/**
@ -293,6 +325,16 @@ public Iterator getProtocolProviders()
{
return this.protocolProviders.keySet().iterator();
}
/**
* Returns a set of all protocol providers supporting multi user chat.
*
* @return a set of all protocol providers supporting multi user chat.
*/
public Iterator getPProvidersSupportingMultiUserChat()
{
return this.multiUserChatOperationSets.keySet().iterator();
}
/**
* Returns the protocol provider associated to the account given
@ -370,7 +412,7 @@ public void addAccount(ProtocolProviderService protocolProvider)
}
if(!callManager.containsCallAccount(protocolProvider)
&& getTelephony(protocolProvider) != null) {
&& getTelephonyOpSet(protocolProvider) != null) {
callManager.addCallAccount(protocolProvider);
}
}
@ -421,7 +463,7 @@ public String getAccount(ProtocolProviderService protocolProvider)
* presence operation set is searched.
* @return the presence operation set for the given protocol provider.
*/
public OperationSetPresence getProtocolPresence(
public OperationSetPresence getProtocolPresenceOpSet(
ProtocolProviderService protocolProvider)
{
Object o = this.protocolPresenceSets.get(protocolProvider);
@ -441,7 +483,7 @@ public OperationSetPresence getProtocolPresence(
* @return OperationSetWebContactInfo The Web Contact Info operation
* set for the given protocol provider.
*/
public OperationSetWebContactInfo getWebContactInfo(
public OperationSetWebContactInfo getWebContactInfoOpSet(
ProtocolProviderService protocolProvider)
{
Object o = this.webContactInfoOperationSets.get(protocolProvider);
@ -456,11 +498,11 @@ public OperationSetWebContactInfo getWebContactInfo(
* Returns the telephony operation set for the given protocol provider.
*
* @param protocolProvider The protocol provider for which the telephony
* is searched.
* operation set is about.
* @return OperationSetBasicTelephony The telephony operation
* set for the given protocol provider.
*/
public OperationSetBasicTelephony getTelephony(
public OperationSetBasicTelephony getTelephonyOpSet(
ProtocolProviderService protocolProvider)
{
Object o = this.protocolTelephonySets.get(protocolProvider);
@ -470,6 +512,25 @@ public OperationSetBasicTelephony getTelephony(
return null;
}
/**
* Returns the multi user chat operation set for the given protocol provider.
*
* @param protocolProvider The protocol provider for which the multi user
* chat operation set is about.
* @return OperationSetMultiUserChat The telephony operation
* set for the given protocol provider.
*/
public OperationSetMultiUserChat getMultiUserChatOpSet(
ProtocolProviderService protocolProvider)
{
Object o = this.multiUserChatOperationSets.get(protocolProvider);
if(o != null)
return (OperationSetMultiUserChat) o;
return null;
}
/**
* Returns the call manager.
@ -515,12 +576,10 @@ public void contactPresenceStatusChanged(
MetaContact metaContact = contactList
.findMetaContactByContact(sourceContact);
if (metaContact != null) {
if(evt.getOldStatus() != evt.getNewStatus()) {
clistPanel.getContactList().modifyContact(metaContact);
chatWindowManager.updateChatContactStatus(
metaContact, sourceContact);
}
if (metaContact != null
&& (evt.getOldStatus() != evt.getNewStatus()))
{
clistPanel.getContactList().modifyContact(metaContact);
}
}
}
@ -536,6 +595,8 @@ private class GUIProviderPresenceStatusListener implements
public void providerStatusChanged(ProviderPresenceStatusChangeEvent evt)
{
ProtocolProviderService pps = evt.getProvider();
getStatusPanel().updateStatus(pps);
if(callManager.containsCallAccount(pps))
{
@ -627,7 +688,8 @@ public void loadConfigurationSettings() {
String isShowOffline = configService.getString(
"net.java.sip.communicator.impl.gui.showOffline");
if(isCallPanelShown != null && isCallPanelShown != "") {
if(isCallPanelShown != null && isCallPanelShown != "")
{
callManager.setShown(new Boolean(isCallPanelShown).booleanValue());
}
else {
@ -726,6 +788,15 @@ public ContactListPanel getContactListPanel()
{
return this.tabbedPane.getContactListPanel();
}
/**
* Returns the panel containing the chat rooms list.
* @return the panel containing the chat rooms list
*/
public ChatRoomsListPanel getChatRoomsListPanel()
{
return this.tabbedPane.getChatRoomsListPanel();
}
/**
* Adds a tab in the main tabbed pane, where the given call panel
@ -950,7 +1021,7 @@ private void updateProvidersIndexes(ProtocolProviderService removedProvider)
public Object getProtocolProviderLastStatus(
ProtocolProviderService protocolProvider)
{
if(getProtocolPresence(protocolProvider) != null)
if(getProtocolPresenceOpSet(protocolProvider) != null)
return this.statusPanel
.getLastPresenceStatus(protocolProvider);
else

@ -10,6 +10,8 @@
import net.java.sip.communicator.impl.gui.customcontrols.*;
import net.java.sip.communicator.impl.gui.i18n.*;
import net.java.sip.communicator.impl.gui.main.call.*;
import net.java.sip.communicator.impl.gui.main.chat.conference.*;
import net.java.sip.communicator.impl.gui.main.chatroomslist.*;
import net.java.sip.communicator.impl.gui.main.contactlist.*;
/**
@ -27,6 +29,7 @@ public class MainTabbedPane extends SIPCommTabbedPane {
private ContactListPanel contactListPanel;
private ChatRoomsListPanel chatRoomsListPanel;
/**
* Constructs the <tt>MainTabbedPane</tt>.
*
@ -43,12 +46,16 @@ public MainTabbedPane(MainFrame parent) {
callHistoryPanel = new CallListPanel(parent);
dialPanel = new DialPanel(parent);
chatRoomsListPanel = new ChatRoomsListPanel(parent);
this.addTab(Messages.getI18NString("contacts").getText(),
contactListPanel);
//this.addTab(Messages.getI18NString("chatRooms").getText(),
//chatRoomsListPanel);
this.addTab(Messages.getI18NString("callList").getText(),
callHistoryPanel);
this.addTab(Messages.getI18NString("dial").getText(), dialPanel);
this.addTab(Messages.getI18NString("dial").getText(), dialPanel);
}
@ -56,10 +63,11 @@ public MainTabbedPane(MainFrame parent) {
* Returns the <tt>ContactListPanel</tt> contained in this tabbed pane.
* @return the <tt>ContactListPanel</tt> contained in this tabbed pane.
*/
public ContactListPanel getContactListPanel() {
public ContactListPanel getContactListPanel()
{
return contactListPanel;
}
/**
* Returns the <tt>CallListPanel</tt> contained in this tabbed pane.
* @return the <tt>CallListPanel</tt> contained in this tabbed pane
@ -68,4 +76,13 @@ public CallListPanel getCallListPanel()
{
return this.callHistoryPanel;
}
/**
* Returns the <tt>ChatRoomsListPanel</tt> contained in this tabbed pane.
* @return the <tt>ChatRoomsListPanel</tt> contained in this tabbed pane
*/
public ChatRoomsListPanel getChatRoomsListPanel()
{
return this.chatRoomsListPanel;
}
}

@ -77,10 +77,11 @@ public void addAccount(ProtocolProviderService pps)
}
else {
OperationSetPresence presence
= callManager.getMainFrame().getProtocolPresence(pps);
= callManager.getMainFrame().getProtocolPresenceOpSet(pps);
OperationSetPresence selectedPresence
= callManager.getMainFrame().getProtocolPresence(selectedProvider);
= callManager.getMainFrame()
.getProtocolPresenceOpSet(selectedProvider);
if(presence != null && selectedPresence != null
&& (selectedPresence.getPresenceStatus().getStatus()
@ -131,7 +132,7 @@ public Image createAccountStatusImage(ProtocolProviderService pps)
Image statusImage;
OperationSetPresence presence
= callManager.getMainFrame().getProtocolPresence(pps);
= callManager.getMainFrame().getProtocolPresenceOpSet(pps);
if(presence != null)
{

@ -288,7 +288,7 @@ else if (buttonName.equalsIgnoreCase("hangup")) {
= call.getProtocolProvider();
OperationSetBasicTelephony telephony
= mainFrame.getTelephony(pps);
= mainFrame.getTelephonyOpSet(pps);
Iterator participants = call.getCallParticipants();
@ -421,7 +421,7 @@ private Contact getTelephonyContact(
Contact contact = (Contact)i.next();
OperationSetBasicTelephony telephony
= mainFrame.getTelephony(contact.getProtocolProvider());
= mainFrame.getTelephonyOpSet(contact.getProtocolProvider());
if(telephony != null)
return contact;
@ -717,7 +717,7 @@ public CreateCallThread(String contact, CallPanel callPanel)
if(selectedCallProvider != null)
telephony = mainFrame.getTelephony(selectedCallProvider);
telephony = mainFrame.getTelephonyOpSet(selectedCallProvider);
}
public CreateCallThread(Vector contacts, CallPanel callPanel)
@ -726,11 +726,14 @@ public CreateCallThread(Vector contacts, CallPanel callPanel)
this.callPanel = callPanel;
if(selectedCallProvider != null)
telephony = mainFrame.getTelephony(selectedCallProvider);
telephony = mainFrame.getTelephonyOpSet(selectedCallProvider);
}
public void run()
{
if(telephony == null)
return;
try {
Call createdCall;
@ -784,7 +787,8 @@ public void run()
CallParticipant participant
= (CallParticipant)participants.next();
OperationSetBasicTelephony telephony = mainFrame.getTelephony(pps);
OperationSetBasicTelephony telephony
= mainFrame.getTelephonyOpSet(pps);
try {
telephony.answerCallParticipant(participant);

@ -5,7 +5,7 @@
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.message;
package net.java.sip.communicator.impl.gui.main.chat;
import java.util.*;

@ -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());
}
}
}

@ -5,36 +5,23 @@
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.message;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.BevelBorder;
import net.java.sip.communicator.impl.gui.GuiActivator;
import net.java.sip.communicator.impl.gui.customcontrols.SIPCommButton;
import net.java.sip.communicator.impl.gui.i18n.Messages;
import net.java.sip.communicator.impl.gui.main.MainFrame;
import net.java.sip.communicator.impl.gui.utils.Constants;
import net.java.sip.communicator.impl.gui.utils.ImageLoader;
import net.java.sip.communicator.service.contactlist.MetaContact;
import net.java.sip.communicator.service.protocol.Contact;
import net.java.sip.communicator.service.protocol.OperationSetWebContactInfo;
import net.java.sip.communicator.service.protocol.PresenceStatus;
import net.java.sip.communicator.service.protocol.ProtocolProviderService;
package net.java.sip.communicator.impl.gui.main.chat;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
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.lookandfeel.*;
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.protocol.*;
/**
* The <tt>ChatContactPanel</tt> is the panel that appears on the right of the
@ -73,15 +60,12 @@ public class ChatContactPanel
private JLabel personNameLabel = new JLabel();
private JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
private JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
private JPanel mainPanel = new JPanel(new BorderLayout());
private JPanel contactNamePanel = new JPanel(new FlowLayout(
FlowLayout.CENTER, 0, 0));
private MetaContact contactItem;
private Contact protocolContact;
private PresenceStatus status;
private ChatPanel chatPanel;
@ -89,51 +73,78 @@ public class ChatContactPanel
/**
* Creates an instance of the <tt>ChatContactPanel</tt>.
*
* @param contactItem The <tt>MetaContact</tt>.
* @param chatPanel
* @param protocolContact
*/
public ChatContactPanel(ChatPanel chatPanel, MetaContact contactItem) {
this(chatPanel, contactItem, null);
public ChatContactPanel(ChatPanel chatPanel, Contact protocolContact)
{
this(chatPanel, null, protocolContact);
}
/**
* Creates an instance of <tt>ChatContactPanel</tt>.
* Creates an instance of the <tt>ChatContactPanel</tt>.
*
* @param chatPanel the parent chat panel
* @param contactItem the meta contact to add to this panel
* @param protocolContact the currently selected protocol contact
* @param chatPanel the <tt>ChatPanel</tt>, to which this
* <tt>ChatContactPanel</tt> belongs to.
* @param metaContact
* @param protocolContact
*/
public ChatContactPanel(ChatPanel chatPanel,
MetaContact contactItem, Contact protocolContact) {
super(new BorderLayout());
MetaContact metaContact, Contact protocolContact)
{
super(new BorderLayout(10, 5));
this.protocolContact = protocolContact;
this.setPreferredSize(new Dimension(100, 60));
this.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
this.contactItem = contactItem;
this.status = protocolContact.getPresenceStatus();
this.chatPanel = chatPanel;
this.setOpaque(false);
this.mainPanel.setOpaque(false);
this.contactNamePanel.setOpaque(false);
//this.contactNamePanel.setOpaque(false);
this.buttonsPanel.setOpaque(false);
this.init();
this.updateProtocolContact(protocolContact);
}
/**
* Constructs the <tt>ChatContactPanel</tt>.
*/
private void init() {
this.personNameLabel.setText(contactItem.getDisplayName());
String chatContactName;
if(metaContact != null)
chatContactName = metaContact.getDisplayName();
else
chatContactName = protocolContact.getDisplayName();
this.personNameLabel.setText(chatContactName);
this.personNameLabel.setFont(this.getFont().deriveFont(Font.BOLD));
this.personNameLabel.setIcon(new ImageIcon(Constants
.getStatusIcon(status)));
// this.personPhotoLabel.setIcon(new ImageIcon(contactItem.getPhoto()));
ImageIcon contactPhoto = null;
Iterator i = metaContact.getContacts();
while(i.hasNext())
{
Contact subContact = (Contact) i.next();
if(subContact.getImage() != null
&& subContact.getImage().length > 0)
{
Image contactImage
= ImageLoader.getBytesInImage(subContact.getImage());
contactPhoto = new ImageIcon(
contactImage.getScaledInstance(40, 45, Image.SCALE_SMOOTH));
break;
}
}
if(contactPhoto != null)
{
this.personPhotoLabel.setBorder(new SIPCommBorders.BoldRoundBorder());
this.personPhotoLabel.setIcon(contactPhoto);
}
this.callButton.setToolTipText(
Messages.getI18NString("call").getText());
@ -152,17 +163,17 @@ private void init() {
this.buttonsPanel.add(callButton);
this.buttonsPanel.add(sendFileButton);
this.contactNamePanel.add(personNameLabel);
this.mainPanel.add(buttonsPanel, BorderLayout.NORTH);
this.mainPanel.add(contactNamePanel, BorderLayout.CENTER);
this.mainPanel.add(personNameLabel, BorderLayout.CENTER);
this.add(personPhotoLabel, BorderLayout.WEST);
this.add(mainPanel, BorderLayout.CENTER);
// Disabled all unused buttons.
this.callButton.setEnabled(false);
this.sendFileButton.setEnabled(false);
this.sendFileButton.setEnabled(false);
this.updateProtocolContact(protocolContact);
}
/**
@ -224,7 +235,7 @@ public void updateProtocolContact(Contact protocolContact)
= protocolContact.getProtocolProvider();
OperationSetWebContactInfo wContactInfo
= mainFrame.getWebContactInfo(pps);
= mainFrame.getWebContactInfoOpSet(pps);
if(wContactInfo == null)
infoButton.setEnabled(false);
@ -246,24 +257,19 @@ public void actionPerformed(ActionEvent e)
if(button.getName().equals("call")) {
}
else if(button.getName().equals("info")){
if(contactItem != null) {
Contact protocolContact = chatPanel.getProtocolContact();
ProtocolProviderService pps
= protocolContact.getProtocolProvider();
OperationSetWebContactInfo wContactInfo
= mainFrame.getWebContactInfo(pps);
if(wContactInfo != null) {
GuiActivator.getBrowserLauncher().openURL(
wContactInfo.getWebContactInfo(protocolContact)
.toString());
}
}
else if(button.getName().equals("info"))
{
ProtocolProviderService pps
= protocolContact.getProtocolProvider();
OperationSetWebContactInfo wContactInfo
= mainFrame.getWebContactInfoOpSet(pps);
if(wContactInfo != null) {
GuiActivator.getBrowserLauncher().openURL(
wContactInfo.getWebContactInfo(protocolContact)
.toString());
}
}
}

@ -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);
}

@ -5,7 +5,7 @@
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.message;
package net.java.sip.communicator.impl.gui.main.chat;
import java.awt.*;
import java.awt.datatransfer.*;
@ -23,8 +23,8 @@
import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.i18n.*;
import net.java.sip.communicator.impl.gui.lookandfeel.*;
import net.java.sip.communicator.impl.gui.main.message.history.*;
import net.java.sip.communicator.impl.gui.main.message.menus.*;
import net.java.sip.communicator.impl.gui.main.chat.history.*;
import net.java.sip.communicator.impl.gui.main.chat.menus.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.util.*;
@ -413,8 +413,7 @@ private void ensureDocumentSize()
//toolbar in order to load differently messages for the last page.
if(chatContainer instanceof ChatPanel) {
((ChatPanel)chatContainer).getChatWindow()
.getMainToolBar().setBeginLastPageTimeStamp(
((ChatPanel)chatContainer).setBeginLastPageTimeStamp(
pageFirstMsgTimestamp);
pageFirstMsgTimestamp = newFirstMsgTimestamp;
@ -487,10 +486,12 @@ private String processLinks(String message)
String replacement;
if (matchGroup.startsWith("www")) {
replacement = "</PLAINTEXT><A href=\"" + "http://" + matchGroup + "\">"
replacement = "</PLAINTEXT><A href=\"" + "http://"
+ matchGroup + "\">"
+ matchGroup + "</A><PLAINTEXT>";
} else {
replacement = "</PLAINTEXT><A href=\"" + matchGroup + "\">" + matchGroup
replacement = "</PLAINTEXT><A href=\"" + matchGroup + "\">"
+ matchGroup
+ "</A><PLAINTEXT>";
}
m.appendReplacement(msgBuffer, replacement);
@ -645,7 +646,7 @@ public void setCarretToEnd()
this.chatEditorPane.setCaretPosition(this.document.getLength());
}
}
/**
* When a right button click is performed in the editor pane, a
* popup menu is opened.

@ -4,8 +4,7 @@
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.message;
package net.java.sip.communicator.impl.gui.main.chat;
import java.awt.*;
import java.awt.event.*;
@ -16,13 +15,8 @@
import javax.swing.text.*;
import javax.swing.text.html.*;
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.utils.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.gui.*;
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.*;
@ -38,141 +32,265 @@
*
* @author Yana Stamcheva
*/
public class ChatPanel
public abstract class ChatPanel
extends JPanel
implements ApplicationWindow,
ChatConversationContainer
{
private static final Logger logger = Logger
.getLogger(ChatPanel.class.getName());
private JSplitPane topSplitPane = new JSplitPane(
JSplitPane.HORIZONTAL_SPLIT);
private JSplitPane messagePane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
private ChatConversationPanel conversationPanel;
private ChatWritePanel writeMessagePanel;
private ChatConferencePanel chatConferencePanel;
private ChatContactListPanel chatContactListPanel;
private ChatSendPanel sendPanel;
private ChatWindow chatWindow;
private MetaContact metaContact;
private boolean isVisible = false;
private Date firstHistoryMsgTimestamp;
private Date lastHistoryMsgTimestamp;
MessageHistoryService msgHistory
= GuiActivator.getMsgHistoryService();
private boolean isChatVisible;
public static final int TYPING_NOTIFICATION_SUCCESSFULLY_SENT = 1;
public static final int TYPING_NOTIFICATION_SEND_FAILED = 0;
private Date beginLastPageTimeStamp;
protected static final int MESSAGES_PER_PAGE = 20;
/**
* Creates a <tt>ChatPanel</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.
* @param metaContacts the list of meta contacts contained in this chat
* @param protocolContacts the list of selected protocol contacts in this
* chat
*/
public ChatPanel( ChatWindow chatWindow,
MetaContact metaContact,
Contact protocolContact) {
public ChatPanel(ChatWindow chatWindow)
{
super(new BorderLayout());
this.chatWindow = chatWindow;
this.metaContact = metaContact;
this.conversationPanel = new ChatConversationPanel(this);
this.chatConferencePanel = new ChatConferencePanel(this,
metaContact, protocolContact);
this.chatContactListPanel = new ChatContactListPanel(this);
this.sendPanel = new ChatSendPanel(this, metaContact, protocolContact);
this.sendPanel = new ChatSendPanel(this);
this.writeMessagePanel = new ChatWritePanel(this);
this.topSplitPane.setResizeWeight(1.0D);
this.messagePane.setResizeWeight(1.0D);
this.chatConferencePanel.setPreferredSize(new Dimension(120, 100));
this.chatConferencePanel.setMinimumSize(new Dimension(120, 100));
this.chatContactListPanel.setPreferredSize(new Dimension(120, 100));
this.chatContactListPanel.setMinimumSize(new Dimension(120, 100));
this.writeMessagePanel.setPreferredSize(new Dimension(500, 100));
this.writeMessagePanel.setMinimumSize(new Dimension(500, 100));
this.conversationPanel.setPreferredSize(new Dimension(400, 200));
this.topSplitPane.setOneTouchExpandable(true);
topSplitPane.setLeftComponent(conversationPanel);
topSplitPane.setRightComponent(chatContactListPanel);
this.init();
this.messagePane.setTopComponent(topSplitPane);
this.messagePane.setBottomComponent(writeMessagePanel);
this.add(messagePane, BorderLayout.CENTER);
this.add(sendPanel, BorderLayout.SOUTH);
addComponentListener(new TabSelectionComponentListener());
}
public abstract Object getChatIdentifier();
public abstract String getChatName();
public abstract PresenceStatus getChatStatus();
public abstract void loadHistory();
public abstract void loadHistory(String escapedMessageID);
public abstract void loadPreviousFromHistory();
public abstract void loadNextFromHistory();
protected abstract void sendMessage();
public abstract void treatReceivedMessage(Contact sourceContact);
public abstract int sendTypingNotification(int typingState);
public abstract Date getFirstHistoryMsgTimestamp();
public abstract Date getLastHistoryMsgTimestamp();
public ChatWindow getChatWindow()
{
return chatWindow;
}
new Thread(){
public void run(){
loadHistoryPeriod();
}
}.start();
/**
* Returns the chat window, where this chat panel
* is located. Implements the
* <tt>ChatConversationContainer.getConversationContainerWindow()</tt>
* method.
*
* @return ChatWindow The chat window, where this
* chat panel is located.
*/
public Window getConversationContainerWindow() {
return chatWindow;
}
/**
* 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){
this.sendPanel.setStatusMessage(statusMessage);
}
public ChatConversationPanel getChatConversationPanel()
{
return this.conversationPanel;
}
public ChatWritePanel getChatWritePanel()
{
return this.writeMessagePanel;
}
public ChatContactListPanel getChatContactListPanel()
{
return this.chatContactListPanel;
}
public ChatSendPanel getChatSendPanel()
{
return this.sendPanel;
}
/**
* Initializes this panel.
* When user select a chat tab clicking with the mouse we change the
* currently selected chat panel, thus changing the title of the window,
* history buttons states, etc.
*/
private void init() {
this.topSplitPane.setOneTouchExpandable(true);
private class TabSelectionComponentListener
implements ComponentListener {
topSplitPane.setLeftComponent(conversationPanel);
topSplitPane.setRightComponent(chatConferencePanel);
public TabSelectionComponentListener() {
super();
}
this.messagePane.setTopComponent(topSplitPane);
this.messagePane.setBottomComponent(writeMessagePanel);
public void componentResized(ComponentEvent e) {
}
this.add(messagePane, BorderLayout.CENTER);
this.add(sendPanel, BorderLayout.SOUTH);
public void componentMoved(ComponentEvent e) {
}
public void componentShown(ComponentEvent e)
{
Component component = e.getComponent();
Container parent = component.getParent();
if (!(parent instanceof JTabbedPane))
return;
JTabbedPane tabbedPane = (JTabbedPane) parent;
if (tabbedPane.getSelectedComponent() != component)
return;
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
String chatName = getChatName();
if(!getChatWindow().getTitle().equals(chatName))
{
getChatWindow().setTitle(chatName);
getChatWindow().getMainToolBar()
.changeHistoryButtonsState(ChatPanel.this);
}
ChatPanel.this.requestFocusInWriteArea();
}
});
}
public void componentHidden(ComponentEvent e) {
}
}
/**
* Loads history in another thread.
* Moves the caret to the end of the conversation panel, contained in the
* given chat panel.
*
* Workaround for the following problem:
* The scrollbar in the conversation area moves up when the
* scrollpane is resized. This happens when ChatWindow is in
* mode "Group messages in one window" and the first chat panel
* is added to the tabbed pane. Then the scrollpane in the
* conversation area is slightly resized and is made smaller,
* which moves the scrollbar up.
*/
public void loadHistory()
public void setCaretToEnd()
{
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();
ChatConversationPanel chatConversationPanel
= getChatConversationPanel();
HTMLDocument doc = (HTMLDocument) chatConversationPanel
.getChatEditorPane().getDocument();
Element root = doc.getDefaultRootElement();
try {
doc.insertAfterEnd(root
.getElement(root.getElementCount() - 1), "<br>");
} catch (BadLocationException e) {
logger.error("Insert in the HTMLDocument failed.", e);
} catch (IOException e) {
logger.error("Insert in the HTMLDocument failed.", e);
}
//Scroll to the last inserted text in the document.
chatConversationPanel.setCarretToEnd();
}
/**
* Loads history messages ignoring the message given by the
* escapedMessageID.
* @param escapedMessageID The id of the message that should be ignored.
* Requests the focus in the write message area.
*/
public void requestFocusInWriteArea()
{
getChatWritePanel().getEditorPane().requestFocus();
}
/**
* Checks if the editor contains text.
*
* @return TRUE if editor contains text, FALSE otherwise.
*/
public void loadHistory(String escapedMessageID)
public boolean isWriteAreaEmpty()
{
Collection historyList = msgHistory.findLast(
metaContact, Constants.CHAT_HISTORY_SIZE);
JEditorPane editorPane = getChatWritePanel().getEditorPane();
processHistory(historyList, escapedMessageID);
if (editorPane.getText() == null
|| editorPane.getText().equals(""))
return true;
else
return false;
}
/**
@ -198,7 +316,7 @@ public void processHistory(Collection historyList,
.getDestinationContact().getProtocolProvider();
historyString += processHistoryMessage(
chatWindow.getMainFrame()
getChatWindow().getMainFrame()
.getAccount(protocolProvider),
evt.getTimestamp(),
Constants.HISTORY_OUTGOING_MESSAGE,
@ -219,137 +337,7 @@ else if(o instanceof MessageReceivedEvent) {
}
conversationPanel.insertMessageAfterStart(historyString);
}
/**
* Updates the contact status in the chat panel.
*
* @param metaContact the meta contact that this chat is about.
* @param protoContact the protocol contact which status to update.
*/
public void updateContactStatus(MetaContact metaContact, Contact protoContact)
{
PresenceStatus status = sendPanel.getProtoContactSelectorBox()
.getSelectedProtocolContact().getPresenceStatus();
this.chatConferencePanel.updateContactStatus(
metaContact.getDefaultContact().getPresenceStatus());
this.sendPanel.updateContactStatus(protoContact);
String message = this.conversationPanel.processMessage(
this.metaContact.getDisplayName(),
new Date(System.currentTimeMillis()),
Constants.SYSTEM_MESSAGE,
Messages.getI18NString("statusChangedChatMessage",
new String[]{status.getStatusName()}).getText());
this.conversationPanel.appendMessageToEnd(message);
}
/**
* Returns the default contact for the chat. The case of conference
* is not yet implemented and for now it returns the first contact.
*
* @return The default contact for the chat.
*/
public MetaContact getMetaContact() {
return this.metaContact;
}
/**
* Returns the chat window, where this chat panel
* is located.
*
* @return ChatWindow The chat window, where this
* chat panel is located.
*/
public ChatWindow getChatWindow() {
return chatWindow;
}
/**
* Returns the chat window, where this chat panel
* is located.
*
* @return ChatWindow The chat window, where this
* chat panel is located.
*/
public Window getWindow() {
return chatWindow;
}
/**
* When user select a chat tab clicking with the mouse we change the
* currently selected chat panel, thus changing the title of the window,
* history buttons states, etc.
*/
private class TabSelectionComponentListener
implements ComponentListener {
public TabSelectionComponentListener() {
super();
}
public void componentResized(ComponentEvent e) {
}
public void componentMoved(ComponentEvent e) {
}
public void componentShown(ComponentEvent e)
{
Component component = e.getComponent();
Container parent = component.getParent();
if (parent instanceof JTabbedPane)
{
JTabbedPane tabbedPane = (JTabbedPane) parent;
if (tabbedPane.getSelectedComponent() == component)
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
String metaContactName
= getMetaContact().getDisplayName();
if(!chatWindow.getTitle().equals(metaContactName))
{
chatWindow.setTitle(metaContactName);
chatWindow.getMainToolBar()
.changeHistoryButtonsState(ChatPanel.this);
}
ChatPanel.this.requestFocusInWriteArea();
}
});
}
}
}
public void componentHidden(ComponentEvent e) {
}
}
/**
* Returns the protocol contact for this chat.
* @return The protocol contact for this chat.
*/
public Contact getProtocolContact() {
return sendPanel.getProtoContactSelectorBox()
.getSelectedProtocolContact();
}
/**
* Sets the currently selected protocol contact to use for sending messages.
* @param protocolContact the protocol contact to select.
*/
public void setProtocolContact(Contact protocolContact) {
sendPanel.getProtoContactSelectorBox()
.setSelected(protocolContact);
}
/**
* Passes the message to the contained <code>ChatConversationPanel</code>
* for processing and appends it at the end of the conversationPanel
@ -362,11 +350,12 @@ public void setProtocolContact(Contact protocolContact) {
* @param message The message text.
*/
public void processMessage(String contactName, Date date,
String messageType, String message){
String messageType, String message)
{
String processedMessage
= this.conversationPanel.processMessage(contactName, date,
messageType, message);
this.conversationPanel.appendMessageToEnd(processedMessage);
this.conversationPanel.appendMessageToEnd(processedMessage);
}
/**
@ -398,48 +387,7 @@ public void refreshWriteArea(){
writeMsgPane.setText("");
}
/**
* Requests the focus in the write message area.
*/
public void requestFocusInWriteArea()
{
this.writeMessagePanel.getEditorPane().requestFocus();
}
/**
* 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){
this.sendPanel.setStatusMessage(statusMessage);
}
/**
* Returns the time of the last received message.
*
* @return The time of the last received message.
*/
public Date getLastIncomingMsgTimestamp() {
return this.conversationPanel.getLastIncomingMsgTimestamp();
}
/**
* Checks if the editor contains text.
*
* @return TRUE if editor contains text, FALSE otherwise.
*/
public boolean isWriteAreaEmpty(){
JEditorPane editorPane = this.writeMessagePanel.getEditorPane();
if (editorPane.getText() == null
|| editorPane.getText().equals(""))
return true;
else
return false;
}
/**
* Adds text to the write area editor.
*
@ -460,14 +408,7 @@ public String getTextFromWriteArea(){
return editorPane.getText();
}
/**
* Stops typing notifications sending.
*/
public void stopTypingNotifications(){
this.writeMessagePanel.stopTypingTimer();
}
/**
* Cuts the write area selected content to the clipboard.
*/
@ -507,67 +448,18 @@ public void paste(){
editorPane.requestFocus();
}
/**
* Sends current write area content.
*/
public void sendMessage(){
public void sendButtonDoClick()
{
JButton sendButton = this.sendPanel.getSendButton();
sendButton.requestFocus();
sendButton.doClick();
}
/**
* Moves the caret to the end of the conversation panel.
*
* Workaround for the following problem:
* The scrollbar in the conversation area moves up when the
* scrollpane is resized. This happens when ChatWindow is in
* mode "Group messages in one window" and the first chat panel
* is added to the tabbed pane. Then the scrollpane in the
* conversation area is slightly resized and is made smaller,
* which moves the scrollbar up.
*/
public void setCaretToEnd(){
HTMLDocument doc = (HTMLDocument)this.conversationPanel
.getChatEditorPane().getDocument();
Element root = doc.getDefaultRootElement();
try {
doc.insertAfterEnd(root
.getElement(root.getElementCount() - 1), "<br>");
} catch (BadLocationException e) {
logger.error("Insert in the HTMLDocument failed.", e);
} catch (IOException e) {
logger.error("Insert in the HTMLDocument failed.", e);
}
//Scroll to the last inserted text in the document.
this.conversationPanel.setCarretToEnd();
}
/**
* Opens the selector box containing the protocol contact icons. This is the
* menu, where user could select the protocol specific contact to
* communicate through.
*/
public void openProtocolSelectorBox() {
SIPCommMenu contactSelector
= this.sendPanel.getProtoContactSelectorBox().getMenu();
contactSelector.doClick();
}
/**
* Returns the <tt>PresenceStatus</tt> of the default contact for this chat
* panel.
* @return the <tt>PresenceStatus</tt> of the default contact for this chat
* panel.
*/
public PresenceStatus getDefaultContactStatus() {
return getMetaContact().getDefaultContact().getPresenceStatus();
}
/**
* Implements the <code>ApplicationWindow.isVisible</code> method, to
* check whether this chat panel is currently visible.
@ -575,7 +467,7 @@ public PresenceStatus getDefaultContactStatus() {
* <code>false</code> otherwise.
*/
public boolean isWindowVisible() {
return this.isVisible;
return isChatVisible;
}
/**
@ -584,7 +476,7 @@ public boolean isWindowVisible() {
*/
public void showWindow()
{
//TODO: Implement the showWindow method coming from Application Window
}
/**
@ -593,7 +485,7 @@ public void showWindow()
*/
public void hideWindow()
{
//TODO: Implement the hideWindow method coming from Application Window
}
/**
@ -603,7 +495,7 @@ public void hideWindow()
* @param height The new height to set.
*/
public void resizeWindow(int width, int height) {
this.chatWindow.setSize(width, height);
getChatWindow().setSize(width, height);
}
/**
@ -613,7 +505,7 @@ public void resizeWindow(int width, int height) {
* @param y The <code>y</code> coordinate.
*/
public void moveWindow(int x, int y) {
this.chatWindow.setLocation(x, y);
getChatWindow().setLocation(x, y);
}
/**
@ -622,7 +514,7 @@ public void moveWindow(int x, int y) {
*/
public void minimizeWindow()
{
this.chatWindow.setState(JFrame.ICONIFIED);
getChatWindow().setState(JFrame.ICONIFIED);
}
/**
@ -631,7 +523,7 @@ public void minimizeWindow()
*/
public void maximizeWindow()
{
this.chatWindow.setState(JFrame.MAXIMIZED_BOTH);
getChatWindow().setState(JFrame.MAXIMIZED_BOTH);
}
/**
@ -643,116 +535,17 @@ public void maximizeWindow()
* not.
*/
public void setChatVisible(boolean isVisible) {
this.isVisible = isVisible;
this.isChatVisible = isVisible;
}
/**
* Returns the chat conversation panel contained in this chat panel.
* @return the chat conversation panel contained in this chat panel
*/
public ChatConversationPanel getChatConversationPanel()
public void setBeginLastPageTimeStamp(Date pageFirstMsgTimestamp)
{
return conversationPanel;
this.beginLastPageTimeStamp = pageFirstMsgTimestamp;
}
/**
* Returns the chat write panel contained in this chat panel.
* @return the chat write panel contained in this chat panel
*/
public ChatWritePanel getChatWritePanel()
{
return writeMessagePanel;
}
/**
* Returns the chat send panel contained in this chat panel.
* @return the chat send panel contained in this chat panel
*/
public ChatSendPanel getChatSendPanel()
{
return sendPanel;
}
/**
* 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();
}
}
this.chatWindow.getMainToolBar().changeHistoryButtonsState(this);
}
public Date getFirstHistoryMsgTimestamp()
{
return firstHistoryMsgTimestamp;
}
public Date getLastHistoryMsgTimestamp()
{
return lastHistoryMsgTimestamp;
}
/**
* Updates all occurences of the contact name in the chat.
* @param newName the new name
*/
public void renameContact(String newName)
{
chatConferencePanel.renameContact(newName);
chatWindow.setTabTitle(this, newName);
if( chatWindow.getCurrentChatPanel() == this)
{
chatWindow.setTitle(newName);
}
}
public ChatConferencePanel getChatConferencePanel()
public Date getBeginLastPageTimeStamp()
{
return chatConferencePanel;
return beginLastPageTimeStamp;
}
}

@ -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;
}
}

@ -5,10 +5,11 @@
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.message;
package net.java.sip.communicator.impl.gui.main.chat;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
@ -16,8 +17,8 @@
import net.java.sip.communicator.impl.gui.customcontrols.*;
import net.java.sip.communicator.impl.gui.customcontrols.events.*;
import net.java.sip.communicator.impl.gui.main.*;
import net.java.sip.communicator.impl.gui.main.message.menus.*;
import net.java.sip.communicator.impl.gui.main.message.toolBars.*;
import net.java.sip.communicator.impl.gui.main.chat.menus.*;
import net.java.sip.communicator.impl.gui.main.chat.toolBars.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.configuration.*;
import net.java.sip.communicator.service.protocol.*;
@ -45,16 +46,15 @@ public class ChatWindow
private MainFrame mainFrame;
private String windowTitle = "";
private SIPCommTabbedPane chatTabbedPane = null;
private boolean enableTypingNotification = true;
/**
* Creates an instance of <tt>ChatWindow</tt>.
* Creates an instance of <tt>ChatWindow</tt> by passing to it an instance
* of the main application window.
*
* @param mainFrame The parent MainFrame.
* @param mainFrame the main application window
*/
public ChatWindow(MainFrame mainFrame)
{
@ -89,7 +89,7 @@ public void closeOperation(MouseEvent e)
this.setSizeAndLocation();
this.init();
this.getContentPane().add(menusPanel, BorderLayout.NORTH);
this.addKeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT,
KeyEvent.ALT_DOWN_MASK), new ForwordTabAction());
@ -105,8 +105,6 @@ public void closeOperation(MouseEvent e)
KeyEvent.META_MASK), new PasteAction());
this.addKeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_M,
KeyEvent.CTRL_DOWN_MASK), new OpenSmileyAction());
this.addKeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_P,
KeyEvent.CTRL_DOWN_MASK), new ChangeProtocolAction());
this.addKeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_H,
KeyEvent.CTRL_DOWN_MASK), new OpenHistoryAction());
this.addKeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_W,
@ -138,14 +136,6 @@ public void changeSendCommand(boolean isEnter)
"CtrlEnter");
}
/**
* Initializes this window, by adding the menus.
*/
public void init()
{
this.getContentPane().add(menusPanel, BorderLayout.NORTH);
}
/**
* Returns the main application widnow.
*
@ -155,16 +145,6 @@ public MainFrame getMainFrame()
{
return mainFrame;
}
/**
* Sets the main application widnow.
*
* @param mainFrame The main application widnow.
*/
public void setMainFrame(MainFrame mainFrame)
{
this.mainFrame = mainFrame;
}
/**
* Returns the main toolbar in this chat window.
@ -210,28 +190,28 @@ private void addSimpleChat(ChatPanel chatPanel)
*/
private void addChatTab(ChatPanel chatPanel)
{
String contactName = chatPanel.getMetaContact().getDisplayName();
PresenceStatus status = chatPanel.getDefaultContactStatus();
String chatName = chatPanel.getChatName();
PresenceStatus status = chatPanel.getChatStatus();
if (getCurrentChatPanel() == null)
{
this.getContentPane().add(chatPanel, BorderLayout.CENTER);
}
else
{
{
if (getChatTabCount() == 0)
{
ChatPanel firstChatPanel = getCurrentChatPanel();
PresenceStatus currentContactStatus = firstChatPanel
.getDefaultContactStatus();
.getChatStatus();
// Add first two tabs to the tabbed pane.
chatTabbedPane.addTab(firstChatPanel.getMetaContact()
.getDisplayName(), new ImageIcon(Constants
.getStatusIcon(currentContactStatus)), firstChatPanel);
chatTabbedPane.addTab(firstChatPanel.getChatName(),
new ImageIcon(Constants.getStatusIcon(currentContactStatus)),
firstChatPanel);
chatTabbedPane.addTab(contactName, new ImageIcon(Constants
chatTabbedPane.addTab(chatName, new ImageIcon(Constants
.getStatusIcon(status)), chatPanel);
//when added to the tabbed pane, the first chat panel should rest
@ -255,7 +235,7 @@ private void addChatTab(ChatPanel chatPanel)
{
// The tabbed pane contains already tabs.
chatTabbedPane.addTab(contactName, new ImageIcon(Constants
chatTabbedPane.addTab(chatName, new ImageIcon(Constants
.getStatusIcon(status)), chatPanel);
chatTabbedPane.getParent().validate();
@ -271,7 +251,7 @@ private void addChatTab(ChatPanel chatPanel)
public void removeChat(ChatPanel chatPanel)
{
logger.debug("Removes chat for contact: "
+ chatPanel.getMetaContact().getDisplayName());
+ chatPanel.getChatName());
//if there's no tabs remove the chat panel directly from the content
//pane and hide the window.
@ -348,12 +328,12 @@ public void removeAllChats()
public void setCurrentChatPanel(ChatPanel chatPanel)
{
logger.debug("Set current chat panel to: "
+ chatPanel.getMetaContact().getDisplayName());
+ chatPanel.getChatName());
if(getChatTabCount() > 0)
this.chatTabbedPane.setSelectedComponent(chatPanel);
this.setTitle(chatPanel.getMetaContact().getDisplayName());
this.setTitle(chatPanel.getChatName());
this.getMainToolBar().changeHistoryButtonsState(chatPanel);
@ -528,7 +508,7 @@ public void actionPerformed(ActionEvent e)
{
ChatPanel chatPanel = getCurrentChatPanel();
// chatPanel.stopTypingNotifications();
chatPanel.sendMessage();
chatPanel.sendButtonDoClick();
}
}
@ -558,19 +538,7 @@ public void actionPerformed(ActionEvent e)
}
}
/**
* 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)
{
getCurrentChatPanel().openProtocolSelectorBox();
}
}
/**
* The <tt>CloseAction</tt> is an <tt>AbstractAction</tt> that
* closes a tab in the chat window.
@ -584,6 +552,19 @@ public void actionPerformed(ActionEvent e)
}
}
/**
* Returns the time of the last received message.
*
* @return The time of the last received message.
*/
public Date getLastIncomingMsgTimestamp(ChatPanel chatPanel)
{
return chatPanel.getChatConversationPanel()
.getLastIncomingMsgTimestamp();
}
/**
* Enables typing notifications.
*
@ -639,8 +620,8 @@ protected void close(boolean isEscaped)
.getChatWritePanel().getRightButtonMenu();
SIPCommMenu selectedMenu = menusPanel.getMainMenuBar().getSelectedMenu();
SIPCommMenu contactMenu = getCurrentChatPanel().getChatSendPanel()
.getProtoContactSelectorBox().getMenu();
//SIPCommMenu contactMenu = getCurrentChatPanel()
// .getProtoContactSelectorBox().getMenu();
MenuSelectionManager menuSelectionManager
= MenuSelectionManager.defaultManager();
@ -654,7 +635,7 @@ else if (writePanelRightMenu.isVisible()) {
writePanelRightMenu.setVisible(false);
}
else if (selectedMenu != null
|| contactMenu.isPopupMenuVisible()
//|| contactMenu.isPopupMenuVisible()
|| menusPanel.getMainToolBar().hasSelectedMenus()) {
menuSelectionManager.clearSelectedPath();
@ -666,5 +647,5 @@ else if (selectedMenu != null
else {
mainFrame.getChatWindowManager().closeWindow();
}
}
}
}

@ -4,7 +4,7 @@
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.message;
package net.java.sip.communicator.impl.gui.main.chat;
import java.util.*;
@ -13,7 +13,7 @@
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.main.contactlist.*;
import net.java.sip.communicator.impl.gui.main.chat.conference.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.protocol.*;
@ -91,6 +91,8 @@ else if(!chatWindow.getCurrentChatPanel().equals(chatPanel)
&& chatWindow.getChatTabCount() > 0)
{
chatPanel.getChatWindow().highlightTab(chatPanel);
chatPanel.setCaretToEnd();
}
}
else
@ -98,12 +100,19 @@ else if(!chatWindow.getCurrentChatPanel().equals(chatPanel)
chatWindow.setVisible(true);
chatWindow.setCurrentChatPanel(chatPanel);
}
chatPanel.setCaretToEnd();
chatPanel.setCaretToEnd();
}
}
}
/**
* Returns TRUE if there is an opened <tt>ChatPanel</tt> for the given
* <tt>MetaContact</tt>.
* @param metaContact the <tt>MetaContact</tt>, for which the chat is about
* @return TRUE if there is an opened <tt>ChatPanel</tt> for the given
* <tt>MetaContact</tt>
*/
public boolean isChatOpenedForContact(MetaContact metaContact)
{
synchronized (syncChat)
@ -115,6 +124,25 @@ && getChat(metaContact).isVisible())
return false;
}
}
/**
* Returns TRUE if there is an opened <tt>ChatPanel</tt> for the given
* <tt>ChatRoom</tt>.
* @param chatRoom the <tt>ChatRoom</tt>, for which the chat is about
* @return TRUE if there is an opened <tt>ChatPanel</tt> for the given
* <tt>ChatRoom</tt>
*/
public boolean isChatOpenedForChatRoom(ChatRoom chatRoom)
{
synchronized (syncChat)
{
if(containsChat(chatRoom)
&& getChat(chatRoom).isVisible())
return true;
return false;
}
}
/**
* Closes the chat corresponding to the given meta contact.
@ -148,12 +176,14 @@ public void closeChat(ChatPanel chatPanel)
msgText, Messages.getI18NString("warning").getText(),
JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
if (answer == JOptionPane.OK_OPTION) {
if (answer == JOptionPane.OK_OPTION)
{
closeChatPanel(chatPanel);
}
}
else if (System.currentTimeMillis() - chatPanel
.getLastIncomingMsgTimestamp().getTime() < 2 * 1000) {
else if (System.currentTimeMillis() - chatWindow
.getLastIncomingMsgTimestamp(chatPanel).getTime() < 2 * 1000)
{
SIPCommMsgTextArea msgText = new SIPCommMsgTextArea(Messages
.getI18NString("closeChatAfterNewMsg").getText());
@ -161,9 +191,8 @@ else if (System.currentTimeMillis() - chatPanel
msgText, Messages.getI18NString("warning").getText(),
JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
if (answer == JOptionPane.OK_OPTION) {
if (answer == JOptionPane.OK_OPTION)
closeChatPanel(chatPanel);
}
}
else {
closeChatPanel(chatPanel);
@ -172,11 +201,17 @@ else if (System.currentTimeMillis() - chatPanel
}
}
/**
* Closes the chat window. Removes all contained chats and invokes
* setVisible(false) to the window.
*/
public void closeWindow()
{
synchronized (syncChat)
{
if (!chatWindow.getCurrentChatPanel().isWriteAreaEmpty())
ChatPanel chatPanel = chatWindow.getCurrentChatPanel();
if (!chatPanel.isWriteAreaEmpty())
{
SIPCommMsgTextArea msgText = new SIPCommMsgTextArea(Messages
.getI18NString("nonEmptyChatWindowClose").getText());
@ -195,8 +230,8 @@ public void closeWindow()
}
}
}
else if (System.currentTimeMillis() - chatWindow.getCurrentChatPanel()
.getLastIncomingMsgTimestamp().getTime() < 2 * 1000)
else if (System.currentTimeMillis() - chatWindow
.getLastIncomingMsgTimestamp(chatPanel).getTime() < 2 * 1000)
{
SIPCommMsgTextArea msgText = new SIPCommMsgTextArea(Messages
.getI18NString("closeChatAfterNewMsg").getText());
@ -246,8 +281,8 @@ public ChatPanel getContactChat(MetaContact metaContact)
else
return createChat(metaContact);
}
}
}
/**
* Returns the chat panel corresponding to the given meta contact
*
@ -291,42 +326,26 @@ public ChatPanel getContactChat(MetaContact metaContact,
return createChat(metaContact, protocolContact, escapedMessageID);
}
}
/**
* Updates the status of the given metacontact in all opened chats
* containing this contact.
*
* @param metaContact the contact whose status we will be updating
* @param protoContact the protocol specific contact
* Returns the chat panel corresponding to the given chat room.
*
* @param chatRoom the chat room, for which the chat panel is about
* @return the chat panel corresponding to the given chat room
*/
public void updateChatContactStatus(MetaContact metaContact,
Contact protoContact)
public ChatPanel getChatRoom(ChatRoom chatRoom)
{
synchronized (syncChat)
{
if(containsChat(metaContact))
if(containsChat(chatRoom))
{
ContactListModel listModel
= (ContactListModel) mainFrame.getContactListPanel()
.getContactList().getModel();
ChatPanel chatPanel = getChat(metaContact);
chatPanel.updateContactStatus(metaContact, protoContact);
if(Constants.TABBED_CHAT_WINDOW)
{
ChatWindow chatWindow = chatPanel.getChatWindow();
if (chatWindow.getChatTabCount() > 0) {
chatWindow.setTabIcon(chatPanel, listModel
.getMetaContactStatusIcon(metaContact));
}
}
return getChat(chatRoom);
}
else
return createChat(chatRoom);
}
}
/**
* Closes the selected chat tab or the window if there are no tabs.
*
@ -338,7 +357,7 @@ private void closeChatPanel(ChatPanel chatPanel)
synchronized (chats)
{
chats.remove(chatPanel.getMetaContact());
chats.remove(chatPanel.getChatIdentifier());
}
}
@ -432,7 +451,7 @@ private ChatPanel createChat(MetaContact contact,
}
ChatPanel chatPanel
= new ChatPanel(chatWindow, contact, protocolContact);
= new MetaContactChatPanel(chatWindow, contact, protocolContact);
synchronized (chats)
{
@ -447,20 +466,52 @@ private ChatPanel createChat(MetaContact contact,
return chatPanel;
}
/**
* Creates a <tt>ChatPanel</tt> for the given <tt>ChatRoom</tt> and saves it
* in the list ot created <tt>ChatPanel</tt>s.
*
* @param chatRoom the <tt>ChatRoom</tt>, for which the chat will be created
* @return The <code>ChatPanel</code> newly created.
*/
private ChatPanel createChat(ChatRoom chatRoom)
{
ChatWindow chatWindow;
if(Constants.TABBED_CHAT_WINDOW)
chatWindow = this.chatWindow;
else
{
chatWindow = new ChatWindow(mainFrame);
this.chatWindow = chatWindow;
}
ChatPanel chatPanel
= new ConferenceChatPanel(chatWindow, chatRoom);
synchronized (chats)
{
this.chats.put(chatRoom, chatPanel);
}
return chatPanel;
}
/**
* Returns TRUE if this chat window contains a chat for the given contact,
* FALSE otherwise.
*
* @param metaContact the meta contact whose corresponding chat we're
* looking for.
* @return TRUE if this chat window contains a chat for the given contact,
* FALSE otherwise
* @param key the key, which corresponds to the chat we are looking for. It
* could be a <tt>MetaContact</tt> in the case of single user chat and
* a <tt>ChatRoom</tt> in the case of a multi user chat
* @return TRUE if this chat window contains a chat corresponding to the
* given key, FALSE otherwise
*/
private boolean containsChat(MetaContact metaContact)
private boolean containsChat(Object key)
{
synchronized (chats)
{
return chats.containsKey(metaContact);
return chats.containsKey(key);
}
}
@ -482,14 +533,17 @@ private boolean containsChat(ChatPanel chatPanel)
/**
* Returns the <tt>ChatPanel</tt> corresponding to the given meta contact.
* @param metaContact the <tt>MetaContact</tt> object for the chat
*
* @param key the key, which corresponds to the chat we are looking for. It
* could be a <tt>MetaContact</tt> in the case of single user chat and
* a <tt>ChatRoom</tt> in the case of a multi user chat
* @return the <tt>ChatPanel</tt> corresponding to the given meta contact
*/
private ChatPanel getChat(MetaContact metaContact)
private ChatPanel getChat(Object key)
{
synchronized (chats)
{
return (ChatPanel) chats.get(metaContact);
return (ChatPanel) chats.get(key);
}
}
}

@ -5,7 +5,7 @@
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.message;
package net.java.sip.communicator.impl.gui.main.chat;
import java.awt.*;
import java.awt.event.*;
@ -18,7 +18,7 @@
import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.i18n.*;
import net.java.sip.communicator.impl.gui.lookandfeel.*;
import net.java.sip.communicator.impl.gui.main.message.menus.*;
import net.java.sip.communicator.impl.gui.main.chat.menus.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.configuration.*;
import net.java.sip.communicator.service.protocol.*;
@ -155,7 +155,7 @@ private class SendMessageAction
public void actionPerformed(ActionEvent e)
{
// chatPanel.stopTypingNotifications();
chatPanel.sendMessage();
chatPanel.sendButtonDoClick();
}
}
@ -221,14 +221,7 @@ public void keyTyped(KeyEvent e) {
* Sends typing notifications when user types.
*/
public void keyPressed(KeyEvent e)
{
Contact chatProtocolContact = chatPanel.getProtocolContact();
OperationSetTypingNotifications tnOperationSet
= (OperationSetTypingNotifications)
chatProtocolContact.getProtocolProvider()
.getOperationSet(OperationSetTypingNotifications.class);
{
if ((e.getModifiers() & KeyEvent.CTRL_MASK) == KeyEvent.CTRL_MASK
&& (e.getKeyCode() == KeyEvent.VK_Z))
{
@ -241,9 +234,7 @@ else if ((e.getModifiers() & KeyEvent.CTRL_MASK) == KeyEvent.CTRL_MASK
if (undo.canRedo())
redo();
}
else if (chatProtocolContact.getProtocolProvider().isRegistered()
&& chatPanel.getChatWindow().isTypingNotificationEnabled()
&& tnOperationSet != null
else if (chatPanel.getChatWindow().isTypingNotificationEnabled()
&& e.getKeyCode() != KeyEvent.VK_ESCAPE)
{
if (typingState != OperationSetTypingNotifications.STATE_TYPING)
@ -251,16 +242,10 @@ else if (chatProtocolContact.getProtocolProvider().isRegistered()
stoppedTypingTimer.setDelay(2 * 1000);
typingState = OperationSetTypingNotifications.STATE_TYPING;
try
{
tnOperationSet.sendTypingNotification(
chatProtocolContact, typingState);
int result = chatPanel.sendTypingNotification(typingState);
if(result == ChatPanel.TYPING_NOTIFICATION_SUCCESSFULLY_SENT)
typingTimer.start();
}
catch (Exception ex)
{
logger.error("Failed to send typing notifications.", ex);
}
}
if (!stoppedTypingTimer.isRunning())
@ -279,25 +264,18 @@ public void keyReleased(KeyEvent e)
private class Timer1ActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Contact chatProtocolContact = chatPanel.getProtocolContact();
OperationSetTypingNotifications tnOperationSet
= (OperationSetTypingNotifications)
chatProtocolContact.getProtocolProvider()
.getOperationSet(OperationSetTypingNotifications.class);
{
typingTimer.stop();
if (typingState == OperationSetTypingNotifications.STATE_TYPING)
{
try
{
tnOperationSet.sendTypingNotification(
chatProtocolContact,
OperationSetTypingNotifications.STATE_PAUSED);
typingState = OperationSetTypingNotifications.STATE_PAUSED;
stoppedTypingTimer.setDelay(3 * 1000);
int result = chatPanel.sendTypingNotification(typingState);
if(result == ChatPanel.TYPING_NOTIFICATION_SUCCESSFULLY_SENT)
stoppedTypingTimer.setDelay(3 * 1000);
}
catch (Exception ex)
{
@ -320,17 +298,9 @@ private class Timer2ActionListener implements ActionListener
public void actionPerformed(ActionEvent e)
{
if (typingState == OperationSetTypingNotifications.STATE_TYPING)
{
Contact chatProtocolContact = chatPanel.getProtocolContact();
OperationSetTypingNotifications tnOperationSet
= (OperationSetTypingNotifications)
chatProtocolContact.getProtocolProvider()
.getOperationSet(OperationSetTypingNotifications.class);
tnOperationSet.sendTypingNotification(
chatProtocolContact,
OperationSetTypingNotifications.STATE_TYPING);
{
chatPanel.sendTypingNotification(
OperationSetTypingNotifications.STATE_TYPING);
}
}
}
@ -340,22 +310,12 @@ public void actionPerformed(ActionEvent e)
*/
public void stopTypingTimer()
{
Contact chatProtocolContact = chatPanel.getProtocolContact();
typingState = OperationSetTypingNotifications.STATE_STOPPED;
if (chatProtocolContact.getProtocolProvider().isRegistered())
{
OperationSetTypingNotifications tnOperationSet
= (OperationSetTypingNotifications)
chatProtocolContact.getProtocolProvider()
.getOperationSet(OperationSetTypingNotifications.class);
int result = chatPanel.sendTypingNotification(typingState);
tnOperationSet.sendTypingNotification(
chatPanel.getProtocolContact(),
OperationSetTypingNotifications.STATE_STOPPED);
typingState = OperationSetTypingNotifications.STATE_STOPPED;
stoppedTypingTimer.stop();
}
if(result == ChatPanel.TYPING_NOTIFICATION_SUCCESSFULLY_SENT)
stoppedTypingTimer.stop();
}
/**
@ -386,6 +346,12 @@ public void mouseEntered(MouseEvent e) {
public void mouseExited(MouseEvent e) {
}
/**
* Returns the <tt>WritePanelRightButtonMenu</tt> opened in this panel.
* Used by the <tt>ChatWindow</tt>, when the ESC button is pressed, to check
* if there is an open menu, which should be closed.
* @return the <tt>WritePanelRightButtonMenu</tt> opened in this panel
*/
public WritePanelRightButtonMenu getRightButtonMenu()
{
return rightButtonMenu;

@ -5,13 +5,13 @@
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.message;
package net.java.sip.communicator.impl.gui.main.chat;
import java.awt.*;
import javax.swing.*;
import net.java.sip.communicator.impl.gui.main.message.menus.*;
import net.java.sip.communicator.impl.gui.main.message.toolBars.*;
import net.java.sip.communicator.impl.gui.main.chat.menus.*;
import net.java.sip.communicator.impl.gui.main.chat.toolBars.*;
/**
* The <tt>MenusPanel</tt> is the panel, containing all toolbars in the chat

@ -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();
}
}
}

@ -4,7 +4,7 @@
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.message;
package net.java.sip.communicator.impl.gui.main.chat;
import java.awt.*;
import java.awt.event.*;
@ -14,9 +14,8 @@
import javax.swing.*;
import net.java.sip.communicator.impl.gui.customcontrols.*;
import net.java.sip.communicator.impl.gui.main.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.contactlist.MetaContact;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.*;
@ -34,7 +33,7 @@ public class ProtocolContactSelectorBox
private static final Logger logger
= Logger.getLogger(ProtocolContactSelectorBox.class);
private ChatPanel chatPanel;
private MetaContactChatPanel chatPanel;
private Hashtable contactsTable = new Hashtable();
@ -44,7 +43,7 @@ public class ProtocolContactSelectorBox
private Contact currentProtoContact;
public ProtocolContactSelectorBox(ChatPanel chatPanel,
public ProtocolContactSelectorBox(MetaContactChatPanel chatPanel,
MetaContact metaContact, Contact protocolContact)
{
this.chatPanel = chatPanel;

@ -5,7 +5,7 @@
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.message;
package net.java.sip.communicator.impl.gui.main.chat;
import java.util.*;

@ -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)
{
}
}

@ -4,7 +4,7 @@
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.message.history;
package net.java.sip.communicator.impl.gui.main.chat.history;
import java.awt.*;
import java.util.*;
@ -13,6 +13,13 @@
import net.java.sip.communicator.impl.gui.utils.*;
/**
* The <tt>DatesListRenderer</tt> is a <tt>ListCellRenderer</tt>, specialized
* to show dates. It's meant to be used in the history window in order to
* represent the list of history dates.
*
* @author Yana Stamcheva
*/
public class DatesListRenderer
extends JPanel
implements ListCellRenderer

@ -4,7 +4,7 @@
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.message.history;
package net.java.sip.communicator.impl.gui.main.chat.history;
import java.awt.*;
import java.util.*;

@ -5,7 +5,7 @@
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.message.history;
package net.java.sip.communicator.impl.gui.main.chat.history;
import java.awt.event.*;

@ -5,7 +5,7 @@
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.message.history;
package net.java.sip.communicator.impl.gui.main.chat.history;
import java.awt.*;
import java.awt.event.*;
@ -21,7 +21,7 @@
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.main.message.*;
import net.java.sip.communicator.impl.gui.main.chat.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.msghistory.*;
@ -82,6 +82,9 @@ public class HistoryWindow
private int lastProgress = 0;
public HistoryWindow(MainFrame mainFrame, Object o)
{}
/**
* Creates an instance of the <tt>HistoryWindow</tt>.
* @param mainFrame the main application window
@ -257,7 +260,7 @@ public void setStatusMessage(String message)
/**
* Implements <tt>ChatConversationContainer.getWindow</tt> method.
*/
public Window getWindow()
public Window getConversationContainerWindow()
{
return this;
}

@ -5,7 +5,7 @@
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.message.history;
package net.java.sip.communicator.impl.gui.main.chat.history;
import java.awt.*;
import java.awt.event.*;

@ -4,7 +4,7 @@
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.message.menus;
package net.java.sip.communicator.impl.gui.main.chat.menus;
import java.awt.*;
import java.awt.event.*;
@ -12,7 +12,7 @@
import javax.swing.*;
import net.java.sip.communicator.impl.gui.i18n.*;
import net.java.sip.communicator.impl.gui.main.message.*;
import net.java.sip.communicator.impl.gui.main.chat.*;
import net.java.sip.communicator.impl.gui.utils.*;
/**
@ -141,7 +141,9 @@ public void actionPerformed(ActionEvent e) {
} else if (itemText.equalsIgnoreCase("close")) {
Window window = this.chatConvPanel.getChatContainer().getWindow();
Window window = this.chatConvPanel
.getChatContainer().getConversationContainerWindow();
window.setVisible(false);
window.dispose();
}

@ -5,7 +5,7 @@
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.message.menus;
package net.java.sip.communicator.impl.gui.main.chat.menus;
import java.awt.event.*;
@ -13,7 +13,7 @@
import net.java.sip.communicator.impl.gui.customcontrols.*;
import net.java.sip.communicator.impl.gui.i18n.*;
import net.java.sip.communicator.impl.gui.main.message.*;
import net.java.sip.communicator.impl.gui.main.chat.*;
import net.java.sip.communicator.impl.gui.utils.*;
/**
* The <tt>EditMenu</tt> is the menu in the chat window menu bar, which contains

@ -5,7 +5,7 @@
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.message.menus;
package net.java.sip.communicator.impl.gui.main.chat.menus;
import java.awt.event.*;
@ -13,7 +13,7 @@
import net.java.sip.communicator.impl.gui.customcontrols.*;
import net.java.sip.communicator.impl.gui.i18n.*;
import net.java.sip.communicator.impl.gui.main.message.*;
import net.java.sip.communicator.impl.gui.main.chat.*;
import net.java.sip.communicator.impl.gui.utils.*;
/**
* The <tt>FileMenu</tt> is the menu in the chat window menu bar that contains

@ -5,7 +5,7 @@
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.message.menus;
package net.java.sip.communicator.impl.gui.main.chat.menus;
import java.awt.event.*;
@ -14,7 +14,7 @@
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.main.message.*;
import net.java.sip.communicator.impl.gui.main.chat.*;
import net.java.sip.communicator.util.*;
/**
* The <tt>HelpMenu</tt> is a menu in the main application menu bar.

@ -5,13 +5,12 @@
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.message.menus;
package net.java.sip.communicator.impl.gui.main.chat.menus;
import javax.swing.*;
import net.java.sip.communicator.impl.gui.customcontrols.*;
import net.java.sip.communicator.impl.gui.i18n.*;
import net.java.sip.communicator.impl.gui.main.message.*;
import net.java.sip.communicator.impl.gui.main.chat.*;
/**
* The <tt>MessageWindowMenuBar</tt> is the menu bar in the chat window where
* all menus are added.

@ -1,4 +1,4 @@
package net.java.sip.communicator.impl.gui.main.message.menus;
package net.java.sip.communicator.impl.gui.main.chat.menus;
import java.awt.event.*;
import javax.swing.*;
@ -6,7 +6,7 @@
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.message.*;
import net.java.sip.communicator.impl.gui.main.chat.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.configuration.*;

@ -4,14 +4,14 @@
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.message.menus;
package net.java.sip.communicator.impl.gui.main.chat.menus;
import java.awt.event.*;
import javax.swing.*;
import net.java.sip.communicator.impl.gui.i18n.*;
import net.java.sip.communicator.impl.gui.main.message.*;
import net.java.sip.communicator.impl.gui.main.chat.*;
import net.java.sip.communicator.impl.gui.utils.*;
/**

@ -5,7 +5,7 @@
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.message.toolBars;
package net.java.sip.communicator.impl.gui.main.chat.toolBars;
import java.awt.*;
import javax.swing.*;

@ -5,7 +5,7 @@
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.message.toolBars;
package net.java.sip.communicator.impl.gui.main.chat.toolBars;
import java.awt.*;
import java.awt.event.*;
@ -13,15 +13,11 @@
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.message.*;
import net.java.sip.communicator.impl.gui.main.message.history.*;
import net.java.sip.communicator.impl.gui.main.chat.*;
import net.java.sip.communicator.impl.gui.main.chat.history.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.msghistory.*;
import net.java.sip.communicator.service.protocol.event.*;
/**
* The <tt>MainToolBar</tt> is a <tt>JToolBar</tt> which contains buttons
@ -67,10 +63,6 @@ public class MainToolBar
private ChatToolbarButton fontButton = new ChatToolbarButton(ImageLoader
.getImage(ImageLoader.FONT_ICON));
private static final int MESSAGES_PER_PAGE = 20;
private Date beginLastPageTimeStamp;
SmiliesSelectorBox smiliesBox;
private ChatWindow messageWindow;
@ -193,6 +185,8 @@ public void actionPerformed(ActionEvent e)
AbstractButton button = (AbstractButton) e.getSource();
String buttonText = button.getName();
ChatPanel chatPanel = messageWindow.getCurrentChatPanel();
if (buttonText.equalsIgnoreCase("save")) {
// TODO: Implement the save operation in chat MainToolBar.
}
@ -201,108 +195,27 @@ else if (buttonText.equalsIgnoreCase("print")) {
}
else if (buttonText.equalsIgnoreCase("cut")) {
this.messageWindow.getCurrentChatPanel().cut();
chatPanel.cut();
}
else if (buttonText.equalsIgnoreCase("copy")) {
this.messageWindow.getCurrentChatPanel().copy();
chatPanel.copy();
}
else if (buttonText.equalsIgnoreCase("paste")) {
this.messageWindow.getCurrentChatPanel().paste();
chatPanel.paste();
}
else if (buttonText.equalsIgnoreCase("previous")) {
new Thread() {
public void run(){
MessageHistoryService msgHistory
= GuiActivator.getMsgHistoryService();
ChatPanel chatPanel
= messageWindow.getCurrentChatPanel();
ChatConversationPanel conversationPanel
= chatPanel.getChatConversationPanel();
MetaContact metaContact = chatPanel.getMetaContact();
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(beginLastPageTimeStamp == null)
beginLastPageTimeStamp = lastMessageTimeStamp;
}
}
}.start();
else if (buttonText.equalsIgnoreCase("previous"))
{
chatPanel.loadPreviousFromHistory();
changeHistoryButtonsState(chatPanel);
}
else if (buttonText.equalsIgnoreCase("next")) {
new Thread() {
public void run(){
MessageHistoryService msgHistory
= GuiActivator.getMsgHistoryService();
else if (buttonText.equalsIgnoreCase("next"))
{
chatPanel.loadPreviousFromHistory();
ChatPanel chatPanel
= messageWindow.getCurrentChatPanel();
ChatConversationPanel conversationPanel
= chatPanel.getChatConversationPanel();
MetaContact metaContact = chatPanel.getMetaContact();
Collection c;
if(beginLastPageTimeStamp.compareTo(
conversationPanel.getPageLastMsgTimestamp()) == 0) {
c = msgHistory.findByPeriod(
metaContact,
beginLastPageTimeStamp,
new Date(System.currentTimeMillis()));
}
else {
c = msgHistory.findFirstMessagesAfter(
metaContact,
conversationPanel.getPageLastMsgTimestamp(),
MESSAGES_PER_PAGE);
}
if(c.size() > 0)
SwingUtilities.invokeLater(
new HistoryMessagesLoader(c));
}
}.start();
changeHistoryButtonsState(chatPanel);
}
else if (buttonText.equalsIgnoreCase("sendFile")) {
@ -310,11 +223,9 @@ else if (buttonText.equalsIgnoreCase("sendFile")) {
else if (buttonText.equalsIgnoreCase("history")) {
HistoryWindow history = new HistoryWindow(messageWindow
.getMainFrame(), messageWindow.getCurrentChatPanel()
.getMetaContact());
.getMainFrame(), chatPanel.getChatIdentifier());
history.setVisible(true);
}
else if (buttonText.equalsIgnoreCase("font")) {
@ -354,39 +265,7 @@ public boolean hasSelectedMenus()
return false;
}
/**
* Loads a "page" from the history in the chat window. Invoked when history
* arrow keys are clicked.
*/
private class HistoryMessagesLoader implements Runnable {
private Collection msgHistory;
ChatPanel chatPanel;
ChatConversationPanel conversationPanel;
public HistoryMessagesLoader(Collection msgHistory)
{
this.msgHistory = msgHistory;
this.chatPanel
= messageWindow.getCurrentChatPanel();
this.conversationPanel
= chatPanel.getChatConversationPanel();
}
public void run()
{
conversationPanel.clear();
chatPanel.processHistory(msgHistory, "");
conversationPanel.setDefaultContent();
changeHistoryButtonsState(chatPanel);
}
}
/**
* Disables/Enables history arrow buttons depending on whether the
* current page is the first, the last page or a middle page.
@ -421,9 +300,4 @@ public void changeHistoryButtonsState(ChatPanel chatPanel)
nextButton.setEnabled(false);
}
}
public void setBeginLastPageTimeStamp(Date beginLastPageTimeStamp)
{
this.beginLastPageTimeStamp = beginLastPageTimeStamp;
}
}

@ -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));
}
}
}
}
}

@ -16,8 +16,8 @@
import javax.swing.text.*;
import net.java.sip.communicator.impl.gui.main.*;
import net.java.sip.communicator.impl.gui.main.message.*;
import net.java.sip.communicator.impl.gui.main.message.history.HistoryWindow;
import net.java.sip.communicator.impl.gui.main.chat.*;
import net.java.sip.communicator.impl.gui.main.chat.history.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.contactlist.event.*;
import net.java.sip.communicator.service.protocol.*;
@ -135,21 +135,9 @@ public void metaContactRenamed(MetaContactRenamedEvent evt)
*/
public void protoContactAdded(ProtoContactEvent evt)
{
Contact contact = evt.getProtoContact();
MetaContact parentMetaContact = evt.getNewParent();
this.modifyContact(parentMetaContact);
ChatWindowManager chatWindowManager = mainFrame.getChatWindowManager();
if (chatWindowManager.isChatOpenedForContact(parentMetaContact))
{
ChatPanel chatPanel
= chatWindowManager.getContactChat(parentMetaContact);
chatPanel.getChatSendPanel().getProtoContactSelectorBox()
.addProtoContact(contact);
}
}
/**
@ -172,26 +160,6 @@ public void protoContactMoved(ProtoContactEvent evt)
this.modifyContact(oldParentMetaContact);
this.modifyContact(newParentMetaContact);
ChatWindowManager chatWindowManager = mainFrame.getChatWindowManager();
if (chatWindowManager.isChatOpenedForContact(oldParentMetaContact))
{
ChatPanel chatPanel
= chatWindowManager.getContactChat(oldParentMetaContact);
chatPanel.getChatSendPanel().getProtoContactSelectorBox()
.removeProtoContact(evt.getProtoContact());
}
if (chatWindowManager.isChatOpenedForContact(newParentMetaContact))
{
ChatPanel chatPanel
= chatWindowManager.getContactChat(newParentMetaContact);
chatPanel.getChatSendPanel().getProtoContactSelectorBox()
.addProtoContact(evt.getProtoContact());
}
}
/**

@ -70,7 +70,7 @@ public ContactListCellRenderer(MainFrame mainFrame) {
this.nameLabel.setPreferredSize(new Dimension(10, 17));
this.add(nameLabel, BorderLayout.CENTER);
this.add(nameLabel, BorderLayout.CENTER);
}
/**
@ -98,6 +98,23 @@ public Component getListCellRendererComponent(JList list, Object value,
this.nameLabel.setIcon(listModel
.getMetaContactStatusIcon(contactItem));
String oldText = getToolTipText();
ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
if (toolTipText != null) {
if (oldText == null) {
toolTipManager.registerComponent(this);
}
} else {
toolTipManager.unregisterComponent(this);
}
JToolTip tooltip = new JToolTip();
tooltip.setTipText("HOHO");
tooltip.setComponent(this);
this.nameLabel.setFont(this.getFont().deriveFont(Font.PLAIN));
this.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
@ -208,8 +225,8 @@ public Component getListCellRendererComponent(JList list, Object value,
}
toolTipText += "</html>";
this.setToolTipText(toolTipText);
//this.setToolTipText(toolTipText);
this.isSelected = isSelected;
return this;

@ -17,7 +17,7 @@
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.message.*;
import net.java.sip.communicator.impl.gui.main.chat.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.protocol.*;
@ -175,7 +175,9 @@ public RunMessageWindow(MetaContact metaContact)
this.metaContact = metaContact;
}
public RunMessageWindow(MetaContact metaContact, Contact protocolContact) {
public RunMessageWindow(MetaContact metaContact,
Contact protocolContact)
{
this.metaContact = metaContact;
this.protocolContact = protocolContact;
}
@ -214,45 +216,19 @@ public void messageReceived(MessageReceivedEvent evt)
MetaContact metaContact = mainFrame.getContactList()
.findMetaContactByContact(protocolContact);
ChatPanel chatPanel;
if (!Constants.TABBED_CHAT_WINDOW) {
// If in mode "open all messages in new window"
chatPanel = chatWindowManager.getContactChat(
metaContact, protocolContact, message.getMessageUID());
ChatPanel chatPanel = chatWindowManager.getContactChat(
metaContact, protocolContact, message.getMessageUID());
chatPanel.processMessage(
protocolContact.getDisplayName(), date,
Constants.INCOMING_MESSAGE, message.getContent());
}
else
{
logger.trace("MESSAGE RECEIVED: create new chat for contact: "
+ evt.getSourceContact().getAddress());
chatPanel = chatWindowManager
.getContactChat(metaContact, protocolContact,
message.getMessageUID());
logger.trace("MESSAGE RECEIVED: process message in chat for contact: "
+ evt.getSourceContact().getAddress());
chatPanel.processMessage(protocolContact.getDisplayName(),
date, Constants.INCOMING_MESSAGE, message.getContent());
}
chatPanel.processMessage(protocolContact.getDisplayName(), date,
Constants.INCOMING_MESSAGE, message.getContent());
chatWindowManager.openChat(chatPanel, false);
GuiActivator.getAudioNotifier()
.createAudio(Sounds.INCOMING_MESSAGE).play();
if (!chatPanel.getProtocolContact().getProtocolProvider()
.equals(protocolContact.getProtocolProvider()))
{
chatPanel.setProtocolContact(protocolContact);
}
chatPanel.treatReceivedMessage(protocolContact);
}
/**
@ -340,51 +316,23 @@ else if (evt.getErrorCode()
errorMsg = Messages.getI18NString(
"msgDeliveryFailedUnknownError").getText();
}
ChatPanel chatPanel = chatWindowManager
.getContactChat(metaContact, sourceContact);
ChatPanel chatPanel;
ChatWindow chatWindow;
chatPanel.refreshWriteArea();
if (!Constants.TABBED_CHAT_WINDOW)
{
// If in mode "open all messages in new window"
chatPanel = chatWindowManager
.getContactChat(metaContact, sourceContact);
chatWindow = chatPanel.getChatWindow();
chatPanel.refreshWriteArea();
chatPanel.processMessage(
metaContact.getDisplayName(),
new Date(System.currentTimeMillis()),
Constants.OUTGOING_MESSAGE,
sourceMessage.getContent());
chatPanel.processMessage(
metaContact.getDisplayName(),
new Date(System.currentTimeMillis()),
Constants.ERROR_MESSAGE,
errorMsg);
}
else
{
chatPanel = chatWindowManager.getContactChat(metaContact, sourceContact);
chatWindow = chatPanel.getChatWindow();
chatPanel.refreshWriteArea();
chatPanel.processMessage(
metaContact.getDisplayName(),
new Date(System.currentTimeMillis()),
Constants.OUTGOING_MESSAGE,
sourceMessage.getContent());
chatPanel.processMessage(
metaContact.getDisplayName(),
new Date(System.currentTimeMillis()),
Constants.ERROR_MESSAGE,
errorMsg);
}
chatPanel.processMessage(
metaContact.getDisplayName(),
new Date(System.currentTimeMillis()),
Constants.OUTGOING_MESSAGE,
sourceMessage.getContent());
chatPanel.processMessage(
metaContact.getDisplayName(),
new Date(System.currentTimeMillis()),
Constants.ERROR_MESSAGE,
errorMsg);
chatWindowManager.openChat(chatPanel, false);
}

@ -19,8 +19,8 @@
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.main.chat.history.*;
import net.java.sip.communicator.impl.gui.main.contactlist.addcontact.*;
import net.java.sip.communicator.impl.gui.main.message.history.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.gui.*;
@ -273,7 +273,7 @@ private void init() {
this.moveSubcontactMenu.add(contactItem1);
OperationSetWebContactInfo wContactInfo
= mainFrame.getWebContactInfo(protocolProvider);
= mainFrame.getWebContactInfoOpSet(protocolProvider);
if(wContactInfo == null) {
contactItem2.setEnabled(false);
@ -441,7 +441,7 @@ else if (itemName.startsWith(infoSubcontactPrefix)) {
= contact.getProtocolProvider();
OperationSetWebContactInfo wContactInfo
= mainFrame.getWebContactInfo(contactProvider);
= mainFrame.getWebContactInfoOpSet(contactProvider);
GuiActivator.getBrowserLauncher().openURL(
wContactInfo.getWebContactInfo(contact)
@ -741,7 +741,7 @@ public Image createAccountStatusImage(ProtocolProviderService pps)
Image statusImage;
OperationSetPresence presence
= this.mainFrame.getProtocolPresence(pps);
= this.mainFrame.getProtocolPresenceOpSet(pps);
if(presence != null)
{

@ -257,7 +257,7 @@ public Image createAccountStatusImage(ProtocolProviderService pps)
Image statusImage;
OperationSetPresence presence
= this.mainFrame.getProtocolPresence(pps);
= this.mainFrame.getProtocolPresenceOpSet(pps);
if(presence != null)
{

@ -16,7 +16,7 @@
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.main.message.*;
import net.java.sip.communicator.impl.gui.main.chat.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.gui.*;
@ -123,14 +123,7 @@ public void run()
clist.renameMetaContact(
metaContact, renameContactPanel.getNewName());
}
}.start();
ChatPanel chatPanel
= mainFrame.getChatWindowManager().getContactChat(metaContact);
if (chatPanel != null) {
chatPanel.renameContact(renameContactPanel.getNewName());
}
}.start();
}
}

@ -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…
Cancel
Save