- Fixes some popup menu focus issues in contact list.

- Introduces the following key bindings in the main window:
	- Enter - opens a chat with the selected contact, or in case in "unknown contact" view opens the "Add contact" dialog
	- Ctrl-Enter / Cmd-Enter - calls the selected contact in the contact list or unknown contact in the search field (or opens the call menu if more than one telephony contacts are available).
cusax-fix
Yana Stamcheva 16 years ago
parent 994f2af577
commit 16ecee1d1c

@ -302,11 +302,15 @@ public void enableUnknownContactView(boolean isEnabled)
if (unknownContactPanel == null)
unknownContactPanel = new UnknownContactPanel(this);
contactListPanel.setVisible(false);
unknownContactPanel.setVisible(true);
centerPanel.remove(contactListPanel);
centerPanel.add(unknownContactPanel, BorderLayout.CENTER);
}
else if (unknownContactPanel != null)
{
unknownContactPanel.setVisible(false);
contactListPanel.setVisible(true);
centerPanel.remove(unknownContactPanel);
centerPanel.add(contactListPanel, BorderLayout.CENTER);
}
@ -1499,6 +1503,31 @@ public boolean dispatchKeyEvent(KeyEvent e)
&& e.getID() != KeyEvent.KEY_TYPED))
return false;
// Ctrl-Enter || Cmd-Enter typed when this window is the focused
// window.
//
// Tried to make this with key bindings first, but has a problem
// with enter key binding. When the popup menu containing call
// contacts was opened the default keyboard manager was prioritizing
// the window ENTER key, which will open a chat and we wanted that
// the enter starts a call with the selected contact from the menu.
// This is why we need to do it here and to check if the
// permanent focus owner is equal to the focus owner, which is not
// the case when a popup menu is opened.
if (e.getKeyCode() == KeyEvent.VK_ENTER
&& (e.isControlDown() || e.isMetaDown()))
{
ctrlEnterKeyTyped();
return false;
}
else if (e.getKeyCode() == KeyEvent.VK_ENTER
&& keyManager.getFocusOwner()
.equals(keyManager.getPermanentFocusOwner()))
{
enterKeyTyped();
return false;
}
TreeContactList contactList
= getContactListPanel().getContactList();
@ -1560,4 +1589,40 @@ public boolean dispatchKeyEvent(KeyEvent e)
return false;
}
}
/**
* Called when the ENTER key was typed when this window was the focused
* window. Performs the appropriate actions depending on the current state
* of the contact list.
*/
private void enterKeyTyped()
{
if (unknownContactPanel != null && unknownContactPanel.isVisible())
{
unknownContactPanel.addUnknownContact();
}
else if (contactListPanel.isVisible())
{
// Starts a chat with the currently selected contact.
GuiActivator.getContactList().startSelectedContactChat();
}
}
/**
* Called when the CTRL-ENTER or CMD-ENTER keys were typed when this window
* was the focused window. Performs the appropriate actions depending on the
* current state of the contact list.
*/
public void ctrlEnterKeyTyped()
{
if (unknownContactPanel != null && unknownContactPanel.isVisible())
{
unknownContactPanel.startCall();
}
else if (contactListPanel.isVisible())
{
// Starts a chat with the currently selected contact.
GuiActivator.getContactList().startSelectedContactCall();
}
}
}

@ -81,6 +81,8 @@ private void init()
this.add(createInfoLabel());
this.addSeparator();
this.setFocusable(true);
}
/**

@ -124,13 +124,6 @@ public void mousePressed(MouseEvent e)
}
}
});
this.getActionMap().put("runChat", new ContactListPanelEnterAction());
InputMap imap = this.getInputMap(
JComponent.WHEN_IN_FOCUSED_WINDOW);
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "runChat");
}
/**

@ -165,6 +165,9 @@ public class ContactListTreeCellRenderer
*/
protected TreeNode treeNode;
/**
* The parent tree.
*/
private JTree tree;
/**
@ -254,7 +257,7 @@ else if (telephonyContacts.size() > 1)
{
ChooseCallAccountPopupMenu chooseAccountDialog
= new ChooseCallAccountPopupMenu(
callButton,
tree,
telephonyContacts);
Point location = new Point(callButton.getX(),
@ -721,4 +724,13 @@ public void paintIcon(Component c, Graphics g, int x, int y)
g.dispose();
}
}
/**
* Returns the call button contained in the current cell.
* @return the call button contained in the current cell
*/
public JButton getCallButton()
{
return callButton;
}
}

@ -8,7 +8,6 @@
import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.main.*;
import net.java.sip.communicator.impl.gui.main.call.*;
import net.java.sip.communicator.util.*;
import net.java.sip.communicator.util.swing.*;
import net.java.sip.communicator.util.swing.plaf.*;
@ -36,14 +35,14 @@ public class SearchField
/**
* Creates the <tt>SearchField</tt>.
* @param mainFrame the main application window
* @param frame the main application window
*/
public SearchField(MainFrame mainFrame)
public SearchField(MainFrame frame)
{
super(GuiActivator.getResources()
.getI18NString("service.gui.ENTER_NAME_OR_NUMBER"));
this.mainFrame = mainFrame;
this.mainFrame = frame;
SearchTextFieldUI textFieldUI = new SearchTextFieldUI();
textFieldUI.setDeleteButtonEnabled(true);
@ -57,7 +56,6 @@ public SearchField(MainFrame mainFrame)
InputMap imap = getInputMap(JComponent.WHEN_FOCUSED);
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "escape");
imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter");
ActionMap amap = getActionMap();
amap.put("escape", new AbstractAction()
{
@ -68,17 +66,6 @@ public void actionPerformed(ActionEvent e)
SearchField.this.mainFrame.requestFocusInCenterPanel();
}
});
amap.put("enter", new AbstractAction()
{
public void actionPerformed(ActionEvent e)
{
if (!lastHasMatching)
CallManager.createCall(getText());
else
// Starts a chat with the currently selected contact.
GuiActivator.getContactList().startSelectedContactChat();
}
});
}
/**

@ -1460,6 +1460,29 @@ public void startSelectedContactChat()
}
}
/**
* Starts a call with the currently selected contact in the contact list.
*/
public void startSelectedContactCall()
{
TreePath selectionPath = getSelectionPath();
if (selectionPath == null)
return;
ContactListTreeCellRenderer renderer
= (ContactListTreeCellRenderer) getCellRenderer()
.getTreeCellRendererComponent(
this,
selectionPath.getLastPathComponent(),
true,
true,
true,
this.getRowForPath(selectionPath),
true);
renderer.getCallButton().doClick();
}
/**
* Sets the given <tt>treeModel</tt> as a model of this tree. Specifies
* also some related properties.

@ -106,4 +106,21 @@ else if (telephonyProviders.size() > 1)
}
});
}
/**
* Clicks the call contact button in order to call the unknown contact.
*/
public void startCall()
{
callContact.doClick();
}
/**
* Clicks the add contact button in order to add the unknown contact
* to the contact list.
*/
public void addUnknownContact()
{
addContact.doClick();
}
}

Loading…
Cancel
Save