<commit_before>package uk.ac.surrey.soc.cress.extrawidgets.api

import org.nlogo.api.Color.MaxColor
import org.nlogo.api.Color.getColor
import org.nlogo.api.Color.modulateDouble
import org.nlogo.api.I18N
import org.nlogo.api.LogoList
import org.nlogo.api.Syntax._
import org.nlogo.api.Syntax.ListType
import org.nlogo.api.Syntax.NumberType
import org.nlogo.api.Syntax.StringType

abstract class PropertyDef[+W <: ExtraWidget, T <: AnyRef](
  val widget: W,
  setter: T ⇒ Unit, // should never be directly accessed from the outside
  val getter: () ⇒ T) {
  val inputTypeConstant: Int
  val outputTypeConstant: Int
  def asInputType(obj: AnyRef): T = obj.asInstanceOf[T] // TODO: handle this
  def updateInState(): Unit = widget.updatePropertyInState(this)
  def setValue(obj: AnyRef): Unit = {
    setter(asInputType(obj))
    updateInState()
  }
}

class ObjectPropertyDef[+W <: ExtraWidget](
  w: W,
  setter: AnyRef ⇒ Unit,
  getter: () ⇒ AnyRef)
  extends PropertyDef(w, setter, getter) {
  val inputTypeConstant = WildcardType
  val outputTypeConstant = WildcardType
}

class StringPropertyDef[+W <: ExtraWidget](
  w: W,
  setter: String ⇒ Unit,
  getter: () ⇒ String)
  extends PropertyDef(w, setter, getter) {
  val inputTypeConstant = StringType
  val outputTypeConstant = StringType
  override def asInputType(obj: AnyRef): String = obj.toString
}<commit_msg>add stringValue method to PropertyDef<commit_after>package uk.ac.surrey.soc.cress.extrawidgets.api

import org.nlogo.api.Color.MaxColor
import org.nlogo.api.Color.getColor
import org.nlogo.api.Color.modulateDouble
import org.nlogo.api.Dump
import org.nlogo.api.I18N
import org.nlogo.api.LogoList
import org.nlogo.api.Syntax.BooleanType
import org.nlogo.api.Syntax.ListType
import org.nlogo.api.Syntax.NumberType
import org.nlogo.api.Syntax.StringType
import org.nlogo.api.Syntax.WildcardType

abstract class PropertyDef[+W <: ExtraWidget, T <: AnyRef](
  val widget: W,
  setter: T ⇒ Unit, // should never be directly accessed from the outside
  val getter: () ⇒ T) {
  val inputTypeConstant: Int
  val outputTypeConstant: Int
  def asInputType(obj: AnyRef): T = obj.asInstanceOf[T] // TODO: handle this
  def updateInState(): Unit = widget.updatePropertyInState(this)
  def setValue(obj: AnyRef): Unit = {
    setter(asInputType(obj))
    updateInState()
  }
  def stringValue =
    Dump.logoObject(getter() match {
      case i: java.lang.Integer ⇒   // `Dump` doesn't like Integer
        Double.box(i.doubleValue()) // so we give it a Double
      case x: AnyRef ⇒ x
    })
}

class ObjectPropertyDef[+W <: ExtraWidget](
  w: W,
  setter: AnyRef ⇒ Unit,
  getter: () ⇒ AnyRef)
  extends PropertyDef(w, setter, getter) {
  val inputTypeConstant = WildcardType
  val outputTypeConstant = WildcardType
}

class StringPropertyDef[+W <: ExtraWidget](
  w: W,
  setter: String ⇒ Unit,
  getter: () ⇒ String)
  extends PropertyDef(w, setter, getter) {
  val inputTypeConstant = StringType
  val outputTypeConstant = StringType
  override def asInputType(obj: AnyRef): String = obj.toString
}
{'fraction_non_alphanumeric': 0.11122015047432122, 'fraction_numerical': 0.0013084723585214263, 'mean_word_length': 4.290657439446367, 'pattern_counts': {'":': 0, '<': 11, '<?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': '378308', 'n_tokens_mistral': 1048, 'n_tokens_neox': 1060, 'n_words': 270}