/*
 * Created on 12.Haz.2005
 */
package com.isoft.mmcd.skin.widgets ;

import java.util.Hashtable ;

import javax.swing.ButtonGroup ;
import javax.swing.JCheckBox ;

import com.isoft.mmcd.exceptions.MMCDException ;
import com.isoft.mmcd.skin.DynamicWidgetBounds ;
import com.isoft.mmcd.skin.Widget ;
import com.isoft.mmcd.utils.cfgreader.MCCompoundProperty ;

public class MMCDCheckBox extends JCheckBox implements Widget, java.io.Serializable
{
    protected String helpId = "" ;

    protected String widgetName = "" ;

    protected String popupMenuName = null ;

    protected DynamicWidgetBounds dwbounds = null ;

    protected static Hashtable checkBoxGroups = new Hashtable( ) ;

    protected int zIndex ;

    public MMCDCheckBox( )
    {
        super( ) ;
    }
    
    
    /*
     * (non-Javadoc)
     * 
     * @see com.isoft.mmcd.skin.Widget#init(com.isoft.mmcd.utils.cfgreader.MCCompoundProperty)
     */
    public boolean init( MCCompoundProperty property ) throws MMCDException
    {
        if( property.getAtomicProperty( "$grup" ) != null )
        {
            if( checkBoxGroups.get( property.getAtomicProperty( "$grup" ).getValue( ) ) == null )
                checkBoxGroups.put( property.getAtomicProperty( "$grup" ).getValue( ), new ButtonGroup( ) ) ;
            getGroup( property.getAtomicProperty( "$grup" ).getValue( ) ).add( this ) ;
        }

        if( property.getAtomicProperty( "$checked" ) != null )
            setSelected( property.getAtomicProperty( "$checked" ).getBooleanValue( ) ) ;
        return true ;
    }

    public static ButtonGroup getGroup( String groupName )
    {
        return ( ButtonGroup )checkBoxGroups.get( groupName ) ;
    }

    public static ButtonGroup getNotNullGroup( String groupName )
    {
        if( !checkBoxGroups.containsKey( groupName ) )
            checkBoxGroups.put( groupName, new ButtonGroup( ) ) ;
        return ( ButtonGroup )checkBoxGroups.get( groupName ) ;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.isoft.mmcd.skin.Widget#setWidgetName(java.lang.String)
     */
    public void setWidgetName( String widgetName )
    {
        this.widgetName = widgetName ;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.isoft.mmcd.skin.Widget#getWidgetName()
     */
    public String getWidgetName( )
    {
        return widgetName ;
    }

    /* (non-Javadoc)
     * @see com.isoft.mmcd.skin.Widget#getPopUpMenuName()
     */
    public String getPopUpMenuName( )
    {        
        return this.popupMenuName ;
    }

    /* (non-Javadoc)
     * @see com.isoft.mmcd.skin.Widget#setPopUpMenuName(java.lang.String)
     */
    public void setPopUpMenuName( String popupMenuName )
    {
        this.popupMenuName = popupMenuName ;
    }
    /* (non-Javadoc)
     * @see com.isoft.mmcd.skin.Widget#setHelpId(java.lang.String)
     */
    public void setHelpId( String helpId )
    {
        this.helpId = helpId ;
    }

    /* (non-Javadoc)
     * @see com.isoft.mmcd.skin.Widget#getHelpId()
     */
    public String getHelpId( )
    {
        return this.helpId ;
    }


}