summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleFileChooser.java
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2016-04-03 19:22:48 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2016-04-03 19:22:48 -0400
commit1c8bc7132d980c1ff2dbd6b9af579c3b2fd8c63e (patch)
treea29777f07ebd81fbef61b5ae02f13f1a9d8f65a2 /BJC-Utils2/src/main/java/bjc/utils/gui/SimpleFileChooser.java
parenta023de85aa08c8f2b8b2441c6b14064eabee2775 (diff)
General code refactoring and maintenance
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/gui/SimpleFileChooser.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/SimpleFileChooser.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleFileChooser.java b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleFileChooser.java
index 9648762..f39ff7c 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleFileChooser.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleFileChooser.java
@@ -18,6 +18,10 @@ import bjc.utils.exceptions.FileNotChosenException;
public class SimpleFileChooser {
private static File doOpenFile(Component parent, String title,
JFileChooser files) {
+ if (title == null) {
+ throw new NullPointerException("Title must not be null");
+ }
+
files.setDialogTitle(title);
boolean success = false;
@@ -38,6 +42,10 @@ public class SimpleFileChooser {
private static File doSaveFile(Component parent, String title,
JFileChooser files) {
+ if (title == null) {
+ throw new NullPointerException("Title must not be null");
+ }
+
files.setDialogTitle(title);
boolean success = false;
@@ -87,6 +95,7 @@ public class SimpleFileChooser {
public static File getOpenFile(Component parent, String title,
String... extensions) {
JFileChooser files = new JFileChooser();
+
files.addChoosableFileFilter(new ExtensionFileFilter(extensions));
return doOpenFile(parent, title, files);
@@ -121,6 +130,7 @@ public class SimpleFileChooser {
public static File getSaveFile(Component parent, String title,
String... extensions) {
JFileChooser files = new JFileChooser();
+
files.addChoosableFileFilter(new ExtensionFileFilter(extensions));
return doSaveFile(parent, title, files);
@@ -128,6 +138,13 @@ public class SimpleFileChooser {
private static void maybeDoOpenFile(Component parent,
JFileChooser files) throws FileNotChosenException {
+ if (parent == null) {
+ throw new NullPointerException("Parent must not be null");
+ } else if (files == null) {
+ throw new NullPointerException(
+ "File chooser must not be null");
+ }
+
int dialogResult = files.showSaveDialog(parent);
if (dialogResult != JFileChooser.APPROVE_OPTION) {
@@ -137,6 +154,13 @@ public class SimpleFileChooser {
private static void maybeDoSaveFile(Component parent,
JFileChooser files) throws FileNotChosenException {
+ if (parent == null) {
+ throw new NullPointerException("Parent must not be null");
+ } else if (files == null) {
+ throw new NullPointerException(
+ "File chooser must not be null");
+ }
+
int dialogResult = files.showSaveDialog(parent);
if (dialogResult != JFileChooser.APPROVE_OPTION) {
@@ -154,6 +178,10 @@ public class SimpleFileChooser {
* @return The file if the user chose one or null if they didn't.
*/
public static File maybeOpenFile(Component parent, String title) {
+ if (title == null) {
+ throw new NullPointerException("Title must not be null");
+ }
+
JFileChooser files = new JFileChooser();
files.setDialogTitle(title);
@@ -175,6 +203,10 @@ public class SimpleFileChooser {
* @return The file if the user chose one or null if they didn't.
*/
public static File maybeSaveFile(Component parent, String title) {
+ if (title == null) {
+ throw new NullPointerException("Title must not be null");
+ }
+
JFileChooser files = new JFileChooser();
files.setDialogTitle(title);