package eu.gity.jmeter.ddos.stairsddosthreadgrp.gui;

import org.apache.jorphan.gui.NumberRenderer;

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;

public class CustomNumberRenderer extends NumberRenderer {
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    private NumberFormat customFormatter = null;

    public CustomNumberRenderer() {
        super();
    }

    public CustomNumberRenderer(String format) {
        super(format);
    }

    public CustomNumberRenderer(String format, char groupingSeparator) {
        super();
        DecimalFormatSymbols symbols = new DecimalFormatSymbols();
        symbols.setGroupingSeparator(groupingSeparator);
        customFormatter = new DecimalFormat(format, symbols);
    }

    @Override
    public void setValue(Object value) {
        String str = "";
        if (value != null) {
            if (customFormatter != null) {
                str = customFormatter.format(value);
            } else {
                str = formatter.format(value);
            }
        }
        setText(str);
    }
}
