/*
 * Copyright (C) 1999-2006 <a href="mailto:adrian.paschke@gmx.de">Adrian Paschke</a>
 * 
 * The RBSLM Environment is part of the Rule Based Service Level Agreement (RBSLA)
 * framework, available at 
 * <a href=" http://ibis.in.tum.de/staff/paschke/rbsla/index.htm">RBSLA</a>
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package rbsla.environment.dialogs;

import java.awt.Button;
import java.awt.Color;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Label;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JDialog;

import rbsla.environment.ECAConstraints;
import rbsla.environment.ECAPanel;
import rbsla.environment.ECAWindow;

public class InfoDialog extends JDialog implements ActionListener, KeyListener,
        WindowListener
{
    protected Frame parentFrame;

    protected Panel p;

    protected Label message;

    protected Button ok;

    protected GridBagLayout myLayout;

    public InfoDialog(Frame parent, String TheTitle, boolean isModal,
            String theMessage, String okString)
    {
        super(parent, TheTitle, isModal);

        parentFrame = parent;

        myLayout = new GridBagLayout();
        this.getContentPane().setLayout(myLayout);

        /*
         * p = new Panel(); p.setLayout(myLayout);
         */
        message = new Label(theMessage);
        getContentPane().add(
                message,
                new ECAConstraints(0, 0, 1, 1, 1.0, 1.0,
                        GridBagConstraints.CENTER, GridBagConstraints.NONE,
                        new Insets(0, 0, 0, 0), 0, 0));

        ok = new Button(okString);
        ok.addActionListener(this);
        ok.addKeyListener(this);
        getContentPane().add(
                ok,
                new ECAConstraints(0, 1, 1, 1, 1.0, 1.0,
                        GridBagConstraints.CENTER, GridBagConstraints.NONE,
                        new Insets(0, 0, 0, 0), 0, 0));

        setBackground(Color.lightGray);
        pack();
        setResizable(false);

        if (parentFrame instanceof ECAWindow)
            ECAPanel.centerDialog(parentFrame, this);
        else
            ECAPanel.centerDialogOnScreen(this);

        addKeyListener(this);
        addWindowListener(this);
        ok.requestFocus();
        show();
        //return;
    }

    public void actionPerformed(ActionEvent E)
    {
        if (E.getSource() == ok)
        {
            dispose();
            return;
        }
        return;
    }

    public void keyPressed(KeyEvent E)
    {
    }

    public void keyReleased(KeyEvent E)
    {
        if (E.getKeyCode() == E.VK_ENTER)
        {
            if (E.getSource() == ok)
            {
                dispose();
                return;
            }
        }
        return;
    }

    public void keyTyped(KeyEvent E)
    {
    }

    public void windowActivated(WindowEvent E)
    {
    }

    public void windowClosed(WindowEvent E)
    {
    }

    public void windowClosing(WindowEvent E)
    {
        dispose();
        return;
    }

    public void windowDeactivated(WindowEvent E)
    {
    }

    public void windowDeiconified(WindowEvent E)
    {
    }

    public void windowIconified(WindowEvent E)
    {
    }

    public void windowOpened(WindowEvent E)
    {
    }
}