<commit_before>/*   RSence
 *   Copyright 2009 Riassence Inc.
 *   http://riassence.com/
 *
 *   You should have received a copy of the GNU General Public License along
 *   with this software package. If not, contact <EMAIL>
 */

/*** = Description
  ** HRadiobuttonList expects the setListItems to be set. See HListItems.
  ** The value of the instance is the selected key in the listItems.
  ***/
var//RSence.Lists
HRadioButtonList = HListItemControl.extend({
  drawSubviews: function(){
    this.setStyle('border','1px solid #999999');
    this.setStyle('border-radius','3px');
    this.setStyle('overflow-y','auto');
  },
  listItems: [],
  listItemViews: [],
  
/** = Description
  * Setter function for listItems and listItemViews. Destroys
  * the old HRadiabuttons before creating the new ones based on the
  * listItems given as an parameter.
  *
  * = Parameters
  * +_listItems+:: listItems is an array-packed array, where each index in the
  *                surrounding array contains a [ value, label ] pair.
  *                The value is mapped to the value of the HRadiobuttonList
  *                instance when its HRadiobutton instance is selected.
  *
  **/
  setListItems: function(_listItems){
    _listItems = this._cleanListItems(_listItems);
    var _listItem,
        _value,
        _label,
        _radioButton,
        i = 0;
    for ( ; i < this.listItemViews.length; i++ ) {
      try {
        this.listItemViews[i].die();
      }
      catch(e) {
        console.log('HRadiobuttonList, setListItems item destruction error: ',e);
      }
    }
    this.listItems = _listItems;
    this.listItemViews = [];
    for ( i = 0 ; i < _listItems.length; i++ ){
      _listItem = _listItems[i];
      _value = _listItem[0];
      _label = _listItem[1];
      _component = this.createComponent( i, _label );
      this.listItemViews[i] = _component;
    }
    this.refreshValue();
  },
  
  createComponent: function( i, _label ){
    return HRadiobutton.nu(
      [ 4, (i*23)+4, null, 23, 4, null ],
      this, {
        label: _label,
        enabled: this.enabled,
        value: false
      }
    );
  },
  
  _listItemResponder: null,
  setListItemResponder: function(_listItemResponder){
    this._listItemResponder = _listItemResponder;
  },
  
/** = Description
  * Destructor. Sets listItems and listItemViews to null and initiates
  * destructor for radioButtonIndexValue.
  *
  **/<commit_msg>HRadioButtonList (and derived classes) is smarter about the index value, when the listItems change.<commit_after>/*   RSence
 *   Copyright 2009 Riassence Inc.
 *   http://riassence.com/
 *
 *   You should have received a copy of the GNU General Public License along
 *   with this software package. If not, contact <EMAIL>
 */

/*** = Description
  ** HRadiobuttonList expects the setListItems to be set. See HListItems.
  ** The value of the instance is the selected key in the listItems.
  ***/
var//RSence.Lists
HRadioButtonList = HListItemControl.extend({
  drawSubviews: function(){
    this.setStyle('border','1px solid #999999');
    this.setStyle('border-radius','3px');
    this.setStyle('overflow-y','auto');
  },
  listItems: [],
  listItemViews: [],
  
/** = Description
  * Setter function for listItems and listItemViews. Destroys
  * the old HRadiabuttons before creating the new ones based on the
  * listItems given as an parameter.
  *
  * = Parameters
  * +_listItems+:: listItems is an array-packed array, where each index in the
  *                surrounding array contains a [ value, label ] pair.
  *                The value is mapped to the value of the HRadiobuttonList
  *                instance when its HRadiobutton instance is selected.
  *
  **/
  setListItems: function(_listItems){
    _listItems = this._cleanListItems(_listItems);
    var _listItem,
        _value,
        _label,
        _radioButton,
        _selected = false,
        i = 0;
    for ( ; i < this.listItemViews.length; i++ ) {
      try {
        this.listItemViews[i].die();
      }
      catch(e) {
        console.log('HRadiobuttonList, setListItems item destruction error: ',e);
      }
    }
    this.listItems = _listItems;
    this.listItemViews = [];
    for ( i = 0 ; i < _listItems.length; i++ ){
      _listItem = _listItems[i];
      _value = _listItem[0];
      _label = _listItem[1];
      _component = this.createComponent( i, _label );
      if( _value === this.value ){
        _selected = _value;
      }
      this.listItemViews[i] = _component;
    }
    if( _selected !== false ){
      this.setValue(-1);
      this.setValue(_selected);
    }
    else if (this['valueMatrix'] !== undefined){
      this.setValue(-1);
      var
      _prevIndex = this.radioButtonIndexValue.value,
      _listLen = _listItems.length;
      this.radioButtonIndexValue.set(-1);
      if( _listLen > 0 ){
        if( _listLen-1 < _prevIndex ){
          this.setValue(this.listItems[_listLen-1][0]);
        }
        else if (this.listItems[_prevIndex]){
          this.setValue(this.listItems[_prevIndex][0]);
        }
        else{
          this.setValue(this.listItems[0][0]);
        }
      }
    }
    this.refreshValue();
  },
  
  createComponent: function( i, _label ){
    return HRadiobutton.nu(
      [ 4, (i*23)+4, null, 23, 4, null ],
      this, {
        label: _label,
        enabled: this.enabled,
        value: false
      }
    );
  },
  
  _listItemResponder: null,
  setListItemResponder: function(_listItemResponder){
    this._listItemResponder = _listItemResponder;
  },
  
/** = Description
  * Destructor. Sets listItems and listItemViews to null and initiates
  * destructor for radioButtonIndexValue.
  *
  **/
{'fraction_non_alphanumeric': 0.11451187335092348, 'fraction_numerical': 0.009850483729111698, 'mean_word_length': 2.5671267252195733, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 6, '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': '3620364', 'n_tokens_mistral': 1816, 'n_tokens_neox': 1762, 'n_words': 461}