Class DialogFooter
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
invalid reference
com.bric.swing.QDialog
DialogFooter
can exist by itself.
On the left of a footer are controls that should apply to the dialog itself,
such as "Help" button, or a "Reset Preferences" button.
On the far right are buttons that should dismiss this dialog. They
may be presented in different orders on different platforms based
on the reverseButtonOrder
boolean.
Buttons are also generally normalized, so the widths of buttons are equal.
This object will "latch onto" the RootPane that contains it. It is assumed two DialogFooters will not be contained in the same RootPane. It is also assumed the same DialogFooter will not be passed around to several different RootPanes.
Preset Options
This class has several OPTION constants to create specific buttons.In each constant the first option is the default button unless you specify otherwise. The Apple Interface Guidelines advises: "The default button should be the button that represents the action that the user is most likely to perform if that action isnŐt potentially dangerous."
The YES_NO options should be approached with special reluctance. Microsoft cautions, "Use Yes and No buttons only to respond to yes or no questions." This seems obvious enough, but Apple adds, "Button names should correspond to the action the user performs when pressing the buttonŃfor example, Erase, Save, or Delete." So instead of presenting a YES_NO dialog with the question "Do you want to continue?" a better dialog might provide the options "Cancel" and "Continue". In short: we as developers might tend to lazily use this option and phrase dialogs in such a way that yes/no options make sense, but in fact the commit buttons should be more descriptive.
Partly because of the need to avoid yes/no questions, DialogFooter
introduces the
dialog type: SAVE_DONT_SAVE_CANCEL_OPTION. This is mostly straightforward, but
there is one catch: on Mac the buttons
are reordered: "Save", "Cancel" and "Don't Save". This is to conform with standard
Mac behavior. (Or, more specifically: because the Apple guidelines
state that a button that can cause permanent data loss be as physically far
from a "safe" button as possible.) On all other platforms the buttons are
listed in the order "Save", "Don't Save" and "Cancel".
Also note the field reverseButtonOrder
controls the order each option is presented in the dialog from left-to-right.
Platform Differences
These are based mostly on studying Apple and Vista interface guidelines.invalid reference
com.bric.swing.JLink
DialogFooter.reverseButtonOrder
field for details.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
This action callsbutton.doClick()
.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
FieldsModifier and TypeFieldDescriptionprotected boolean
static final int
Used to indicate the user selected "Cancel" in a dialog.static Action
This action takes the Window associated with the source of this event, hides it, and then callsdispose()
on it.protected JButton
protected JComponent[]
static final int
Used to indicate the user selected "Don't Save" in a dialog.static final int
This (the default behavior) does nothing when the escape key is pressed.static final int
This triggers the cancel button when the escape key is pressed.static final int
This triggers the default button when the escape key is pressed.static final int
This triggers the non-default button when the escape key is pressed.static final boolean
static final boolean
protected JComponent
protected JComponent[]
static final int
Used to indicate the user selected "No" in a dialog.static final int
Used to indicate a dialog should present a "OK" and "Cancel" option.static final int
Used to indicate the user selected "OK" in a dialog.static final String
This client property is used to impose a meta-shortcut to click a button.static String
This is the client property of buttons created in static methods by this class.static final String
This client property is used to indicate a button is "unsafe".static boolean
This indicates whether the dismiss controls should be displayed in reverse order.static final int
Used to indicate a dialog should present a "Save", "Don't Save", and "Cancel" option.static final int
Used to indicate the user selected "Save" in a dialog.static ResourceBundle
The localized strings used in dialogs.static final int
Used to indicate a dialog should present a "Yes", "No", and "Cancel" option.static final int
Used to indicate a dialog should present a "Yes" and "No" option.static final int
Used to indicate the user selected "Yes" in a dialog.Fields inherited from class javax.swing.JComponent
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
accessibleContext, 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
ConstructorsConstructorDescriptionDialogFooter
(JComponent[] leftControls, JComponent[] dismissControls, boolean autoClose, JButton defaultButton) Create a newDialogFooter
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds anActionListener
.static JButton
createCancelButton
(boolean escapeKeyIsTrigger) Creates a new "Cancel" button.static DialogFooter
createDialogFooter
(JComponent[] leftComponents, int options, int escapeKeyBehavior) Creates aDialogFooter
and assigns a default button.static DialogFooter
createDialogFooter
(JComponent[] leftComponents, int options, int defaultButton, int escapeKeyBehavior) Creates aDialogFooter
.static JButton
Creates a new "Don't Save" button that is not triggered by the escape key.static JButton
createDontSaveButton
(boolean escapeKeyIsTrigger) Creates a new "Don't Save" button.static JButton
Creates a new "No" button that is not triggered by the escape key.static JButton
createNoButton
(boolean escapeKeyIsTrigger) Creates a new "No" button.static JButton
Creates a new "OK" button that is not triggered by the escape key.static JButton
createOKButton
(boolean escapeKeyIsTrigger) Creates a new "OK" button.static JButton
Creates a new "Save" button that is not triggered by the escape key.static JButton
createSaveButton
(boolean escapeKeyIsTrigger) Creates a new "Save" button.static JButton
Creates a new "Yes" button that is not triggered by the escape key.static JButton
createYesButton
(boolean escapeKeyIsTrigger) Creates a new "Yes" button.getButton
(int buttonType) Finds a certain type of button, if it is available.Returns a copy of thedismissControls
array used to construct this footer.Returns the component last used to dismiss the dialog.Returns a copy of theleftControls
array used to construct this footer.static void
makeEscapeKeyActivate
(AbstractButton button) This guarantees that when the escape key is pressed (if its parent window has the keyboard focus) this button is clicked.static void
normalizeButtons
(JButton[] buttons) This takes a set of buttons and gives them all the width/height of the largest button among them.void
Removes anActionListener
.void
reset()
This resets the value oflastSelectedComponent
to null.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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
ESCAPE_KEY_DOES_NOTHING
public static final int ESCAPE_KEY_DOES_NOTHINGThis (the default behavior) does nothing when the escape key is pressed.- See Also:
-
ESCAPE_KEY_TRIGGERS_CANCEL
public static final int ESCAPE_KEY_TRIGGERS_CANCELThis triggers the cancel button when the escape key is pressed. If no cancel button is present: this does nothing. (Also on Macs command+period acts the same as the escape key.)This should only be used if the cancel button does not lead to data loss, because users may quickly press the escape key before reading the text in a dialog.
- See Also:
-
ESCAPE_KEY_TRIGGERS_DEFAULT
public static final int ESCAPE_KEY_TRIGGERS_DEFAULTThis triggers the default button when the escape key is pressed. If no default button is defined: this does nothing. (Also on Macs command+period acts the same as the escape key.)This should only be used if the default button does not lead to data loss, because users may quickly press the escape key before reading the text in a dialog.
- See Also:
-
ESCAPE_KEY_TRIGGERS_NONDEFAULT
public static final int ESCAPE_KEY_TRIGGERS_NONDEFAULTThis triggers the non-default button when the escape key is pressed. If no non-default button is defined: this does nothing. (Also on Macs command+period acts the same as the escape key.)This should only be used if the non-default button does not lead to data loss, because users may quickly press the escape key before reading the text in a dialog.
- See Also:
-
strings
The localized strings used in dialogs. -
PROPERTY_OPTION
This is the client property of buttons created in static methods by this class. -
CANCEL_OPTION
public static final int CANCEL_OPTIONUsed to indicate the user selected "Cancel" in a dialog.
Also this can be used as a dialog type, to indicate that "Cancel" should be the only option presented to the user.Note the usage is similar to JOptionPane's, but the numerical value is different, so you cannot substitute JOptionPane.CANCEL_OPTION for DialogFooter.CANCEL_OPTION.
-
OK_OPTION
public static final int OK_OPTIONUsed to indicate the user selected "OK" in a dialog.
Also this can be used as a dialog type, to indicate that "OK" should be the only option presented to the user.Note the usage is similar to JOptionPane's, but the numerical value is different, so you cannot substitute JOptionPane.OK_OPTION for DialogFooter.OK_OPTION.
-
NO_OPTION
public static final int NO_OPTIONUsed to indicate the user selected "No" in a dialog.
Also this can be used as a dialog type, to indicate that "No" should be the only option presented to the user.Note the usage is similar to JOptionPane's, but the numerical value is different, so you cannot substitute JOptionPane.NO_OPTION for DialogFooter.NO_OPTION.
-
YES_OPTION
public static final int YES_OPTIONUsed to indicate the user selected "Yes" in a dialog.
Also this can be used as a dialog type, to indicate that "Yes" should be the only option presented to the user.Note the usage is similar to JOptionPane's, but the numerical value is different, so you cannot substitute JOptionPane.YES_OPTION for DialogFooter.YES_OPTION.
-
YES_NO_OPTION
public static final int YES_NO_OPTIONUsed to indicate a dialog should present a "Yes" and "No" option.Note the usage is similar to JOptionPane's, but the numerical value is different, so you cannot substitute JOptionPane.YES_NO_OPTION for DialogFooter.YES_NO_OPTION.
-
YES_NO_CANCEL_OPTION
public static final int YES_NO_CANCEL_OPTIONUsed to indicate a dialog should present a "Yes", "No", and "Cancel" option.Note the usage is similar to JOptionPane's, but the numerical value is different, so you cannot substitute JOptionPane.YES_NO_CANCEL_OPTION for DialogFooter.YES_NO_CANCEL_OPTION.
-
OK_CANCEL_OPTION
public static final int OK_CANCEL_OPTIONUsed to indicate a dialog should present a "OK" and "Cancel" option.Note the usage is similar to JOptionPane's, but the numerical value is different, so you cannot substitute JOptionPane.OK_CANCEL_OPTION for DialogFooter.OK_CANCEL_OPTION.
-
SAVE_DONT_SAVE_CANCEL_OPTION
public static final int SAVE_DONT_SAVE_CANCEL_OPTIONUsed to indicate a dialog should present a "Save", "Don't Save", and "Cancel" option. -
SAVE_OPTION
public static final int SAVE_OPTIONUsed to indicate the user selected "Save" in a dialog.
Also this can be used as a dialog type, to indicate that "Save" should be the only option presented to the user. -
DONT_SAVE_OPTION
public static final int DONT_SAVE_OPTIONUsed to indicate the user selected "Don't Save" in a dialog.
Also this can be used as a dialog type, to indicate that "Don't Save" should be the only option presented to the user. -
isMac
public static final boolean isMac -
isVista
public static final boolean isVista -
PROPERTY_META_SHORTCUT
This client property is used to impose a meta-shortcut to click a button. This should map to a Character.- See Also:
-
PROPERTY_UNSAFE
This client property is used to indicate a button is "unsafe". Apple guidelines state that "unsafe" buttons (such as "discard changes") should be several pixels away from "safe" buttons.- See Also:
-
reverseButtonOrder
public static boolean reverseButtonOrderThis indicates whether the dismiss controls should be displayed in reverse order. When you construct a DialogFooter, the dismiss controls should be listed in order of priority (with the most preferred listed first, the least preferred last). If this boolean is false, then those components will be listed in that order. If this is true, then those components will be listed in the reverse order.By default on Mac this is true, because Macs put the default button on the right side of dialogs. On all other platforms this is false by default.
Window's guidelines advise to, "Position the most important button -- typically the default command -- as the first button in the set."
-
leftControls
-
dismissControls
-
lastSelectedComponent
-
autoClose
protected boolean autoClose -
defaultButton
-
closeDialogAndDisposeAction
This action takes the Window associated with the source of this event, hides it, and then callsdispose()
on it.(This will not throw an exception if there is no parent window, but it does nothing in that case...)
-
-
Constructor Details
-
DialogFooter
public DialogFooter(JComponent[] leftControls, JComponent[] dismissControls, boolean autoClose, JButton defaultButton) Create a newDialogFooter
.- Parameters:
leftControls
- the controls on the left side of this dialog, such as a help component, or a "Reset" button.dismissControls
- the controls on the right side of this dialog that should dismiss this dialog. Also called "action" buttons.autoClose
- whether the dismiss buttons should automatically close the containing window. If this isfalse
, then it is assumed someone else is taking care of closing/disposing the containing dialogdefaultButton
- the optional button indismissControls
to make the default button in this dialog. (May be null.)
-
-
Method Details
-
createCancelButton
Creates a new "Cancel" button.- Parameters:
escapeKeyIsTrigger
- if true then pressing the escape key will trigger this button. (Also on Macs command-period will act like the escape key.) This should befalse
if this button can lead to permanent data loss.
-
makeEscapeKeyActivate
This guarantees that when the escape key is pressed (if its parent window has the keyboard focus) this button is clicked.It is assumed that no two buttons will try to consume escape keys in the same window.
- Parameters:
button
- the button to trigger when the escape key is pressed.
-
createOKButton
Creates a new "OK" button that is not triggered by the escape key. -
createOKButton
Creates a new "OK" button.- Parameters:
escapeKeyIsTrigger
- if true then pressing the escape key will trigger this button. (Also on Macs command-period will act like the escape key.) This should befalse
if this button can lead to permanent data loss.
-
createYesButton
Creates a new "Yes" button that is not triggered by the escape key. -
createYesButton
Creates a new "Yes" button.- Parameters:
escapeKeyIsTrigger
- if true then pressing the escape key will trigger this button. (Also on Macs command-period will act like the escape key.) This should befalse
if this button can lead to permanent data loss.
-
createNoButton
Creates a new "No" button that is not triggered by the escape key. -
createNoButton
Creates a new "No" button.- Parameters:
escapeKeyIsTrigger
- if true then pressing the escape key will trigger this button. (Also on Macs command-period will act like the escape key.) This should befalse
if this button can lead to permanent data loss.
-
createSaveButton
Creates a new "Save" button that is not triggered by the escape key. -
createSaveButton
Creates a new "Save" button.- Parameters:
escapeKeyIsTrigger
- if true then pressing the escape key will trigger this button. (Also on Macs command-period will act like the escape key.) This should befalse
if this button can lead to permanent data loss.
-
createDontSaveButton
Creates a new "Don't Save" button that is not triggered by the escape key. -
createDontSaveButton
Creates a new "Don't Save" button.- Parameters:
escapeKeyIsTrigger
- if true then pressing the escape key will trigger this button. (Also on Macs command-period will act like the escape key.) This should befalse
if this button can lead to permanent data loss.
-
normalizeButtons
This takes a set of buttons and gives them all the width/height of the largest button among them.(More specifically, this sets the
preferredSize
of each button to the largest preferred size in the list of buttons.- Parameters:
buttons
- an array of buttons.
-
addActionListener
Adds anActionListener
.- Parameters:
l
- this listener will be notified when adismissControl
is activated.
-
removeActionListener
Removes anActionListener
. -
getLastSelectedComponent
Returns the component last used to dismiss the dialog.Note the components on the left side of this footer (such as a "Help" button or a "Reset Preferences" button) do NOT dismiss the dialog, and so this method has nothing to do with those components. This only related to the components on the right side of dialog.
- Returns:
- the component last used to dismiss the dialog.
-
getButton
Finds a certain type of button, if it is available.- Parameters:
buttonType
- of the options in this class (such as YES_OPTION or CANCEL_OPTION)- Returns:
- the button that maps to that option, or null if no such button was found.
-
reset
public void reset()This resets the value oflastSelectedComponent
to null.If this footer is recycled in different dialogs, then you may need to nullify this value for
getLastSelectedComponent()
to remain relevant. -
getDismissControls
Returns a copy of thedismissControls
array used to construct this footer. -
getLeftControls
Returns a copy of theleftControls
array used to construct this footer.
-