/** * Returns the preferred size of this component. * * @return the preferred size of this component */ public Dimension getPreferredSize() { Dimension preferredSize = new Dimension(); int preferredHeight; if (treeNode instanceof ContactNode) { UIContact contact = ((ContactNode) treeNode).getContactDescriptor(); preferredHeight = contact.getPreferredHeight(); if (preferredHeight > 0) preferredSize.height = preferredHeight; else if (contact instanceof ShowMoreContact) preferredSize.height = 20; else if (isSelected && treeContactList.isContactButtonsVisible()) preferredSize.height = 70; else preferredSize.height = 35; } else if (treeNode instanceof GroupNode) { UIGroup group = ((GroupNode) treeNode).getGroupDescriptor(); preferredHeight = group.getPreferredHeight(); if (isSelected && customActionButtonsUIGroup != null && !customActionButtonsUIGroup.isEmpty()) preferredSize.height = 70; else if (preferredHeight > 0) preferredSize.height = preferredHeight; else preferredSize.height = 20; } return preferredSize; }
/** * Initializes buttons panel. * * @param uiContact the <tt>UIContact</tt> for which we initialize the button panel */ private void initButtonsPanel(UIContact uiContact) { this.remove(chatButton); this.remove(callButton); this.remove(callVideoButton); this.remove(desktopSharingButton); this.remove(addContactButton); clearCustomActionButtons(); if (!isSelected) return; UIContactDetail imContact = null; // For now we support instance messaging only for contacts in our // contact list until it's implemented for external source contacts. if (uiContact.getDescriptor() instanceof MetaContact) imContact = uiContact.getDefaultContactDetail(OperationSetBasicInstantMessaging.class); int x = (statusIcon == null ? 0 : statusIcon.getIconWidth()) + LEFT_BORDER + H_GAP; // Re-initialize the x grid. constraints.gridx = 0; int gridX = 0; if (imContact != null) { x += addButton(chatButton, ++gridX, x, false); } UIContactDetail telephonyContact = uiContact.getDefaultContactDetail(OperationSetBasicTelephony.class); // Check if contact has additional phone numbers, if yes show the // call button ContactPhoneUtil contactPhoneUtil = null; // check for phone stored in contact info only // if telephony contact is missing if (uiContact.getDescriptor() != null && uiContact.getDescriptor() instanceof MetaContact && telephonyContact == null) { contactPhoneUtil = ContactPhoneUtil.getPhoneUtil((MetaContact) uiContact.getDescriptor()); MetaContact metaContact = (MetaContact) uiContact.getDescriptor(); Iterator<Contact> contacts = metaContact.getContacts(); while (contacts.hasNext()) // && !hasPhone) { Contact contact = contacts.next(); if (!contact.getProtocolProvider().isRegistered()) continue; contactPhoneUtil.addDetailsResponseListener( contact, new DetailsListener(treeNode, callButton, uiContact)); } } // for SourceContact in history that do not support telephony, we // show the button but disabled List<ProtocolProviderService> providers = AccountUtils.getOpSetRegisteredProviders(OperationSetBasicTelephony.class, null, null); if ((telephonyContact != null && telephonyContact.getAddress() != null) || (contactPhoneUtil != null && contactPhoneUtil.isCallEnabled() && providers.size() > 0)) { x += addButton(callButton, ++gridX, x, false); } UIContactDetail videoContact = uiContact.getDefaultContactDetail(OperationSetVideoTelephony.class); if (videoContact != null || (contactPhoneUtil != null && contactPhoneUtil.isVideoCallEnabled())) { x += addButton(callVideoButton, ++gridX, x, false); } UIContactDetail desktopContact = uiContact.getDefaultContactDetail(OperationSetDesktopSharingServer.class); if (desktopContact != null || (contactPhoneUtil != null && contactPhoneUtil.isDesktopSharingEnabled())) { x += addButton(desktopSharingButton, ++gridX, x, false); } // enable add contact button if contact source has indicated // that this is possible if (uiContact.getDescriptor() instanceof SourceContact && uiContact.getDefaultContactDetail(OperationSetPersistentPresence.class) != null && AccountUtils.getOpSetRegisteredProviders( OperationSetPersistentPresence.class, null, null) .size() > 0 && !ConfigurationUtils.isAddContactDisabled()) { x += addButton(addContactButton, ++gridX, x, false); } // The list of the contact actions // we will create a button for every action Collection<SIPCommButton> contactActions = uiContact.getContactCustomActionButtons(); int lastGridX = gridX; if (contactActions != null && contactActions.size() > 0) { lastGridX = initContactActionButtons(contactActions, gridX, x); } else { addLabels(gridX); } if (lastAddedButton != null) setButtonBg(lastAddedButton, lastGridX, true); this.setBounds(0, 0, treeContactList.getWidth(), getPreferredSize().height); }