/*
 * MyCheckBoxCellEditor.java
 *
 * Created on September 20, 2007, 10:05 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package usda.weru.mcrew;

import com.klg.jclass.cell.JCCellInfo;
import com.klg.jclass.cell.editors.JCCheckBoxCellEditor;
import java.awt.AWTEvent;
import java.awt.Graphics;
import javax.swing.JComponent;
import javax.swing.JLabel;

/**
 *
 * @author Joseph Levin
 */
public class MyCheckBoxCellEditor extends JCCheckBoxCellEditor{
    private static final long serialVersionUID = 1L;
    
    private static final JComponent DUMMY = new JLabel();
    /** Creates a new instance of MyCheckBoxCellEditor */
    public MyCheckBoxCellEditor() {
        
    }
    
    @Override
    public void initialize(AWTEvent ev, JCCellInfo info, Object o) {
        try{
            if (o == null){
                super.initialize(ev, info, o);
                return;
            }
            else if(Integer.parseInt(o.toString()) == 1) {
                o = Boolean.TRUE;
            } else {
                o = Boolean.FALSE;
            }
        } catch(NumberFormatException e) {
            o = Boolean.FALSE;
        }
        super.initialize(ev, info, o);
    }

	/**
	 *
	 * @param g
	 */
	@Override
    public void paint(Graphics g) {
        if (data == null){
            DUMMY.paint(g);
        } else{
            super.paint(g);
        }
    }
    
    @Override
    public boolean isModified() {
        if (data == null){
            return false;
        } else{
            
        }
        
        boolean currentValue = getCellEditorValue().equals("1");
        return(getOriginalValue() != currentValue);
    }
    
    
    
    @Override
    public Object getCellEditorValue() {
        Object o = super.getCellEditorValue();
        if (o == null){
            return "0";
        }
        Boolean value = Boolean.parseBoolean(o.toString());
        if (value){
            return "1";
        } else{
            return "0";
        }
    }
    
    
}
