diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2017-04-10 16:40:33 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2017-04-10 16:40:33 -0400 |
| commit | 889fac2bdf993dc86f64a8893c0260fdcf848acb (patch) | |
| tree | 99ed08552efa86fdc5fdf4ddb8720d10e599fafe /BJC-Utils2/src/main/java/bjc/utils/gui/panels | |
| parent | 1656b02144446aeedebb3d1179e07ed99c01861c (diff) | |
Cleanup
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/gui/panels')
8 files changed, 97 insertions, 96 deletions
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 6e6be02..4f71d38 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,9 +1,5 @@ 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; @@ -13,6 +9,10 @@ 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 * @@ -34,27 +34,27 @@ public class DropdownListPanel extends JPanel { * @param choices * The items to choose from */ - public <T> DropdownListPanel(String type, DefaultListModel<T> model, IList<T> choices) { + public <T> DropdownListPanel(final String type, final DefaultListModel<T> model, final IList<T> choices) { setLayout(new AutosizeLayout()); - JPanel itemInputPanel = new JPanel(); + final JPanel itemInputPanel = new JPanel(); itemInputPanel.setLayout(new BorderLayout()); - JPanel addItemPanel = new JPanel(); + final JPanel addItemPanel = new JPanel(); addItemPanel.setLayout(new HLayout(2)); - JComboBox<T> addItemBox = new JComboBox<>(); + final JComboBox<T> addItemBox = new JComboBox<>(); choices.forEach(addItemBox::addItem); - JButton addItemButton = new JButton("Add " + type); + final JButton addItemButton = new JButton("Add " + type); addItemPanel.add(addItemBox); addItemPanel.add(addItemButton); - JList<T> itemList = new JList<>(model); + final JList<T> itemList = new JList<>(model); itemList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - JButton removeItemButton = new JButton("Remove " + type); + final JButton removeItemButton = new JButton("Remove " + type); addItemButton.addActionListener((ev) -> { model.addElement(addItemBox.getItemAt(addItemBox.getSelectedIndex())); 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 877f308..2cecf0c 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,7 +1,5 @@ package bjc.utils.gui.panels; -import bjc.utils.gui.layout.HLayout; - import java.util.function.Consumer; import javax.swing.JFormattedTextField; @@ -9,6 +7,8 @@ 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 * @@ -20,7 +20,7 @@ import javax.swing.JPanel; public class FormattedInputPanel<InputVal> extends JPanel { private static final long serialVersionUID = 5232016563558588031L; - private JFormattedTextField field; + private final JFormattedTextField field; /** * Create a new formatted input panel @@ -35,10 +35,11 @@ public class FormattedInputPanel<InputVal> extends JPanel { * The action to call whenever the value changes */ @SuppressWarnings("unchecked") - public FormattedInputPanel(String label, int length, AbstractFormatter formatter, Consumer<InputVal> reciever) { + public FormattedInputPanel(final String label, final int length, final AbstractFormatter formatter, + final Consumer<InputVal> reciever) { setLayout(new HLayout(2)); - JLabel lab = new JLabel(label); + final JLabel lab = new JLabel(label); field = new JFormattedTextField(formatter); field.setColumns(length); @@ -59,7 +60,7 @@ public class FormattedInputPanel<InputVal> extends JPanel { * @param value * The value to set the panel to */ - public void resetValues(InputVal value) { + public void resetValues(final InputVal value) { field.setValue(value); } } 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 054eb38..653dace 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,12 +1,12 @@ 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} * @@ -16,10 +16,10 @@ import javax.swing.Timer; 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 final JLabel value; + private final int nDelay; + private final IHolder<String> val; /** * Create a new display panel, backed by a holder @@ -31,13 +31,13 @@ public class HolderOutputPanel extends JPanel { * @param nDelay * The delay in ms between value updates */ - public HolderOutputPanel(String lab, IHolder<String> valueHolder, int nDelay) { + public HolderOutputPanel(final String lab, final IHolder<String> valueHolder, final int nDelay) { this.val = valueHolder; this.nDelay = nDelay; setLayout(new HLayout(2)); - JLabel label = new JLabel(lab); + final JLabel label = new JLabel(lab); value = new JLabel("(stopped)"); updater = new Timer(nDelay, (event) -> { 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 8f68571..cca73d5 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,10 +1,5 @@ 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; @@ -14,6 +9,11 @@ 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 * @@ -36,7 +36,7 @@ public class ListParameterPanel<E> extends JPanel { * @param remove * The action that removes items */ - public ListParameterPanel(Supplier<E> add, Consumer<E> edit, Consumer<E> remove) { + public ListParameterPanel(final Supplier<E> add, final Consumer<E> edit, final Consumer<E> remove) { this(add, edit, remove, null); } @@ -52,12 +52,13 @@ public class ListParameterPanel<E> extends JPanel { * @param defaults * The default values to put in the list */ - public ListParameterPanel(Supplier<E> add, Consumer<E> edit, Consumer<E> remove, 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<>()); @@ -65,19 +66,19 @@ public class ListParameterPanel<E> extends JPanel { list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - JPanel buttonPanel = new JPanel(); + final JPanel buttonPanel = new 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,10 +86,10 @@ 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(); + final DefaultListModel<E> model = (DefaultListModel<E>) list.getModel(); model.addElement(add.get()); }); @@ -96,7 +97,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,24 +106,24 @@ 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(); + 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/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleInputPanel.java b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleInputPanel.java index d0881c5..65c533d 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 @@ -28,12 +28,12 @@ public class SimpleInputPanel extends JPanel { * @param columns * The number of columns of text input to take */ - public SimpleInputPanel(String label, int columns) { + public SimpleInputPanel(final String label, final int columns) { setLayout(new BorderLayout()); - JLabel inputLabel = new JLabel(label); + final 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 b4fcfe1..edc1797 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,8 +1,5 @@ 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; @@ -15,6 +12,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 * @@ -24,11 +24,11 @@ import javax.swing.ListSelectionModel; public class SimpleListPanel extends JPanel { private static final long serialVersionUID = 2719963952350133541L; - private static void addItem(DefaultListModel<String> model, Predicate<String> verifier, - Consumer<String> onFailure, JTextField addItemField) { - String potentialItem = addItemField.getText(); + 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); @@ -49,28 +49,28 @@ public class SimpleListPanel extends JPanel { * @param onFailure * The function to call when an item doesn't verify */ - public SimpleListPanel(String type, DefaultListModel<String> model, Predicate<String> verifier, - Consumer<String> onFailure) { + public SimpleListPanel(final String type, final DefaultListModel<String> model, + final Predicate<String> verifier, final Consumer<String> onFailure) { setLayout(new AutosizeLayout()); - JPanel itemInputPanel = new JPanel(); + final JPanel itemInputPanel = new JPanel(); itemInputPanel.setLayout(new BorderLayout()); - JPanel addItemPanel = new JPanel(); + final JPanel addItemPanel = new JPanel(); addItemPanel.setLayout(new HLayout(2)); - JTextField addItemField = new JTextField(255); - JButton addItemButton = new JButton("Add " + type); + final JTextField addItemField = new JTextField(255); + final JButton addItemButton = new JButton("Add " + type); addItemPanel.add(addItemField); addItemPanel.add(addItemButton); - JList<String> itemList = new JList<>(model); + final JList<String> itemList = new JList<>(model); itemList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - JScrollPane listScroller = new JScrollPane(itemList); + final JScrollPane listScroller = new JScrollPane(itemList); - JButton removeItemButton = new JButton("Remove " + type); + final JButton removeItemButton = new JButton("Remove " + type); addItemButton.addActionListener((ev) -> { addItem(model, verifier, onFailure, addItemField); 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 2b48adf..6106182 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 @@ -29,10 +29,10 @@ public class SimpleSpinnerPanel extends JPanel { * @param model * The model to attach to the spinner */ - public SimpleSpinnerPanel(String label, SpinnerModel model) { + public SimpleSpinnerPanel(final String label, final SpinnerModel model) { setLayout(new BorderLayout()); - JLabel inputLabel = new JLabel(label); + final JLabel inputLabel = new JLabel(label); inputValue = new JSpinner(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 71eaf33..e6a6da4 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,7 +1,5 @@ package bjc.utils.gui.panels; -import bjc.utils.gui.layout.HLayout; - import java.text.ParseException; import java.util.function.Consumer; @@ -10,6 +8,8 @@ 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 @@ -21,12 +21,12 @@ 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 final int minValue; + private final int maxValue; - private int initValue; + private final int initValue; - public NumberFormatter(SliderSettings settings) { + public NumberFormatter(final SliderSettings settings) { minValue = settings.minValue; maxValue = settings.maxValue; @@ -34,18 +34,17 @@ public class SliderInputPanel extends JPanel { } @Override - public Object stringToValue(String text) throws ParseException { + public Object stringToValue(final String text) throws ParseException { try { - int val = Integer.parseInt(text); + 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(NumberFormatException nfex) { - ParseException pex = new ParseException("Value must be a valid integer", 0); + else return val; + } catch (final NumberFormatException nfex) { + final ParseException pex = new ParseException("Value must be a valid integer", 0); pex.initCause(nfex); @@ -54,8 +53,8 @@ public class SliderInputPanel extends JPanel { } @Override - public String valueToString(Object value) throws ParseException { - if(value == null) return Integer.toString(initValue); + public String valueToString(final Object value) throws ParseException { + if (value == null) return Integer.toString(initValue); return Integer.toString((Integer) value); } @@ -91,7 +90,7 @@ public class SliderInputPanel extends JPanel { * @param max * The maximum value of the slider */ - public SliderSettings(int min, int max) { + public SliderSettings(final int min, final int max) { this(min, max, (min + max) / 2); } @@ -105,7 +104,7 @@ public class SliderInputPanel extends JPanel { * @param init * Th initial slider value */ - public SliderSettings(int min, int max, int init) { + public SliderSettings(final int min, final int max, final int init) { minValue = min; maxValue = max; @@ -113,9 +112,9 @@ public class SliderInputPanel extends JPanel { } } - private static final long serialVersionUID = 2956394160569961404L; - private JSlider slider; - private JFormattedTextField field; + private static final long serialVersionUID = 2956394160569961404L; + private final JSlider slider; + private final JFormattedTextField field; /** * Create a new slider input panel @@ -131,11 +130,11 @@ public class SliderInputPanel extends JPanel { * @param action * The action to execute for a given value */ - public SliderInputPanel(String lab, SliderSettings settings, int majorTick, int minorTick, - 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)); - JLabel label = new JLabel(lab); + final JLabel label = new JLabel(lab); slider = new JSlider(settings.minValue, settings.maxValue, settings.initValue); field = new JFormattedTextField(new NumberFormatter(settings)); @@ -146,10 +145,10 @@ public class SliderInputPanel extends JPanel { slider.setPaintLabels(true); slider.addChangeListener((event) -> { - if(slider.getValueIsAdjusting()) { + if (slider.getValueIsAdjusting()) { // Do nothing } else { - int val = slider.getValue(); + final int val = slider.getValue(); field.setValue(val); @@ -160,9 +159,9 @@ public class SliderInputPanel extends JPanel { field.setFocusLostBehavior(JFormattedTextField.COMMIT_OR_REVERT); field.setColumns(15); field.addPropertyChangeListener("value", (event) -> { - Object value = field.getValue(); + final Object value = field.getValue(); - if(value == null) { + if (value == null) { // Do nothing } else { slider.setValue((Integer) value); @@ -180,7 +179,7 @@ public class SliderInputPanel extends JPanel { * @param value * The value to reset the fields to */ - public void resetValues(int value) { + public void resetValues(final int value) { slider.setValue(value); field.setValue(value); |
