summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleFileChooser.java
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2016-02-21 15:42:14 -0500
committerbculkin2442 <bjculkin@mix.wvu.edu>2016-02-21 15:42:14 -0500
commitc2089e5a3e604424c7cd00bbddcb03731ff5a0ea (patch)
tree31854f794e47b8dc67ea10d6699368810ca78f55 /BJC-Utils2/src/main/java/bjc/utils/gui/SimpleFileChooser.java
parenteb30c23bb03579bf839189ab0d2ad172d5b07766 (diff)
Added new control and some commenting
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.java159
1 files changed, 90 insertions, 69 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 fd5492b..efbe74e 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleFileChooser.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleFileChooser.java
@@ -7,6 +7,9 @@ import javax.swing.JFileChooser;
/**
* Utility class for easily prompting user for files.
+ *
+ * Built for Swing.
+ *
* @author ben
*
*/
@@ -20,7 +23,7 @@ public class SimpleFileChooser {
while (!success) {
try {
maybeDoOpenFile(par, files);
-
+
success = true;
} catch (FileNotChosenException e) {
SimpleDialogs.showError(par, "I/O Error",
@@ -40,7 +43,7 @@ public class SimpleFileChooser {
while (!success) {
try {
maybeDoSaveFile(par, files);
-
+
return files.getSelectedFile();
} catch (FileNotChosenException e) {
SimpleDialogs.showError(par, "I/O Error",
@@ -51,31 +54,14 @@ public class SimpleFileChooser {
return files.getSelectedFile();
}
- private static void maybeDoSaveFile(Component par, JFileChooser files)
- throws FileNotChosenException {
- int res = files.showSaveDialog(par);
-
- System.out.println("Result: " + res);
-
- if (res != JFileChooser.APPROVE_OPTION) {
- throw new FileNotChosenException();
- }
- }
-
- private static void maybeDoOpenFile(Component par, JFileChooser files)
- throws FileNotChosenException {
- int res = files.showSaveDialog(par);
-
- if (res != JFileChooser.APPROVE_OPTION) {
- throw new FileNotChosenException();
- }
- }
-
/**
- * Prompt the user with a "Open File..." dialog.
- * Keeps prompting them until they pick a file.
- * @param par The component to use as the parent for the dialog.
- * @param title The title of the dialog to prompt with.
+ * Prompt the user with a "Open File..." dialog. Keeps prompting them
+ * until they pick a file.
+ *
+ * @param par
+ * The component to use as the parent for the dialog.
+ * @param title
+ * The title of the dialog to prompt with.
* @return The file the user has chosen.
*/
public static File getOpenFile(Component par, String title) {
@@ -85,11 +71,15 @@ public class SimpleFileChooser {
}
/**
- * Prompt the user with a "Open File..." dialog.
- * Keeps prompting them until they pick a file.
- * @param par The component to use as the parent for the dialog.
- * @param title The title of the dialog to prompt with.
- * @param extensions The list of file extensions the file should have.
+ * Prompt the user with a "Open File..." dialog. Keeps prompting them
+ * until they pick a file.
+ *
+ * @param par
+ * The component to use as the parent for the dialog.
+ * @param title
+ * The title of the dialog to prompt with.
+ * @param extensions
+ * The list of file extensions the file should have.
* @return The file the user has chosen.
*/
public static File getOpenFile(Component par, String title,
@@ -101,67 +91,98 @@ public class SimpleFileChooser {
}
/**
+ * Prompt the user with a "Save File..." dialog.
+ *
+ * @param par
+ * The component to use as the parent for the dialog.
+ * @param title
+ * The title of the dialog to prompt with.
+ * @return The file the user chose.
+ */
+ public static File getSaveFile(Component par, String title) {
+ JFileChooser files = new JFileChooser();
+
+ return doSaveFile(par, title, files);
+ }
+
+ /**
+ * Prompt the user with a "Save File..." dialog.
+ *
+ * @param par
+ * The component to use as the parent for the dialog.
+ * @param title
+ * The title of the dialog to prompt with.
+ * @param extensions
+ * The extensions of the files the user can choose.
+ * @return The file the user chose.
+ */
+ public static File getSaveFile(Component par, String title,
+ String... extensions) {
+ JFileChooser files = new JFileChooser();
+ files.addChoosableFileFilter(new ExtensionFileFilter(extensions));
+
+ return doSaveFile(par, title, files);
+ }
+
+ private static void maybeDoOpenFile(Component par, JFileChooser files)
+ throws FileNotChosenException {
+ int res = files.showSaveDialog(par);
+
+ if (res != JFileChooser.APPROVE_OPTION) {
+ throw new FileNotChosenException();
+ }
+ }
+
+ private static void maybeDoSaveFile(Component par, JFileChooser files)
+ throws FileNotChosenException {
+ int res = files.showSaveDialog(par);
+
+ System.out.println("Result: " + res);
+
+ if (res != JFileChooser.APPROVE_OPTION) {
+ throw new FileNotChosenException();
+ }
+ }
+
+ /**
* Prompt the user with a "Open File..." dialog.
- * @param par The component to use as the parent for the dialog.
- * @param title The title of the dialog to prompt with.
+ *
+ * @param par
+ * The component to use as the parent for the dialog.
+ * @param title
+ * The title of the dialog to prompt with.
* @return The file if the user chose one or null if they didn't.
*/
public static File maybeOpenFile(Component par, String title) {
JFileChooser files = new JFileChooser();
files.setDialogTitle(title);
-
+
try {
maybeDoOpenFile(par, files);
} catch (FileNotChosenException e) {
}
-
+
return files.getSelectedFile();
}
-
+
/**
* Prompt the user with a "Save File..." dialog.
- * @param par The component to use as the parent for the dialog.
- * @param title The title of the dialog to prompt with.
+ *
+ * @param par
+ * The component to use as the parent for the dialog.
+ * @param title
+ * The title of the dialog to prompt with.
* @return The file if the user chose one or null if they didn't.
*/
public static File maybeSaveFile(Component par, String title) {
JFileChooser files = new JFileChooser();
files.setDialogTitle(title);
-
+
try {
maybeDoSaveFile(par, files);
} catch (FileNotChosenException e) {
}
-
- return files.getSelectedFile();
- }
-
- /**
- * Prompt the user with a "Save File..." dialog.
- *
- * @param par The component to use as the parent for the dialog.
- * @param title The title of the dialog to prompt with.
- * @return The file the user chose.
- */
- public static File getSaveFile(Component par, String title) {
- JFileChooser files = new JFileChooser();
-
- return doSaveFile(par, title, files);
- }
-
- /**
- * Prompt the user with a "Save File..." dialog.
- *
- * @param par The component to use as the parent for the dialog.
- * @param title The title of the dialog to prompt with.
- * @param extensions The extensions of the files the user can choose.
- * @return The file the user chose.
- */
- public static File getSaveFile(Component par, String title,
- String... extensions) {
- JFileChooser files = new JFileChooser();
- files.addChoosableFileFilter(new ExtensionFileFilter(extensions));
- return doSaveFile(par, title, files);
+ return files.getSelectedFile();
}
}