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: HtmlTableRow.java,v 1.3 2007-10-19 10:05:39 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 a row within a
031: * HTML table.
032: *
033: * @see HtmlTable
034: * @see HtmlTableDataCell
035: * @see HtmlTableHeaderCell
036: * @author Kyle Clark
037: * @author Paul Morgan
038: * @version 1.0 (File $Revision: 1.3 $)
039: */
040: public class HtmlTableRow {
041:
042: public static final int ALIGN_LEFT = 1;
043: public static final int ALIGN_CENTER = 2;
044: public static final int ALIGN_RIGHT = 3;
045: public static final int VALIGN_TOP = 1;
046: public static final int VALIGN_MIDDLE = 2;
047: public static final int VALIGN_BOTTOM = 3;
048:
049: // private String caption = null;
050: private String align = null;
051: private String valign = null;
052: private Vector row = new Vector();
053: private int colSpan = 0;
054: private int rowSpan = 0;
055: private String bgColor = null;
056:
057: public HtmlTableRow() {
058: // noop
059: }
060:
061: public HtmlTableRow(HtmlTableCell td) {
062: addCell(td);
063: }
064:
065: public HtmlTableRow(String td) {
066: addCell(td);
067: }
068:
069: public void addCell(HtmlTableCell td) {
070: row.addElement(td);
071: }
072:
073: public void addCell(String td) {
074: row.addElement(td);
075: }
076:
077: public void setHorizontalAlignment(int alignment) {
078: switch (alignment) {
079: case ALIGN_CENTER:
080: this .align = "CENTER";
081: break;
082: case ALIGN_RIGHT:
083: this .align = "RIGHT";
084: break;
085: default:
086: this .align = "LEFT";
087: break;
088: }
089: }
090:
091: public void setVerticalAlignment(int alignment) {
092: switch (alignment) {
093: case VALIGN_TOP:
094: this .valign = "TOP";
095: break;
096: case VALIGN_MIDDLE:
097: this .valign = "MIDDLE";
098: break;
099: default:
100: this .valign = "BOTTOM";
101: break;
102: }
103: }
104:
105: public void setRowSpan(int rowSpan) {
106: if (rowSpan > 0)
107: this .rowSpan = rowSpan;
108: }
109:
110: public void setColSpan(int colSpan) {
111: if (colSpan > 0)
112: this .colSpan = colSpan;
113: }
114:
115: public void setBackgroundColor(String bgColor) {
116: this .bgColor = bgColor;
117: }
118:
119: public String toString() {
120: StringBuffer html = new StringBuffer();
121:
122: html.append("<TR");
123: if (align != null)
124: html.append(" ALIGN=" + align);
125: if (valign != null)
126: html.append(" VALIGN=" + valign);
127: if (colSpan > 0)
128: html.append(" COLSPAN=" + colSpan);
129: if (rowSpan > 0)
130: html.append(" ROWSPAN=" + rowSpan);
131: if (bgColor != null)
132: html.append(" BGCOLOR=" + bgColor);
133: html.append(">\n");
134:
135: Enumeration e = row.elements();
136: while (e.hasMoreElements()) {
137: html.append(e.nextElement().toString());
138: }
139: html.append("</TR>\n");
140:
141: return html.toString();
142: }
143: }
|