Bug 161902 [JFace] Enhancements to GridLayoutFactory.margins
This enhancement requests the following: 1. Rename the new GridLayoutFactory.margins(int,int,int,int) to GridLayoutFactory.extendedMargins(int,int,int,int) 2. Add a GridLayoutFactory.extendedMargins(Rectangle) method that accepts a difference rectangle. 3. Add static methods to Geometry in order to easily construct difference rectangles. Why? 1. We should not use overloaded methods in GridLayoutFactory unless they really do set the same thing. Since the four-argument margins(...) method and the two-argument margins(...) method set independent values, we should give them different names or clients will expect a call to margins(int, int, int, int) to overwrite a previous call to margins(int, int). 2. All methods on GridLayoutFactory and GridDataFactory should have vector initializers, so that clients can store and reuse standard margin settings in a single variable. 3. Vector initializers are only a convenience if there is a convenient way to construct the vector.
bundles/org.eclipse.jface/src/org/eclipse/jface/util/Geometry.java
result |= SWT.LEFT;
        } else if (toTest.x >= boundary.x + boundary.width) {
            result |= SWT.RIGHT;
        }
        if (toTest.y < boundary.y) {
            result |= SWT.TOP;
        } else if (toTest.y >= boundary.y + boundary.height) {
            result |= SWT.BOTTOM;
        }
        return result;
    }
    /**
     * Returns the distance from the point to the nearest edge of the given
     * rectangle. Returns negative values if the point lies outside the rectangle.
     * 
     * @param boundary rectangle to test
     * @param toTest point to test
     * @return the distance between the given point and the nearest edge of the rectangle.
     * Returns positive values for points inside the rectangle and negative values for points
     * outside the rectangle.
     * @since 3.1
     */
    public static int getDistanceFrom(Rectangle boundary, Point toTest) {
        int side = getClosestSide(boundary, toTest);
        return getDistanceFromEdge(boundary, toTest, side);
    }
    
    /**
     * Returns the edge of the given rectangle is closest to the given
     * point.