/*
 * 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.util.ProcessorInfo;
import com.jniwrapper.win32.system.MemoryStatus;
import com.jniwrapper.samples.shell.components.LazyPanel;
import com.jniwrapper.samples.shell.components.HTMLText;
import com.jniwrapper.samples.shell.components.LineBevel;

import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.net.URL;
import java.net.MalformedURLException;

/**
 @author Serge Piletsky
 */
public class SystemInfoSample extends LazyPanel
{
    private JLabel lblAdvisoryText;
    private JLabel lblProcessorInformation;
    private JLabel lblVendorCaption;
    private JLabel lblVendor;
    private JLabel lblProcessorNameCaption;
    private JLabel lblProcessorName;
    private JLabel lblFrequencyCaption;
    private JLabel lblFrequency;
    private JLabel lblFamilyCaption;
    private JLabel lblFamily;
    private JLabel lblModelCaption;
    private JLabel lblModel;
    private JLabel lblSteppingCaption;
    private JLabel lblStepping;
    private JCheckBox chkFPU;
    private JCheckBox chkMMX;
    private JCheckBox chkMMXPlus;
    private JCheckBox chk3DNow;
    private JCheckBox chk3DNowPlus;
    private JCheckBox chkSSE;
    private JCheckBox chkSSE2;
    private JLabel lblMemoryInformationCaption;
    private JLabel lblPhisicalTotalCaption;
    private JLabel lblPhisicalAvailableCaption;
    private JLabel lblPhisicalTotal;
    private JLabel lblPhisicalAvailable;

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

    public void initialize() throws Exception
    {
        ProcessorInfo info = ProcessorInfo.getInstance();
        lblAdvisoryText = new HTMLText("This page displays information about your processor using ProcessorInfo class and memory information using MemoryStatus class.");
        lblProcessorInformation = new JLabel("Processor Information:");
        lblVendorCaption = new JLabel("Vendor:");
        lblVendor = new JLabel(info.getVendor());
        lblProcessorNameCaption = new JLabel("Processor Name:");
        lblProcessorName = new JLabel(info.getProcessorName());
        lblFrequencyCaption = new JLabel("Frequency:");
        lblFrequency = new JLabel(String.valueOf(info.getFrequency()) " MHz");
        lblFamilyCaption = new JLabel("Family:");
        lblFamily = new JLabel(String.valueOf(info.getFamily()));
        lblModelCaption = new JLabel("Model:");
        lblModel = new JLabel(String.valueOf(info.getModel()));
        lblSteppingCaption = new JLabel("Stepping:");
        lblStepping = new JLabel(String.valueOf(info.getStepping()));
        chkFPU = new CPUFeature("FPU", info.hasFPU());
        chkMMX = new CPUFeature("MMX", info.hasMMX());
        chkMMXPlus = new CPUFeature("MMXPlus", info.hasMMXPlus());
        chk3DNow = new CPUFeature("3DNow!", info.has3DNow());
        chk3DNowPlus = new CPUFeature("3DNow! Plus", info.has3DNowPlus());
        chkSSE = new CPUFeature("SSE", info.hasSSE());
        chkSSE2 = new CPUFeature("SSE2", info.hasSSE2());
        lblMemoryInformationCaption = new JLabel("Memory Information:");
        lblPhisicalTotalCaption = new JLabel("Physical Total:");
        lblPhisicalTotal = new JLabel();
        lblPhisicalAvailableCaption = new JLabel("Physical Available:");
        lblPhisicalAvailable = new JLabel();

        setLayout(new GridBagLayout());

        add(lblAdvisoryText, new GridBagConstraints(00310.00.0
                , GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10101010)00));

        add(lblProcessorInformation, new GridBagConstraints(01210.00.0
                , GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(010010)00));

        JPanel bevel1 = new LineBevel();

        add(bevel1, new GridBagConstraints(11210.00.0
                , GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(010010)00));

        add(lblVendorCaption, new GridBagConstraints(02110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1020010)00));

        add(lblVendor, new GridBagConstraints(12110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(520010)00));

        add(lblProcessorNameCaption, new GridBagConstraints(03110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(520010)00));

        add(lblProcessorName, new GridBagConstraints(13210.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(520010)00));

        add(lblFrequencyCaption, new GridBagConstraints(04110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(520010)00));

        add(lblFrequency, new GridBagConstraints(14110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(520010)00));

        add(lblFamilyCaption, new GridBagConstraints(05110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(520010)00));

        add(lblFamily, new GridBagConstraints(15110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(520010)00));

        add(lblModelCaption, new GridBagConstraints(06110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(520010)00));

        add(lblModel, new GridBagConstraints(16110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(520010)00));

        add(lblSteppingCaption, new GridBagConstraints(07110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(520010)00));

        add(lblStepping, new GridBagConstraints(17110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(520010)00));

        add(chkFPU, new GridBagConstraints(08110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1020010)00));

        add(chkMMX, new GridBagConstraints(18110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1020010)00));

        add(chkMMXPlus, new GridBagConstraints(28110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1020010)00));

        add(chk3DNow, new GridBagConstraints(09110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(020010)00));

        add(chk3DNowPlus, new GridBagConstraints(19110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(020010)00));

        add(chkSSE, new GridBagConstraints(010110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(020010)00));

        add(chkSSE2, new GridBagConstraints(110110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(020010)00));

        add(lblMemoryInformationCaption, new GridBagConstraints(011210.00.0
                , GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(1010010)00));

        JPanel bevel2 = new LineBevel();

        add(bevel2, new GridBagConstraints(111210.00.0
                , GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(1010010)00));

        add(lblPhisicalTotalCaption, new GridBagConstraints(012110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1020010)00));

        add(lblPhisicalTotal, new GridBagConstraints(112110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(520010)00));

        add(lblPhisicalAvailableCaption, new GridBagConstraints(013110.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(520010)00));

        add(lblPhisicalAvailable, new GridBagConstraints(113210.00.0
                , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(520010)00));

        add(new JPanel()new GridBagConstraints(014311.01.0
                , GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0000)00));
        super.initialize();
    }

    private class CPUFeature extends JCheckBox
    {
        public CPUFeature(String text, boolean selected)
        {
            super(text, selected);
            setMargin(new Insets(0000));
            setFocusPainted(false);

            setSelectedIcon(new ImageIcon(this.getClass().getResource("res/checked.gif")));
            setIcon(new ImageIcon(this.getClass().getResource("res/unchecked.gif")));

        }

        protected void processMouseEvent(MouseEvent e)
        {
        }

        protected void processKeyEvent(KeyEvent e)
        {
        }
    }

    public void activate() throws Exception
    {
        super.activate();
        MemoryStatus memoryStatus = new MemoryStatus();
        lblPhisicalTotal.setText("" + memoryStatus.getTotalPhys() 1024 " Kb");
        lblPhisicalAvailable.setText("" + memoryStatus.getAvailPhys() 1024 " Kb");
    }
}