diff options
author | Yana Stamcheva <yana@jitsi.org> | 2009-11-24 15:13:16 +0000 |
---|---|---|
committer | Yana Stamcheva <yana@jitsi.org> | 2009-11-24 15:13:16 +0000 |
commit | 53fe8eefaebb42912dd8e723293e140857ba7508 (patch) | |
tree | ba9a8bc017b2a65c190ee58e0660270ac8d96bc1 /src/net/java/sip | |
parent | f660a5ed6c54749e3822ccdcd106fb8928943fa4 (diff) | |
download | jitsi-53fe8eefaebb42912dd8e723293e140857ba7508.zip jitsi-53fe8eefaebb42912dd8e723293e140857ba7508.tar.gz jitsi-53fe8eefaebb42912dd8e723293e140857ba7508.tar.bz2 |
Call and Chat Conference Invite Dialog enhancements:
- Added the possibility to add contacts, which are not in the contact list.
- Filter contact list contacts already added in a conference.
Diffstat (limited to 'src/net/java/sip')
11 files changed, 325 insertions, 53 deletions
diff --git a/src/net/java/sip/communicator/impl/contactlist/MetaContactImpl.java b/src/net/java/sip/communicator/impl/contactlist/MetaContactImpl.java index c6912b6..e063434 100644 --- a/src/net/java/sip/communicator/impl/contactlist/MetaContactImpl.java +++ b/src/net/java/sip/communicator/impl/contactlist/MetaContactImpl.java @@ -260,6 +260,17 @@ public class MetaContactImpl return null; } + /** + * Returns <tt>true</tt> if the given <tt>protocolContact</tt> is contained + * in this <tt>MetaContact</tt>, otherwise - returns <tt>false</tt>. + * @param protocolContact the <tt>Contact</tt> we're looking for + * @return <tt>true</tt> if the given <tt>protocolContact</tt> is contained + * in this <tt>MetaContact</tt>, otherwise - returns <tt>false</tt> + */ + public boolean containsContact(Contact protocolContact) + { + return protoContacts.contains(protocolContact); + } /** * Returns a <tt>java.util.Iterator</tt> over all protocol specific diff --git a/src/net/java/sip/communicator/impl/gui/customcontrols/SIPCommSmartComboBox.java b/src/net/java/sip/communicator/impl/gui/customcontrols/SIPCommSmartComboBox.java index 1a8d84c..c9c96a4 100644 --- a/src/net/java/sip/communicator/impl/gui/customcontrols/SIPCommSmartComboBox.java +++ b/src/net/java/sip/communicator/impl/gui/customcontrols/SIPCommSmartComboBox.java @@ -15,6 +15,7 @@ import javax.swing.*; import javax.swing.event.*; import net.java.sip.communicator.impl.gui.lookandfeel.*; +import net.java.sip.communicator.util.swing.plaf.*; /** * <tt>SIPCommSmartComboBox</tt> is an editable combo box which selects an item diff --git a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommComboBoxEditor.java b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommComboBoxEditor.java index 7a96a1c..c35ed33 100644 --- a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommComboBoxEditor.java +++ b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommComboBoxEditor.java @@ -13,6 +13,7 @@ import javax.swing.border.*; import javax.swing.plaf.metal.*; import net.java.sip.communicator.util.swing.*; +import net.java.sip.communicator.util.swing.plaf.*; /** * The default editor for SIPCommunicator editable combo boxes. 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 6520495..b935ea9 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 @@ -194,7 +194,7 @@ public class CallComboBox = callHistory.findLast(MAX_HISTORY_SIZE); FilterableComboBoxModel callComboModel - = (FilterableComboBoxModel)getModel(); + = (FilterableComboBoxModel) getModel(); for (CallRecord call : historyCalls) { diff --git a/src/net/java/sip/communicator/impl/gui/main/call/conference/ConferenceInviteDialog.java b/src/net/java/sip/communicator/impl/gui/main/call/conference/ConferenceInviteDialog.java index fc08b37..4f4b9e9 100644 --- a/src/net/java/sip/communicator/impl/gui/main/call/conference/ConferenceInviteDialog.java +++ b/src/net/java/sip/communicator/impl/gui/main/call/conference/ConferenceInviteDialog.java @@ -113,7 +113,8 @@ public class ConferenceInviteDialog { public void actionPerformed(ActionEvent e) { - if (getSelectedMetaContacts().hasMoreElements()) + if (getSelectedMetaContacts() != null + || getSelectedStrings() != null) { inviteContacts(); @@ -216,7 +217,8 @@ public class ConferenceInviteDialog { MetaContact metaContact = contactListIter.next(); - this.addMetaContact(metaContact); + if (!containsContact(metaContact)) + this.addMetaContact(metaContact); } } @@ -228,30 +230,45 @@ public class ConferenceInviteDialog ProtocolProviderService selectedProvider = (ProtocolProviderService) accountSelectorBox.getSelectedItem(); - java.util.List<String> selectedContactAddresses = - new ArrayList<String>(); + java.util.List<String> selectedContactAddresses + = new ArrayList<String>(); - Enumeration<MetaContact> selectedContacts - = getSelectedMetaContacts(); + // Obtain selected contacts. + Enumeration<MetaContact> selectedContacts = getSelectedMetaContacts(); - while (selectedContacts.hasMoreElements()) + if (selectedContacts != null) { - MetaContact metaContact - = selectedContacts.nextElement(); + while (selectedContacts.hasMoreElements()) + { + MetaContact metaContact + = selectedContacts.nextElement(); - Iterator<Contact> contactsIter = metaContact - .getContactsForProvider(selectedProvider); + Iterator<Contact> contactsIter = metaContact + .getContactsForProvider(selectedProvider); - // We invite the first protocol contact that corresponds to the - // invite provider. - if (contactsIter.hasNext()) - { - Contact inviteContact = contactsIter.next(); + // We invite the first protocol contact that corresponds to the + // invite provider. + if (contactsIter.hasNext()) + { + Contact inviteContact = contactsIter.next(); - selectedContactAddresses.add(inviteContact.getAddress()); + selectedContactAddresses.add(inviteContact.getAddress()); + } } } + // Obtain selected strings. + Enumeration<String> selectedStrings = getSelectedStrings(); + + if (selectedStrings != null) + { + while (selectedStrings.hasMoreElements()) + { + selectedContactAddresses.add(selectedStrings.nextElement()); + } + } + + // Invite all selected. String[] contactAddressStrings = null; if (selectedContactAddresses.size() > 0) { @@ -270,4 +287,30 @@ public class ConferenceInviteDialog contactAddressStrings, selectedProvider); } } + + /** + * Check if the given <tt>metaContact</tt> is already contained in the call. + * + * @param metaContact the <tt>Contact</tt> to check for + * @return <tt>true</tt> if the given <tt>metaContact</tt> is already + * contained in the call, otherwise - returns <tt>false</tt> + */ + private boolean containsContact(MetaContact metaContact) + { + // If the call is not yet created we just return false. + if (call == null) + return false; + + Iterator<? extends CallPeer> callPeers = call.getCallPeers(); + + while(callPeers.hasNext()) + { + CallPeer callPeer = callPeers.next(); + + if(metaContact.containsContact(callPeer.getContact())) + return true; + } + + return false; + } } diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/conference/ChatInviteDialog.java b/src/net/java/sip/communicator/impl/gui/main/chat/conference/ChatInviteDialog.java index b4400b4..82500c4 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/conference/ChatInviteDialog.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/conference/ChatInviteDialog.java @@ -92,30 +92,47 @@ public class ChatInviteDialog java.util.List<String> selectedContactAddresses = new ArrayList<String>(); - Enumeration<MetaContact> selectedContacts - = getSelectedMetaContacts(); + // Obtain selected contacts. + Enumeration<MetaContact> selectedContacts = getSelectedMetaContacts(); - while (selectedContacts.hasMoreElements()) + if (selectedContacts != null) { - MetaContact metaContact - = selectedContacts.nextElement(); + while (selectedContacts.hasMoreElements()) + { + MetaContact metaContact + = selectedContacts.nextElement(); - Iterator<Contact> contactsIter = metaContact - .getContactsForProvider( - inviteChatTransport.getProtocolProvider()); + Iterator<Contact> contactsIter = metaContact + .getContactsForProvider( + inviteChatTransport.getProtocolProvider()); - // We invite the first protocol contact that corresponds to the - // invite provider. - if (contactsIter.hasNext()) - { - Contact inviteContact = contactsIter.next(); + // We invite the first protocol contact that corresponds to the + // invite provider. + if (contactsIter.hasNext()) + { + Contact inviteContact = contactsIter.next(); - selectedContactAddresses.add(inviteContact.getAddress()); + selectedContactAddresses.add(inviteContact.getAddress()); + } } } - chatPanel.inviteContacts( inviteChatTransport, - selectedContactAddresses, - this.getReason()); + // Obtain selected strings. + Enumeration<String> selectedStrings = getSelectedStrings(); + if (selectedStrings != null) + { + while (selectedStrings.hasMoreElements()) + { + selectedContactAddresses.add(selectedStrings.nextElement()); + } + } + + // Invite all selected. + if (selectedContactAddresses.size() > 0) + { + chatPanel.inviteContacts( inviteChatTransport, + selectedContactAddresses, + this.getReason()); + } } } diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListCellRenderer.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListCellRenderer.java index 7c59830..d6b7ec6 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListCellRenderer.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListCellRenderer.java @@ -229,6 +229,12 @@ public class ContactListCellRenderer this.isLeaf = false; } + else if (value instanceof String) + { + this.setPreferredSize(new Dimension(20, 30)); + this.nameLabel.setText((String) value); + this.nameLabel.setFont(this.getFont().deriveFont(Font.PLAIN)); + } this.isSelected = isSelected; diff --git a/src/net/java/sip/communicator/impl/gui/utils/InviteDialog.java b/src/net/java/sip/communicator/impl/gui/utils/InviteDialog.java index 2bf3f33..7b90d6d 100644 --- a/src/net/java/sip/communicator/impl/gui/utils/InviteDialog.java +++ b/src/net/java/sip/communicator/impl/gui/utils/InviteDialog.java @@ -152,8 +152,7 @@ public class InviteDialog contactListScrollPane.getViewport().add(contactList); contactListScrollPane.getViewport().setBorder(null); contactListScrollPane.setViewportBorder(null); - contactListScrollPane.setBorder( - SIPCommBorders.getRoundBorder()); + contactListScrollPane.setBorder(null); JScrollPane selectedListScrollPane = new JScrollPane(); @@ -165,10 +164,20 @@ public class InviteDialog selectedListScrollPane.setBorder( SIPCommBorders.getRoundBorder()); + // New contact text field panel. + final SIPCommTextField newContactField + = new SIPCommTextField(GuiActivator.getResources() + .getI18NString("service.gui.OR_ENTER_PHONE_NUMBER")); + + TransparentPanel leftPanel = new TransparentPanel(new BorderLayout()); + leftPanel.setBorder(SIPCommBorders.getRoundBorder()); + leftPanel.add(contactListScrollPane); + leftPanel.add(newContactField, BorderLayout.SOUTH); + JPanel listPanel = new JPanel(new GridLayout(0, 2, 5, 5)); listPanel.setPreferredSize(new Dimension(400, 200)); - listPanel.add(contactListScrollPane); + listPanel.add(leftPanel); listPanel.add(selectedListScrollPane); listPanel.setOpaque(false); @@ -193,6 +202,14 @@ public class InviteDialog if (metaContacts != null && metaContacts.length > 0) moveContactsFromLeftToRight(metaContacts); + + String newContactText = newContactField.getText(); + + if (newContactText != null && newContactText.length() > 0) + { + moveStringFromLeftToRight(newContactText); + newContactField.setText(""); + } } }); @@ -253,13 +270,45 @@ public class InviteDialog } /** - * Returns an enumeration of the list of selected contacts. - * @return an enumeration of the list of selected contacts. + * Returns an enumeration of the list of selected <tt>MetaContact</tt>s. + * @return an enumeration of the list of selected <tt>MetaContact</tt>s */ - @SuppressWarnings("unchecked") //We'd like to force the cast here. public Enumeration<MetaContact> getSelectedMetaContacts() { - return (Enumeration<MetaContact>) selectedContactListModel.elements(); + if (selectedContactListModel.getSize() == 0) + return null; + + Vector<MetaContact> selectedMetaContacts = new Vector<MetaContact>(); + Enumeration<?> selectedContacts = selectedContactListModel.elements(); + while(selectedContacts.hasMoreElements()) + { + Object contact = selectedContacts.nextElement(); + if (contact instanceof MetaContact) + selectedMetaContacts.add((MetaContact)contact); + } + + return selectedMetaContacts.elements(); + } + + /** + * Returns an enumeration of the list of selected Strings. + * @return an enumeration of the list of selected Strings + */ + public Enumeration<String> getSelectedStrings() + { + if (selectedContactListModel.getSize() == 0) + return null; + + Vector<String> selectedStrings = new Vector<String>(); + Enumeration<?> selectedContacts = selectedContactListModel.elements(); + while(selectedContacts.hasMoreElements()) + { + Object contact = selectedContacts.nextElement(); + if (contact instanceof String) + selectedStrings.add((String)contact); + } + + return selectedStrings.elements(); } /** @@ -315,17 +364,28 @@ public class InviteDialog } /** + * Moves a string from left to right. + * @param text the text to move from left to right + */ + private void moveStringFromLeftToRight(String text) + { + selectedContactListModel.addElement(text); + } + + /** * Moves a contact from the right list to the left. * - * @param metaContacts the contact to move. + * @param contacts the contact to move. */ - private void moveContactsFromRightToLeft(Object[] metaContacts) + private void moveContactsFromRightToLeft(Object[] contacts) { - for (Object metaContact : metaContacts) + for (Object contact : contacts) { - selectedContactListModel.removeElement(metaContact); + selectedContactListModel.removeElement(contact); - contactListModel.addElement(metaContact); + // If this is a MetaContact re-add it in the left list. + if (contact instanceof MetaContact) + contactListModel.addElement(contact); } } } diff --git a/src/net/java/sip/communicator/service/contactlist/MetaContact.java b/src/net/java/sip/communicator/service/contactlist/MetaContact.java index 2fd5acc..65a4bc8 100644 --- a/src/net/java/sip/communicator/service/contactlist/MetaContact.java +++ b/src/net/java/sip/communicator/service/contactlist/MetaContact.java @@ -69,6 +69,15 @@ public interface MetaContact ProtocolProviderService ownerProvider); /** + * Returns <tt>true</tt> if the given <tt>protocolContact</tt> is contained + * in this <tt>MetaContact</tt>, otherwise - returns <tt>false</tt>. + * @param protocolContact the <tt>Contact</tt> we're looking for + * @return <tt>true</tt> if the given <tt>protocolContact</tt> is contained + * in this <tt>MetaContact</tt>, otherwise - returns <tt>false</tt> + */ + public boolean containsContact(Contact protocolContact); + + /** * Returns the number of protocol speciic <tt>Contact</tt>s that this * <tt>MetaContact</tt> contains. * @return an int indicating the number of protocol specific contacts merged diff --git a/src/net/java/sip/communicator/util/swing/SIPCommTextField.java b/src/net/java/sip/communicator/util/swing/SIPCommTextField.java new file mode 100644 index 0000000..5475da3 --- /dev/null +++ b/src/net/java/sip/communicator/util/swing/SIPCommTextField.java @@ -0,0 +1,123 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.util.swing; + +import java.awt.*; +import java.awt.event.*; + +import javax.swing.*; + +/** + * The <tt>SIPCommTextField</tt> is a <tt>JTextField</tt> that offers the + * possibility to specify a default (tip) text that explains what is the + * required data. + * @author Yana Stamcheva + */ +public class SIPCommTextField + extends JTextField + implements MouseListener, + FocusListener +{ + private final String defaultText; + + /** + * Creates an instance of <tt>SIPCommTextField</tt> by specifying the text + * we would like to show by default in it. + * @param text the text we would like to enter by default + */ + public SIPCommTextField(String text) + { + super(text); + + this.defaultText = text; + + this.setFont(getFont().deriveFont(11f)); + this.setForeground(Color.GRAY); + + this.addMouseListener(this); + this.addFocusListener(this); + } + + /** + * Indicates that the mouse button was pressed on this component. Hides + * the default text when user clicks on the text field. + * @param e the <tt>MouseEvent</tt> that notified us + */ + public void mousePressed(MouseEvent e) + { + if (getText() == null) + { + // We call the super.setText() because we have modified ours to + // set the default text each time someone has set null text. + super.setText(""); + this.setForeground(Color.BLACK); + } + } + + public void mouseClicked(MouseEvent e) {} + + public void mouseEntered(MouseEvent e) {} + + public void mouseExited(MouseEvent e) {} + + public void mouseReleased(MouseEvent e) {} + + /** + * Selects the user text when this text field gains the focus. + * @param e the <tt>FocusEvent</tt> that notified us + */ + public void focusGained(FocusEvent e) + { + if (getText() != null) + select(0, super.getText().length()); + } + + /** + * Sets the default text when the field looses focus. + * @param e the <tt>FocusEvent</tt> that notified us + */ + public void focusLost(FocusEvent e) + { + if (getText() == null || getText().length() == 0) + { + setDefaultText(); + } + } + + /** + * Returns the text contained in this field. + * @return the text contained in this field + */ + public String getText() + { + if (!super.getText().equals(defaultText)) + return super.getText(); + + return null; + } + + /** + * Sets the text of this text field. + * @param text the text to show in this text field + */ + public void setText(String text) + { + if (text != null && text.length() > 0) + super.setText(text); + else + setDefaultText(); + } + + /** + * Sets the default text. + */ + private void setDefaultText() + { + super.setText(defaultText); + this.setForeground(Color.GRAY); + } +} diff --git a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommTextFieldUI.java b/src/net/java/sip/communicator/util/swing/plaf/SIPCommTextFieldUI.java index 616689b..35143f6 100644 --- a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommTextFieldUI.java +++ b/src/net/java/sip/communicator/util/swing/plaf/SIPCommTextFieldUI.java @@ -3,7 +3,7 @@ * * Distributable under LGPL license. See terms of license at gnu.org. */ -package net.java.sip.communicator.impl.gui.lookandfeel; +package net.java.sip.communicator.util.swing.plaf; import java.awt.*; import java.awt.event.*; @@ -13,7 +13,7 @@ import javax.swing.plaf.*; import javax.swing.plaf.metal.*; import javax.swing.text.*; -import net.java.sip.communicator.impl.gui.utils.*; +import net.java.sip.communicator.util.*; import net.java.sip.communicator.util.swing.*; /** @@ -41,11 +41,12 @@ public class SIPCommTextFieldUI */ public SIPCommTextFieldUI() { - deleteButtonImg - = ImageLoader.getImage(ImageLoader.DELETE_TEXT_ICON); + deleteButtonImg = UtilActivator.getResources() + .getImage("service.gui.lookandfeel.DELETE_TEXT_ICON").getImage(); - deleteButtonRolloverImg - = ImageLoader.getImage(ImageLoader.DELETE_TEXT_ROLLOVER_ICON); + deleteButtonRolloverImg = UtilActivator.getResources() + .getImage("service.gui.lookandfeel.DELETE_TEXT_ROLLOVER_ICON") + .getImage(); deleteButton = new SIPCommButton( deleteButtonImg, deleteButtonRolloverImg); |