/*
* Copyright (C) 2004 TiongHiang Lee
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Email: thlee@onemindsoft.org
*/
package org.onemind.swingweb.templaterender.peerdelegate.javax.swing.table;
import java.awt.Component;
import java.awt.Rectangle;
import javax.swing.JTable;
import javax.swing.table.*;
import org.onemind.awtbridge.peer.BridgePeer;
import org.onemind.awtbridge.render.BridgeRenderContext;
import org.onemind.awtbridge.render.RenderingException;
import org.onemind.swingweb.templaterender.peerdelegate.TemplateRenderDelegate;
import org.onemind.swingweb.templaterender.peerdelegate.javax.swing.JComponentRenderDelegate;
/**
* JTableHeader render delegate
* @author TiongHiang Lee (thlee@onemindsoft.org)
*
*/
public class JTableHeaderRenderDelegate extends JComponentRenderDelegate
{
/** the instance **/
public static TemplateRenderDelegate INSTANCE = new JTableHeaderRenderDelegate();
/**
* Constructor
*/
public JTableHeaderRenderDelegate()
{
super();
}
/**
* Render a table cell using particular cell peer
* @param peer the peer
* @param context the context
* @param output the output
* @param col the column
* @throws RenderingException if there's rendering problem
*/
public void renderCell(BridgePeer peer, BridgeRenderContext context,
Object output, int col) throws RenderingException
{
JTableHeader header = (JTableHeader) peer.getComponentObject();
TableColumnModel model = header.getColumnModel();
TableColumn column = model.getColumn(col);
TableCellRenderer renderer = column.getHeaderRenderer();
if (renderer == null)
{
renderer = header.getDefaultRenderer();
}
JTable table = header.getTable();
Component com = renderer.getTableCellRendererComponent(table, column
.getHeaderValue(), false, false, 0, 0);
Rectangle rect = header.getHeaderRect(col);
com.setSize(rect.getSize());
BridgePeer cellPeer = context.getContext().getPeer(com);
if (cellPeer == null)
{
header.getTable().add(com);
com.addNotify();
cellPeer = context.getContext().getPeer(com);
}
// masquerade the peer id
String origId = cellPeer.getId();
String newId = peer.getId() + "_" + + col;
cellPeer.setId(newId); //fake it
try
{
context.renderOutput(com, output);
} finally
{
cellPeer.setId(origId); //set it back
//table.removeEditor(); //make the table not in edit state
}
//context.renderOutput(com, output);
}
}