package org.lucci.madhoc.gui.runtime;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;

/*
 * Created on May 8, 2005
 */

/**
 * @author luc.hogie
 */
public class JVMComponent extends RuntimeComponentElement
{
    private JButton gcButton = new JButton();
    private JButton shootButton = new JButton("Shoot!");

    public JVMComponent()
    {
        ActionListener buttonHandler = new ButtonHandler();

        setLayout(new GridBagLayout());
        {
            gcButton.addActionListener(buttonHandler);
            gcButton.setToolTipText("<html><b>Forces</b> the garbage collector to proceed..");
            shootButton.setIcon(new ImageIcon(getClass().getResource("YellowCircle.gif")));
            GridBagConstraints c = new GridBagConstraints();
            c.gridx = 0;
            c.gridy = 0;
            add(gcButton, c);
        }
        {
            shootButton.addActionListener(buttonHandler);
            shootButton.setToolTipText("<html><b>Shoots</b> the window in a file.");
            GridBagConstraints c = new GridBagConstraints();
            c.gridx = 0;
            c.gridy = 1;
            add(shootButton, c);
        }
    }
    
    public class ButtonHandler implements ActionListener
    {
        /*
         * (non-Javadoc)
         * 
         * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
         */
        public void actionPerformed(ActionEvent event)
        {
            Object source = event.getSource();

            if (source == gcButton)
            {
                System.gc();
            }
            else if (source == shootButton)
            {
            }
        }
    }

    /* (non-Javadoc)
     * @see org.lucci.madhoc.gui.SimulationRuntimeListener#stateChanged()
     */
    public void stateChanged()
    {
    }

    /* (non-Javadoc)
     * @see org.lucci.madhoc.gui.SimulationRuntimeListener#iterationPerformed()
     */
    public void iterationPerformed()
    {
    }
}