/* dIntProg Browser. A webbrowser written in Java.
 * Copyright (C) 2001 Martin Geisler <gimpster@gimpster.com>
 *  
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the
 * 
 * Free Software Foundation, Inc.,
 * 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

import java.util.*;
import java.awt.*;
import javax.swing.*;

/** Adaptor class for {@link FlexibleBox}. It implements the common
 *  methods of all flexible boxes. */
public abstract class
    AbstractFlexibleBox extends AbstractBox implements FlexibleBox {

    /** The child-boxes of this box. All flexible boxes contains one
     * or more child-boxes. */
    protected LinkedList boxes = new LinkedList();

    public void insert(Box b) {
        boxes.addLast(b);
    }

    public boolean isEmpty() {
        return (boxes.size() == 0);
    }

    /** Runs through the child-boxes and asks them to do layout with
     * the same parameters as this method was called with.
     * @param g the graphics context. Some boxes, like TextFragments,
     * need a graphics context before they can determine their width
     * and height.
     * @param c the component into which the box will be drawn. An
     * ImageBox needs to know the component to calculate the width and
     * height.
     * @param w the width available for to the box. */
    public void doLayout(Graphics g, JComponent c, int w) {
        ListIterator iterator = boxes.listIterator();
        while (iterator.hasNext()) {
            ((Box)iterator.next()).doLayout(g, c, w);
        }
    }

}