001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: // Copyright (C) 1999 - 2002, Salmon LLC
004: //
005: // This program is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU General Public License version 2
007: // as published by the Free Software Foundation;
008: //
009: // This program is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: // GNU General Public License for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // along with this program; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: //
018: // For more information please visit http://www.salmonllc.com
019: //** End Copyright Statement ***************************************************
020: package com.salmonllc.jsp;
021:
022: /////////////////////////
023: //$Archive: /SOFIA/SourceCode/com/salmonllc/jsp/JspTable.java $
024: //$Author: Dan $
025: //$Revision: 18 $
026: //$Modtime: 1/22/04 12:36p $
027: /////////////////////////
028:
029: import com.salmonllc.properties.Props;
030: import com.salmonllc.util.Util;
031:
032: /**
033: * This component will generate an HTML table. It serves as a container and layout manager for other components.
034: */
035:
036: public class JspTable extends JspContainer {
037: public static final int SIZE_PERCENT = 0;
038: public static final int SIZE_PIXELS = 1;
039: //
040: public static final String ALIGN_LEFT = "LEFT";
041: public static final String ALIGN_CENTER = "CENTER";
042: public static final String ALIGN_RIGHT = "RIGHT";
043: public static final String ALIGN_NONE = "";
044: //
045: public static final String VALIGN_BASELINE = "BASELINE";
046: public static final String VALIGN_BOTTOM = "BOTTOM";
047: public static final String VALIGN_MIDDLE = "MIDDLE";
048: public static final String VALIGN_TOP = "TOP";
049: public static final String VALIGN_NONE = "";
050: //
051: private int _nextTDRowNo;
052: private int _nextTRRowNo;
053: //
054: private String _bgcolor = "";
055: private String _bordercolor = "";
056: private String _theme;
057: //
058: private int _sizeOption = SIZE_PERCENT;
059:
060: //
061: private String _align = null;
062: private int _border = -1;
063: private int _cellPadding = -1;
064: private int _cellSpacing = -1;
065: private int _cols = -1;
066: private int _hSpace = -1;
067: private int _vSpace = -1;
068: private String _height, _width;
069: private String _rowStyleClass;
070:
071: //
072:
073: /**
074: * Constructs a new JSP Table.
075: * @param name Each component on a page must have a unique name.
076: * @param p The page that the table will be added to.
077: */
078: public JspTable(String name, com.salmonllc.html.HtmlPage p) {
079: this (name, null, p);
080: }
081:
082: /**
083: * Constructs a new JSP Table.
084: * @param name Each component on a page must have a unique name.
085: * @param theme The theme to use for loading properties
086: * @param p The page that the table will be added to.
087: */
088: public JspTable(String name, String theme,
089: com.salmonllc.html.HtmlPage p) {
090: super (name, p);
091: setTheme(theme);
092: }
093:
094: /**
095: * This method will generate the HTML to render the table
096: */
097: public void generateHTML(TagWriter writer, String content)
098: throws java.io.IOException {
099:
100: StringBuffer sb = new StringBuffer();
101:
102: sb.append("<TABLE");
103:
104: if (_border != -1)
105: sb.append(" BORDER=\"" + _border + "\"");
106:
107: if (Util.isFilled(_bordercolor))
108: sb.append(" BORDERCOLOR=\"" + _bordercolor + "\"");
109:
110: if (_cellPadding != -1)
111: sb.append(" CELLPADDING=\"" + _cellPadding + "\"");
112:
113: if (_cellSpacing != -1)
114: sb.append(" CELLSPACING=\"" + _cellSpacing + "\"");
115:
116: if (_bgcolor != null)
117: sb.append(" BGCOLOR=\"" + _bgcolor + "\"");
118:
119: if (_height != null)
120: sb.append(" HEIGHT=\"" + _height + "\"");
121:
122: if (_width != null)
123: sb.append(" WIDTH=\"" + _width + "\"");
124:
125: if (_align != null)
126: sb.append(" ALIGN=\"" + _align + "\"");
127:
128: if (_cols != -1)
129: sb.append(" COLS=\"" + _cols + "\"");
130:
131: if (_class != null)
132: sb.append(" CLASS=\"" + _class + "\"");
133:
134: if (_hSpace != -1)
135: sb.append(" HSPACE=\"" + _hSpace + "\"");
136:
137: if (_vSpace != -1)
138: sb.append(" VSPACE=\"" + _vSpace + "\"");
139:
140: sb.append(">");
141:
142: writer.print(sb.toString(), TagWriter.TYPE_BEGIN_TAG);
143: writer.print(content, TagWriter.TYPE_CONTENT);
144: writer.print("</TABLE>", TagWriter.TYPE_END_TAG);
145: }
146:
147: /**
148: * This method should not be called directly. It is public so it can be called from com.salmonllc.jsp.tags
149: */
150: public String generateNextTDName(int colSpan) {
151: String ret = "";
152: ret = getName() + "TDRow" + _nextTDRowNo;
153: _nextTDRowNo += colSpan;
154:
155: return ret;
156: }
157:
158: /**
159: * This method should not be called directly. It is public so it can be called from com.salmonllc.jsp.tags
160: */
161:
162: public String generateNextTRName() {
163: String ret = "";
164: ret = getName() + "TRRow" + _nextTRRowNo;
165: _nextTRRowNo++;
166:
167: return ret;
168: }
169:
170: /**
171: * Returns the alignment property for the table.
172: * @return align Valid values are ALIGN_LEFT,ALIGN_CENTER,ALIGN_RIGHT and ALIGN_NONE.
173: */
174: public String getAlign() {
175: return _align;
176: }
177:
178: /**
179: * Gets the background color for the table.
180: */
181: public String getBackgroundColor() {
182: return _bgcolor;
183: }
184:
185: /**
186: * Gets the border thickness for the table.
187: */
188: public int getBorder() {
189: return _border;
190: }
191:
192: /**
193: * Gets the background color for the table.
194: */
195: public String getBorderColor() {
196: return _bordercolor;
197: }
198:
199: /**
200: * Gets the cell padding for the table.
201: */
202: public int getCellPadding() {
203: return _cellPadding;
204: }
205:
206: /**
207: * Gets the cell spacing for the table.
208: */
209: public int getCellSpacing() {
210: return _cellSpacing;
211: }
212:
213: /**
214: * Sets the cell padding for the table.
215: */
216: public int getCols() {
217: return _cols;
218: }
219:
220: /**
221: * This method gets the minimum height of the table in pixels.
222: */
223: public String getHeight() {
224: return _height;
225: }
226:
227: /**
228: * Gets the horizontal margin for the table.
229: */
230: public int getHSpace() {
231: return _hSpace;
232: }
233:
234: /**
235: * This method returns the size option for the table and each cell in it. Valid return values are SIZE_PIXELS or SIZE_PERCENT.
236: */
237: public int getSizeOption() {
238: return _sizeOption;
239: }
240:
241: /**
242: * This method returns the property theme for the component.
243: * @param theme The theme to use.
244: */
245: public String getTheme() {
246: return _theme;
247: }
248:
249: /**
250: * Gets the vertical margin for the table.
251: */
252: public int getVSpace() {
253: return _vSpace;
254: }
255:
256: /**
257: * This method returns the width of the table.
258: */
259: public String getWidth() {
260: return _width;
261: }
262:
263: /**
264: * This method should not be called directly. It is public so it can be called from com.salmonllc.jsp.tags
265: */
266:
267: public void resetCounters() {
268: _nextTDRowNo = 0;
269: _nextTRRowNo = 0;
270: }
271:
272: /**
273: * Sets the alignment property for the table.
274: * @param align Valid values are ALIGN_LEFT,ALIGN_CENTER,ALIGN_RIGHT and ALIGN_NONE.
275: */
276:
277: public void setAlign(String align) {
278: _align = align;
279: }
280:
281: /**
282: * Sets the background color for the table.
283: */
284: public void setBackgroundColor(String value) {
285: _bgcolor = value;
286: }
287:
288: /**
289: * Sets the border width for the table.
290: */
291: public void setBorder(int border) {
292: _border = border;
293: }
294:
295: /**
296: * Sets the background color for the table.
297: */
298: public void setBorderColor(String value) {
299: _bordercolor = value;
300: }
301:
302: /**
303: * Sets the cell padding for the table.
304: */
305: public void setCellPadding(int value) {
306: _cellPadding = value;
307: }
308:
309: /**
310: * Sets the cell spacing for the table.
311: */
312: public void setCellSpacing(int value) {
313: _cellSpacing = value;
314: }
315:
316: /**
317: * Sets the cell padding for the table.
318: */
319: public void setCols(int value) {
320: _cols = value;
321: }
322:
323: /**
324: * This method gets the minimum height of the table in pixels.
325: */
326: public void setHeight(String val) {
327: _height = val;
328: }
329:
330: /**
331: * Sets the horizontal margin for the table.
332: */
333: public void setHSpace(int val) {
334: _hSpace = val;
335: }
336:
337: /**
338: * This method sets the size option for the table and each cell in it. Valid return values are SIZE_PIXELS or SIZE_PERCENT.
339: */
340: public void setSizeOption(int option) {
341: _sizeOption = option;
342: }
343:
344: /**
345: * This method sets the property theme for the component.
346: * @param theme The theme to use.
347: */
348: public void setTheme(String theme) {
349: Props prop = getPage().getPageProperties();
350:
351: _border = prop.getThemeIntProperty(theme, Props.TABLE_BORDER);
352: _bgcolor = prop.getThemeProperty(theme,
353: Props.TABLE_BACKGROUND_COLOR);
354: _cellPadding = prop.getThemeIntProperty(theme,
355: Props.TABLE_CELLPADDING);
356: _cellSpacing = prop.getThemeIntProperty(theme,
357: Props.TABLE_CELLSPACING);
358:
359: _theme = theme;
360: }
361:
362: /**
363: * Sets the vertical margin for the table.
364: */
365: public void setVSpace(int val) {
366: _vSpace = val;
367: }
368:
369: /**
370: * This method sets the minimum width of the table in either pixels or percent depending on size option.
371: */
372: public void setWidth(String width) {
373: _width = width;
374: }
375:
376: /**
377: * @return the default style sheet class for rows in the table
378: */
379: public String getRowStyleClassName() {
380: return _rowStyleClass;
381: }
382:
383: /**
384: * @param string the default style sheet class for rows in the table
385: */
386: public void setRowStyleClassName(String string) {
387: _rowStyleClass = string;
388: }
389:
390: }
|