From 42ef51a263dcb1bf85bd928d91c2141a0a720f8d Mon Sep 17 00:00:00 2001
From: Lyubomir Marinov <lyubomir.marinov@jitsi.org>
Date: Wed, 25 Jul 2012 22:05:56 +0000
Subject: [PATCH] - Fixes the horizontal gap between multiple videos in a call.
 It used to appear different between the different columns and caused videos
 with equal aspect ratios to appear with unequal heights. - Tries to prevent a
 deadlock in UI-related code upon hanging up a call. It appeared as if the
 camera wouldn't get closed. - Fixes a NullPointerException.

---
 src/org/jitsi/util/swing/VideoLayout.java | 35 +++++++++++++++--------
 1 file changed, 23 insertions(+), 12 deletions(-)

diff --git a/src/org/jitsi/util/swing/VideoLayout.java b/src/org/jitsi/util/swing/VideoLayout.java
index 3ff9c2b7..6d2818da 100644
--- a/src/org/jitsi/util/swing/VideoLayout.java
+++ b/src/org/jitsi/util/swing/VideoLayout.java
@@ -42,6 +42,12 @@ public class VideoLayout
      */
     public static final String EAST_REMOTE = "EAST_REMOTE";
 
+    /**
+     * The horizontal gap between the <tt>Component</tt> being laid out by
+     * <tt>VideoLayout</tt>.
+     */
+    private static final int HGAP = 10;
+
     /**
      * The local video constraint.
      */
@@ -229,13 +235,9 @@ public void layoutContainer(Container parent)
             remotes = this.remotes;
 
         int remoteCount = remotes.size();
-
-        // We need to reduce parent size in order to fit also the space we've
-        // left between videos.
         Dimension parentSize = parent.getSize();
-        parentSize.width -= remoteCount*10;
 
-        if (remoteCount == 1 && !isConference)
+        if ((remoteCount == 1) && !isConference)
         {
             super.layoutContainer(parent,
                     (local == null)
@@ -245,14 +247,21 @@ public void layoutContainer(Container parent)
         else if (remoteCount > 0)
         {
             int columns = calculateColumnCount(remotes);
-            int rows = (remoteCount + columns - 1) / columns;
+            int columnsMinus1 = columns - 1;
+            int rows = (remoteCount + columnsMinus1) / columns;
             Rectangle bounds
                 = new Rectangle(
                         0,
                         0,
-                        parentSize.width / columns,
+                        /*
+                         * HGAP is the horizontal gap between the Components
+                         * being laid out by this VideoLayout so the number of
+                         * HGAPs will be with one less than the number of
+                         * columns and that horizontal space cannot be allocated
+                         * to the bounds of the Components.
+                         */
+                        (parentSize.width - (columnsMinus1 * HGAP)) / columns,
                         parentSize.height / rows);
-            int columnsMinus1 = columns - 1;
             int i = 0;
 
             for (Component remote : remotes)
@@ -261,12 +270,14 @@ else if (remoteCount > 0)
                  * We want the remote videos ordered from right to left so that
                  * the local video does not cover a remote video when possible.
                  */
-                bounds.x = (columnsMinus1 - (i % columns)) * bounds.width;
+                /*
+                 * We account for the HGAP between the Components being laid out
+                 * by this VideoLayout.
+                 */
+                bounds.x
+                    = (columnsMinus1 - (i % columns)) * (bounds.width + HGAP);
                 bounds.y = (i / columns) * bounds.height;
 
-                if (bounds.x > 0)
-                    bounds.x += ((columns - (i%columns))*10);
-
                 super.layoutComponent(
                         remote,
                         bounds,
-- 
GitLab