package org.bitstrings.maven.plugins.splasher;

import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.List;

import org.apache.maven.plugin.MojoExecutionException;
import org.bitstrings.maven.plugins.splasher.FlowLayout.Alignment;

public class DrawImagesFromText
    extends Drawable
{
    // - parameters --[

    private String text;

    private String imageNamePrefix;

    private int padding;

    private Alignment alignment = Alignment.HORIZONTAL;

    // ]--

    protected FlowLayout drawImagesFromText;

    public String getText()
    {
        return text;
    }

    public String getImageNamePrefix()
    {
        return imageNamePrefix;
    }

    public int getPadding()
    {
        return padding;
    }

    public Alignment getAlignment()
    {
        return alignment;
    }

    @Override
    public void init( Graphics2D g )
        throws MojoExecutionException
    {
        drawImagesFromText = new FlowLayout();

        drawImagesFromText.setDrawingContext( dwContext );
        drawImagesFromText.setPosition( getPosition() );
        drawImagesFromText.setAlignment( alignment );
        drawImagesFromText.setPadding( padding );

        final List<Drawable> drawables = new ArrayList<Drawable>();

        for ( int i = 0; i < text.length(); i++ )
        {
            DrawImage drawImage = new DrawImage();

            drawImage.setImageName( imageNamePrefix + text.charAt( i ) );

            drawables.add( drawImage );
        }

        drawImagesFromText.setDraw( drawables );

        super.init( g );

        Graphics2D sg = (Graphics2D) g.create();

        try
        {
            drawImagesFromText.init( sg );
        }
        finally
        {
            sg.dispose();
        }
    }

    @Override
    public void render( Graphics2D g )
    {
        Graphics2D sg = (Graphics2D) g.create();

        try
        {
            drawImagesFromText.draw( sg );
        }
        finally
        {
            sg.dispose();
        }
    }
}

@@ -1539,34 +1539,8 @@
 );%0A%0A
-        super.init( g );%0A%0A
     
@@ -1717,24 +1717,87 @@
 );%0A        %7D
+%0A%0A        dwBounds.setBounds( drawImagesFromText.getBounds() );
 %0A    %7D%0A%0A    

fix bounds (was off)