Package jmri.util
Class QuickPromptUtil
java.lang.Object
jmri.util.QuickPromptUtil
A collection of utilities related to prompting for values
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class(package private) static final class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncheckIntRange(Integer min, Integer max, String valueLabel) Creates a min/max predicate which will check the bounds.static doublepromptForDouble(Component parentComponent, String message, String title, double oldValue) Utility function to prompt for new double value.static floatpromptForFloat(Component parentComponent, String message, String title, float oldValue) Utility function to prompt for new float value.static intpromptForInt(Component parentComponent, String message, String title, int oldValue) Utility function to prompt for new integer value.static IntegerpromptForInteger(Component parentComponent, String message, String title, Integer oldValue, Predicate<Integer> validator) Utility function to prompt for new integer value.static StringpromptForString(Component parentComponent, String message, String title, String oldValue) Utility function to prompt for new string value.
-
Constructor Details
-
QuickPromptUtil
public QuickPromptUtil()
-
-
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 componentmessage- the prompt messagetitle- the dialog titleoldValue- 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 componentmessage- the prompt messagetitle- the dialog titleoldValue- 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
IllegalArgumentExceptionwhoseThrowable.getLocalizedMessage()will be displayed. The Predicate may also simply returnfalse, 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 componentmessage- the prompt message.title- title for the dialogoldValue- the original valuevalidator- the validator instance. May benull- 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 messagetitle- the dialog titleoldValue- 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 componentmessage- the prompt messagetitle- the dialog titleoldValue- the original double value- Returns:
- the new double value
-
checkIntRange
Creates a min/max predicate which will check the bounds. Suitable forpromptForInteger(java.awt.Component, java.lang.String, java.lang.String, Integer, java.util.function.Predicate).- Parameters:
min- minimum value. UseInteger.MIN_VALUEto disable check.max- maximum value, inclusive. UseInteger.MAX_VALUEto disable check.valueLabel- label to be included in the message. Must be already I18Ned.- Returns:
- predicate instance
-