From 2483a06f10c83eda32f874d88e9b62f9a1615dcf Mon Sep 17 00:00:00 2001 From: Yana Stamcheva Date: Mon, 23 Oct 2006 12:49:05 +0000 Subject: [PATCH] in the call combo box - dial the selected contact when enter is pressed --- .../impl/gui/main/call/CallComboBox.java | 33 ++++++++++++++++++- .../impl/gui/main/call/CallManager.java | 29 ++++++++++++++-- 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/net/java/sip/communicator/impl/gui/main/call/CallComboBox.java b/src/net/java/sip/communicator/impl/gui/main/call/CallComboBox.java index ec9225d05..a1093d07a 100644 --- a/src/net/java/sip/communicator/impl/gui/main/call/CallComboBox.java +++ b/src/net/java/sip/communicator/impl/gui/main/call/CallComboBox.java @@ -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); + } + } + } } diff --git a/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java b/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java index e22a1d0c2..1a7ce82a7 100644 --- a/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java +++ b/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java @@ -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;