Closing a tab changes the selected tab in msg window - fixed

cusax-fix
Yana Stamcheva 20 years ago
parent 44d7d9be5d
commit adec8bae4c

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

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

@ -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 <tt>JTabbedPane</tt> is added in the window, where each tab contains a
* <tt>ChatPanel</tt>. In the second case the <tt>ChatPanel</tt> is added
* directly to the window. The <tt>ChatPanel</tt> contains all chat elements
* like a "write message area", "send" button, etc. It corresponds to a
* <tt>MetaContact</tt> or to a conference.
* <p>
@ -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 <tt>ChatWindow</tt>.
@ -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) {

Loading…
Cancel
Save