Field

public abstract class Field extends Observable<Field.Observer>
implements Cloneable
Known Direct Subclasses

The base class for Fields in Blockly. A field is the smallest piece of a Block and is wrapped by an Input.

Nested Class Summary

@interface Field.FieldType  
interface Field.Observer Observer for listening to changes to a field. 

Constant Summary

int TYPE_ANGLE
String TYPE_ANGLE_STRING
int TYPE_CHECKBOX
String TYPE_CHECKBOX_STRING
int TYPE_COLOR
String TYPE_COLOR_STRING
int TYPE_DATE
String TYPE_DATE_STRING
int TYPE_DROPDOWN
String TYPE_DROPDOWN_STRING
int TYPE_IMAGE
String TYPE_IMAGE_STRING
int TYPE_INPUT
String TYPE_INPUT_STRING
int TYPE_LABEL
String TYPE_LABEL_STRING
int TYPE_NUMBER
String TYPE_NUMBER_STRING
int TYPE_UNKNOWN
int TYPE_VARIABLE
String TYPE_VARIABLE_STRING

Inherited Field Summary

Public Constructor Summary

Field(String name, int type)

Public Method Summary

Field
clone()
Block
String
getName()
Get the name of this field.
abstract String
int
getType()
Get the type of this field.
static boolean
isFieldType(String typeString)
Checks if the given type name is a known field type.
void
serialize(XmlSerializer serializer)
Writes information about the editable parts of the field as XML.
abstract boolean
setFromString(String text)
Sets the values of the field from a string.

Protected Method Summary

void
fireValueChanged(String oldValueString, String newValueString)
Triggers events (both BlocklyEvent.ChangeEvents and Field.Observers) in response to a value change.
void
setBlock(Block block)
Sets the parent block for this field.

Inherited Method Summary

Constants

public static final int TYPE_ANGLE

Constant Value: 2

public static final String TYPE_ANGLE_STRING

Constant Value: "field_angle"

public static final int TYPE_CHECKBOX

Constant Value: 3

public static final String TYPE_CHECKBOX_STRING

Constant Value: "field_checkbox"

public static final int TYPE_COLOR

Constant Value: 4

public static final String TYPE_COLOR_STRING

Constant Value: "field_colour"

public static final int TYPE_DATE

Constant Value: 5

public static final String TYPE_DATE_STRING

Constant Value: "field_date"

public static final int TYPE_DROPDOWN

Constant Value: 7

public static final String TYPE_DROPDOWN_STRING

Constant Value: "field_dropdown"

public static final int TYPE_IMAGE

Constant Value: 8

public static final String TYPE_IMAGE_STRING

Constant Value: "field_image"

public static final int TYPE_INPUT

Constant Value: 1

public static final String TYPE_INPUT_STRING

Constant Value: "field_input"

public static final int TYPE_LABEL

Constant Value: 0

public static final String TYPE_LABEL_STRING

Constant Value: "field_label"

public static final int TYPE_NUMBER

Constant Value: 9

public static final String TYPE_NUMBER_STRING

Constant Value: "field_number"

public static final int TYPE_UNKNOWN

Constant Value: -1

public static final int TYPE_VARIABLE

Constant Value: 6

public static final String TYPE_VARIABLE_STRING

Constant Value: "field_variable"

Public Constructors

public Field (String name, int type)

Parameters
name
type

Public Methods

public Field clone ()

Throws
CloneNotSupportedException

public Block getBlock ()

Returns
  • The parent block for this field.

public String getName ()

Get the name of this field. Names, if they are not null, are expected to be unique within a block but are not guaranteed to be.

public abstract String getSerializedValue ()

Returns
  • The value serialized into a string.

public int getType ()

Get the type of this field. There should be a concrete implementation for each field type.

public static boolean isFieldType (String typeString)

Checks if the given type name is a known field type.

Parameters
typeString The type to check.
Returns
  • true if this is a known field type, false otherwise.

public void serialize (XmlSerializer serializer)

Writes information about the editable parts of the field as XML.

Parameters
serializer The XmlSerializer to write to.
Throws
IOException

public abstract boolean setFromString (String text)

Sets the values of the field from a string.

This is used for setting values of all types of fields when loading a workspace from XML. It is also used, however, as the primary means of setting text fields (e.g., inputs, labels, dates).

There should be a concrete implementation for each field type.

Parameters
text The text value for this field from the XML.
Returns
  • True if the value was set, false otherwise.

Protected Methods

protected void fireValueChanged (String oldValueString, String newValueString)

Triggers events (both BlocklyEvent.ChangeEvents and Field.Observers) in response to a value change. If the field is attached to a event workspace (workspace, toolbox, or trash), must be called on the main thread.

Parameters
oldValueString Old value in serialized string form.
newValueString New value in serialized string form.

protected void setBlock (Block block)

Sets the parent block for this field. Should only be used during block intialization.

Parameters
block The parent block for this field.