package com.uvigo.mhp.looks;

import java.awt.*;
import org.dvb.ui.*;
import org.havi.ui.*;

public class HGraphicLook1 extends HGraphicLook
{
    public void showLook(Graphics g, HVisible visible, int state)
    {
        if (g instanceof DVBGraphics)
        {
            DVBGraphics g2=(DVBGraphics) g;
            DVBAlphaComposite a=DVBAlphaComposite.getInstance(DVBAlphaComposite.SRC_OVER);
            try
            {
                g2.setDVBComposite(a);
            }
            catch(Exception e)
            {
                System.out.println("No se puede aplicar la regla de composicion");
            }
        }
        
        if (visible.getBackgroundMode()==HVisible.BACKGROUND_FILL)
        {
            g.setColor(visible.getBackground());
            g.fillRect(0,0,visible.getSize().width,visible.getSize().height);
        }

        Image img=visible.getGraphicContent(state);
        if (img==null) return;
        
        int width=img.getWidth(null);
        int height=img.getHeight(null);
        int hpos=0, vpos=0;
        
        if (visible.getSize().width>width)
        {
            switch (visible.getHorizontalAlignment())
            {
                case HVisible.HALIGN_LEFT:
                    hpos=0;
                    break;
                case HVisible.HALIGN_RIGHT:
                    hpos=visible.getSize().width-width;
                    break;
                case HVisible.HALIGN_CENTER:
                    hpos=(visible.getSize().width-width)/2;
                    break;
                default:
                    hpos=0;
            }
        }
        else
            hpos=0;
        
        if (visible.getSize().height>height)
        {
            switch (visible.getVerticalAlignment())
            {
                case HVisible.VALIGN_TOP:
                    vpos=0;
                    break;
                case HVisible.VALIGN_BOTTOM:
                    vpos=visible.getSize().height-height;
                    break;
                case HVisible.VALIGN_CENTER:
                    vpos=(visible.getSize().height-height)/2;
                    break;
                default:
                    vpos=0;
            }
        }
        else
            vpos=0;
        
        g.drawImage(img,hpos,vpos,width,height,null);
    }
}
