001: package com.xoetrope.builder.w3c.html;
002:
003: import java.awt.Component;
004: import java.awt.Container;
005: import java.awt.Dimension;
006: import java.awt.Insets;
007: import java.awt.LayoutManager;
008:
009: /**
010: * A layout manager for html pages. Components flow along the page length occupying
011: * slots that span the width of the container.
012: * <p> Copyright (c) Xoetrope Ltd., 2002-2006</p>
013: * <p> $Revision: 1.2 $</p>
014: * <p> License: see License.txt</p>
015: */
016: public class XHtmlLayout implements LayoutManager {
017: protected XHtmlBuilder builder;
018:
019: /**
020: * Creates a new layout manager
021: *
022: * @param htmlBuilder the html builder for the current document
023: */
024: public XHtmlLayout(XHtmlBuilder htmlBuilder) {
025: builder = htmlBuilder;
026: }
027:
028: /**
029: * If the layout manager uses a per-component string,
030: * adds the component <code>comp</code> to the layout,
031: * associating it
032: * with the string specified by <code>name</code>.
033: *
034: * @param name the string to be associated with the component
035: * @param comp the component to be added
036: */
037: public void addLayoutComponent(String name, Component comp) {
038: }
039:
040: /**
041: * Removes the specified component from the layout.
042: * @param comp the component to be removed
043: */
044: public void removeLayoutComponent(Component comp) {
045:
046: }
047:
048: /**
049: * Calculates the preferred size dimensions for the specified
050: * container, given the components it contains.
051: * @param parent the container to be laid out
052: *
053: * @see #minimumLayoutSize
054: */
055: public Dimension preferredLayoutSize(Container parent) {
056: int numComponents = parent.getComponentCount();
057: int preferredWidth = 0;
058: int preferredHeight = 0;
059: for (int i = 0; i < numComponents; i++) {
060: Component c = parent.getComponent(i);
061: Dimension d = c.getPreferredSize();
062: preferredWidth = Math.max(d.width, preferredWidth);
063: preferredHeight += d.height;
064: // preferredHeight = Math.max( d.height, preferredHeight );
065: }
066:
067: Insets insets = parent.getInsets();
068: return new Dimension(preferredWidth + insets.left
069: + insets.right, preferredHeight + insets.top
070: + insets.bottom);
071: }
072:
073: /**
074: * Calculates the minimum size dimensions for the specified
075: * container, given the components it contains.
076: * @param parent the component to be laid out
077: * @see #preferredLayoutSize
078: */
079: public Dimension minimumLayoutSize(Container parent) {
080: int numComponents = parent.getComponentCount();
081: int preferredWidth = 0;
082: int preferredHeight = 0;
083: for (int i = 0; i < numComponents; i++) {
084: Component c = parent.getComponent(i);
085: Dimension d = c.getMinimumSize();
086: preferredWidth = Math.max(d.width, preferredWidth);
087: preferredHeight += d.height;
088: // preferredHeight = Math.max( d.height, preferredHeight );
089: }
090:
091: Insets insets = parent.getInsets();
092: return new Dimension(preferredWidth + insets.left
093: + insets.right, preferredHeight + insets.top
094: + insets.bottom);
095: }
096:
097: /**
098: * Lays out the specified container.
099: * @param parent the container to be laid out
100: */
101: public void layoutContainer(Container parent) {
102: int numComponents = parent.getComponentCount();
103: int width = parent.getWidth();
104: int cx = 0;
105: int cy = 0;
106: for (int i = 0; i < numComponents; i++) {
107: Component c = parent.getComponent(i);
108: Dimension d = c.getPreferredSize();
109: c.setBounds(cx, cy, width, d.height);
110: cy += d.height;
111: }
112: }
113: }
|