Showing categories and labels for contact details coming from AddressBook or Outlook.

cusax-fix
Yana Stamcheva 16 years ago
parent d72d64b136
commit c6971afd00

@ -153,6 +153,7 @@ service.gui.DISCONNECTED_STATUS=Disconnected
service.gui.DND_STATUS=Do not disturb
service.gui.DO_NOT_ASK_AGAIN=Don't ask again
service.gui.DO_NOT_SHOW_AGAIN=Don't show this message again
service.gui.DRAG_FOR_SHARING=Drag here anything you want to share...
service.gui.DURATION=duration
service.gui.EDIT=&Edit
service.gui.EMPTY_HISTORY=&Empty history

@ -277,6 +277,19 @@ public List<ContactDetail> getContactDetails(
return new LinkedList<ContactDetail>(contactDetails);
}
/**
* Returns a list of all <tt>ContactDetail</tt>s corresponding to the given
* category.
* @param category the <tt>OperationSet</tt> class we're looking for
* @return a list of all <tt>ContactDetail</tt>s corresponding to the given
* category
*/
public List<ContactDetail> getContactDetails(String category)
{
// We don't support category for call history details, so we return null.
return null;
}
/**
* Returns the preferred <tt>ContactDetail</tt> for a given
* <tt>OperationSet</tt> class.

@ -9,6 +9,7 @@
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.util.*;
import java.util.List;
import javax.swing.*;
@ -18,6 +19,7 @@
import net.java.sip.communicator.impl.gui.main.chat.*;
import net.java.sip.communicator.impl.gui.main.contactlist.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.contactsource.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.*;
import net.java.sip.communicator.util.skin.*;
@ -252,7 +254,56 @@ else if (opSetClass.equals(
}
});
this.add(contactItem);
String category = telephonyContact.getCategory();
if (category != null && category.equals(ContactDetail.CATEGORY_PHONE))
{
int index = findPhoneItemIndex();
if (index < 0)
add(contactItem);
else
insert(contactItem, findPhoneItemIndex());
}
else
{
Component lastComp = getComponent(getComponentCount() - 1);
if (lastComp instanceof ContactMenuItem)
category = ((ContactMenuItem) lastComp).getCategory();
if (category != null
&& category.equals(ContactDetail.CATEGORY_PHONE))
addSeparator();
add(contactItem);
}
}
/**
* Returns the index of a phone menu item.
*
* @return the index of a phone menu item
*/
private int findPhoneItemIndex()
{
int index = -1;
for (int i = getComponentCount() - 1; i > 1; i--)
{
Component c = getComponent(i);
if (c instanceof ContactMenuItem)
{
String category = ((ContactMenuItem) c).getCategory();
if (category == null
|| !category.equals(ContactDetail.CATEGORY_PHONE))
continue;
}
else if (c instanceof JSeparator)
index = i - 1;
else
return index;
}
return index;
}
/**
@ -329,7 +380,10 @@ public void showPopupMenu()
*/
private Component createInfoLabel(String infoString)
{
JLabel infoLabel = new JLabel();
JMenuItem infoLabel = new JMenuItem();
infoLabel.setEnabled(false);
infoLabel.setFocusable(false);
infoLabel.setText("<html><b>" + infoString + "</b></html>");
@ -395,10 +449,31 @@ private class ContactMenuItem
public ContactMenuItem(UIContactDetail contact)
{
this.contact = contact;
this.setText(contact.getDisplayName());
String itemName = "<html>";
Iterator<String> labels = contact.getLabels();
if (labels != null && labels.hasNext())
while (labels.hasNext())
itemName += "<b style=\"color: gray\">"
+ labels.next().toLowerCase() + "</b> ";
itemName += contact.getDisplayName() + "</html>";
this.setText(itemName);
loadSkin();
}
/**
* Returns the category of the underlying contact detail.
*
* @return the category of the underlying contact detail
*/
public String getCategory()
{
return contact.getCategory();
}
/**
* Reloads contact icon.
*/

@ -6,6 +6,8 @@
*/
package net.java.sip.communicator.impl.gui.main.contactlist;
import java.util.*;
import javax.swing.*;
import net.java.sip.communicator.service.protocol.*;
@ -45,11 +47,23 @@ public abstract class UIContactDetail
*/
private final String preferredProtocol;
/**
* The collection of labels associated with this detail.
*/
private final Collection<String> labels;
/**
* The category of the underlying contact detail.
*/
private final String category;
/**
* Creates a <tt>UIContactDetail</tt> by specifying the contact
* <tt>address</tt>, the <tt>displayName</tt> and <tt>preferredProvider</tt>.
* @param address the contact address
* @param displayName the contact display name
* @param category the category of the underlying contact detail
* @param labels the collection of labels associated with this detail
* @param statusIcon the status icon of this contact detail
* @param preferredProvider the preferred protocol provider
* @param preferredProtocol the preferred protocol if no protocol provider
@ -58,12 +72,16 @@ public abstract class UIContactDetail
public UIContactDetail(
String address,
String displayName,
String category,
Collection<String> labels,
ImageIcon statusIcon,
ProtocolProviderService preferredProvider,
String preferredProtocol)
{
this.address = address;
this.displayName = displayName;
this.category = category;
this.labels = labels;
this.statusIcon = statusIcon;
this.protocolProvider = preferredProvider;
this.preferredProtocol = preferredProtocol;
@ -87,6 +105,31 @@ public String getAddress()
return address;
}
/**
* Returns the category of the underlying detail.
*
* @return the category of the underlying detail
*/
public String getCategory()
{
return category;
}
/**
* Returns an iterator over the collection of labels associated with this
* detail.
*
* @return an iterator over the collection of labels associated with this
* detail
*/
public Iterator<String> getLabels()
{
if (labels != null)
return labels.iterator();
return null;
}
/**
* Returns the status icon of this contact detail.
*

@ -423,6 +423,8 @@ public MetaContactDetail(Contact contact)
{
super( contact.getAddress(),
contact.getDisplayName(),
null,
null,
new ImageIcon(
contact.getPresenceStatus().getStatusIcon()),
contact.getProtocolProvider(),

@ -6,7 +6,9 @@
*/
package net.java.sip.communicator.impl.gui.main.contactlist.contactsource;
import java.awt.*;
import java.util.*;
import java.util.List;
import javax.swing.*;
@ -254,6 +256,8 @@ public SourceContactDetail( ContactDetail detail,
{
super( detail.getContactAddress(),
detail.getContactAddress(),
detail.getCategory(),
detail.getLabels(),
null,
detail.getPreferredProtocolProvider(opSetClass),
detail.getPreferredProtocol(opSetClass));
@ -295,22 +299,74 @@ public ExtendedTooltip getToolTip()
tip.setTitle(sourceContact.getDisplayName());
Iterator<ContactDetail> details
= sourceContact.getContactDetails().iterator();
List<ContactDetail> details = sourceContact.getContactDetails(
ContactDetail.CATEGORY_PHONE);
ContactDetail contactDetail;
while (details.hasNext())
{
contactDetail = details.next();
if (details != null && details.size() > 0)
addDetailsToToolTip(details,
ContactDetail.CATEGORY_PHONE,
tip);
String contactAddress = contactDetail.getContactAddress();
//String statusMessage = protocolContact.getStatusMessage();
details = sourceContact.getContactDetails(
ContactDetail.CATEGORY_EMAIL);
tip.addLine(null, contactAddress);
}
if (details != null && details.size() > 0)
addDetailsToToolTip(details,
ContactDetail.CATEGORY_EMAIL,
tip);
details = sourceContact.getContactDetails(
ContactDetail.CATEGORY_INSTANT_MESSAGING);
if (details != null && details.size() > 0)
addDetailsToToolTip(details,
ContactDetail.CATEGORY_INSTANT_MESSAGING,
tip);
tip.setBottomText(getDisplayDetails());
return tip;
}
private void addDetailsToToolTip( List<ContactDetail> details,
String category,
ExtendedTooltip toolTip)
{
ContactDetail contactDetail;
JLabel categoryLabel = new JLabel(category + "s", null, JLabel.LEFT);
categoryLabel.setFont(categoryLabel.getFont().deriveFont(Font.BOLD));
categoryLabel.setForeground(Color.DARK_GRAY);
toolTip.addLine(null, " ");
toolTip.addLine(new JLabel[]{categoryLabel});
Iterator<ContactDetail> detailsIter = details.iterator();
while (detailsIter.hasNext())
{
contactDetail = detailsIter.next();
Collection<String> labels = contactDetail.getLabels();
JLabel[] jLabels = new JLabel[labels.size() + 1];
int i = 0;
if (labels != null && labels.size() > 0)
{
Iterator<String> labelsIter = labels.iterator();
while(labelsIter.hasNext())
{
JLabel label = new JLabel(labelsIter.next().toLowerCase());
label.setFont(label.getFont().deriveFont(Font.BOLD));
label.setForeground(Color.GRAY);
jLabels[i] = label;
i++;
}
}
jLabels[i] = new JLabel(contactDetail.getContactAddress());
toolTip.addLine(jLabels);
}
}
}

@ -405,6 +405,8 @@ public MessageWaitingDetail(ProtocolProviderService protocolProvider,
{
super( messageAccount,
messageAccount,
null,
null,
ImageLoader.getAccountStatusImage(protocolProvider),
protocolProvider,
protocolProvider.getProtocolName());

@ -12,6 +12,7 @@
import javax.swing.plaf.metal.*;
import net.java.sip.communicator.util.*;
import net.java.sip.communicator.util.swing.*;
/**
* The tooltip shown over a contact in the contact list.
@ -120,32 +121,97 @@ public void addLine(Icon icon,
{
JLabel lineLabel = new JLabel( text,
icon,
JLabel.CENTER);
JLabel.LEFT);
linesPanel.add(lineLabel);
Dimension labelSize = calculateLabelSize(lineLabel);
recalculateTooltipSize(labelSize.width, labelSize.height);
}
/**
* Adds the given array of labels as one line in this tool tip.
*
* @param labels the labels to add
*/
public void addLine(JLabel[] labels)
{
Dimension lineSize = null;
JPanel labelPanel = null;
if (labels.length > 0)
{
labelPanel = new TransparentPanel(
new FlowLayout(FlowLayout.LEFT, 2, 0));
linesPanel.add(labelPanel);
}
else
return;
if (labelPanel != null)
for (JLabel label : labels)
{
labelPanel.add(label);
if (lineSize == null)
lineSize = calculateLabelSize(label);
else
lineSize = new Dimension(
lineSize.width + calculateLabelSize(label).width,
lineSize.height);
}
recalculateTooltipSize(lineSize.width, lineSize.height);
}
/**
* Sets the text that would appear on the bottom of the tooltip.
* @param text the text to set
*/
public void setBottomText(String text)
{
this.bottomLabel.setText(text);
}
/**
* Calculates label size.
*
* @param label the label, which size we should calculate
* @return the Dimension indicating the label size
*/
private Dimension calculateLabelSize(JLabel label)
{
Icon icon = label.getIcon();
String text = label.getText();
int iconWidth = 0;
if (icon != null)
iconWidth = icon.getIconWidth();
int stringWidth
= GuiUtils.getStringWidth(lineLabel, text)
= GuiUtils.getStringWidth(label, text)
+ iconWidth
+ lineLabel.getIconTextGap();
+ label.getIconTextGap();
if (textWidth < stringWidth)
textWidth = stringWidth;
int stringHeight = GuiUtils.getStringSize(label, text).height;
textHeight += GuiUtils.getStringSize(lineLabel, text).height;
return new Dimension(stringWidth, stringHeight);
}
/**
* Sets the text that would appear on the bottom of the tooltip.
* @param text the text to set
* Re-calculates the tooltip size.
*
* @param newTextWidth the width of the newly added text that should be
* added to the global width
* @param newTextHeight the height of the newly added text that should be
* added to the global height
*/
public void setBottomText(String text)
private void recalculateTooltipSize(int newTextWidth, int newTextHeight)
{
this.bottomLabel.setText(text);
if (textWidth < newTextWidth)
textWidth = newTextWidth;
textHeight += newTextHeight;
}
/**

@ -97,6 +97,26 @@ public List<ContactDetail> getContactDetails(
return contactDetails;
}
/**
* Returns a list of all <tt>ContactDetail</tt>s corresponding to the given
* category.
* @param category the <tt>OperationSet</tt> class we're looking for
* @return a list of all <tt>ContactDetail</tt>s corresponding to the given
* category
*/
public List<ContactDetail> getContactDetails(String category)
{
List<ContactDetail> contactDetails = new LinkedList<ContactDetail>();
for (ContactDetail contactDetail : getContactDetails())
{
String detailCategory = contactDetail.getCategory();
if (detailCategory != null && detailCategory.equals(category))
contactDetails.add(contactDetail);
}
return contactDetails;
}
/**
* Gets the <tt>ContactSourceService</tt> which has created this
* <tt>SourceContact</tt>.

@ -60,6 +60,15 @@ public interface SourceContact
public List<ContactDetail> getContactDetails(
Class<? extends OperationSet> operationSet);
/**
* Returns a list of all <tt>ContactDetail</tt>s corresponding to the given
* category.
* @param category the <tt>OperationSet</tt> class we're looking for
* @return a list of all <tt>ContactDetail</tt>s corresponding to the given
* category
*/
public List<ContactDetail> getContactDetails(String category);
/**
* Returns the preferred <tt>ContactDetail</tt> for a given
* <tt>OperationSet</tt> class.

Loading…
Cancel
Save