/*
 * IntegerRenderer.java
 *
 * Created on September 21, 2000, 3:01 PM
 */
package CITableTest;

import javax.swing.table.TableCellRenderer;
import javax.swing.JTextField;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import java.text.DecimalFormat;
import java.awt.Component;

/** Table cell renderer for java.lang.Byte and java.lang.Integer.
 *
 * @author  Somchai LIMSIRORATANA, Nuntiya LIMSIRORATANA(Yawai)
 * @version 1.1
 */
public class NumberCellRenderer extends JTextField implements TableCellRenderer {
    protected DecimalFormat formatter = new DecimalFormat();
    /** Creates new IntegerRenderer */
    public NumberCellRenderer() {
        setEditable(false);
        setHorizontalAlignment(SwingConstants.RIGHT);
        formatter.setMaximumFractionDigits(4);
    }

    /** This method is sent to the renderer by the drawing table to
     * configure the renderer appropriately before drawing.  Return
     * the Component used for drawing.
     *
     * @param   table       the JTable that is asking the renderer to draw.
     *              This parameter can be null.
     * @param   value       the value of the cell to be rendered.  It is
     *              up to the specific renderer to interpret
     *              and draw the value.  eg. if value is the
     *              String "true", it could be rendered as a
     *              string or it could be rendered as a check
     *              box that is checked.  null is a valid value.
     * @param   isSelected  true is the cell is to be renderer with
     *              selection highlighting
     * @param   row         the row index of the cell being drawn.  When
     *              drawing the header the rowIndex is -1.
     * @param   column          the column index of the cell being drawn
     */
    public Component getTableCellRendererComponent(JTable table,Object value,boolean isSelected,boolean hasFocus,int row,int column) {
        setText(value.toString());
        if (table != null)
            if (table.isCellEditable(row, column)) 
                setForeground(CellRendererConstants.EDITABLE_COLOR);
            else
                setForeground(CellRendererConstants.UNEDITABLE_COLOR);
        setBackground(table.getBackground());
        return this;
    }
}