summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java
diff options
context:
space:
mode:
authorEVE <EVE@EVE-PC>2017-03-14 12:07:14 -0400
committerEVE <EVE@EVE-PC>2017-03-14 12:07:14 -0400
commit504ca816530efdff06bc202e0432ebd354aec304 (patch)
tree4836932fb81d1d625470502c78c94d202c9a7420 /BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java
parent5c1163df17c46f7d3e15b6c7949c38843ec56146 (diff)
Cleanup
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.java68
1 files changed, 29 insertions, 39 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 b5f0d6c..d7bb700 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java
@@ -10,14 +10,14 @@ import javax.swing.JOptionPane;
* Utility class for getting simple input from the user.
*
* Modified to work with JDesktopPanes
- *
+ *
* @author ben
*
*/
public class SimpleInternalDialogs {
/**
* Get a bounded integer from the user.
- *
+ *
* @param parent
* The parent component for the dialogs.
* @param title
@@ -35,8 +35,8 @@ public class SimpleInternalDialogs {
try {
int value = Integer.parseInt(strang);
- return (value < upperBound) && (value > lowerBound);
- } catch (NumberFormatException nfex) {
+ return value < upperBound && value > lowerBound;
+ } catch(NumberFormatException nfex) {
// We don't care about the specifics of the
// exception, just
// that this value isn't good
@@ -47,7 +47,7 @@ public class SimpleInternalDialogs {
/**
* Get a integer from the user
- *
+ *
* @param parent
* The parent component for dialogs.
* @param title
@@ -61,7 +61,7 @@ public class SimpleInternalDialogs {
try {
Integer.parseInt(strang);
return true;
- } catch (NumberFormatException nfex) {
+ } catch(NumberFormatException nfex) {
// We don't care about this exception, just mark
// the value
// as not good
@@ -72,7 +72,7 @@ public class SimpleInternalDialogs {
/**
* Get a string from the user
- *
+ *
* @param parent
* The parent component for dialogs.
* @param title
@@ -82,23 +82,21 @@ public class SimpleInternalDialogs {
* @return A string.
*/
public static String getString(Component parent, String title, String prompt) {
- if (parent == null) {
+ 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);
}
/**
* Get a value parsable from a string from the user.
- *
+ *
* @param <E>
* The type of the value parsed from the string
- *
+ *
* @param parent
* The parent component for dialogs.
* @param title
@@ -113,15 +111,13 @@ public class SimpleInternalDialogs {
*/
public static <E> E getValue(Component parent, String title, String prompt, Predicate<String> validator,
Function<String, E> transformer) {
- if (validator == null) {
+ 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);
@@ -132,7 +128,7 @@ public class SimpleInternalDialogs {
/**
* Get a whole number from the user.
- *
+ *
* @param parent
* The parent component for dialogs.
* @param title
@@ -147,7 +143,7 @@ public class SimpleInternalDialogs {
/**
* Ask the user a Yes/No question.
- *
+ *
* @param parent
* The parent component for dialogs.
* @param title
@@ -157,22 +153,20 @@ public class SimpleInternalDialogs {
* @return True if the user said yes, false otherwise.
*/
public static boolean getYesNo(Component parent, String title, String question) {
- if (parent == null) {
+ 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);
- return (result == JOptionPane.YES_OPTION ? true : false);
+ return result == JOptionPane.YES_OPTION ? true : false;
}
/**
* Show a error message to the user
- *
+ *
* @param parent
* The parent component for dialogs.
* @param title
@@ -181,20 +175,18 @@ public class SimpleInternalDialogs {
* The error to show the user.
*/
public static void showError(Component parent, String title, String message) {
- if (parent == null) {
+ 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);
}
/**
* Show an informative message to the user
- *
+ *
* @param parent
* The parent for this dialog
* @param title
@@ -203,13 +195,11 @@ public class SimpleInternalDialogs {
* Show the message for this dialog
*/
public static void showMessage(Component parent, String title, String message) {
- if (parent == null) {
+ 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);
}