From d4ca769e542b2489b1e23cfcbdc3a0b7275b87cd Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Mon, 13 Apr 2020 18:40:41 -0400 Subject: Cleanup pass Cleanup pass to uniformize things --- .../bjc/utils/gui/awt/ExtensionFileFilter.java | 7 ++- .../java/bjc/utils/gui/awt/SimpleFileDialog.java | 70 ++++++++++++---------- 2 files changed, 43 insertions(+), 34 deletions(-) (limited to 'base/src/main/java/bjc/utils/gui/awt') diff --git a/base/src/main/java/bjc/utils/gui/awt/ExtensionFileFilter.java b/base/src/main/java/bjc/utils/gui/awt/ExtensionFileFilter.java index e207a35..04b0b68 100644 --- a/base/src/main/java/bjc/utils/gui/awt/ExtensionFileFilter.java +++ b/base/src/main/java/bjc/utils/gui/awt/ExtensionFileFilter.java @@ -22,10 +22,11 @@ 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. + * The extensions to show in this filter. */ public ExtensionFileFilter(final List 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); } @@ -34,7 +35,7 @@ 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. + * The extensions to show in this filter. */ public ExtensionFileFilter(final String... exts) { extensions = new FunctionalList<>(exts); diff --git a/base/src/main/java/bjc/utils/gui/awt/SimpleFileDialog.java b/base/src/main/java/bjc/utils/gui/awt/SimpleFileDialog.java index daea7cd..2cb3122 100644 --- a/base/src/main/java/bjc/utils/gui/awt/SimpleFileDialog.java +++ b/base/src/main/java/bjc/utils/gui/awt/SimpleFileDialog.java @@ -19,10 +19,10 @@ public class SimpleFileDialog { * Prompt the user to pick a file to open. * * @param parent - * The parent of the file picker. + * The parent of the file picker. * * @param title - * The title of the file picker. + * The title of the file picker. * * @return The file the user picked. */ @@ -34,34 +34,36 @@ public class SimpleFileDialog { * Prompt the user to pick a file to open. * * @param parent - * The parent of the file picker. + * The parent of the file picker. * * @param title - * The title of the file picker. + * The title of the file picker. * * @param extensions - * The extensions to accept as valid. + * 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) { + 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) { + } else if (title == null) { throw new NullPointerException("Title must not be null"); } final FileDialog chooser = new FileDialog(parent, title, FileDialog.LOAD); - if(extensions != null) { + 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."); + while (chooser.getFile() == null) { + SimpleDialogs.showError(parent, "File I/O Error", + "Please choose a file to open."); chooser.setVisible(true); } @@ -72,24 +74,26 @@ public class SimpleFileDialog { * Prompt the user to pick a file to open. * * @param parent - * The parent of the file picker. + * The parent of the file picker. * * @param title - * The title of the file picker. + * The title of the file picker. * * @param extensions - * The extensions to accept as valid. + * 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) + 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"); final FileDialog chooser = new FileDialog(parent, title, FileDialog.LOAD); - if(extensions != null) { + if (extensions != null) { final FilenameFilter filter = new ExtensionFileFilter(extensions); chooser.setFilenameFilter(filter); } @@ -97,8 +101,9 @@ public class SimpleFileDialog { chooser.setMultipleMode(true); chooser.setVisible(true); - while(chooser.getFile() == null) { - SimpleDialogs.showError(parent, "File I/O Error", "Please choose a file to open."); + while (chooser.getFile() == null) { + SimpleDialogs.showError(parent, "File I/O Error", + "Please choose a file to open."); chooser.setVisible(true); } @@ -109,10 +114,10 @@ public class SimpleFileDialog { * Prompt the user to pick a file to save * * @param parent - * The parent of the file picker + * The parent of the file picker * * @param title - * The title of the file picker + * The title of the file picker * * @return The file the user picked */ @@ -124,32 +129,35 @@ public class SimpleFileDialog { * Prompt the user to pick a file to save * * @param parent - * The parent of the file picker + * The parent of the file picker * * @param title - * The title of the file picker + * The title of the file picker * * @param extensions - * The extensions to accept as valid + * 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) + 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"); final FileDialog chooser = new FileDialog(parent, title, FileDialog.SAVE); - if(extensions != null) { + 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."); + 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