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

import java.awt.Dimension ;
import java.awt.Rectangle ;

import javax.swing.JLabel ;

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


public class MMCDLabel extends JLabel implements java.io.Serializable, Widget, ResizableWidget
{
    protected String helpId = "" ;

    protected String widgetName = "" ;
    
    protected String popupMenuName = null ;

    protected DynamicWidgetBounds dwbounds = null ;

    protected int zIndex ;

    /** Creates a new instance of MMCDTextField */
    public MMCDLabel( )
    { 
        super( ) ;
    }

    public boolean init( MCCompoundProperty property ) throws MMCDException
    {
        MCProperty p = property.getAtomicProperty( "$align" ) ;
        if( p != null )
        {
            if( p.getNumValues( ) > 0 )
            {
                if( "left".equals( p.getValue( ) ) || "sol".equals( p.getValue( ) ) )
                    this.setHorizontalAlignment( LEFT ) ;
                else if( "right".equals( p.getValue( ) ) || "sag".equals( p.getValue( ) ) )
                    this.setHorizontalAlignment( RIGHT ) ;
                else if( "center".equals( p.getValue( ) ) || "orta".equals( p.getValue( ) ) )
                    this.setHorizontalAlignment( CENTER ) ;
                else if( "leading".equals( p.getValue( ) ) || "basa".equals( p.getValue( ) ) )
                    this.setHorizontalAlignment( LEADING ) ;
                else if( "trailing".equals( p.getValue( ) ) || "sona".equals( p.getValue( ) ) )
                    this.setHorizontalAlignment( TRAILING ) ;
            }
            if( p.getNumValues( ) > 1 )
            {
                if( "top".equals( p.getValue( 1 ) ) || "ust".equals( p.getValue( 1 ) ) )
                    this.setHorizontalAlignment( TOP ) ;
                else if( "bottom".equals( p.getValue( 1 ) ) || "alt".equals( p.getValue( 1 ) ) )
                    this.setHorizontalAlignment( BOTTOM ) ;
                else if( "center".equals( p.getValue( 1 ) ) || "orta".equals( p.getValue( 1 ) ) )
                    this.setHorizontalAlignment( CENTER ) ;
            }
        }
        return true ;
    }

    public String getWidgetName( )
    {
        return widgetName ;
    }

    public void setWidgetName( String widgetName )
    {
        this.widgetName = widgetName ;
    }

    public DynamicWidgetBounds getDynamicWidgetBounds( )
    {
        return dwbounds ;
    }

    public void setDynamicWidgetBounds( DynamicWidgetBounds dwb )
    {
        this.dwbounds = dwb ;
    }

    public void resizeWidget( Rectangle newParentBounds )
    {
        getDynamicWidgetBounds( ).calculateBounds( newParentBounds ) ;
        setBounds( getDynamicWidgetBounds( ).getBounds( ) ) ;
        setPreferredSize( new Dimension( getDynamicWidgetBounds( ).getBounds( ).width, getDynamicWidgetBounds( ).getBounds( ).height ) ) ;
    }

    /* (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 ;
    }

}