diff options
Diffstat (limited to 'base/src/main/java/bjc/utils/gui/awt/SimpleFileDialog.java')
| -rw-r--r-- | base/src/main/java/bjc/utils/gui/awt/SimpleFileDialog.java | 70 |
1 files changed, 39 insertions, 31 deletions
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); } |
