edu.neu.ccs.gui
Class AbsoluteLayout

java.lang.Object
  extended byedu.neu.ccs.gui.AbsoluteLayout
All Implemented Interfaces:
LayoutManager, LayoutManager2

public class AbsoluteLayout
extends Object
implements LayoutManager2

Layout manager allowing child components of a container to control their own locations and sizes.

In version 2.3.5, a serious bug was fixed. In the possess of fixing the bug, the following policy about the determination of Component size was implemented.

If a Component is actually a Container then its size is computed by calling getPreferredSize and any existing size set by setSize is ignored. This permits objects that extend Container to effectively change their size by changing the return value of getPreferredSize and this change is not affected by an obsolete value set earlier by setSize.

For a general Component, the size is set to be the maximum of getSize and getMinimumSize. This approach was a design choice based on the fact that for many older Java Component objects people often directly set the size and do not bother with the minimum size. This means that the resulting size set in this layout manager is at least a big as both the actual size set earlier and the minimum size.

The size policy is consistent with the effort in JPT to use getPreferredSize (which is algorithmic) rather than rely on size settings that may become obsolete for dynamically changing components.

Since:
1.1
Version:
2.3.5

Field Summary
protected  Vector components
          Child components of the parent container.
 
Constructor Summary
AbsoluteLayout()
           
 
Method Summary
 void addLayoutComponent(Component component, Object constraints)
          Adds the given component to this layout with the given constraints.
 void addLayoutComponent(String name, Component component)
          Adds the given component to this layout with the given name.
 float getLayoutAlignmentX(Container target)
          Returns the layout alignment along the x-axis.
 float getLayoutAlignmentY(Container target)
          Returns the layout alignment along the y-axis.
static Rectangle getPreferredBounds(Component c)
          If the component is a container then returns bounds where the width and height are replaced by the width and height of the preferred size.
 void invalidateLayout(Container parent)
          This method does nothing, as this layout does not cache information about its parent container.
 void layoutContainer(Container parent)
          Lays out the container.
 Dimension maximumLayoutSize(Container parent)
          Returns the maximum size required to layout the components contained in the parent container.
 Dimension minimumLayoutSize(Container parent)
          Returns the minimum size required to layout the components contained in the parent container.
 Dimension preferredLayoutSize(Container parent)
          Returns the preferred size required to layout the components contained in the parent container.
 void removeLayoutComponent(Component component)
          Removes the given component from this layout.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

components

protected Vector components
Child components of the parent container.

Constructor Detail

AbsoluteLayout

public AbsoluteLayout()
Method Detail

addLayoutComponent

public void addLayoutComponent(String name,
                               Component component)

Adds the given component to this layout with the given name.

Ignores a null component.

Ignores the name parameter.

Specified by:
addLayoutComponent in interface LayoutManager
Parameters:
name - the name for the component
component - the component to be added
See Also:
addLayoutComponent(Component, Object)

addLayoutComponent

public void addLayoutComponent(Component component,
                               Object constraints)

Adds the given component to this layout with the given constraints.

Ignores a null component.

Ignores the constraints parameter since the position is determined by getLocation and the size is computed by the policy described in the introduction to the class.

Specified by:
addLayoutComponent in interface LayoutManager2
Parameters:
component - the component to be added
constraints - the constraints applied to the component
See Also:
addLayoutComponent(String, Component)

removeLayoutComponent

public void removeLayoutComponent(Component component)

Removes the given component from this layout.

Specified by:
removeLayoutComponent in interface LayoutManager
Parameters:
component - the component to be removed

minimumLayoutSize

public Dimension minimumLayoutSize(Container parent)

Returns the minimum size required to layout the components contained in the parent container. This will be the same as the preferred layout size.

Specified by:
minimumLayoutSize in interface LayoutManager
Parameters:
parent - the parent container
See Also:
preferredLayoutSize(Container), maximumLayoutSize(Container)

preferredLayoutSize

public Dimension preferredLayoutSize(Container parent)

Returns the preferred size required to layout the components contained in the parent container.

This method computes component size by the policy described in the introduction to the class.

Specified by:
preferredLayoutSize in interface LayoutManager
Parameters:
parent - the parent container
See Also:
minimumLayoutSize(Container), maximumLayoutSize(Container)

maximumLayoutSize

public Dimension maximumLayoutSize(Container parent)

Returns the maximum size required to layout the components contained in the parent container. This will be the same as the preferred layout size.

Specified by:
maximumLayoutSize in interface LayoutManager2
Parameters:
parent - the parent container
See Also:
minimumLayoutSize(Container), preferredLayoutSize(Container)

layoutContainer

public void layoutContainer(Container parent)

Lays out the container.

This implementation ensures that components have a size equal to their preferred size if that value is available or at least as big as their minimum size otherwise.

This counteracts a bug (feature?) of Java that some components have an initial size of (0,0) even when their preferred size is not zero.

The location (upper-left) of each component is left as is.

Specified by:
layoutContainer in interface LayoutManager
Parameters:
parent - the parent container

getLayoutAlignmentY

public float getLayoutAlignmentY(Container target)
Returns the layout alignment along the y-axis.

Specified by:
getLayoutAlignmentY in interface LayoutManager2
Parameters:
target - the target container
See Also:
getLayoutAlignmentX(Container)

getLayoutAlignmentX

public float getLayoutAlignmentX(Container target)
Returns the layout alignment along the x-axis.

Specified by:
getLayoutAlignmentX in interface LayoutManager2
Parameters:
target - the target container
See Also:
getLayoutAlignmentY(Container)

invalidateLayout

public void invalidateLayout(Container parent)
This method does nothing, as this layout does not cache information about its parent container.

Specified by:
invalidateLayout in interface LayoutManager2
Parameters:
parent - the parent container

getPreferredBounds

public static Rectangle getPreferredBounds(Component c)

If the component is a container then returns bounds where the width and height are replaced by the width and height of the preferred size. The current size is ignored in this case.

Otherwise, returns the maximum of the current size and the minimum size.

The location is set to the value returned by the method getLocation

.

This method is used to implement the size policy described in the introduction to the class.

Parameters:
c - the component whose preferred bounds are required