Package jmri.util

Class QuickPromptUtil


  • public class QuickPromptUtil
    extends java.lang.Object
    A collection of utilities related to prompting for values
    • Constructor Summary

      Constructors 
      Constructor Description
      QuickPromptUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.function.Predicate<java.lang.Integer> checkIntRange​(java.lang.Integer min, java.lang.Integer max, java.lang.String valueLabel)
      Creates a min/max predicate which will check the bounds.
      static double promptForDouble​(java.awt.Component parentComponent, java.lang.String message, java.lang.String title, double oldValue)
      Utility function to prompt for new double value.
      static float promptForFloat​(java.awt.Component parentComponent, java.lang.String message, java.lang.String title, float oldValue)
      Utility function to prompt for new float value.
      static int promptForInt​(java.awt.Component parentComponent, java.lang.String message, java.lang.String title, int oldValue)
      Utility function to prompt for new integer value.
      static java.lang.Integer promptForInteger​(java.awt.Component parentComponent, java.lang.String message, java.lang.String title, java.lang.Integer oldValue, java.util.function.Predicate<java.lang.Integer> validator)
      Utility function to prompt for new integer value.
      static java.lang.String promptForString​(java.awt.Component parentComponent, java.lang.String message, java.lang.String title, java.lang.String oldValue)
      Utility function to prompt for new string value.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • promptForString

        public static java.lang.String promptForString​(java.awt.Component parentComponent,
                                                       java.lang.String message,
                                                       java.lang.String title,
                                                       java.lang.String oldValue)
        Utility function to prompt for new string value.
        Parameters:
        parentComponent - the parent component
        message - the prompt message
        title - the dialog title
        oldValue - the original string value
        Returns:
        the new string value
      • promptForInt

        public static int promptForInt​(java.awt.Component parentComponent,
                                       java.lang.String message,
                                       java.lang.String title,
                                       int oldValue)
        Utility function to prompt for new integer value.
        Parameters:
        parentComponent - the parent component
        message - the prompt message
        title - the dialog title
        oldValue - the original integer value
        Returns:
        the new integer value
      • promptForInteger

        public static java.lang.Integer promptForInteger​(java.awt.Component parentComponent,
                                                         @Nonnull
                                                         java.lang.String message,
                                                         @Nonnull
                                                         java.lang.String title,
                                                         java.lang.Integer oldValue,
                                                         @CheckForNull
                                                         java.util.function.Predicate<java.lang.Integer> validator)
        Utility function to prompt for new integer value. Allows to constrain values using a Predicate (validator).

        The validator may throw an IllegalArgumentException whose Throwable.getLocalizedMessage() will be displayed. The Predicate may also simply return false, which causes just general message (the value is invalid) to be printed. If the Predicate rejects the input, the OK button is disabled and the user is unable to confirm the dialog.

        The function returns the original value if the dialog was cancelled or the entered value was empty or invalid. Otherwise, it returns the new value entered by the user.

        Parameters:
        parentComponent - the parent component
        message - the prompt message.
        title - title for the dialog
        oldValue - the original value
        validator - the validator instance. May be null
        Returns:
        the updated value, or the original one.
      • promptForFloat

        public static float promptForFloat​(java.awt.Component parentComponent,
                                           java.lang.String message,
                                           java.lang.String title,
                                           float oldValue)
        Utility function to prompt for new float value.
        Parameters:
        parentComponent - the parent component.
        message - the prompt message
        title - the dialog title
        oldValue - the original float value
        Returns:
        the new float value
      • promptForDouble

        public static double promptForDouble​(java.awt.Component parentComponent,
                                             java.lang.String message,
                                             java.lang.String title,
                                             double oldValue)
        Utility function to prompt for new double value.
        Parameters:
        parentComponent - the parent component
        message - the prompt message
        title - the dialog title
        oldValue - the original double value
        Returns:
        the new double value