Dialog Panel : Dialog « Swing Components « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » Swing Components » Dialog 




Dialog Panel
     

/*
 * Enhydra Java Application Server Project
 *
 * The contents of this file are subject to the Enhydra Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License on
 * the Enhydra web site ( http://www.enhydra.org/ ).
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 * the License for the specific terms governing rights and limitations
 * under the License.
 *
 * The Initial Developer of the Enhydra Application Server is Lutris
 * Technologies, Inc. The Enhydra Application Server and portions created
 * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
 * All Rights Reserved.
 *
 * Contributor(s):
 *
 */

// Standard imports
import java.awt.BorderLayout;
import java.awt.Window;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.Point;
import java.awt.event.WindowEvent;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JOptionPane;

//
public class DialogPanel extends JPanel {
    public final static int CANCEL_OPTION = JOptionPane.CANCEL_OPTION;
    public final static int OK_OPTION = JOptionPane.OK_OPTION;

    //
    private int             option = DialogPanel.CANCEL_OPTION;
    private LocalDialog     dialog = null;
    private Window          owner = null;
    private boolean         windowClose = false;
    private boolean         standalone = false;
    private boolean         modal = true;
    private String          title = new String();

    public Window getOwner() {
        return owner;
    }

    public void setOwner(Window w) {
        owner = w;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String t) {
        title = t;
    }

    public boolean isModal() {
        return modal;
    }

    public void setModal(boolean b) {
        modal = b;
    }

    public int getOption() {
        return option;
    }

    public void setOption(int o) {
        option = o;
    }

    public LocalDialog getDialog() {
        return dialog;
    }

    public void startDialogThread() {
        Thread dialogThread = new Thread() {
            public void run() {
                showDialog();
            }

        };

        dialogThread.start();
    }

    public int showDialog() {
        BorderLayout layout = null;
        Point        cp = null;

        if (dialog == null) {
            if (getOwner() == null) {
                dialog = new LocalDialog();
            else if (getOwner() instanceof Frame) {
                dialog = new LocalDialog((FramegetOwner());
            else if (getOwner() instanceof Dialog) {
                dialog = new LocalDialog((DialoggetOwner());
            else {
                dialog = new LocalDialog();
            }
        }
        dialog.setModal(isModal());
        dialog.setTitle(getTitle());
        layout = new BorderLayout();
        dialog.getRootPane().setLayout(layout);
        dialog.getRootPane().add(this, BorderLayout.CENTER);
        dialog.pack();

  
        dialog.show();
        return option;
    }

    //
    // PROTECTED
    //
    protected void hideDialog() {
        if (dialog != null) {
            dialog.setVisible(false);
        }
    }

    protected void clearDialog() {
        if (dialog != null) {
            dialog.setVisible(false);
            dialog.getRootPane().removeAll();
            dialog.removeAll();
            dialog.dispose();
        }
        if (isStandalone()) {
            System.exit(0);
        }
    }

    protected boolean isWindowClose() {
        return windowClose;
    }

    protected void setWindowClose(boolean b) {
        windowClose = b;
    }

    protected boolean isStandalone() {
        return standalone;
    }

    protected void setStandalone(boolean b) {
        standalone = b;
    }

    private class LocalDialog extends JDialog {
        public LocalDialog() {
            super();
        }

        public LocalDialog(Dialog owner) {
            super(owner);
        }

        public LocalDialog(Frame owner) {
            super(owner);
        }

        protected void processWindowEvent(WindowEvent e) {
            if (isWindowClose()) {
                if (e.getID() == WindowEvent.WINDOW_CLOSING) {
                    clearDialog();
                }
                super.processWindowEvent(e);
            }
        }

    }
}

   
    
    
    
    
  














Related examples in the same category
1.Vista Transparent DialogVista Transparent Dialog
2.Use this modal dialog to let the user choose one string from a long list
3.Tip Of Day Dialog
4.Swing error dialog (Exception dialog)Swing error dialog (Exception dialog)
5.Swing Login Domain Dialog with animationSwing Login Domain Dialog with animation
6.Shake a dialog
7.About dialog
8.Login DialogLogin Dialog
9.The base class for standard dialogs.
10.Password Dialog
11.A popup dialog with a message and a scrollable list of items
12.Custom dialog box to enter dates
13.Login Panel
14.Exception dump and Dialog Box
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.