001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: *
021: * $Id: HtmlTable.java,v 1.2 2006-06-15 13:47:00 sinisa Exp $
022: */
023:
024: package com.lutris.html;
025:
026: import java.util.Enumeration;
027: import java.util.Vector;
028:
029: /**
030: * This utility class is used to compose an HTML table.
031: *
032: * @see HtmlTableRow
033: * @see HtmlTableDataCell
034: * @see HtmlTableHeaderCell
035: * @author Kyle Clark
036: * @author Paul Morgan
037: * @version 1.0 (File $Revision: 1.2 $)
038: */
039: public class HtmlTable {
040:
041: private String caption = null;
042: private int percentWidth = 0;
043: private int borderWidth = -1;
044: private int cellPadding = -1;
045: private int cellSpacing = -1;
046: private String bgColor = null;
047: private String rules = null;
048: private String frame = null;
049: private Vector rows = new Vector();
050: private Object thead = null;
051:
052: public HtmlTable() {
053: this .caption = null;
054: }
055:
056: public HtmlTable(String caption) {
057: this .caption = caption;
058: }
059:
060: public void setBorderWidth(int pixels) {
061: this .borderWidth = pixels;
062: }
063:
064: public void addRow(HtmlTableRow row) {
065: rows.addElement(row);
066: }
067:
068: public void addRow(String row) {
069: rows.addElement(row);
070: }
071:
072: public void setHeader(Object row) {
073: thead = row;
074: }
075:
076: public void setPercentWidth(int percent) {
077: if (percent > 0 && percent <= 100)
078: this .percentWidth = percent;
079: }
080:
081: public void setCaption(String caption) {
082: this .caption = caption;
083: }
084:
085: public void setCellSpacing(int size) {
086: if (size >= 0)
087: cellSpacing = size;
088: }
089:
090: public void setCellPadding(int size) {
091: if (size >= 0)
092: cellPadding = size;
093: }
094:
095: public void setBackgroundColor(String bgColor) {
096: this .bgColor = bgColor;
097: }
098:
099: public void setFrame(String frame) {
100: this .frame = frame;
101: }
102:
103: public void setRules(String rules) {
104: this .rules = rules;
105: }
106:
107: public String toString() {
108: StringBuffer html = new StringBuffer();
109:
110: html.append("<TABLE");
111: if (borderWidth >= 0)
112: html.append(" BORDER=" + borderWidth);
113: if (percentWidth > 0)
114: html.append(" WIDTH=" + percentWidth + "%");
115: if (cellPadding >= 0)
116: html.append(" CELLPADDING=" + cellPadding);
117: if (cellSpacing >= 0)
118: html.append(" CELLSPACING=" + cellSpacing);
119: if (bgColor != null)
120: html.append(" BGCOLOR=" + bgColor);
121: if (rules != null)
122: html.append(" RULES=" + rules);
123: if (frame != null)
124: html.append(" FRAME=" + frame);
125: html.append(">\n");
126:
127: if (caption != null) {
128: html.append("<CAPTION>");
129: html.append(caption);
130: html.append("</CAPTION>\n");
131: }
132:
133: if (thead != null) {
134: html.append("<THEAD>");
135: html.append(thead.toString());
136: html.append("</THEAD>\n");
137: }
138:
139: Enumeration e = rows.elements();
140: while (e.hasMoreElements()) {
141: html.append(e.nextElement().toString());
142: }
143: html.append("</TABLE>\n");
144:
145: return html.toString();
146: }
147: }
|