001: /*
002: * Copyright Javelin Software, All rights reserved.
003: */
004:
005: package com.javelin.swinglets.plaf.wml;
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:
015: /**
016: * WMLTableUI defines a look and feel for default WML.
017: *
018: * @author Robin Sharp
019: */
020:
021: public class WMLTableUI extends WMLComponentUI {
022:
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: out.print(" columns=\"");
035: out.print(table.getColumnCount());
036: out.print("\"");
037:
038: out.println(" >");
039:
040: Object cell = null;
041: SComponent component = null;
042:
043: /* WHERE ?
044: if( table.getHorizontalAlignmentAt( column ) == SConstants.LEFT ) out.print( "alignment=L" );
045: else if( table.getHorizontalAlignmentAt( column ) == SConstants.CENTER )out.print( "alignment=C" );
046: else if( table.getHorizontalAlignmentAt( column ) == SConstants.RIGHT ) out.print( "alignment=R" );
047: */
048:
049: if (table.getTableHeader() != null) {
050: table.getTableHeader().getUI().update(out,
051: table.getTableHeader());
052: }
053:
054: STableCellRenderer tableCellRenderer = table
055: .getTableCellRenderer();
056:
057: for (int row = 0; row < table.getRowCount(); row++) {
058: out.println("<tr>");
059:
060: for (int column = 0; column < table.getColumnCount(); column++) {
061: cell = table.getValueAt(row, column);
062:
063: if (cell instanceof STable.Cell) {
064: cell = null;
065: }
066:
067: //Get the component if there is one
068: if (tableCellRenderer != null) {
069: component = tableCellRenderer
070: .getTableCellRendererComponent(table, cell,
071: row, column);
072: if (component != null) {
073: //Change the look and feel to that of the table.
074: component
075: .setLookAndFeel(table.getLookAndFeel());
076: }
077: } else if (cell instanceof SComponent) {
078: component = (SComponent) cell;
079: }
080:
081: //Render the component
082: if (component != null) {
083: out.print("<td>");
084: component.paint(out);
085: out.println("</td>");
086: } else if (cell != null) {
087: out.print("<td>");
088: out.print(cell);
089: out.println("</td>");
090: } else {
091: out.print("<td>");
092: out.println("</td>");
093: }
094: }
095: out.println("</tr>");
096: }
097:
098: out.println("</table>");
099:
100: }
101:
102: }
|