diff options
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.java | 50 | ||||
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/gui/awt/SimpleFileDialog.java | 144 |
2 files changed, 0 insertions, 194 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 deleted file mode 100644 index eb60ae2..0000000 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/awt/ExtensionFileFilter.java +++ /dev/null @@ -1,50 +0,0 @@ -package bjc.utils.gui.awt; - -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 - * - */ -public class ExtensionFileFilter implements FilenameFilter { - /** - * The list of extensions to filter - */ - private final IList<String> extensions; - - /** - * Create a new filter only showing files with the specified extensions. - * - * @param exts - * The extensions to show in this filter. - */ - public ExtensionFileFilter(final List<String> exts) { - 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. - */ - public ExtensionFileFilter(final String... exts) { - extensions = new FunctionalList<>(exts); - } - - @Override - public boolean accept(final File directory, final String name) { - return extensions.anyMatch(name::endsWith); - } -}
\ No newline at end of file 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 deleted file mode 100644 index 77a4a59..0000000 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/awt/SimpleFileDialog.java +++ /dev/null @@ -1,144 +0,0 @@ -package bjc.utils.gui.awt; - -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 - * The title of the file picker - * @return The file the user picked - */ - public static File getOpenFile(final Frame parent, final String title) { - return getOpenFile(parent, title, (String[]) null); - } - - /** - * Prompt the user to pick a file to open - * - * @param parent - * The parent of the file picker - * @param title - * The title of the file picker - * @param extensions - * The extensions to accept as valid - * @return The file the user picked - */ - public static File getOpenFile(final Frame parent, final String title, final String... extensions) { - if (parent == null) - throw new NullPointerException("Parent must not be null"); - else if (title == null) throw new NullPointerException("Title must not be null"); - - final FileDialog chooser = new FileDialog(parent, title, FileDialog.LOAD); - - if (extensions != null) { - final FilenameFilter filter = new ExtensionFileFilter(extensions); - chooser.setFilenameFilter(filter); - } - - chooser.setVisible(true); - - while (chooser.getFile() == null) { - SimpleDialogs.showError(parent, "File I/O Error", "Please choose a file to open."); - chooser.setVisible(true); - } - - return chooser.getFiles()[0]; - } - - /** - * Prompt the user to pick a file to open - * - * @param parent - * The parent of the file picker - * @param title - * The title of the file picker - * @param extensions - * The extensions to accept as valid - * @return The file the user picked - */ - public static File[] getOpenFiles(final Frame parent, final String title, final String... extensions) { - if (parent == null) - throw new NullPointerException("Parent must not be null"); - else if (title == null) throw new NullPointerException("Title must not be null"); - - final FileDialog chooser = new FileDialog(parent, title, FileDialog.LOAD); - - if (extensions != null) { - final FilenameFilter filter = new ExtensionFileFilter(extensions); - chooser.setFilenameFilter(filter); - } - - chooser.setMultipleMode(true); - chooser.setVisible(true); - - while (chooser.getFile() == null) { - SimpleDialogs.showError(parent, "File I/O Error", "Please choose a file to open."); - chooser.setVisible(true); - } - - return chooser.getFiles(); - } - - /** - * Prompt the user to pick a file to save - * - * @param parent - * The parent of the file picker - * @param title - * The title of the file picker - * @return The file the user picked - */ - public static File getSaveFile(final Frame parent, final String title) { - return getSaveFile(parent, title, (String[]) null); - } - - /** - * Prompt the user to pick a file to save - * - * @param parent - * The parent of the file picker - * @param title - * The title of the file picker - * @param extensions - * The extensions to accept as valid - * @return The file the user picked - */ - public static File getSaveFile(final Frame parent, final String title, final String... extensions) { - if (parent == null) - throw new NullPointerException("Parent must not be null"); - else if (title == null) throw new NullPointerException("Title must not be null"); - - final FileDialog chooser = new FileDialog(parent, title, FileDialog.SAVE); - - if (extensions != null) { - final FilenameFilter filter = new ExtensionFileFilter(extensions); - chooser.setFilenameFilter(filter); - } - - chooser.setVisible(true); - - while (chooser.getFile() == null) { - SimpleDialogs.showError(parent, "File I/O Error", "Please choose a file to save to."); - chooser.setVisible(true); - } - - return chooser.getFiles()[0]; - } -} |
