info.aduna.swing
Class DialogTemplate

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by info.aduna.swing.DialogTemplate
All Implemented Interfaces:
ActionListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible

public class DialogTemplate
extends JPanel
implements ActionListener

A template that can be used to construct dialogs. Such a dialog will look like this:

Title
icon message
buttons
The dialog always show one "message", which can be anything as long as it's a JComponent. The icon is an optional decoration.

Any number of buttons can be added to the dialog, they are layed out from left to right in the order they were added. A button must be of class JButton or of some subclass of JButton. Buttons don't automatically close the dialog, this can be set when a button is added.

As the dialog's components are layed out on the DialogTemplate itself and since that is a JPanel, changing display properties of the DialogTemplate will also effect the dialog (e.g. changing the background color will result in a dialog with that background color).

This implementation is a redo of the JOptionPane because that implementation is far too restrictive.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
DialogTemplate()
          Creates a new non-modal DialogTemplate.
DialogTemplate(JComponent message)
          Creates a new non-modal DialogTemplate that will display the supplied message.
 
Method Summary
 void actionPerformed(ActionEvent e)
          DialogTemplate listens to ActionEvents from buttons that should hide the dialog.
 JButton addButton(Icon icon, boolean hidesDialog)
          Adds a JButton with a certain icon on it to the dialog.
 JButton addButton(JButton button, boolean hidesDialog)
          Adds a JButton to the dialog.
 JButton addButton(String label, boolean hidesDialog)
          Adds a JButton with a certain label to the dialog.
 void addWindowListener(WindowListener listener)
           
 void disposeDialog()
          Gets rid of the dialog.
 JButton getClickedButton()
          Gets the button that caused the dialog to hide.
 void hideDialog()
          Hides the dialog.
 void makeModalOn(Window owner)
          Makes the dialog modal on the supplied owner.
 void makeNonModal()
          Makes the dialog non-modal.
 void removeWindowListener(WindowListener listener)
           
 void setDefaultButton(JButton button)
          Sets the default button of the dialog.
 void setIcon(Icon icon)
          Sets the icon to display on the dialog.
 void setMessage(JComponent message)
          Sets the "message" for the dialog.
 void setParent(Component parent)
          Sets the 'parent' of the dialog.
 void setTitle(String title)
          Sets the title for the dialog.
 void showDialog()
          Shows the dialog.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DialogTemplate

public DialogTemplate()
Creates a new non-modal DialogTemplate. Don't forget to set the message for the dialog! Trying to show a dialog when no message is set will result in an exception.


DialogTemplate

public DialogTemplate(JComponent message)
Creates a new non-modal DialogTemplate that will display the supplied message. The DialogTemplate will supply the spacing around the message component.

Parameters:
message - The message to display
Method Detail

setMessage

public void setMessage(JComponent message)
Sets the "message" for the dialog. This message can be anything as long as it's a JComponent. The DialogTemplate will supply the spacing around the message component.

Parameters:
message - The (new) message

setIcon

public void setIcon(Icon icon)
Sets the icon to display on the dialog.

Parameters:
icon - The icon to display

addButton

public JButton addButton(String label,
                         boolean hidesDialog)
Adds a JButton with a certain label to the dialog. This is a convenience method that creates a JButton and uses addButton(JButton, boolean) to add it to the dialog.

Parameters:
label - The label for the button
hidesDialog - Flag indicating whether a click on the button should hide the dialog
Returns:
The created button

addButton

public JButton addButton(Icon icon,
                         boolean hidesDialog)
Adds a JButton with a certain icon on it to the dialog. This is a convenience method that creates a JButton and uses addButton(JButton, boolean) to add it to the dialog.

Parameters:
icon - The icon for the button
hidesDialog - Flag indicating whether a click on the button should hide the dialog
Returns:
The created button

addButton

public JButton addButton(JButton button,
                         boolean hidesDialog)
Adds a JButton to the dialog. You can indicate whether or not a click on the button hides the dialog. This way you have maximum control over the buttons. You can even add "previous" and "next" buttons to create a wizard.

Parameters:
button - The button to add
hidesDialog - Flag indicating whether a click on the button should hide the dialog
Returns:
The added button

getClickedButton

public JButton getClickedButton()
Gets the button that caused the dialog to hide.

Returns:
The button that caused the dialog to hide or null if the dialog was not hidden using a button

actionPerformed

public void actionPerformed(ActionEvent e)
DialogTemplate listens to ActionEvents from buttons that should hide the dialog. This method should not be called directly.

Specified by:
actionPerformed in interface ActionListener

setDefaultButton

public void setDefaultButton(JButton button)
Sets the default button of the dialog. If the specified button was not added already, it is added now.


setTitle

public void setTitle(String title)
Sets the title for the dialog.

Parameters:
title - The (new) title

makeModalOn

public void makeModalOn(Window owner)
Makes the dialog modal on the supplied owner. This 'owner' is the component that will block when the dialog is shown. The 'owner' should be a (subclass of) Frame or Dialog.

Parameters:
owner - The 'owner' of the dialog
Throws:
IllegalArgumentException - If 'owner' is not a (subclass of) Frame or Dialog, or if it is equal to 'null'.

makeNonModal

public void makeNonModal()
Makes the dialog non-modal.


setParent

public void setParent(Component parent)
Sets the 'parent' of the dialog. The dialog's position on screen will be based on the position of the parent.

Parameters:
parent - The (new) parent of the component, or null if no parent should be set

addWindowListener

public void addWindowListener(WindowListener listener)

removeWindowListener

public void removeWindowListener(WindowListener listener)

showDialog

public void showDialog()
Shows the dialog. If the dialog is set to modal, the method call will block until the dialog is closed. If the dialog is closed by a click on a button, then getClickedButton() will return that button.


hideDialog

public void hideDialog()
Hides the dialog. Any calls to 'showDialog()' will be unblocked.


disposeDialog

public void disposeDialog()
Gets rid of the dialog.



Copyright © 1997-2008 Aduna. All Rights Reserved.