
com.globalmentor.swing.BasicDialog Maven / Gradle / Ivy
Show all versions of globalmentor-swing Show documentation
/*
* Copyright © 1996-2009 GlobalMentor, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.globalmentor.swing;
import java.awt.*;
import javax.swing.*;
import com.globalmentor.awt.Windows;
/**
* An improved dialog class with basic needed functionality.
*
* This class improves its packing functionality by proportionally resizing dialogs that prefer to be larger than the screen and contain a scrollpane.
*
* @author Garret Wilson
*/
public class BasicDialog extends JDialog {
/**
* Creates a non-modal dialog without a title and without a specified Frame
owner. A shared, hidden frame will be set as the owner of the dialog.
*
* This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale
.
*
* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns true.
* @see java.awt.GraphicsEnvironment#isHeadless
* @see JComponent#getDefaultLocale
*/
public BasicDialog() throws HeadlessException {
this((Frame)null, false);
}
/**
* Creates a non-modal dialog without a title with the specified Frame
as its owner. If owner
is null
, a shared, hidden
* frame will be set as the owner of the dialog.
*
* This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale
.
*
* @param owner the Frame
from which the dialog is displayed
* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns true.
* @see java.awt.GraphicsEnvironment#isHeadless
* @see JComponent#getDefaultLocale
*/
public BasicDialog(Frame owner) throws HeadlessException {
this(owner, false);
}
/**
* Creates a modal or non-modal dialog without a title and with the specified owner Frame
. If owner
is null
, a shared,
* hidden frame will be set as the owner of the dialog.
*
* This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale
.
*
* @param owner the Frame
from which the dialog is displayed
* @param modal true for a modal dialog, false for one that allows others windows to be active at the same time
* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns true.
* @see java.awt.GraphicsEnvironment#isHeadless
* @see JComponent#getDefaultLocale
*/
public BasicDialog(Frame owner, boolean modal) throws HeadlessException {
this(owner, null, modal);
}
/**
* Creates a non-modal dialog with the specified title and with the specified owner frame. If owner
is null
, a shared, hidden frame
* will be set as the owner of the dialog.
*
* This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale
.
*
* @param owner the Frame
from which the dialog is displayed
* @param title the String
to display in the dialog's title bar
* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns true.
* @see java.awt.GraphicsEnvironment#isHeadless
* @see JComponent#getDefaultLocale
*/
public BasicDialog(Frame owner, String title) throws HeadlessException {
this(owner, title, false);
}
/**
* Creates a modal or non-modal dialog with the specified title and the specified owner Frame
. If owner
is null
, a
* shared, hidden frame will be set as the owner of this dialog. All constructors defer to this one.
*
* NOTE: Any popup components (JComboBox
, JPopupMenu
, JMenuBar
) created within a modal dialog will be forced to be
* lightweight.
*
* This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale
.
*
* @param owner the Frame
from which the dialog is displayed
* @param title the String
to display in the dialog's title bar
* @param modal true for a modal dialog, false for one that allows other windows to be active at the same time
* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns true.
* @see java.awt.GraphicsEnvironment#isHeadless
* @see JComponent#getDefaultLocale
*/
public BasicDialog(Frame owner, String title, boolean modal) throws HeadlessException {
super(owner, title, modal);
}
/**
* Creates a modal or non-modal dialog with the specified title, owner Frame
, and GraphicsConfiguration
.
*
*
* NOTE: Any popup components (JComboBox
, JPopupMenu
, JMenuBar
) created within a modal dialog will be forced to be
* lightweight.
*
* This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale
.
*
* @param owner the Frame
from which the dialog is displayed
* @param title the String
to display in the dialog's title bar
* @param modal true for a modal dialog, false for one that allows other windows to be active at the same time
* @param gc the GraphicsConfiguration
of the target screen device. If gc
is null
, the same
* GraphicsConfiguration
as the owning Frame is used.
* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns true.
* @see java.awt.GraphicsEnvironment#isHeadless
* @see JComponent#getDefaultLocale
* @since 1.4
*/
public BasicDialog(Frame owner, String title, boolean modal, GraphicsConfiguration gc) {
super(owner, title, modal, gc);
}
/**
* Creates a non-modal dialog without a title with the specified Dialog
as its owner.
*
* This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale
.
*
* @param owner the non-null Dialog
from which the dialog is displayed
* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns true.
* @see java.awt.GraphicsEnvironment#isHeadless
* @see JComponent#getDefaultLocale
*/
public BasicDialog(Dialog owner) throws HeadlessException {
this(owner, false);
}
/**
* Creates a modal or non-modal dialog without a title and with the specified owner dialog.
*
* This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale
.
*
* @param owner the non-null Dialog
from which the dialog is displayed
* @param modal true for a modal dialog, false for one that allows other windows to be active at the same time
* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns true.
* @see java.awt.GraphicsEnvironment#isHeadless
* @see JComponent#getDefaultLocale
*/
public BasicDialog(Dialog owner, boolean modal) throws HeadlessException {
this(owner, null, modal);
}
/**
* Creates a non-modal dialog with the specified title and with the specified owner dialog.
*
* This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale
.
*
* @param owner the non-null Dialog
from which the dialog is displayed
* @param title the String
to display in the dialog's title bar
* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns true.
* @see java.awt.GraphicsEnvironment#isHeadless
* @see JComponent#getDefaultLocale
*/
public BasicDialog(Dialog owner, String title) throws HeadlessException {
this(owner, title, false);
}
/**
* Creates a modal or non-modal dialog with the specified title and the specified owner frame.
*
* This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale
.
*
* @param owner the non-null Dialog
from which the dialog is displayed
* @param title the String
to display in the dialog's title bar
* @param modal true for a modal dialog, false for one that allows other windows to be active at the same time
* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns true.
* @see java.awt.GraphicsEnvironment#isHeadless
* @see JComponent#getDefaultLocale
*/
public BasicDialog(Dialog owner, String title, boolean modal) throws HeadlessException {
super(owner, title, modal);
}
/**
* Creates a modal or non-modal dialog with the specified title, owner Dialog
, and GraphicsConfiguration
.
*
*
* NOTE: Any popup components (JComboBox
, JPopupMenu
, JMenuBar
) created within a modal dialog will be forced to be
* lightweight.
*
* This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale
.
*
* @param owner the Dialog
from which the dialog is displayed
* @param title the String
to display in the dialog's title bar
* @param modal true for a modal dialog, false for one that allows other windows to be active at the same time
* @param gc the GraphicsConfiguration
of the target screen device. If gc
is null
, the same
* GraphicsConfiguration
as the owning Dialog is used.
* @throws HeadlessException if GraphicsEnvironment.isHeadless()
* @see java.awt.GraphicsEnvironment#isHeadless
* @see JComponent#getDefaultLocale returns true.
* @since 1.4
*/
public BasicDialog(Dialog owner, String title, boolean modal, GraphicsConfiguration gc) throws HeadlessException {
super(owner, title, modal, gc);
}
/**
* Causes this window to be sized to fit the preferred size and layouts of its subcomponents.
*
* This version proportionally resizes the dialog if it prefers to be larger than the screen and contains a scrollpane.
*
* @see Windows#constrainSize(Window)
*/
public void pack() {
super.pack(); //pack the window normally
Windows.constrainSize(this); //make sure this dialog isn't too large for the graphics configuration
}
}