001: /*
002: * Copyright Javelin Software, All rights reserved.
003: */
004:
005: package com.javelin.swinglets.table;
006:
007: import java.awt.*;
008: import java.util.*;
009: import java.io.*;
010:
011: import javax.swing.table.*;
012: import com.javelin.swinglets.*;
013: import com.javelin.swinglets.table.*;
014: import com.javelin.swinglets.plaf.*;
015:
016: /**
017: * STableHeader defines a table header.
018: *
019: * @author Robin Sharp
020: */
021:
022: public class STableHeader extends SComponent {
023: /**
024: * Constant for the column index.
025: */
026: public final static String SOURCE_COLUMN = "_SOURCE_COLUMN";
027:
028: /**
029: * Creates a STableHeader.
030: * This defaults to invisible.
031: */
032: public STableHeader(STable table) {
033: this .table = table;
034: }
035:
036: /**
037: * Returns the name of the class for L&F of this component.
038: */
039: public Class getUIClass() {
040: return STableHeader.class;
041: }
042:
043: /**
044: * Get the table for this STableHeader.
045: */
046: public STable getTable() {
047: return table;
048: }
049:
050: /**
051: * Get the table for this STableHeader.
052: */
053: public STableHeader setTable(STable table) {
054: if (getTable() == table)
055: return this ;
056:
057: if (table != null) {
058: table.setTableHeader(this );
059: }
060:
061: this .table = table;
062:
063: return this ;
064: }
065:
066: /**
067: * Set Table header renderer for each look and feel.
068: */
069: public STableHeader setTableHeaderRenderer(String lookAndFeel,
070: STableCellRenderer tableHeaderRenderer) {
071: tableHeaderRenderers.put(lookAndFeel, tableHeaderRenderer);
072:
073: return this ;
074: }
075:
076: /**
077: * Get Table header renderer, for the current look and feel.
078: */
079: public STableCellRenderer getTableHeaderRenderer() {
080: return getTableHeaderRenderer(getLookAndFeel().getClass()
081: .getName());
082: }
083:
084: /**
085: * Get Table header renderer, or null.
086: * <P>
087: * If a renderer has not been installed for the look and feel, it is.
088: * picked up from the LookAndFeel as SLookAndFeel.TABLE_DEFAULT_HEADER_RENDERER.
089: */
090: public STableCellRenderer getTableHeaderRenderer(String lookAndFeel) {
091: STableCellRenderer renderer = (STableCellRenderer) tableHeaderRenderers
092: .get(lookAndFeel);
093:
094: if (renderer == null) {
095: Class clazz = getLookAndFeel().getUIDefaults()
096: .getTableCellRenderer(
097: SLookAndFeel.TABLE_DEFAULT_HEADER_RENDERER);
098:
099: //System.out.println( lookAndFeel + " " + clazz.getName() );
100:
101: if (clazz != null) {
102: try {
103: renderer = (STableCellRenderer) clazz.newInstance();
104: } catch (Exception e) {
105: throw new IllegalArgumentException(
106: "Cannot load header renderer for class "
107: + clazz.getName());
108: }
109: }
110:
111: if (renderer != null) {
112: tableHeaderRenderers.put(lookAndFeel, renderer);
113: }
114: }
115:
116: return renderer;
117: }
118:
119: // PRIVATE //////////////////////////////////////////////////////////////
120:
121: protected STable table;
122:
123: protected Hashtable tableHeaderRenderers = new Hashtable();
124:
125: }
|