public class ExtendedDialog extends javax.swing.JDialog implements IExtendedDialog
getValue() to retrieve the
button index. Note that the user can close the dialog
by other means. This is usually equivalent to cancel action.
For non-modal dialogs, buttonAction(int, ActionEvent) can be overridden.
There are various options, see below.
Note: The button indices are counted from 1 and upwards.
So for getValue(), setDefaultButton(int) and
setCancelButton(java.lang.Integer...) the first button has index 1.
Simple example:
ExtendedDialog ed = new ExtendedDialog(
MainApplication.getMainFrame(), tr("Dialog Title"),
new String[] {tr("Ok"), tr("Cancel")});
ed.setButtonIcons(new String[] {"ok", "cancel"}); // optional
ed.setIcon(JOptionPane.WARNING_MESSAGE); // optional
ed.setContent(tr("Really proceed? Interesting things may happen..."));
ed.showDialog();
if (ed.getValue() == 1) { // user clicked first button "Ok"
// proceed...
}
| Modifier and Type | Class and Description |
|---|---|
(package private) class |
ExtendedDialog.HelpAction |
javax.swing.JDialog.AccessibleJDialogjava.awt.Dialog.AccessibleAWTDialog, java.awt.Dialog.ModalExclusionType, java.awt.Dialog.ModalityTypejava.awt.Window.AccessibleAWTWindow, java.awt.Window.Type| Modifier and Type | Field and Description |
|---|---|
private javax.swing.Icon[] |
bIcons |
private java.lang.String[] |
bTexts |
private java.lang.String[] |
bToolTipTexts |
protected java.util.List<javax.swing.JButton> |
buttons |
private java.util.Set<java.lang.Integer> |
cancelButtonIdx |
private java.awt.Component |
content |
protected java.awt.Insets |
contentInsets |
protected javax.swing.JButton |
defaultButton |
private int |
defaultButtonIdx |
private WindowGeometry |
defaultWindowGeometry |
static int |
DialogClosedOtherwise |
private boolean |
disposeOnClose |
private boolean |
focusOnDefaultButton |
private java.lang.String |
helpTopic
the help topic
|
private javax.swing.Icon |
icon |
private boolean |
modal |
private java.awt.Component |
parent |
private boolean |
placeContentInScrollPane
set to true if the content of the extended dialog should
be placed in a
JScrollPane |
private java.lang.String |
rememberSizePref |
private int |
result |
private boolean |
setupDone |
private boolean |
showHelpButton
true, if the dialog should include a help button
|
private boolean |
toggleable |
private ConditionalOptionPaneUtil.MessagePanel |
togglePanel |
private java.lang.String |
togglePref |
private int |
toggleValue |
accessibleContext, rootPane, rootPaneCheckingEnabledBOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT| Constructor and Description |
|---|
ExtendedDialog(java.awt.Component parent,
java.lang.String title,
java.lang.String... buttonTexts)
This method sets up the most basic options for the dialog.
|
ExtendedDialog(java.awt.Component parent,
java.lang.String title,
java.lang.String[] buttonTexts,
boolean modal)
Same as above but lets you define if the dialog should be modal.
|
ExtendedDialog(java.awt.Component parent,
java.lang.String title,
java.lang.String[] buttonTexts,
boolean modal,
boolean disposeOnClose)
Same as above but lets you define if the dialog should be disposed on close.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
buttonAction(int buttonIndex,
java.awt.event.ActionEvent evt)
This gets performed whenever a button is clicked or activated
|
ExtendedDialog |
configureContextsensitiveHelp(java.lang.String helpTopic,
boolean showHelpButton)
Configures how this dialog support for context sensitive help.
|
protected javax.swing.Action |
createButtonAction(int i) |
protected java.awt.Dimension |
findMaxDialogSize()
Tries to find a good value of how large the dialog should be
|
int |
getValue()
Retrieve the user choice after the dialog has been closed.
|
protected WindowGeometry |
initWindowGeometry() |
protected void |
rememberWindowGeometry(WindowGeometry geometry) |
private void |
requestFocusToDefaultButton() |
private static java.awt.Frame |
searchRealParent(java.awt.Component parent) |
ExtendedDialog |
setButtonIcons(javax.swing.Icon... buttonIcons)
Allows decorating the buttons with icons.
|
ExtendedDialog |
setButtonIcons(java.lang.String... buttonIcons)
Convenience method to provide image names instead of images.
|
ExtendedDialog |
setCancelButton(java.lang.Integer... cancelButtonIdx)
Used in combination with toggle:
If the user presses 'cancel' the toggle settings are ignored and not saved to the pref
|
ExtendedDialog |
setContent(java.awt.Component content)
Sets the content that will be displayed in the message dialog.
|
ExtendedDialog |
setContent(java.awt.Component content,
boolean placeContentInScrollPane)
Sets the content that will be displayed in the message dialog.
|
ExtendedDialog |
setContent(java.lang.String message)
Sets the message that will be displayed.
|
ExtendedDialog |
setDefaultButton(int defaultButtonIdx)
Sets the button that will react to ENTER.
|
void |
setFocusOnDefaultButton(boolean focus)
Makes default button request initial focus or not.
|
ExtendedDialog |
setIcon(javax.swing.Icon icon)
Decorate the dialog with an icon that is shown on the left part of
the window area.
|
ExtendedDialog |
setIcon(int messageType)
Convenience method to allow values that would be accepted by
JOptionPane as messageType. |
ExtendedDialog |
setRememberWindowGeometry(java.lang.String pref,
WindowGeometry wg)
Call this if you want the dialog to remember the geometry (size and position) set by the user.
|
ExtendedDialog |
setToolTipTexts(java.lang.String... toolTipTexts)
Allows decorating the buttons with tooltips.
|
void |
setupDialog()
This is called by
IExtendedDialog.showDialog(). |
private void |
setupEscListener()
Makes the dialog listen to ESC keypressed
|
void |
setVisible(boolean visible)
Override setVisible to be able to save the window geometry if required
|
ExtendedDialog |
showDialog()
Show the dialog to the user.
|
private static JMultilineLabel |
string2label(java.lang.String msg)
Convenience function that converts a given string into a JMultilineLabel
|
boolean |
toggleCheckState()
This function returns true if the dialog has been set to "do not show again"
|
ExtendedDialog |
toggleEnable(java.lang.String togglePref)
Calling this will offer the user a "Do not show again" checkbox for the
dialog.
|
protected void |
toggleSaveState()
This function checks the state of the "Do not show again" checkbox and
writes the corresponding pref.
|
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, updateaddNotify, getModalityType, getTitle, hide, isModal, isResizable, isUndecorated, setBackground, setModal, setModalityType, setOpacity, setResizable, setShape, setTitle, setUndecorated, show, toBackaddPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeNotify, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImage, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, toFrontadd, 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, transferFocusDownCycle, validate, validateTreeaction, 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, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, 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, 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, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycleprivate final boolean disposeOnClose
private volatile int result
public static final int DialogClosedOtherwise
private boolean toggleable
private java.lang.String rememberSizePref
private transient WindowGeometry defaultWindowGeometry
private java.lang.String togglePref
private int toggleValue
private ConditionalOptionPaneUtil.MessagePanel togglePanel
private java.awt.Component parent
private java.awt.Component content
private final java.lang.String[] bTexts
private java.lang.String[] bToolTipTexts
private transient javax.swing.Icon[] bIcons
private java.util.Set<java.lang.Integer> cancelButtonIdx
private int defaultButtonIdx
protected javax.swing.JButton defaultButton
private transient javax.swing.Icon icon
private boolean modal
private boolean focusOnDefaultButton
private boolean showHelpButton
private java.lang.String helpTopic
private boolean placeContentInScrollPane
JScrollPaneprotected transient java.awt.Insets contentInsets
protected transient java.util.List<javax.swing.JButton> buttons
private boolean setupDone
public ExtendedDialog(java.awt.Component parent, java.lang.String title, java.lang.String... buttonTexts)
setButtonIconssetContenttoggleEnabletoggleDisablesetToggleCheckboxTextsetRememberWindowGeometryshowDialog to display it. You can receive
the user's choice using getValue. Have a look at this function
for possible return values.parent - The parent element that will be used for position and maximum sizetitle - The text that will be shown in the window titlebarbuttonTexts - String Array of the text that will appear on the buttons. The first button is the default one.public ExtendedDialog(java.awt.Component parent, java.lang.String title, java.lang.String[] buttonTexts, boolean modal)
parent - The parent element that will be used for position and maximum sizetitle - The text that will be shown in the window titlebarbuttonTexts - String Array of the text that will appear on the buttons. The first button is the default one.modal - Set it to true if you want the dialog to be modalpublic ExtendedDialog(java.awt.Component parent, java.lang.String title, java.lang.String[] buttonTexts, boolean modal, boolean disposeOnClose)
parent - The parent element that will be used for position and maximum sizetitle - The text that will be shown in the window titlebarbuttonTexts - String Array of the text that will appear on the buttons. The first button is the default one.modal - Set it to true if you want the dialog to be modaldisposeOnClose - whether to call Window.dispose() when closing the dialogprivate static java.awt.Frame searchRealParent(java.awt.Component parent)
public ExtendedDialog setButtonIcons(javax.swing.Icon... buttonIcons)
IExtendedDialogsetButtonIcons in interface IExtendedDialogbuttonIcons - The button iconsthispublic ExtendedDialog setButtonIcons(java.lang.String... buttonIcons)
IExtendedDialogsetButtonIcons in interface IExtendedDialogbuttonIcons - The button icon namesthispublic ExtendedDialog setToolTipTexts(java.lang.String... toolTipTexts)
IExtendedDialogsetToolTipTexts in interface IExtendedDialogtoolTipTexts - the tool tip texts. Ignored, if null.thispublic ExtendedDialog setContent(java.awt.Component content)
IExtendedDialogsetContent in interface IExtendedDialogcontent - Any element that can be displayed in the message dialogthispublic ExtendedDialog setContent(java.awt.Component content, boolean placeContentInScrollPane)
IExtendedDialogsetContent in interface IExtendedDialogcontent - Any element that can be displayed in the message dialogplaceContentInScrollPane - if true, places the content in a JScrollPanethispublic ExtendedDialog setContent(java.lang.String message)
IExtendedDialogsetContent in interface IExtendedDialogmessage - The text that should be shown to the userthispublic ExtendedDialog setIcon(javax.swing.Icon icon)
IExtendedDialogJOptionPane)setIcon in interface IExtendedDialogicon - The icon to displaythispublic ExtendedDialog setIcon(int messageType)
IExtendedDialogJOptionPane as messageType.setIcon in interface IExtendedDialogmessageType - The JOptionPane messageTypethispublic ExtendedDialog showDialog()
IExtendedDialogIExtendedDialog.getValue().showDialog in interface IExtendedDialogthispublic int getValue()
IExtendedDialoggetValue in interface IExtendedDialogDialogClosedOtherwise means the dialog has been closed otherwise.public void setupDialog()
IExtendedDialogIExtendedDialog.showDialog().
Only invoke from outside if you need to modify the contentPanesetupDialog in interface IExtendedDialogprotected javax.swing.Action createButtonAction(int i)
protected void buttonAction(int buttonIndex, java.awt.event.ActionEvent evt)
buttonIndex - the button index (first index is 0)evt - the button eventprotected java.awt.Dimension findMaxDialogSize()
private void setupEscListener()
protected final void rememberWindowGeometry(WindowGeometry geometry)
protected final WindowGeometry initWindowGeometry()
public void setVisible(boolean visible)
setVisible in class java.awt.Dialogpublic ExtendedDialog setRememberWindowGeometry(java.lang.String pref, WindowGeometry wg)
IExtendedDialognull or to an empty string to disable again.
By default, it's disabled.
Note: If you want to set the width of this dialog directly use the usual
setSize, setPreferredSize, setMaxSize, setMinSizesetRememberWindowGeometry in interface IExtendedDialogpref - The preference to save the dimension towg - The default window geometry that should be used if no
existing preference is found (only takes effect if
pref is not null or emptythispublic ExtendedDialog toggleEnable(java.lang.String togglePref)
IExtendedDialogtoggleEnable in interface IExtendedDialogtogglePref - The preference to save the checkbox state tothispublic ExtendedDialog setDefaultButton(int defaultButtonIdx)
IExtendedDialogsetDefaultButton in interface IExtendedDialogdefaultButtonIdx - The button index (starts to 1)thispublic ExtendedDialog setCancelButton(java.lang.Integer... cancelButtonIdx)
IExtendedDialogsetCancelButton in interface IExtendedDialogcancelButtonIdx - index of the button that stands for cancel, accepts multiple valuesthispublic void setFocusOnDefaultButton(boolean focus)
IExtendedDialogsetFocusOnDefaultButton in interface IExtendedDialogfocus - true to make default button request initial focusprivate void requestFocusToDefaultButton()
public final boolean toggleCheckState()
IExtendedDialogtoggleCheckState in interface IExtendedDialogprotected void toggleSaveState()
private static JMultilineLabel string2label(java.lang.String msg)
msg - the message to displaymsgpublic ExtendedDialog configureContextsensitiveHelp(java.lang.String helpTopic, boolean showHelpButton)
IExtendedDialogconfigureContextsensitiveHelp in interface IExtendedDialoghelpTopic - the help topicshowHelpButton - true, if the dialog displays a help buttonthis