/*
 * Created on Aug 17, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package hibergui.property;

import hibergui.Edit;
import hibergui.Form;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

/**
 * @author espakm
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class CheckBoxEdit extends Edit<Boolean> {
    
    protected Button cbx;
    
    public CheckBoxEdit(Form form, Composite cptParent, int style, String prop, String name) {
        super(form, cptParent, style, prop, name);
        
        cbx.addSelectionListener(lsn_WIDGET_MOD);
        cbx.addKeyListener(lsn_WIDGET_KEY);
        cbx.addFocusListener(lsn_WIDGET_FOCUS);
        cbx.addTraverseListener(lsn_TRAVERSE);
    }
    
    public void setLabel(String label) {
        cbx.setText(label);
    }
    
    @Override
    protected Control createContents(Composite cptParent) {
        return cbx = new Button(cptParent, SWT.CHECK);
    }
    
    @Override
    public void clear() {
        cbx.setSelection(false);
    }
    
    @Override
    public void fill() {
        cbx.setSelection(value.booleanValue());
    }
    
    @Override
    public Boolean extract() {
        return cbx.getSelection() ? Boolean.TRUE : Boolean.FALSE; 
    }
    
    @Override
    public void setBackground(Color clr) {
    	cbx.setBackground(clr);
    }
    
    @Override
    public boolean setFocus() {
        return cbx.setFocus();
    }
    
    @Override
    public boolean isEnabled() {
        return cbx.isEnabled();
    }
    
    @Override
    public void setEnabled(boolean b) {
        cbx.setEnabled(b);
    }
    
	@Override
	public void setEditable(boolean b) {
		cbx.setEnabled(b);
	}
}
