Package jmri.util

Class QuickPromptUtil

java.lang.Object
jmri.util.QuickPromptUtil

public class QuickPromptUtil extends Object
A collection of utilities related to prompting for values
  • Constructor Details

  • Method Details

    • promptForString

      public static String promptForString(Component parentComponent, String message, String title, 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(Component parentComponent, String message, 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 Integer promptForInteger(Component parentComponent, @Nonnull String message, @Nonnull String title, Integer oldValue, @CheckForNull Predicate<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(Component parentComponent, String message, 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(Component parentComponent, String message, 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
    • checkIntRange

      public static Predicate<Integer> checkIntRange(Integer min, Integer max, String valueLabel)
      Parameters:
      min - minimum value. Use Integer.MIN_VALUE to disable check.
      max - maximum value, inclusive. Use Integer.MAX_VALUE to disable check.
      valueLabel - label to be included in the message. Must be already I18Ned.
      Returns:
      predicate instance