Class ExtendedDialog

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (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, java.awt.Window.Type
      • 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
    • Constructor Summary

      Constructors 
      Constructor 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.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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​(java.lang.String... buttonIcons)
      Convenience method to provide image names instead of images.
      ExtendedDialog setButtonIcons​(javax.swing.Icon... buttonIcons)
      Allows decorating the buttons with icons.
      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​(int messageType)
      Convenience method to allow values that would be accepted by JOptionPane as messageType.
      ExtendedDialog setIcon​(javax.swing.Icon icon)
      Decorate the dialog with an icon that is shown on the left part of the window area.
      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.
      • 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, setBackground, setModal, setModalityType, setOpacity, setResizable, setShape, setTitle, setUndecorated, show, toBack
      • Methods inherited from class java.awt.Window

        addPropertyChangeListener, 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, 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, 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, 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, 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, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setMixingCutoutShape, 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
    • 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:
        • setButtonIcons
        • setContent
        • toggleEnable
        • toggleDisable
        • setToggleCheckboxText
        • setRememberWindowGeometry
        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.
        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.
        modal - Set it to true if you want the dialog to be modal
      • ExtendedDialog

        public 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.
        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.
        modal - Set it to true if you want the dialog to be modal
        disposeOnClose - whether to call Window.dispose() when closing the dialog
    • Method Detail

      • searchRealParent

        private static java.awt.Frame searchRealParent​(java.awt.Component parent)
      • setToolTipTexts

        public ExtendedDialog setToolTipTexts​(java.lang.String... toolTipTexts)
        Description copied from interface: IExtendedDialog
        Allows decorating the buttons with tooltips. Expects a String array with translated tooltip texts.
        Specified by:
        setToolTipTexts in interface IExtendedDialog
        Parameters:
        toolTipTexts - the tool tip texts. Ignored, if null.
        Returns:
        this
      • setContent

        public ExtendedDialog setContent​(java.awt.Component content)
        Description copied from interface: IExtendedDialog
        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.
        Specified by:
        setContent in interface IExtendedDialog
        Parameters:
        content - Any element that can be displayed in the message dialog
        Returns:
        this
      • setContent

        public ExtendedDialog setContent​(java.awt.Component content,
                                         boolean placeContentInScrollPane)
        Description copied from interface: IExtendedDialog
        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.
        Specified by:
        setContent in interface IExtendedDialog
        Parameters:
        content - Any element that can be displayed in the message dialog
        placeContentInScrollPane - if true, places the content in a JScrollPane
        Returns:
        this
      • setContent

        public ExtendedDialog setContent​(java.lang.String message)
        Description copied from interface: IExtendedDialog
        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.
        Specified by:
        setContent in interface IExtendedDialog
        Parameters:
        message - The text that should be shown to the user
        Returns:
        this
      • setIcon

        public ExtendedDialog setIcon​(javax.swing.Icon icon)
        Description copied from interface: IExtendedDialog
        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)
        Specified by:
        setIcon in interface IExtendedDialog
        Parameters:
        icon - The icon to display
        Returns:
        this
      • setIcon

        public ExtendedDialog setIcon​(int messageType)
        Description copied from interface: IExtendedDialog
        Convenience method to allow values that would be accepted by JOptionPane as messageType.
        Specified by:
        setIcon in interface IExtendedDialog
        Parameters:
        messageType - The JOptionPane messageType
        Returns:
        this
      • getValue

        public int getValue()
        Description copied from interface: IExtendedDialog
        Retrieve the user choice after the dialog has been closed.
        Specified by:
        getValue in interface IExtendedDialog
        Returns:
        • The selected button. The count starts with 1.
        • A return value of DialogClosedOtherwise means the dialog has been closed otherwise.
      • 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 if visible or 2/3 of screen size if not available or hidden
      • 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)
        Description copied from interface: IExtendedDialog
        Call this if you want the dialog to remember the geometry (size and position) 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
        Specified by:
        setRememberWindowGeometry in interface IExtendedDialog
        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
        Returns:
        this
      • toggleEnable

        public ExtendedDialog toggleEnable​(java.lang.String togglePref)
        Description copied from interface: IExtendedDialog
        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.
        Specified by:
        toggleEnable in interface IExtendedDialog
        Parameters:
        togglePref - The preference to save the checkbox state to
        Returns:
        this
      • setCancelButton

        public ExtendedDialog setCancelButton​(java.lang.Integer... cancelButtonIdx)
        Description copied from interface: IExtendedDialog
        Used in combination with toggle: If the user presses 'cancel' the toggle settings are ignored and not saved to the pref
        Specified by:
        setCancelButton in interface IExtendedDialog
        Parameters:
        cancelButtonIdx - index of the button that stands for cancel, accepts multiple values
        Returns:
        this
      • toggleSaveState

        protected 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 - the message to display
        Returns:
        JMultilineLabel displaying msg
      • configureContextsensitiveHelp

        public ExtendedDialog configureContextsensitiveHelp​(java.lang.String helpTopic,
                                                            boolean showHelpButton)
        Description copied from interface: IExtendedDialog
        Configures how this dialog support for context sensitive help.
        • if helpTopic is null, the dialog doesn't provide context sensitive help
        • if helpTopic != null, the dialog redirect user to the help page for this helpTopic when the user clicks F1 in the dialog
        • if showHelpButton is true, the dialog displays "Help" button (rightmost button in the button row)
        Specified by:
        configureContextsensitiveHelp in interface IExtendedDialog
        Parameters:
        helpTopic - the help topic
        showHelpButton - true, if the dialog displays a help button
        Returns:
        this