diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListTreeCellRenderer.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListTreeCellRenderer.java index 17974c762..ea663cf02 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListTreeCellRenderer.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListTreeCellRenderer.java @@ -116,6 +116,21 @@ public class ContactListTreeCellRenderer */ private static final int V_GAP = 3; + /** + * The calculated preferred height of a selected contact node. + */ + private Integer preferredSelectedContactNodeHeight = null; + + /** + * The calculated preferred height of a non selected contact node. + */ + private Integer preferredNotSelectedContactNodeHeight = null; + + /** + * The calculated preferred height of a group node. + */ + private Integer preferredGroupNodeHeight = null; + /** * The separator image for the button toolbar. */ @@ -579,6 +594,23 @@ && isMobile((MetaContact)contact.getDescriptor())) } setToolTipText(contact.getDescriptor().toString()); + + // lets calculate the height of contact node, if not done already + if(preferredNotSelectedContactNodeHeight == null) + { + preferredNotSelectedContactNodeHeight + = ComponentUtils.getStringHeight(nameLabel) + + V_GAP + + ComponentUtils.getStringHeight(displayDetailsLabel); + } + + if(preferredSelectedContactNodeHeight == null && isSelected) + { + preferredSelectedContactNodeHeight = + preferredNotSelectedContactNodeHeight + + V_GAP + + chatButton.getHeight(); + } } else if (value instanceof GroupNode) { @@ -659,6 +691,13 @@ else if (value instanceof GroupNode) (groupItemDescriptor != null) ? groupItemDescriptor.toString() : groupItem.getDisplayName()); + + // lets calculate group node height, if not done already + if(preferredGroupNodeHeight == null) + { + preferredGroupNodeHeight = + ComponentUtils.getStringHeight(nameLabel); + } } return this; @@ -794,11 +833,29 @@ public Dimension getPreferredSize() if (preferredHeight > 0) preferredSize.height = preferredHeight; else if (contact instanceof ShowMoreContact) - preferredSize.height = 20; + { + // will reuse preferredGroupNodeHeight if available + // as it is the same height (one line text) + if(preferredGroupNodeHeight != null) + preferredSize.height = preferredGroupNodeHeight; + else + preferredSize.height = 20; + } else if (isSelected && treeContactList.isContactButtonsVisible()) - preferredSize.height = 70; + { + if(preferredSelectedContactNodeHeight != null) + preferredSize.height = preferredSelectedContactNodeHeight; + else + preferredSize.height = 70; + } else - preferredSize.height = 35; + { + if(preferredNotSelectedContactNodeHeight != null) + preferredSize.height + = preferredNotSelectedContactNodeHeight; + else + preferredSize.height = 35; + } } else if (treeNode instanceof GroupNode) { @@ -810,11 +867,24 @@ else if (treeNode instanceof GroupNode) if (isSelected && customActionButtonsUIGroup != null && !customActionButtonsUIGroup.isEmpty()) - preferredSize.height = 70; + { + if(preferredGroupNodeHeight != null) + preferredSize.height = preferredGroupNodeHeight + + customActionButtonsUIGroup.size() + * customActionButtonsUIGroup.get(0).getHeight() + + V_GAP; + else + preferredSize.height = 70; + } else if (preferredHeight > 0) preferredSize.height = preferredHeight; else - preferredSize.height = 20; + { + if(preferredGroupNodeHeight != null) + preferredSize.height = preferredGroupNodeHeight; + else + preferredSize.height = 20; + } } return preferredSize; diff --git a/src/net/java/sip/communicator/plugin/desktoputil/ComponentUtils.java b/src/net/java/sip/communicator/plugin/desktoputil/ComponentUtils.java index 8cb945d1b..bea6d68fd 100644 --- a/src/net/java/sip/communicator/plugin/desktoputil/ComponentUtils.java +++ b/src/net/java/sip/communicator/plugin/desktoputil/ComponentUtils.java @@ -54,6 +54,22 @@ public static Dimension getStringSize(Component c, String text) return new Dimension(adv+2, hgt+2); } + /** + * Returns the height of the given component. + * + * @param c the component where the text is contained + * @return the height of the text + */ + public static int getStringHeight(Component c) + { + // get metrics from the graphics + FontMetrics metrics = c.getFontMetrics(c.getFont()); + // get the height of a line of text in this font and render context + int hgt = metrics.getHeight(); + // calculate the height of a box to hold the text with some padding. + return hgt+2; + } + /** * Returns the bounds of the given string. *