summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java
diff options
context:
space:
mode:
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java58
1 files changed, 30 insertions, 28 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java
index d7bb700..5237557 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java
@@ -30,13 +30,14 @@ public class SimpleInternalDialogs {
* The upper integer bound to accept.
* @return A int within the specified bounds.
*/
- public static int getBoundedInt(Component parent, String title, String prompt, int lowerBound, int upperBound) {
+ public static int getBoundedInt(final Component parent, final String title, final String prompt,
+ final int lowerBound, final int upperBound) {
return getValue(parent, title, prompt, (strang) -> {
try {
- int value = Integer.parseInt(strang);
+ final int value = Integer.parseInt(strang);
return value < upperBound && value > lowerBound;
- } catch(NumberFormatException nfex) {
+ } catch (final NumberFormatException nfex) {
// We don't care about the specifics of the
// exception, just
// that this value isn't good
@@ -56,12 +57,12 @@ public class SimpleInternalDialogs {
* The prompt to tell the user what to enter.
* @return A int.
*/
- public static int getInt(Component parent, String title, String prompt) {
+ public static int getInt(final Component parent, final String title, final String prompt) {
return getValue(parent, title, prompt, strang -> {
try {
Integer.parseInt(strang);
return true;
- } catch(NumberFormatException nfex) {
+ } catch (final NumberFormatException nfex) {
// We don't care about this exception, just mark
// the value
// as not good
@@ -81,12 +82,12 @@ public class SimpleInternalDialogs {
* The prompt to tell the user what to enter.
* @return A string.
*/
- public static String getString(Component parent, String title, String prompt) {
- if(parent == null)
+ public static String getString(final Component parent, final String title, final String prompt) {
+ if (parent == null)
throw new NullPointerException("Parent must not be null");
- else if(title == null)
+ else if (title == null)
throw new NullPointerException("Title must not be null");
- else if(prompt == null) throw new NullPointerException("Prompt must not be null");
+ else if (prompt == null) throw new NullPointerException("Prompt must not be null");
return JOptionPane.showInternalInputDialog(parent, prompt, title, JOptionPane.QUESTION_MESSAGE);
}
@@ -109,15 +110,15 @@ public class SimpleInternalDialogs {
* The function to transform the string into a value.
* @return The value parsed from a string.
*/
- public static <E> E getValue(Component parent, String title, String prompt, Predicate<String> validator,
- Function<String, E> transformer) {
- if(validator == null)
+ public static <E> E getValue(final Component parent, final String title, final String prompt,
+ final Predicate<String> validator, final Function<String, E> transformer) {
+ if (validator == null)
throw new NullPointerException("Validator must not be null");
- else if(transformer == null) throw new NullPointerException("Transformer must not be null");
+ else if (transformer == null) throw new NullPointerException("Transformer must not be null");
String strang = getString(parent, title, prompt);
- while(!validator.test(strang)) {
+ while (!validator.test(strang)) {
showError(parent, "I/O Error", "Please enter a valid value");
strang = getString(parent, title, prompt);
@@ -137,7 +138,7 @@ public class SimpleInternalDialogs {
* The prompt to tell the user what to enter.
* @return A whole number.
*/
- public static int getWhole(Component parent, String title, String prompt) {
+ public static int getWhole(final Component parent, final String title, final String prompt) {
return getBoundedInt(parent, title, prompt, 0, Integer.MAX_VALUE);
}
@@ -152,14 +153,15 @@ public class SimpleInternalDialogs {
* The question to ask the user.
* @return True if the user said yes, false otherwise.
*/
- public static boolean getYesNo(Component parent, String title, String question) {
- if(parent == null)
+ public static boolean getYesNo(final Component parent, final String title, final String question) {
+ if (parent == null)
throw new NullPointerException("Parent must not be null");
- else if(title == null)
+ else if (title == null)
throw new NullPointerException("Title must not be null");
- else if(question == null) throw new NullPointerException("Question must not be null");
+ else if (question == null) throw new NullPointerException("Question must not be null");
- int result = JOptionPane.showInternalConfirmDialog(parent, question, title, JOptionPane.YES_NO_OPTION);
+ final int result = JOptionPane.showInternalConfirmDialog(parent, question, title,
+ JOptionPane.YES_NO_OPTION);
return result == JOptionPane.YES_OPTION ? true : false;
}
@@ -174,12 +176,12 @@ public class SimpleInternalDialogs {
* @param message
* The error to show the user.
*/
- public static void showError(Component parent, String title, String message) {
- if(parent == null)
+ public static void showError(final Component parent, final String title, final String message) {
+ if (parent == null)
throw new NullPointerException("Parent must not be null");
- else if(title == null)
+ else if (title == null)
throw new NullPointerException("Title must not be null");
- else if(message == null) throw new NullPointerException("Error message must not be null");
+ else if (message == null) throw new NullPointerException("Error message must not be null");
JOptionPane.showInternalMessageDialog(parent, message, title, JOptionPane.ERROR_MESSAGE);
}
@@ -194,12 +196,12 @@ public class SimpleInternalDialogs {
* @param message
* Show the message for this dialog
*/
- public static void showMessage(Component parent, String title, String message) {
- if(parent == null)
+ public static void showMessage(final Component parent, final String title, final String message) {
+ if (parent == null)
throw new NullPointerException("Parent must not be null");
- else if(title == null)
+ else if (title == null)
throw new NullPointerException("Title must not be null");
- else if(message == null) throw new NullPointerException("Message must not be null");
+ else if (message == null) throw new NullPointerException("Message must not be null");
JOptionPane.showInternalMessageDialog(parent, title, message, JOptionPane.INFORMATION_MESSAGE);
}