diff options
Diffstat (limited to 'src/net/java/sip/communicator')
9 files changed, 309 insertions, 23 deletions
diff --git a/src/net/java/sip/communicator/impl/callhistory/CallHistorySourceContact.java b/src/net/java/sip/communicator/impl/callhistory/CallHistorySourceContact.java index 4de7ba9..7c40dff 100644 --- a/src/net/java/sip/communicator/impl/callhistory/CallHistorySourceContact.java +++ b/src/net/java/sip/communicator/impl/callhistory/CallHistorySourceContact.java @@ -278,6 +278,19 @@ public class CallHistorySourceContact implements SourceContact } /** + * 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. * @param operationSet the <tt>OperationSet</tt> class, for which we would diff --git a/src/net/java/sip/communicator/impl/gui/main/call/ChooseCallAccountPopupMenu.java b/src/net/java/sip/communicator/impl/gui/main/call/ChooseCallAccountPopupMenu.java index e4d00cc..12731c2 100644 --- a/src/net/java/sip/communicator/impl/gui/main/call/ChooseCallAccountPopupMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/call/ChooseCallAccountPopupMenu.java @@ -9,6 +9,7 @@ package net.java.sip.communicator.impl.gui.main.call; 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.customcontrols.*; 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 @@ public class ChooseCallAccountPopupMenu } }); - 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 class ChooseCallAccountPopupMenu */ 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,11 +449,32 @@ public class ChooseCallAccountPopupMenu 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. */ public void loadSkin() diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/UIContactDetail.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/UIContactDetail.java index ad9ce3d..8b97fdf 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/UIContactDetail.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/UIContactDetail.java @@ -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.*; @@ -46,10 +48,22 @@ 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; @@ -88,6 +106,31 @@ public abstract class UIContactDetail } /** + * 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. * * @return the status icon of this contact detail diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/MetaUIContact.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/MetaUIContact.java index 2ff6875..6990330 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/MetaUIContact.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/MetaUIContact.java @@ -423,6 +423,8 @@ public class MetaUIContact { super( contact.getAddress(), contact.getDisplayName(), + null, + null, new ImageIcon( contact.getPresenceStatus().getStatusIcon()), contact.getProtocolProvider(), diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/SourceUIContact.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/SourceUIContact.java index 4274fd5..c903f51 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/SourceUIContact.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/SourceUIContact.java @@ -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 class SourceUIContact { super( detail.getContactAddress(), detail.getContactAddress(), + detail.getCategory(), + detail.getLabels(), null, detail.getPreferredProtocolProvider(opSetClass), detail.getPreferredProtocol(opSetClass)); @@ -295,22 +299,74 @@ public class SourceUIContact 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); + } + + } } diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/notifsource/NotificationContact.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/notifsource/NotificationContact.java index 788d091..67f0bea 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/notifsource/NotificationContact.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/notifsource/NotificationContact.java @@ -405,6 +405,8 @@ public class NotificationContact { super( messageAccount, messageAccount, + null, + null, ImageLoader.getAccountStatusImage(protocolProvider), protocolProvider, protocolProvider.getProtocolName()); diff --git a/src/net/java/sip/communicator/impl/gui/utils/ExtendedTooltip.java b/src/net/java/sip/communicator/impl/gui/utils/ExtendedTooltip.java index 5029e3f..cc19088 100644 --- a/src/net/java/sip/communicator/impl/gui/utils/ExtendedTooltip.java +++ b/src/net/java/sip/communicator/impl/gui/utils/ExtendedTooltip.java @@ -12,6 +12,7 @@ import javax.swing.*; 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 class ExtendedTooltip { 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; } /** diff --git a/src/net/java/sip/communicator/plugin/addrbook/AddrBookSourceContact.java b/src/net/java/sip/communicator/plugin/addrbook/AddrBookSourceContact.java index 73fbe0e..91cfceb 100644 --- a/src/net/java/sip/communicator/plugin/addrbook/AddrBookSourceContact.java +++ b/src/net/java/sip/communicator/plugin/addrbook/AddrBookSourceContact.java @@ -98,6 +98,26 @@ public class AddrBookSourceContact }
/**
+ * 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>.
*
diff --git a/src/net/java/sip/communicator/service/contactsource/SourceContact.java b/src/net/java/sip/communicator/service/contactsource/SourceContact.java index 99b47ca..2f71806 100644 --- a/src/net/java/sip/communicator/service/contactsource/SourceContact.java +++ b/src/net/java/sip/communicator/service/contactsource/SourceContact.java @@ -61,6 +61,15 @@ public interface SourceContact 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. * @param operationSet the <tt>OperationSet</tt> class, for which we would |