<commit_before>//
// $Id: $

package com.threerings.admin.web.client;

import com.google.gwt.user.client.ui.Label;
import com.threerings.admin.web.gwt.ConfigField;
import com.threerings.admin.web.gwt.ConfigField.FieldType;

import com.google.gwt.dom.client.Style;

import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;

import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;

import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

/**
 * A class responsible for constructing and exporting the widgets involved in manipulating
 * one specific configuration field.
 */
public abstract class ConfigFieldEditor
{
    public static ConfigFieldEditor getEditorFor (ConfigField field, Command onChange)
    {
        if (field.type == FieldType.BOOLEAN) {
            return new CheckboxFieldEditor(field, onChange);
        }
        return new StringFieldEditor(field, onChange);
    }

    /**
     * This editor represents values as strings.
     */
    protected static class StringFieldEditor extends ConfigFieldEditor
    {
        public StringFieldEditor (ConfigField field, Command onChange)
        {
            super(field, onChange);
        }

        @Override
        protected Widget buildWidget (ConfigField field)
        {
            _box = new TextBox();
            _box.setStyleName("configStringEditor");
            _box.setVisibleLength(40);
            resetField();

            _box.addChangeHandler(new ChangeHandler() {
                public void onChange (ChangeEvent changeEvent) {
                    // if the string fails conversion, just reset to the old value
                    if (_field.type.toValue(_box.getText().trim()) == null) {
                        _box.setText(_field.valStr);
                    }
                    updateModificationState();
                }
            });
            return _box;
        }

        @Override
        public ConfigField getModifiedField ()
        {
            Object newValue = _field.type.toValue(_box.getText().trim());
            if (newValue == null) {
                return null;
            }
            String newValStr = newValue.toString();
            if ((newValStr.size() == 0 && _field.valStr == null) ||newValStr.equals(_field.valStr)) {
                return null;
            }
            return new ConfigField(_field.name, _field.type, newValStr);
        }

        @Override
        protected void resetField ()
        {
            _box.setText(_field.valStr);
        }

        protected TextBox _box;
    }

    /**
     * This editor represents boolean values as checkboxes.
     */
    protected static class CheckboxFieldEditor extends ConfigFieldEditor
    {
        public CheckboxFieldEditor (ConfigField field, Command onChange)<commit_msg>Strings have length, Zell.<commit_after>//
// $Id: $

package com.threerings.admin.web.client;

import com.google.gwt.user.client.ui.Label;
import com.threerings.admin.web.gwt.ConfigField;
import com.threerings.admin.web.gwt.ConfigField.FieldType;

import com.google.gwt.dom.client.Style;

import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;

import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;

import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

/**
 * A class responsible for constructing and exporting the widgets involved in manipulating
 * one specific configuration field.
 */
public abstract class ConfigFieldEditor
{
    public static ConfigFieldEditor getEditorFor (ConfigField field, Command onChange)
    {
        if (field.type == FieldType.BOOLEAN) {
            return new CheckboxFieldEditor(field, onChange);
        }
        return new StringFieldEditor(field, onChange);
    }

    /**
     * This editor represents values as strings.
     */
    protected static class StringFieldEditor extends ConfigFieldEditor
    {
        public StringFieldEditor (ConfigField field, Command onChange)
        {
            super(field, onChange);
        }

        @Override
        protected Widget buildWidget (ConfigField field)
        {
            _box = new TextBox();
            _box.setStyleName("configStringEditor");
            _box.setVisibleLength(40);
            resetField();

            _box.addChangeHandler(new ChangeHandler() {
                public void onChange (ChangeEvent changeEvent) {
                    // if the string fails conversion, just reset to the old value
                    if (_field.type.toValue(_box.getText().trim()) == null) {
                        _box.setText(_field.valStr);
                    }
                    updateModificationState();
                }
            });
            return _box;
        }

        @Override
        public ConfigField getModifiedField ()
        {
            Object newValue = _field.type.toValue(_box.getText().trim());
            if (newValue == null) {
                return null;
            }
            String newValStr = newValue.toString();
            if ((newValStr.length() == 0 && _field.valStr == null)
                    || newValStr.equals(_field.valStr)) {
                return null;
            }
            return new ConfigField(_field.name, _field.type, newValStr);
        }

        @Override
        protected void resetField ()
        {
            _box.setText(_field.valStr);
        }

        protected TextBox _box;
    }

    /**
     * This editor represents boolean values as checkboxes.
     */
    protected static class CheckboxFieldEditor extends ConfigFieldEditor
    {
        public CheckboxFieldEditor (ConfigField field, Command onChange)
{'fraction_non_alphanumeric': 0.09623964308476737, 'fraction_numerical': 0.0009560229445506692, 'mean_word_length': 2.2091002044989776, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2369104', 'n_tokens_mistral': 1703, 'n_tokens_neox': 1678, 'n_words': 368}