/*
 * CloseDialog.java  $Revision: 1.2 $  $Date: 2007/10/03 04:39:40 $
 *
 * Copyright (C) 2007 Meldcraft Corporation
 *
 * This file is part of Scaffold.
 * 
 * Scaffold 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 3 of the License, or
 * (at your option) any later version.
 * 
 * Scaffold 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 Scaffold.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.meldcraft.gui.swing;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

/**
 * @version $Revision: 1.2 $ $Date: 2007/10/03 04:39:40 $
 * @author rob
 */
public class CloseDialog extends JDialog
{
// Static variables
// Member variables
// Constructors and initialization
// Interface implemenations
// Public methods
    public static JDialog createCloseDialog(Component parent,
                                            Component content)
    {
        final JDialog dialog = new JDialog(SwingUtil.getJFrame(parent), "", true);

        JButton button = new JButton("Close");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e)
            {
                dialog.hide();
                dialog.dispose();
            }
        });

        JPanel panel = new JPanel(new BorderLayout());
        panel.setBorder(BorderFactory.createEmptyBorder(13,13,13,13));
        panel.add(button, BorderLayout.EAST);
        dialog.getContentPane().add(panel, BorderLayout.SOUTH);
        dialog.getContentPane().add(content, BorderLayout.CENTER);

        //dialog.setResizable(false);
        //dialog.setUndecorated(true);
        dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);

        dialog.pack();
        dialog.setLocationRelativeTo(parent);

        return dialog;
    }

// Protected methods
// Private methods
// Inner classes
}
