diff options
| author | Ben Culkin <scorpress@gmail.com> | 2020-04-13 18:40:41 -0400 |
|---|---|---|
| committer | Ben Culkin <scorpress@gmail.com> | 2020-04-13 18:40:41 -0400 |
| commit | d4ca769e542b2489b1e23cfcbdc3a0b7275b87cd (patch) | |
| tree | 1653a7399f97fb0c63ce62e3f60fd830d5c37f70 /base/src/main/java/bjc/utils/gui | |
| parent | 2ac2e31a56ae59ee582e43a90c3495f86dd9ee7a (diff) | |
Cleanup pass
Cleanup pass to uniformize things
Diffstat (limited to 'base/src/main/java/bjc/utils/gui')
21 files changed, 411 insertions, 334 deletions
diff --git a/base/src/main/java/bjc/utils/gui/ExtensionFileFilter.java b/base/src/main/java/bjc/utils/gui/ExtensionFileFilter.java index d2129b0..d9ebda5 100644 --- a/base/src/main/java/bjc/utils/gui/ExtensionFileFilter.java +++ b/base/src/main/java/bjc/utils/gui/ExtensionFileFilter.java @@ -26,7 +26,7 @@ public class ExtensionFileFilter extends FileFilter { * 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<String> exts) { extensions = new FunctionalList<>(exts); @@ -36,7 +36,7 @@ public class ExtensionFileFilter extends FileFilter { * 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); @@ -44,7 +44,8 @@ public class ExtensionFileFilter extends FileFilter { @Override public boolean accept(final File pathname) { - if(pathname == null) throw new NullPointerException("Pathname must not be null"); + if (pathname == null) + throw new NullPointerException("Pathname must not be null"); return extensions.anyMatch(pathname.getName()::endsWith); } diff --git a/base/src/main/java/bjc/utils/gui/SimpleDialogs.java b/base/src/main/java/bjc/utils/gui/SimpleDialogs.java index b7763a2..a0df64d 100644 --- a/base/src/main/java/bjc/utils/gui/SimpleDialogs.java +++ b/base/src/main/java/bjc/utils/gui/SimpleDialogs.java @@ -25,25 +25,25 @@ public class SimpleDialogs { * Get a bounded integer from the user. * * @param parent - * The parent component for the dialogs. + * The parent component for the dialogs. * @param title - * The title for the dialogs. + * The title for the dialogs. * @param prompt - * The prompt to tell the user what to enter. + * The prompt to tell the user what to enter. * @param lowerBound - * The lower integer bound to accept. + * The lower integer bound to accept. * @param upperBound - * The upper integer bound to accept. + * The upper integer bound to accept. * @return A int within the specified bounds. */ - public static int getBoundedInt(final Component parent, final String title, final String prompt, - final int lowerBound, final int upperBound) { - return getValue(parent, title, prompt, (strang) -> { + public static int getBoundedInt(final Component parent, final String title, + final String prompt, final int lowerBound, final int upperBound) { + return getValue(parent, title, prompt, strang -> { try { final int value = Integer.parseInt(strang); return value < upperBound && value > lowerBound; - } catch(final NumberFormatException nfex) { + } catch (final NumberFormatException nfex) { // We don't care about the specifics of the // exception, just // that this value isn't good @@ -56,26 +56,27 @@ public class SimpleDialogs { * Asks the user to pick an option from a series of choices. * * @param <E> - * The type of choices for the user to pick + * The type of choices for the user to pick * * @param parent - * The parent frame for this dialog + * The parent frame for this dialog * @param title - * The title of this dialog + * The title of this dialog * @param question - * The question being asked + * The question being asked * @param choices - * The available choices for the question + * The available choices for the question * @return The choice the user picked, or null if they didn't pick one */ @SuppressWarnings("unchecked") - public static <E> E getChoice(final Frame parent, final String title, final String question, - final E... choices) { - if(parent == null) + public static <E> E getChoice(final Frame parent, final String title, + final String question, final E... choices) { + 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"); - else if(question == null) throw new NullPointerException("Question must not be null"); + else if (question == null) + throw new NullPointerException("Question must not be null"); final JDialog chooser = new JDialog(parent, title, true); chooser.setLayout(new VLayout(2)); @@ -93,8 +94,8 @@ public class SimpleDialogs { final JButton okButton = new JButton("Ok"); final JButton cancelButton = new JButton("Cancel"); - okButton.addActionListener((event) -> chooser.dispose()); - cancelButton.addActionListener((event) -> chooser.dispose()); + okButton.addActionListener(event -> chooser.dispose()); + cancelButton.addActionListener(event -> chooser.dispose()); buttonPane.add(cancelButton); buttonPane.add(okButton); @@ -112,19 +113,20 @@ public class SimpleDialogs { * Get a integer from the user * * @param parent - * The parent component for dialogs. + * The parent component for dialogs. * @param title - * The title for dialogs. + * The title for dialogs. * @param prompt - * The prompt to tell the user what to enter. + * The prompt to tell the user what to enter. * @return A int. */ - public static int getInt(final Component parent, final String title, final String prompt) { + public static int getInt(final Component parent, final String title, + final String prompt) { return getValue(parent, title, prompt, strang -> { try { Integer.parseInt(strang); return true; - } catch(final NumberFormatException nfex) { + } catch (final NumberFormatException nfex) { // We don't care about this exception, just mark // the value // as not good @@ -137,50 +139,55 @@ public class SimpleDialogs { * Get a string from the user * * @param parent - * The parent component for dialogs. + * The parent component for dialogs. * @param title - * The title for the dialogs. + * The title for the dialogs. * @param prompt - * The prompt to tell the user what to enter. + * The prompt to tell the user what to enter. * @return A string. */ - public static String getString(final Component parent, final String title, final String prompt) { - if(parent == null) + public static String getString(final Component parent, final String title, + final String prompt) { + 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"); - else if(prompt == null) throw new NullPointerException("Prompt must not be null"); + else if (prompt == null) + throw new NullPointerException("Prompt must not be null"); - return JOptionPane.showInputDialog(parent, prompt, title, JOptionPane.QUESTION_MESSAGE); + return JOptionPane.showInputDialog(parent, prompt, title, + JOptionPane.QUESTION_MESSAGE); } /** * Get a value parsable from a string from the user. * * @param <E> - * The type of the value parsed from the string + * The type of the value parsed from the string * * @param parent - * The parent component for dialogs. + * The parent component for dialogs. * @param title - * The title for dialogs. + * The title for dialogs. * @param prompt - * The prompt to tell the user what to enter. + * The prompt to tell the user what to enter. * @param validator - * A predicate to determine if a input is valid. + * A predicate to determine if a input is valid. * @param transformer - * The function to transform the string into a value. + * The function to transform the string into a value. * @return The value parsed from a string. */ - public static <E> E getValue(final Component parent, final String title, final String prompt, - final Predicate<String> validator, final Function<String, E> transformer) { - if(validator == null) + public static <E> E getValue(final Component parent, final String title, + final String prompt, final Predicate<String> validator, + final Function<String, E> transformer) { + if (validator == null) throw new NullPointerException("Validator must not be null"); - else if(transformer == null) throw new NullPointerException("Transformer must not be null"); + else if (transformer == null) + throw new NullPointerException("Transformer must not be null"); String input = getString(parent, title, prompt); - while(!validator.test(input)) { + while (!validator.test(input)) { showError(parent, "I/O Error", "Please enter a valid value"); input = getString(parent, title, prompt); @@ -193,14 +200,15 @@ public class SimpleDialogs { * Get a whole number from the user. * * @param parent - * The parent component for dialogs. + * The parent component for dialogs. * @param title - * The title for dialogs. + * The title for dialogs. * @param prompt - * The prompt to tell the user what to enter. + * The prompt to tell the user what to enter. * @return A whole number. */ - public static int getWhole(final Component parent, final String title, final String prompt) { + public static int getWhole(final Component parent, final String title, + final String prompt) { return getBoundedInt(parent, title, prompt, 0, Integer.MAX_VALUE); } @@ -208,21 +216,24 @@ public class SimpleDialogs { * Ask the user a Yes/No question. * * @param parent - * The parent component for dialogs. + * The parent component for dialogs. * @param title - * The title for dialogs. + * The title for dialogs. * @param question - * The question to ask the user. + * The question to ask the user. * @return True if the user said yes, false otherwise. */ - public static boolean getYesNo(final Component parent, final String title, final String question) { - if(parent == null) + public static boolean getYesNo(final Component parent, final String title, + final String question) { + 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"); - else if(question == null) throw new NullPointerException("Question must not be null"); + else if (question == null) + throw new NullPointerException("Question must not be null"); - final int result = JOptionPane.showConfirmDialog(parent, question, title, JOptionPane.YES_NO_OPTION); + final int result = JOptionPane.showConfirmDialog(parent, question, title, + JOptionPane.YES_NO_OPTION); return result == JOptionPane.YES_OPTION ? true : false; } @@ -231,18 +242,20 @@ public class SimpleDialogs { * Show a error message to the user * * @param parent - * The parent component for dialogs. + * The parent component for dialogs. * @param title - * The title for dialogs. + * The title for dialogs. * @param message - * The error to show the user. + * The error to show the user. */ - public static void showError(final Component parent, final String title, final String message) { - if(parent == null) + public static void showError(final Component parent, final String title, + final String message) { + 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"); - else if(message == null) throw new NullPointerException("Error message must not be null"); + else if (message == null) + throw new NullPointerException("Error message must not be null"); JOptionPane.showMessageDialog(parent, message, title, JOptionPane.ERROR_MESSAGE); } @@ -251,19 +264,22 @@ public class SimpleDialogs { * Show an informative message to the user * * @param parent - * The parent for this dialog + * The parent for this dialog * @param title - * Show the title for this dialog + * Show the title for this dialog * @param message - * Show the message for this dialog + * Show the message for this dialog */ - public static void showMessage(final Component parent, final String title, final String message) { - if(parent == null) + public static void showMessage(final Component parent, final String title, + final String message) { + 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"); - else if(message == null) throw new NullPointerException("Message must not be null"); + else if (message == null) + throw new NullPointerException("Message must not be null"); - JOptionPane.showMessageDialog(parent, title, message, JOptionPane.INFORMATION_MESSAGE); + JOptionPane.showMessageDialog(parent, title, message, + JOptionPane.INFORMATION_MESSAGE); } } diff --git a/base/src/main/java/bjc/utils/gui/SimpleFileChooser.java b/base/src/main/java/bjc/utils/gui/SimpleFileChooser.java index 01cd37f..7be9f84 100644 --- a/base/src/main/java/bjc/utils/gui/SimpleFileChooser.java +++ b/base/src/main/java/bjc/utils/gui/SimpleFileChooser.java @@ -16,54 +16,60 @@ import bjc.utils.exceptions.FileNotChosenException; * */ public class SimpleFileChooser { - private static File doOpenFile(final Component parent, final String title, final JFileChooser files) { - if(title == null) throw new NullPointerException("Title must not be null"); + private static File doOpenFile(final Component parent, final String title, + final JFileChooser files) { + if (title == null) + throw new NullPointerException("Title must not be null"); files.setDialogTitle(title); boolean success = false; - while(!success) { + while (!success) { try { maybeDoOpenFile(parent, files); success = true; - } catch(final FileNotChosenException fncx) { + } catch (final FileNotChosenException fncx) { // We don't care about specifics - SimpleDialogs.showError(parent, "I/O Error", "Please pick a file to open"); + SimpleDialogs.showError(parent, "I/O Error", + "Please pick a file to open"); } } return files.getSelectedFile(); } - private static File doSaveFile(final Component parent, final String title, final JFileChooser files) { - if(title == null) throw new NullPointerException("Title must not be null"); + private static File doSaveFile(final Component parent, final String title, + final JFileChooser files) { + if (title == null) + throw new NullPointerException("Title must not be null"); files.setDialogTitle(title); final boolean success = false; - while(!success) { + while (!success) { try { maybeDoSaveFile(parent, files); return files.getSelectedFile(); - } catch(final FileNotChosenException fncex) { + } catch (final FileNotChosenException fncex) { // We don't care about specifics - SimpleDialogs.showError(parent, "I/O Error", "Please pick a file to save to"); + SimpleDialogs.showError(parent, "I/O Error", + "Please pick a file to save to"); } } } /** - * Prompt the user with a "Open File..." dialog. Keeps prompting them - * until they pick a file. + * Prompt the user with a "Open File..." dialog. Keeps prompting them until they + * pick a file. * * @param parent - * The component to use as the parent for the dialog. + * The component to use as the parent for the dialog. * @param title - * The title of the dialog to prompt with. + * The title of the dialog to prompt with. * @return The file the user has chosen. */ public static File getOpenFile(final Component parent, final String title) { @@ -73,18 +79,19 @@ public class SimpleFileChooser { } /** - * Prompt the user with a "Open File..." dialog. Keeps prompting them - * until they pick a file. + * Prompt the user with a "Open File..." dialog. Keeps prompting them until they + * pick a file. * * @param parent - * The component to use as the parent for the dialog. + * The component to use as the parent for the dialog. * @param title - * The title of the dialog to prompt with. + * The title of the dialog to prompt with. * @param extensions - * The list of file extensions the file should have. + * The list of file extensions the file should have. * @return The file the user has chosen. */ - public static File getOpenFile(final Component parent, final String title, final String... extensions) { + public static File getOpenFile(final Component parent, final String title, + final String... extensions) { final JFileChooser files = new JFileChooser(); files.addChoosableFileFilter(new ExtensionFileFilter(extensions)); @@ -96,9 +103,9 @@ public class SimpleFileChooser { * Prompt the user with a "Save File..." dialog. * * @param parent - * The component to use as the parent for the dialog. + * The component to use as the parent for the dialog. * @param title - * The title of the dialog to prompt with. + * The title of the dialog to prompt with. * @return The file the user chose. */ public static File getSaveFile(final Component parent, final String title) { @@ -111,14 +118,15 @@ public class SimpleFileChooser { * Prompt the user with a "Save File..." dialog. * * @param parent - * The component to use as the parent for the dialog. + * The component to use as the parent for the dialog. * @param title - * The title of the dialog to prompt with. + * The title of the dialog to prompt with. * @param extensions - * The extensions of the files the user can choose. + * The extensions of the files the user can choose. * @return The file the user chose. */ - public static File getSaveFile(final Component parent, final String title, final String... extensions) { + public static File getSaveFile(final Component parent, final String title, + final String... extensions) { final JFileChooser files = new JFileChooser(); files.addChoosableFileFilter(new ExtensionFileFilter(extensions)); @@ -128,44 +136,49 @@ public class SimpleFileChooser { private static void maybeDoOpenFile(final Component parent, final JFileChooser files) throws FileNotChosenException { - if(parent == null) + if (parent == null) throw new NullPointerException("Parent must not be null"); - else if(files == null) throw new NullPointerException("File chooser must not be null"); + else if (files == null) + throw new NullPointerException("File chooser must not be null"); final int result = files.showSaveDialog(parent); - if(result != JFileChooser.APPROVE_OPTION) throw new FileNotChosenException(); + if (result != JFileChooser.APPROVE_OPTION) + throw new FileNotChosenException(); } private static void maybeDoSaveFile(final Component parent, final JFileChooser files) throws FileNotChosenException { - if(parent == null) + if (parent == null) throw new NullPointerException("Parent must not be null"); - else if(files == null) throw new NullPointerException("File chooser must not be null"); + else if (files == null) + throw new NullPointerException("File chooser must not be null"); final int result = files.showSaveDialog(parent); - if(result != JFileChooser.APPROVE_OPTION) throw new FileNotChosenException(); + if (result != JFileChooser.APPROVE_OPTION) + throw new FileNotChosenException(); } /** * Prompt the user with a "Open File..." dialog. * * @param parent - * The component to use as the parent for the dialog. + * The component to use as the parent for the dialog. * @param title - * The title of the dialog to prompt with. + * The title of the dialog to prompt with. * @return The file if the user chose one or null if they didn't. */ public static File maybeOpenFile(final Component parent, final String title) { - if(title == null) throw new NullPointerException("Title must not be null"); + if (title == null) + throw new NullPointerException("Title must not be null"); final JFileChooser files = new JFileChooser(); files.setDialogTitle(title); try { maybeDoOpenFile(parent, files); - } catch(final FileNotChosenException fncex) { + } catch (final FileNotChosenException fncex) { // We don't care about specifics } @@ -176,45 +189,47 @@ public class SimpleFileChooser { * Prompt the user with a "Save File..." dialog. * * @param parent - * The component to use as the parent for the dialog. + * The component to use as the parent for the dialog. * @param title - * The title of the dialog to prompt with. + * The title of the dialog to prompt with. * @return The file if the user chose one or null if they didn't. */ public static File maybeSaveFile(final Component parent, final String title) { - if(title == null) throw new NullPointerException("Title must not be null"); + if (title == null) + throw new NullPointerException("Title must not be null"); final JFileChooser files = new JFileChooser(); files.setDialogTitle(title); try { maybeDoSaveFile(parent, files); - } catch(final FileNotChosenException fncex) { + } catch (final FileNotChosenException fncex) { // We don't care about specifics } return files.getSelectedFile(); } - + /** * Show a dialog box to pick a directory. - * + * * @param parent - * The component to use as the parent for the dialog. + * The component to use as the parent for the dialog. * @param title - * The title of the dialog for prompting. + * The title of the dialog for prompting. * @return The directory picked, if the user picked one; null if they didn't. */ public static File pickDirectory(final Component parent, final String title) { - if (title == null) throw new NullPointerException("Title must not be null"); - + if (title == null) + throw new NullPointerException("Title must not be null"); + final JFileChooser files = new JFileChooser(); files.setDialogType(JFileChooser.OPEN_DIALOG); files.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); files.setDialogTitle(title); - + files.showOpenDialog(parent); - + return files.getSelectedFile(); } } diff --git a/base/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java b/base/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java index ef56011..5e16c84 100644 --- a/base/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java +++ b/base/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java @@ -19,25 +19,25 @@ public class SimpleInternalDialogs { * Get a bounded integer from the user. * * @param parent - * The parent component for the dialogs. + * The parent component for the dialogs. * @param title - * The title for the dialogs. + * The title for the dialogs. * @param prompt - * The prompt to tell the user what to enter. + * The prompt to tell the user what to enter. * @param lowerBound - * The lower integer bound to accept. + * The lower integer bound to accept. * @param upperBound - * The upper integer bound to accept. + * The upper integer bound to accept. * @return A int within the specified bounds. */ - public static int getBoundedInt(final Component parent, final String title, final String prompt, - final int lowerBound, final int upperBound) { - return getValue(parent, title, prompt, (strang) -> { + public static int getBoundedInt(final Component parent, final String title, + final String prompt, final int lowerBound, final int upperBound) { + return getValue(parent, title, prompt, strang -> { try { final int value = Integer.parseInt(strang); return value < upperBound && value > lowerBound; - } catch(final NumberFormatException nfex) { + } catch (final NumberFormatException nfex) { // We don't care about the specifics of the // exception, just // that this value isn't good @@ -50,19 +50,20 @@ public class SimpleInternalDialogs { * Get a integer from the user * * @param parent - * The parent component for dialogs. + * The parent component for dialogs. * @param title - * The title for dialogs. + * The title for dialogs. * @param prompt - * The prompt to tell the user what to enter. + * The prompt to tell the user what to enter. * @return A int. */ - public static int getInt(final Component parent, final String title, final String prompt) { + public static int getInt(final Component parent, final String title, + final String prompt) { return getValue(parent, title, prompt, strang -> { try { Integer.parseInt(strang); return true; - } catch(final NumberFormatException nfex) { + } catch (final NumberFormatException nfex) { // We don't care about this exception, just mark // the value // as not good @@ -75,50 +76,55 @@ public class SimpleInternalDialogs { * Get a string from the user * * @param parent - * The parent component for dialogs. + * The parent component for dialogs. * @param title - * The title for the dialogs. + * The title for the dialogs. * @param prompt - * The prompt to tell the user what to enter. + * The prompt to tell the user what to enter. * @return A string. */ - public static String getString(final Component parent, final String title, final String prompt) { - if(parent == null) + public static String getString(final Component parent, final String title, + final String prompt) { + 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"); - else if(prompt == null) throw new NullPointerException("Prompt must not be null"); + else if (prompt == null) + throw new NullPointerException("Prompt must not be null"); - return JOptionPane.showInternalInputDialog(parent, prompt, title, JOptionPane.QUESTION_MESSAGE); + return JOptionPane.showInternalInputDialog(parent, prompt, title, + JOptionPane.QUESTION_MESSAGE); } /** * Get a value parsable from a string from the user. * * @param <E> - * The type of the value parsed from the string + * The type of the value parsed from the string * * @param parent - * The parent component for dialogs. + * The parent component for dialogs. * @param title - * The title for dialogs. + * The title for dialogs. * @param prompt - * The prompt to tell the user what to enter. + * The prompt to tell the user what to enter. * @param validator - * A predicate to determine if a input is valid. + * A predicate to determine if a input is valid. * @param transformer - * The function to transform the string into a value. + * The function to transform the string into a value. * @return The value parsed from a string. */ - public static <E> E getValue(final Component parent, final String title, final String prompt, - final Predicate<String> validator, final Function<String, E> transformer) { - if(validator == null) + public static <E> E getValue(final Component parent, final String title, + final String prompt, final Predicate<String> validator, + final Function<String, E> transformer) { + if (validator == null) throw new NullPointerException("Validator must not be null"); - else if(transformer == null) throw new NullPointerException("Transformer must not be null"); + else if (transformer == null) + throw new NullPointerException("Transformer must not be null"); String strang = getString(parent, title, prompt); - while(!validator.test(strang)) { + while (!validator.test(strang)) { showError(parent, "I/O Error", "Please enter a valid value"); strang = getString(parent, title, prompt); @@ -131,14 +137,15 @@ public class SimpleInternalDialogs { * Get a whole number from the user. * * @param parent - * The parent component for dialogs. + * The parent component for dialogs. * @param title - * The title for dialogs. + * The title for dialogs. * @param prompt - * The prompt to tell the user what to enter. + * The prompt to tell the user what to enter. * @return A whole number. */ - public static int getWhole(final Component parent, final String title, final String prompt) { + public static int getWhole(final Component parent, final String title, + final String prompt) { return getBoundedInt(parent, title, prompt, 0, Integer.MAX_VALUE); } @@ -146,19 +153,21 @@ public class SimpleInternalDialogs { * Ask the user a Yes/No question. * * @param parent - * The parent component for dialogs. + * The parent component for dialogs. * @param title - * The title for dialogs. + * The title for dialogs. * @param question - * The question to ask the user. + * The question to ask the user. * @return True if the user said yes, false otherwise. */ - public static boolean getYesNo(final Component parent, final String title, final String question) { - if(parent == null) + public static boolean getYesNo(final Component parent, final String title, + final String question) { + 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"); - else if(question == null) throw new NullPointerException("Question must not be null"); + else if (question == null) + throw new NullPointerException("Question must not be null"); final int result = JOptionPane.showInternalConfirmDialog(parent, question, title, JOptionPane.YES_NO_OPTION); @@ -170,39 +179,45 @@ public class SimpleInternalDialogs { * Show a error message to the user * * @param parent - * The parent component for dialogs. + * The parent component for dialogs. * @param title - * The title for dialogs. + * The title for dialogs. * @param message - * The error to show the user. + * The error to show the user. */ - public static void showError(final Component parent, final String title, final String message) { - if(parent == null) + public static void showError(final Component parent, final String title, + final String message) { + 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"); - else if(message == null) throw new NullPointerException("Error message must not be null"); + else if (message == null) + throw new NullPointerException("Error message must not be null"); - JOptionPane.showInternalMessageDialog(parent, message, title, JOptionPane.ERROR_MESSAGE); + JOptionPane.showInternalMessageDialog(parent, message, title, + JOptionPane.ERROR_MESSAGE); } /** * Show an informative message to the user * * @param parent - * The parent for this dialog + * The parent for this dialog * @param title - * Show the title for this dialog + * Show the title for this dialog * @param message - * Show the message for this dialog + * Show the message for this dialog */ - public static void showMessage(final Component parent, final String title, final String message) { - if(parent == null) + public static void showMessage(final Component parent, final String title, + final String message) { + 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"); - else if(message == null) throw new NullPointerException("Message must not be null"); + else if (message == null) + throw new NullPointerException("Message must not be null"); - JOptionPane.showInternalMessageDialog(parent, title, message, JOptionPane.INFORMATION_MESSAGE); + JOptionPane.showInternalMessageDialog(parent, title, message, + JOptionPane.INFORMATION_MESSAGE); } } diff --git a/base/src/main/java/bjc/utils/gui/SimpleInternalFrame.java b/base/src/main/java/bjc/utils/gui/SimpleInternalFrame.java index 5c7983c..9cec9e1 100644 --- a/base/src/main/java/bjc/utils/gui/SimpleInternalFrame.java +++ b/base/src/main/java/bjc/utils/gui/SimpleInternalFrame.java @@ -22,7 +22,7 @@ public class SimpleInternalFrame extends JInternalFrame { * Create a new blank internal frame with a specific title * * @param title - * The title of the internal frame + * The title of the internal frame */ public SimpleInternalFrame(final String title) { super(title); diff --git a/base/src/main/java/bjc/utils/gui/SimpleJList.java b/base/src/main/java/bjc/utils/gui/SimpleJList.java index 31c995c..ca8eeb9 100644 --- a/base/src/main/java/bjc/utils/gui/SimpleJList.java +++ b/base/src/main/java/bjc/utils/gui/SimpleJList.java @@ -15,14 +15,15 @@ public class SimpleJList { * Create a new JList from a given list. * * @param <E> - * The type of data in the JList + * The type of data in the JList * * @param source - * The list to populate the JList with. + * The list to populate the JList with. * @return A JList populated with the elements from ls. */ public static <E> JList<E> buildFromList(final Iterable<E> source) { - if(source == null) throw new NullPointerException("Source must not be null"); + if (source == null) + throw new NullPointerException("Source must not be null"); return new JList<>(buildModel(source)); } @@ -31,14 +32,15 @@ public class SimpleJList { * Create a new list model from a given list. * * @param <E> - * The type of data in the list model + * The type of data in the list model * * @param source - * The list to fill the list model from. + * The list to fill the list model from. * @return A list model populated with the elements from ls. */ public static <E> ListModel<E> buildModel(final Iterable<E> source) { - if(source == null) throw new NullPointerException("Source must not be null"); + if (source == null) + throw new NullPointerException("Source must not be null"); final DefaultListModel<E> defaultModel = new DefaultListModel<>(); diff --git a/base/src/main/java/bjc/utils/gui/SimpleKeyedButton.java b/base/src/main/java/bjc/utils/gui/SimpleKeyedButton.java index 031cee3..0c40fbe 100644 --- a/base/src/main/java/bjc/utils/gui/SimpleKeyedButton.java +++ b/base/src/main/java/bjc/utils/gui/SimpleKeyedButton.java @@ -10,7 +10,7 @@ import javax.swing.KeyStroke; /** * Simple {@link JButton} that provides an easy way to add a key-map to it. - * + * * @author Ben Culkin * */ @@ -32,48 +32,62 @@ public class SimpleKeyedButton extends JButton { } private static final long serialVersionUID = -8550504153221678178L; - + private String label; /** * Create a new keyed button. - * - * @param label The label for the button. + * + * @param label + * The label for the button. */ public SimpleKeyedButton(String label) { super(label); - + this.label = label; } - + /** - * Sets the default action for this button, and installs a global (WHEN_IN_FOCUSED_WINDOW) keystroke handler for it. - * - * @param eventName An unique internal name for the event. - * @param keystroke The keystroke for this event, passed to {@link KeyStroke#getKeyStroke(String)}. - * @param aevListener The listener that handles the implementation of the action. + * Sets the default action for this button, and installs a global + * (WHEN_IN_FOCUSED_WINDOW) keystroke handler for it. + * + * @param eventName + * An unique internal name for the event. + * @param keystroke + * The keystroke for this event, passed to + * {@link KeyStroke#getKeyStroke(String)}. + * @param aevListener + * The listener that handles the implementation of the + * action. */ - public void setGlobalDefaultKeystroke(String eventName, String keystroke, Consumer<ActionEvent> aevListener) { + public void setGlobalDefaultKeystroke(String eventName, String keystroke, + Consumer<ActionEvent> aevListener) { Action act = new KeyedButtonAction(eventName, aevListener); KeyStroke stroke = KeyStroke.getKeyStroke(keystroke); - + this.setAction(act); this.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(stroke, eventName); this.getActionMap().put(eventName, act); this.setText(label); } - + /** * Installs a global (WHEN_IN_FOCUSED_WINDOW) keystroke handler for an action. - * - * @param eventName An unique internal name for the event. - * @param keystroke The keystroke for this event, passed to {@link KeyStroke#getKeyStroke(String)}. - * @param aevListener The listener that handles the implementation of the action. + * + * @param eventName + * An unique internal name for the event. + * @param keystroke + * The keystroke for this event, passed to + * {@link KeyStroke#getKeyStroke(String)}. + * @param aevListener + * The listener that handles the implementation of the + * action. */ - public void addGlobalKeystroke(String eventName, String keystroke, Consumer<ActionEvent> aevListener) { + public void addGlobalKeystroke(String eventName, String keystroke, + Consumer<ActionEvent> aevListener) { Action act = new KeyedButtonAction(eventName, aevListener); KeyStroke stroke = KeyStroke.getKeyStroke(keystroke); - + this.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(stroke, eventName); this.getActionMap().put(eventName, act); this.setText(label); diff --git a/base/src/main/java/bjc/utils/gui/SimpleTitledBorder.java b/base/src/main/java/bjc/utils/gui/SimpleTitledBorder.java index bddb564..81b0579 100644 --- a/base/src/main/java/bjc/utils/gui/SimpleTitledBorder.java +++ b/base/src/main/java/bjc/utils/gui/SimpleTitledBorder.java @@ -17,7 +17,7 @@ public class SimpleTitledBorder extends TitledBorder { * Create a new border with the specified title. * * @param title - * The title for the border. + * The title for the border. */ public SimpleTitledBorder(final String title) { super(new EtchedBorder(), title); diff --git a/base/src/main/java/bjc/utils/gui/TextAreaOutputStream.java b/base/src/main/java/bjc/utils/gui/TextAreaOutputStream.java index 0beb1e2..fbc58ed 100644 --- a/base/src/main/java/bjc/utils/gui/TextAreaOutputStream.java +++ b/base/src/main/java/bjc/utils/gui/TextAreaOutputStream.java @@ -18,7 +18,7 @@ public class TextAreaOutputStream extends OutputStream { * Create a new output stream attached to a textarea * * @param console - * The textarea to write to + * The textarea to write to */ public TextAreaOutputStream(final JTextArea console) { this.textArea = console; @@ -28,7 +28,7 @@ public class TextAreaOutputStream extends OutputStream { public void write(final int b) throws IOException { textArea.append("" + (char) b); - if(b == '\n') { + if (b == '\n') { textArea.repaint(); } } 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<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); } @@ -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); } diff --git a/base/src/main/java/bjc/utils/gui/layout/HLayout.java b/base/src/main/java/bjc/utils/gui/layout/HLayout.java index c2caa01..977cb15 100644 --- a/base/src/main/java/bjc/utils/gui/layout/HLayout.java +++ b/base/src/main/java/bjc/utils/gui/layout/HLayout.java @@ -16,7 +16,7 @@ public class HLayout extends GridLayout { * Create a new horizontal layout with the specified number of columns. * * @param columns - * The number of columns in this layout. + * The number of columns in this layout. */ public HLayout(final int columns) { super(1, columns); diff --git a/base/src/main/java/bjc/utils/gui/layout/VLayout.java b/base/src/main/java/bjc/utils/gui/layout/VLayout.java index d0f0503..3ee99e8 100644 --- a/base/src/main/java/bjc/utils/gui/layout/VLayout.java +++ b/base/src/main/java/bjc/utils/gui/layout/VLayout.java @@ -17,7 +17,7 @@ public class VLayout extends GridLayout { * Create a new vertical layout with the specified number of rows. * * @param rows - * The number of rows. + * The number of rows. */ public VLayout(final int rows) { super(rows, 1); diff --git a/base/src/main/java/bjc/utils/gui/panels/DropdownListPanel.java b/base/src/main/java/bjc/utils/gui/panels/DropdownListPanel.java index 642eee9..8f65577 100644 --- a/base/src/main/java/bjc/utils/gui/panels/DropdownListPanel.java +++ b/base/src/main/java/bjc/utils/gui/panels/DropdownListPanel.java @@ -26,15 +26,16 @@ public class DropdownListPanel extends JPanel { * Create a new dropdown list panel * * @param <T> - * The type of items in the dropdown list + * The type of items in the dropdown list * @param type - * The label of the type of items in the list + * The label of the type of items in the list * @param model - * The model to put items into + * The model to put items into * @param choices - * The items to choose from + * The items to choose from */ - public <T> DropdownListPanel(final String type, final DefaultListModel<T> model, final IList<T> choices) { + public <T> DropdownListPanel(final String type, final DefaultListModel<T> model, + final IList<T> choices) { setLayout(new AutosizeLayout()); final JPanel itemInputPanel = new JPanel(); @@ -56,11 +57,11 @@ public class DropdownListPanel extends JPanel { final JButton removeItemButton = new JButton("Remove " + type); - addItemButton.addActionListener((ev) -> { + addItemButton.addActionListener(ev -> { model.addElement(addItemBox.getItemAt(addItemBox.getSelectedIndex())); }); - removeItemButton.addActionListener((ev) -> { + removeItemButton.addActionListener(ev -> { model.remove(itemList.getSelectedIndex()); }); diff --git a/base/src/main/java/bjc/utils/gui/panels/FormattedInputPanel.java b/base/src/main/java/bjc/utils/gui/panels/FormattedInputPanel.java index 96f0487..3b66086 100644 --- a/base/src/main/java/bjc/utils/gui/panels/FormattedInputPanel.java +++ b/base/src/main/java/bjc/utils/gui/panels/FormattedInputPanel.java @@ -15,7 +15,7 @@ import bjc.utils.gui.layout.HLayout; * @author ben * * @param <InputVal> - * The type of value being formatted + * The type of value being formatted */ public class FormattedInputPanel<InputVal> extends JPanel { private static final long serialVersionUID = 5232016563558588031L; @@ -26,17 +26,17 @@ public class FormattedInputPanel<InputVal> extends JPanel { * Create a new formatted input panel * * @param label - * The label for this panel + * The label for this panel * @param length - * The length of this panel + * The length of this panel * @param formatter - * The formatter to use for input + * The formatter to use for input * @param reciever - * The action to call whenever the value changes + * The action to call whenever the value changes */ @SuppressWarnings("unchecked") - public FormattedInputPanel(final String label, final int length, final AbstractFormatter formatter, - final Consumer<InputVal> reciever) { + public FormattedInputPanel(final String label, final int length, + final AbstractFormatter formatter, final Consumer<InputVal> reciever) { setLayout(new HLayout(2)); final JLabel lab = new JLabel(label); @@ -44,7 +44,7 @@ public class FormattedInputPanel<InputVal> extends JPanel { field.setColumns(length); field.setFocusLostBehavior(JFormattedTextField.COMMIT_OR_REVERT); - field.addPropertyChangeListener("value", (event) -> { + field.addPropertyChangeListener("value", event -> { // This is safe, because InputVal should be the type of // whatever object the formatter is returning reciever.accept((InputVal) field.getValue()); @@ -58,7 +58,7 @@ public class FormattedInputPanel<InputVal> extends JPanel { * Reset the value in this panel to a specified value * * @param value - * The value to set the panel to + * The value to set the panel to */ public void resetValues(final InputVal value) { field.setValue(value); diff --git a/base/src/main/java/bjc/utils/gui/panels/HolderOutputPanel.java b/base/src/main/java/bjc/utils/gui/panels/HolderOutputPanel.java index 9e1592e..d0b5383 100644 --- a/base/src/main/java/bjc/utils/gui/panels/HolderOutputPanel.java +++ b/base/src/main/java/bjc/utils/gui/panels/HolderOutputPanel.java @@ -25,13 +25,14 @@ public class HolderOutputPanel extends JPanel { * Create a new display panel, backed by a holder * * @param lab - * The label to attach to this field + * The label to attach to this field * @param valueHolder - * The holder to get the value from + * The holder to get the value from * @param nDelay - * The delay in ms between value updates + * The delay in ms between value updates */ - public HolderOutputPanel(final String lab, final IHolder<String> valueHolder, final int nDelay) { + public HolderOutputPanel(final String lab, final IHolder<String> valueHolder, + final int nDelay) { this.val = valueHolder; this.nDelay = nDelay; @@ -40,7 +41,7 @@ public class HolderOutputPanel extends JPanel { final JLabel label = new JLabel(lab); value = new JLabel("(stopped)"); - updater = new Timer(nDelay, (event) -> { + updater = new Timer(nDelay, event -> { value.setText(valueHolder.getValue()); }); @@ -56,7 +57,7 @@ public class HolderOutputPanel extends JPanel { value.setText("(stopped)"); - updater = new Timer(nDelay, (event) -> { + updater = new Timer(nDelay, event -> { value.setText(val.getValue()); }); } diff --git a/base/src/main/java/bjc/utils/gui/panels/ListParameterPanel.java b/base/src/main/java/bjc/utils/gui/panels/ListParameterPanel.java index d9c5966..3b48309 100644 --- a/base/src/main/java/bjc/utils/gui/panels/ListParameterPanel.java +++ b/base/src/main/java/bjc/utils/gui/panels/ListParameterPanel.java @@ -20,7 +20,7 @@ import bjc.utils.gui.layout.VLayout; * @author ben * * @param <E> - * The type of data stored in the list + * The type of data stored in the list */ public class ListParameterPanel<E> extends JPanel { // Version id for serialization @@ -30,13 +30,14 @@ public class ListParameterPanel<E> extends JPanel { * Create a new panel using the specified actions for doing things * * @param add - * The action that provides items + * The action that provides items * @param edit - * The action that edits items + * The action that edits items * @param remove - * The action that removes items + * The action that removes items */ - public ListParameterPanel(final Supplier<E> add, final Consumer<E> edit, final Consumer<E> remove) { + public ListParameterPanel(final Supplier<E> add, final Consumer<E> edit, + final Consumer<E> remove) { this(add, edit, remove, null); } @@ -44,21 +45,21 @@ public class ListParameterPanel<E> extends JPanel { * Create a new panel using the specified actions for doing things * * @param add - * The action that provides items + * The action that provides items * @param edit - * The action that edits items + * The action that edits items * @param remove - * The action that removes items + * The action that removes items * @param defaults - * The default values to put in the list + * The default values to put in the list */ - public ListParameterPanel(final Supplier<E> add, final Consumer<E> edit, final Consumer<E> remove, - final IList<E> defaults) { + public ListParameterPanel(final Supplier<E> add, final Consumer<E> edit, + final Consumer<E> remove, final IList<E> defaults) { setLayout(new VLayout(2)); JList<E> list; - if(defaults != null) { + if (defaults != null) { list = SimpleJList.buildFromList(defaults.toIterable()); } else { list = new JList<>(new DefaultListModel<>()); @@ -70,15 +71,15 @@ public class ListParameterPanel<E> extends JPanel { int numButtons = 0; - if(add != null) { + if (add != null) { numButtons++; } - if(edit != null) { + if (edit != null) { numButtons++; } - if(remove != null) { + if (remove != null) { numButtons++; } @@ -86,9 +87,9 @@ public class ListParameterPanel<E> extends JPanel { JButton addParam = null; - if(add != null) { + if (add != null) { addParam = new JButton("Add..."); - addParam.addActionListener((event) -> { + addParam.addActionListener(event -> { final DefaultListModel<E> model = (DefaultListModel<E>) list.getModel(); model.addElement(add.get()); @@ -97,33 +98,33 @@ public class ListParameterPanel<E> extends JPanel { JButton editParam = null; - if(edit != null) { + if (edit != null) { editParam = new JButton("Edit..."); - editParam.addActionListener((event) -> { + editParam.addActionListener(event -> { edit.accept(list.getSelectedValue()); }); } JButton removeParam = null; - if(remove != null) { + if (remove != null) { removeParam = new JButton("Remove..."); - removeParam.addActionListener((event) -> { + removeParam.addActionListener(event -> { final DefaultListModel<E> model = (DefaultListModel<E>) list.getModel(); remove.accept(model.remove(list.getSelectedIndex())); }); } - if(add != null) { + if (add != null) { buttonPanel.add(addParam); } - if(edit != null) { + if (edit != null) { buttonPanel.add(editParam); } - if(remove != null) { + if (remove != null) { buttonPanel.add(removeParam); } diff --git a/base/src/main/java/bjc/utils/gui/panels/SimpleInputPanel.java b/base/src/main/java/bjc/utils/gui/panels/SimpleInputPanel.java index 301a183..65c533d 100644 --- a/base/src/main/java/bjc/utils/gui/panels/SimpleInputPanel.java +++ b/base/src/main/java/bjc/utils/gui/panels/SimpleInputPanel.java @@ -24,16 +24,16 @@ public class SimpleInputPanel extends JPanel { * Create a new input panel * * @param label - * The label for the field + * The label for the field * @param columns - * The number of columns of text input to take + * The number of columns of text input to take */ public SimpleInputPanel(final String label, final int columns) { setLayout(new BorderLayout()); final JLabel inputLabel = new JLabel(label); - if(columns < 1) { + if (columns < 1) { inputValue = new JTextField(); } else { inputValue = new JTextField(columns); diff --git a/base/src/main/java/bjc/utils/gui/panels/SimpleListPanel.java b/base/src/main/java/bjc/utils/gui/panels/SimpleListPanel.java index 628d146..d4dda55 100644 --- a/base/src/main/java/bjc/utils/gui/panels/SimpleListPanel.java +++ b/base/src/main/java/bjc/utils/gui/panels/SimpleListPanel.java @@ -24,11 +24,12 @@ import bjc.utils.gui.layout.HLayout; public class SimpleListPanel extends JPanel { private static final long serialVersionUID = 2719963952350133541L; - private static void addItem(final DefaultListModel<String> model, final Predicate<String> verifier, - final Consumer<String> onFailure, final JTextField addItemField) { + private static void addItem(final DefaultListModel<String> model, + final Predicate<String> verifier, final Consumer<String> onFailure, + final JTextField addItemField) { final String potentialItem = addItemField.getText(); - if(verifier == null || verifier.test(potentialItem)) { + if (verifier == null || verifier.test(potentialItem)) { model.addElement(potentialItem); } else { onFailure.accept(potentialItem); @@ -41,13 +42,13 @@ public class SimpleListPanel extends JPanel { * Create a new list panel * * @param type - * The type of things in the list + * The type of things in the list * @param model - * The model to put items into + * The model to put items into * @param verifier - * The predicate to use to verify items + * The predicate to use to verify items * @param onFailure - * The function to call when an item doesn't verify + * The function to call when an item doesn't verify */ public SimpleListPanel(final String type, final DefaultListModel<String> model, final Predicate<String> verifier, final Consumer<String> onFailure) { @@ -72,15 +73,15 @@ public class SimpleListPanel extends JPanel { final JButton removeItemButton = new JButton("Remove " + type); - addItemButton.addActionListener((ev) -> { + addItemButton.addActionListener(ev -> { addItem(model, verifier, onFailure, addItemField); }); - addItemField.addActionListener((ev) -> { + addItemField.addActionListener(ev -> { addItem(model, verifier, onFailure, addItemField); }); - removeItemButton.addActionListener((ev) -> { + removeItemButton.addActionListener(ev -> { model.remove(itemList.getSelectedIndex()); }); diff --git a/base/src/main/java/bjc/utils/gui/panels/SimpleSpinnerPanel.java b/base/src/main/java/bjc/utils/gui/panels/SimpleSpinnerPanel.java index 2628c39..8ca6f2b 100644 --- a/base/src/main/java/bjc/utils/gui/panels/SimpleSpinnerPanel.java +++ b/base/src/main/java/bjc/utils/gui/panels/SimpleSpinnerPanel.java @@ -25,9 +25,9 @@ public class SimpleSpinnerPanel extends JPanel { * Create a new spinner panel * * @param label - * The label for the spinner + * The label for the spinner * @param model - * The model to attach to the spinner + * The model to attach to the spinner */ public SimpleSpinnerPanel(final String label, final SpinnerModel model) { setLayout(new BorderLayout()); diff --git a/base/src/main/java/bjc/utils/gui/panels/SliderInputPanel.java b/base/src/main/java/bjc/utils/gui/panels/SliderInputPanel.java index da87357..835513a 100644 --- a/base/src/main/java/bjc/utils/gui/panels/SliderInputPanel.java +++ b/base/src/main/java/bjc/utils/gui/panels/SliderInputPanel.java @@ -38,14 +38,15 @@ public class SliderInputPanel extends JPanel { try { final int val = Integer.parseInt(text); - if(val < minValue) + if (val < minValue) throw new ParseException("Value must be greater than " + minValue, 0); - else if(val > maxValue) + else if (val > maxValue) throw new ParseException("Value must be smaller than " + maxValue, 0); else return val; - } catch(final NumberFormatException nfex) { - final ParseException pex = new ParseException("Value must be a valid integer", 0); + } catch (final NumberFormatException nfex) { + final ParseException pex + = new ParseException("Value must be a valid integer", 0); pex.initCause(nfex); @@ -55,7 +56,8 @@ public class SliderInputPanel extends JPanel { @Override public String valueToString(final Object value) throws ParseException { - if(value == null) return Integer.toString(initValue); + if (value == null) + return Integer.toString(initValue); return Integer.toString((Integer) value); } @@ -83,13 +85,12 @@ public class SliderInputPanel extends JPanel { public final int initValue; /** - * Create a new slider settings, with the initial value in the - * middle + * Create a new slider settings, with the initial value in the middle * * @param min - * The minimum value of the slider + * The minimum value of the slider * @param max - * The maximum value of the slider + * The maximum value of the slider */ public SliderSettings(final int min, final int max) { this(min, max, (min + max) / 2); @@ -99,11 +100,11 @@ public class SliderInputPanel extends JPanel { * Create a new set of slider sttings * * @param min - * The minimum slider value + * The minimum slider value * @param max - * The maximum slider value + * The maximum slider value * @param init - * Th initial slider value + * Th initial slider value */ public SliderSettings(final int min, final int max, final int init) { minValue = min; @@ -121,18 +122,18 @@ public class SliderInputPanel extends JPanel { * Create a new slider input panel * * @param lab - * The label for the field + * The label for the field * @param settings - * The settings for slider values + * The settings for slider values * @param majorTick - * The setting for where to place big ticks + * The setting for where to place big ticks * @param minorTick - * The setting for where to place small ticks + * The setting for where to place small ticks * @param action - * The action to execute for a given value + * The action to execute for a given value */ - public SliderInputPanel(final String lab, final SliderSettings settings, final int majorTick, - final int minorTick, final Consumer<Integer> action) { + public SliderInputPanel(final String lab, final SliderSettings settings, + final int majorTick, final int minorTick, final Consumer<Integer> action) { setLayout(new HLayout(3)); final JLabel label = new JLabel(lab); @@ -145,8 +146,8 @@ public class SliderInputPanel extends JPanel { slider.setPaintTicks(true); slider.setPaintLabels(true); - slider.addChangeListener((event) -> { - if(slider.getValueIsAdjusting()) { + slider.addChangeListener(event -> { + if (slider.getValueIsAdjusting()) { // Do nothing } else { final int val = slider.getValue(); @@ -159,10 +160,10 @@ public class SliderInputPanel extends JPanel { field.setFocusLostBehavior(JFormattedTextField.COMMIT_OR_REVERT); field.setColumns(15); - field.addPropertyChangeListener("value", (event) -> { + field.addPropertyChangeListener("value", event -> { final Object value = field.getValue(); - if(value == null) { + if (value == null) { // Do nothing } else { slider.setValue((Integer) value); @@ -178,7 +179,7 @@ public class SliderInputPanel extends JPanel { * Reset the values in this panel to a specified value * * @param value - * The value to reset the fields to + * The value to reset the fields to */ public void resetValues(final int value) { slider.setValue(value); |
