|
|
|
|
@ -68,6 +68,25 @@ public ChatWindow(MainFrame mainFrame)
|
|
|
|
|
|
|
|
|
|
menusPanel = new MenusPanel(this);
|
|
|
|
|
|
|
|
|
|
//If in mode TABBED_CHAT_WINDOW initialize the tabbed pane
|
|
|
|
|
if(Constants.TABBED_CHAT_WINDOW)
|
|
|
|
|
{
|
|
|
|
|
chatTabbedPane = new SIPCommTabbedPane(true, false);
|
|
|
|
|
|
|
|
|
|
chatTabbedPane.addCloseListener(new CloseListener() {
|
|
|
|
|
public void closeOperation(MouseEvent e)
|
|
|
|
|
{
|
|
|
|
|
int tabIndex = chatTabbedPane.getOverTabIndex();
|
|
|
|
|
|
|
|
|
|
ChatPanel chatPanel
|
|
|
|
|
= (ChatPanel) chatTabbedPane.getComponentAt(tabIndex);
|
|
|
|
|
|
|
|
|
|
ChatWindow.this.mainFrame
|
|
|
|
|
.getChatWindowManager().closeChat(chatPanel);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.setSizeAndLocation();
|
|
|
|
|
|
|
|
|
|
this.init();
|
|
|
|
|
@ -156,7 +175,6 @@ public MainToolBar getMainToolBar()
|
|
|
|
|
return menusPanel.getMainToolBar();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adds a given <tt>ChatPanel</tt> to this chat window.
|
|
|
|
|
*
|
|
|
|
|
@ -165,15 +183,9 @@ public MainToolBar getMainToolBar()
|
|
|
|
|
public void addChat(ChatPanel chatPanel)
|
|
|
|
|
{
|
|
|
|
|
if(Constants.TABBED_CHAT_WINDOW)
|
|
|
|
|
{
|
|
|
|
|
this.addChatTab(chatPanel);
|
|
|
|
|
this.chatTabbedPane.revalidate();
|
|
|
|
|
this.chatTabbedPane.repaint();
|
|
|
|
|
}
|
|
|
|
|
addChatTab(chatPanel);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
addSimpleChat(chatPanel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
chatPanel.setChatVisible(true);
|
|
|
|
|
}
|
|
|
|
|
@ -187,13 +199,7 @@ private void addSimpleChat(ChatPanel chatPanel)
|
|
|
|
|
{
|
|
|
|
|
chatPanel.setChatVisible(true);
|
|
|
|
|
|
|
|
|
|
this.setCurrentChatPanel(chatPanel);
|
|
|
|
|
|
|
|
|
|
this.getContentPane().add(chatPanel, BorderLayout.CENTER);
|
|
|
|
|
|
|
|
|
|
this.windowTitle += chatPanel.getMetaContact().getDisplayName() + " ";
|
|
|
|
|
|
|
|
|
|
this.setTitle(this.windowTitle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -206,44 +212,20 @@ private void addChatTab(ChatPanel chatPanel)
|
|
|
|
|
{
|
|
|
|
|
String contactName = chatPanel.getMetaContact().getDisplayName();
|
|
|
|
|
PresenceStatus status = chatPanel.getDefaultContactStatus();
|
|
|
|
|
|
|
|
|
|
if (chatTabbedPane == null) {
|
|
|
|
|
// Initialize the tabbed pane for the first time
|
|
|
|
|
|
|
|
|
|
chatTabbedPane = new SIPCommTabbedPane(true, false);
|
|
|
|
|
|
|
|
|
|
chatTabbedPane.addCloseListener(new CloseListener() {
|
|
|
|
|
public void closeOperation(MouseEvent e)
|
|
|
|
|
{
|
|
|
|
|
int tabIndex = chatTabbedPane.getOverTabIndex();
|
|
|
|
|
|
|
|
|
|
ChatPanel chatPanel
|
|
|
|
|
= (ChatPanel) chatTabbedPane.getComponentAt(tabIndex);
|
|
|
|
|
|
|
|
|
|
mainFrame.getChatWindowManager().closeChat(chatPanel);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (getCurrentChatPanel() == null)
|
|
|
|
|
{
|
|
|
|
|
this.getContentPane().add(chatPanel, BorderLayout.CENTER);
|
|
|
|
|
|
|
|
|
|
this.setTitle(contactName);
|
|
|
|
|
|
|
|
|
|
this.setCurrentChatPanel(chatPanel);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (chatTabbedPane.getTabCount() > 0) {
|
|
|
|
|
// The tabbed pane contains already tabs.
|
|
|
|
|
|
|
|
|
|
chatTabbedPane.addTab(contactName, new ImageIcon(Constants
|
|
|
|
|
.getStatusIcon(status)), chatPanel);
|
|
|
|
|
|
|
|
|
|
chatTabbedPane.getParent().validate();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (getChatTabCount() == 0)
|
|
|
|
|
{
|
|
|
|
|
ChatPanel firstChatPanel = getCurrentChatPanel();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PresenceStatus currentContactStatus = firstChatPanel
|
|
|
|
|
.getDefaultContactStatus();
|
|
|
|
|
|
|
|
|
|
// Add first two tabs to the tabbed pane.
|
|
|
|
|
chatTabbedPane.addTab(firstChatPanel.getMetaContact()
|
|
|
|
|
.getDisplayName(), new ImageIcon(Constants
|
|
|
|
|
@ -260,139 +242,169 @@ public void closeOperation(MouseEvent e)
|
|
|
|
|
// conversation area is slightly resized and is made smaller,
|
|
|
|
|
// which moves the scrollbar up.
|
|
|
|
|
firstChatPanel.setCaretToEnd();
|
|
|
|
|
|
|
|
|
|
//add the chatTabbedPane to the window
|
|
|
|
|
this.getContentPane().add(chatTabbedPane, BorderLayout.CENTER);
|
|
|
|
|
this.getContentPane().validate();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// The tabbed pane contains already tabs.
|
|
|
|
|
|
|
|
|
|
this.getContentPane().add(chatTabbedPane, BorderLayout.CENTER);
|
|
|
|
|
this.getContentPane().validate();
|
|
|
|
|
chatTabbedPane.addTab(contactName, new ImageIcon(Constants
|
|
|
|
|
.getStatusIcon(status)), chatPanel);
|
|
|
|
|
|
|
|
|
|
int chatIndex = chatTabbedPane.getTabCount() - 1;
|
|
|
|
|
if (chatTabbedPane.getSelectedIndex() == chatIndex)
|
|
|
|
|
this.setCurrentChatPanel(chatPanel);
|
|
|
|
|
chatTabbedPane.getParent().validate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Selects the chat tab which corresponds to the given <tt>MetaContact</tt>.
|
|
|
|
|
*
|
|
|
|
|
* @param contact The <tt>MetaContact</tt> to select.
|
|
|
|
|
*/
|
|
|
|
|
public void setSelectedChatTab(ChatPanel chatPanel)
|
|
|
|
|
{
|
|
|
|
|
this.chatTabbedPane.setSelectedComponent(chatPanel);
|
|
|
|
|
this.setCurrentChatPanel(chatPanel);
|
|
|
|
|
chatPanel.requestFocusInWriteArea();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Selects the contact tab given by <code>index</code>.
|
|
|
|
|
*
|
|
|
|
|
* @param index The index of the tab to select.
|
|
|
|
|
*/
|
|
|
|
|
public void setSelectedChatTab(int index)
|
|
|
|
|
{
|
|
|
|
|
ChatPanel chatPanel = (ChatPanel) this.chatTabbedPane
|
|
|
|
|
.getComponentAt(index);
|
|
|
|
|
|
|
|
|
|
this.setCurrentChatPanel(chatPanel);
|
|
|
|
|
this.chatTabbedPane.setSelectedIndex(index);
|
|
|
|
|
chatPanel.requestFocusInWriteArea();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes a given <tt>ChatPanel</tt> from the tabbed pane.
|
|
|
|
|
* Removes a given <tt>ChatPanel</tt> from this chat window.
|
|
|
|
|
*
|
|
|
|
|
* @param chatPanel The <tt>ChatPanel</tt> to remove.
|
|
|
|
|
*/
|
|
|
|
|
public void removeChatTab(ChatPanel chatPanel)
|
|
|
|
|
public void removeChat(ChatPanel chatPanel)
|
|
|
|
|
{
|
|
|
|
|
logger.debug("Removes chat for contact: "
|
|
|
|
|
+ chatPanel.getMetaContact().getDisplayName());
|
|
|
|
|
|
|
|
|
|
//if there's no tabs remove the chat panel directly from the content
|
|
|
|
|
//pane and hide the window.
|
|
|
|
|
if(getChatTabCount() == 0)
|
|
|
|
|
{
|
|
|
|
|
this.getContentPane().remove(chatPanel);
|
|
|
|
|
|
|
|
|
|
this.setVisible(false);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//in the case of a tabbed chat window
|
|
|
|
|
int index = chatTabbedPane.indexOfComponent(chatPanel);
|
|
|
|
|
|
|
|
|
|
String title = chatTabbedPane.getTitleAt(index);
|
|
|
|
|
|
|
|
|
|
if (title != null)
|
|
|
|
|
if (index != -1)
|
|
|
|
|
{
|
|
|
|
|
if (chatTabbedPane.getTabCount() > 1)
|
|
|
|
|
chatTabbedPane.removeTabAt(index);
|
|
|
|
|
|
|
|
|
|
if (chatTabbedPane.getTabCount() == 1) {
|
|
|
|
|
|
|
|
|
|
String onlyTabtitle = chatTabbedPane.getTitleAt(0);
|
|
|
|
|
|
|
|
|
|
if (chatTabbedPane.getTabCount() == 1)
|
|
|
|
|
{
|
|
|
|
|
ChatPanel currentChatPanel = (ChatPanel) this.chatTabbedPane
|
|
|
|
|
.getComponentAt(0);
|
|
|
|
|
|
|
|
|
|
this.getContentPane().remove(chatTabbedPane);
|
|
|
|
|
|
|
|
|
|
this.chatTabbedPane.removeAll();
|
|
|
|
|
|
|
|
|
|
this.getContentPane().remove(chatTabbedPane);
|
|
|
|
|
|
|
|
|
|
this.getContentPane().add(currentChatPanel, BorderLayout.CENTER);
|
|
|
|
|
|
|
|
|
|
this.setCurrentChatPanel(currentChatPanel);
|
|
|
|
|
|
|
|
|
|
this.setTitle(onlyTabtitle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void removeChatTab(int index)
|
|
|
|
|
/**
|
|
|
|
|
* Removes the chat at the given index. If there's no tabbed pane
|
|
|
|
|
* does nothing.
|
|
|
|
|
*
|
|
|
|
|
* @param index the index indicating, which tab to remove
|
|
|
|
|
*/
|
|
|
|
|
public void removeChat(int index)
|
|
|
|
|
{
|
|
|
|
|
this.removeChatTab((ChatPanel)chatTabbedPane.getComponentAt(index));
|
|
|
|
|
if(getChatTabCount() > 0)
|
|
|
|
|
this.removeChat((ChatPanel)chatTabbedPane.getComponentAt(index));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void removeAllTabs()
|
|
|
|
|
{
|
|
|
|
|
this.getContentPane().remove(chatTabbedPane);
|
|
|
|
|
|
|
|
|
|
this.chatTabbedPane.removeAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the currently selected chat panel.
|
|
|
|
|
*
|
|
|
|
|
* @return the currently selected chat panel.
|
|
|
|
|
* Removes all tabs in the chat tabbed pane. If not in mode
|
|
|
|
|
* TABBED_CHAT_WINDOW doesn nothing.
|
|
|
|
|
*/
|
|
|
|
|
public ChatPanel getCurrentChatPanel()
|
|
|
|
|
public void removeAllChats()
|
|
|
|
|
{
|
|
|
|
|
if(Constants.TABBED_CHAT_WINDOW && getTabCount() > 1)
|
|
|
|
|
return (ChatPanel)chatTabbedPane.getSelectedComponent();
|
|
|
|
|
logger.debug("Remove all tabs from the chat window.");
|
|
|
|
|
|
|
|
|
|
if(getChatTabCount() > 0)
|
|
|
|
|
{
|
|
|
|
|
this.chatTabbedPane.removeAll();
|
|
|
|
|
|
|
|
|
|
this.getContentPane().remove(chatTabbedPane);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return (ChatPanel) getContentPane().getComponent(1);
|
|
|
|
|
{
|
|
|
|
|
this.removeChat(getCurrentChatPanel());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the currently selected chat panel.
|
|
|
|
|
* Selects the chat tab which corresponds to the given <tt>MetaContact</tt>.
|
|
|
|
|
*
|
|
|
|
|
* @param chatPanel The chat panel which is currently selected.
|
|
|
|
|
* @param contact The <tt>MetaContact</tt> to select.
|
|
|
|
|
*/
|
|
|
|
|
public void setCurrentChatPanel(ChatPanel chatPanel)
|
|
|
|
|
{
|
|
|
|
|
logger.debug("Set current chat panel to: "
|
|
|
|
|
+ chatPanel.getMetaContact().getDisplayName());
|
|
|
|
|
|
|
|
|
|
if(getChatTabCount() > 0)
|
|
|
|
|
this.chatTabbedPane.setSelectedComponent(chatPanel);
|
|
|
|
|
|
|
|
|
|
this.setTitle(chatPanel.getMetaContact().getDisplayName());
|
|
|
|
|
|
|
|
|
|
this.getMainToolBar().changeHistoryButtonsState(chatPanel);
|
|
|
|
|
|
|
|
|
|
chatPanel.requestFocusInWriteArea();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Selects the tab given by the index. If there's no tabbed pane does nothing.
|
|
|
|
|
* @param index the index to select
|
|
|
|
|
*/
|
|
|
|
|
public void setCurrentChatTab(int index)
|
|
|
|
|
{
|
|
|
|
|
ChatPanel chatPanel = null;
|
|
|
|
|
if(getChatTabCount() > 0)
|
|
|
|
|
{
|
|
|
|
|
chatPanel = (ChatPanel) this.chatTabbedPane
|
|
|
|
|
.getComponentAt(index);
|
|
|
|
|
|
|
|
|
|
setCurrentChatPanel(chatPanel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the tab count of the chat tabbed pane. Meant to be used when in
|
|
|
|
|
* "Group chat windows" mode.
|
|
|
|
|
* Returns the currently selected chat panel.
|
|
|
|
|
*
|
|
|
|
|
* @return int The number of opened tabs.
|
|
|
|
|
* @return the currently selected chat panel.
|
|
|
|
|
*/
|
|
|
|
|
public int getTabCount()
|
|
|
|
|
{
|
|
|
|
|
return (chatTabbedPane == null) ? 0 : chatTabbedPane.getTabCount();
|
|
|
|
|
public ChatPanel getCurrentChatPanel()
|
|
|
|
|
{
|
|
|
|
|
if(getChatTabCount() > 0)
|
|
|
|
|
return (ChatPanel)chatTabbedPane.getSelectedComponent();
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int componentCount = getContentPane().getComponentCount();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < componentCount; i ++)
|
|
|
|
|
{
|
|
|
|
|
Component c = getContentPane().getComponent(i);
|
|
|
|
|
|
|
|
|
|
if(c instanceof ChatPanel)
|
|
|
|
|
return (ChatPanel)c;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the chat tab index for the given MetaContact.
|
|
|
|
|
* Returns the tab count of the chat tabbed pane. Meant to be used when in
|
|
|
|
|
* "Group chat windows" mode.
|
|
|
|
|
*
|
|
|
|
|
* @param contact The MetaContact we are searching for.
|
|
|
|
|
* @return int The chat tab index for the given MetaContact.
|
|
|
|
|
* @return int The number of opened tabs.
|
|
|
|
|
*/
|
|
|
|
|
public int getTabInex(ChatPanel chatPanel)
|
|
|
|
|
public int getChatTabCount()
|
|
|
|
|
{
|
|
|
|
|
return this.chatTabbedPane.indexOfComponent(chatPanel);
|
|
|
|
|
return (chatTabbedPane == null) ? 0 : chatTabbedPane.getTabCount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -442,13 +454,13 @@ private class ForwordTabAction
|
|
|
|
|
{
|
|
|
|
|
public void actionPerformed(ActionEvent e)
|
|
|
|
|
{
|
|
|
|
|
if (chatTabbedPane != null) {
|
|
|
|
|
if (getChatTabCount() > 0) {
|
|
|
|
|
int selectedIndex = chatTabbedPane.getSelectedIndex();
|
|
|
|
|
if (selectedIndex < chatTabbedPane.getTabCount() - 1) {
|
|
|
|
|
setSelectedChatTab(selectedIndex + 1);
|
|
|
|
|
setCurrentChatTab(selectedIndex + 1);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
setSelectedChatTab(0);
|
|
|
|
|
setCurrentChatTab(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -464,13 +476,13 @@ private class BackwordTabAction
|
|
|
|
|
{
|
|
|
|
|
public void actionPerformed(ActionEvent e)
|
|
|
|
|
{
|
|
|
|
|
if (chatTabbedPane != null) {
|
|
|
|
|
if (getChatTabCount() > 0) {
|
|
|
|
|
int selectedIndex = chatTabbedPane.getSelectedIndex();
|
|
|
|
|
if (selectedIndex != 0) {
|
|
|
|
|
setSelectedChatTab(selectedIndex - 1);
|
|
|
|
|
setCurrentChatTab(selectedIndex - 1);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
setSelectedChatTab(chatTabbedPane.getTabCount() - 1);
|
|
|
|
|
setCurrentChatTab(chatTabbedPane.getTabCount() - 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -608,7 +620,6 @@ public void windowDeiconified(WindowEvent e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Implements the <tt>SIPCommFrame</tt> close method. We check for an open
|
|
|
|
|
* menu and if there's one we close it, otherwise we close the current chat.
|
|
|
|
|
@ -650,7 +661,7 @@ else if (selectedMenu != null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
mainFrame.getChatWindowManager().closeTabbedWindow();
|
|
|
|
|
mainFrame.getChatWindowManager().closeWindow();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|