KickJava   Java API By Example, From Geeks To Geeks.

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


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: HtmlTable.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 an HTML table.
36  *
37  * @see HtmlTableRow
38  * @see HtmlTableDataCell
39  * @see HtmlTableHeaderCell
40  * @author Kyle Clark
41  * @author Paul Morgan
42  * @version 1.0 (File $Revision: 1.2 $)
43  */

44 public class HtmlTable {
45
46     private String JavaDoc caption = null;
47     private int percentWidth = 0;
48     private int borderWidth = -1;
49     private int cellPadding = -1;
50     private int cellSpacing = -1;
51     private String JavaDoc bgColor = null;
52     private String JavaDoc rules = null;
53     private String JavaDoc frame = null;
54     private Vector JavaDoc rows = new Vector JavaDoc();
55     private Object JavaDoc thead = null;
56
57     public HtmlTable()
58     {
59         this.caption = null;
60     }
61
62     public HtmlTable(String JavaDoc caption)
63     {
64         this.caption = caption;
65     }
66
67     public void setBorderWidth(int pixels)
68     {
69         this.borderWidth = pixels;
70     }
71
72     public void addRow(HtmlTableRow row)
73     {
74         rows.addElement(row);
75     }
76
77     public void addRow(String JavaDoc row)
78     {
79         rows.addElement(row);
80     }
81
82     public void setHeader(Object JavaDoc row)
83     {
84         thead = row;
85     }
86
87     public void setPercentWidth(int percent)
88     {
89         if (percent > 0 && percent <= 100)
90             this.percentWidth = percent;
91     }
92
93     public void setCaption(String JavaDoc caption)
94     {
95         this.caption = caption;
96     }
97
98     public void setCellSpacing(int size)
99     {
100         if (size >= 0)
101             cellSpacing = size;
102     }
103
104     public void setCellPadding(int size)
105     {
106         if (size >= 0)
107             cellPadding = size;
108     }
109
110     public void setBackgroundColor(String JavaDoc bgColor)
111     {
112         this.bgColor = bgColor;
113     }
114
115     public void setFrame(String JavaDoc frame)
116     {
117         this.frame = frame;
118     }
119
120     public void setRules(String JavaDoc rules)
121     {
122         this.rules = rules;
123     }
124
125     public String JavaDoc toString()
126     {
127         StringBuffer JavaDoc html = new StringBuffer JavaDoc();
128
129         html.append("<TABLE");
130         if (borderWidth >= 0)
131             html.append(" BORDER=" + borderWidth);
132         if (percentWidth > 0)
133             html.append(" WIDTH=" + percentWidth + "%");
134         if (cellPadding >= 0)
135             html.append(" CELLPADDING=" + cellPadding);
136         if (cellSpacing >= 0)
137             html.append(" CELLSPACING=" + cellSpacing);
138         if (bgColor != null)
139             html.append(" BGCOLOR=" + bgColor);
140         if (rules != null)
141             html.append(" RULES=" + rules);
142         if (frame != null)
143             html.append(" FRAME=" + frame);
144         html.append(">\n");
145
146         if (caption != null) {
147             html.append("<CAPTION>");
148             html.append(caption);
149             html.append("</CAPTION>\n");
150         }
151
152         if (thead != null) {
153             html.append("<THEAD>");
154             html.append(thead.toString());
155             html.append("</THEAD>\n");
156         }
157         
158         Enumeration JavaDoc e = rows.elements();
159         while (e.hasMoreElements()) {
160             html.append(e.nextElement().toString());
161         }
162         html.append("</TABLE>\n");
163
164         return html.toString();
165     }
166 }
167
Popular Tags