/*
 * 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.DefaultLibraryLoader;
import com.jniwrapper.samples.shell.BasicDemoShell;
import com.jniwrapper.util.Logger;
import com.jniwrapper.win32.gdi.Icon;
import com.jniwrapper.win32.ui.Wnd;

import javax.swing.*;
import java.awt.*;
import java.io.IOException;

/**
 @author Serge Piletsky
 @author Vladimir Kondrashchenko
 */
public class ComfyjDemo extends BasicDemoShell
{
    private static final Logger LOG = Logger.getInstance(ComfyjDemo.class);
    private static final String xmlFile = "ComfyjDemo.xml";

    public ComfyjDemo() throws IOException
    {
        super(ComfyjDemo.class.getResource(xmlFile).openStream(), SourcePanel.class);
    }

    private static void createGUI()
    {
        ComfyjDemo window = null;
        try
        {
            window = new ComfyjDemo();
        }
        catch (IOException e)
        {
            LOG.error("", e);
            System.exit(1);
        }
        window.setSize(750630);
        final Dimension screenSize = window.getToolkit().getScreenSize();
        window.setLocation((screenSize.width - window.getWidth()) 2(screenSize.height - window.getHeight()) 2);
        window.setVisible(true);
        try
        {
            Wnd decorator = new Wnd(window);
            Icon bigIcon = new Icon(ComfyjDemo.class.getResourceAsStream("res/ComfyJ.ico"), Icon.IconType.BIG.getSize());
            Icon smallIcon = new Icon(ComfyjDemo.class.getResourceAsStream("res/ComfyJ.ico"), Icon.IconType.SMALL.getSize());
            decorator.setWindowIcon(smallIcon, Icon.IconType.SMALL);
            decorator.setWindowIcon(bigIcon, Icon.IconType.BIG);
        }
        catch (IOException e)
        {
            LOG.error("", e);
        }
    }

    public static void main(String[] args)
    {
        DefaultLibraryLoader.getInstance().addPath("bin");

        try
        {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch (Exception e)
        {
            LOG.error("", e);
        }

        SwingUtilities.invokeLater(new Runnable()
        {
            public void run()
            {
                createGUI();
            }
        });
    }
}