Input

public abstract class Input extends Object
implements Cloneable
Known Direct Subclasses

An input on a Blockly block. Inputs come in three varieties:

  • Input.InputValue which can connect to a block's output. Values are rendered (at least, by blocklylib-vertical) as either an external connection, or a embedded block (i.e., inline input).
  • Input.InputStatement which connect to a block's previous connector. Statements are rendered as a stack of blocks, partially wrapped. For instance, consider loops or "if" blocks.
  • Input.InputDummy which lacks a connection to a child block. These act as simple field containers.

In addition, most inputs also include a list of fields preceding any connected block.

The list of fields, and block type are immutable for a given Input.

Nested Class Summary

@interface Input.Alignment  
class Input.InputDummy An input that only wraps fields and does not provide its own input connection. 
class Input.InputStatement An input that accepts one or more statement blocks. 
@interface Input.InputType  
class Input.InputValue An Input that takes a value. 

Constant Summary

int ALIGN_CENTER This input's fields should be aligned in the center of the block.
String ALIGN_CENTER_STRING
int ALIGN_LEFT This input's fields should be aligned at the left of the block, or the right in a RTL configuration.
String ALIGN_LEFT_STRING
int ALIGN_RIGHT This input's fields should be aligned at the right of the block, or the left in a RTL configuration.
String ALIGN_RIGHT_STRING
int TYPE_DUMMY An input that just wraps fields.
String TYPE_DUMMY_STRING
int TYPE_STATEMENT An input that takes a set of statement blocks.
String TYPE_STATEMENT_STRING
int TYPE_VALUE An input that takes a single value.
String TYPE_VALUE_STRING

Field Summary

protected static final Set<String> INPUT_TYPES The list of known input types.

Public Constructor Summary

Input(String name, int type, List<? extends Field> fields, int align, Connection connection)
Creates a new input that can be added to a block.

Protected Constructor Summary

Input(String name, int type, List<? extends Field> fields, String alignString, Connection connection)
Creates a new input that can be added to a block.

Public Method Summary

Input
clone()
static Input
fromJson(JSONObject json, List<Field> fields)
Generate an Input instance from a JSON definition.
int
Block
static String[]
getChecksFromJson(JSONObject json, String checksKey)
Gets a list of connection checks from JSON.
Block
Connection
List<Field>
String
int
InputView
static boolean
isInputType(String typeString)
Checks if a given type is a known input type.
void
serialize(XmlSerializer serializer, IOOptions options)
Writes the value of the Input and all of its Fields as a string.
void
setBlock(Block block)
Sets the block that is the parent of this input.
void
setView(InputView view)
Sets the view that renders this input.

Protected Method Summary

void
serializeImpl(XmlSerializer serializer, String tag, IOOptions options)
Writes the value of the Input and all of its Fields as a string.

Inherited Method Summary

Constants

public static final int ALIGN_CENTER

This input's fields should be aligned in the center of the block.

Constant Value: 2

public static final String ALIGN_CENTER_STRING

Constant Value: "CENTRE"

public static final int ALIGN_LEFT

This input's fields should be aligned at the left of the block, or the right in a RTL configuration.

Constant Value: 0

public static final String ALIGN_LEFT_STRING

Constant Value: "LEFT"

public static final int ALIGN_RIGHT

This input's fields should be aligned at the right of the block, or the left in a RTL configuration.

Constant Value: 1

public static final String ALIGN_RIGHT_STRING

Constant Value: "RIGHT"

public static final int TYPE_DUMMY

An input that just wraps fields. Has no connections.

Constant Value: 2

public static final String TYPE_DUMMY_STRING

Constant Value: "input_dummy"

public static final int TYPE_STATEMENT

An input that takes a set of statement blocks. Must have a next connection.

Constant Value: 1

public static final String TYPE_STATEMENT_STRING

Constant Value: "input_statement"

public static final int TYPE_VALUE

An input that takes a single value. Must have an input connection.

Constant Value: 0

public static final String TYPE_VALUE_STRING

Constant Value: "input_value"

Fields

protected static final Set<String> INPUT_TYPES

The list of known input types.

Public Constructors

public Input (String name, int type, List<? extends Field> fields, int align, Connection connection)

Creates a new input that can be added to a block.

Parameters
name The name of the input. Not for display.
type The type of the input (value, statement, or dummy).
fields
align The alignment for fields in this input (left, right, center).
connection (Optional) The connection for this input, if any..

Protected Constructors

protected Input (String name, int type, List<? extends Field> fields, String alignString, Connection connection)

Creates a new input that can be added to a block.

Parameters
name The name of the input. Not for display.
type The type of the input (value, statement, or dummy).
fields
alignString The alignment for fields in this input (left, right, center).
connection (Optional) The connection for this input, if any..

Public Methods

public Input clone ()

public static Input fromJson (JSONObject json, List<Field> fields)

Generate an Input instance from a JSON definition. The type must be a known input type. If the type is not supported an alternate input type should be used instead.

Parameters
json The JSONObject that describes the input.
fields
Returns
  • An instance of Input generated from the json.

public int getAlign ()

Returns
  • The alignment of this input.

public Block getBlock ()

Returns
  • The block this input belongs to.

public static String[] getChecksFromJson (JSONObject json, String checksKey)

Gets a list of connection checks from JSON. If json does not contain a 'check' field null will be returned instead.

Parameters
json The JSON to extract the connection checks from.
checksKey The key for the checks.
Returns
  • The set of checks or null.

public Block getConnectedBlock ()

public Connection getConnection ()

Returns
  • The input's Connection, or null if it is a dummy input.

public List<Field> getFields ()

Returns
  • The list of fields in this input.

public String getName ()

Returns
  • The name of this input.

public int getType ()

Returns
  • The type of this input.

public InputView getView ()

Returns
  • The view that renders this input.

public static boolean isInputType (String typeString)

Checks if a given type is a known input type.

Parameters
typeString The type to check.
Returns
  • True if the type is known to be an input type, false otherwise.

public void serialize (XmlSerializer serializer, IOOptions options)

Writes the value of the Input and all of its Fields as a string. By default only fields are written. Subclasses should override this and call serializeImpl(XmlSerializer, String, IOOptions) with the correct tag to also serialize any connected blocks.

Parameters
serializer The XmlSerializer to write to.
options The options to configure writing.
Throws
IOException

public void setBlock (Block block)

Sets the block that is the parent of this input.

Parameters
block The block that owns this input.

public void setView (InputView view)

Sets the view that renders this input.

Parameters
view

Protected Methods

protected void serializeImpl (XmlSerializer serializer, String tag, IOOptions options)

Writes the value of the Input and all of its Fields as a string. If a tag is given, anything attached to the input's connection will also be serialized.

Parameters
serializer The XmlSerializer to write to.
tag The xml tag to use for wrapping the block connected to the input or null.
options The I/O options.
Throws
IOException