relativelayout
Class RelativeLayout

java.lang.Object
  extended by relativelayout.RelativeLayout
All Implemented Interfaces:
LayoutManager, LayoutManager2

public class RelativeLayout
extends Object
implements LayoutManager2

The main RelativeLayout class. A LayoutManager implementation that uses Bindings and RelativeConstraints to lay out components.

Author:
Brian Ellis (firebird@andrew.cmu.edu)

Constructor Summary
RelativeLayout()
           
 
Method Summary
 void addLayoutComponent(Component theComp, Object theConstraints)
           
 void addLayoutComponent(String theName, Component theComp)
           
static boolean getDebug()
          Gets the debugging flag.
 float getLayoutAlignmentX(Container theTarget)
           
 float getLayoutAlignmentY(Container theTarget)
           
 void invalidateLayout(Container theTarget)
           
 void layoutContainer(Container theParent)
           
 Dimension maximumLayoutSize(Container theTarget)
           
 Dimension minimumLayoutSize(Container theParent)
           
 Dimension preferredLayoutSize(Container theParent)
          Returns the preferred size of the given container given the components that are to be laid out inside it.
 void removeLayoutComponent(Component theComp)
           
static void setDebug(boolean debug)
          Sets the debugging flag.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RelativeLayout

public RelativeLayout()
Method Detail

setDebug

public static void setDebug(boolean debug)
Sets the debugging flag. If debug is set to true, RelativeLayout will attempt to validate your entire layout every time a constraint is added or changed. This takes a long time, reducing the performance of RelativeLayout by over an order of magnitude on complex layouts, but it will cause any exceptions thrown while laying out the window to be traceable back to the exact line of code that caused the problem. Due to the considerable performance penalty, debugging is off by default.

Parameters:
debug - true if debugging should be turned on, false otherwise

getDebug

public static boolean getDebug()
Gets the debugging flag. See setDebug(boolean) for more information.

Returns:
true if the debugging flag is set, false otherwise.

addLayoutComponent

public void addLayoutComponent(Component theComp,
                               Object theConstraints)
Specified by:
addLayoutComponent in interface LayoutManager2

addLayoutComponent

public void addLayoutComponent(String theName,
                               Component theComp)
Specified by:
addLayoutComponent in interface LayoutManager

getLayoutAlignmentX

public float getLayoutAlignmentX(Container theTarget)
Specified by:
getLayoutAlignmentX in interface LayoutManager2

getLayoutAlignmentY

public float getLayoutAlignmentY(Container theTarget)
Specified by:
getLayoutAlignmentY in interface LayoutManager2

invalidateLayout

public void invalidateLayout(Container theTarget)
Specified by:
invalidateLayout in interface LayoutManager2

layoutContainer

public void layoutContainer(Container theParent)
Specified by:
layoutContainer in interface LayoutManager

maximumLayoutSize

public Dimension maximumLayoutSize(Container theTarget)
Specified by:
maximumLayoutSize in interface LayoutManager2

minimumLayoutSize

public Dimension minimumLayoutSize(Container theParent)
Specified by:
minimumLayoutSize in interface LayoutManager

preferredLayoutSize

public Dimension preferredLayoutSize(Container theParent)
Returns the preferred size of the given container given the components that are to be laid out inside it. This method is called when a container using a RelativeLayout is packed using the Window.pack() method.

Since RelativeLayout is different from other layout managers in that the size of the window determines the size of the controls instead of vice versa, the behavior of this method (and therefore of the Window.pack() method of a window that uses a RelativeLayout) is a little complicated. If the window has dynamically sized components in it (that is, anything whose size depends on the size of the window), the window will be "maximized" -- that is, it will be made as big as possible on the screen. If, however, the window does not have dynamically sized components (that is, no controls resize if you resize the window), then the window will be sized to fit its contents precisely. This will work even if there are controls anchored to the right or bottom of the window, but if there are, the window may be larger than desired in some cases.

Note that due to the complexity of adding center-aligned components into the mix, the layout will not take into account components that are center-aligned in the window. If such components exist, you may need to manually set the size of the window instead of, or in addition to, calling Window.pack().

Specified by:
preferredLayoutSize in interface LayoutManager
See Also:
LayoutManager.preferredLayoutSize(java.awt.Container)

removeLayoutComponent

public void removeLayoutComponent(Component theComp)
Specified by:
removeLayoutComponent in interface LayoutManager