From afb578019648b701ce1dfb2c87be8d5f067916ea Mon Sep 17 00:00:00 2001 From: Yana Stamcheva Date: Tue, 10 Aug 2010 11:17:29 +0000 Subject: [PATCH] Add contact dialog enhancements, including no account selection by default, disabled "add" button if no account is selected or no contact address is entered. --- .../main/contactlist/AddContactDialog.java | 74 ++++++++++++++++--- 1 file changed, 65 insertions(+), 9 deletions(-) diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/AddContactDialog.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/AddContactDialog.java index f09389ed7..ea99e462f 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/AddContactDialog.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/AddContactDialog.java @@ -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.*; @@ -163,6 +164,22 @@ private void init() labelsPanel.add(contactAddressLabel); fieldsPanel.add(contactAddressField); + contactAddressField.getDocument().addDocumentListener( + new DocumentListener() + { + public void changedUpdate(DocumentEvent e) {} + + public void insertUpdate(DocumentEvent e) + { + updateAddButtonState(); + } + + public void removeUpdate(DocumentEvent e) + { + updateAddButtonState(); + } + }); + TransparentPanel dataPanel = new TransparentPanel(new BorderLayout()); dataPanel.add(labelsPanel, BorderLayout.WEST); @@ -204,6 +221,10 @@ private Container createButtonsPanel() buttonsPanel.add(addButton); buttonsPanel.add(cancelButton); + // Disable the add button so that it would be clear for the user that + // they need to choose an account and enter a contact id first. + addButton.setEnabled(false); + return buttonsPanel; } @@ -215,6 +236,17 @@ private void initAccountCombo() Iterator providers = mainFrame.getProtocolProviders(); + accountCombo.addItem(GuiActivator.getResources() + .getI18NString("service.gui.SELECT_ACCOUNT")); + + accountCombo.addItemListener(new ItemListener() + { + public void itemStateChanged(ItemEvent e) + { + updateAddButtonState(); + } + }); + while (providers.hasNext()) { ProtocolProviderService provider = providers.next(); @@ -414,18 +446,27 @@ public Component getListCellRendererComponent( JList list, boolean isSelected, boolean cellHasFocus) { - ProtocolProviderService provider = (ProtocolProviderService) value; - - if (provider != null) + if (value instanceof String) { - Image protocolImg - = ImageLoader.getBytesInImage(provider.getProtocolIcon() - .getIcon(ProtocolIcon.ICON_SIZE_16x16)); + setIcon(null); + setText((String) value); + } + else if (value instanceof ProtocolProviderService) + { + ProtocolProviderService provider + = (ProtocolProviderService) value; + + if (provider != null) + { + Image protocolImg + = ImageLoader.getBytesInImage(provider.getProtocolIcon() + .getIcon(ProtocolIcon.ICON_SIZE_16x16)); - if (protocolImg != null) - this.setIcon(new ImageIcon(protocolImg)); + if (protocolImg != null) + this.setIcon(new ImageIcon(protocolImg)); - this.setText(provider.getAccountID().getDisplayName()); + this.setText(provider.getAccountID().getDisplayName()); + } } if (isSelected) @@ -540,4 +581,19 @@ public void minimize() * @param windowParams the parameters to pass. */ public void setParams(Object[] windowParams) {} + + /** + * Updates the state of the add button. + */ + private void updateAddButtonState() + { + String contactAddress = contactAddressField.getText(); + + if (accountCombo.getSelectedItem() + instanceof ProtocolProviderService + && contactAddress != null && contactAddress.length() > 0) + addButton.setEnabled(true); + else + addButton.setEnabled(false); + } }