Show an add contact button for call history and external source contacts.

cusax-fix
Yana Stamcheva 15 years ago
parent 52ef7b1f07
commit 81a2a1f5d9

@ -120,6 +120,8 @@ service.gui.buttons.DESKTOP_BUTTON_SMALL_PRESSED=resources/images/impl/gui/butto
service.gui.buttons.CALL_DESKTOP_BUTTON=resources/images/impl/gui/buttons/callDesktopSharing.png
service.gui.buttons.CHAT_BUTTON_SMALL=resources/images/impl/gui/buttons/chatSmall.png
service.gui.buttons.CHAT_BUTTON_SMALL_PRESSED=resources/images/impl/gui/buttons/chatSmallPressed.png
service.gui.buttons.ADD_CONTACT_BUTTON_SMALL=resources/images/impl/gui/buttons/addContactSmall.png
service.gui.buttons.ADD_CONTACT_BUTTON_SMALL_PRESSED=resources/images/impl/gui/buttons/addContactSmallPressed.png
service.gui.buttons.CALL_BUTTON_PRESSED_BG=resources/images/impl/gui/buttons/callButtonPressed.png
service.gui.buttons.HANGUP_BUTTON_BG=resources/images/impl/gui/buttons/hangupButton.png
service.gui.buttons.HANGUP_ROLLOVER_BUTTON_BG=resources/images/impl/gui/buttons/hangupButtonRollover.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

@ -413,9 +413,6 @@ public void loadSkin()
BufferedImage statusIcon = null;
if (status != null)
statusIcon = Constants.getStatusIcon(status);
else
statusIcon
= Constants.getStatusIcon(Constants.OFFLINE_STATUS);
if (statusIcon != null)
contactIcon = new ImageIcon(statusIcon);

@ -13,11 +13,13 @@
import java.util.List;
import javax.swing.*;
import javax.swing.JPopupMenu.*;
import javax.swing.tree.*;
import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.customcontrols.*;
import net.java.sip.communicator.impl.gui.main.call.*;
import net.java.sip.communicator.impl.gui.main.contactlist.contactsource.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.contactsource.*;
import net.java.sip.communicator.service.contactlist.*;
@ -129,6 +131,14 @@ public class ContactListTreeCellRenderer
*/
private final SIPCommButton chatButton = new SIPCommButton();
/**
* The add contact button.
*/
private final SIPCommButton addContactButton = new SIPCommButton(
ImageLoader.getImage(ImageLoader.ADD_CONTACT_BUTTON_SMALL),
ImageLoader.getImage(ImageLoader.ADD_CONTACT_BUTTON_SMALL_PRESSED),
null);
/**
* The constraints used to align components in the <tt>centerPanel</tt>.
*/
@ -213,14 +223,14 @@ public ContactListTreeCellRenderer()
constraints.weightx = 1f;
constraints.weighty = 0f;
constraints.gridheight = 1;
constraints.gridwidth = 4;
constraints.gridwidth = 5;
this.add(nameLabel, constraints);
rightLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2));
constraints.anchor = GridBagConstraints.NORTHEAST;
constraints.fill = GridBagConstraints.VERTICAL;
constraints.gridx = 5;
constraints.gridx = 6;
constraints.gridy = 0;
constraints.gridheight = 3;
constraints.weightx = 0f;
@ -280,6 +290,25 @@ public void actionPerformed(ActionEvent e)
}
});
addContactButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if (treeNode != null && treeNode instanceof ContactNode)
{
UIContact contactDescriptor
= ((ContactNode) treeNode).getContactDescriptor();
// The add contact function has only sense for external
// source contacts.
if (contactDescriptor instanceof SourceUIContact)
{
addContact((SourceUIContact) contactDescriptor);
}
}
}
});
this.setToolTipText("");
}
@ -402,6 +431,7 @@ else if (value instanceof GroupNode)
this.remove(callVideoButton);
this.remove(desktopSharingButton);
this.remove(chatButton);
this.remove(addContactButton);
this.statusLabel.setIcon(
expanded
@ -606,7 +636,7 @@ private void initDisplayDetails(UIContact contact)
constraints.gridy = 1;
constraints.weightx = 0f;
constraints.weighty = 0f;
constraints.gridwidth = 4;
constraints.gridwidth = 5;
constraints.gridheight = 1;
this.add(displayDetailsLabel, constraints);
@ -624,6 +654,7 @@ private void initButtonsPanel(UIContact uiContact)
this.remove(callVideoButton);
this.remove(desktopSharingButton);
this.remove(chatButton);
this.remove(addContactButton);
if (!isSelected)
return;
@ -641,6 +672,8 @@ private void initButtonsPanel(UIContact uiContact)
imContact = uiContact.getDefaultContactDetail(
OperationSetBasicInstantMessaging.class);
int x = statusLabel.getWidth();
if (imContact != null)
{
constraints.anchor = GridBagConstraints.WEST;
@ -654,11 +687,11 @@ private void initButtonsPanel(UIContact uiContact)
this.chatButton.setBorder(null);
this.add(chatButton, constraints);
int x = statusLabel.getWidth();
chatButton.setBounds(x,
nameLabel.getHeight() + statusMessageLabelHeight,
28, 28);
x += chatButton.getWidth();
}
UIContactDetail telephonyContact
@ -681,14 +714,11 @@ private void initButtonsPanel(UIContact uiContact)
this.callButton.setBorder(null);
this.add(callButton, constraints);
int x = statusLabel.getWidth();
if (imContact != null)
x += callButton.getWidth();
callButton.setBounds(x,
nameLabel.getHeight() + statusMessageLabelHeight, 28, 28);
callButton.setEnabled(telephonyContact != null);
x += callButton.getWidth();
}
UIContactDetail videoContact
@ -708,16 +738,10 @@ private void initButtonsPanel(UIContact uiContact)
this.callVideoButton.setBorder(null);
this.add(callVideoButton, constraints);
int x = statusLabel.getWidth();
if (imContact != null)
x += chatButton.getWidth();
if (telephonyContact != null)
x += callButton.getWidth();
callVideoButton.setBounds(x,
nameLabel.getHeight() + statusMessageLabelHeight, 28, 28);
x += callVideoButton.getWidth();
}
UIContactDetail desktopContact
@ -737,19 +761,29 @@ private void initButtonsPanel(UIContact uiContact)
this.desktopSharingButton.setBorder(null);
this.add(desktopSharingButton, constraints);
int x = statusLabel.getWidth();
if (imContact != null)
x += chatButton.getWidth();
desktopSharingButton.setBounds(x,
nameLabel.getHeight() + statusMessageLabelHeight, 28, 28);
if (telephonyContact != null)
x += callButton.getWidth();
x += desktopSharingButton.getWidth();
}
if (videoContact != null)
x += callVideoButton.getWidth();
if (uiContact.getDescriptor() instanceof SourceContact)
{
constraints.anchor = GridBagConstraints.WEST;
constraints.fill = GridBagConstraints.NONE;
constraints.gridx = 5;
constraints.gridy = 2;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.weightx = 0f;
constraints.weighty = 0f;
this.addContactButton.setBorder(null);
this.add(addContactButton, constraints);
desktopSharingButton.setBounds(x,
addContactButton.setBounds(x,
nameLabel.getHeight() + statusMessageLabelHeight, 28, 28);
x += addContactButton.getWidth();
}
this.setBounds(0, 0, tree.getWidth(), getPreferredSize().height);
@ -822,6 +856,15 @@ public JButton getDesktopSharingButton()
return desktopSharingButton;
}
/**
* Returns the add contact button contained in the current cell.
* @return the add contact button contained in the current cell
*/
public JButton getAddContactButton()
{
return addContactButton;
}
/**
* Calls the given treeNode.
* @param treeNode the <tt>TreeNode</tt> to call
@ -1138,7 +1181,56 @@ else if (deviceNumber > 1)
}
}
/**
/**
* Shows the appropriate user interface that would allow the user to add
* the given <tt>SourceUIContact</tt> to their contact list.
*
* @param contact the contact to add
*/
private void addContact(SourceUIContact contact)
{
JMenuItem addContactMenu = TreeContactList.createAddContactMenu(
(SourceContact) contact.getDescriptor());
JPopupMenu popupMenu;
if (addContactMenu instanceof JMenu)
{
JMenu menu = ((JMenu) addContactMenu);
popupMenu = menu.getPopupMenu();
}
else
{
popupMenu = new JPopupMenu();
popupMenu.add(addContactMenu);
}
// Add a title label.
JLabel infoLabel = new JLabel();
infoLabel.setText("<html><b>"
+ GuiActivator.getResources()
.getI18NString("service.gui.ADD_CONTACT")
+ "</b></html>");
popupMenu.insert(infoLabel, 0);
popupMenu.insert(new Separator(), 1);
popupMenu.setFocusable(true);
popupMenu.setInvoker(tree);
Point location = new Point(addContactButton.getX(),
addContactButton.getY() + addContactButton.getHeight());
SwingUtilities.convertPointToScreen(location, tree);
location.y = location.y
+ tree.getPathBounds(tree.getSelectionPath()).y;
popupMenu.setLocation(location.x + 8, location.y - 8);
popupMenu.setVisible(true);
}
/**
* Returns the drag icon used to represent a cell in all drag operations.
*
* @param tree the parent tree object

@ -79,7 +79,8 @@ private void initItems()
if (cDetail != null)
add(initCallMenu());
addContactComponent = initAddContactMenu();
addContactComponent
= TreeContactList.createAddContactMenu(sourceContact);
if (addContactComponent != null)
add(addContactComponent);
@ -151,94 +152,6 @@ else if (providersCount > 1)
return callContactMenu;
}
/**
* Initializes the add contact menu item.
* @return the add contact menu item
*/
private Component initAddContactMenu()
{
Component addContactComponentTmp = null;
List<ContactDetail> details = sourceContact.getContactDetails();
if (details.size() == 1)
{
addContactComponentTmp
= new JMenuItem(GuiActivator.getResources().getI18NString(
"service.gui.ADD_CONTACT"),
new ImageIcon(ImageLoader
.getImage(ImageLoader.ADD_CONTACT_16x16_ICON)));
final ContactDetail detail = details.get(0);
((JMenuItem) addContactComponentTmp)
.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
showAddContactDialog(detail);
}
});
}
// If we have more than one details we would propose a separate menu
// item for each one of them.
else if (details.size() > 1)
{
addContactComponentTmp
= new JMenu(GuiActivator.getResources().getI18NString(
"service.gui.ADD_CONTACT"));
Iterator<ContactDetail> detailsIter = details.iterator();
while (detailsIter.hasNext())
{
final ContactDetail detail = detailsIter.next();
JMenuItem addMenuItem
= new JMenuItem(detail.getContactAddress());
((JMenu) addContactComponentTmp).add(addMenuItem);
addMenuItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
showAddContactDialog(detail);
}
});
}
}
return addContactComponentTmp;
}
/**
* Creates and shows an <tt>AddContactDialog</tt> with a predefined
* <tt>contactAddress</tt> and <tt>protocolProvider</tt>.
* @param contactDetail the contact detail to be added
*/
private void showAddContactDialog(ContactDetail contactDetail)
{
AddContactDialog dialog = new AddContactDialog(
GuiActivator.getUIService().getMainFrame());
// Try to obtain a preferred provider.
ProtocolProviderService preferredProvider = null;
List<Class<? extends OperationSet>> opSetClasses
= contactDetail.getSupportedOperationSets();
if (opSetClasses != null
&& opSetClasses.size() > 0)
{
preferredProvider
= contactDetail.getPreferredProtocolProvider(
opSetClasses.get(0));
}
if (preferredProvider != null)
dialog.setSelectedAccount(preferredProvider);
dialog.setContactAddress(contactDetail.getContactAddress());
dialog.setVisible(true);
}
// private Component initIMMenu()
// {
// SIPCommMenu callContactMenu = new SIPCommMenu(

@ -1962,6 +1962,98 @@ private static void setScaledLabelImage(
label.repaint();
}
/**
* Create an the add contact menu, taking into account the number of contact
* details available in the given <tt>sourceContact</tt>.
*
* @param sourceContact the external source contact, for which we'd like
* to create a menu
* @return the add contact menu
*/
public static JMenuItem createAddContactMenu(SourceContact sourceContact)
{
JMenuItem addContactComponentTmp = null;
List<ContactDetail> details = sourceContact.getContactDetails();
if (details.size() == 1)
{
addContactComponentTmp
= new JMenuItem(GuiActivator.getResources().getI18NString(
"service.gui.ADD_CONTACT"),
new ImageIcon(ImageLoader
.getImage(ImageLoader.ADD_CONTACT_16x16_ICON)));
final ContactDetail detail = details.get(0);
((JMenuItem) addContactComponentTmp)
.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
showAddContactDialog(detail);
}
});
}
// If we have more than one details we would propose a separate menu
// item for each one of them.
else if (details.size() > 1)
{
addContactComponentTmp
= new JMenu(GuiActivator.getResources().getI18NString(
"service.gui.ADD_CONTACT"));
Iterator<ContactDetail> detailsIter = details.iterator();
while (detailsIter.hasNext())
{
final ContactDetail detail = detailsIter.next();
JMenuItem addMenuItem
= new JMenuItem(detail.getContactAddress());
((JMenu) addContactComponentTmp).add(addMenuItem);
addMenuItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
showAddContactDialog(detail);
}
});
}
}
return addContactComponentTmp;
}
/**
* Creates and shows an <tt>AddContactDialog</tt> with a predefined
* <tt>contactAddress</tt> and <tt>protocolProvider</tt>.
* @param contactDetail the contact detail to be added
*/
private static void showAddContactDialog(ContactDetail contactDetail)
{
AddContactDialog dialog = new AddContactDialog(
GuiActivator.getUIService().getMainFrame());
// Try to obtain a preferred provider.
ProtocolProviderService preferredProvider = null;
List<Class<? extends OperationSet>> opSetClasses
= contactDetail.getSupportedOperationSets();
if (opSetClasses != null
&& opSetClasses.size() > 0)
{
preferredProvider
= contactDetail.getPreferredProtocolProvider(
opSetClasses.get(0));
}
if (preferredProvider != null)
dialog.setSelectedAccount(preferredProvider);
dialog.setContactAddress(contactDetail.getContactAddress());
dialog.setVisible(true);
}
/**
* Listens for adding and removing of <tt>ContactSourceService</tt>
* implementations.

@ -7,7 +7,6 @@
package net.java.sip.communicator.impl.gui.main.contactlist;
import java.util.*;
import java.util.List;
import javax.swing.*;

@ -254,8 +254,7 @@ public SourceContactDetail( ContactDetail detail,
{
super( detail.getContactAddress(),
detail.getContactAddress(),
new ImageIcon(
Constants.getStatusIcon(Constants.OFFLINE_STATUS)),
null,
detail.getPreferredProtocolProvider(opSetClass),
detail.getPreferredProtocol(opSetClass));
}

@ -305,6 +305,20 @@ public class ImageLoader
public static final ImageID CALL_VIDEO_BUTTON_SMALL_PRESSED
= new ImageID("service.gui.buttons.CALL_VIDEO_BUTTON_SMALL_PRESSED");
/**
* The add contact button small image, shown when an external source contact
* is selected.
*/
public static final ImageID ADD_CONTACT_BUTTON_SMALL
= new ImageID("service.gui.buttons.ADD_CONTACT_BUTTON_SMALL");
/**
* The add contact button small pressed image, shown when an external source
* contact is selected and add contact button is pressed.
*/
public static final ImageID ADD_CONTACT_BUTTON_SMALL_PRESSED
= new ImageID("service.gui.buttons.ADD_CONTACT_BUTTON_SMALL_PRESSED");
/**
* The chat button small image.
*/

Loading…
Cancel
Save