/*
 * 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/winpack/license.jsf
 */
package com.jniwrapper.win32.samples.demo;

import com.jniwrapper.win32.gdi.SystemColor;
import com.jniwrapper.win32.ui.controls.ChooseColorField;
import com.jniwrapper.samples.shell.components.LazyPanel;
import com.jniwrapper.samples.shell.components.HTMLText;

import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

/**
 @author Serge Piletsky
 */
public class SystemColorsSample extends LazyPanel implements PropertyChangeListener
{
    private JLabel lblAdvisoryText;
    private JLabel lblDesktopColor;
    private ChooseColorField fldDesktopColor;
    private JLabel lblMenuColor;
    private ChooseColorField fldMenuColor;
    private JLabel lblMenuTextColor;
    private ChooseColorField fldMenuTextColor;
    private JLabel lblInactiveCaptionColor;
    private ChooseColorField fldInactiveCaptionColor;
    private JLabel lblActiveCaptionColor;
    private ChooseColorField fldActiveCaptionColor;

    public SystemColorsSample(Window parent)
    {
        super(parent);
    }

    public void initialize() throws Exception
    {
        lblAdvisoryText = new HTMLText("This page shows colors set in your Windows Appearance schema using the SystemColor class functions." +
                "<br><br><b>NOTE:</b> The WinPackDemo uses these colors as well.<br><br>Be carefull" +
                " changing colours as the changes are applied automatically to your Windows Appearance schema.");

        lblDesktopColor = new JLabel("Desktop Color:");
        fldDesktopColor = new ChooseColorField(SystemColor.DESKTOP.getColor());
        fldDesktopColor.addPropertyChangeListener(ChooseColorField.PROPERTY_COLOR, this);

        lblMenuColor = new JLabel("Menu Color:");
        fldMenuColor = new ChooseColorField(SystemColor.MENU.getColor());
        fldMenuColor.addPropertyChangeListener(ChooseColorField.PROPERTY_COLOR, this);

        lblMenuTextColor = new JLabel("Menu Text Color:");
        fldMenuTextColor = new ChooseColorField(SystemColor.MENUTEXT.getColor());
        fldMenuTextColor.addPropertyChangeListener(ChooseColorField.PROPERTY_COLOR, this);

        lblInactiveCaptionColor = new JLabel("Inactive Caption Color:");
        fldInactiveCaptionColor = new ChooseColorField(SystemColor.INACTIVECAPTION.getColor());
        fldInactiveCaptionColor.addPropertyChangeListener(ChooseColorField.PROPERTY_COLOR, this);

        lblActiveCaptionColor = new JLabel("Active Caption Color:");
        fldActiveCaptionColor = new ChooseColorField(SystemColor.ACTIVECAPTION.getColor());
        fldActiveCaptionColor.addPropertyChangeListener(ChooseColorField.PROPERTY_COLOR, this);

        setLayout(new GridBagLayout());

        add(lblAdvisoryText, new GridBagConstraints(00210.00.0
                , GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10102010)00));

        add(lblDesktopColor, new GridBagConstraints(01110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0101010)00));

        add(fldDesktopColor, new GridBagConstraints(11110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0101010)00));

        add(lblMenuColor, new GridBagConstraints(02110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0101010)00));

        add(fldMenuColor, new GridBagConstraints(12110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0101010)00));

        add(lblMenuTextColor, new GridBagConstraints(03110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0101010)00));

        add(fldMenuTextColor, new GridBagConstraints(13110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0101010)00));

        add(lblInactiveCaptionColor, new GridBagConstraints(04110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0101010)00));

        add(fldInactiveCaptionColor, new GridBagConstraints(14110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0101010)00));

        add(lblActiveCaptionColor, new GridBagConstraints(05110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0101010)00));

        add(fldActiveCaptionColor, new GridBagConstraints(15110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0101010)00));

        add(new JPanel()new GridBagConstraints(06211.01.0
                , GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0000)00));

        super.initialize();
    }

    public void propertyChange(PropertyChangeEvent evt)
    {
        if (evt.getSource().equals(fldDesktopColor))
        {
            SystemColor.DESKTOP.setColor((Color)evt.getNewValue());
        }
        else if (evt.getSource().equals(fldMenuColor))
        {
            SystemColor.MENU.setColor((Color)evt.getNewValue());
        }
        else if (evt.getSource().equals(fldMenuTextColor))
        {
            SystemColor.MENUTEXT.setColor((Color)evt.getNewValue());
        }
        else if (evt.getSource().equals(fldInactiveCaptionColor))
        {
            SystemColor.INACTIVECAPTION.setColor((Color)evt.getNewValue());
        }
        else if (evt.getSource().equals(fldActiveCaptionColor))
        {
            SystemColor.ACTIVECAPTION.setColor((Color)evt.getNewValue());
        }
    }
}