/* dIntProg Browser. A webbrowser written in Java. * Copyright (C) 2001 Martin Geisler * * 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 javax.swing.*; import java.util.*; import java.awt.*; /** A horizontal stack of boxes. It will place it's child-boxes side by side on a single line */ public class HorizontalBoxStack extends AbstractFlexibleBox { public void doLayout(Graphics g, JComponent c, int w) { //int total_w = 0; int h = 0; ListIterator iterator = boxes.listIterator(); while (iterator.hasNext()) { Box b = (Box)iterator.next(); b.doLayout(g, c, w/boxes.size()); h = h + b.getHeight(); } width = w; height = h; } /** The preferred width of this box. This is the sum of the * preferred widths of all the child-boxes. If the box is resized * to it's preferred width, all the child-boxes would fit on a * single line. * @return the preferred width of the box. */ public int getPreferredWidth() { if (pref_width == -1) { pref_width = 0; ListIterator iterator = boxes.listIterator(); while (iterator.hasNext()) { pref_width = pref_width + ((Box)iterator.next()).getPreferredWidth(); } } return pref_width; } /** The minimum width of this box. This is the sum of the * minimum widths of all the child-boxes. * @return the minimum width of the box. */ public int getMinimumWidth() { if (min_width == -1) { min_width = 0; ListIterator iterator = boxes.listIterator(); while (iterator.hasNext()) { min_width = min_width + ((Box)iterator.next()).getMinimumWidth(); } } return min_width; } 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, v); x_offset = x_offset + b.getWidth(); } } }