public class Block extends java.lang.Object implements ISupportMemento
| Modifier and Type | Field and Description |
|---|---|
static java.lang.Long |
NULL |
| Constructor and Description |
|---|
Block(Workspace workspace,
java.lang.String genusName)
Constructs a new
Block instance. |
Block(Workspace workspace,
java.lang.String genusName,
boolean linkToStubs)
Constructs a new
Block instance. |
Block(Workspace workspace,
java.lang.String genusName,
java.lang.String label)
Constructs a new
Block instance. |
Block(Workspace workspace,
java.lang.String genusName,
java.lang.String label,
boolean linkToStubs)
Constructs a new
Block instance. |
| Modifier and Type | Method and Description |
|---|---|
BlockConnector |
addSocket(int index,
java.lang.String kind,
BlockConnector.PositionType positionType,
java.lang.String label,
boolean isLabelEditable,
boolean isExpandable,
java.lang.Long blockID)
Adds another socket to this.
|
void |
addSocket(java.lang.String kind,
BlockConnector.PositionType positionType,
java.lang.String label,
boolean isLabelEditable,
boolean isExpandable,
java.lang.Long blockID)
Adds another socket to this.
|
boolean |
areSocketsExpandable()
Returns true if this genus has expandable sockets; false otherwise
FORWARDED FROM BLOCK GENUS
|
void |
blockConnected(BlockConnector connectedSocket,
java.lang.Long connectedBlockID)
Informs this Block that a block with id connectedBlockID has connected to the specified
connectedSocket
|
void |
blockDisconnected(BlockConnector disconnectedSocket)
Informs this Block that a block has disconnected from the specified disconnectedSocket
|
void |
changeGenusTo(java.lang.String genusName)
Changes the genus of this block, while maintaining this current blocks
relationships with other blocks it's connected to.
|
boolean |
equals(java.lang.Object other)
Returns true iff the other Object is an instance of Block and has the same
blockID as this; false otherwise
|
java.lang.Long |
getAfterBlockID()
Returns the Block ID connected to the after connector of this;
Block.Null if this does not have an after block
|
BlockConnector |
getAfterConnector()
Returns the BlockConnector representing the connection to the block after this
|
java.lang.String |
getArgumentDescription(int index)
Returns the the argument description at index i.
|
java.lang.String |
getBadMsg()
Returns the "bad" message of this block.
|
java.lang.Long |
getBeforeBlockID()
Returns the Block ID connected to the before connector of this; Block.Null
if this does not have a before block
|
BlockConnector |
getBeforeConnector()
Returns the BlockConnector representing the connection to the block before this
|
java.lang.String |
getBlockDescription()
Returns the String block text description of this.
|
java.lang.Long |
getBlockID()
Returns the block ID of this
|
java.lang.String |
getBlockLabel()
Returns the block label of this
|
java.awt.Color |
getColor()
Returns the Color of this; May return Color.Black if color was unspecified.
|
BlockConnector |
getConnectorTo(java.lang.Long otherBlockID)
Searches for the BlockConnector linking this block to another block
|
java.lang.Iterable<BlockStub> |
getFreshStubs()
Returns the Stubs of this Block, if it has Stubs; null otherwise
|
java.lang.String |
getGenusName()
Returns the name of this genus
FORWARDED FROM BLOCK GENUS
|
BlockConnector |
getInitAfter()
Returns the initial after connector of this
FORWARDED FROM BLOCK GENUS
|
BlockConnector |
getInitBefore()
Returns the initial before connector of this
FORWARDED FROM BLOCK GENUS
|
java.util.Map<BlockImageIcon.ImageLocation,BlockImageIcon> |
getInitBlockImageMap()
Returns the initial BlockImageIcon mapping of this.
|
java.lang.String |
getInitialLabel()
Returns the initial label of this
FORWARDED FROM BLOCK GENUS
|
BlockConnector |
getInitPlug()
Returns the initial plug connector of this
FORWARDED FROM BLOCK GENUS
|
java.lang.Iterable<BlockConnector> |
getInitSockets()
Returns the initial set of sockets of this
FORWARDED FROM BLOCK GENUS
|
java.lang.String |
getLabelPrefix()
Returns the String block label prefix of this
FORWARDED FROM BLOCK GENUS
|
java.lang.String |
getLabelSuffix()
Returns the String block label prefix of this
FORWARDED FROM BLOCK GENUS
|
int |
getNumSockets()
Returns the number of sockets of this
|
java.lang.String |
getPageLabel()
Returns the page label string of this
|
BlockConnector |
getPlug()
Returns the BlockConnector plug of this
|
java.lang.Long |
getPlugBlockID()
Return plug block id; null if plug does not exist
|
java.lang.String |
getPlugKind()
Return plug kind; null if plug does not exist
|
java.lang.String |
getPlugLabel()
Return plug label; null if plug does not exist
|
java.lang.String |
getProperty(java.lang.String property)
Returns the value of the specified language dependent property
(partially) FORWARDED FROM BLOCK GENUS depending on specified property
|
org.w3c.dom.Node |
getSaveNode(org.w3c.dom.Document document,
int x,
int y,
org.w3c.dom.Node commentNode,
boolean isCollapsed)
Returns the node of this using additional location information
specified in x and y and comment text .
|
java.util.List<java.lang.String> |
getSiblingsList()
Returns the siblings of this genus.
|
BlockConnector |
getSocketAt(int index)
Returns the socket (BlockConnector instance) at the specified index
|
int |
getSocketIndex(BlockConnector socket)
Returns the index number of a given socket
|
java.lang.Iterable<BlockConnector> |
getSockets()
Returns an unmodifiable iterable over a safe copy of the Sockets of this
|
java.lang.Object |
getState() |
java.lang.Iterable<java.lang.String> |
getStubList()
Returns a list of the stub kinds (or stub genus names) of this; if this genus does not have any stubs,
returns an empty list
FORWARDED FROM BLOCK GENUS
|
Workspace |
getWorkspace()
Returns the workspace that this block is living in
|
boolean |
hasAfterConnector()
Returns true if this genus has a "after" connector; false otherwise.
|
boolean |
hasBeforeConnector()
Returns true if this genus has a "before" connector; false otherwise.
|
boolean |
hasDefaultArgs()
Returns true iff any one of the connectors for this genus has default arguments; false otherwise
FORWARDED FROM BLOCK GENUS
|
boolean |
hasFocus()
Returns true iff this block has focus.
|
int |
hashCode()
Returns the hash code of this
|
boolean |
hasPageLabel()
Returns true iff this block has a page label and it is non-empty
|
boolean |
hasPlug()
Returns if BlockConnector plug exists
|
boolean |
hasSiblings()
Returns true if this genus has siblings; false otherwise.
|
boolean |
hasStubs()
Returns true is this genus has stubs (references such as getters, setters, etc.); false otherwise
FORWARDED FROM BLOCK GENUS
|
boolean |
isBad()
Returns true iff this block is "bad."
|
boolean |
isCommandBlock()
Returns true if this block is a command block (i.e. forward, say, etc.); false otherwise
FORWARDED FROM BLOCK GENUS
|
boolean |
isDataBlock()
Returns true if this block is a data block a.k.a. a primitive (i.e. number, string, boolean);
false otherwise
FORWARDED FROM BLOCK GENUS
|
boolean |
isDeclaration()
Returns true if this genus is a declaration block.
|
boolean |
isFunctionBlock()
Returns true iff this block is a function block, which takes in an input and produces an
output.
|
boolean |
isInfix()
Returns true if this genus is infix (i.e. math blocks, and/or blocks); false otherwise
FORWARDED FROM BLOCK GENUS
|
boolean |
isLabelEditable()
Returns true if the label of this is editable; false otherwise
FORWARDED FROM BLOCK GENUS
|
boolean |
isLabelValue()
Returns true if the value of this genus is contained within the label of this; false
otherwise
FORWARDED FROM BLOCK GENUS
|
boolean |
isListRelated()
Returns true if this block is a list or a list operator (determined by whether it has at
least one list connector of any type); false otherwise.
|
boolean |
isPageLabelSetByPage()
Returns true iff page label of this is set by a page
FORWARDED FROM BLOCK GENUS
|
boolean |
isProcedureDeclBlock()
Returns true if this block is a procedure declaration block; false otherwise
FORWARDED FROM BLOCK GENUS
|
boolean |
isProcedureParamBlock()
Returns true if this block is a procedure parameter block; false otherwise.
|
boolean |
isVariableDeclBlock()
Returns true if this block is a variable block; false otherwise
FORWARDED FROM BLOCK GENUS
|
boolean |
labelMustBeUnique()
Returns true if the label of this must be unique; false otherwise
FORWARDED FROM BLOCK GENUS
|
java.lang.Iterable<java.lang.Long> |
linkAllDefaultArgs()
Links all the default arguments specified in the
BlockGenus of this to the
specified sockets of this block. |
static Block |
loadBlockFrom(Workspace workspace,
org.w3c.dom.Node node,
java.util.HashMap<java.lang.Long,java.lang.Long> idMapping)
Loads Block information from the specified node and return a Block
instance with the loaded information
|
void |
loadState(java.lang.Object memento) |
void |
notifyRenderable()
Notifies the "views" (in this case the RenderableBlock) of any
changes to the Block data that would need an immediate visual
update.
|
void |
removeSocket(BlockConnector socket)
Removes specified socket
|
void |
removeSocket(int index)
Removes the socket at the specified index
|
void |
setBad(boolean isBad)
Sets the "bad"-ness of this block.
|
void |
setBadMsg(java.lang.String badMsg)
Sets the message describing this block's badness.
|
void |
setBlockLabel(java.lang.String newLabel)
Sets the block label of this iff this block label is editable
|
void |
setFocus(boolean hasFocus)
Sets the focus state of the block.
|
void |
setPageLabel(java.lang.String newPageLabel)
Sets the page label of this
|
void |
setPlug(java.lang.String kind,
BlockConnector.PositionType positionType,
java.lang.String label,
boolean isLabelEditable,
java.lang.Long blockID)
Sets the plug of this.
|
void |
setPlugBlockID(java.lang.Long id)
Sets the block attached to this plug
|
void |
setPlugKind(java.lang.String kind)
Sets the plug kind of this
|
void |
setPlugLabel(java.lang.String label)
Sets the plug label of this
|
boolean |
setProperty(java.lang.String property,
java.lang.String value)
Sets the block property with the specified property and value.
|
boolean |
setSocketAt(int index,
java.lang.String kind,
BlockConnector.PositionType pos,
java.lang.String label,
boolean isLabelEditable,
boolean isExpandable,
java.lang.Long blockID)
Replaces the socket at the specified index with the new specified parameters
|
java.lang.String |
toString() |
static java.lang.Long |
translateLong(Workspace workspace,
java.lang.Long input,
java.util.HashMap<java.lang.Long,java.lang.Long> mapping) |
public Block(Workspace workspace, java.lang.String genusName, java.lang.String label, boolean linkToStubs)
Block instance. Using the genusName specified
of this Block's corresponding BlockGenus, this constructor populates this Block
with its genus information.workspace - The workspace in which this block should be createdgenusName - the name of its associated BlockGenuslabel - the label of this Block.linkToStubs - if true, this block can have stubs and be linked to them;
if false, then this block even though the genus specifies it will not be
linked to stubspublic Block(Workspace workspace, java.lang.String genusName, java.lang.String label)
Block instance. Using the genusName specified
of this Block's corresponding BlockGenus, this constructor populates this Block
with its genus information.workspace - The workspace in which this block should be createdgenusName - the name of its associated BlockGenuslabel - the label of this Block.public Block(Workspace workspace, java.lang.String genusName)
Block instance. Using the genusName specified
of this Block's corresponding BlockGenus, this constructor populates this Block
with its genus information.workspace - The workspace in which this block should be createdgenusName - the name of its associated BlockGenuspublic Block(Workspace workspace, java.lang.String genusName, boolean linkToStubs)
Block instance. Using the genusName specified
of this Block's corresponding BlockGenus, this constructor populates this Block
with its genus information.workspace - The workspace in which this block should be createdgenusName - the name of its associated BlockGenuslinkToStubs - if true, this block can have stubs and be linked to them;
if false, then this block even though the genus specifies it will not be
linked to stubspublic Workspace getWorkspace()
public java.lang.Long getBlockID()
public boolean setProperty(java.lang.String property,
java.lang.String value)
property - the property key to setvalue - the value associated with this propertypublic java.lang.String getBlockLabel()
public boolean hasPageLabel()
public java.lang.String getPageLabel()
public void setBlockLabel(java.lang.String newLabel)
newLabel - the desired labelpublic void setPageLabel(java.lang.String newPageLabel)
newPageLabel - the desired page labelpublic void changeGenusTo(java.lang.String genusName)
genusName - the String name of the BlockGenus to change this Block topublic java.lang.Long getBeforeBlockID()
public java.lang.Long getAfterBlockID()
public BlockConnector getAfterConnector()
public BlockConnector getBeforeConnector()
public void blockConnected(BlockConnector connectedSocket, java.lang.Long connectedBlockID)
public void blockDisconnected(BlockConnector disconnectedSocket)
disconnectedSocket - public java.lang.Iterable<BlockConnector> getSockets()
public int getNumSockets()
public BlockConnector getSocketAt(int index)
index - the index of the desired socket. 0 <= index < getNumSockets()public boolean setSocketAt(int index,
java.lang.String kind,
BlockConnector.PositionType pos,
java.lang.String label,
boolean isLabelEditable,
boolean isExpandable,
java.lang.Long blockID)
index - of the BlockConnector to replaceisLabelEditable - is true iff this BlockConnector can have its labels edited.public int getSocketIndex(BlockConnector socket)
socket - a socket of this blockpublic void addSocket(java.lang.String kind,
BlockConnector.PositionType positionType,
java.lang.String label,
boolean isLabelEditable,
boolean isExpandable,
java.lang.Long blockID)
kind - the socket kind of new socketlabel - the label of the new socketpositionType - the BlockConnector.PositionType of the new connectorisLabelEditable - is true iff this BlockConnector can have its labels edited.isExpandable - true iff this connector can expand to another connectorblockID - the block id of the block attached to new socketpublic BlockConnector addSocket(int index, java.lang.String kind, BlockConnector.PositionType positionType, java.lang.String label, boolean isLabelEditable, boolean isExpandable, java.lang.Long blockID)
index - the index to insert new socket tokind - the socket kind of new socketlabel - the label of the new socketpositionType - the BlockConnector.PositionType of the new connectorisLabelEditable - is true iff this BlockConnector can have its labels edited.isExpandable - true iff this connector can expand to another connectorblockID - the block id of the block attached to new socketpublic void removeSocket(int index)
index - the index of the socket to removepublic void removeSocket(BlockConnector socket)
socket - BlockConnector to remove from thispublic boolean hasPlug()
public BlockConnector getPlug()
public void setPlug(java.lang.String kind,
BlockConnector.PositionType positionType,
java.lang.String label,
boolean isLabelEditable,
java.lang.Long blockID)
kind - the socket kind of pluglabel - the label of the plugpositionType - the BlockConnector.PositionType of this plugisLabelEditable - is true iff this BlockConnector can have its labels edited.blockID - the block id of the block attached to plugpublic void setPlugKind(java.lang.String kind)
kind - the desired plug kindpublic void setPlugLabel(java.lang.String label)
label - the desired plug labelpublic void setPlugBlockID(java.lang.Long id)
id - the block id to attach to this plugpublic java.lang.String getPlugKind()
public java.lang.String getPlugLabel()
public java.lang.Long getPlugBlockID()
public BlockConnector getConnectorTo(java.lang.Long otherBlockID)
otherBlockID - the Block ID if the other blockpublic boolean isBad()
public void setBad(boolean isBad)
isBad - public java.lang.String getBadMsg()
public void setBadMsg(java.lang.String badMsg)
badMsg - public boolean hasFocus()
public void setFocus(boolean hasFocus)
hasFocus - public java.lang.Iterable<java.lang.Long> linkAllDefaultArgs()
BlockGenus of this to the
specified sockets of this block. By default a new Block does not have
default arguments attached. Each index in the Long list corresponds to the index of the socket
the default argument is attached to. If an element in this list is Block.NULL, then no default argument
exists for that socket or there already is a block attached at that socket.
Default arguments are linked whenever a block is dragged to the workspace for the first timepublic java.lang.Iterable<BlockStub> getFreshStubs()
public void notifyRenderable()
public java.util.List<java.lang.String> getSiblingsList()
public boolean hasSiblings()
public java.lang.Iterable<java.lang.String> getStubList()
public boolean hasStubs()
public boolean hasDefaultArgs()
public boolean isCommandBlock()
public boolean isDataBlock()
public boolean isFunctionBlock()
public boolean isVariableDeclBlock()
public boolean isProcedureDeclBlock()
public boolean isDeclaration()
public boolean isProcedureParamBlock()
public boolean isListRelated()
public boolean hasBeforeConnector()
public boolean hasAfterConnector()
public BlockConnector getInitBefore()
public BlockConnector getInitAfter()
public boolean isLabelValue()
public boolean isLabelEditable()
public boolean isPageLabelSetByPage()
public boolean labelMustBeUnique()
public boolean isInfix()
public boolean areSocketsExpandable()
public java.lang.String getGenusName()
public java.lang.String getInitialLabel()
public java.lang.String getLabelPrefix()
public java.lang.String getLabelSuffix()
public java.lang.String getBlockDescription()
public java.lang.String getArgumentDescription(int index)
public java.awt.Color getColor()
public java.util.Map<BlockImageIcon.ImageLocation,BlockImageIcon> getInitBlockImageMap()
public java.lang.String getProperty(java.lang.String property)
property - the property to look uppublic java.lang.Iterable<BlockConnector> getInitSockets()
public BlockConnector getInitPlug()
public java.lang.String toString()
toString in class java.lang.Objectpublic boolean equals(java.lang.Object other)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic org.w3c.dom.Node getSaveNode(org.w3c.dom.Document document,
int x,
int y,
org.w3c.dom.Node commentNode,
boolean isCollapsed)
x - y - public static Block loadBlockFrom(Workspace workspace, org.w3c.dom.Node node, java.util.HashMap<java.lang.Long,java.lang.Long> idMapping)
workspace - The workspace in usenode - Node cantaining desired informationpublic static java.lang.Long translateLong(Workspace workspace, java.lang.Long input, java.util.HashMap<java.lang.Long,java.lang.Long> mapping)
public java.lang.Object getState()
getState in interface ISupportMementopublic void loadState(java.lang.Object memento)
loadState in interface ISupportMemento