Package jmri.util
Class QuickPromptUtil
- java.lang.Object
-
- jmri.util.QuickPromptUtil
-
public class QuickPromptUtil extends java.lang.Object
A collection of utilities related to prompting for values
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
QuickPromptUtil.FloatRangePredicate
(package private) static class
QuickPromptUtil.IntRangePredicate
-
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.
-
-
-
Constructor Detail
-
QuickPromptUtil
public QuickPromptUtil()
-
-
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 componentmessage
- the prompt messagetitle
- the dialog titleoldValue
- 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 componentmessage
- the prompt messagetitle
- the dialog titleoldValue
- 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
whoseThrowable.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(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 messagetitle
- the dialog titleoldValue
- 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 componentmessage
- the prompt messagetitle
- the dialog titleoldValue
- the original double value- Returns:
- the new double value
-
checkIntRange
public 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. Suitable forpromptForInteger(java.awt.Component, java.lang.String, java.lang.String, Integer, java.util.function.Predicate)
.- Parameters:
min
- minimum value. UseInteger.MIN_VALUE
to disable check.max
- maximum value, inclusive. UseInteger.MAX_VALUE
to disable check.valueLabel
- label to be included in the message. Must be already I18Ned.- Returns:
- predicate instance
-
-