aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDamian Minkov <damencho@jitsi.org>2014-06-04 18:24:30 +0300
committerDamian Minkov <damencho@jitsi.org>2014-06-04 18:24:30 +0300
commitf7ce39c32fd1e95af8fc51d164937dbb03cf8eb6 (patch)
tree4f609e1d0455415a66767745fbddc662598f6c21 /src
parent4ee2a0d18f4747042ed2550b95e535ca1aa34099 (diff)
downloadjitsi-f7ce39c32fd1e95af8fc51d164937dbb03cf8eb6.zip
jitsi-f7ce39c32fd1e95af8fc51d164937dbb03cf8eb6.tar.gz
jitsi-f7ce39c32fd1e95af8fc51d164937dbb03cf8eb6.tar.bz2
Calculates height of the components in the cell when rendering contacts and groups in the contactlist to respect OS font size settings.
Diffstat (limited to 'src')
-rw-r--r--src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListTreeCellRenderer.java80
-rw-r--r--src/net/java/sip/communicator/plugin/desktoputil/ComponentUtils.java16
2 files changed, 91 insertions, 5 deletions
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 17974c7..ea663cf 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
@@ -117,6 +117,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.
*/
private static final Image BUTTON_SEPARATOR_IMG
@@ -579,6 +594,23 @@ public class ContactListTreeCellRenderer
}
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 @@ public class ContactListTreeCellRenderer
(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 class ContactListTreeCellRenderer
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 @@ public class ContactListTreeCellRenderer
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 8cb945d..bea6d68 100644
--- a/src/net/java/sip/communicator/plugin/desktoputil/ComponentUtils.java
+++ b/src/net/java/sip/communicator/plugin/desktoputil/ComponentUtils.java
@@ -55,6 +55,22 @@ public class ComponentUtils
}
/**
+ * 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.
*
* @param text the string to measure