FileDocCategorySizeDatePackage
CornerLayout.javaAPI DocExample9750Mon Mar 24 02:03:54 GMT 1997None

CornerLayout

public class CornerLayout extends Object implements LayoutManager
An 'educational' layout. CornerLayout will layout a container using members named "Northeast", "Northwest", "Southeast", "Southwest", and "Center". The "Northeast", "Northwest", "Southeast" and "Soutwest" components get sized relative to the adjacent corner's components and the constraints of the container's size. The "Center" component will get any space left over.

Fields Summary
int
hgap
int
vgap
int
mode
public static final int
NORMAL
public static final int
FULL_WIDTH
public static final int
FULL_HEIGHT
Component
northwest
Component
southwest
Component
northeast
Component
southeast
Component
center
Constructors Summary
public CornerLayout()
Constructs a new CornerLayout.


             
      
        this (0, 0, CornerLayout.NORMAL);
    
public CornerLayout(int mode)

        this (0, 0, mode);
    
public CornerLayout(int hgap, int vgap)

        this (hgap, vgap, CornerLayout.NORMAL);
    
public CornerLayout(int hgap, int vgap, int mode)

	this.hgap = hgap;
	this.vgap = vgap;
        this.mode = mode;
    
Methods Summary
public voidaddLayoutComponent(java.lang.String name, java.awt.Component comp)

	if ("Center".equals(name)) {
	    center = comp;
        } else if ("Northwest".equals(name)) {
            northwest = comp;
        } else if ("Southeast".equals(name)) {
            southeast = comp;
        } else if ("Northeast".equals(name)) {
            northeast = comp;
        } else if ("Southwest".equals(name)) {
            southwest = comp;
	}
    
public voidlayoutContainer(java.awt.Container target)

	Insets insets = target.insets();
	int top = insets.top;
        int bottom = target.size().height - insets.bottom;
	int left = insets.left;
        int right = target.size().width - insets.right;

        Dimension northeastDim = new Dimension (0,0);
        Dimension northwestDim = new Dimension (0,0);
        Dimension southeastDim = new Dimension (0,0);
        Dimension southwestDim = new Dimension (0,0);
        Dimension centerDim    = new Dimension (0,0);

        Point topLeftCorner, topRightCorner, bottomLeftCorner,
                        bottomRightCorner;

        if ((northeast != null) && northeast.isVisible()) {
            northeastDim = northeast.preferredSize();
	}
        if ((southwest != null) && southwest.isVisible()) {
            southwestDim = southwest.preferredSize();
	}
        if ((center != null) && center.isVisible()) {
            centerDim = center.preferredSize();
	}
        if ((northwest != null) && northwest.isVisible()) {
            northwestDim = northwest.preferredSize();
	}
        if ((southeast != null) && southeast.isVisible()) {
            southeastDim = southeast.preferredSize();
	}

        topLeftCorner = new Point (left +
                          Math.max (northwestDim.width, southwestDim.width),
                                top + 
                          Math.max (northwestDim.height, northeastDim.height));
        topRightCorner = new Point (right -
                          Math.max (northeastDim.width, southeastDim.width),
                                top +
                          Math.max (northwestDim.height, northeastDim.height));
        bottomLeftCorner = new Point (left + 
                          Math.max (northwestDim.width, southwestDim.width),
                                bottom - 
                          Math.max (southwestDim.height, southeastDim.height));
        bottomRightCorner = new Point (right  -
                          Math.max (northeastDim.width, southeastDim.width),
                                bottom - 
                          Math.max (southwestDim.height, southeastDim.height));

        if ((northwest != null) && northwest.isVisible()) {
            northwest.reshape(left, top,
                                left + topLeftCorner.x,
                                top + topLeftCorner.y);
	}

        if ((southwest != null) && southwest.isVisible()) {
            southwest.reshape(left, bottomLeftCorner.y,
                                bottomLeftCorner.x - left,
                                bottom - bottomLeftCorner.y);
	}

        if ((southeast != null) && southeast.isVisible()) {
            southeast.reshape(bottomRightCorner.x,
                        bottomRightCorner.y,
                        right - bottomRightCorner.x,
                        bottom - bottomRightCorner.y);
	}

        if ((northeast != null) && northeast.isVisible()) {
            northeast.reshape(topRightCorner.x, top,
                                right - topRightCorner.x,
                                topRightCorner.y);
	}

        if ((center != null) && center.isVisible()) {
            int x = topLeftCorner.x + hgap;
            int y = topLeftCorner.y + vgap;
            int width = bottomRightCorner.x - topLeftCorner.x - hgap * 2;
            int height = bottomRightCorner.y - topLeftCorner.y - vgap * 2;

            if (mode == CornerLayout.FULL_WIDTH) {

                x = left;
                width = right - left;

            } else if (mode == CornerLayout.FULL_HEIGHT) {

                y = top;
                height = bottom - top;

            }

            center.reshape(x, y, width, height);

	}
    
public java.awt.DimensionminimumLayoutSize(java.awt.Container target)

	Dimension dim = new Dimension(0, 0);

        Dimension northeastDim = new Dimension (0,0);
        Dimension northwestDim = new Dimension (0,0);
        Dimension southeastDim = new Dimension (0,0);
        Dimension southwestDim = new Dimension (0,0);
        Dimension centerDim    = new Dimension (0,0);

        if ((northeast != null) && northeast.isVisible()) {
            northeastDim = northeast.minimumSize();
	}
        if ((southwest != null) && southwest.isVisible()) {
            southwestDim = southwest.minimumSize();
	}
        if ((center != null) && center.isVisible()) {
            centerDim = center.minimumSize();
	}
        if ((northwest != null) && northwest.isVisible()) {
            northwestDim = northwest.minimumSize();
	}
        if ((southeast != null) && southeast.isVisible()) {
            southeastDim = southeast.minimumSize();
	}

        dim.width = Math.max (northwestDim.width, southwestDim.width) +
                        hgap + centerDim.width + hgap +
                        Math.max (northeastDim.width, southeastDim.width);
        dim.height = Math.max (northwestDim.height, northeastDim.height) +
                        + vgap + centerDim.height + vgap +
                        Math.max (southeastDim.height, southwestDim.height);

	Insets insets = target.insets();
        dim.width += insets.left + insets.right;
	dim.height += insets.top + insets.bottom;

	return dim;
    
public java.awt.DimensionpreferredLayoutSize(java.awt.Container target)

	Dimension dim = new Dimension(0, 0);
        Dimension northeastDim = new Dimension (0,0);
        Dimension northwestDim = new Dimension (0,0);
        Dimension southeastDim = new Dimension (0,0);
        Dimension southwestDim = new Dimension (0,0);
        Dimension centerDim    = new Dimension (0,0);


        if ((northeast != null) && northeast.isVisible()) {
            northeastDim = northeast.preferredSize();
	}
        if ((southwest != null) && southwest.isVisible()) {
            southwestDim = southwest.preferredSize();
	}
        if ((center != null) && center.isVisible()) {
            centerDim = center.preferredSize();
	}
        if ((northwest != null) && northwest.isVisible()) {
            northwestDim = northwest.preferredSize();
	}
        if ((southeast != null) && southeast.isVisible()) {
            southeastDim = southeast.preferredSize();
	}

        dim.width = Math.max (northwestDim.width, southwestDim.width) +
                        hgap + centerDim.width + hgap +
                        Math.max (northeastDim.width, southeastDim.width);
        dim.height = Math.max (northwestDim.height, northeastDim.height) +
                        + vgap + centerDim.height + vgap +
                        Math.max (southeastDim.height, southwestDim.height);

	Insets insets = target.insets();
	dim.width += insets.left + insets.right;
	dim.height += insets.top + insets.bottom;

	return dim;
    
public voidremoveLayoutComponent(java.awt.Component comp)

	if (comp == center) {
	    center = null;
        } else if (comp == northwest) {
            northwest = null;
        } else if (comp == southeast) {
            southeast = null;
        } else if (comp == northeast) {
            northeast = null;
        } else if (comp == southwest) {
            southwest = null;
	}
    
public java.lang.StringtoString()

        String str;
        switch (mode) {
            case FULL_WIDTH:  str = "wide";
                         break;
            case FULL_HEIGHT: str = "tall";
                         break;
            default:     str = "normal";
                         break;
        }
	return getClass().getName() + "[hgap=" + hgap +
                        ",vgap=" + vgap + ",mode=" + str + "]";