Fields User Interface


The Fields property is a collection of individual fields. A field is special type of variable that becomes part of the component once you've compiled it. You can create your own fields and in some cases Repast Py will implicitly add fields for you. Fields can be edited by clicking on a Fields property edit button in the property pane. The layout of the Fields editor is shown below.




You use the Fields editor to add and edit individual fields. The Fields editor has three parts.
  • The Add Field Pane. The add field pane located at the top of the dialog is used to add a new field to the list of fields. You must specify the fields name (e.g. numAgents) and its type. The name cannot include any spaces. The type can be one of the already listed primitive types or any java class. If the type is a java class, you must use the fully qualified class name (i.e. the package + class name, i.e. java.awt.Color). Optionally you can specify a default value for primitive types, and whether or not the field is accessible and / or probeable. If the field is accessible, then implicit accessor actions for the field will be created. For example, if you create a field called numAgents and mark it as accessible then the implicit getNumAgents and setNumAgents actions will be created. The field is then accessible to other components via these accessor methods. If the field is probeable it will show up as part of the parameters pane when the model is run, assuming the field is part of a model type component. Note that probeable necessarily implies accessible. Once you have defined your field you can add it to the list of fields in the fields table by clicking the Add button.

  • The Fields Table. The Fields table lists any fields that you have defined and any that are pre-defined or implicitly added by Repast Py. You can delete a field from the table and thus from the list of defined fields by selecting the field in the table, and then clicking the delete button. Fields can also be edited directly in the table.

  • OK and Cancel. The OK button will set the value of the fields property to the new set of fields in the fields list. The Cancel button will ignore any changes you have made to the fields property and revert the property to its original list of fields.

Usage

Adding fields

You add fields by filling in the appropriate values in the add field pane and then pressing the add button. The field will then appear in the fields table. You must provide a name and type for the field. Providing a default value is optional and accessible and probeable defaults to false.

Editing fields

You can edit a field's properties directly in the field table. Click on the cell you want to edit (i.e. the field's name, type, and so on) that you want to edit and edit the property. Note that you can only edit the default value of fields implicitly added by Repast Py.

Deleting fields
You can delete a field by clicking on that field in the fields table and clicking the delete button. Note that you cannot delete fields added by Repast Py.

You can refer to the fields of a component from within a components action code as "self.X" where X is the field name. For example, if you define a field called startWealth in a component you have named WealthModel, you can refer to this startWealth field from within WealthModel's actions as self.startWealth. Any fields you have defined will also show up in the variables list in the action code editor. If you want to get or set the value of a field from outside the component in which it is defined, you need to mark the field as accessible. You can then use the getX and setX methods, where X is the name of the field. So, getStartWealth() and setStartWealth() can be used to access component Y's startWealth field from within another component's action code. It is also possible to use a "property" type shorthand for accessing a component's fields. For example, a = wealthModel.startWealth will call the getStartWealth() accessor action and wealthModel.startWealth = 3 will call the setStartWealth action passing the value 3 as an argument.