From d4ca769e542b2489b1e23cfcbdc3a0b7275b87cd Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Mon, 13 Apr 2020 18:40:41 -0400 Subject: Cleanup pass Cleanup pass to uniformize things --- .../bjc/utils/gui/panels/DropdownListPanel.java | 15 +++---- .../bjc/utils/gui/panels/FormattedInputPanel.java | 18 ++++---- .../bjc/utils/gui/panels/HolderOutputPanel.java | 13 +++--- .../bjc/utils/gui/panels/ListParameterPanel.java | 49 +++++++++++----------- .../bjc/utils/gui/panels/SimpleInputPanel.java | 6 +-- .../java/bjc/utils/gui/panels/SimpleListPanel.java | 21 +++++----- .../bjc/utils/gui/panels/SimpleSpinnerPanel.java | 4 +- .../bjc/utils/gui/panels/SliderInputPanel.java | 49 +++++++++++----------- 8 files changed, 90 insertions(+), 85 deletions(-) (limited to 'base/src/main/java/bjc/utils/gui/panels') 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 - * 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 DropdownListPanel(final String type, final DefaultListModel model, final IList choices) { + public DropdownListPanel(final String type, final DefaultListModel model, + final IList 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 - * The type of value being formatted + * The type of value being formatted */ public class FormattedInputPanel extends JPanel { private static final long serialVersionUID = 5232016563558588031L; @@ -26,17 +26,17 @@ public class FormattedInputPanel 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 reciever) { + public FormattedInputPanel(final String label, final int length, + final AbstractFormatter formatter, final Consumer reciever) { setLayout(new HLayout(2)); final JLabel lab = new JLabel(label); @@ -44,7 +44,7 @@ public class FormattedInputPanel 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 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 valueHolder, final int nDelay) { + public HolderOutputPanel(final String lab, final IHolder 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 - * The type of data stored in the list + * The type of data stored in the list */ public class ListParameterPanel extends JPanel { // Version id for serialization @@ -30,13 +30,14 @@ public class ListParameterPanel 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 add, final Consumer edit, final Consumer remove) { + public ListParameterPanel(final Supplier add, final Consumer edit, + final Consumer remove) { this(add, edit, remove, null); } @@ -44,21 +45,21 @@ public class ListParameterPanel 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 add, final Consumer edit, final Consumer remove, - final IList defaults) { + public ListParameterPanel(final Supplier add, final Consumer edit, + final Consumer remove, final IList defaults) { setLayout(new VLayout(2)); JList 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 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 extends JPanel { JButton addParam = null; - if(add != null) { + if (add != null) { addParam = new JButton("Add..."); - addParam.addActionListener((event) -> { + addParam.addActionListener(event -> { final DefaultListModel model = (DefaultListModel) list.getModel(); model.addElement(add.get()); @@ -97,33 +98,33 @@ public class ListParameterPanel 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 model = (DefaultListModel) 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 model, final Predicate verifier, - final Consumer onFailure, final JTextField addItemField) { + private static void addItem(final DefaultListModel model, + final Predicate verifier, final Consumer 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 model, final Predicate verifier, final Consumer 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 action) { + public SliderInputPanel(final String lab, final SliderSettings settings, + final int majorTick, final int minorTick, final Consumer 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); -- cgit v1.2.3