org.openstreetmap.josm.gui
Class ExtendedDialog

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.openstreetmap.josm.gui.ExtendedDialog
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.RootPaneContainer, javax.swing.WindowConstants
Direct Known Subclasses:
AddTagsDialog, CustomProjectionChoice.ParameterInfoDialog, ImageryAdjustAction.ImageryOffsetDialog, InspectPrimitiveDialog, LatLonDialog, ListEditor, ListListEditor, LogShowDialog, MapListEditor, RelationEditor, SessionSaveAsAction.SessionSaveAsDialog, SourceEditor.EditSourceEntryDialog, StringEditor, TaggingPresetSearchDialog

public class ExtendedDialog
extends javax.swing.JDialog

General configurable dialog window. If dialog is modal, you can use 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(
          Main.parent, 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...
  }
 

See Also:
Serialized Form

Nested Class Summary
(package private)  class ExtendedDialog.HelpAction
           
 
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
private  javax.swing.Icon[] bIcons
           
private  java.lang.String[] bTexts
           
private  java.lang.String[] bToolTipTexts
           
protected  java.util.ArrayList<javax.swing.JButton> buttons
           
private  java.util.List<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  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  javax.swing.JCheckBox toggleCheckbox
           
private  java.lang.String toggleCheckboxText
           
private  java.lang.String togglePref
           
private  int toggleValue
           
 
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
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)
           
 
Method Summary
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  java.awt.Dimension findMaxDialogSize()
          Tries to find a good value of how large the dialog should be
protected  void fixFocus()
          Don't focus the "do not show this again" check box, but the default button.
 int getValue()
          Retrieve the user choice after the dialog has been closed.
 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.
 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 size set by the user.
 ExtendedDialog setToggleCheckboxText(java.lang.String text)
          Overwrites the default "Don't show again" text of the toggle checkbox if you want to give more information.
 ExtendedDialog setToolTipTexts(java.lang.String[] toolTipTexts)
          Allows decorating the buttons with tooltips.
 void setupDialog()
          This is called by 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
private  boolean toggleCheckState(java.lang.String togglePref)
          This function returns true if the dialog has been set to "do not show again"
 ExtendedDialog toggleDisable()
          Call this if you "accidentally" called toggleEnable.
 ExtendedDialog toggleEnable(java.lang.String togglePref)
          Calling this will offer the user a "Do not show again" checkbox for the dialog.
private  void toggleSaveState()
          This function checks the state of the "Do not show again" checkbox and writes the corresponding pref.
 
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, 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, 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, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, 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, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

disposeOnClose

private final boolean disposeOnClose

result

private int result

DialogClosedOtherwise

public static final int DialogClosedOtherwise
See Also:
Constant Field Values

toggleable

private boolean toggleable

rememberSizePref

private java.lang.String rememberSizePref

defaultWindowGeometry

private WindowGeometry defaultWindowGeometry

togglePref

private java.lang.String togglePref

toggleValue

private int toggleValue

toggleCheckboxText

private java.lang.String toggleCheckboxText

toggleCheckbox

private javax.swing.JCheckBox toggleCheckbox

parent

private java.awt.Component parent

content

private java.awt.Component content

bTexts

private final java.lang.String[] bTexts

bToolTipTexts

private java.lang.String[] bToolTipTexts

bIcons

private javax.swing.Icon[] bIcons

cancelButtonIdx

private java.util.List<java.lang.Integer> cancelButtonIdx

defaultButtonIdx

private int defaultButtonIdx

defaultButton

protected javax.swing.JButton defaultButton

icon

private javax.swing.Icon icon

modal

private boolean modal

showHelpButton

private boolean showHelpButton
true, if the dialog should include a help button


helpTopic

private java.lang.String helpTopic
the help topic


placeContentInScrollPane

private boolean placeContentInScrollPane
set to true if the content of the extended dialog should be placed in a JScrollPane


contentInsets

protected java.awt.Insets contentInsets

buttons

protected java.util.ArrayList<javax.swing.JButton> buttons

setupDone

private boolean setupDone
Constructor Detail

ExtendedDialog

public ExtendedDialog(java.awt.Component parent,
                      java.lang.String title,
                      java.lang.String[] buttonTexts)
This method sets up the most basic options for the dialog. Add more advanced features with dedicated methods. Possible features: When done, call showDialog to display it. You can receive the user's choice using getValue. Have a look at this function for possible return values.

Parameters:
parent - The parent element that will be used for position and maximum size
title - The text that will be shown in the window titlebar
buttonTexts - String Array of the text that will appear on the buttons. The first button is the default one.

ExtendedDialog

public 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

public ExtendedDialog(java.awt.Component parent,
                      java.lang.String title,
                      java.lang.String[] buttonTexts,
                      boolean modal,
                      boolean disposeOnClose)
Method Detail

setButtonIcons

public ExtendedDialog setButtonIcons(javax.swing.Icon[] buttonIcons)
Allows decorating the buttons with icons.

Parameters:
buttonIcons -

setButtonIcons

public ExtendedDialog setButtonIcons(java.lang.String[] buttonIcons)
Convenience method to provide image names instead of images.


setToolTipTexts

public ExtendedDialog setToolTipTexts(java.lang.String[] toolTipTexts)
Allows decorating the buttons with tooltips. Expects a String array with translated tooltip texts.

Parameters:
toolTipTexts - the tool tip texts. Ignored, if null.

setContent

public ExtendedDialog setContent(java.awt.Component content)
Sets the content that will be displayed in the message dialog. Note that depending on your other settings more UI elements may appear. The content is played on top of the other elements though.

Parameters:
content - Any element that can be displayed in the message dialog

setContent

public ExtendedDialog setContent(java.awt.Component content,
                                 boolean placeContentInScrollPane)
Sets the content that will be displayed in the message dialog. Note that depending on your other settings more UI elements may appear. The content is played on top of the other elements though.

Parameters:
content - Any element that can be displayed in the message dialog
placeContentInScrollPane - if true, places the content in a JScrollPane

setContent

public ExtendedDialog setContent(java.lang.String message)
Sets the message that will be displayed. The String will be automatically wrapped if it is too long. Note that depending on your other settings more UI elements may appear. The content is played on top of the other elements though.

Parameters:
message - The text that should be shown to the user

setIcon

public ExtendedDialog setIcon(javax.swing.Icon icon)
Decorate the dialog with an icon that is shown on the left part of the window area. (Similar to how it is done in JOptionPane)


setIcon

public ExtendedDialog setIcon(int messageType)
Convenience method to allow values that would be accepted by JOptionPane as messageType.


showDialog

public ExtendedDialog showDialog()
Show the dialog to the user. Call this after you have set all options for the dialog. You can retrieve the result using getValue().


getValue

public int getValue()
Retrieve the user choice after the dialog has been closed.

Returns:
  • The selected button. The count starts with 1.
  • A return value of DialogClosedOtherwise means the dialog has been closed otherwise.

setupDialog

public void setupDialog()
This is called by showDialog(). Only invoke from outside if you need to modify the contentPane


buttonAction

protected void buttonAction(int buttonIndex,
                            java.awt.event.ActionEvent evt)
This gets performed whenever a button is clicked or activated

Parameters:
buttonIndex - the button index (first index is 0)
evt - the button event

findMaxDialogSize

protected java.awt.Dimension findMaxDialogSize()
Tries to find a good value of how large the dialog should be

Returns:
Dimension Size of the parent Component or 2/3 of screen size if not available

setupEscListener

private void setupEscListener()
Makes the dialog listen to ESC keypressed


setVisible

public void setVisible(boolean visible)
Override setVisible to be able to save the window geometry if required

Overrides:
setVisible in class java.awt.Dialog

setRememberWindowGeometry

public ExtendedDialog setRememberWindowGeometry(java.lang.String pref,
                                                WindowGeometry wg)
Call this if you want the dialog to remember the size set by the user. Set the pref to null 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, setMinSize

Parameters:
pref - The preference to save the dimension to
wg - The default window geometry that should be used if no existing preference is found (only takes effect if pref is not null or empty

toggleEnable

public ExtendedDialog toggleEnable(java.lang.String togglePref)
Calling this will offer the user a "Do not show again" checkbox for the dialog. Default is to not offer the choice; the dialog will be shown every time. Currently, this is not supported for non-modal dialogs.

Parameters:
togglePref - The preference to save the checkbox state to

toggleDisable

public ExtendedDialog toggleDisable()
Call this if you "accidentally" called toggleEnable. This doesn't need to be called for every dialog, as it's the default anyway.


setToggleCheckboxText

public ExtendedDialog setToggleCheckboxText(java.lang.String text)
Overwrites the default "Don't show again" text of the toggle checkbox if you want to give more information. Only has an effect if toggleEnable is set.

Parameters:
text -

setDefaultButton

public ExtendedDialog setDefaultButton(int defaultButtonIdx)
Sets the button that will react to ENTER.


setCancelButton

public 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

Parameters:
cancelButton - index of the button that stands for cancel, accepts multiple values

fixFocus

protected void fixFocus()
Don't focus the "do not show this again" check box, but the default button.


toggleCheckState

private boolean toggleCheckState(java.lang.String togglePref)
This function returns true if the dialog has been set to "do not show again"

Returns:
true if dialog should not be shown again

toggleSaveState

private void toggleSaveState()
This function checks the state of the "Do not show again" checkbox and writes the corresponding pref.


string2label

private static JMultilineLabel string2label(java.lang.String msg)
Convenience function that converts a given string into a JMultilineLabel

Parameters:
msg -
Returns:
JMultilineLabel

configureContextsensitiveHelp

public ExtendedDialog configureContextsensitiveHelp(java.lang.String helpTopic,
                                                    boolean showHelpButton)
Configures how this dialog support for context sensitive help.

Parameters:
helpTopic - the help topic
showHelpButton - true, if the dialog displays a help button


JOSM