KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lobobrowser > html > renderer > RTableCell


1 /*
2     GNU LESSER GENERAL PUBLIC LICENSE
3     Copyright (C) 2006 The Lobo Project
4
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Lesser General Public
7     License as published by the Free Software Foundation; either
8     version 2.1 of the License, or (at your option) any later version.
9
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13     Lesser General Public License for more details.
14
15     You should have received a copy of the GNU Lesser General Public
16     License along with this library; if not, write to the Free Software
17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19     Contact info: xamjadmin@users.sourceforge.net
20 */

21 /*
22  * Created on Dec 3, 2005
23  */

24 package org.lobobrowser.html.renderer;
25
26 import java.awt.Insets JavaDoc;
27
28 import org.lobobrowser.html.*;
29 import org.lobobrowser.html.domimpl.*;
30 import org.lobobrowser.html.style.RenderState;
31 import org.lobobrowser.html.style.TableCellRenderState;
32
33 class RTableCell extends RBlock {
34     private final HTMLTableCellElementImpl cellElement;
35     private VirtualCell topLeftVirtualCell;
36     private int cellPadding;
37     
38     /**
39      * @param element
40      */

41     public RTableCell(HTMLTableCellElementImpl element, UserAgentContext pcontext, HtmlRendererContext rcontext, FrameContext frameContext, RenderableContainer tableAsContainer) {
42         super(element, 0, pcontext, rcontext, frameContext, tableAsContainer);
43         this.cellElement = element;
44     }
45     
46     public void setCellPadding(int value) {
47         this.cellPadding = value;
48     }
49     
50     protected int getDeclaredHeight(int availHeight) {
51         // Override RBlock method to allow TableMatrix to set bounds.
52
return -1;
53     }
54
55     protected int getDeclaredWidth(int availWidth) {
56         // Override RBlock method to allow TableMatrix to set bounds.
57
return -1;
58     }
59
60 // public void applyStyle() {
61
// super.applyStyle();
62
// if(this.paddingInsets == null) {
63
// int cp = this.cellPadding;
64
// this.paddingInsets = new Insets(cp, cp, cp, cp);
65
// }
66
// }
67

68     public void finalize() throws Throwable JavaDoc {
69         super.finalize();
70     }
71
72     public void setTopLeftVirtualCell(VirtualCell vc) {
73         this.topLeftVirtualCell = vc;
74     }
75     
76     public VirtualCell getTopLeftVirtualCell() {
77         return this.topLeftVirtualCell;
78     }
79     
80     private int colSpan = -1;
81     private int rowSpan = -1;
82
83     /**
84      * @return Returns the virtualColumn.
85      */

86     public int getVirtualColumn() {
87         VirtualCell vc = this.topLeftVirtualCell;
88         return vc == null ? 0 : vc.getColumn();
89     }
90
91     /**
92      * @return Returns the virtualRow.
93      */

94     public int getVirtualRow() {
95         VirtualCell vc = this.topLeftVirtualCell;
96         return vc == null ? 0 : vc.getRow();
97     }
98
99     public int getColSpan() {
100         int cs = this.colSpan;
101         if(cs == -1) {
102             cs = this.cellElement.getColSpan();
103             if(cs < 1) {
104                 cs = 1;
105             }
106             this.colSpan = cs;
107         }
108         return cs;
109     }
110     
111     public int getRowSpan() {
112         int rs = this.rowSpan;
113         if(rs == -1) {
114             rs = this.cellElement.getRowSpan();
115             if(rs < 1) {
116                 rs = 1;
117             }
118             this.rowSpan = rs;
119         }
120         return rs;
121     }
122
123     public String JavaDoc getHeightText() {
124         return this.cellElement.getHeight();
125     }
126
127     public String JavaDoc getWidthText() {
128         return this.cellElement.getWidth();
129     }
130     
131     
132
133     // public Dimension layoutMinWidth() {
134
//
135
// return this.panel.layoutMinWidth();
136
//
137
// }
138
//
139
//
140

141     public void setCellBounds(TableMatrix.SizeInfo[] colSizes, TableMatrix.SizeInfo[] rowSizes, int hasBorder, int cellSpacingX, int cellSpacingY) {
142         int vcol = this.getVirtualColumn();
143         int vrow = this.getVirtualRow();
144         TableMatrix.SizeInfo colSize = colSizes[vcol];
145         TableMatrix.SizeInfo rowSize = rowSizes[vrow];
146         int x = colSize.offset;
147         int y = rowSize.offset;
148         int width;
149         int height;
150         int colSpan = this.getColSpan();
151         if(colSpan > 1) {
152             width = 0;
153             for(int i = 0; i < colSpan; i++) {
154                 int vc = vcol + i;
155                 width += colSizes[vc].actualSize;
156                 if(i + 1 < colSpan) {
157                     width += cellSpacingX + hasBorder * 2;
158                 }
159             }
160         }
161         else {
162             width = colSizes[vcol].actualSize;
163         }
164         int rowSpan = this.getRowSpan();
165         if(rowSpan > 1) {
166             height = 0;
167             for(int i = 0; i < rowSpan; i++) {
168                 int vr = vrow + i;
169                 height += rowSizes[vr].actualSize;
170                 if(i + 1 < rowSpan) {
171                     height += cellSpacingY + hasBorder * 2;
172                 }
173             }
174         }
175         else {
176             height = rowSizes[vrow].actualSize;
177         }
178         this.setBounds(x, y, width, height);
179     }
180 }
181
Popular Tags