diff options
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/gui')
21 files changed, 217 insertions, 272 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/ExtensionFileFilter.java b/BJC-Utils2/src/main/java/bjc/utils/gui/ExtensionFileFilter.java index 6a5e676..8662f4e 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/ExtensionFileFilter.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/ExtensionFileFilter.java @@ -1,18 +1,18 @@ package bjc.utils.gui; +import bjc.utils.funcdata.FunctionalList; +import bjc.utils.funcdata.IList; + import java.io.File; import java.util.List; import javax.swing.filechooser.FileFilter; -import bjc.utils.funcdata.FunctionalList; -import bjc.utils.funcdata.IList; - /** * A file filter based on extensions. - * + * * Built for Swing. - * + * * @author ben * */ @@ -24,7 +24,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. */ @@ -34,7 +34,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. */ @@ -44,9 +44,7 @@ public class ExtensionFileFilter extends FileFilter { @Override public boolean accept(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/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java index 7e3cdfd..bb14327 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java @@ -1,5 +1,7 @@ package bjc.utils.gui; +import bjc.utils.gui.layout.VLayout; + import java.awt.Component; import java.awt.Frame; import java.util.function.Function; @@ -12,18 +14,16 @@ import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; -import bjc.utils.gui.layout.VLayout; - /** * Utility class for getting simple input from the user. - * + * * @author ben * */ public class SimpleDialogs { /** * Get a bounded integer from the user. - * + * * @param parent * The parent component for the dialogs. * @param title @@ -41,8 +41,8 @@ public class SimpleDialogs { try { int value = Integer.parseInt(strang); - return (value < upperBound) && (value > lowerBound); - } catch (NumberFormatException nfex) { + return value < upperBound && value > lowerBound; + } catch(NumberFormatException nfex) { // We don't care about the specifics of the // exception, just // that this value isn't good @@ -53,10 +53,10 @@ 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 - * + * * @param parent * The parent frame for this dialog * @param title @@ -69,13 +69,11 @@ public class SimpleDialogs { */ @SuppressWarnings("unchecked") public static <E> E getChoice(Frame parent, String title, String question, E... choices) { - if (parent == null) { + 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"); JDialog chooser = new JDialog(parent, title, true); chooser.setLayout(new VLayout(2)); @@ -110,7 +108,7 @@ public class SimpleDialogs { /** * Get a integer from the user - * + * * @param parent * The parent component for dialogs. * @param title @@ -124,7 +122,7 @@ public class SimpleDialogs { try { Integer.parseInt(strang); return true; - } catch (NumberFormatException nfex) { + } catch(NumberFormatException nfex) { // We don't care about this exception, just mark // the value // as not good @@ -135,7 +133,7 @@ public class SimpleDialogs { /** * Get a string from the user - * + * * @param parent * The parent component for dialogs. * @param title @@ -145,23 +143,21 @@ public class SimpleDialogs { * @return A string. */ public static String getString(Component parent, String title, String prompt) { - if (parent == null) { + 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); } /** * Get a value parsable from a string from the user. - * + * * @param <E> * The type of the value parsed from the string - * + * * @param parent * The parent component for dialogs. * @param title @@ -176,15 +172,13 @@ public class SimpleDialogs { */ public static <E> E getValue(Component parent, String title, String prompt, Predicate<String> validator, Function<String, E> transformer) { - if (validator == null) { + 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); @@ -195,7 +189,7 @@ public class SimpleDialogs { /** * Get a whole number from the user. - * + * * @param parent * The parent component for dialogs. * @param title @@ -210,7 +204,7 @@ public class SimpleDialogs { /** * Ask the user a Yes/No question. - * + * * @param parent * The parent component for dialogs. * @param title @@ -220,22 +214,20 @@ public class SimpleDialogs { * @return True if the user said yes, false otherwise. */ public static boolean getYesNo(Component parent, String title, String question) { - if (parent == null) { + 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"); int result = JOptionPane.showConfirmDialog(parent, question, title, JOptionPane.YES_NO_OPTION); - return (result == JOptionPane.YES_OPTION ? true : false); + return result == JOptionPane.YES_OPTION ? true : false; } /** * Show a error message to the user - * + * * @param parent * The parent component for dialogs. * @param title @@ -244,20 +236,18 @@ public class SimpleDialogs { * The error to show the user. */ public static void showError(Component parent, String title, String message) { - if (parent == null) { + 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); } /** * Show an informative message to the user - * + * * @param parent * The parent for this dialog * @param title @@ -266,13 +256,11 @@ public class SimpleDialogs { * Show the message for this dialog */ public static void showMessage(Component parent, String title, String message) { - if (parent == null) { + 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); } diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleFileChooser.java b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleFileChooser.java index ec4b784..cd7c180 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleFileChooser.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleFileChooser.java @@ -1,36 +1,34 @@ package bjc.utils.gui; +import bjc.utils.exceptions.FileNotChosenException; + import java.awt.Component; import java.io.File; import javax.swing.JFileChooser; -import bjc.utils.exceptions.FileNotChosenException; - /** * Utility class for easily prompting user for files. - * + * * Built for Swing. - * + * * @author ben * */ public class SimpleFileChooser { private static File doOpenFile(Component parent, String title, JFileChooser files) { - if (title == null) { - throw new NullPointerException("Title must not be null"); - } + 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 (FileNotChosenException fncx) { + } catch(FileNotChosenException fncx) { // We don't care about specifics SimpleDialogs.showError(parent, "I/O Error", "Please pick a file to open"); } @@ -40,20 +38,18 @@ public class SimpleFileChooser { } private static File doSaveFile(Component parent, String title, JFileChooser files) { - if (title == null) { - throw new NullPointerException("Title must not be null"); - } + if(title == null) throw new NullPointerException("Title must not be null"); files.setDialogTitle(title); boolean success = false; - while (!success) { + while(!success) { try { maybeDoSaveFile(parent, files); return files.getSelectedFile(); - } catch (FileNotChosenException fncex) { + } catch(FileNotChosenException fncex) { // We don't care about specifics SimpleDialogs.showError(parent, "I/O Error", "Please pick a file to save to"); } @@ -65,7 +61,7 @@ public class SimpleFileChooser { /** * 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. * @param title @@ -81,7 +77,7 @@ public class SimpleFileChooser { /** * 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. * @param title @@ -100,7 +96,7 @@ public class SimpleFileChooser { /** * Prompt the user with a "Save File..." dialog. - * + * * @param parent * The component to use as the parent for the dialog. * @param title @@ -115,7 +111,7 @@ public class SimpleFileChooser { /** * Prompt the user with a "Save File..." dialog. - * + * * @param parent * The component to use as the parent for the dialog. * @param title @@ -133,36 +129,28 @@ public class SimpleFileChooser { } private static void maybeDoOpenFile(Component parent, 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"); 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(Component parent, 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"); 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. * @param title @@ -170,16 +158,14 @@ public class SimpleFileChooser { * @return The file if the user chose one or null if they didn't. */ public static File maybeOpenFile(Component parent, String title) { - if (title == null) { - throw new NullPointerException("Title must not be null"); - } + if(title == null) throw new NullPointerException("Title must not be null"); JFileChooser files = new JFileChooser(); files.setDialogTitle(title); try { maybeDoOpenFile(parent, files); - } catch (FileNotChosenException fncex) { + } catch(FileNotChosenException fncex) { // We don't care about specifics } @@ -188,7 +174,7 @@ public class SimpleFileChooser { /** * Prompt the user with a "Save File..." dialog. - * + * * @param parent * The component to use as the parent for the dialog. * @param title @@ -196,16 +182,14 @@ public class SimpleFileChooser { * @return The file if the user chose one or null if they didn't. */ public static File maybeSaveFile(Component parent, String title) { - if (title == null) { - throw new NullPointerException("Title must not be null"); - } + if(title == null) throw new NullPointerException("Title must not be null"); JFileChooser files = new JFileChooser(); files.setDialogTitle(title); try { maybeDoSaveFile(parent, files); - } catch (FileNotChosenException fncex) { + } catch(FileNotChosenException fncex) { // We don't care about specifics } diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java index b5f0d6c..d7bb700 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalDialogs.java @@ -10,14 +10,14 @@ import javax.swing.JOptionPane; * Utility class for getting simple input from the user. * * Modified to work with JDesktopPanes - * + * * @author ben * */ public class SimpleInternalDialogs { /** * Get a bounded integer from the user. - * + * * @param parent * The parent component for the dialogs. * @param title @@ -35,8 +35,8 @@ public class SimpleInternalDialogs { try { int value = Integer.parseInt(strang); - return (value < upperBound) && (value > lowerBound); - } catch (NumberFormatException nfex) { + return value < upperBound && value > lowerBound; + } catch(NumberFormatException nfex) { // We don't care about the specifics of the // exception, just // that this value isn't good @@ -47,7 +47,7 @@ public class SimpleInternalDialogs { /** * Get a integer from the user - * + * * @param parent * The parent component for dialogs. * @param title @@ -61,7 +61,7 @@ public class SimpleInternalDialogs { try { Integer.parseInt(strang); return true; - } catch (NumberFormatException nfex) { + } catch(NumberFormatException nfex) { // We don't care about this exception, just mark // the value // as not good @@ -72,7 +72,7 @@ public class SimpleInternalDialogs { /** * Get a string from the user - * + * * @param parent * The parent component for dialogs. * @param title @@ -82,23 +82,21 @@ public class SimpleInternalDialogs { * @return A string. */ public static String getString(Component parent, String title, String prompt) { - if (parent == null) { + 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); } /** * Get a value parsable from a string from the user. - * + * * @param <E> * The type of the value parsed from the string - * + * * @param parent * The parent component for dialogs. * @param title @@ -113,15 +111,13 @@ public class SimpleInternalDialogs { */ public static <E> E getValue(Component parent, String title, String prompt, Predicate<String> validator, Function<String, E> transformer) { - if (validator == null) { + 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); @@ -132,7 +128,7 @@ public class SimpleInternalDialogs { /** * Get a whole number from the user. - * + * * @param parent * The parent component for dialogs. * @param title @@ -147,7 +143,7 @@ public class SimpleInternalDialogs { /** * Ask the user a Yes/No question. - * + * * @param parent * The parent component for dialogs. * @param title @@ -157,22 +153,20 @@ public class SimpleInternalDialogs { * @return True if the user said yes, false otherwise. */ public static boolean getYesNo(Component parent, String title, String question) { - if (parent == null) { + 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"); int result = JOptionPane.showInternalConfirmDialog(parent, question, title, JOptionPane.YES_NO_OPTION); - return (result == JOptionPane.YES_OPTION ? true : false); + return result == JOptionPane.YES_OPTION ? true : false; } /** * Show a error message to the user - * + * * @param parent * The parent component for dialogs. * @param title @@ -181,20 +175,18 @@ public class SimpleInternalDialogs { * The error to show the user. */ public static void showError(Component parent, String title, String message) { - if (parent == null) { + 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); } /** * Show an informative message to the user - * + * * @param parent * The parent for this dialog * @param title @@ -203,13 +195,11 @@ public class SimpleInternalDialogs { * Show the message for this dialog */ public static void showMessage(Component parent, String title, String message) { - if (parent == null) { + 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); } diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalFrame.java b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalFrame.java index 4fe23e1..9fdf18f 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalFrame.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalFrame.java @@ -4,7 +4,7 @@ import javax.swing.JInternalFrame; /** * A simple internal frame class - * + * * @author ben * */ @@ -20,7 +20,7 @@ public class SimpleInternalFrame extends JInternalFrame { /** * Create a new blank internal frame with a specific title - * + * * @param title * The title of the internal frame */ diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleJList.java b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleJList.java index 0cac1c9..e469f2f 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleJList.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleJList.java @@ -6,43 +6,39 @@ import javax.swing.ListModel; /** * Utility class for making JLists and their models. - * + * * @author ben * */ public class SimpleJList { /** * Create a new JList from a given list. - * + * * @param <E> * The type of data in the JList - * + * * @param source * The list to populate the JList with. * @return A JList populated with the elements from ls. */ public static <E> JList<E> buildFromList(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)); } /** * Create a new list model from a given list. - * + * * @param <E> * The type of data in the list model - * + * * @param source * The list to fill the list model from. * @return A list model populated with the elements from ls. */ public static <E> ListModel<E> buildModel(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"); DefaultListModel<E> defaultModel = new DefaultListModel<>(); diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleTitledBorder.java b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleTitledBorder.java index 75d89e7..723fad0 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleTitledBorder.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleTitledBorder.java @@ -5,7 +5,7 @@ import javax.swing.border.TitledBorder; /** * A simple border with a title attached to it. - * + * * @author ben * */ @@ -15,7 +15,7 @@ public class SimpleTitledBorder extends TitledBorder { /** * Create a new border with the specified title. - * + * * @param title * The title for the border. */ diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/TextAreaOutputStream.java b/BJC-Utils2/src/main/java/bjc/utils/gui/TextAreaOutputStream.java index 2fab8be..c63abfd 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/TextAreaOutputStream.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/TextAreaOutputStream.java @@ -16,7 +16,7 @@ public class TextAreaOutputStream extends OutputStream { /** * Create a new output stream attached to a textarea - * + * * @param console * The textarea to write to */ @@ -28,7 +28,7 @@ public class TextAreaOutputStream extends OutputStream { public void write(int b) throws IOException { textArea.append("" + (char) b); - if (b == '\n') { + if(b == '\n') { textArea.repaint(); } } 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 0990f4f..68978e7 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,17 +1,17 @@ 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. - * + * * Built for AWT - * + * * @author ben * */ @@ -23,21 +23,19 @@ 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. */ public ExtensionFileFilter(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); } /** * Create a new filter only showing files with the specified extensions. - * + * * @param exts * The extensions to show in this filter. */ 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 041a9a2..47f76b8 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,24 +1,24 @@ 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 - * + * * 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 @@ -31,7 +31,7 @@ public class SimpleFileDialog { /** * Prompt the user to pick a file to open - * + * * @param parent * The parent of the file picker * @param title @@ -41,22 +41,20 @@ public class SimpleFileDialog { * @return The file the user picked */ public static File getOpenFile(Frame parent, String title, String... extensions) { - if (parent == null) { + 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); - if (extensions != null) { + if(extensions != null) { 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); } @@ -66,7 +64,7 @@ public class SimpleFileDialog { /** * Prompt the user to pick a file to open - * + * * @param parent * The parent of the file picker * @param title @@ -76,15 +74,13 @@ public class SimpleFileDialog { * @return The file the user picked */ public static File[] getOpenFiles(Frame parent, String title, String... extensions) { - if (parent == null) { + 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); - if (extensions != null) { + if(extensions != null) { FilenameFilter filter = new ExtensionFileFilter(extensions); chooser.setFilenameFilter(filter); } @@ -92,7 +88,7 @@ public class SimpleFileDialog { 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); } @@ -102,7 +98,7 @@ public class SimpleFileDialog { /** * Prompt the user to pick a file to save - * + * * @param parent * The parent of the file picker * @param title @@ -115,7 +111,7 @@ public class SimpleFileDialog { /** * Prompt the user to pick a file to save - * + * * @param parent * The parent of the file picker * @param title @@ -125,22 +121,20 @@ public class SimpleFileDialog { * @return The file the user picked */ public static File getSaveFile(Frame parent, String title, String... extensions) { - if (parent == null) { + 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); - if (extensions != null) { + if(extensions != null) { 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); } diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/layout/AutosizeLayout.java b/BJC-Utils2/src/main/java/bjc/utils/gui/layout/AutosizeLayout.java index 07acd56..6f384f2 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/layout/AutosizeLayout.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/layout/AutosizeLayout.java @@ -5,7 +5,7 @@ import java.awt.GridLayout; /** * A layout that simply holds one component that it auto-resizes whenever it is * resized. - * + * * @author ben * */ diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/layout/HLayout.java b/BJC-Utils2/src/main/java/bjc/utils/gui/layout/HLayout.java index 3380321..be2116a 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/layout/HLayout.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/layout/HLayout.java @@ -5,7 +5,7 @@ import java.awt.GridLayout; /** * A layout manager that lays out its components horizontally, evenly sizing * them. - * + * * @author ben * */ @@ -15,7 +15,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. */ diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/layout/VLayout.java b/BJC-Utils2/src/main/java/bjc/utils/gui/layout/VLayout.java index fdae31e..9c5a563 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/layout/VLayout.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/layout/VLayout.java @@ -5,7 +5,7 @@ import java.awt.GridLayout; /** * A layout that lays out its components vertically, evenly sharing space among * them. - * + * * @author ben * */ @@ -15,7 +15,7 @@ public class VLayout extends GridLayout { /** * Create a new vertical layout with the specified number of rows. - * + * * @param rows * The number of rows. */ diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/DropdownListPanel.java b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/DropdownListPanel.java index f2d7f7b..6e6be02 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/DropdownListPanel.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/DropdownListPanel.java @@ -1,5 +1,9 @@ package bjc.utils.gui.panels; +import bjc.utils.funcdata.IList; +import bjc.utils.gui.layout.AutosizeLayout; +import bjc.utils.gui.layout.HLayout; + import java.awt.BorderLayout; import javax.swing.DefaultListModel; @@ -9,13 +13,9 @@ import javax.swing.JList; import javax.swing.JPanel; import javax.swing.ListSelectionModel; -import bjc.utils.funcdata.IList; -import bjc.utils.gui.layout.AutosizeLayout; -import bjc.utils.gui.layout.HLayout; - /** * A panel that allows you to select choices from a dropdown list - * + * * @author ben * */ @@ -24,7 +24,7 @@ public class DropdownListPanel extends JPanel { /** * Create a new dropdown list panel - * + * * @param <T> * The type of items in the dropdown list * @param type diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/FormattedInputPanel.java b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/FormattedInputPanel.java index ae62a43..877f308 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/FormattedInputPanel.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/FormattedInputPanel.java @@ -1,5 +1,7 @@ package bjc.utils.gui.panels; +import bjc.utils.gui.layout.HLayout; + import java.util.function.Consumer; import javax.swing.JFormattedTextField; @@ -7,11 +9,9 @@ import javax.swing.JFormattedTextField.AbstractFormatter; import javax.swing.JLabel; import javax.swing.JPanel; -import bjc.utils.gui.layout.HLayout; - /** * A simple panel allowing for input of a single formatted value - * + * * @author ben * * @param <InputVal> @@ -24,7 +24,7 @@ public class FormattedInputPanel<InputVal> extends JPanel { /** * Create a new formatted input panel - * + * * @param label * The label for this panel * @param length @@ -55,7 +55,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 */ diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/HolderOutputPanel.java b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/HolderOutputPanel.java index b6fc807..054eb38 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/HolderOutputPanel.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/HolderOutputPanel.java @@ -1,29 +1,29 @@ package bjc.utils.gui.panels; +import bjc.utils.data.IHolder; +import bjc.utils.gui.layout.HLayout; + import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.Timer; -import bjc.utils.data.IHolder; -import bjc.utils.gui.layout.HLayout; - /** * A panel that outputs a value bound to a {@link IHolder} - * + * * @author ben * */ public class HolderOutputPanel extends JPanel { private static final long serialVersionUID = 166573313903782080L; - private Timer updater; - private JLabel value; - private int nDelay; - private IHolder<String> val; + private Timer updater; + private JLabel value; + private int nDelay; + private IHolder<String> val; /** * Create a new display panel, backed by a holder - * + * * @param lab * The label to attach to this field * @param valueHolder diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/ListParameterPanel.java b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/ListParameterPanel.java index 29ede89..8f68571 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/ListParameterPanel.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/ListParameterPanel.java @@ -1,5 +1,10 @@ package bjc.utils.gui.panels; +import bjc.utils.funcdata.IList; +import bjc.utils.gui.SimpleJList; +import bjc.utils.gui.layout.HLayout; +import bjc.utils.gui.layout.VLayout; + import java.util.function.Consumer; import java.util.function.Supplier; @@ -9,14 +14,9 @@ import javax.swing.JList; import javax.swing.JPanel; import javax.swing.ListSelectionModel; -import bjc.utils.funcdata.IList; -import bjc.utils.gui.SimpleJList; -import bjc.utils.gui.layout.HLayout; -import bjc.utils.gui.layout.VLayout; - /** * A panel that has a list of objects and ways of manipulating that list - * + * * @author ben * * @param <E> @@ -28,7 +28,7 @@ public class ListParameterPanel<E> extends JPanel { /** * Create a new panel using the specified actions for doing things - * + * * @param add * The action that provides items * @param edit @@ -42,7 +42,7 @@ public class ListParameterPanel<E> extends JPanel { /** * Create a new panel using the specified actions for doing things - * + * * @param add * The action that provides items * @param edit @@ -57,7 +57,7 @@ public class ListParameterPanel<E> extends JPanel { JList<E> list; - if (defaults != null) { + if(defaults != null) { list = SimpleJList.buildFromList(defaults.toIterable()); } else { list = new JList<>(new DefaultListModel<>()); @@ -69,15 +69,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++; } @@ -85,7 +85,7 @@ public class ListParameterPanel<E> extends JPanel { JButton addParam = null; - if (add != null) { + if(add != null) { addParam = new JButton("Add..."); addParam.addActionListener((event) -> { DefaultListModel<E> model = (DefaultListModel<E>) list.getModel(); @@ -96,7 +96,7 @@ public class ListParameterPanel<E> extends JPanel { JButton editParam = null; - if (edit != null) { + if(edit != null) { editParam = new JButton("Edit..."); editParam.addActionListener((event) -> { edit.accept(list.getSelectedValue()); @@ -105,7 +105,7 @@ public class ListParameterPanel<E> extends JPanel { JButton removeParam = null; - if (remove != null) { + if(remove != null) { removeParam = new JButton("Remove..."); removeParam.addActionListener((event) -> { DefaultListModel<E> model = (DefaultListModel<E>) list.getModel(); @@ -114,15 +114,15 @@ public class ListParameterPanel<E> extends JPanel { }); } - 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/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleInputPanel.java b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleInputPanel.java index b90e25c..d0881c5 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleInputPanel.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleInputPanel.java @@ -8,7 +8,7 @@ import javax.swing.JTextField; /** * A simple component for text input - * + * * @author ben * */ @@ -22,7 +22,7 @@ public class SimpleInputPanel extends JPanel { /** * Create a new input panel - * + * * @param label * The label for the field * @param columns @@ -33,7 +33,7 @@ public class SimpleInputPanel extends JPanel { JLabel inputLabel = new JLabel(label); - if (columns < 1) { + if(columns < 1) { inputValue = new JTextField(); } else { inputValue = new JTextField(columns); diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleListPanel.java b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleListPanel.java index 11b209f..b4fcfe1 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleListPanel.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleListPanel.java @@ -1,5 +1,8 @@ package bjc.utils.gui.panels; +import bjc.utils.gui.layout.AutosizeLayout; +import bjc.utils.gui.layout.HLayout; + import java.awt.BorderLayout; import java.util.function.Consumer; import java.util.function.Predicate; @@ -12,12 +15,9 @@ import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.ListSelectionModel; -import bjc.utils.gui.layout.AutosizeLayout; -import bjc.utils.gui.layout.HLayout; - /** * A simple list of strings - * + * * @author ben * */ @@ -28,7 +28,7 @@ public class SimpleListPanel extends JPanel { Consumer<String> onFailure, JTextField addItemField) { String potentialItem = addItemField.getText(); - if (verifier == null || verifier.test(potentialItem)) { + if(verifier == null || verifier.test(potentialItem)) { model.addElement(potentialItem); } else { onFailure.accept(potentialItem); @@ -39,7 +39,7 @@ public class SimpleListPanel extends JPanel { /** * Create a new list panel - * + * * @param type * The type of things in the list * @param model diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleSpinnerPanel.java b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleSpinnerPanel.java index e9e94d5..a573bea 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleSpinnerPanel.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleSpinnerPanel.java @@ -9,7 +9,7 @@ import javax.swing.SpinnerModel; /** * A simple spinner control - * + * * @author ben * */ @@ -23,7 +23,7 @@ public class SimpleSpinnerPanel extends JPanel { /** * Create a new spinner panel - * + * * @param label * The label for the spinner * @param model diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SliderInputPanel.java b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SliderInputPanel.java index 53bff32..71eaf33 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SliderInputPanel.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SliderInputPanel.java @@ -1,5 +1,7 @@ package bjc.utils.gui.panels; +import bjc.utils.gui.layout.HLayout; + import java.text.ParseException; import java.util.function.Consumer; @@ -8,12 +10,10 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSlider; -import bjc.utils.gui.layout.HLayout; - /** * A simple input panel for a slider-controlled value and a manual-input field * for setting the slider - * + * * @author ben * */ @@ -21,8 +21,8 @@ public class SliderInputPanel extends JPanel { private final class NumberFormatter extends JFormattedTextField.AbstractFormatter { private static final long serialVersionUID = -4448291795913908270L; - private int minValue; - private int maxValue; + private int minValue; + private int maxValue; private int initValue; @@ -38,14 +38,13 @@ public class SliderInputPanel extends JPanel { try { 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 { + else return val; - } - } catch (NumberFormatException nfex) { + } catch(NumberFormatException nfex) { ParseException pex = new ParseException("Value must be a valid integer", 0); pex.initCause(nfex); @@ -56,9 +55,7 @@ public class SliderInputPanel extends JPanel { @Override public String valueToString(Object value) throws ParseException { - if (value == null) { - return Integer.toString(initValue); - } + if(value == null) return Integer.toString(initValue); return Integer.toString((Integer) value); } @@ -66,7 +63,7 @@ public class SliderInputPanel extends JPanel { /** * Represents the settings for a slider - * + * * @author ben * */ @@ -74,11 +71,11 @@ public class SliderInputPanel extends JPanel { /** * The minimum value of the slider */ - public final int minValue; + public final int minValue; /** * The maximum value of the slider */ - public final int maxValue; + public final int maxValue; /** * The initial value of the slider @@ -88,7 +85,7 @@ public class SliderInputPanel extends JPanel { /** * Create a new slider settings, with the initial value in the * middle - * + * * @param min * The minimum value of the slider * @param max @@ -100,7 +97,7 @@ public class SliderInputPanel extends JPanel { /** * Create a new set of slider sttings - * + * * @param min * The minimum slider value * @param max @@ -116,13 +113,13 @@ public class SliderInputPanel extends JPanel { } } - private static final long serialVersionUID = 2956394160569961404L; - private JSlider slider; - private JFormattedTextField field; + private static final long serialVersionUID = 2956394160569961404L; + private JSlider slider; + private JFormattedTextField field; /** * Create a new slider input panel - * + * * @param lab * The label for the field * @param settings @@ -149,7 +146,7 @@ public class SliderInputPanel extends JPanel { slider.setPaintLabels(true); slider.addChangeListener((event) -> { - if (slider.getValueIsAdjusting()) { + if(slider.getValueIsAdjusting()) { // Do nothing } else { int val = slider.getValue(); @@ -165,7 +162,7 @@ public class SliderInputPanel extends JPanel { field.addPropertyChangeListener("value", (event) -> { Object value = field.getValue(); - if (value == null) { + if(value == null) { // Do nothing } else { slider.setValue((Integer) value); @@ -179,7 +176,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 */ |
