Skip to content
Snippets Groups Projects
Commit b7637929 authored by Daniel Schramm's avatar Daniel Schramm
Browse files

Misleading parameter replaced in the method signature

parent 2d77d1ff
No related branches found
No related tags found
No related merge requests found
...@@ -461,10 +461,11 @@ public class ControlPanelBuilder { ...@@ -461,10 +461,11 @@ public class ControlPanelBuilder {
public JTextField addSliderWithVal(int max, ActionListener inputAction) { public JTextField addSliderWithVal(int max, ActionListener inputAction) {
JSlider slider = addSlider(max); JSlider slider = addSlider(max);
IntValueRange range = max == -1 ? null : new IntValueRange(0, max); boolean percentageSlider = max == -1;
IntValueRange range = percentageSlider ? null : new IntValueRange(0, max);
JTextField inputField = addFormattedInputField(range, inputAction); JTextField inputField = addFormattedInputField(range, inputAction);
connectSliderWithTextField(slider, inputField, max); connectSliderWithTextField(slider, inputField, percentageSlider);
return inputField; return inputField;
} }
...@@ -483,10 +484,11 @@ public class ControlPanelBuilder { ...@@ -483,10 +484,11 @@ public class ControlPanelBuilder {
public JTextField addSliderButtonedWithVal(int max, double stepSize, ActionListener inputAction) { public JTextField addSliderButtonedWithVal(int max, double stepSize, ActionListener inputAction) {
JSlider slider = addSlider(max); JSlider slider = addSlider(max);
IntValueRange range = max == -1 ? null : new IntValueRange(0, max); boolean percentageSlider = max == -1;
IntValueRange range = percentageSlider ? null : new IntValueRange(0, max);
JTextField inputField = addFormattedInputFieldButtoned(range, stepSize, inputAction); JTextField inputField = addFormattedInputFieldButtoned(range, stepSize, inputAction);
connectSliderWithTextField(slider, inputField, max); connectSliderWithTextField(slider, inputField, percentageSlider);
return inputField; return inputField;
} }
...@@ -497,12 +499,15 @@ public class ControlPanelBuilder { ...@@ -497,12 +499,15 @@ public class ControlPanelBuilder {
* *
* @param slider Slider to be associated with the given text field. * @param slider Slider to be associated with the given text field.
* @param inputField Text field to be associated with the given slider. * @param inputField Text field to be associated with the given slider.
* @param max Max value of the slider (and the text field). * @param percentage If {@code true}, the slider is treated as a percentage slider
* If {@code -1}, then percentage slider is used with 100 as the max. value. * with 100 as the maximum value. The text field then treats
* the percentual values as <b>decimal</b> numbers from the interval [0,1].<br>
* If {@code false}, the slider works with <b>integer</b> values
* from the interval [0,{@code max}] and so does the text field.
*/ */
private void connectSliderWithTextField(JSlider slider, JTextField inputField, int max) { private void connectSliderWithTextField(JSlider slider, JTextField inputField, boolean percentage) {
slider.addChangeListener((ChangeEvent ce) -> { slider.addChangeListener((ChangeEvent ce) -> {
if (max == -1) { if (percentage) {
inputField.setText(doubleToStringLocale(slider.getValue() / 100.0)); inputField.setText(doubleToStringLocale(slider.getValue() / 100.0));
} else { } else {
inputField.setText(intToStringLocale(slider.getValue())); inputField.setText(intToStringLocale(slider.getValue()));
...@@ -544,7 +549,7 @@ public class ControlPanelBuilder { ...@@ -544,7 +549,7 @@ public class ControlPanelBuilder {
); );
inputField.addActionListener((ActionEvent ae) -> { inputField.addActionListener((ActionEvent ae) -> {
if (max == -1) { // percents in [0,1] if (percentage) { // percents in [0,1]
slider.setValue((int) (parseLocaleDouble(inputField) * 100)); slider.setValue((int) (parseLocaleDouble(inputField) * 100));
} else { // integers } else { // integers
slider.setValue(parseLocaleInt(inputField)); slider.setValue(parseLocaleInt(inputField));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment