/*
 * 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.Int32;
import com.jniwrapper.util.Logger;
import com.jniwrapper.win32.automation.Automation;
import com.jniwrapper.win32.automation.OleContainer;
import com.jniwrapper.win32.ole.types.OleVerbs;
import com.jniwrapper.win32.gdi.*;

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

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

    private JLabel lblTrackType;
    private JLabel lblVersion;
    private JTextField tfClipName;
    private JLabel lblLanguage;

    public QuickTimeContainer()
    {
        super("QuickTime.QuickTime",
                "Media Files (*.mov;*.mp3)|*.mov;*.mp3",
                "This page demonstrates the QuickTime ActiveX component embedded into OleContainer.""mov");
    }

    public void loadFile(final String fileName)
    {
        final OleContainer container = getContainer();
        Automation qt = new Automation(container.getOleObject());
        qt.invoke("setURL"new Object[] {fileName});

        String verstion = qt.invoke("getURL").getBstrVal().getValue();
        String duration = qt.invoke("getPluginVersion").getBstrVal().getValue();
        String trackType = qt.invoke("getTrackType"new Object[] { new Int32(1)}).getBstrVal().getValue();
        String language = qt.invoke("getLanguage").getBstrVal().getValue();

        tfClipName.setText(verstion);
        lblVersion.setText(duration);
        lblTrackType.setText(trackType);
        lblLanguage.setText(language);
    }

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

    public JPanel createFileInfoPanel()
    {
        JPanel fileInfo = new JPanel(new GridBagLayout());

        lblVersion = new JLabel();
        tfClipName = new JTextField();
        tfClipName.setBorder(BorderFactory.createEmptyBorder());
        tfClipName.setBackground(null);
        tfClipName.setEditable(false);
        lblTrackType = new JLabel();
        lblLanguage = new JLabel();

        fileInfo.setBorder(BorderFactory.createTitledBorder("Media File Info"));
        fileInfo.setPreferredSize(new Dimension(10075));

        JLabel lblClipNameLabel = new JLabel("Movie Name:");
        JLabel lblVersionLabel = new JLabel("QuickTime version:");
        JLabel lblTrackTypeLabel = new JLabel("Track Type:");
        JLabel lblLanguageLabel = new JLabel("Language:");

        fileInfo.add(lblClipNameLabel, new GridBagConstraints(00110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10101010)00));
        fileInfo.add(tfClipName, new GridBagConstraints(10111.00.0
                , GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(1001010)00));
        fileInfo.add(lblVersionLabel, new GridBagConstraints(01110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0101010)00));
        fileInfo.add(lblVersion, new GridBagConstraints(11111.00.0
                , GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(001010)00));
        fileInfo.add(lblTrackTypeLabel, new GridBagConstraints(20110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10101010)00));
        fileInfo.add(lblTrackType, new GridBagConstraints(30111.00.0
                , GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(1001010)00));
        fileInfo.add(lblLanguageLabel, new GridBagConstraints(21110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0101010)00));
        fileInfo.add(lblLanguage, new GridBagConstraints(31111.00.0
                , GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(001010)00));

        fileInfo.add(new Panel()new GridBagConstraints(02311.01.0
                , GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0000)00));

        return fileInfo;
    }

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