org.xnap.commons.gui
Class DefaultDialog

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.xnap.commons.gui.DefaultDialog
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants
Direct Known Subclasses:
AboutDialog, DirectoryChooser, ErrorDialog, ProgressDialog, WizardDialog

public class DefaultDialog
extends JDialog

This class provides a default implementation for a dialog. A dialog consists of two areas. The main area, located at the center of the dialog, contains the user interaction components. The button area, located at the south west of the dialog, is surrounded by an empty border and contains the buttons.

The most common buttons are provided with default actions.

When you extend this class make sure pack() is called after all components have been added.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JDialog
JDialog.AccessibleJDialog
 
Nested classes/interfaces inherited from class java.awt.Dialog
Dialog.AccessibleAWTDialog
 
Nested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static int BUTTON_APPLY
          The button type for the apply button.
static int BUTTON_CANCEL
          The button type for the cancel button.
static int BUTTON_CLOSE
          The button type for the close button.
static int BUTTON_CONTEXT_HELP
          The button type for the context help button.
static int BUTTON_DEFAULTS
          The button type for the defaults button.
static int BUTTON_HELP
          The button type for the help button.
static int BUTTON_NONE
          The button type for no buttons.
static int BUTTON_OKAY
          The button type for the okay button.
protected  boolean isOkay
           
 
Fields inherited from class javax.swing.JDialog
accessibleContext, rootPane, rootPaneCheckingEnabled
 
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
DefaultDialog()
          Constructs a dialog with an okay and cancel button.
DefaultDialog(Dialog owner)
          Convenience wrapper for DefaultDialog(Dialog, BUTTON_OKAY | BUTTON_CANCEL).
DefaultDialog(Dialog owner, int buttons)
          Convenience wrapper for DefaultDialog(Dialog, int, null).
DefaultDialog(Dialog owner, int buttons, JComponent mainComponent)
          Constructs a dialog showing the specified buttons and a mainComponent.
DefaultDialog(Frame owner)
          Convenience wrapper for DefaultDialog(Frame, BUTTON_OKAY | BUTTON_CANCEL).
DefaultDialog(Frame owner, int buttons)
          Convenience wrapper for DefaultDialog(Frame, int, null).
DefaultDialog(Frame owner, int buttons, JComponent mainComponent)
          Constructs a dialog showing the specified buttons and a mainComponent.
DefaultDialog(int buttons)
          Convenience wrapper for DefaultDialog(int, null).
DefaultDialog(int buttons, JComponent mainComponent)
          Constructs a dialog.
 
Method Summary
 boolean apply()
          Called by ApplyAction and OkayAction when the dialog is closed.
protected  void cancelled()
           
 void close()
          Disposes the dialog.
 void contextHelp()
          Invoked when the context help button is selected.
protected  void defaults()
           
 Action getApplyAction()
          Returns the apply action.
 JPanel getButtonPanel()
          Returns the button panel.
 Action getCancelAction()
          Returns the cancel action.
 Action getCloseAction()
          Returns the close action.
 Action getContextHelpAction()
          Returns the cancel action.
 Action getDefaultsAction()
          Returns the defaults action.
 Action getHelpAction()
          Returns the cancel action.
 JPanel getMainPanel()
          Returns the main panel.
 Action getOkayAction()
          Returns the cancel action.
 JPanel getTopPanel()
          Returns the top most panel.
 void help()
          Invoked when the context help is selected.
 boolean isOkay()
          Returns true, if the dialog was closed with the Okay button.
 void setApplyOnEnter(boolean apply)
           
 void setButtonSeparatorVisible(boolean visible)
           
 void setMainComponent(Component component)
          Sets the main component to component.
 void show(Component c)
          Sets this dialogs position relative to c and makes it visible.
 
Methods inherited from class javax.swing.JDialog
addImpl, createRootPane, dialogInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.awt.Dialog
addNotify, getTitle, hide, isModal, isResizable, isUndecorated, setModal, setResizable, setTitle, setUndecorated, show
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, finalize, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, isActive, isAlwaysOnTop, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setAlwaysOnTop, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationByPlatform, setLocationRelativeTo, toBack, 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, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, removeNotify, 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, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, 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, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BUTTON_NONE

public static int BUTTON_NONE
The button type for no buttons.


BUTTON_OKAY

public static int BUTTON_OKAY
The button type for the okay button.


BUTTON_APPLY

public static int BUTTON_APPLY
The button type for the apply button.


BUTTON_CANCEL

public static int BUTTON_CANCEL
The button type for the cancel button.


BUTTON_CLOSE

public static int BUTTON_CLOSE
The button type for the close button.


BUTTON_HELP

public static int BUTTON_HELP
The button type for the help button.


BUTTON_CONTEXT_HELP

public static int BUTTON_CONTEXT_HELP
The button type for the context help button.


BUTTON_DEFAULTS

public static int BUTTON_DEFAULTS
The button type for the defaults button.


isOkay

protected boolean isOkay
Constructor Detail

DefaultDialog

public DefaultDialog(Dialog owner,
                     int buttons,
                     JComponent mainComponent)
Constructs a dialog showing the specified buttons and a mainComponent.

Parameters:
owner - the dialog owner
buttons - the ored value of button codes, e.g BUTTON_CANCEL | BUTTON_OKAY
mainComponent - the main component of the dialog, shown in the center of the dialog.

DefaultDialog

public DefaultDialog(Frame owner,
                     int buttons,
                     JComponent mainComponent)
Constructs a dialog showing the specified buttons and a mainComponent.

Parameters:
owner - the dialog owner
buttons - the ored value of button codes, e.g BUTTON_CANCEL | BUTTON_OKAY
mainComponent - the main component of the dialog, shown in the center of the dialog.

DefaultDialog

public DefaultDialog(int buttons,
                     JComponent mainComponent)
Constructs a dialog. The escape key is by default bound to the cancel button.

Parameters:
buttons - a logical and combination of button type constants
mainComponent - the main component that is centered in the dialog

DefaultDialog

public DefaultDialog(Dialog owner,
                     int buttons)
Convenience wrapper for DefaultDialog(Dialog, int, null).


DefaultDialog

public DefaultDialog(Frame owner,
                     int buttons)
Convenience wrapper for DefaultDialog(Frame, int, null).


DefaultDialog

public DefaultDialog(int buttons)
Convenience wrapper for DefaultDialog(int, null).

Parameters:
buttons -

DefaultDialog

public DefaultDialog(Dialog owner)
Convenience wrapper for DefaultDialog(Dialog, BUTTON_OKAY | BUTTON_CANCEL).


DefaultDialog

public DefaultDialog(Frame owner)
Convenience wrapper for DefaultDialog(Frame, BUTTON_OKAY | BUTTON_CANCEL).


DefaultDialog

public DefaultDialog()
Constructs a dialog with an okay and cancel button.

Method Detail

apply

public boolean apply()
Called by ApplyAction and OkayAction when the dialog is closed.

Returns:
true, if apply was successful and close() should be invoked; false, otherwise

cancelled

protected void cancelled()

defaults

protected void defaults()

close

public void close()
Disposes the dialog. Called by the actions to close the dialog. Sub classes can reimplement this.

See Also:
isOkay()

getButtonPanel

public JPanel getButtonPanel()
Returns the button panel. Sub classes can add aditional buttons to this panel.


getApplyAction

public Action getApplyAction()
Returns the apply action.


getCancelAction

public Action getCancelAction()
Returns the cancel action.


getDefaultsAction

public Action getDefaultsAction()
Returns the defaults action.


getOkayAction

public Action getOkayAction()
Returns the cancel action.


getHelpAction

public Action getHelpAction()
Returns the cancel action.


getContextHelpAction

public Action getContextHelpAction()
Returns the cancel action.


getCloseAction

public Action getCloseAction()
Returns the close action.


contextHelp

public void contextHelp()
Invoked when the context help button is selected.

Invokes WhatsThis.enterWhatsThisMode(). Sub-classes may override this method.


help

public void help()
Invoked when the context help is selected.

Does nothing. Sub-classes may override this method.


setApplyOnEnter

public void setApplyOnEnter(boolean apply)

setMainComponent

public void setMainComponent(Component component)
Sets the main component to component. TODO can this be called multiple times?, it can they are all added, don't know how this looks then


getMainPanel

public JPanel getMainPanel()
Returns the main panel. Sub classes can add components to this panel.


getTopPanel

public JPanel getTopPanel()
Returns the top most panel.


setButtonSeparatorVisible

public void setButtonSeparatorVisible(boolean visible)

isOkay

public boolean isOkay()
Returns true, if the dialog was closed with the Okay button.


show

public void show(Component c)
Sets this dialogs position relative to c and makes it visible.



Copyright © 2004-2007 XNap Commons Team. All Rights Reserved.