in the call combo box - dial the selected contact when enter is pressed

cusax-fix
Yana Stamcheva 20 years ago
parent 2e00540b90
commit 2483a06f10

@ -43,8 +43,12 @@ public CallComboBox(CallManager callManager) {
JTextField textField = (JTextField)this.getEditor().getEditorComponent();
textField.addFocusListener(this);
textField.addFocusListener(this);
textField.getDocument().addDocumentListener(this);
textField.getActionMap().put("createCall", new CreateCallAction());
textField.getInputMap().put(
KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "createCall");
}
/**
@ -74,6 +78,10 @@ public void actionPerformed(ActionEvent e)
callManager.getCallButton().setEnabled(true);
}
/**
* When the combo editor field gains the focus removes the selection
* in the contact list to prevent confusion on who should be dialed.
*/
public void focusGained(FocusEvent e)
{
this.callManager.setCallMetaContact(false);
@ -92,6 +100,10 @@ public void focusLost(FocusEvent e)
public void removeUpdate(DocumentEvent e) { handleChange(); }
public void changedUpdate(DocumentEvent e) {}
/**
* Enables or disabled the call button according to the content in the
* combo box editor field.
*/
protected void handleChange() {
String item = ((CallComboEditor)this.getEditor()).getItem().toString();
@ -108,4 +120,23 @@ protected void handleChange() {
callManager.getCallButton().setEnabled(false);
}
}
/**
* Creates a call to the contact given by the string in the combo box
* editor field.
*/
private class CreateCallAction extends AbstractAction
{
public void actionPerformed(ActionEvent e)
{
String item = ((CallComboEditor)getEditor()).getItem().toString();
if(item.length() > 0)
callManager.createCall(item);
else {
if(!isPopupVisible())
setPopupVisible(true);
}
}
}
}

@ -180,7 +180,7 @@ else if(selectedPanel != null
String stringContact = callRecord.getParticipantName();
new CreateCallThread(stringContact).start();
createCall(stringContact);
}
//call button is pressed when a meta contact is selected
else if(isCallMetaContact && o != null && o instanceof MetaContact) {
@ -191,7 +191,7 @@ else if(isCallMetaContact && o != null && o instanceof MetaContact) {
Contact contact = getTelephonyContact(metaContact);
if(contact != null) {
new CreateCallThread(contact).start();
createCall(contact);
}
else {
JOptionPane.showMessageDialog(this.mainFrame,
@ -206,7 +206,7 @@ else if(!phoneNumberCombo.isComboFieldEmpty()) {
String stringContact
= phoneNumberCombo.getEditor().getItem().toString();
new CreateCallThread(stringContact).start();
createCall(stringContact);
}
}
else if (buttonName.equalsIgnoreCase("hangup")) {
@ -543,8 +543,31 @@ public boolean isCallMetaContact()
public void setCallMetaContact(boolean isCallMetaContact)
{
this.isCallMetaContact = isCallMetaContact;
}
/**
* Creates a call to the contact represented by the given string.
*
* @param contact the contact to call to
*/
public void createCall(String contact)
{
new CreateCallThread(contact).start();
}
/**
* Creates a call to the given contact.
*
* @param contact the protocol contact to call to
*/
public void createCall(Contact contact)
{
new CreateCallThread(contact).start();
}
/**
* Creates a call from a given Contact or a given String.
*/
private class CreateCallThread extends Thread
{
Contact contact;

Loading…
Cancel
Save