<commit_before>package carrot2.demo.swing.util;

import java.text.MessageFormat;
import java.util.Hashtable;

import javax.swing.JLabel;
import javax.swing.JSlider;


/**
 * A threshold slider.
 * 
 * @author <NAME>
 */
public class JDoubleSlider extends JSlider {
    private final MessageFormat labelFormat = new MessageFormat("{0,number,#.##}");
    private RangeScaler scaler;

    public JDoubleSlider(double min, double max, double minorTicks, double majorTicks) {
        this.scaler = new RangeScaler(min, max, 0, 1000);

        super.setMinimum(scaler.getIntMin());
        super.setMaximum(scaler.getIntMax());

        setMinorTickSpacing(scaler.scale(minorTicks));
        setMajorTickSpacing(scaler.scale(majorTicks));
        setPaintLabels(true);
        setPaintTicks(true);
        setSnapToTicks(false);

        setLabelTable(createLabels(scaler.getIntMin(), scaler.getIntMax(), scaler.scale(majorTicks)));
    }

    public void setValue(double value) {
        super.setValue(scaler.to(value));
    }

    public double getDoubleValue() {
        return scaler.from(super.getValue());
    }

    private Hashtable createLabels(int min, int max, int step) {
        final Hashtable table = new Hashtable();

        
        for (int i = min; i <= max; i = i + step) {
            final String label = labelFormat.format(new Object [] {new Double(scaler.from(i))});
            table.put(new Integer(i), createLabel(label));
        }

        String label;

        label = labelFormat.format(new Object [] {new Double(scaler.from(min))});
        table.put(new Integer(min), createLabel(label));

        label = labelFormat.format(new Object [] {new Double(scaler.from(max))});
        table.put(new Integer(max), createLabel(label));

        return table;
    }

    private JLabel createLabel(String label) {<commit_msg>The slider now adjusts the returned value to the ticker position (if snapping is enabled). The returned value is also rounded to 0.xx).<commit_after>package carrot2.demo.swing.util;

import java.text.MessageFormat;
import java.util.Hashtable;

import javax.swing.JLabel;
import javax.swing.JSlider;


/**
 * A threshold slider for double values.
 * 
 * @author <NAME>
 */
public class JDoubleSlider extends JSlider {
    private final MessageFormat labelFormat = new MessageFormat("{0,number,#.##}");
    private RangeScaler scaler;

    private double tickScale;
    
    public JDoubleSlider(double min, double max, double minorTicks, double majorTicks) {
        this.scaler = new RangeScaler(min, max, 0, 1000);

        super.setMinimum(scaler.getIntMin());
        super.setMaximum(scaler.getIntMax());

        tickScale = Math.min(minorTicks, majorTicks);

        setMinorTickSpacing(scaler.scale(minorTicks));
        setMajorTickSpacing(scaler.scale(majorTicks));
        setPaintLabels(true);
        setPaintTicks(true);
        setSnapToTicks(false);

        setLabelTable(createLabels(scaler.getIntMin(), scaler.getIntMax(), scaler.scale(majorTicks)));
    }

    public void setValue(double value) {
        super.setValue(scaler.to(value));
    }

    public double getDoubleValue() {
        double value = scaler.from(super.getValue());

        if (getSnapToTicks()) {
            final double n = Math.round(value / tickScale);
            value = tickScale * n;
        }

        return Math.round(value * 100.0) / 100.0;
    }

    private Hashtable createLabels(int min, int max, int step) {
        final Hashtable table = new Hashtable();

        
        for (int i = min; i <= max; i = i + step) {
            final String label = labelFormat.format(new Object [] {new Double(scaler.from(i))});
            table.put(new Integer(i), createLabel(label));
        }

        String label;

        label = labelFormat.format(new Object [] {new Double(scaler.from(min))});
        table.put(new Integer(min), createLabel(label));

        label = labelFormat.format(new Object [] {new Double(scaler.from(max))});
        table.put(new Integer(max), createLabel(label));

        return table;
    }

    private JLabel createLabel(String label) {
{'fraction_non_alphanumeric': 0.12060179568066004, 'fraction_numerical': 0.005581169619024508, 'mean_word_length': 3.0136319376825704, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3320657', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1214, 'n_words': 286}