New Add contact button in chat window if the current contact is from the not in contactList group.

cusax-fix
Damian Minkov 18 years ago
parent b431319f5f
commit 6b65ff49bc

@ -0,0 +1,22 @@
/*
* 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;
/**
* Listens for changes in the chat window
* and its chat panles. Fires when new chat is created and focused
* or when changing chats through the tab pane.
* @author Damian Minkov
*/
public interface ChatChangeListener
{
/**
* @param panel the current visible chat panel
*/
public void chatChanged(ChatPanel panel);
}

@ -13,6 +13,7 @@
import javax.swing.*;
import javax.swing.event.*;
import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.customcontrols.*;
import net.java.sip.communicator.impl.gui.customcontrols.events.*;
@ -54,6 +55,8 @@ public class ChatWindow
private SIPCommTabbedPane chatTabbedPane = null;
private int chatCount = 0;
private Vector chatChangeListeners = new Vector();
/**
* Creates an instance of <tt>ChatWindow</tt> by passing to it an instance
@ -86,6 +89,22 @@ public void closeOperation(MouseEvent e)
.getChatWindowManager().closeChat(chatPanel);
}
});
chatTabbedPane.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent e)
{
int tabIndex = chatTabbedPane.getSelectedIndex();
if(tabIndex == -1)
return;
ChatPanel chatPanel
= (ChatPanel) chatTabbedPane.getComponentAt(tabIndex);
fireChatChangeEvent(chatPanel);
}
});
}
this.setSizeAndLocation();
@ -168,6 +187,8 @@ public void addChat(ChatPanel chatPanel)
private void addSimpleChat(ChatPanel chatPanel)
{
this.getContentPane().add(chatPanel, BorderLayout.CENTER);
fireChatChangeEvent(chatPanel);
}
/**
@ -183,6 +204,7 @@ private void addChatTab(ChatPanel chatPanel)
if (getCurrentChatPanel() == null)
{
this.getContentPane().add(chatPanel, BorderLayout.CENTER);
fireChatChangeEvent(chatPanel);
}
else
{
@ -731,7 +753,40 @@ public int getChatCount()
{
return chatCount;
}
public void addChatChangeListener(ChatChangeListener listener)
{
synchronized (chatChangeListeners)
{
chatChangeListeners.add(listener);
}
}
public void removeChatChangeListener(ChatChangeListener listener)
{
synchronized (chatChangeListeners)
{
chatChangeListeners.remove(listener);
}
}
private void fireChatChangeEvent(ChatPanel panel)
{
Iterator listeners = null;
synchronized (chatChangeListeners)
{
listeners = new ArrayList(chatChangeListeners).iterator();
}
while (listeners.hasNext())
{
ChatChangeListener listener
= (ChatChangeListener) listeners.next();
listener.chatChanged(panel);
}
}
private class LogoBar
extends JPanel
{

@ -9,7 +9,6 @@
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
@ -18,9 +17,12 @@
import net.java.sip.communicator.impl.gui.i18n.*;
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.main.contactlist.addcontact.*;
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.gui.Container;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.*;
import org.osgi.framework.*;
@ -72,7 +74,11 @@ public class ExtendedMainToolBar
private ToolBarButton historyButton = new ToolBarButton(
Messages.getI18NString("history").getText(),
ImageLoader.getImage(ImageLoader.HISTORY_ICON));
private ToolBarButton addButton = new ToolBarButton(
Messages.getI18NString("addContact").getText(),
ImageLoader.getImage(ImageLoader.QUICK_MENU_ADD_ICON));
private ToolBarButton sendFileButton = new ToolBarButton(
Messages.getI18NString("sendFile").getText(),
ImageLoader.getImage(ImageLoader.SEND_FILE_ICON));
@ -90,6 +96,8 @@ public class ExtendedMainToolBar
private SmiliesSelectorBox smiliesBox;
private ChatWindow messageWindow;
private Contact currentChatContact = null;
/**
* Creates an instance and constructs the <tt>MainToolBar</tt>.
@ -134,6 +142,9 @@ public ExtendedMainToolBar(ChatWindow messageWindow)
// this.add(sendFileButton);
this.add(historyButton);
this.addSeparator();
this.add(addButton);
// this.addSeparator();
//
@ -179,6 +190,10 @@ public ExtendedMainToolBar(ChatWindow messageWindow)
this.historyButton.setToolTipText(
Messages.getI18NString("history").getText() + " Ctrl-H");
this.addButton.setName("addContact");
this.addButton.setToolTipText(
Messages.getI18NString("addContact").getText());
this.fontButton.setName("font");
this.fontButton.setToolTipText(
Messages.getI18NString("font").getText());
@ -215,6 +230,7 @@ public ExtendedMainToolBar(ChatWindow messageWindow)
this.nextButton.addMouseListener(this);
this.sendFileButton.addMouseListener(this);
this.historyButton.addMouseListener(this);
this.addButton.addMouseListener(this);
this.fontButton.addMouseListener(this);
// Disable all buttons that do nothing.
@ -224,7 +240,47 @@ public ExtendedMainToolBar(ChatWindow messageWindow)
this.fontButton.setEnabled(false);
this.initPluginComponents();
}
messageWindow.addChatChangeListener(new ChatChangeListener()
{
public void chatChanged(ChatPanel panel)
{
if(panel instanceof MetaContactChatPanel)
{
MetaContact contact =
((MetaContactChatPanel)panel).getMetaContact();
if(contact == null) return;
Contact defaultContact = contact.getDefaultContact();
if(defaultContact == null) return;
ContactGroup parent = defaultContact.getParentContactGroup();
boolean isParentPersist = true;
boolean isParentResolved = true;
if(parent != null)
{
isParentPersist = parent.isPersistent();
isParentResolved = parent.isResolved();
}
if(!defaultContact.isPersistent() &&
!defaultContact.isResolved() &&
!isParentPersist &&
!isParentResolved)
{
addButton.setVisible(true);
currentChatContact = defaultContact;
}
else
{
addButton.setVisible(false);
currentChatContact = null;
}
}
}
});
}
/**
* Handles the <tt>ActionEvent</tt>, when one of the toolbar buttons is
@ -300,6 +356,19 @@ else if (buttonText.equalsIgnoreCase("history"))
else if (buttonText.equalsIgnoreCase("font")) {
}
else if (buttonText.equalsIgnoreCase("addContact"))
{
if(currentChatContact != null)
{
AddContactWizard addCWizz =
new AddContactWizard(
messageWindow.getMainFrame(),
currentChatContact.getAddress(),
currentChatContact.getProtocolProvider()
);
addCWizz.setVisible(true);
}
}
}
private void initPluginComponents()

@ -21,10 +21,12 @@
import net.java.sip.communicator.impl.gui.i18n.*;
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.main.contactlist.addcontact.*;
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.gui.Container;
import net.java.sip.communicator.service.gui.event.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.*;
/**
@ -66,6 +68,9 @@ public class MainToolBar
private ChatToolbarButton historyButton = new ChatToolbarButton(ImageLoader
.getImage(ImageLoader.HISTORY_ICON));
private ChatToolbarButton addButton = new ChatToolbarButton(ImageLoader
.getImage(ImageLoader.QUICK_MENU_ADD_ICON));
private ChatToolbarButton sendFileButton = new ChatToolbarButton(
ImageLoader.getImage(ImageLoader.SEND_FILE_ICON));
@ -82,6 +87,8 @@ public class MainToolBar
private SmiliesSelectorBox smiliesBox;
private ChatWindow messageWindow;
private Contact currentChatContact = null;
/**
* Empty constructor to be used from inheritors.
@ -128,6 +135,10 @@ public MainToolBar(ChatWindow messageWindow) {
// this.add(sendFileButton);
this.add(historyButton);
this.addSeparator();
this.add(addButton);
// this.addSeparator();
//
@ -173,6 +184,11 @@ public MainToolBar(ChatWindow messageWindow) {
this.historyButton.setToolTipText(
Messages.getI18NString("history").getText() + " Ctrl-H");
this.addButton.setName("addContact");
this.addButton.setToolTipText(
Messages.getI18NString("addContact").getText());
// this.addButton.setEnabled(false);
this.fontButton.setName("font");
this.fontButton.setToolTipText(
Messages.getI18NString("font").getText());
@ -186,6 +202,7 @@ public MainToolBar(ChatWindow messageWindow) {
this.nextButton.addActionListener(this);
this.sendFileButton.addActionListener(this);
this.historyButton.addActionListener(this);
this.addButton.addActionListener(this);
this.fontButton.addActionListener(this);
this.saveButton.setPreferredSize(
@ -216,6 +233,46 @@ public MainToolBar(ChatWindow messageWindow) {
this.fontButton.setEnabled(false);
this.initPluginComponents();
messageWindow.addChatChangeListener(new ChatChangeListener()
{
public void chatChanged(ChatPanel panel)
{
if(panel instanceof MetaContactChatPanel)
{
MetaContact contact =
((MetaContactChatPanel)panel).getMetaContact();
if(contact == null) return;
Contact defaultContact = contact.getDefaultContact();
if(defaultContact == null) return;
ContactGroup parent = defaultContact.getParentContactGroup();
boolean isParentPersist = true;
boolean isParentResolved = true;
if(parent != null)
{
isParentPersist = parent.isPersistent();
isParentResolved = parent.isResolved();
}
if(!defaultContact.isPersistent() &&
!defaultContact.isResolved() &&
!isParentPersist &&
!isParentResolved)
{
addButton.setVisible(true);
currentChatContact = defaultContact;
}
else
{
addButton.setVisible(false);
currentChatContact = null;
}
}
}
});
}
/**
@ -293,6 +350,19 @@ else if (buttonText.equalsIgnoreCase("history"))
else if (buttonText.equalsIgnoreCase("font")) {
}
else if (buttonText.equalsIgnoreCase("addContact"))
{
if(currentChatContact != null)
{
AddContactWizard addCWizz =
new AddContactWizard(
messageWindow.getMainFrame(),
currentChatContact.getAddress(),
currentChatContact.getProtocolProvider()
);
addCWizz.setVisible(true);
}
}
}
/**

@ -110,6 +110,11 @@ public String getUIN()
return textField.getText();
}
public void setUIN(String uin)
{
textField.setText(uin);
}
public void requestFocusInField() {
this.textField.requestFocus();
}

@ -83,6 +83,25 @@ public AddContactWizard(MainFrame mainFrame)
this.setCurrentPage(AddContactWizardPage1.IDENTIFIER);
}
/**
* Creates new wizard with already defined protocol and
* contact address
* @param mainFrame
* @param newContactAddress the contact address to add
* @param protocolProvider the protocol for the new contact
*/
public AddContactWizard(MainFrame mainFrame,
String newContactAddress,
ProtocolProviderService protocolProvider)
{
this(mainFrame);
newContact.addProtocolProvider(protocolProvider);
this.setCurrentPage(AddContactWizardPage2.IDENTIFIER);
page3.setUIN(newContactAddress);
}
/**
* Creates a new meta contact in a separate thread.
*/

@ -80,4 +80,9 @@ public void pageNext() {
public void pageBack() {
}
public void setUIN(String uin)
{
addContactPanel.setUIN(uin);
}
}

Loading…
Cancel
Save