001: /*
002: * Copyright Javelin Software, All rights reserved.
003: */
004:
005: package com.javelin.swinglets.plaf.html;
006:
007: import java.awt.*;
008: import java.util.*;
009: import java.io.*;
010:
011: import com.javelin.swinglets.*;
012: import com.javelin.swinglets.table.*;
013: import com.javelin.swinglets.plaf.*;
014: import com.javelin.swinglets.theme.*;
015:
016: /**
017: * HTMLTableUI defines a look and feel for default HTML.
018: *
019: * @author Robin Sharp
020: */
021:
022: public class HTMLTableUI extends HTMLComponentUI {
023: /**
024: * Render the UI on the PrintWriter
025: */
026: public void update(PrintWriter out, SComponent c) {
027: if (!c.isVisible())
028: return;
029:
030: STable table = (STable) c;
031:
032: out.print("<TABLE ");
033:
034: //CSS Style Sheet
035: Object cssClass = c.getClientProperty(CSS_CLASS);
036: if (cssClass != null) {
037: out.print(" class=\"");
038: out.print(cssClass);
039: }
040:
041: if (table.getGridWidth() >= 0) {
042: out.print(" BORDER=");
043: out.print(table.getGridWidth());
044: }
045: if (table.getIntercellSpacing() != null) {
046: out.print(" CELLSPACING=");
047: out.print(table.getIntercellSpacing().width);
048: }
049: if (table.getIntercellPadding() != null) {
050: out.print(" CELLPADDING=");
051: out.print(table.getIntercellPadding().height);
052: }
053:
054: if (table.getBackgroundIcon() != null) {
055: out.print(" BACKGROUND=\"");
056: out.print(table.getBackgroundIcon().getUrl());
057: out.print("\"");
058: } else if (!table.isOpaque()) {
059: } else if (table.getBackground() != null) {
060: out.print(" BGCOLOR=\"#");
061: out.print(SColor.toHexString(table.getBackground()));
062: out.print("\"");
063: }
064:
065: if (table.getSize() != null) {
066: if (table.getSize().width > 0) {
067: out.print(" WIDTH=\"");
068: out.print(table.getSize().width);
069: out.print("\"");
070: } else if (table.getSize().width < 0) {
071: out.print(" WIDTH=\"");
072: out.print((0 - table.getSize().width));
073: out.print("%\"");
074: }
075:
076: if (table.getSize().height > 0) {
077: out.print(" HEIGHT=\"");
078: out.print(table.getSize().height);
079: out.print("\"");
080: } else if (table.getSize().height < 0) {
081: out.print(" HEIGHT=\"");
082: out.print((0 - table.getSize().height));
083: out.print("%\"");
084: }
085: }
086:
087: //out.print( " COLS=" + table.getColumnCount() ); buggers up NS
088:
089: out.println(" >");
090:
091: SComponent component = null;
092: Object cell = null;
093: int alignment = 0;
094: Dimension cellSpan = null;
095: SIcon icon = null;
096:
097: if (table.getTableHeader() != null) {
098: table.getTableHeader().getUI().update(out,
099: table.getTableHeader());
100: }
101:
102: STableCellRenderer tableCellRenderer = table
103: .getTableCellRenderer();
104: //UPDATE THE TABLE HEADER
105:
106: updateHeader(out, table);
107:
108: for (int row = 0; row < table.getRowCount(); row++) {
109: out.println("<TR>");
110:
111: for (int column = 0; column < table.getColumnCount(); column++) {
112: cell = table.getValueAt(row, column);
113:
114: if (cell instanceof STable.Cell) {
115: cell = null;
116: }
117:
118: //System.out.println( "column=" + column + ", row=" + row + ", value=" + cell );
119:
120: //Get the component if there is one
121: if (tableCellRenderer != null) {
122: component = tableCellRenderer
123: .getTableCellRendererComponent(table, cell,
124: row, column);
125: } else if (cell instanceof SComponent) {
126: component = (SComponent) cell;
127: }
128:
129: if (component != null) {
130: //Change the look and feel to that of the table.
131: component.setLookAndFeel(table.getLookAndFeel());
132: }
133:
134: //Abort if there is no value
135: if (cell == null && component == null) {
136: // if not row column spanned then
137: //out.print( "<TD></TD>" );
138: continue;
139: }
140:
141: //Start the cell
142: out.print("<TD ");
143:
144: if (table.getNoWrapAt(row, column) || table.isNoWrap()) {
145: out.print(" NOWRAP");
146: }
147:
148: //Horizontal Alignment
149: alignment = table.getHorizontalAlignmentAt(row, column);
150:
151: HTMLUtility.updateHorizontalAlignment(out, alignment,
152: component);
153:
154: //Vertical Alignment
155: alignment = table.getVerticalAlignmentAt(row, column);
156:
157: HTMLUtility.updateVerticalAlignment(out, alignment,
158: component);
159:
160: //Cell span
161: cellSpan = table.getCellSpanAt(row, column);
162: if (cellSpan != null) {
163: if (cellSpan.width > 0) {
164: out.print(" COLSPAN=");
165: out.print(cellSpan.width);
166: // out.print( "\"" );
167: }
168: if (cellSpan.height > 0) {
169: out.print(" ROWSPAN=");
170: out.print(cellSpan.height);
171: //out.print( "\"" );
172: }
173: }
174:
175: //Background
176: icon = table.getBackgroundIconAt(row, column);
177: if (icon != null) {
178: out.print(" BACKGROUND=");
179: out.print(icon.getUrl());
180: }
181:
182: //Render the component
183: if (component != null) {
184: if (component.getBackground() != null) {
185: out.print(" BGCOLOR=\"#");
186: out.print(SColor.toHexString(component
187: .getBackground()));
188: out.print("\"");
189: } else if (table.getBackground() != null) {
190: out.print(" BGCOLOR=\"#");
191: out.print(SColor.toHexString(table
192: .getBackground()));
193: out.print("\"");
194: }
195:
196: if (component.getForeground() == null) {
197: if (table.getForeground() != null) {
198: component.setForeground(table
199: .getForeground());
200: } else {
201: component.setForeground(getTheme()
202: .getControlTextColor());
203: }
204: }
205:
206: if (component.getFont() == null) {
207: if (table.getFont() != null) {
208: component.setFont(table.getFont());
209: } else {
210: component.setFont(getTheme()
211: .getControlTextFont());
212: }
213: }
214:
215: if (component.getSize() != null) {
216: if (component.getSize().width > 0) {
217: out.print(" WIDTH=\"");
218: out.print(component.getSize().width);
219: out.print("\"");
220: } else if (component.getSize().width < 0) {
221: out.print(" WIDTH=\"");
222: out.print((0 - component.getSize().width));
223: out.print("%\"");
224: }
225:
226: if (component.getSize().height > 0) {
227: out.print(" HEIGHT=\"");
228: out.print(component.getSize().height);
229: out.print("\"");
230: } else if (component.getSize().height < 0) {
231: out.print(" HEIGHT=\"");
232: out.print((0 - component.getSize().height));
233: out.print("%\"");
234: }
235: }
236:
237: out.print(">");
238: component.paint(out);
239: out.println("</TD>");
240: } else if (cell != null) {
241: out.print(">");
242: out.print(cell);
243: out.println("</TD>");
244: } else {
245: out.print(">");
246: out.println("</TD>");
247: }
248:
249: }
250: out.print("</TR>");
251: }
252:
253: if (table.getTableFooter() != null) {
254: table.getTableFooter().getUI().update(out,
255: table.getTableFooter());
256: }
257:
258: out.print("</TABLE>");
259: }
260:
261: // PRIVATE //////////////////////////////////////////////////////////////////////////
262:
263: }
|