//
// Triple Play - utilities for use in PlayN-based games
// Copyright (c) 2011-2013, Three Rings Design, Inc. - All rights reserved.
// http://github.com/threerings/tripleplay/blob/master/LICENSE

package tripleplay.ui;

import react.Slot;
import react.Value;

import playn.core.Image;
import playn.core.Pointer;
import playn.core.Sound;

/**
 * Displays a checkbox which can be toggled. The checkbox must be configured with either a
 * font-based checkmark, or a checkmark icon, which will be shown when it is checked.
 */
public class CheckBox extends TextWidget<CheckBox>
{
    /** The checked status of this widget. */
    public final Value<Boolean> checked = Value.create(false);

    /** Creates a checkbox using the default check glyph: U+2713. */
    public CheckBox () {
        this('\u2713');
    }

    /** Creates a checkbox with the supplied check character. */
    public CheckBox (char checkChar) {
        this(checkChar, (Icon)null);
    }

    public CheckBox (Icon checkIcon) {
        this((char)0, checkIcon);
    }

    @Deprecated
    public CheckBox (Image checkIcon) {
        this((char)0, Icons.image(checkIcon));
    }

    protected CheckBox (char checkChar, Icon checkIcon) {
        enableInteraction();
        _checkStr = String.valueOf(checkChar);
        _checkIcon = checkIcon;
        checked.connect(new Slot<Boolean> () {
            @Override public void onEmit (Boolean checked) {
                updateCheckViz();
            }
        });
    }

    @Override protected Class<?> getStyleClass () {
        return CheckBox.class;
    }

    @Override protected String text () {
        return (_checkIcon == null) ? _checkStr : null;
    }

    @Override protected Icon icon () {
        return _checkIcon;
    }

    @Override protected void onClick (Pointer.Event event) {
        if (_actionSound != null) _actionSound.play();
        checked.update(!checked.get());
    }

    @Override protected void layout () {
        super.layout();
        _actionSound = resolveStyle(Style.ACTION_SOUND);
        updateCheckViz();
    }

    protected void updateCheckViz () {
        boolean isChecked = checked.get();
        if (_tglyph.layer() != null) _tglyph.layer().setVisible(isChecked);
        if (_ilayer != null) _ilayer.setVisible(isChecked);
    }

    protected final String _checkStr;
    protected final Icon _checkIcon;
    protected Sound _actionSound;
}

@@ -1137,32 +1137,472 @@
 kIcon));%0A    %7D%0A%0A
+    /**%0A     * Updates the selected state of this checkbox. This method is called when the user taps and%0A     * releases the checkbox. One can override this method if they want to react to only%0A     * user-interaction-initiated changes to the checkbox's state (versus listening to %7B@link%0A     * #checked%7D which could be updated programmatically).%0A     */%0A    public void select (boolean selected) %7B%0A        checked.update(selected);%0A    %7D%0A%0A
     protected Ch
@@ -2317,30 +2317,22 @@
         
-checked.update
+select
 (!checke

Break user-initiated selection into overridable method.