diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-03-31 11:43:21 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-03-31 11:43:21 -0400 |
| commit | 8a8b457c98e207d809a7616e73eb59bfe197a7a5 (patch) | |
| tree | 36fcbb7f10e92adbfb866fced7f27af1ef89f636 /BJC-Utils2/src/main/java/bjc/utils/gui | |
| parent | 32b1b46fcc855fffe6b0dddd10442a9a4f1544d2 (diff) | |
More code maintenance
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/gui')
11 files changed, 132 insertions, 141 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 7212e61..be1746f 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/ExtensionFileFilter.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/ExtensionFileFilter.java @@ -42,8 +42,8 @@ public class ExtensionFileFilter extends FileFilter { public ExtensionFileFilter(String... exts) { extensions = new FunctionalList<>(new ArrayList<>(exts.length)); - for (String ext : exts) { - extensions.add(ext); + for (String extension : exts) { + extensions.add(extension); } } @@ -56,5 +56,4 @@ public class ExtensionFileFilter extends FileFilter { public String getDescription() { return extensions.toString(); } - -} +}
\ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/ListParameterPanel.java b/BJC-Utils2/src/main/java/bjc/utils/gui/ListParameterPanel.java index 6272b5f..42c5761 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/ListParameterPanel.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/ListParameterPanel.java @@ -22,46 +22,45 @@ import bjc.utils.gui.layout.VLayout; * The type of data stored in the list */ public class ListParameterPanel<E> extends JPanel { - /** - * Version id for serialization - */ + // Version id for serialization private static final long serialVersionUID = 3442971104975491571L; /** * Create a new panel using the specified actions for doing things * - * @param addAct + * @param addAction * The action that provides items - * @param editAct + * @param editAction * The action that edits items - * @param removeAct + * @param removeAction * The action that removes items */ - public ListParameterPanel(Supplier<E> addAct, Consumer<E> editAct, - Consumer<E> removeAct) { - this(addAct, editAct, removeAct, null); + public ListParameterPanel(Supplier<E> addAction, + Consumer<E> editAction, Consumer<E> removeAction) { + this(addAction, editAction, removeAction, null); } /** * Create a new panel using the specified actions for doing things * - * @param addAct + * @param addAction * The action that provides items - * @param editAct + * @param editAction * The action that edits items - * @param removeAct + * @param removeAction * The action that removes items - * @param defVals + * @param defaultValues * The default values to put in the list */ - public ListParameterPanel(Supplier<E> addAct, Consumer<E> editAct, - Consumer<E> removeAct, FunctionalList<E> defVals) { + public ListParameterPanel(Supplier<E> addAction, + Consumer<E> editAction, Consumer<E> removeAction, + FunctionalList<E> defaultValues) { setLayout(new VLayout(2)); JList<E> list; - if (defVals != null) { - list = SimpleJList.buildFromList(defVals.toIterable()); + if (defaultValues != null) { + list = SimpleJList.buildFromList(defaultValues.toIterable()); } else { list = new JList<>(new DefaultListModel<>()); } @@ -76,11 +75,11 @@ public class ListParameterPanel<E> extends JPanel { JButton removeParam = new JButton("Remove..."); addParam.addActionListener( - (ev) -> ((DefaultListModel<E>) list.getModel()) - .addElement(addAct.get())); + (event) -> ((DefaultListModel<E>) list.getModel()) + .addElement(addAction.get())); editParam.addActionListener( - (ev) -> editAct.accept(list.getSelectedValue())); - removeParam.addActionListener((ev) -> removeAct + (event) -> editAction.accept(list.getSelectedValue())); + removeParam.addActionListener((event) -> removeAction .accept(((DefaultListModel<E>) list.getModel()) .remove(list.getSelectedIndex()))); 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 c85a86e..fd7d05a 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java @@ -30,22 +30,22 @@ public class SimpleDialogs { * The title for the dialogs. * @param prompt * The prompt to tell the user what to enter. - * @param lower + * @param lowerBound * The lower integer bound to accept. - * @param upper + * @param upperBound * The upper integer bound to accept. * @return A int within the specified bounds. */ public static int getBoundedInt(Component parent, String title, - String prompt, int lower, int upper) { - return getValue(parent, title, prompt, s -> { + String prompt, int lowerBound, int upperBound) { + return getValue(parent, title, prompt, strang -> { try { - int n = Integer.parseInt(s); - return (n < upper) && (n > lower); + int value = Integer.parseInt(strang); + return (value < upperBound) && (value > lowerBound); } catch (NumberFormatException nfe) { return false; } - } , Integer::parseInt); + }, Integer::parseInt); } /** @@ -67,8 +67,8 @@ public class SimpleDialogs { @SuppressWarnings("unchecked") public static <E> E getChoice(Frame parent, String title, String question, E... choices) { - JDialog jd = new JDialog(parent, title, true); - jd.setLayout(new VLayout(2)); + JDialog mainDialog = new JDialog(parent, title, true); + mainDialog.setLayout(new VLayout(2)); JPanel questionPane = new JPanel(); @@ -83,17 +83,17 @@ public class SimpleDialogs { JButton okButton = new JButton("Ok"); JButton cancelButton = new JButton("Cancel"); - okButton.addActionListener(e -> jd.dispose()); - cancelButton.addActionListener(e -> jd.dispose()); + okButton.addActionListener((event) -> mainDialog.dispose()); + cancelButton.addActionListener((event) -> mainDialog.dispose()); buttonPane.add(cancelButton); buttonPane.add(okButton); - jd.add(questionPane); - jd.add(buttonPane); + mainDialog.add(questionPane); + mainDialog.add(buttonPane); - jd.pack(); - jd.setVisible(true); + mainDialog.pack(); + mainDialog.setVisible(true); return (E) questionChoices.getSelectedItem(); } @@ -111,14 +111,14 @@ public class SimpleDialogs { */ public static int getInt(Component parent, String title, String prompt) { - return getValue(parent, title, prompt, s -> { + return getValue(parent, title, prompt, strang -> { try { - Integer.parseInt(s); + Integer.parseInt(strang); return true; } catch (NumberFormatException nfe) { return false; } - } , Integer::parseInt); + }, Integer::parseInt); } /** @@ -150,23 +150,24 @@ public class SimpleDialogs { * The title for dialogs. * @param prompt * The prompt to tell the user what to enter. - * @param p + * @param inputValidator * A predicate to determine if a input is valid. - * @param f + * @param inputTransformer * The function to transform the string into a value. * @return The value parsed from a string. */ public static <E> E getValue(Component parent, String title, - String prompt, Predicate<String> p, Function<String, E> f) { - String inp = getString(parent, title, prompt); + String prompt, Predicate<String> inputValidator, + Function<String, E> inputTransformer) { + String inputString = getString(parent, title, prompt); - while (!p.test(inp)) { + while (!inputValidator.test(inputString)) { showError(parent, "I/O Error", "Please enter a valid value"); - inp = getString(parent, title, prompt); + inputString = getString(parent, title, prompt); } - return f.apply(inp); + return inputTransformer.apply(inputString); } /** @@ -198,10 +199,10 @@ public class SimpleDialogs { */ public static boolean getYesNo(Component parent, String title, String question) { - int res = JOptionPane.showConfirmDialog(parent, question, title, - JOptionPane.YES_NO_OPTION); + int dialogResult = JOptionPane.showConfirmDialog(parent, question, + title, JOptionPane.YES_NO_OPTION); - return (res == JOptionPane.YES_OPTION ? true : false); + return (dialogResult == JOptionPane.YES_OPTION ? true : false); } /** @@ -211,12 +212,12 @@ public class SimpleDialogs { * The parent component for dialogs. * @param title * The title for dialogs. - * @param err + * @param errorMessage * The error to show the user. */ public static void showError(Component parent, String title, - String err) { - JOptionPane.showMessageDialog(parent, err, title, + String errorMessage) { + JOptionPane.showMessageDialog(parent, errorMessage, title, JOptionPane.ERROR_MESSAGE); } -} +}
\ No newline at end of file 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 39d944b..9648762 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleFileChooser.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleFileChooser.java @@ -16,7 +16,7 @@ import bjc.utils.exceptions.FileNotChosenException; * */ public class SimpleFileChooser { - private static File doOpenFile(Component par, String title, + private static File doOpenFile(Component parent, String title, JFileChooser files) { files.setDialogTitle(title); @@ -24,11 +24,11 @@ public class SimpleFileChooser { while (!success) { try { - maybeDoOpenFile(par, files); + maybeDoOpenFile(parent, files); success = true; } catch (FileNotChosenException e) { - SimpleDialogs.showError(par, "I/O Error", + SimpleDialogs.showError(parent, "I/O Error", "Please pick a file to open"); } } @@ -36,7 +36,7 @@ public class SimpleFileChooser { return files.getSelectedFile(); } - private static File doSaveFile(Component par, String title, + private static File doSaveFile(Component parent, String title, JFileChooser files) { files.setDialogTitle(title); @@ -44,11 +44,11 @@ public class SimpleFileChooser { while (!success) { try { - maybeDoSaveFile(par, files); + maybeDoSaveFile(parent, files); return files.getSelectedFile(); } catch (FileNotChosenException e) { - SimpleDialogs.showError(par, "I/O Error", + SimpleDialogs.showError(parent, "I/O Error", "Please pick a file to save to"); } } @@ -60,23 +60,23 @@ public class SimpleFileChooser { * Prompt the user with a "Open File..." dialog. Keeps prompting them * until they pick a file. * - * @param par + * @param parent * The component to use as the parent for the dialog. * @param title * The title of the dialog to prompt with. * @return The file the user has chosen. */ - public static File getOpenFile(Component par, String title) { + public static File getOpenFile(Component parent, String title) { JFileChooser files = new JFileChooser(); - return doOpenFile(par, title, files); + return doOpenFile(parent, title, files); } /** * Prompt the user with a "Open File..." dialog. Keeps prompting them * until they pick a file. * - * @param par + * @param parent * The component to use as the parent for the dialog. * @param title * The title of the dialog to prompt with. @@ -84,33 +84,33 @@ public class SimpleFileChooser { * The list of file extensions the file should have. * @return The file the user has chosen. */ - public static File getOpenFile(Component par, String title, + public static File getOpenFile(Component parent, String title, String... extensions) { JFileChooser files = new JFileChooser(); files.addChoosableFileFilter(new ExtensionFileFilter(extensions)); - return doOpenFile(par, title, files); + return doOpenFile(parent, title, files); } /** * Prompt the user with a "Save File..." dialog. * - * @param par + * @param parent * The component to use as the parent for the dialog. * @param title * The title of the dialog to prompt with. * @return The file the user chose. */ - public static File getSaveFile(Component par, String title) { + public static File getSaveFile(Component parent, String title) { JFileChooser files = new JFileChooser(); - return doSaveFile(par, title, files); + return doSaveFile(parent, title, files); } /** * Prompt the user with a "Save File..." dialog. * - * @param par + * @param parent * The component to use as the parent for the dialog. * @param title * The title of the dialog to prompt with. @@ -118,30 +118,28 @@ public class SimpleFileChooser { * The extensions of the files the user can choose. * @return The file the user chose. */ - public static File getSaveFile(Component par, String title, + public static File getSaveFile(Component parent, String title, String... extensions) { JFileChooser files = new JFileChooser(); files.addChoosableFileFilter(new ExtensionFileFilter(extensions)); - return doSaveFile(par, title, files); + return doSaveFile(parent, title, files); } - private static void maybeDoOpenFile(Component par, JFileChooser files) - throws FileNotChosenException { - int res = files.showSaveDialog(par); + private static void maybeDoOpenFile(Component parent, + JFileChooser files) throws FileNotChosenException { + int dialogResult = files.showSaveDialog(parent); - if (res != JFileChooser.APPROVE_OPTION) { + if (dialogResult != JFileChooser.APPROVE_OPTION) { throw new FileNotChosenException(); } } - private static void maybeDoSaveFile(Component par, JFileChooser files) - throws FileNotChosenException { - int res = files.showSaveDialog(par); + private static void maybeDoSaveFile(Component parent, + JFileChooser files) throws FileNotChosenException { + int dialogResult = files.showSaveDialog(parent); - System.out.println("Result: " + res); - - if (res != JFileChooser.APPROVE_OPTION) { + if (dialogResult != JFileChooser.APPROVE_OPTION) { throw new FileNotChosenException(); } } @@ -149,18 +147,18 @@ public class SimpleFileChooser { /** * Prompt the user with a "Open File..." dialog. * - * @param par + * @param parent * The component to use as the parent for the dialog. * @param title * 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(Component par, String title) { + public static File maybeOpenFile(Component parent, String title) { JFileChooser files = new JFileChooser(); files.setDialogTitle(title); try { - maybeDoOpenFile(par, files); + maybeDoOpenFile(parent, files); } catch (FileNotChosenException e) { } @@ -170,18 +168,18 @@ public class SimpleFileChooser { /** * Prompt the user with a "Save File..." dialog. * - * @param par + * @param parent * The component to use as the parent for the dialog. * @param title * 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(Component par, String title) { + public static File maybeSaveFile(Component parent, String title) { JFileChooser files = new JFileChooser(); files.setDialogTitle(title); try { - maybeDoSaveFile(par, files); + maybeDoSaveFile(parent, files); } catch (FileNotChosenException e) { } 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 614cf33..4695318 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleJList.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleJList.java @@ -17,12 +17,12 @@ public class SimpleJList { * @param <E> * The type of data in the JList * - * @param ls + * @param listSource * The list to populate the JList with. * @return A JList populated with the elements from ls. */ - public static <E> JList<E> buildFromList(Iterable<E> ls) { - return new JList<>(buildModel(ls)); + public static <E> JList<E> buildFromList(Iterable<E> listSource) { + return new JList<>(buildModel(listSource)); } /** @@ -31,15 +31,15 @@ public class SimpleJList { * @param <E> * The type of data in the list model * - * @param ls + * @param listSource * 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> ls) { - DefaultListModel<E> dlm = new DefaultListModel<>(); + public static <E> ListModel<E> buildModel(Iterable<E> listSource) { + DefaultListModel<E> defaultModel = new DefaultListModel<>(); - ls.forEach(dlm::addElement); + listSource.forEach(defaultModel::addElement); - return dlm; + return defaultModel; } } 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 9c6feef..ddf5492 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleTitledBorder.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleTitledBorder.java @@ -10,9 +10,7 @@ import javax.swing.border.TitledBorder; * */ public class SimpleTitledBorder extends TitledBorder { - /** - * Version ID for serialization - */ + // Version ID for serialization private static final long serialVersionUID = -5655969079949148487L; /** 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 6f43ba9..368f8be 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 @@ -42,13 +42,13 @@ public class ExtensionFileFilter implements FilenameFilter { public ExtensionFileFilter(String... exts) { extensions = new FunctionalList<>(new ArrayList<>(exts.length)); - for (String ext : exts) { - extensions.add(ext); + for (String extension : exts) { + extensions.add(extension); } } @Override - public boolean accept(File dir, String name) { + public boolean accept(File directory, String name) { return extensions.anyMatch(name::endsWith); } }
\ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/awt/SimpleFileDialog.java b/BJC-Utils2/src/main/java/bjc/utils/gui/awt/SimpleFileDialog.java index c12119f..a8df3b9 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 @@ -19,20 +19,20 @@ public class SimpleFileDialog { /** * Prompt the user to pick a file to open * - * @param par + * @param parent * The parent of the file picker * @param title * The title of the file picker * @return The file the user picked */ - public static File getOpenFile(Frame par, String title) { - return getOpenFile(par, title, (String[]) null); + public static File getOpenFile(Frame parent, String title) { + return getOpenFile(parent, title, (String[]) null); } /** * Prompt the user to pick a file to open * - * @param par + * @param parent * The parent of the file picker * @param title * The title of the file picker @@ -40,43 +40,44 @@ public class SimpleFileDialog { * The extensions to accept as valid * @return The file the user picked */ - public static File getOpenFile(Frame par, String title, + public static File getOpenFile(Frame parent, String title, String... extensions) { - FileDialog fd = new FileDialog(par, title, FileDialog.LOAD); + FileDialog fileDialog = + new FileDialog(parent, title, FileDialog.LOAD); if (extensions != null) { FilenameFilter filter = new ExtensionFileFilter(extensions); - fd.setFilenameFilter(filter); + fileDialog.setFilenameFilter(filter); } - fd.setVisible(true); + fileDialog.setVisible(true); - while (fd.getFile() == null) { - SimpleDialogs.showError(par, "File I/O Error", + while (fileDialog.getFile() == null) { + SimpleDialogs.showError(parent, "File I/O Error", "Please choose a file to open."); - fd.setVisible(true); + fileDialog.setVisible(true); } - return fd.getFiles()[0]; + return fileDialog.getFiles()[0]; } /** * Prompt the user to pick a file to save * - * @param par + * @param parent * The parent of the file picker * @param title * The title of the file picker * @return The file the user picked */ - public static File getSaveFile(Frame par, String title) { - return getSaveFile(par, title, (String[]) null); + public static File getSaveFile(Frame parent, String title) { + return getSaveFile(parent, title, (String[]) null); } /** * Prompt the user to pick a file to save * - * @param par + * @param parent * The parent of the file picker * @param title * The title of the file picker @@ -84,23 +85,24 @@ public class SimpleFileDialog { * The extensions to accept as valid * @return The file the user picked */ - public static File getSaveFile(Frame par, String title, + public static File getSaveFile(Frame parent, String title, String... extensions) { - FileDialog fd = new FileDialog(par, title, FileDialog.SAVE); + FileDialog fileDialog = + new FileDialog(parent, title, FileDialog.SAVE); if (extensions != null) { FilenameFilter filter = new ExtensionFileFilter(extensions); - fd.setFilenameFilter(filter); + fileDialog.setFilenameFilter(filter); } - fd.setVisible(true); + fileDialog.setVisible(true); - while (fd.getFile() == null) { - SimpleDialogs.showError(par, "File I/O Error", + while (fileDialog.getFile() == null) { + SimpleDialogs.showError(parent, "File I/O Error", "Please choose a file to save to."); - fd.setVisible(true); + fileDialog.setVisible(true); } - return fd.getFiles()[0]; + return fileDialog.getFiles()[0]; } } 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 0130eee..d8a60ed 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 @@ -10,9 +10,7 @@ import java.awt.GridLayout; * */ public class AutosizeLayout extends GridLayout { - /** - * Version id for serialization - */ + // Version id for serialization private static final long serialVersionUID = -2495693595953396924L; /** 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 83b3793..c986310 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 @@ -10,18 +10,16 @@ import java.awt.GridLayout; * */ public class HLayout extends GridLayout { - /** - * Version id for serialization - */ + // Version ID for serialization private static final long serialVersionUID = 1244964456966270026L; /** * Create a new horizontal layout with the specified number of columns. * - * @param cols + * @param columns * The number of columns in this layout. */ - public HLayout(int cols) { - super(1, cols); + public HLayout(int columns) { + super(1, columns); } } 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 23ab61e..5951ba5 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 @@ -10,9 +10,7 @@ import java.awt.GridLayout; * */ public class VLayout extends GridLayout { - /** - * Version id for serialization - */ + // Version ID for serializations private static final long serialVersionUID = -6417962941602322663L; /** |
