package cn.com.customization.util;


import java.util.Enumeration;
import java.util.Vector;

import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;



/**
 * GroupableTableHeader
 * @author flyx
 */

public class GroupableTableHeader extends JTableHeader {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final String uiClassID = "GroupableTableHeaderUI";
    protected Vector columnGroups = null;
  public GroupableTableHeader(TableColumnModel model) {
    super(model);
    setUI(new GroupableTableHeaderUI());
    setReorderingAllowed(false);
    setRequestFocusEnabled(false);
  }                                       
public void addColumnGroup(ColumnGroup g) {
    if (columnGroups == null) {
        columnGroups = new Vector();
    }
    columnGroups.addElement(g);
}
/**
 *
 * ´´½¨ÈÕÆÚ:(2001-8-31 15:54:29)
 */
public void clearColumnGroups() {
    columnGroups = null;
}
public ColumnGroup[] getColumnGroups() {
    ColumnGroup[] retg=null;
    if (columnGroups.size()>0) {
        retg=new ColumnGroup[columnGroups.size()];
        columnGroups.copyInto(retg);
    }
    return retg;
}
public Enumeration getColumnGroups(TableColumn col) {
    if (columnGroups == null)
        return null;
    Enumeration enumi = columnGroups.elements();
    while (enumi.hasMoreElements()) {
        ColumnGroup cGroup = (ColumnGroup) enumi.nextElement();
        Vector v_ret = (Vector) cGroup.getColumnGroups(col, new Vector());
        if (v_ret != null) {
            return v_ret.elements();
        }
    }
    return null;
}
/**
 * Identifies whether or not this component can receive the focus.
 * A disabled button, for example, would return false.
 *
 * @return true if this component can receive the focus
 */
public boolean isFocusTraversable() {
    return super.isFocusTraversable() && isRequestFocusEnabled();
}
public void setColumnMargin() {
    if (columnGroups == null)
        return;
    int columnMargin = getColumnModel().getColumnMargin();
    Enumeration enumi = columnGroups.elements();
    while (enumi.hasMoreElements()) {
        ColumnGroup cGroup = (ColumnGroup) enumi.nextElement();
        cGroup.setColumnMargin(columnMargin);
    }
}
public void setReorderingAllowed(boolean b) {
    reorderingAllowed = b;
}
}


