Commit 2d77d1ff authored by Daniel Schramm's avatar Daniel Schramm
Browse files

Javadoc added

parent a314b781
Loading
Loading
Loading
Loading
+97 −29
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import javax.swing.text.NumberFormatter;
 * Builder for control panels. Layout is based on GridBagLayout. 
 * 
 * @author Radek Oslejsek
 * @author Daniel Schramm
 */
public class ControlPanelBuilder {
    
@@ -75,7 +76,7 @@ public class ControlPanelBuilder {
    
    /**
     * Helper method that parses and returns integer from the input field taking
     * Local into consideration.
     * Locale into consideration.
     * 
     * @param inputField The input field
     * @return Integer or 0
@@ -92,7 +93,7 @@ public class ControlPanelBuilder {
    
    /**
     * Helper method that parses and returns floating point number from the input field 
     * takingLocale into consideration Locale.
     * taking Locale into consideration.
     * 
     * @param inputField The input field
     * @return Double or 0.0
@@ -108,7 +109,8 @@ public class ControlPanelBuilder {
    }
    
    /**
     * Converts number into the text taking into account Locale
     * Converts number into the text taking into account Locale.
     * 
     * @param value Number
     * @return Text representation of given number
     */
@@ -117,7 +119,8 @@ public class ControlPanelBuilder {
    }
    
    /**
     * Converts number into the text taking into account Locale
     * Converts number into the text taking into account Locale.
     * 
     * @param value Number
     * @return Text representation of given number
     */
@@ -180,11 +183,13 @@ public class ControlPanelBuilder {
    /**
     * Adds a line with slider option.
     * 
     * @param helpAction Action listener invoked when the help icon is clicked. If {@code null}, then no help is shown.
     * @param helpAction Action listener invoked when the help icon is clicked.
     *                   If {@code null}, then no help is shown.
     * @param text Option text.
     * @param sliderMax Max value of the slider (and the value field). If {@code -1}, then percentage slider is shown with 100 as the max. value.
     * @param inputAction Action listener invoked when the input field is changed
     * @return Creates slider
     * @param sliderMax Max value of the slider (and the value field).
     *                  If {@code -1}, then percentage slider is shown with 100 as the max. value.
     * @param inputAction Action listener invoked when the value is changed.
     * @return Text field associated with the slider
     */
    public JTextField addSliderOptionLine(ActionListener helpAction, String text, int sliderMax, ActionListener inputAction) {
        if (helpAction != null) {
@@ -197,7 +202,21 @@ public class ControlPanelBuilder {
        return addSliderWithVal(sliderMax, inputAction);
    }
    
    public JTextField addSliderButtonedOptionLine(ActionListener helpAction, String text, int sliderMax, double step, ActionListener inputAction) {
    /**
     * Adds a line with slider with buttons option.
     * 
     * @param helpAction Action listener invoked when the help icon is clicked.
     *                   If {@code null}, then no help is shown.
     * @param text Option text.
     * @param sliderMax Max value of the slider (and the value field).
     *                  If {@code -1}, then percentage slider is shown with 100 as the max. value.
     * @param stepSize Size of an increment/decrement of the slider value on a plus/minus button click.
     *                 If the {@code stepSize} is negative, the step size will be set to 1
     *                 (or 1 % in case of a percentage slider).
     * @param inputAction Action listener invoked when the value is changed.
     * @return Text field associated with the slider
     */
    public JTextField addSliderButtonedOptionLine(ActionListener helpAction, String text, int sliderMax, double stepSize, ActionListener inputAction) {
        if (helpAction != null) {
            addOptionHelpIcon(helpAction);
        } else {
@@ -205,13 +224,14 @@ public class ControlPanelBuilder {
        }
        addOptionText((text == null) ? "" : text);
        
        return addSliderButtonedWithVal(sliderMax, step, inputAction);
        return addSliderButtonedWithVal(sliderMax, stepSize, inputAction);
    }
    
    /**
     * Adds a line with a checkbox option.
     * 
     * @param helpAction Action listener invoked when the help icon is clicked. If {@code null}, then no help is shown.
     * @param helpAction Action listener invoked when the help icon is clicked.
     *                   If {@code null}, then no help is shown.
     * @param text Option text.
     * @param selected Initial state of the checkbox.
     * @param checkBoxAction Action listener invoked when the check box is clicked.
@@ -245,7 +265,7 @@ public class ControlPanelBuilder {
     * 
     * @param buttons Labels.
     * @param actions Action listener invoked when the corresponding button is clicked.
     * @return This builder
     * @return List of new buttons
     * @throws IllegalArgumentException if the size of the two lists is different
     */
    public List<JButton> addButtons(List<String> buttons, List<ActionListener> actions) {
@@ -306,10 +326,11 @@ public class ControlPanelBuilder {
    }
    
    /**
     * Adds a combo box
     * Adds a combo box.
     * 
     * @param items Items
     * @param action Action listener invoked when some item is selected
     * @return 
     * @return This new GUI object
     */
    public JComboBox addComboBox(List<String> items, ActionListener action) {
        GridBagConstraints c = new GridBagConstraints();
@@ -329,7 +350,7 @@ public class ControlPanelBuilder {
    }
    
    /**
     * Adds a horizontal strut that moves upper lines to the top of the panel
     * Adds a horizontal strut that moves upper lines to the top of the panel.
     */
    public void addVerticalStrut() {
        GridBagConstraints c = new GridBagConstraints();
@@ -343,7 +364,7 @@ public class ControlPanelBuilder {
    }
    
    /**
     * Adds a gap occupying given number of grid cells
     * Adds a gap occupying given number of grid cells.
     */
    public void addGap() {
        GridBagConstraints c = new GridBagConstraints();
@@ -361,7 +382,7 @@ public class ControlPanelBuilder {
     * 
     * @param selected Initial state
     * @param action Action listener invoked when the checkbox is clicked.
     * @return This builder
     * @return This new GUI object
     */
    public JCheckBox addCheckBox(boolean selected, ActionListener action) {
        GridBagConstraints c = new GridBagConstraints();
@@ -384,7 +405,7 @@ public class ControlPanelBuilder {
     * Adds a help icon.
     * 
     * @param action Action listener invoked when the icon is clicked.
     * @return This builder
     * @return This new GUI object
     */
    public JButton addOptionHelpIcon(ActionListener action) {
        GridBagConstraints c = new GridBagConstraints();
@@ -409,7 +430,7 @@ public class ControlPanelBuilder {
     * Adds a text of the option.
     * 
     * @param text Text.
     * @return This builder
     * @return This new GUI object
     */
    public JLabel addOptionText(String text) {
        GridBagConstraints c = new GridBagConstraints();
@@ -430,11 +451,12 @@ public class ControlPanelBuilder {
    }
    
    /**
     * Adds a slider and connects it with given input field
     * Adds a slider associated with a text field.
     * 
     * @param max Max value of the slider (and the value field). If {@code -1}, then percentage slider is shown with 100 as the max. value.
     * @param inputField Input field connected with the slider.
     * @return This builder
     * @param max Max value of the slider (and the value field).
     *            If {@code -1}, then percentage slider is shown with 100 as the max. value.
     * @param inputAction Action listener invoked when the value is changed.
     * @return Text field associated with the slider
     */
    public JTextField addSliderWithVal(int max, ActionListener inputAction) {
        JSlider slider = addSlider(max);
@@ -442,23 +464,43 @@ public class ControlPanelBuilder {
        IntValueRange range = max == -1 ? null : new IntValueRange(0, max);
        JTextField inputField = addFormattedInputField(range, inputAction);
        
        connectSliderWithTextField(slider, max, inputField);
        connectSliderWithTextField(slider, inputField, max);
        
        return inputField;
    }
    
    public JTextField addSliderButtonedWithVal(int max, double step, ActionListener inputAction) {
    /**
     * Adds a slider associated with a text field with buttons.
     * 
     * @param max Max value of the slider (and the value field).
     *            If {@code -1}, then percentage slider is shown with 100 as the max. value.
     * @param stepSize Size of an increment/decrement of the slider value on a plus/minus button click.
     *                 If the {@code stepSize} is negative, the step size will be set to 1
     *                 (or 1 % in case of a percentage slider).
     * @param inputAction Action listener invoked when the value is changed.
     * @return Text field associated with the slider
     */
    public JTextField addSliderButtonedWithVal(int max, double stepSize, ActionListener inputAction) {
        JSlider slider = addSlider(max);
        
        IntValueRange range = max == -1 ? null : new IntValueRange(0, max);
        JTextField inputField = addFormattedInputFieldButtoned(range, step, inputAction);
        JTextField inputField = addFormattedInputFieldButtoned(range, stepSize, inputAction);
        
        connectSliderWithTextField(slider, max, inputField);
        connectSliderWithTextField(slider, inputField, max);
        
        return inputField;
    }
    
    private void connectSliderWithTextField(JSlider slider, int max, JTextField inputField) {
    /**
     * Associates slider with the given text field and links the slider's listeners
     * to the listeners of the text field and vice versa.
     * 
     * @param slider Slider to be associated with the given text field.
     * @param inputField Text field to be associated with the given slider.
     * @param max Max value of the slider (and the text field).
     *            If {@code -1}, then percentage slider is used with 100 as the max. value.
     */
    private void connectSliderWithTextField(JSlider slider, JTextField inputField, int max) {
        slider.addChangeListener((ChangeEvent ce) -> {
            if (max == -1) {
                inputField.setText(doubleToStringLocale(slider.getValue() / 100.0));
@@ -510,6 +552,13 @@ public class ControlPanelBuilder {
        });
    }
    
    /**
     * Adds a slider.
     * 
     * @param max Max value of the slider.
     *            If {@code -1}, then percentage slider is shown with 100 as the max. value.
     * @return This new GUI object
     */
    public JSlider addSlider(int max) {
        GridBagConstraints c = new GridBagConstraints();
        c.gridwidth = SLIDER_WIDTH;
@@ -532,6 +581,18 @@ public class ControlPanelBuilder {
        return slider;
    }
    
    /**
     * Adds a formatted text field with buttons that accepts either integer
     * or percentage (decimal) input values.
     * 
     * @param range Interval defining the range of integers that are accepted as an input value.
     *              If {@code null}, then decimal percentage values between 0.0 and 1.0 are accepted.
     * @param stepSize Size of an increment/decrement of the text field value on a plus/minus button click.
     *                 If the {@code stepSize} is negative, the step size will be set to 1
     *                 (or 1 % in case of a percentage text field).
     * @param inputAction Action listener invoked when the value is changed.
     * @return This new GUI object
     */
    public JFormattedTextField addFormattedInputFieldButtoned(IntValueRange range, double stepSize, ActionListener inputAction) {
        GridBagConstraints c = new GridBagConstraints();
        c.gridwidth = 1;
@@ -599,6 +660,14 @@ public class ControlPanelBuilder {
        return inputField;
    }
    
    /**
     * Adds a formatted text field that accepts either integer or percentage (decimal) input values.
     * 
     * @param range Interval defining the range of integers that are accepted as an input value.
     *              If {@code null}, then decimal percentage values between 0.0 and 1.0 are accepted.
     * @param inputAction Action listener invoked when the value is changed.
     * @return This new GUI object
     */
    public JFormattedTextField addFormattedInputField(IntValueRange range, ActionListener inputAction) {
        GridBagConstraints c = new GridBagConstraints();
        c.gridwidth = 2;
@@ -655,5 +724,4 @@ public class ControlPanelBuilder {
        
        return scrollPane;
    }
    
}
+19 −1
Original line number Diff line number Diff line
package cz.fidentis.analyst.core;

/**
 * Class holding the upper and lower bounds of an interval.
 * 
 * @author Daniel Schramm
 */
@@ -8,6 +9,13 @@ public class IntValueRange {
    
    private final int minimum, maximum;

    /**
     * Constructor.
     * 
     * @param minimum The lower bound of the interval
     * @param maximum The upper bound of the interval
     * @throws IllegalArgumentException if the {@code minimum} is greater than the {@code maximum}
     */
    public IntValueRange(int minimum, int maximum) {
        if (minimum > maximum) {
            throw new IllegalArgumentException("Minimum value must be less or equal to maximum value");
@@ -17,10 +25,20 @@ public class IntValueRange {
        this.maximum = maximum;
    }

    /**
     * Returns the lower bound of the interval.
     * 
     * @return Lower bound of the interval
     */
    public int getMinimum() {
        return minimum;
    }

    /**
     * Returns the upper bound of the interval.
     * 
     * @return Upper bound of the interval
     */
    public int getMaximum() {
        return maximum;
    }
+1 −0
Original line number Diff line number Diff line
@@ -148,6 +148,7 @@ public class DistancePanel extends ControlPanel {
                
                if (ControlPanelBuilder.TEXT_FIELD_BUTTON_PRESSED_MINUS.equals(ae.getActionCommand())
                        || ControlPanelBuilder.TEXT_FIELD_BUTTON_PRESSED_PLUS.equals(ae.getActionCommand())) {
                    // Plus/minus button was pressed -> recompute
                    action.actionPerformed(new ActionEvent(
                            ae.getSource(),
                            ActionEvent.ACTION_PERFORMED,