edu.cmu.relativelayout
Class BindingFactory

java.lang.Object
  extended by edu.cmu.relativelayout.BindingFactory

public class BindingFactory
extends Object

A factory for quickly creating Bindings to lay out simple interfaces. When you create a BindingFactory, you can set top, left, bottom, and right margins, as well as horizontal and vertical spacing for controls. When you subsequently ask the BindingFactory for Bindings, it uses this information to generate them.

Author:
Brian Ellis (phoenix1701@gmail.com)

Constructor Summary
BindingFactory()
          Constructs a BindingFactory with the given margins and spacing.
BindingFactory(int topMargin, int leftMargin, int bottomMargin, int rightMargin, int horizontalSpacing, int verticalSpacing)
          Constructs a BindingFactory with the given margins and spacing.
 
Method Summary
 Binding above(Component fixed)
          Returns a Binding that will place a component above the given fixed component.
 Binding below(Component fixed)
          Returns a Binding that will place a component below the given fixed component.
 Binding bottomAlignedWith(Component fixed)
          Returns a Binding that will align a component's bottom edge to that of the given fixed component.
 Binding bottomEdge()
          Returns a Binding that will place a component just above the bottom edge of its container.
 Binding directBottomEdge()
          Returns a Binding that will place a component directly above the bottom edge of its container.
 Binding directLeftEdge()
          Returns a Binding that will place a component directly to the right of the left edge of its container.
 Binding directlyAbove(Component fixed)
          Returns a Binding that will place a component directly above the given fixed component.
 Binding directlyBelow(Component fixed)
          Returns a Binding that will place a component directly below of the given fixed component.
 Binding directlyLeftOf(Component fixed)
          Returns a Binding that will place a component directly to the left of the given fixed component.
 Binding directlyRightOf(Component fixed)
          Returns a Binding that will place a component directly to the right of the given fixed component.
 Binding directRightEdge()
          Returns a Binding that will place a component directly to the left of the right edge of its container.
 Binding directTopEdge()
          Returns a Binding that will place a component directly below the top edge of its container.
static BindingFactory getBindingFactory()
          This method returns the default instance of BindingFactory.
 int getBottomMargin()
          Returns the current bottom margin of this BindingFactory.
 int getHorizontalSpacing()
          Returns the current horizontal spacing used by this BindingFactory.
 int getLeftMargin()
          Returns the current left margin of this BindingFactory.
 int getRightMargin()
          Returns the current right margin of this BindingFactory.
 int getTopMargin()
          Returns the current top margin of this BindingFactory.
 int getVerticalSpacing()
          Returns the current vertical spacing used by this BindingFactory.
 Binding horizontallyCenterAlignedWith(Component fixed)
          Returns a Binding that will align a component's horizontal center to that of the given fixed component.
 Binding leftAlignedWith(Component fixed)
          Returns a Binding that will align a component's left edge to that of the given fixed component.
 Binding leftEdge()
          Returns a Binding that will place a component just to the right of the left edge of its container.
 Binding leftOf(Component fixed)
          Returns a Binding that will place a component to the left of the given fixed component.
 Binding rightAlignedWith(Component fixed)
          Returns a Binding that will align a component's right edge to that of the given fixed component.
 Binding rightEdge()
          Returns a Binding that will place a component just to the left of the right edge of its container.
 Binding rightOf(Component fixed)
          Returns a Binding that will place a component to the right of the given fixed component.
 void setBottomMargin(int bottomMargin)
          Sets the bottom margin of this BindingFactory.
 void setHorizontalSpacing(int horizontalSpacing)
          Sets the horizontal spacing used by this BindingFactory.
 void setLeftMargin(int leftMargin)
          Sets the left margin of this BindingFactory.
 void setMargin(int topMargin, int leftMargin, int bottomMargin, int rightMargin)
          Sets the margins for this BindingFactory.
 void setRightMargin(int rightMargin)
          Sets the right margin of this BindingFactory.
 void setSpacing(int horizontalSpacing, int verticalSpacing)
          Sets the spacing for the BindingFactory
 void setTopMargin(int topMargin)
          Sets the top margin of this BindingFactory.
 void setVerticalSpacing(int verticalSpacing)
          Sets the vertical spacing used by this BindingFactory.
 Binding topAlign(Component fixed)
          Returns a Binding that will align a component's top edge to that of the given fixed component.
 Binding topEdge()
          Returns a Binding that will place a component just below the top edge of its container.
 Binding verticallyCenterAlignedWith(Component fixed)
          Returns a Binding that will align a component's vertical center to that of the given fixed component.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BindingFactory

public BindingFactory()
Constructs a BindingFactory with the given margins and spacing.


BindingFactory

public BindingFactory(int topMargin,
                      int leftMargin,
                      int bottomMargin,
                      int rightMargin,
                      int horizontalSpacing,
                      int verticalSpacing)
Constructs a BindingFactory with the given margins and spacing.

Parameters:
topMargin - the distance between the top of the container and controls bound using topEdgeBinding()
leftMargin - the distance between the left edge of the container and controls bound using leftEdgeBinding()
bottomMargin - the distance between the bottom of the container and controls bound using bottomEdgeBinding()
rightMargin - the distance between the right edge of the container and controls bound using rightEdgeBinding()
horizontalSpacing - the distance between controls bound together using leftOf() or rightOf()
verticalSpacing - the distance between controls bound together using above() or below()
Method Detail

getBindingFactory

public static BindingFactory getBindingFactory()
This method returns the default instance of BindingFactory. This instance uses the default margins and spacing by default, and can be referenced when you do not wish to construct a BindingFactory specifically for your use.


above

public Binding above(Component fixed)
Returns a Binding that will place a component above the given fixed component.

Parameters:
fixed - the component to place this one next to
Returns:
the Binding

below

public Binding below(Component fixed)
Returns a Binding that will place a component below the given fixed component.

Parameters:
fixed - the component to place this one next to
Returns:
the Binding

bottomAlignedWith

public Binding bottomAlignedWith(Component fixed)
Returns a Binding that will align a component's bottom edge to that of the given fixed component.

Parameters:
fixed - the component to align to
Returns:
the Binding

bottomEdge

public Binding bottomEdge()
Returns a Binding that will place a component just above the bottom edge of its container.

Returns:
the Binding

directBottomEdge

public Binding directBottomEdge()
Returns a Binding that will place a component directly above the bottom edge of its container. The difference between this method and bottomEdge() is that this method ignores the margin and puts the component directly against the edge of the container.

Returns:
the Binding

directLeftEdge

public Binding directLeftEdge()
Returns a Binding that will place a component directly to the right of the left edge of its container. The difference between this method and leftEdge() is that this method ignores the margin and puts the component directly against the edge of the container.

Returns:
the Binding

directlyAbove

public Binding directlyAbove(Component fixed)
Returns a Binding that will place a component directly above the given fixed component. The difference between this and above() is that this method ignores the vertical spacing and places the component directly adjacent to (i.e., zero pixels away from) the fixed component.

Parameters:
fixed - the component to place this one next to
Returns:
the Binding

directlyBelow

public Binding directlyBelow(Component fixed)
Returns a Binding that will place a component directly below of the given fixed component. The difference between this and below() is that this method ignores the vertical spacing and places the component directly adjacent to (i.e., zero pixels away from) the fixed component.

Parameters:
fixed - the component to place this one next to
Returns:
the Binding

directlyLeftOf

public Binding directlyLeftOf(Component fixed)
Returns a Binding that will place a component directly to the left of the given fixed component. The difference between this and leftOf() is that this method ignores the horizontal spacing and places the component directly adjacent to (i.e., zero pixels away from) the fixed component.

Parameters:
fixed - the component to place this one next to
Returns:
the Binding

directlyRightOf

public Binding directlyRightOf(Component fixed)
Returns a Binding that will place a component directly to the right of the given fixed component. The difference between this and rightOf() is that this method ignores the horizontal spacing and places the component directly adjacent to (i.e., zero pixels away from) the fixed component.

Parameters:
fixed - the component to place this one next to
Returns:
the Binding

directRightEdge

public Binding directRightEdge()
Returns a Binding that will place a component directly to the left of the right edge of its container. The difference between this method and rightEdge() is that this method ignores the margin and puts the component directly against the edge of the container.

Returns:
the Binding

directTopEdge

public Binding directTopEdge()
Returns a Binding that will place a component directly below the top edge of its container. The difference between this method and topEdge() is that this method ignores the margin and puts the component directly against the edge of the container.

Returns:
the Binding

getBottomMargin

public int getBottomMargin()
Returns the current bottom margin of this BindingFactory.

Returns:
the margin

getHorizontalSpacing

public int getHorizontalSpacing()
Returns the current horizontal spacing used by this BindingFactory.

Returns:
the horizontal spacing

getLeftMargin

public int getLeftMargin()
Returns the current left margin of this BindingFactory.

Returns:
the margin

getRightMargin

public int getRightMargin()
Returns the current right margin of this BindingFactory.

Returns:
the margin

getTopMargin

public int getTopMargin()
Returns the current top margin of this BindingFactory.

Returns:
the margin

getVerticalSpacing

public int getVerticalSpacing()
Returns the current vertical spacing used by this BindingFactory.

Returns:
the vertical spacing

horizontallyCenterAlignedWith

public Binding horizontallyCenterAlignedWith(Component fixed)
Returns a Binding that will align a component's horizontal center to that of the given fixed component. This can be used to align one component's center directly above or below another's.

Parameters:
fixed - the component to align to
Returns:
the Binding

leftAlignedWith

public Binding leftAlignedWith(Component fixed)
Returns a Binding that will align a component's left edge to that of the given fixed component.

Parameters:
fixed - the component to align to
Returns:
the Binding

leftEdge

public Binding leftEdge()
Returns a Binding that will place a component just to the right of the left edge of its container.

Returns:
the Binding

leftOf

public Binding leftOf(Component fixed)
Returns a Binding that will place a component to the left of the given fixed component.

Parameters:
fixed - the component to place this one next to
Returns:
the Binding

rightAlignedWith

public Binding rightAlignedWith(Component fixed)
Returns a Binding that will align a component's right edge to that of the given fixed component.

Parameters:
fixed - the component to align to
Returns:
the Binding

rightEdge

public Binding rightEdge()
Returns a Binding that will place a component just to the left of the right edge of its container.

Returns:
the Binding

rightOf

public Binding rightOf(Component fixed)
Returns a Binding that will place a component to the right of the given fixed component.

Parameters:
fixed - the component to place this one next to
Returns:
the Binding

setBottomMargin

public void setBottomMargin(int bottomMargin)
Sets the bottom margin of this BindingFactory. Subsequently created Bindings will use this margin.

Parameters:
bottomMargin - the new margin

setHorizontalSpacing

public void setHorizontalSpacing(int horizontalSpacing)
Sets the horizontal spacing used by this BindingFactory. Subsequently created Bindings will use this spacing.

Parameters:
horizontalSpacing - the new spacing

setLeftMargin

public void setLeftMargin(int leftMargin)
Sets the left margin of this BindingFactory. Subsequently created Bindings will use this margin.

Parameters:
leftMargin - the new margin

setMargin

public void setMargin(int topMargin,
                      int leftMargin,
                      int bottomMargin,
                      int rightMargin)
Sets the margins for this BindingFactory.

Parameters:
topMargin - the distance between the top of the container and controls bound using topEdgeBinding()
leftMargin - the distance between the left edge of the container and controls bound using leftEdgeBinding()
bottomMargin - the distance between the bottom of the container and controls bound using bottomEdgeBinding()
rightMargin - the distance between the right edge of the container and controls bound using rightEdgeBinding()

setRightMargin

public void setRightMargin(int rightMargin)
Sets the right margin of this BindingFactory. Subsequently created Bindings will use this margin.

Parameters:
rightMargin - the new margin

setSpacing

public void setSpacing(int horizontalSpacing,
                       int verticalSpacing)
Sets the spacing for the BindingFactory

Parameters:
horizontalSpacing - the distance between controls bound together using leftOf() or rightOf()
verticalSpacing - the distance between controls bound together using above() or below()

setTopMargin

public void setTopMargin(int topMargin)
Sets the top margin of this BindingFactory. Subsequently created Bindings will use this margin.

Parameters:
topMargin - the new margin

setVerticalSpacing

public void setVerticalSpacing(int verticalSpacing)
Sets the vertical spacing used by this BindingFactory. Subsequently created Bindings will use this spacing.

Parameters:
verticalSpacing - the new spacing

topAlign

public Binding topAlign(Component fixed)
Returns a Binding that will align a component's top edge to that of the given fixed component.

Parameters:
fixed - the component to align to
Returns:
the Binding

topEdge

public Binding topEdge()
Returns a Binding that will place a component just below the top edge of its container.

Returns:
the Binding

verticallyCenterAlignedWith

public Binding verticallyCenterAlignedWith(Component fixed)
Returns a Binding that will align a component's vertical center to that of the given fixed component. This can be used to align one component's center directly to the left or right of another's.

Parameters:
fixed - the component to align to
Returns:
the Binding