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: * HTMLTableFooterUI defines a look and feel for default HTML.
018: *
019: * @author Robin Sharp
020: */
021:
022: public class HTMLTableFooterUI extends HTMLComponentUI {
023: /**
024: * Render the UI on the PrintWriter
025: */
026: public void update(Object out, SComponent c) {
027: update((PrintWriter) out, c);
028: }
029:
030: /**
031: * Render the UI on the PrintWriter
032: */
033: public void update(PrintWriter out, SComponent c) {
034: STableFooter tableFooter = (STableFooter) c;
035: STable table = tableFooter.getTable();
036:
037: if (!tableFooter.isVisible())
038: return;
039: if (table.getColumnCount() == 0) {
040: return;
041: }
042: out.println("<TR>");
043:
044: int alignment = 0;
045:
046: STableCellRenderer footerCellRenderer = tableFooter
047: .getTableFooterRenderer();
048:
049: out.print("<TD ");
050: if (tableFooter.getBackground() != null) {
051: out.print(" BGCOLOR=\"#"
052: + SColor.toHexString(tableFooter.getBackground())
053: + "\"");
054: } else {
055: out.print(" BGCOLOR=\"#"
056: + SColor.toHexString(getTheme().getControl())
057: + "\"");
058: }
059:
060: out.print(" COLSPAN=" + table.getColumnCount());
061: //Horizontal Alignment
062: alignment = tableFooter.getHorizontalAlignment();
063: if (alignment == SConstants.LEFT) {
064: out.print(" ALIGN=LEFT");
065: } else if (alignment == SConstants.CENTER) {
066: out.print(" ALIGN=CENTER");
067: } else if (alignment == SConstants.RIGHT) {
068: out.print(" ALIGN=RIGHT");
069: }
070:
071: //Vertical Alignment
072: alignment = tableFooter.getVerticalAlignment();
073: if (alignment == SConstants.TOP) {
074: out.print(" VALIGN=TOP");
075: } else if (alignment == SConstants.MIDDLE) {
076: out.print(" VALIGN=MIDDLE");
077: } else if (alignment == SConstants.BOTTOM) {
078: out.print(" VALIGN=BOTTOM");
079: }
080: out.print(">");
081:
082: SComponent component = null;
083:
084: for (int label = 0; label < tableFooter.getLabelCount(); label++) {
085:
086: //Load the component to render the header
087: if (footerCellRenderer != null) {
088: component = footerCellRenderer
089: .getTableCellRendererComponent(table,
090: tableFooter.getLabel(label), -1, label);
091: }
092:
093: //PAINT THE HEADER CELL AS A COMPONENT OR TEXT
094: if (component != null) {
095: //Change the look and feel to that of the table.
096: component.setLookAndFeel(table.getLookAndFeel());
097:
098: if (component.getForeground() == null) {
099: if (tableFooter.getForeground() != null) {
100: component.setForeground(tableFooter
101: .getForeground());
102: } else {
103: component.setForeground(getTheme()
104: .getControlTextColor());
105: }
106: }
107:
108: if (component.getFont() == null) {
109: if (tableFooter.getFont() != null) {
110: component.setFont(tableFooter.getFont());
111: } else {
112: component.setFont(getTheme()
113: .getControlTextFont());
114: }
115: }
116: component.paint(out);
117: out.print(" ");
118:
119: }
120:
121: }
122: out.println("</TD>");
123: out.println("</TR>");
124:
125: }
126:
127: // PRIVATE //////////////////////////////////////////////////////////////////////////
128:
129: }
|