package leaf.ui;

import java.awt.Insets;

import com.evolute.utils.images.ImageException;
import com.evolute.utils.images.ImageIconLoader;

public class LeafIconButton extends LeafButton implements LeafUIConstants
{
	private static final long serialVersionUID = 1L;

	private LeafIconButton( String imagePath ) throws ImageException
	{
		super(ImageIconLoader.loadImageIcon( imagePath ));
	}
	
	public static LeafIconButton createDefaultNewButton()
	{
		LeafIconButton result =  createButton( ICON_NAME_CREATE );
		result.setToolTipText( "Criar" );
		return result;
	}
	
	public static LeafIconButton createDefaultEditButton()
	{
		LeafIconButton result =  createButton( ICON_NAME_EDIT );
		result.setToolTipText( "Editar" );
		return result;
	}
	
	public static LeafIconButton createDefaultRemoveButton()
	{
		LeafIconButton result =  createButton( ICON_NAME_REMOVE );
		result.setToolTipText( "Remover" );
		return result;
	}
	
	public static LeafIconButton createButton( String imagePath )
	{
		LeafIconButton result = null;
		if( imagePath != null )
		{
			try
			{
				result = new LeafIconButton(imagePath);
				result.setMargin( new Insets(0,0,0,0) );
			} catch( ImageException e )
			{
				e.printStackTrace();
			}
		}
		return result;
	}
	
	public static LeafIconButton createButton( String title, String imagePath )
	{
		LeafIconButton result = createButton( imagePath );
		if( result != null )
		{
			result.setText( title );
		}
		return result;
	}
	
}
