summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java
diff options
context:
space:
mode:
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java116
1 files changed, 52 insertions, 64 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java
index 68c4962..7e3cdfd 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java
@@ -25,26 +25,26 @@ public class SimpleDialogs {
* Get a bounded integer from the user.
*
* @param parent
- * The parent component for the dialogs.
+ * The parent component for the dialogs.
* @param title
- * The title for the dialogs.
+ * The title for the dialogs.
* @param prompt
- * The prompt to tell the user what to enter.
+ * The prompt to tell the user what to enter.
* @param lowerBound
- * The lower integer bound to accept.
+ * The lower integer bound to accept.
* @param upperBound
- * The upper integer bound to accept.
+ * 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(Component parent, String title, String prompt, int lowerBound, int upperBound) {
return getValue(parent, title, prompt, (strang) -> {
try {
int value = Integer.parseInt(strang);
return (value < upperBound) && (value > lowerBound);
} catch (NumberFormatException nfex) {
- // We don't care about the specifics of the exception, just
+ // We don't care about the specifics of the
+ // exception, just
// that this value isn't good
return false;
}
@@ -55,21 +55,20 @@ public class SimpleDialogs {
* Asks the user to pick an option from a series of choices.
*
* @param <E>
- * The type of choices for the user to pick
+ * The type of choices for the user to pick
*
* @param parent
- * The parent frame for this dialog
+ * The parent frame for this dialog
* @param title
- * The title of this dialog
+ * The title of this dialog
* @param question
- * The question being asked
+ * The question being asked
* @param choices
- * The available choices for the question
+ * The available choices for the question
* @return The choice the user picked, or null if they didn't pick one
*/
@SuppressWarnings("unchecked")
- public static <E> E getChoice(Frame parent, String title,
- String question, E... choices) {
+ public static <E> E getChoice(Frame parent, String title, String question, E... choices) {
if (parent == null) {
throw new NullPointerException("Parent must not be null");
} else if (title == null) {
@@ -113,21 +112,21 @@ public class SimpleDialogs {
* Get a integer from the user
*
* @param parent
- * The parent component for dialogs.
+ * The parent component for dialogs.
* @param title
- * The title for dialogs.
+ * The title for dialogs.
* @param prompt
- * The prompt to tell the user what to enter.
+ * 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(Component parent, String title, String prompt) {
return getValue(parent, title, prompt, strang -> {
try {
Integer.parseInt(strang);
return true;
} catch (NumberFormatException nfex) {
- // We don't care about this exception, just mark the value
+ // We don't care about this exception, just mark
+ // the value
// as not good
return false;
}
@@ -138,15 +137,14 @@ public class SimpleDialogs {
* Get a string from the user
*
* @param parent
- * The parent component for dialogs.
+ * The parent component for dialogs.
* @param title
- * The title for the dialogs.
+ * The title for the dialogs.
* @param prompt
- * The prompt to tell the user what to enter.
+ * The prompt to tell the user what to enter.
* @return A string.
*/
- public static String getString(Component parent, String title,
- String prompt) {
+ public static String getString(Component parent, String title, String prompt) {
if (parent == null) {
throw new NullPointerException("Parent must not be null");
} else if (title == null) {
@@ -155,30 +153,28 @@ public class SimpleDialogs {
throw new NullPointerException("Prompt must not be null");
}
- return JOptionPane.showInputDialog(parent, prompt, title,
- JOptionPane.QUESTION_MESSAGE);
+ return JOptionPane.showInputDialog(parent, prompt, title, JOptionPane.QUESTION_MESSAGE);
}
/**
* Get a value parsable from a string from the user.
*
* @param <E>
- * The type of the value parsed from the string
+ * The type of the value parsed from the string
*
* @param parent
- * The parent component for dialogs.
+ * The parent component for dialogs.
* @param title
- * The title for dialogs.
+ * The title for dialogs.
* @param prompt
- * The prompt to tell the user what to enter.
+ * The prompt to tell the user what to enter.
* @param validator
- * A predicate to determine if a input is valid.
+ * A predicate to determine if a input is valid.
* @param transformer
- * The function to transform the string into a value.
+ * 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,
+ public static <E> E getValue(Component parent, String title, String prompt, Predicate<String> validator,
Function<String, E> transformer) {
if (validator == null) {
throw new NullPointerException("Validator must not be null");
@@ -201,15 +197,14 @@ public class SimpleDialogs {
* Get a whole number from the user.
*
* @param parent
- * The parent component for dialogs.
+ * The parent component for dialogs.
* @param title
- * The title for dialogs.
+ * The title for dialogs.
* @param prompt
- * The prompt to tell the user what to enter.
+ * 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(Component parent, String title, String prompt) {
return getBoundedInt(parent, title, prompt, 0, Integer.MAX_VALUE);
}
@@ -217,15 +212,14 @@ public class SimpleDialogs {
* Ask the user a Yes/No question.
*
* @param parent
- * The parent component for dialogs.
+ * The parent component for dialogs.
* @param title
- * The title for dialogs.
+ * The title for dialogs.
* @param question
- * The question to ask the user.
+ * 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) {
+ public static boolean getYesNo(Component parent, String title, String question) {
if (parent == null) {
throw new NullPointerException("Parent must not be null");
} else if (title == null) {
@@ -234,8 +228,7 @@ public class SimpleDialogs {
throw new NullPointerException("Question must not be null");
}
- int result = JOptionPane.showConfirmDialog(parent, question,
- title, JOptionPane.YES_NO_OPTION);
+ int result = JOptionPane.showConfirmDialog(parent, question, title, JOptionPane.YES_NO_OPTION);
return (result == JOptionPane.YES_OPTION ? true : false);
}
@@ -244,39 +237,35 @@ public class SimpleDialogs {
* Show a error message to the user
*
* @param parent
- * The parent component for dialogs.
+ * The parent component for dialogs.
* @param title
- * The title for dialogs.
+ * The title for dialogs.
* @param message
- * The error to show the user.
+ * The error to show the user.
*/
- public static void showError(Component parent, String title,
- String message) {
+ public static void showError(Component parent, String title, String message) {
if (parent == null) {
throw new NullPointerException("Parent must not be 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");
+ throw new NullPointerException("Error message must not be null");
}
- JOptionPane.showMessageDialog(parent, message, title,
- JOptionPane.ERROR_MESSAGE);
+ JOptionPane.showMessageDialog(parent, message, title, JOptionPane.ERROR_MESSAGE);
}
/**
* Show an informative message to the user
*
* @param parent
- * The parent for this dialog
+ * The parent for this dialog
* @param title
- * Show the title for this dialog
+ * Show the title for this dialog
* @param message
- * Show the message for this dialog
+ * Show the message for this dialog
*/
- public static void showMessage(Component parent, String title,
- String message) {
+ public static void showMessage(Component parent, String title, String message) {
if (parent == null) {
throw new NullPointerException("Parent must not be null");
} else if (title == null) {
@@ -285,7 +274,6 @@ public class SimpleDialogs {
throw new NullPointerException("Message must not be null");
}
- JOptionPane.showMessageDialog(parent, title, message,
- JOptionPane.INFORMATION_MESSAGE);
+ JOptionPane.showMessageDialog(parent, title, message, JOptionPane.INFORMATION_MESSAGE);
}
}