org.openbp.swing.components
Class JMsgBox

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Dialog
                  extended by javax.swing.JDialog
                      extended by org.openbp.swing.components.JMsgBox
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.RootPaneContainer, javax.swing.WindowConstants

public class JMsgBox
extends javax.swing.JDialog
implements java.awt.event.ActionListener

General purpose modal message box component. To be used similar to the JOptionPane class. This class subclasses the JDialog class in order to provide functionality commonly needed in message boxes. The message box provides some additional features in addition to the features known by JOptionPane:
- Resource based images and button texts
- 'Yes for all'/'No for all' button
- Extended accelerators
- Help support using help strategy (planned)
- Stack trace display support using an JTextField (planned) A special feature is the TYPE_OKLATER flag for the message type. If set, the message box will be displayed at a later time using SwingUtilities.invokeLater(Runnable) method. This is very useful if e. g. a field validation is performed from withing a focus lost handler. Displaying the message box at this point in time would lead to a hangup of the Swing event thread. Using TYPE_OKLATER will immediately return, displaying the dialog after the processing of the current event has taken place.

Author:
Stephan Schmid
See Also:
Serialized Form

Nested Class Summary
static interface JMsgBox.DefaultOwnerProvider
           
 
Nested classes/interfaces inherited from class javax.swing.JDialog
javax.swing.JDialog.AccessibleJDialog
 
Nested classes/interfaces inherited from class java.awt.Dialog
java.awt.Dialog.AccessibleAWTDialog, java.awt.Dialog.ModalExclusionType, java.awt.Dialog.ModalityType
 
Nested classes/interfaces inherited from class java.awt.Window
java.awt.Window.AccessibleAWTWindow
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int DEFAULT_ABORT
          Message type: Default button abort
static int DEFAULT_CANCEL
          Message type: Default button cancel
static int DEFAULT_IGNORE
          Message type: Default button ignore
static int DEFAULT_NO
          Message type: Default button no
static int DEFAULT_OK
          Message type: Default button ok
static int DEFAULT_RETRY
          Message type: Default button retry
static int DEFAULT_YES
          Message type: Default button yes
static JMsgBox.DefaultOwnerProvider defaultOwnerProvider
          Default message box owner provider
static int ICON_ERROR
          Message type: Error icon
static int ICON_FATAL
          Message type: Fatal icon
static int ICON_INFO
          Message type: Info icon
static int ICON_QUESTION
          Message type: Question icon
static int ICON_WARNING
          Message type: Warning icon
static int TYPE_ABORT
          Message type: Abort button
static int TYPE_CANCEL
          Message type: Cancel button
static int TYPE_DO_NOT_SHOW_AGAIN
          Additional message type: Display 'Do not show this message again' checkbox
static int TYPE_FOR_ALL
          Message type: Yes/No for all button
static int TYPE_IGNORE
          Message type: Ignore button
static int TYPE_NO
          Message type: No button
static int TYPE_NO_FOR_ALL
          Message type: No for all button
static int TYPE_OK
          Message type: Ok button
static int TYPE_OKCANCEL
          Message type: Ok and cancel button
static int TYPE_OKLATER
          Message type: Ok button
static int TYPE_RETRY
          Message type: Retry button
static int TYPE_YES
          Message type: Yes button
static int TYPE_YES_FOR_ALL
          Message type: Yes for all button
static int TYPE_YESNO
          Message type: Yes and no button
static int TYPE_YESNOCANCEL
          Message type: Yes, no and cancel button
 
Fields inherited from class javax.swing.JDialog
accessibleContext, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Dialog
DEFAULT_MODALITY_TYPE
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JMsgBox(java.awt.Component owner, java.lang.String title, java.lang.String msg, int msgType)
          Constructor.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          ActionListener implementation - determines the return value of the message box.
static javax.swing.JFrame getParentFrame(java.awt.Component c)
          Determines the parent frame of a component.
 ResourceCollection getResource()
          Gets the actual resource to use for this message box.
 java.lang.String getResourcePrefix()
          Gets the actual resource to use for this message box.
 int getUserChoice()
          Gets the the return value of the message box.
 void initDialog()
          Initializes the dialog.
static void setDefaultOwnerProvider(JMsgBox.DefaultOwnerProvider defaultOwnerProviderArg)
          Sets the default message box owner provider.
static void setDefaultResourceCollection(ResourceCollection defaultResourceCollectionArg)
          Sets the message box default resource.
static void setDefaultTitle(java.lang.String defaultTitleArg)
          Sets the default title.
 void setResource(ResourceCollection resourceCollection)
          Sets the actual resource to use for this message box.
 void setResourcePrefix(java.lang.String resourcePrefix)
          Sets the actual resource to use for this message box.
static int show(java.awt.Component owner, java.lang.String msg, int msgType)
          Shows a modal message box using the default title.
static int show(java.awt.Component owner, java.lang.String msg, java.lang.Object[] msgArgs, int msgType)
          Shows a modal message box using the default title.
static int show(java.awt.Component owner, java.lang.String title, java.lang.String msg, int msgType)
          Shows a modal message box.
static int show(java.awt.Component owner, java.lang.String title, java.lang.String msg, java.lang.Object[] msgArgs, int msgType)
          Shows a modal message box.
static int showFormat(java.awt.Component owner, java.lang.String msg, java.lang.Object msgArg1, int msgType)
          Shows a modal message box using the default title.
static int showFormat(java.awt.Component owner, java.lang.String msg, java.lang.Object msgArg1, java.lang.Object msgArg2, int msgType)
          Shows a modal message box using the default title.
static int showFormat(java.awt.Component owner, java.lang.String msg, java.lang.Object msgArg1, java.lang.Object msgArg2, java.lang.Object msgArg3, int msgType)
          Shows a modal message box using the default title.
 
Methods inherited from class javax.swing.JDialog
addImpl, createRootPane, dialogInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
 
Methods inherited from class java.awt.Dialog
addNotify, getModalityType, getTitle, hide, isModal, isResizable, isUndecorated, setModal, setModalityType, setResizable, setTitle, setUndecorated, setVisible, show, toBack
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeNotify, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImage, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE_OK

public static final int TYPE_OK
Message type: Ok button

See Also:
Constant Field Values

TYPE_CANCEL

public static final int TYPE_CANCEL
Message type: Cancel button

See Also:
Constant Field Values

TYPE_OKCANCEL

public static final int TYPE_OKCANCEL
Message type: Ok and cancel button

See Also:
Constant Field Values

TYPE_YES

public static final int TYPE_YES
Message type: Yes button

See Also:
Constant Field Values

TYPE_NO

public static final int TYPE_NO
Message type: No button

See Also:
Constant Field Values

TYPE_YESNO

public static final int TYPE_YESNO
Message type: Yes and no button

See Also:
Constant Field Values

TYPE_YESNOCANCEL

public static final int TYPE_YESNOCANCEL
Message type: Yes, no and cancel button

See Also:
Constant Field Values

TYPE_YES_FOR_ALL

public static final int TYPE_YES_FOR_ALL
Message type: Yes for all button

See Also:
Constant Field Values

TYPE_NO_FOR_ALL

public static final int TYPE_NO_FOR_ALL
Message type: No for all button

See Also:
Constant Field Values

TYPE_FOR_ALL

public static final int TYPE_FOR_ALL
Message type: Yes/No for all button

See Also:
Constant Field Values

TYPE_ABORT

public static final int TYPE_ABORT
Message type: Abort button

See Also:
Constant Field Values

TYPE_RETRY

public static final int TYPE_RETRY
Message type: Retry button

See Also:
Constant Field Values

TYPE_IGNORE

public static final int TYPE_IGNORE
Message type: Ignore button

See Also:
Constant Field Values

TYPE_DO_NOT_SHOW_AGAIN

public static final int TYPE_DO_NOT_SHOW_AGAIN
Additional message type: Display 'Do not show this message again' checkbox

See Also:
Constant Field Values

ICON_INFO

public static final int ICON_INFO
Message type: Info icon

See Also:
Constant Field Values

ICON_WARNING

public static final int ICON_WARNING
Message type: Warning icon

See Also:
Constant Field Values

ICON_ERROR

public static final int ICON_ERROR
Message type: Error icon

See Also:
Constant Field Values

ICON_FATAL

public static final int ICON_FATAL
Message type: Fatal icon

See Also:
Constant Field Values

ICON_QUESTION

public static final int ICON_QUESTION
Message type: Question icon

See Also:
Constant Field Values

DEFAULT_OK

public static final int DEFAULT_OK
Message type: Default button ok

See Also:
Constant Field Values

DEFAULT_CANCEL

public static final int DEFAULT_CANCEL
Message type: Default button cancel

See Also:
Constant Field Values

DEFAULT_YES

public static final int DEFAULT_YES
Message type: Default button yes

See Also:
Constant Field Values

DEFAULT_NO

public static final int DEFAULT_NO
Message type: Default button no

See Also:
Constant Field Values

DEFAULT_ABORT

public static final int DEFAULT_ABORT
Message type: Default button abort

See Also:
Constant Field Values

DEFAULT_RETRY

public static final int DEFAULT_RETRY
Message type: Default button retry

See Also:
Constant Field Values

DEFAULT_IGNORE

public static final int DEFAULT_IGNORE
Message type: Default button ignore

See Also:
Constant Field Values

TYPE_OKLATER

public static final int TYPE_OKLATER
Message type: Ok button

See Also:
Constant Field Values

defaultOwnerProvider

public static JMsgBox.DefaultOwnerProvider defaultOwnerProvider
Default message box owner provider

Constructor Detail

JMsgBox

public JMsgBox(java.awt.Component owner,
               java.lang.String title,
               java.lang.String msg,
               int msgType)
Constructor.

Parameters:
owner - Parent window that opened the message box
title - Title of the message box
msg - Message to display in the message box
msgType - Msg type (see the constants of this class)
Method Detail

getUserChoice

public int getUserChoice()
Gets the the return value of the message box.


getResource

public ResourceCollection getResource()
Gets the actual resource to use for this message box.


setResource

public void setResource(ResourceCollection resourceCollection)
Sets the actual resource to use for this message box.


getResourcePrefix

public java.lang.String getResourcePrefix()
Gets the actual resource to use for this message box.


setResourcePrefix

public void setResourcePrefix(java.lang.String resourcePrefix)
Sets the actual resource to use for this message box.


initDialog

public void initDialog()
Initializes the dialog.


show

public static int show(java.awt.Component owner,
                       java.lang.String msg,
                       int msgType)
Shows a modal message box using the default title.

Parameters:
owner - Owner window of this message box
msg - Message to display
msgType - Msg type (see the constants of this class)
Returns:
The user's response or 0 on error

show

public static int show(java.awt.Component owner,
                       java.lang.String title,
                       java.lang.String msg,
                       int msgType)
Shows a modal message box.

Parameters:
owner - Owner window of this message box
title - Message box title
msg - Message to display
msgType - Msg type (see the constants of this class)
Returns:
The user's response or 0 on error

show

public static int show(java.awt.Component owner,
                       java.lang.String msg,
                       java.lang.Object[] msgArgs,
                       int msgType)
Shows a modal message box using the default title.

Parameters:
owner - Owner window of this message box
msg - Message to display
msgArgs - Message arguments (for details see the MsgFormat class)
msgType - Msg type (see the constants of this class)
Returns:
The user's response or 0 on error

show

public static int show(java.awt.Component owner,
                       java.lang.String title,
                       java.lang.String msg,
                       java.lang.Object[] msgArgs,
                       int msgType)
Shows a modal message box.

Parameters:
owner - Owner window of this message box
title - Message box title
msg - Message to display
msgArgs - Message arguments (for details see the MsgFormat class)
msgType - Msg type (see the constants of this class)
Returns:
The user's response or 0 on error

showFormat

public static int showFormat(java.awt.Component owner,
                             java.lang.String msg,
                             java.lang.Object msgArg1,
                             int msgType)
Shows a modal message box using the default title.

Parameters:
owner - Owner window of this message box
msg - Message to display
msgArg1 - First message argument (for details see the MsgFormat class)
msgType - Msg type (see the constants of this class)
Returns:
The user's response or 0 on error

showFormat

public static int showFormat(java.awt.Component owner,
                             java.lang.String msg,
                             java.lang.Object msgArg1,
                             java.lang.Object msgArg2,
                             int msgType)
Shows a modal message box using the default title.

Parameters:
owner - Owner window of this message box
msg - Message to display
msgArg1 - First message argument (for details see the MsgFormat class)
msgArg2 - First message argument (for details see the MsgFormat class)
msgType - Msg type (see the constants of this class)
Returns:
The user's response or 0 on error

showFormat

public static int showFormat(java.awt.Component owner,
                             java.lang.String msg,
                             java.lang.Object msgArg1,
                             java.lang.Object msgArg2,
                             java.lang.Object msgArg3,
                             int msgType)
Shows a modal message box using the default title.

Parameters:
owner - Owner window of this message box
msg - Message to display
msgArg1 - First message argument (for details see the MsgFormat class)
msgArg2 - First message argument (for details see the MsgFormat class)
msgArg3 - First message argument (for details see the MsgFormat class)
msgType - Msg type (see the constants of this class)
Returns:
The user's response or 0 on error

setDefaultResourceCollection

public static void setDefaultResourceCollection(ResourceCollection defaultResourceCollectionArg)
Sets the message box default resource.


setDefaultTitle

public static void setDefaultTitle(java.lang.String defaultTitleArg)
Sets the default title.


setDefaultOwnerProvider

public static void setDefaultOwnerProvider(JMsgBox.DefaultOwnerProvider defaultOwnerProviderArg)
Sets the default message box owner provider.


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
ActionListener implementation - determines the return value of the message box.

Specified by:
actionPerformed in interface java.awt.event.ActionListener

getParentFrame

public static javax.swing.JFrame getParentFrame(java.awt.Component c)
Determines the parent frame of a component.

Parameters:
c - Component
Returns:
The parent frame or null if the component is not a direct or indirect child of a JFrame


Copyright © 2011. All Rights Reserved.