diff --git a/src/net/java/sip/communicator/impl/gui/customcontrols/SIPCommTabbedPane.java b/src/net/java/sip/communicator/impl/gui/customcontrols/SIPCommTabbedPane.java
index 474287515..ebbcf671f 100644
--- a/src/net/java/sip/communicator/impl/gui/customcontrols/SIPCommTabbedPane.java
+++ b/src/net/java/sip/communicator/impl/gui/customcontrols/SIPCommTabbedPane.java
@@ -11,12 +11,14 @@
* SETLabs, Infosys Technologies Ltd. May 2004 - Jul 2004 Ecole des Mines de
* Nantes, France
*/
-import java.util.*;
-
import java.awt.*;
import java.awt.event.*;
+import java.util.*;
+
+import javax.accessibility.*;
import javax.swing.*;
import javax.swing.border.*;
+import javax.swing.event.*;
import net.java.sip.communicator.impl.gui.customcontrols.events.*;
import net.java.sip.communicator.impl.gui.lookandfeel.*;
@@ -28,9 +30,14 @@
*
* @author Yana Stamcheva
*/
-public class SIPCommTabbedPane extends JTabbedPane {
-
+public class SIPCommTabbedPane
+ extends JTabbedPane
+ implements ChangeListener
+{
+
private int overTabIndex = -1;
+
+ private int lastSelectedIndex;
/**
* Creates the CloseAndMaxTabbedPane with an enhanced UI if
@@ -49,6 +56,8 @@ public SIPCommTabbedPane(boolean closingTabs, boolean maximizingTabs) {
if(!maximizingTabs)
this.setMaxIcon(false);
+
+ this.addChangeListener(this);
}
/**
@@ -384,6 +393,7 @@ public void firePopupOutsideTabEvent(MouseEvent e) {
* @param tabIndex The index of the tab to be selected.
*/
public void setSelectedIndex(int tabIndex) {
+
SIPCommTabbedPaneUI ui = (SIPCommTabbedPaneUI) this.getUI();
if (ui.isTabHighlighted(tabIndex)) {
ui.tabRemoveHighlight(tabIndex);
@@ -404,4 +414,23 @@ public void highlightTab(int tabIndex) {
this.repaint();
}
+
+ public void removeTabAt(int index)
+ {
+ if (index < lastSelectedIndex)
+ {
+ this.setSelectedIndex(lastSelectedIndex - 1);
+ }
+ else if (index > lastSelectedIndex)
+ {
+ this.setSelectedIndex(lastSelectedIndex);
+ }
+
+ super.removeTabAt(index);
+ }
+
+ public void stateChanged(ChangeEvent e)
+ {
+ lastSelectedIndex = this.getSelectedIndex();
+ }
}
diff --git a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommTabbedPaneUI.java b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommTabbedPaneUI.java
index 13697de3a..acc31128d 100644
--- a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommTabbedPaneUI.java
+++ b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommTabbedPaneUI.java
@@ -1444,22 +1444,21 @@ public MyMouseHandler() {
}
public void mousePressed(MouseEvent e) {
+
if (closeIndexStatus == OVER) {
closeIndexStatus = PRESSED;
- tabScroller.tabPanel.repaint();
- return;
+ tabScroller.tabPanel.repaint();
}
-
- if (maxIndexStatus == OVER) {
+ else if (maxIndexStatus == OVER) {
maxIndexStatus = PRESSED;
tabScroller.tabPanel.repaint();
- return;
}
-
+ else {
+ super.mousePressed(e);
+ }
}
public void mouseClicked(MouseEvent e) {
- super.mousePressed(e);
if (e.getClickCount() > 1 && overTabIndex != -1) {
((SIPCommTabbedPane) tabPane).fireDoubleClickTabEvent(e,
overTabIndex);
@@ -1467,7 +1466,7 @@ public void mouseClicked(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
-
+
updateOverTab(e.getX(), e.getY());
if (overTabIndex == -1) {
diff --git a/src/net/java/sip/communicator/impl/gui/main/message/ChatWindow.java b/src/net/java/sip/communicator/impl/gui/main/message/ChatWindow.java
index 3edb4974e..5884e7904 100755
--- a/src/net/java/sip/communicator/impl/gui/main/message/ChatWindow.java
+++ b/src/net/java/sip/communicator/impl/gui/main/message/ChatWindow.java
@@ -12,6 +12,7 @@
import java.util.*;
import javax.swing.*;
+import javax.swing.event.*;
import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.customcontrols.*;
@@ -32,7 +33,6 @@
* messages in one window" and "Open messages in new window". In the first case
* a JTabbedPane is added in the window, where each tab contains a
* ChatPanel. In the second case the ChatPanel is added
- * directly to the window. The ChatPanel contains all chat elements
* like a "write message area", "send" button, etc. It corresponds to a
* MetaContact or to a conference.
*
@@ -58,6 +58,10 @@ public class ChatWindow private Hashtable contactChats = new Hashtable(); private boolean enableTypingNotification = true; + + private int lastSelectedIndex; + + private boolean isLastIndex; /** * Creates an instance of ChatWindow. @@ -220,12 +224,12 @@ public void addChatTab(ChatPanel chatPanel) chatTabbedPane.addCloseListener(new CloseListener() { public void closeOperation(MouseEvent e) { - int tabIndex = chatTabbedPane.getOverTabIndex(); + removeContactTab(tabIndex); } }); - + this.getContentPane().add(chatPanel, BorderLayout.CENTER); this.setTitle(contactName); @@ -327,7 +331,7 @@ public void removeContactTab(int index) this.contactChats.remove(closeChat.getMetaContact() .getMetaUID()); - chatTabbedPane.remove(index); + chatTabbedPane.removeTabAt(index); } if (chatTabbedPane.getTabCount() == 1) {