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 |
getBlock()
|
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.ChangeEvent s and Field.Observer s) in response to a value
change. |
void |
Inherited Method Summary
Constants
public static final int TYPE_ANGLE
public static final String TYPE_ANGLE_STRING
public static final int TYPE_CHECKBOX
public static final String TYPE_CHECKBOX_STRING
public static final int TYPE_COLOR
public static final String TYPE_COLOR_STRING
public static final int TYPE_DATE
public static final String TYPE_DATE_STRING
public static final int TYPE_DROPDOWN
public static final String TYPE_DROPDOWN_STRING
public static final int TYPE_IMAGE
public static final String TYPE_IMAGE_STRING
public static final int TYPE_INPUT
public static final String TYPE_INPUT_STRING
public static final int TYPE_LABEL
public static final String TYPE_LABEL_STRING
public static final int TYPE_NUMBER
public static final String TYPE_NUMBER_STRING
public static final int TYPE_UNKNOWN
public static final int TYPE_VARIABLE
public static final String TYPE_VARIABLE_STRING
Public Constructors
public Field (String name, int type)
Parameters
name | |
---|---|
type |
Public Methods
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.ChangeEvent
s and Field.Observer
s) 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. |
---|