aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/apache/fop/fo/flow/TableColumn.java
blob: 44684ae335272ef70f848c5c822dd327ccfb1459 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
 * $Id$
 * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
 * For details on use and redistribution please refer to the
 * LICENSE file included with these sources.
 */

package org.apache.fop.fo.flow;

// FOP
import org.apache.fop.fo.*;
import org.apache.fop.fo.properties.*;
import org.apache.fop.layout.*;
import org.apache.fop.apps.FOPException;
import org.apache.fop.datatypes.*;

public class TableColumn extends FObj {

    ColorType backgroundColor;

    Length columnWidthPropVal;
    int columnWidth;
    int columnOffset;
    int numColumnsRepeated;
    int iColumnNumber;

    boolean setup = false;

    AreaContainer areaContainer;

    public static class Maker extends FObj.Maker {
        public FObj make(FObj parent,
                         PropertyList propertyList) throws FOPException {
            return new TableColumn(parent, propertyList);
        }

    }

    public static FObj.Maker maker() {
        return new TableColumn.Maker();
    }

    public TableColumn(FObj parent, PropertyList propertyList) {
        super(parent, propertyList);
        this.name = "fo:table-column";
    }

    public Length getColumnWidthAsLength() {
        return columnWidthPropVal;
    }

    public int getColumnWidth() {
        return columnWidth;
    }

    /**
     * Set the column width value in base units which overrides the
     * value from the column-width Property.
     */
    public void setColumnWidth(int columnWidth) {
        this.columnWidth = columnWidth;
    }

    public int getColumnNumber() {
        return iColumnNumber;
    }

    public int getNumColumnsRepeated() {
        return numColumnsRepeated;
    }

    public void doSetup(Area area) throws FOPException {

        // Common Border, Padding, and Background Properties
        // only background apply, border apply if border-collapse
        // is collapse.
        BorderAndPadding bap = propMgr.getBorderAndPadding();
        BackgroundProps bProps = propMgr.getBackgroundProps();

        // this.properties.get("column-width");
        // this.properties.get("number-columns-repeated");
        // this.properties.get("number-columns-spanned");
        // this.properties.get("visibility");

        this.iColumnNumber =
	    this.properties.get("column-number").getNumber().intValue();

        this.numColumnsRepeated =
            this.properties.get("number-columns-repeated").getNumber().intValue();

        this.backgroundColor =
            this.properties.get("background-color").getColorType();

        this.columnWidthPropVal =
            this.properties.get("column-width").getLength();
	// This won't include resolved table-units or % values yet.
	this.columnWidth = columnWidthPropVal.mvalue();

        // initialize id
        String id = this.properties.get("id").getString();
        area.getIDReferences().initializeID(id, area);

        setup = true;
    }

    public Status layout(Area area) throws FOPException {
        if (this.marker == BREAK_AFTER) {
            return new Status(Status.OK);
        }

        if (this.marker == START) {
            if (!setup) {
                doSetup(area);
            }
        }
	if (columnWidth > 0) {
	    this.areaContainer =
		new AreaContainer(propMgr.getFontState(area.getFontInfo()),
				  columnOffset, 0, columnWidth,
				  area.getContentHeight(), Position.RELATIVE);
	    areaContainer.foCreator = this;    // G Seshadri
	    areaContainer.setPage(area.getPage());
	    areaContainer.setBorderAndPadding(propMgr.getBorderAndPadding());
	    areaContainer.setBackgroundColor(this.backgroundColor);
	    areaContainer.setHeight(area.getHeight());
	    area.addChild(areaContainer);
	}
        return new Status(Status.OK);
    }

    public void setColumnOffset(int columnOffset) {
        this.columnOffset = columnOffset;
    }

    public void setHeight(int height) {
	if (areaContainer != null) {
	    areaContainer.setMaxHeight(height);
	    areaContainer.setHeight(height);
	}
    }

}