// excerpted from:

// From: Daryl Huff <dhuff@eng.sun.com>
// Newsgroups: comp.lang.java
// Subject: Re: Q: AWT: Dummy question: What is the best container/layout for NO RESIZING
// Date: Mon, 16 Oct 1995 14:54:21 -0700
// Organization: Sun Microsystems Inc., Mountain View, CA

// Usage example:
// 
//         setLayout(new AbsoluteLayout());
//         add(lbl1 = new Label("File 1"));
//         add(txt1 = new TextField("", 20));
//         add(lbl2 = new Label("File 2"));
//         add(txt2 = new TextField("", 20));
//         lbl1.move(0, 5);
//         txt1.move(75, 0);
//         lbl2.move(0, 40);
//         txt2.move(75, 35);
// 
// AbsoluteLayout.java:

import java.awt.*;

public class AbsoluteLayout implements LayoutManager {

    public AbsoluteLayout(){
    }

    public void addLayoutComponent(String name, Component comp) {
    }

    public void removeLayoutComponent(Component comp) {
    }

    public Dimension preferredLayoutSize(Container parent) {
        Insets insets = parent.insets();
        int ncomponents = parent.countComponents();
        int w = 0;
        int h = 0;

        for (int i = 0; i < ncomponents; i++) {
            Component comp = parent.getComponent(i);
            Dimension d = comp.preferredSize();
            Point p = comp.location();
            if ((p.x + d.width) > w)
                w = p.x + d.width;
            if ((p.y + d.height) > h)
                h = p.y + d.height;
        }
        return new Dimension(insets.left + insets.right + w,
                             insets.top + insets.bottom + h);
    }

    public Dimension minimumLayoutSize(Container parent) {
        Insets insets = parent.insets();
        int ncomponents = parent.countComponents();
        int w = 0;
        int h = 0;

        for (int i = 0; i < ncomponents; i++) {
            Component comp = parent.getComponent(i);
            Dimension d = comp.preferredSize();
            Point p = comp.location();
            if ((p.x + d.width) > w)
                w = p.x + d.width;
            if ((p.y + d.height) > h)
                h = p.y + d.height;
        }
        return new Dimension(insets.left + insets.right + w,
                             insets.top + insets.bottom + h);
    }

    public void layoutContainer(Container parent) {
        int     nmembers = parent.countComponents();

        for (int i = 0; i < nmembers; i++) {
            Component m = parent.getComponent(i);
            Dimension d = m.preferredSize();
            m.resize(d.width, d.height);
        }
    }
}
