/* dIntProg Browser. A webbrowser written in Java. * Copyright (C) 2001 Martin Geisler <[email protected]> * * 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.*; /** An unordered list eg. one with bullits before each item. */ public class UnorderedList extends VerticalBoxStack { private final int diameter = 10; private final int hspace = 6; private final int vspace = 4; private int nesting; public UnorderedList(int n) { nesting = n; } public void doLayout(Graphics g, JComponent c, int w) { super.doLayout(g, c, w - diameter - 2*hspace); width = w; if (height < diameter + 2*vspace) { height = diameter + 2*vspace; } } /** The minimum width of this box. This is the greatest of the * minimum widths of all the child-boxes. * @return the minimum width of the box. */ public int getMinimumWidth() { if (min_width == -1) { int w = 0; ListIterator iterator = boxes.listIterator(); while (iterator.hasNext()) { Box b = (Box)iterator.next(); w = b.getMinimumWidth(); Browser.debug("UnorderedList: min width is " + w + " of " + b); if (w > min_width) { min_width = w; } } min_width += diameter + 2*hspace; } return min_width; } public void drawAt(int x, int y, DocumentView v) { int y_offset = 0; ListIterator iterator = boxes.listIterator(); while (iterator.hasNext()) { if (nesting % 2 == 0) { v.fillOval(x + hspace, y + vspace + y_offset, diameter, diameter, Color.black); } else { v.drawOval(x + hspace, y + vspace + y_offset, diameter, diameter, Color.black); } Box b = (Box)iterator.next(); b.drawAt(x+diameter+2*hspace, y+y_offset, v); y_offset = y_offset + b.getHeight(); } } }