Skip to content

Commit

Permalink
Fix for "Main window menu bar can not always be navigated using keybo…
Browse files Browse the repository at this point in the history
…ard".
  • Loading branch information
netmackan authored and yanas committed May 21, 2013
1 parent 33f428e commit 4bed7e4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/net/java/sip/communicator/impl/gui/main/MainFrame.java
Expand Up @@ -225,7 +225,8 @@ public MainFrame()

clKeyDispatcher = new ContactListSearchKeyDispatcher( keyManager,
searchField,
this);
this,
menu);
keyManager.addKeyEventDispatcher(clKeyDispatcher);

/*
Expand Down
Expand Up @@ -8,6 +8,7 @@

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import javax.swing.text.*;

Expand Down Expand Up @@ -45,17 +46,25 @@ public class ContactListSearchKeyDispatcher
*/
private final ContactListContainer contactListContainer;

/**
* The menu bar of the parent window.
*/
private final JMenuBar menuBar;

/**
* Creates an instance of <tt>MainKeyDispatcher</tt>.
* @param keyManager the parent <tt>KeyboardFocusManager</tt>
* @param menuBar of the parent window or null if none is used.
*/
public ContactListSearchKeyDispatcher( KeyboardFocusManager keyManager,
SearchField searchField,
ContactListContainer container)
ContactListContainer container,
JMenuBar menuBar)
{
this.keyManager = keyManager;
this.searchField = searchField;
this.contactListContainer = container;
this.menuBar = menuBar;
}

/**
Expand All @@ -78,9 +87,10 @@ public void setContactList(ContactList contactList)
public boolean dispatchKeyEvent(KeyEvent e)
{
Component focusOwner = keyManager.getFocusOwner();

// If this window is not the focus window or if the event is not
// of type PRESSED we have nothing more to do here.
// Also don't re-dispatch any events if the menu is active.
if (!contactListContainer.isFocused()
|| (e.getID() != KeyEvent.KEY_PRESSED
&& e.getID() != KeyEvent.KEY_TYPED)
Expand All @@ -90,7 +100,8 @@ public boolean dispatchKeyEvent(KeyEvent e)
.getSingleWindowContainer().containsFocus()
|| (focusOwner != null
&& !searchField.isFocusOwner()
&& focusOwner instanceof JTextComponent))
&& focusOwner instanceof JTextComponent)
|| (menuBar != null && menuBar.isSelected()))
return false;

// Ctrl-Enter || Cmd-Enter typed when this window is the focused
Expand Down
Expand Up @@ -235,7 +235,8 @@ public void actionPerformed(ActionEvent e)
ContactListSearchKeyDispatcher clKeyDispatcher
= new ContactListSearchKeyDispatcher( keyManager,
searchField,
this);
this,
null);

clKeyDispatcher.setContactList(srcContactList);

Expand Down
Expand Up @@ -138,7 +138,8 @@ public void focusGained(FocusEvent e)
ContactListSearchKeyDispatcher clKeyDispatcher
= new ContactListSearchKeyDispatcher( keyManager,
searchField,
this);
this,
null);

clKeyDispatcher.setContactList(contactList);

Expand Down

0 comments on commit 4bed7e4

Please sign in to comment.