summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/gui/awt
diff options
context:
space:
mode:
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/gui/awt')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/awt/ExtensionFileFilter.java18
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/awt/SimpleFileDialog.java48
2 files changed, 29 insertions, 37 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/awt/ExtensionFileFilter.java b/BJC-Utils2/src/main/java/bjc/utils/gui/awt/ExtensionFileFilter.java
index 0990f4f..68978e7 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/awt/ExtensionFileFilter.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/awt/ExtensionFileFilter.java
@@ -1,17 +1,17 @@
package bjc.utils.gui.awt;
+import bjc.utils.funcdata.FunctionalList;
+import bjc.utils.funcdata.IList;
+
import java.io.File;
import java.io.FilenameFilter;
import java.util.List;
-import bjc.utils.funcdata.FunctionalList;
-import bjc.utils.funcdata.IList;
-
/**
* Filter a set of filenames by extension.
- *
+ *
* Built for AWT
- *
+ *
* @author ben
*
*/
@@ -23,21 +23,19 @@ public class ExtensionFileFilter implements FilenameFilter {
/**
* Create a new filter only showing files with the specified extensions.
- *
+ *
* @param exts
* The extensions to show in this filter.
*/
public ExtensionFileFilter(List<String> exts) {
- if (exts == null) {
- throw new NullPointerException("Extensions must not be null");
- }
+ if(exts == null) throw new NullPointerException("Extensions must not be null");
extensions = new FunctionalList<>(exts);
}
/**
* Create a new filter only showing files with the specified extensions.
- *
+ *
* @param exts
* The extensions to show in this filter.
*/
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/awt/SimpleFileDialog.java b/BJC-Utils2/src/main/java/bjc/utils/gui/awt/SimpleFileDialog.java
index 041a9a2..47f76b8 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/awt/SimpleFileDialog.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/awt/SimpleFileDialog.java
@@ -1,24 +1,24 @@
package bjc.utils.gui.awt;
+import bjc.utils.gui.SimpleDialogs;
+
import java.awt.FileDialog;
import java.awt.Frame;
import java.io.File;
import java.io.FilenameFilter;
-import bjc.utils.gui.SimpleDialogs;
-
/**
* A simple way to get the user to pick a file
- *
+ *
* Built for AWT.
- *
+ *
* @author ben
*
*/
public class SimpleFileDialog {
/**
* Prompt the user to pick a file to open
- *
+ *
* @param parent
* The parent of the file picker
* @param title
@@ -31,7 +31,7 @@ public class SimpleFileDialog {
/**
* Prompt the user to pick a file to open
- *
+ *
* @param parent
* The parent of the file picker
* @param title
@@ -41,22 +41,20 @@ public class SimpleFileDialog {
* @return The file the user picked
*/
public static File getOpenFile(Frame parent, String title, String... extensions) {
- if (parent == null) {
+ 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(title == null) throw new NullPointerException("Title must not be null");
FileDialog chooser = new FileDialog(parent, title, FileDialog.LOAD);
- if (extensions != null) {
+ if(extensions != null) {
FilenameFilter filter = new ExtensionFileFilter(extensions);
chooser.setFilenameFilter(filter);
}
chooser.setVisible(true);
- while (chooser.getFile() == null) {
+ while(chooser.getFile() == null) {
SimpleDialogs.showError(parent, "File I/O Error", "Please choose a file to open.");
chooser.setVisible(true);
}
@@ -66,7 +64,7 @@ public class SimpleFileDialog {
/**
* Prompt the user to pick a file to open
- *
+ *
* @param parent
* The parent of the file picker
* @param title
@@ -76,15 +74,13 @@ public class SimpleFileDialog {
* @return The file the user picked
*/
public static File[] getOpenFiles(Frame parent, String title, String... extensions) {
- if (parent == null) {
+ 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(title == null) throw new NullPointerException("Title must not be null");
FileDialog chooser = new FileDialog(parent, title, FileDialog.LOAD);
- if (extensions != null) {
+ if(extensions != null) {
FilenameFilter filter = new ExtensionFileFilter(extensions);
chooser.setFilenameFilter(filter);
}
@@ -92,7 +88,7 @@ public class SimpleFileDialog {
chooser.setMultipleMode(true);
chooser.setVisible(true);
- while (chooser.getFile() == null) {
+ while(chooser.getFile() == null) {
SimpleDialogs.showError(parent, "File I/O Error", "Please choose a file to open.");
chooser.setVisible(true);
}
@@ -102,7 +98,7 @@ public class SimpleFileDialog {
/**
* Prompt the user to pick a file to save
- *
+ *
* @param parent
* The parent of the file picker
* @param title
@@ -115,7 +111,7 @@ public class SimpleFileDialog {
/**
* Prompt the user to pick a file to save
- *
+ *
* @param parent
* The parent of the file picker
* @param title
@@ -125,22 +121,20 @@ public class SimpleFileDialog {
* @return The file the user picked
*/
public static File getSaveFile(Frame parent, String title, String... extensions) {
- if (parent == null) {
+ 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(title == null) throw new NullPointerException("Title must not be null");
FileDialog chooser = new FileDialog(parent, title, FileDialog.SAVE);
- if (extensions != null) {
+ if(extensions != null) {
FilenameFilter filter = new ExtensionFileFilter(extensions);
chooser.setFilenameFilter(filter);
}
chooser.setVisible(true);
- while (chooser.getFile() == null) {
+ while(chooser.getFile() == null) {
SimpleDialogs.showError(parent, "File I/O Error", "Please choose a file to save to.");
chooser.setVisible(true);
}