<commit_before>/*
 * Copyright 2014 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Eclipse Public License version 1.0, available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package org.jboss.forge.plugin.idea.ui.component;

import java.awt.Container;

import javax.swing.JComponent;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.jboss.forge.addon.convert.Converter;
import org.jboss.forge.addon.ui.context.UIContext;
import org.jboss.forge.addon.ui.hints.InputType;
import org.jboss.forge.addon.ui.input.InputComponent;
import org.jboss.forge.addon.ui.input.UIInput;
import org.jboss.forge.addon.ui.util.InputComponents;
import org.jboss.forge.plugin.idea.service.PluginService;
import org.jboss.forge.plugin.idea.service.callbacks.FormUpdateCallback;

/**
 * @author <NAME>
 */
public class SpinnerComponentBuilder extends ComponentBuilder
{

    @SuppressWarnings("unchecked")
    @Override
    public ForgeComponent build(UIContext context, final InputComponent<?, Object> input)
    {
        return new LabeledComponent(input, new ForgeComponent()
        {
            private JSpinner spinner;
            private Converter<Object, Integer> converter = converterFactory
                    .getConverter(input.getValueType(), Integer.class);

            @Override
            public void buildUI(Container container)
            {
                spinner = new JSpinner();
                container.add(spinner);

                JComponent editor = spinner.getEditor();
                if (editor instanceof JSpinner.DefaultEditor)
                {
                    ((JSpinner.DefaultEditor) editor).getTextField().setHorizontalAlignment(JTextField.LEFT);
                }

                spinner.addChangeListener(new ChangeListener()
                {
                    @Override
                    public void stateChanged(ChangeEvent e)
                    {
                        Object selectedItem = spinner.getValue();
                        PluginService.getInstance().submitFormUpdate(
                                new FormUpdateCallback(converterFactory, input,
                                        selectedItem, valueChangeListener));
                    }
                });
                addNoteLabel(container, spinner).setText(input.getNote());
            }

            @Override
            public void updateState()
            {
                spinner.setEnabled(input.isEnabled());

                if (getValue() != getInputValue())
                {
                    reloadValue();<commit_msg>FORGE-2346: Fixed number format in Spinner<commit_after>/*
 * Copyright 2014 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Eclipse Public License version 1.0, available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package org.jboss.forge.plugin.idea.ui.component;

import java.awt.Container;

import javax.swing.JComponent;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.jboss.forge.addon.convert.Converter;
import org.jboss.forge.addon.ui.context.UIContext;
import org.jboss.forge.addon.ui.hints.InputType;
import org.jboss.forge.addon.ui.input.InputComponent;
import org.jboss.forge.addon.ui.input.UIInput;
import org.jboss.forge.addon.ui.util.InputComponents;
import org.jboss.forge.plugin.idea.service.PluginService;
import org.jboss.forge.plugin.idea.service.callbacks.FormUpdateCallback;

/**
 * @author <NAME>
 */
public class SpinnerComponentBuilder extends ComponentBuilder
{

    @SuppressWarnings("unchecked")
    @Override
    public ForgeComponent build(UIContext context, final InputComponent<?, Object> input)
    {
        return new LabeledComponent(input, new ForgeComponent()
        {
            private JSpinner spinner;
            private Converter<Object, Integer> converter = converterFactory
                    .getConverter(input.getValueType(), Integer.class);

            @Override
            public void buildUI(Container container)
            {
                spinner = new JSpinner();
                container.add(spinner);

                JSpinner.NumberEditor editor = new JSpinner.NumberEditor(spinner, "0");
                editor.getTextField().setHorizontalAlignment(JTextField.LEFT);
                spinner.setEditor(editor);

                spinner.addChangeListener(new ChangeListener()
                {
                    @Override
                    public void stateChanged(ChangeEvent e)
                    {
                        Object selectedItem = spinner.getValue();
                        PluginService.getInstance().submitFormUpdate(
                                new FormUpdateCallback(converterFactory, input,
                                        selectedItem, valueChangeListener));
                    }
                });
                addNoteLabel(container, spinner).setText(input.getNote());
            }

            @Override
            public void updateState()
            {
                spinner.setEnabled(input.isEnabled());

                if (getValue() != getInputValue())
                {
                    reloadValue();
{'fraction_non_alphanumeric': 0.09414853713428357, 'fraction_numerical': 0.003938484621155289, 'mean_word_length': 2.0915942028985506, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4445303', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1312, 'n_words': 256}