KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > services > html > Row


1 /* ====================================================================
2  * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
3  *
4  * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution,
19  * if any, must include the following acknowledgment:
20  * "This product includes software developed by Jcorporate Ltd.
21  * (http://www.jcorporate.com/)."
22  * Alternately, this acknowledgment may appear in the software itself,
23  * if and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. "Jcorporate" and product names such as "Expresso" must
26  * not be used to endorse or promote products derived from this
27  * software without prior written permission. For written permission,
28  * please contact info@jcorporate.com.
29  *
30  * 5. Products derived from this software may not be called "Expresso",
31  * or other Jcorporate product names; nor may "Expresso" or other
32  * Jcorporate product names appear in their name, without prior
33  * written permission of Jcorporate Ltd.
34  *
35  * 6. No product derived from this software may compete in the same
36  * market space, i.e. framework, without prior written permission
37  * of Jcorporate Ltd. For written permission, please contact
38  * partners@jcorporate.com.
39  *
40  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43  * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
44  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
46  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  * ====================================================================
53  *
54  * This software consists of voluntary contributions made by many
55  * individuals on behalf of the Jcorporate Ltd. Contributions back
56  * to the project(s) are encouraged when you make modifications.
57  * Please send them to support@jcorporate.com. For more information
58  * on Jcorporate Ltd. and its products, please see
59  * <http://www.jcorporate.com/>.
60  *
61  * Portions of this software are based upon other open source
62  * products and are subject to their respective licenses.
63  */

64
65 package com.jcorporate.expresso.services.html;
66
67 /**
68  * Row.java
69  *
70  * Copyright 1999, 2000, 2001 Jcorporate Ltd.
71  */

72
73 import java.io.PrintWriter JavaDoc;
74 import java.util.Enumeration JavaDoc;
75 import java.util.StringTokenizer JavaDoc;
76
77
78 /**
79  * @author Michael Nash
80  * @version $Revision: 1.9 $ $Date: 2004/11/17 20:48:18 $
81  */

82 public class Row
83         extends HtmlElement {
84     private String JavaDoc thisClass = (this.getClass().getName() + ".");
85     private String JavaDoc alignment = null;
86     private int cellspacing = 0;
87     private int border = 0;
88     private String JavaDoc titleString = null;
89     private boolean captionRow = false;
90
91     /**
92      * Constructor
93      */

94     public Row()
95             throws HtmlException {
96         super();
97     } /* Row() */
98
99     /**
100      * Constructor
101      *
102      * @param newElement nested element
103      */

104     public Row(HtmlElement newElement)
105             throws HtmlException {
106         super(newElement);
107     } /* Row(HtmlElement) */
108
109     /**
110      * Constructor
111      *
112      * @param newName name of the row
113      */

114     public Row(String JavaDoc newName)
115             throws HtmlException {
116         super(newName);
117     } /* Row(String) */
118
119     /**
120      * One can only add cells to tables. If we're handed something other than a cell,
121      * put in IN a cell, then add the cell
122      *
123      * @param newElement nested element
124      */

125     public synchronized void add(HtmlElement newElement)
126             throws HtmlException {
127         if (newElement instanceof Cell) {
128             super.add(newElement);
129         } else {
130             Cell newCell = new Cell();
131             newCell.add(newElement);
132             add(newCell);
133         }
134     } /* add(HtmlElement) */
135
136
137     /**
138      * @param cellContents cell contents
139      */

140     public synchronized void addCell(String JavaDoc cellContents)
141             throws HtmlException {
142         Cell oneCell = new Cell(cellContents);
143         add(oneCell);
144     } /* addCell(String) */
145
146
147     /**
148      * @param out the output stream
149      * @param depth the number of tabs to indent
150      */

151     protected synchronized void display(PrintWriter JavaDoc out, int depth)
152             throws HtmlException {
153         String JavaDoc myName = (thisClass + "display(PrintWriter)");
154
155         if (contents.size() == 0 && captionRow == false &&
156                 titleString == null) {
157             throw new HtmlException(myName + ":Row '" + getName() +
158                     "' has no contents");
159         }
160         if (captionRow) {
161             this.padWithTabs(out, depth);
162             out.print("<caption class=\"jc-caption\">");
163             out.print(titleString);
164             out.println("</caption>");
165         } else {
166             if (titleString != null) {
167                 StringTokenizer JavaDoc stk = new StringTokenizer JavaDoc(titleString, "|");
168                 this.padWithTabs(out, depth);
169                 out.println("<tr class=\"jc-tabletitlerow\">");
170
171                 while (stk.hasMoreTokens()) {
172                     this.padWithTabs(out, depth + 1);
173                     out.print("<th class=\"jc-tabletitle\">");
174                     out.print(stk.nextToken());
175                     out.println("</th>");
176                 }
177
178                 this.padWithTabs(out, depth);
179                 out.println("</tr>");
180             }
181             if (contents.size() != 0) {
182                 this.padWithTabs(out, depth);
183                 out.print("<tr");
184
185                 if (cSSClass != null) {
186                     out.print(" class=\"" + cSSClass + "\"");
187                 }
188                 if (cSSID != null) {
189                     out.print(" id=\"" + cSSID + "\"");
190                 }
191
192                 out.println(">");
193
194                 HtmlElement oneElement = null;
195
196                 for (Enumeration JavaDoc e = contents.elements(); e.hasMoreElements();) {
197                     oneElement = (HtmlElement) e.nextElement();
198                     oneElement.display(out, depth + 1);
199                 }
200
201                 this.padWithTabs(out, depth);
202                 out.println("</tr>");
203             }
204         }
205
206         setDisplayed();
207     } /* display(PrintWriter) */
208
209
210     public synchronized boolean isCaptionRow() {
211         return captionRow;
212     }
213
214     /**
215      * @param newAlignment left|right|center
216      */

217     public synchronized void setAlignment(String JavaDoc newAlignment)
218             throws HtmlException {
219         String JavaDoc myName = (thisClass + "setAlignment(String)");
220
221         if (newAlignment.equalsIgnoreCase("left")) {
222             alignment = newAlignment;
223         } else if (newAlignment.equalsIgnoreCase("right")) {
224             alignment = newAlignment;
225         } else if (newAlignment.equalsIgnoreCase("center")) {
226             alignment = newAlignment;
227         } else {
228             throw new HtmlException(myName +
229                     ":Alignment must be left, right, or center for " +
230                     getName());
231         }
232     } /* setAlignment(String) */
233
234
235     /**
236      * @param newBorder border size
237      */

238     public synchronized void setBorder(int newBorder)
239             throws HtmlException {
240         border = newBorder;
241     } /* setBorder(int) */
242
243
244     /**
245      * @param state is it a caption row
246      */

247     public void setCaptionRow(boolean state) {
248         captionRow = state;
249     } /* setCaptionRow(boolean) */
250
251     /**
252      * @param newSpacing cell spacing
253      */

254     public synchronized void setCellSpacing(int newSpacing)
255             throws HtmlException {
256         cellspacing = newSpacing;
257     } /* setCellSpacing(int) */
258
259
260     /**
261      * @param newTitleString title of the cell
262      */

263     public synchronized void setTitle(String JavaDoc newTitleString)
264             throws HtmlException {
265         titleString = newTitleString;
266     } /* setTitle(String) */
267
268
269 } /* Row */
270
Popular Tags