1/* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved.
2 *
3 * This program and the accompanying materials are made available under
4 * the terms of the Common Public License v1.0 which accompanies this distribution,
5 * and is available at http://www.eclipse.org/legal/cpl-v10.html
6 *
7 * $Id: HTMLTable.java,v 1.1.1.1 2004/05/09 16:57:41 vlad_r Exp $
8 */
9package com.vladium.emma.report.html.doc;
10
11// ----------------------------------------------------------------------------
12/**
13 * @author Vlad Roubtsov, (C) 2003
14 */
15public
16final class HTMLTable extends IElement.Factory.ElementImpl
17{
18    // public: ................................................................
19
20    public static interface ICell extends IElement
21    {
22        ICell setColspan (final int span);
23
24    } // end of nested interface
25
26    public static interface IRow extends IElement
27    {
28        ICell newCell ();
29
30    } // end of nested interface
31
32    public HTMLTable (final String width, final String border, final String cellpadding, final String cellspacing)
33    {
34        super (Tag.TABLE, AttributeSet.create ());
35
36        final AttributeSet attrs = getAttributes ();
37
38        if (width != null) attrs.set (Attribute.WIDTH, width);
39        if (border != null) attrs.set (Attribute.BORDER, border);
40        if (cellpadding != null) attrs.set (Attribute.CELLPADDING, cellpadding);
41        if (cellspacing != null) attrs.set (Attribute.CELLSPACING, cellspacing);
42
43        //m_rows = new LinkedList ();
44    }
45
46    public void setCaption (final String align, final String text, final boolean nbsp)
47    {
48        m_caption = IElement.Factory.create (Tag.CAPTION);
49
50        m_caption.getAttributes ().set (Attribute.ALIGN, align);
51        m_caption.setText (text, nbsp);
52    }
53
54    public IRow newTitleRow ()
55    {
56        final Row row = new Row (true);
57        add (row);
58
59        return row;
60    }
61
62    public IRow newRow ()
63    {
64        final Row row = new Row (false);
65        add (row);
66
67        return row;
68    }
69
70    public void emit (final HTMLWriter out)
71    {
72        if (m_caption != null)
73        {
74            add (0, m_caption);
75        }
76
77        super.emit(out);
78    }
79
80    // protected: .............................................................
81
82    // package: ...............................................................
83
84    // private: ...............................................................
85
86
87    private static class Cell extends IElement.Factory.ElementImpl
88                              implements ICell
89    {
90        public ICell setColspan (final int span)
91        {
92            getAttributes ().set (Attribute.COLSPAN, span);
93
94            return this;
95        }
96
97        Cell (Tag tag)
98        {
99            super (tag, AttributeSet.create ());
100        }
101
102    } // end of nested class
103
104
105    private static class Row extends IElement.Factory.ElementImpl
106                             implements IRow
107    {
108        public ICell newCell ()
109        {
110            final ICell cell = new Cell (m_th ? Tag.TH : Tag.TD);
111            add (cell);
112
113            return cell;
114        }
115
116        Row (final boolean th)
117        {
118            super (Tag.TR, AttributeSet.create ());
119
120            m_th = th;
121        }
122
123
124        private final boolean m_th;
125
126    } // end of nested class
127
128
129    private IElement m_caption;
130
131} // end of class
132// ----------------------------------------------------------------------------