1/*
2 * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25
26package com.sun.java.swing.ui;
27
28import java.awt.BorderLayout;
29import java.awt.Container;
30import java.awt.event.ActionEvent;
31import java.awt.event.ActionListener;
32import javax.swing.JDialog;
33import javax.swing.JPanel;
34
35// Referenced classes of package com.sun.java.swing.ui:
36//            OkCancelButtonPanel, CommonUI
37
38public class OkCancelDialog extends JDialog
39    implements ActionListener
40{
41
42    public OkCancelDialog(String title, JPanel panel)
43    {
44        this(title, panel, true);
45    }
46
47    public OkCancelDialog(String title, JPanel panel, boolean modal)
48    {
49        setTitle(title);
50        setModal(modal);
51        Container pane = getContentPane();
52        pane.setLayout(new BorderLayout());
53        pane.add(panel, "Center");
54        pane.add(new OkCancelButtonPanel(this), "South");
55        pack();
56        CommonUI.centerComponent(this);
57    }
58
59    public boolean isOk()
60    {
61        return okPressed;
62    }
63
64    public void actionPerformed(ActionEvent evt)
65    {
66        String command = evt.getActionCommand();
67        if(command.equals("ok-command"))
68        {
69            okPressed = true;
70            setVisible(false);
71            dispose();
72        } else
73        if(command.equals("cancel-command"))
74        {
75            okPressed = false;
76            setVisible(false);
77            dispose();
78        }
79    }
80
81    private boolean okPressed;
82}
83