/*
 * Copyright (c) 2002-2007 TeamDev Ltd. All rights reserved.
 *
 * Use is subject to license terms.
 *
 * The complete licence text can be found at
 * http://www.teamdev.com/comfyj/license.jsf
 */
package com.jniwrapper.win32.samples.demo;

import com.jniwrapper.win32.automation.Automation;
import com.jniwrapper.win32.automation.OleContainer;
import com.jniwrapper.win32.gdi.Region;
import com.jniwrapper.win32.gdi.Icon;
import com.jniwrapper.win32.ole.types.OleVerbs;
import com.jniwrapper.win32.ui.Wnd;

import javax.swing.ImageIcon;
import java.io.IOException;

/**
 @author Vladimir Kondrashchenko
 */
public class CustomShapePlayerContainer extends OleContainerInfoBean
{
    private Region _region;

    public CustomShapePlayerContainer()
    {
        super("MediaPlayer.MediaPlayer.1"//"WMPlayer.OCX",
                "Media Files (*.avi; *.mpg; *.mpeg; *.wmv; *.asf; *.mp3)|*.avi;*.mpg;*.mpeg;*.wmv;*.asf; *.mp3",
                "This page demonstrates the MediaPlayer ActiveX component embedded into OleContainer. The shape of the OleContainer itself is altered " +
                "(using the Region created from the image), to show video through the decorated view port.",
                "avi");

        ImageIcon image = new ImageIcon(this.getClass().getResource("res/cup.gif"));
        _region = Region.createFromImage(image.getImage());
    }

    public void loadFile(String fileName)
    {
        final OleContainer container = getContainer();
        Automation automation = new Automation(container.getOleObject());
        automation.setProperty("FileName", fileName);
        container.doVerb(OleVerbs.INPLACEACTIVATE);
    }

    public ImageIcon getIcon()
    {
        Icon icon = null;
        try
        {
            icon = new Icon(ComfyjDemo.class.getResourceAsStream("res/jniwrapper.ico"), Icon.IconType.SMALL.getSize());
        }
        catch (IOException e)
        {
        }
        if (icon == null)
        {
            return super.getIcon();
        }
        else
        {
            return new ImageIcon(icon.toImage());
        }
    }

    public void activate()
    {
        final OleContainer container = getContainer();
        container.doVerb(OleVerbs.INPLACEACTIVATE);

        Wnd containerWnd = new Wnd(container);
        containerWnd.setRegion(_region, true);
    }


}