FileDocCategorySizeDatePackage
OverlayLayout.javaAPI DocJava SE 6 API8507Tue Jun 10 00:26:40 BST 2008javax.swing

OverlayLayout

public class OverlayLayout extends Object implements Serializable, LayoutManager2
A layout manager to arrange components over the top of each other. The requested size of the container will be the largest requested size of the children, taking alignment needs into consideration. The alignment is based upon what is needed to properly fit the children in the allocation area. The children will be placed such that their alignment points are all on top of each other.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see {@link java.beans.XMLEncoder}.

version
1.29 04/10/06
author
Timothy Prinzing

Fields Summary
private Container
target
private SizeRequirements[]
xChildren
private SizeRequirements[]
yChildren
private SizeRequirements
xTotal
private SizeRequirements
yTotal
Constructors Summary
public OverlayLayout(Container target)
Constructs a layout manager that performs overlay arrangement of the children. The layout manager created is dedicated to the given container.

param
target the container to do layout against

	this.target = target;
    
Methods Summary
public voidaddLayoutComponent(java.lang.String name, java.awt.Component comp)
Adds the specified component to the layout. Used by this class to know when to invalidate layout.

param
name the name of the component
param
comp the the component to be added

        invalidateLayout(comp.getParent());
    
public voidaddLayoutComponent(java.awt.Component comp, java.lang.Object constraints)
Adds the specified component to the layout, using the specified constraint object. Used by this class to know when to invalidate layout.

param
comp the component to be added
param
constraints where/how the component is added to the layout.

        invalidateLayout(comp.getParent());
    
voidcheckContainer(java.awt.Container target)

	if (this.target != target) {
	    throw new AWTError("OverlayLayout can't be shared");
	}
    
voidcheckRequests()

	if (xChildren == null || yChildren == null) {
	    // The requests have been invalidated... recalculate
	    // the request information.
	    int n = target.getComponentCount();
	    xChildren = new SizeRequirements[n];
	    yChildren = new SizeRequirements[n];
	    for (int i = 0; i < n; i++) {
		Component c = target.getComponent(i);
		Dimension min = c.getMinimumSize();
		Dimension typ = c.getPreferredSize();
		Dimension max = c.getMaximumSize();
		xChildren[i] = new SizeRequirements(min.width, typ.width, 
						    max.width, 
						    c.getAlignmentX());
		yChildren[i] = new SizeRequirements(min.height, typ.height, 
						    max.height, 
						    c.getAlignmentY());
	    }
	    
	    xTotal = SizeRequirements.getAlignedSizeRequirements(xChildren);
	    yTotal = SizeRequirements.getAlignedSizeRequirements(yChildren);
	}
    
public floatgetLayoutAlignmentX(java.awt.Container target)
Returns the alignment along the x axis for the container.

param
target the container
return
the alignment >= 0.0f && <= 1.0f

	checkContainer(target);
	checkRequests();
	return xTotal.alignment;
    
public floatgetLayoutAlignmentY(java.awt.Container target)
Returns the alignment along the y axis for the container.

param
target the container
return
the alignment >= 0.0f && <= 1.0f

	checkContainer(target);
	checkRequests();
	return yTotal.alignment;
    
public final java.awt.ContainergetTarget()
Returns the container that uses this layout manager.

return
the container that uses this layout manager
since
1.6

        return this.target;
    
public voidinvalidateLayout(java.awt.Container target)
Indicates a child has changed its layout related information, which causes any cached calculations to be flushed.

param
target the container

	checkContainer(target);
	xChildren = null;
	yChildren = null;
	xTotal = null;
	yTotal = null;
    
public voidlayoutContainer(java.awt.Container target)
Called by the AWT when the specified container needs to be laid out.

param
target the container to lay out
exception
AWTError if the target isn't the container specified to the constructor

	checkContainer(target);
	checkRequests();
	
	int nChildren = target.getComponentCount();
	int[] xOffsets = new int[nChildren];
	int[] xSpans = new int[nChildren];
	int[] yOffsets = new int[nChildren];
	int[] ySpans = new int[nChildren];

	// determine the child placements
	Dimension alloc = target.getSize();
	Insets in = target.getInsets();
	alloc.width -= in.left + in.right;
	alloc.height -= in.top + in.bottom;
	SizeRequirements.calculateAlignedPositions(alloc.width, xTotal, 
						   xChildren, xOffsets,
						   xSpans);
	SizeRequirements.calculateAlignedPositions(alloc.height, yTotal,
						   yChildren, yOffsets,
						   ySpans);

	// flush changes to the container
	for (int i = 0; i < nChildren; i++) {
	    Component c = target.getComponent(i);
	    c.setBounds(in.left + xOffsets[i], in.top + yOffsets[i],
			xSpans[i], ySpans[i]);
	}
    
public java.awt.DimensionmaximumLayoutSize(java.awt.Container target)
Returns the maximum dimensions needed to lay out the components contained in the specified target container. Recomputes the layout if it has been invalidated, and factors in the inset setting returned by getInset.

param
target the component that needs to be laid out
return
a Dimension object containing the maximum dimensions
see
#preferredLayoutSize

	checkContainer(target);
	checkRequests();

	Dimension size = new Dimension(xTotal.maximum, yTotal.maximum);
	Insets insets = target.getInsets();
	size.width += insets.left + insets.right;
	size.height += insets.top + insets.bottom;
	return size;
    
public java.awt.DimensionminimumLayoutSize(java.awt.Container target)
Returns the minimum dimensions needed to lay out the components contained in the specified target container. Recomputes the layout if it has been invalidated, and factors in the current inset setting.

param
target the component which needs to be laid out
return
a Dimension object containing the minimum dimensions
see
#preferredLayoutSize

	checkContainer(target);
	checkRequests();

	Dimension size = new Dimension(xTotal.minimum, yTotal.minimum);
	Insets insets = target.getInsets();
	size.width += insets.left + insets.right;
	size.height += insets.top + insets.bottom;
	return size;
    
public java.awt.DimensionpreferredLayoutSize(java.awt.Container target)
Returns the preferred dimensions for this layout given the components in the specified target container. Recomputes the layout if it has been invalidated. Factors in the current inset setting returned by getInsets().

param
target the component which needs to be laid out
return
a Dimension object containing the preferred dimensions
see
#minimumLayoutSize

	checkContainer(target);
	checkRequests();

	Dimension size = new Dimension(xTotal.preferred, yTotal.preferred);
	Insets insets = target.getInsets();
	size.width += insets.left + insets.right;
	size.height += insets.top + insets.bottom;
	return size;
    
public voidremoveLayoutComponent(java.awt.Component comp)
Removes the specified component from the layout. Used by this class to know when to invalidate layout.

param
comp the component to remove

        invalidateLayout(comp.getParent());