From 889fac2bdf993dc86f64a8893c0260fdcf848acb Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Mon, 10 Apr 2017 16:40:33 -0400 Subject: Cleanup --- .../bjc/utils/gui/awt/ExtensionFileFilter.java | 16 +++---- .../java/bjc/utils/gui/awt/SimpleFileDialog.java | 50 +++++++++++----------- 2 files changed, 33 insertions(+), 33 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/gui/awt') 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 68978e7..eb60ae2 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,12 +1,12 @@ 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. * @@ -19,7 +19,7 @@ public class ExtensionFileFilter implements FilenameFilter { /** * The list of extensions to filter */ - private IList extensions; + private final IList extensions; /** * Create a new filter only showing files with the specified extensions. @@ -27,8 +27,8 @@ public class ExtensionFileFilter implements FilenameFilter { * @param exts * The extensions to show in this filter. */ - public ExtensionFileFilter(List exts) { - if(exts == null) throw new NullPointerException("Extensions must not be null"); + public ExtensionFileFilter(final List exts) { + if (exts == null) throw new NullPointerException("Extensions must not be null"); extensions = new FunctionalList<>(exts); } @@ -39,12 +39,12 @@ public class ExtensionFileFilter implements FilenameFilter { * @param exts * The extensions to show in this filter. */ - public ExtensionFileFilter(String... exts) { + public ExtensionFileFilter(final String... exts) { extensions = new FunctionalList<>(exts); } @Override - public boolean accept(File directory, String name) { + 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 index 47f76b8..77a4a59 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,12 +1,12 @@ 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 * @@ -25,7 +25,7 @@ public class SimpleFileDialog { * The title of the file picker * @return The file the user picked */ - public static File getOpenFile(Frame parent, String title) { + public static File getOpenFile(final Frame parent, final String title) { return getOpenFile(parent, title, (String[]) null); } @@ -40,21 +40,21 @@ public class SimpleFileDialog { * The extensions to accept as valid * @return The file the user picked */ - public static File getOpenFile(Frame parent, String title, String... extensions) { - if(parent == null) + 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"); + else if (title == null) throw new NullPointerException("Title must not be null"); - FileDialog chooser = new FileDialog(parent, title, FileDialog.LOAD); + final FileDialog chooser = new FileDialog(parent, title, FileDialog.LOAD); - if(extensions != null) { - FilenameFilter filter = new ExtensionFileFilter(extensions); + if (extensions != null) { + final 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); } @@ -73,22 +73,22 @@ public class SimpleFileDialog { * The extensions to accept as valid * @return The file the user picked */ - public static File[] getOpenFiles(Frame parent, String title, String... extensions) { - if(parent == null) + 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"); + else if (title == null) throw new NullPointerException("Title must not be null"); - FileDialog chooser = new FileDialog(parent, title, FileDialog.LOAD); + final FileDialog chooser = new FileDialog(parent, title, FileDialog.LOAD); - if(extensions != null) { - FilenameFilter filter = new ExtensionFileFilter(extensions); + if (extensions != null) { + final FilenameFilter filter = new ExtensionFileFilter(extensions); chooser.setFilenameFilter(filter); } 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); } @@ -105,7 +105,7 @@ public class SimpleFileDialog { * The title of the file picker * @return The file the user picked */ - public static File getSaveFile(Frame parent, String title) { + public static File getSaveFile(final Frame parent, final String title) { return getSaveFile(parent, title, (String[]) null); } @@ -120,21 +120,21 @@ public class SimpleFileDialog { * The extensions to accept as valid * @return The file the user picked */ - public static File getSaveFile(Frame parent, String title, String... extensions) { - if(parent == null) + 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"); + else if (title == null) throw new NullPointerException("Title must not be null"); - FileDialog chooser = new FileDialog(parent, title, FileDialog.SAVE); + final FileDialog chooser = new FileDialog(parent, title, FileDialog.SAVE); - if(extensions != null) { - FilenameFilter filter = new ExtensionFileFilter(extensions); + if (extensions != null) { + final 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); } -- cgit v1.2.3