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: * HTMLTableHeaderUI defines a look and feel for default HTML.
018: *
019: * @author Robin Sharp
020: */
021:
022: public class HTMLTableHeaderUI 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: STableHeader tableHeader = (STableHeader) c;
035: STable table = tableHeader.getTable();
036:
037: if (!tableHeader.isVisible())
038: return;
039:
040: out.println("<TR>");
041:
042: int alignment = 0;
043:
044: STableCellRenderer headerCellRenderer = tableHeader
045: .getTableHeaderRenderer();
046: SComponent component = null;
047:
048: for (int column = 0; column < table.getColumnCount(); column++) {
049: String columnName = table.getModel().getColumnName(column);
050:
051: out.print("<TD");
052:
053: //Horizontal Alignment
054: alignment = tableHeader.getHorizontalAlignment();
055: if (alignment == SConstants.LEFT) {
056: out.print(" ALIGN=LEFT");
057: } else if (alignment == SConstants.CENTER) {
058: out.print(" ALIGN=CENTER");
059: } else if (alignment == SConstants.RIGHT) {
060: out.print(" ALIGN=RIGHT");
061: }
062:
063: //Vertical Alignment
064: alignment = tableHeader.getVerticalAlignment();
065: if (alignment == SConstants.TOP) {
066: out.print(" VALIGN=TOP");
067: } else if (alignment == SConstants.MIDDLE) {
068: out.print(" VALIGN=MIDDLE");
069: } else if (alignment == SConstants.BOTTOM) {
070: out.print(" VALIGN=BOTTOM");
071: }
072:
073: //Load the component to render the header
074: if (headerCellRenderer != null) {
075: component = headerCellRenderer
076: .getTableCellRendererComponent(table,
077: columnName, -1, column);
078: }
079:
080: //PAINT THE HEADER CELL AS A COMPONENT OR TEXT
081: if (component != null) {
082: //Change the look and feel to that of the table.
083: component.setLookAndFeel(table.getLookAndFeel());
084:
085: if (component.getBackground() != null) {
086: out.print(" BGCOLOR=\"#"
087: + SColor.toHexString(component
088: .getBackground()) + "\"");
089: } else if (tableHeader.getBackground() != null) {
090: out.print(" BGCOLOR=\"#"
091: + SColor.toHexString(tableHeader
092: .getBackground()) + "\"");
093: } else {
094: out.print(" BGCOLOR=\"#"
095: + SColor.toHexString(getTheme()
096: .getControl()) + "\"");
097: }
098:
099: if (component.getForeground() == null) {
100: if (tableHeader.getForeground() != null) {
101: component.setForeground(tableHeader
102: .getForeground());
103: } else {
104: component.setForeground(getTheme()
105: .getControlTextColor());
106: }
107: }
108:
109: if (component.getFont() == null) {
110: if (tableHeader.getFont() != null) {
111: component.setFont(tableHeader.getFont());
112: } else {
113: component.setFont(getTheme()
114: .getControlTextFont());
115: }
116: }
117:
118: out.print(">");
119: component.paint(out);
120: out.println("</TD>");
121: } else {
122: if (tableHeader.getBackground() != null) {
123: out.print(" BGCOLOR=\"#"
124: + SColor.toHexString(tableHeader
125: .getBackground()) + "\"");
126: } else {
127: out.print(" BGCOLOR=\"#"
128: + SColor.toHexString(getTheme()
129: .getControl()) + "\"");
130: }
131:
132: out.print(">");
133: out.print(columnName);
134: out.println("</TD>");
135: }
136:
137: }
138: out.println("</TR>");
139:
140: }
141:
142: // PRIVATE //////////////////////////////////////////////////////////////////////////
143:
144: }
|