summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleFileChooser.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/SimpleFileChooser.java
parent5c1163df17c46f7d3e15b6c7949c38843ec56146 (diff)
Cleanup
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.java68
1 files changed, 26 insertions, 42 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 ec4b784..cd7c180 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleFileChooser.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleFileChooser.java
@@ -1,36 +1,34 @@
package bjc.utils.gui;
+import bjc.utils.exceptions.FileNotChosenException;
+
import java.awt.Component;
import java.io.File;
import javax.swing.JFileChooser;
-import bjc.utils.exceptions.FileNotChosenException;
-
/**
* Utility class for easily prompting user for files.
- *
+ *
* Built for Swing.
- *
+ *
* @author ben
*
*/
public class SimpleFileChooser {
private static File doOpenFile(Component parent, String title, JFileChooser files) {
- if (title == null) {
- throw new NullPointerException("Title must not be null");
- }
+ if(title == null) throw new NullPointerException("Title must not be null");
files.setDialogTitle(title);
boolean success = false;
- while (!success) {
+ while(!success) {
try {
maybeDoOpenFile(parent, files);
success = true;
- } catch (FileNotChosenException fncx) {
+ } catch(FileNotChosenException fncx) {
// We don't care about specifics
SimpleDialogs.showError(parent, "I/O Error", "Please pick a file to open");
}
@@ -40,20 +38,18 @@ public class SimpleFileChooser {
}
private static File doSaveFile(Component parent, String title, JFileChooser files) {
- if (title == null) {
- throw new NullPointerException("Title must not be null");
- }
+ if(title == null) throw new NullPointerException("Title must not be null");
files.setDialogTitle(title);
boolean success = false;
- while (!success) {
+ while(!success) {
try {
maybeDoSaveFile(parent, files);
return files.getSelectedFile();
- } catch (FileNotChosenException fncex) {
+ } catch(FileNotChosenException fncex) {
// We don't care about specifics
SimpleDialogs.showError(parent, "I/O Error", "Please pick a file to save to");
}
@@ -65,7 +61,7 @@ public class SimpleFileChooser {
/**
* Prompt the user with a "Open File..." dialog. Keeps prompting them
* until they pick a file.
- *
+ *
* @param parent
* The component to use as the parent for the dialog.
* @param title
@@ -81,7 +77,7 @@ public class SimpleFileChooser {
/**
* Prompt the user with a "Open File..." dialog. Keeps prompting them
* until they pick a file.
- *
+ *
* @param parent
* The component to use as the parent for the dialog.
* @param title
@@ -100,7 +96,7 @@ public class SimpleFileChooser {
/**
* Prompt the user with a "Save File..." dialog.
- *
+ *
* @param parent
* The component to use as the parent for the dialog.
* @param title
@@ -115,7 +111,7 @@ public class SimpleFileChooser {
/**
* Prompt the user with a "Save File..." dialog.
- *
+ *
* @param parent
* The component to use as the parent for the dialog.
* @param title
@@ -133,36 +129,28 @@ public class SimpleFileChooser {
}
private static void maybeDoOpenFile(Component parent, JFileChooser files) throws FileNotChosenException {
- if (parent == null) {
+ if(parent == null)
throw new NullPointerException("Parent must not be null");
- } else if (files == null) {
- throw new NullPointerException("File chooser must not be null");
- }
+ else if(files == null) throw new NullPointerException("File chooser must not be null");
int result = files.showSaveDialog(parent);
- if (result != JFileChooser.APPROVE_OPTION) {
- throw new FileNotChosenException();
- }
+ if(result != JFileChooser.APPROVE_OPTION) throw new FileNotChosenException();
}
private static void maybeDoSaveFile(Component parent, JFileChooser files) throws FileNotChosenException {
- if (parent == null) {
+ if(parent == null)
throw new NullPointerException("Parent must not be null");
- } else if (files == null) {
- throw new NullPointerException("File chooser must not be null");
- }
+ else if(files == null) throw new NullPointerException("File chooser must not be null");
int result = files.showSaveDialog(parent);
- if (result != JFileChooser.APPROVE_OPTION) {
- throw new FileNotChosenException();
- }
+ if(result != JFileChooser.APPROVE_OPTION) throw new FileNotChosenException();
}
/**
* Prompt the user with a "Open File..." dialog.
- *
+ *
* @param parent
* The component to use as the parent for the dialog.
* @param title
@@ -170,16 +158,14 @@ 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");
- }
+ if(title == null) throw new NullPointerException("Title must not be null");
JFileChooser files = new JFileChooser();
files.setDialogTitle(title);
try {
maybeDoOpenFile(parent, files);
- } catch (FileNotChosenException fncex) {
+ } catch(FileNotChosenException fncex) {
// We don't care about specifics
}
@@ -188,7 +174,7 @@ public class SimpleFileChooser {
/**
* Prompt the user with a "Save File..." dialog.
- *
+ *
* @param parent
* The component to use as the parent for the dialog.
* @param title
@@ -196,16 +182,14 @@ 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");
- }
+ if(title == null) throw new NullPointerException("Title must not be null");
JFileChooser files = new JFileChooser();
files.setDialogTitle(title);
try {
maybeDoSaveFile(parent, files);
- } catch (FileNotChosenException fncex) {
+ } catch(FileNotChosenException fncex) {
// We don't care about specifics
}