alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.core.windows.services;

import org.openide.util.HelpCtx;
import org.openide.util.Utilities;
import org.openide.windows.WindowManager;

import javax.swing.*;
import java.awt.*;


// XXX before as org.netbeans.core.CoronaDialog;

/** The CoronaDialog is a standard dialog that contains a ButtonBar on the South.
* All the "add(Component)" and "setLayout(LayoutManager)" requests should be
* performed on the Container acquired from getContentPane() (similar to
* getContentPane() in JFrame and JDialog).
* The dialog can be both instantiated OR subclassed.
*
* @author   Ian Formanek, Jaroslav Tulach, Jan Jancura, Petr Hamernik
* @version  0.56, May 16, 1998
*/
class CoronaDialog extends JDialog {
    /** generated Serialized Version UID */
    static final long serialVersionUID = 5301615034186604735L;
    /** Constructs a new modal CoronaDialog with empty button bar.
    * Descendants can initialize the ButtonBar later by calling setButtons()
    * on the buttonBar acquired by protected method getButtonBar.
    * @param parent The Frame parent of the dialog or null if the parent should be the Corona's MainWIndow
    * @param modal If the dialog is modal
    */
    public CoronaDialog (Frame parent, boolean modal) {
        this(parent, ButtonBar.EMPTY, modal);
    }

    /** Constructs a new modal CoronaDialog with empty button bar.
    * Descendants can initialize the ButtonBar later by calling setButtons()
    * on the buttonBar acquired by protected method getButtonBar.
    * @param parent The Frame parent of the dialog or null if the parent should be the Corona's MainWIndow
    */
    public CoronaDialog (Frame parent) {
        this(parent, ButtonBar.EMPTY, true);
    }

    /** Constructs a new modal CoronaDialog with given preset mode of ButtonBar.
    * @param mode The ButtonBar mode
    * @param parent The Frame parent of the dialog or null if the parent should be the Corona's MainWIndow
    */
    public CoronaDialog (Frame parent, int mode) {
        this(parent, mode, true);
    }

    /** Constructs a new CoronaDialog with given preset mode of ButtonBar.
    * @param parent The Frame parent of the dialog or null if the parent should be the Corona's MainWIndow
    * @param bb button bar to use
    * @param modal If the dialog is modal
    */
    public CoronaDialog (Frame parent, ButtonBar bb, boolean modal) {
        super(
            parent == null ? WindowManager.getDefault().getMainWindow() : parent,
            modal
        );

        getContentPane().setLayout(new BorderLayout());
        buttonBar = bb;
        buttonBar.addButtonBarListener(new ButtonBar.ButtonBarListener() {
                                           public void buttonPressed(ButtonBar.ButtonBarEvent evt) {
                                               CoronaDialog.this.buttonPressed(evt);
                                           }
                                       }
                                      );

        inside = new JPanel();
        inside.setLayout(new BorderLayout());
        getContentPane().add (inside, BorderLayout.CENTER);

        getContentPane().add (buttonBar,
                              (bb.getOrientation() == ButtonBar.HORIZONTAL) ? BorderLayout.SOUTH : BorderLayout.EAST);

    }

    /** Constructs a new CoronaDialog with given preset mode of ButtonBar.
    * @param parent The Frame parent of the dialog or null if the parent should be the Corona's MainWIndow
    * @param mode The ButtonBar mode
    * @param modal If the dialog is modal
    */
    public CoronaDialog (Frame parent, int mode, boolean modal) {
        this (parent, new ButtonBar (mode), modal);
    }

    /** Method that allows getting the inside pane that can be used
    * for adding/removing components to the Dialog.
    * This pane should be used *exclusively* for this - it is a
    * equivalent of getContentpane in swing windows.
    * @return The pane to be used for setting layout and adding components
    */
    public JPanel getCustomPane() {
        return inside;
    }

    /** A method that allows descendants to acquire a reference to ButtonBar
    * so that the ButtonBar can be initialized / altered.
    * @return The ButtonBar of this dialog
    */
    protected ButtonBar getButtonBar() {
        return buttonBar;
    }

    /** Default implementation of close() from TopWindow - returns true.
    *
    * Called when one wants to close the window and never
    * restore it anymore. Can initiate interaction with user and
    * he can stop closing.
    * In such a case the method should return false to
    * indicate the failure.
    *
    * @return true if the window has been successfully closed and false
    *   if the user has canceled the action.
    */
    public boolean close () {
        return true;
    }

    /** Every window must have its own help page. The suggested model
    * is described in HelpCtx and Help classes.
    * @return the help page reference
    */
    public HelpCtx getHelp () {
        return helpCtx;
    }

    /** Sets the help context for this window.
    * Every window must have its own help page. The suggested model
    * is described in HelpCtx and Help classes.
    * @return the help page reference
    */
    protected void setHelp(HelpCtx help) {
        helpCtx = help;
    }

    /** Reshapes the dialog so that is is sized according to its preferrddSize
    * and places it into the center of the screen
    */
    public void center() {
        // standard way how to place the dialog to the center of the screen
        pack();
        setBounds(Utilities.findCenterBounds(getSize()));
    }

    /** Called when user presses a button on the ButtonBar.
    * @param evt The ButtonBarEvent.
    */
    protected void buttonPressed(ButtonBar.ButtonBarEvent evt) {
    }

    /** addNotify redefined */
    public void addNotify() {
        super.addNotify();
        getRootPane().requestDefaultFocus(); // patch to make default button work
    }

    /** The "inside" part of the Dialog */ // NOI18N
    private JPanel inside;

    /** the help context for this dialog */
    private HelpCtx helpCtx = HelpCtx.DEFAULT_HELP;

    /** The ButtonBar of this dialog */
    private ButtonBar buttonBar;

}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.