KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > html > HtmlTableRow


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  *
22  * $Id: HtmlTableRow.java,v 1.2 2005/03/24 10:51:20 slobodan Exp $
23  */

24
25
26
27
28
29 package com.lutris.html;
30
31 import java.util.Enumeration JavaDoc;
32 import java.util.Vector JavaDoc;
33
34 /**
35  * This utility class is used to compose a row within a
36  * HTML table.
37  *
38  * @see HtmlTable
39  * @see HtmlTableDataCell
40  * @see HtmlTableHeaderCell
41  * @author Kyle Clark
42  * @author Paul Morgan
43  * @version 1.0 (File $Revision: 1.2 $)
44  */

45 public class HtmlTableRow {
46
47     public static final int ALIGN_LEFT = 1;
48     public static final int ALIGN_CENTER = 2;
49     public static final int ALIGN_RIGHT = 3;
50     public static final int VALIGN_TOP = 1;
51     public static final int VALIGN_MIDDLE = 2;
52     public static final int VALIGN_BOTTOM = 3;
53
54     private String JavaDoc caption = null;
55     private String JavaDoc align = null;
56     private String JavaDoc valign = null;
57     private Vector JavaDoc row = new Vector JavaDoc();
58     private int colSpan = 0;
59     private int rowSpan = 0;
60     private String JavaDoc bgColor = null;
61
62     public HtmlTableRow()
63     {
64         // noop
65
}
66
67     public HtmlTableRow(HtmlTableCell td)
68     {
69         addCell(td);
70     }
71
72     public HtmlTableRow(String JavaDoc td)
73     {
74         addCell(td);
75     }
76
77     public void addCell(HtmlTableCell td)
78     {
79         row.addElement(td);
80     }
81
82     public void addCell(String JavaDoc td)
83     {
84         row.addElement(td);
85     }
86
87     public void setHorizontalAlignment(int alignment)
88     {
89         switch (alignment) {
90         case ALIGN_CENTER:
91             this.align = "CENTER";
92             break;
93         case ALIGN_RIGHT:
94             this.align = "RIGHT";
95             break;
96         default:
97             this.align = "LEFT";
98             break;
99         }
100     }
101
102     public void setVerticalAlignment(int alignment)
103     {
104         switch (alignment) {
105         case VALIGN_TOP:
106             this.valign = "TOP";
107             break;
108         case VALIGN_MIDDLE:
109             this.valign = "MIDDLE";
110             break;
111         default:
112             this.valign = "BOTTOM";
113             break;
114         }
115     }
116
117     public void setRowSpan(int rowSpan)
118     {
119         if (rowSpan > 0)
120             this.rowSpan = rowSpan;
121     }
122
123     public void setColSpan(int colSpan)
124     {
125         if (colSpan > 0)
126             this.colSpan = colSpan;
127     }
128
129     public void setBackgroundColor(String JavaDoc bgColor)
130     {
131         this.bgColor = bgColor;
132     }
133
134     public String JavaDoc toString()
135     {
136         StringBuffer JavaDoc html = new StringBuffer JavaDoc();
137
138         html.append("<TR");
139         if (align != null)
140             html.append(" ALIGN=" + align);
141         if (valign != null)
142             html.append(" VALIGN=" + valign);
143         if (colSpan > 0)
144             html.append(" COLSPAN=" + colSpan);
145         if (rowSpan > 0)
146             html.append(" ROWSPAN=" + rowSpan);
147         if (bgColor != null)
148             html.append(" BGCOLOR=" + bgColor);
149         html.append(">\n");
150
151         Enumeration JavaDoc e = row.elements();
152         while (e.hasMoreElements()) {
153             html.append(e.nextElement().toString());
154         }
155         html.append("</TR>\n");
156
157         return html.toString();
158     }
159 }
160
Popular Tags