/*
 * 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.util.Logger;

import javax.swing.*;
import javax.imageio.ImageIO;
import java.awt.*;

/**
 @author Serge Piletsky
 @author Vladimir Kondrashchenko
 */
public class ShockwaveFlashContainer extends OleContainerInfoBean
{
    private static final Logger LOG = Logger.getInstance(ShockwaveFlashContainer.class);

    private JLabel lblWindowMode;
    private JLabel lblFrames;
    private JLabel lblQuality;
    private JLabel lblScale;


    public ShockwaveFlashContainer()
    {
        super("ShockwaveFlash.ShockwaveFlash.1",
                "ShockwaveFlash files |*.swf",
                "This page demonstrates OLE Container with ShockwaveFlash ActiveX control.",
                "swf");
    }

    public void loadFile(String fileName)
    {
        final OleContainer container = getContainer();
        Automation flash = new Automation(container.getOleObject());
        flash.setProperty("Movie", fileName);
        flash.invoke("Play");

        String wMode = flash.getProperty("WMode").getBstrVal().getValue();
        String frames = String.valueOf(flash.getProperty("TotalFrames").getIntVal().getValue());
        String scale = flash.getProperty("Scale").getBstrVal().getValue();
        String quality = flash.getProperty("Quality2").getBstrVal().getValue();

        lblWindowMode.setText(wMode);
        lblFrames.setText(frames);
        lblScale.setText(scale);
        lblQuality.setText(quality);
    }

    public JPanel createFileInfoPanel()
    {
        JPanel playerInfo = new JPanel(new GridBagLayout());
        playerInfo.setBorder(BorderFactory.createTitledBorder("Player Info"));
        playerInfo.setPreferredSize(new Dimension(10075));

        JLabel lblWindowModeLabel = new JLabel("Window Mode:");
        JLabel lblFramesLabel = new JLabel("Number of Frames:");
        JLabel lblScaleLabel = new JLabel("Display Scale:");
        JLabel lblQualityLabel = new JLabel("Display Quality:");

        lblFrames = new JLabel();
        lblQuality = new JLabel();
        lblScale = new JLabel();
        lblWindowMode = new JLabel();

        playerInfo.add(lblWindowModeLabel, new GridBagConstraints(00110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10101010)00));
        playerInfo.add(lblWindowMode, new GridBagConstraints(10111.00.0
                , GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(1001010)00));
        playerInfo.add(lblFramesLabel, new GridBagConstraints(01110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0101010)00));
        playerInfo.add(lblFrames, new GridBagConstraints(11111.00.0
                , GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(001010)00));
        playerInfo.add(lblScaleLabel, new GridBagConstraints(20110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10101010)00));
        playerInfo.add(lblScale, new GridBagConstraints(30111.00.0
                , GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(1001010)00));
        playerInfo.add(lblQualityLabel, new GridBagConstraints(21110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0101010)00));
        playerInfo.add(lblQuality, new GridBagConstraints(31111.00.0
                , GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(001010)00));

        playerInfo.add(new Panel()new GridBagConstraints(02411.01.0
                , GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0000)00));

        return playerInfo;
    }

    public ImageIcon getIcon()
    {
        ImageIcon icon = null;
        try
        {
            icon = new ImageIcon(ImageIO.read(ExcelContainer.class.getResourceAsStream("res/flash.png")));
        }
        catch (Exception e)
        {
            LOG.error("", e);
        }
        return icon;
    }
}