/* 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.awt.Graphics;
import java.awt.Color;
import javax.swing.*;
import java.util.*;

// RigidBoxGroup isn't used at this time.

/** A group of rigid boxes. A <code>RigidBoxGroup</code> is special
 *  because it is a rigid box with child-boxes - it has a {@link
 *  #insert(Box)} method. It cannot be split (it groups the
 *  child-boxes into an unbreakable unit) and it cannot be resized. */
public class RigidBoxGroup extends AbstractRigidBox {

    private LinkedList boxes = new LinkedList();

    /** Inserts a box into the group
     * @param b the box to be inserted. The box is added to the end of
     * the group - it will be drawn to the right of the other boxes in
     * the group. */
    public void insert(Box b) {
        boxes.addLast(b);
    }

    public void drawAt(int x, int y, DocumentView v) {
        
        int x_offset = 0;
        
        ListIterator iterator = boxes.listIterator();

        while (iterator.hasNext()) {
            Box b = (Box)iterator.next();
            b.drawAt(x + x_offset, y +  height - b.getHeight(), v);
            x_offset = x_offset + b.getWidth();
        }
        
        if (Browser.debugging) {
            v.drawRect(x, y, width, height, Color.green);
        }
    }


    public void doLayout(Graphics g, JComponent c, int w) {
        width = 0;
        ListIterator iterator = boxes.listIterator();
        while (iterator.hasNext()) {
            Box b = (Box)iterator.next();
            b.doLayout(g, c, w);
            width = width + b.getWidth();
            
        }
        min_width = width;
        pref_width = width;
    }

}