codeblocks
Class BlockConnector

java.lang.Object
  extended by codeblocks.BlockConnector
All Implemented Interfaces:
ISupportMemento

public class BlockConnector
extends java.lang.Object
implements ISupportMemento

BlockConnector is a light class that describes the socket/plug information for each socket or plug of a particular Block. Each socket has a kind (i.e. number, String, boolean, etc.), a label, and the block id of the block at that socket (not to be confused with the block that hold the socket information - socket does not have a reference to that parent block).


Nested Class Summary
static class BlockConnector.PositionType
           
 
Constructor Summary
BlockConnector(BlockConnector con)
          Constucts a new BlockConnector by copying the connector information from the specified con.
BlockConnector(java.lang.String kind, BlockConnector.PositionType positionType, java.lang.String label, boolean isLabelEditable, boolean isExpandable, java.lang.Long connBlockID)
          Constructs a new BlockConnector
BlockConnector(java.lang.String kind, BlockConnector.PositionType positionType, java.lang.String label, boolean isLabelEditable, boolean isExpandable, java.lang.String expandGroup, java.lang.Long connBlockID)
          Constructs a new BlockConnector
BlockConnector(java.lang.String label, java.lang.String kind, boolean isLabelEditable, boolean isExpandable)
          Constructs a new BlockConnector with the specified label and kind.
BlockConnector(java.lang.String kind, java.lang.String label, java.lang.Long socketBlockID)
          Constructs a new BlockConnector with a single position
 
Method Summary
 java.lang.Long getBlockID()
          Returns the block id attached (in) this socket
 java.lang.String getExpandGroup()
          Returns the expand group of this connector, or an empty string ("") if the connector is not part of a group.
 java.lang.String getKind()
          Returns the kind of this
 java.lang.String getLabel()
          Returns the label of this
 BlockConnector.PositionType getPositionType()
          Returns the PositionType of this
 java.lang.String getSaveString(java.lang.String conKind)
          Returns the save string of this.
 java.lang.Object getState()
           
 boolean hasBlock()
          Returns true iff a block is attached to this socket; false otherwise
 boolean hasDefArg()
          Returns true is this connector has a default argument; false otherwise
 java.lang.String initKind()
          Returns the initial kind of this
static BlockConnector instantiateFromState(java.lang.Object memento)
          This is a way of generating a BlockConnector from a memento.
 boolean isExpandable()
          Returns true iff this connector is expandable, meaning if a block is connected to it, it may cause another empty connector just like this to appear.
 boolean isLabelEditable()
          Returns true iff this socket's label is editable.
 java.lang.Long linkDefArgument()
          Connects this connector with its default argument, if it has any, and returns the block ID of the connected default argument or Block.NULL if there is none.
static BlockConnector loadBlockConnector(org.w3c.dom.Node node, java.util.HashMap<java.lang.Long,java.lang.Long> idMapping)
          Loads information for a single BlockConnector and returns an instance of BlockConnector with the loaded information
 void loadState(java.lang.Object memento)
           
 void setConnectorBlockID(java.lang.Long id)
          Sets the socket block attached to this connector
 void setDefaultArgument(java.lang.String genusName, java.lang.String label)
          Sets this connector's default argument to the specified genus and initial label.
 void setKind(java.lang.String kind)
          Sets the socket kind of this to the specified kind
 void setLabel(java.lang.String label)
          Sets the socket label of this to specified label
 void setPositionType(BlockConnector.PositionType pos)
          Sets the position type of this connector
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BlockConnector

public BlockConnector(java.lang.String kind,
                      BlockConnector.PositionType positionType,
                      java.lang.String label,
                      boolean isLabelEditable,
                      boolean isExpandable,
                      java.lang.String expandGroup,
                      java.lang.Long connBlockID)
Constructs a new BlockConnector

Parameters:
kind - the kind of this socket
positionType - the PositionType of connector
label - the String label of this socket
isLabelEditable - is true iff this BlockConnector can have its labels edited.
isExpandable - whether this socket can expand into another connector when a block is connected
expandGroup - the expand socket group of this connector
connBlockID - the ID of the block connected to this

BlockConnector

public BlockConnector(java.lang.String kind,
                      BlockConnector.PositionType positionType,
                      java.lang.String label,
                      boolean isLabelEditable,
                      boolean isExpandable,
                      java.lang.Long connBlockID)
Constructs a new BlockConnector

Parameters:
label - the String label of this socket
kind - the kind of this socket
isLabelEditable - is true iff this BlockConnector can have its labels edited.
isExpandable - true if this socket can expand into another connector when a block is connected to this
positionType - specifies the PositionType of connector

BlockConnector

public BlockConnector(java.lang.String kind,
                      java.lang.String label,
                      java.lang.Long socketBlockID)
Constructs a new BlockConnector with a single position

Parameters:
label - the String label of this socket
kind - the kind of this socket
socketBlockID - the block id attached to this socket

BlockConnector

public BlockConnector(java.lang.String label,
                      java.lang.String kind,
                      boolean isLabelEditable,
                      boolean isExpandable)
Constructs a new BlockConnector with the specified label and kind. This new socket does not have an attached block.

Parameters:
label - the String label of this socket
isLabelEditable - is true iff this BlockConnector can have its labels edited.
kind - the kind of this socket

BlockConnector

public BlockConnector(BlockConnector con)
Constucts a new BlockConnector by copying the connector information from the specified con. Copies the con's connector label and kind.

Parameters:
con - the BlockConnector to copy from
Method Detail

getLabel

public java.lang.String getLabel()
Returns the label of this

Returns:
the label of this

getKind

public java.lang.String getKind()
Returns the kind of this

Returns:
the kind of this

initKind

public java.lang.String initKind()
Returns the initial kind of this

Returns:
the initial kind of this

getPositionType

public BlockConnector.PositionType getPositionType()
Returns the PositionType of this

Returns:
the PositionType of this

getBlockID

public java.lang.Long getBlockID()
Returns the block id attached (in) this socket

Returns:
the block id attached (in) this socket

hasBlock

public boolean hasBlock()
Returns true iff a block is attached to this socket; false otherwise

Returns:
true iff a block is attached to this socket; false otherwise

isExpandable

public boolean isExpandable()
Returns true iff this connector is expandable, meaning if a block is connected to it, it may cause another empty connector just like this to appear. Whether or not a block actually appears depends on this connector's parent block. Technically only sockets can expand. Each block can only have one plug (meaning return one value).

Returns:
true iff this connector is expandable; false otherwise

getExpandGroup

public java.lang.String getExpandGroup()
Returns the expand group of this connector, or an empty string ("") if the connector is not part of a group.


setLabel

public void setLabel(java.lang.String label)
Sets the socket label of this to specified label

Parameters:
label - the desired label

isLabelEditable

public boolean isLabelEditable()
Returns true iff this socket's label is editable.

Returns:
true iff this socket's label is editable; false otherwise

setKind

public void setKind(java.lang.String kind)
Sets the socket kind of this to the specified kind

Parameters:
kind - the desired kind

setConnectorBlockID

public void setConnectorBlockID(java.lang.Long id)
Sets the socket block attached to this connector

Parameters:
id - the block id of the desired block to attach

setPositionType

public void setPositionType(BlockConnector.PositionType pos)
Sets the position type of this connector

Parameters:
pos - the desired PositionType for this

hasDefArg

public boolean hasDefArg()
Returns true is this connector has a default argument; false otherwise

Returns:
true is this connector has a default argument; false otherwise

setDefaultArgument

public void setDefaultArgument(java.lang.String genusName,
                               java.lang.String label)
Sets this connector's default argument to the specified genus and initial label.

Parameters:
genusName - the desired BLockGenus name of the default agrument
label - the initial label of the default argument

linkDefArgument

public java.lang.Long linkDefArgument()
Connects this connector with its default argument, if it has any, and returns the block ID of the connected default argument or Block.NULL if there is none.

Returns:
the block ID of the connected default argument or Block.NULL if there is none.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

loadBlockConnector

public static BlockConnector loadBlockConnector(org.w3c.dom.Node node,
                                                java.util.HashMap<java.lang.Long,java.lang.Long> idMapping)
Loads information for a single BlockConnector and returns an instance of BlockConnector with the loaded information

Parameters:
node - the Node containing the desired information
Returns:
BlockConnector instance with the loaded information

getSaveString

public java.lang.String getSaveString(java.lang.String conKind)
Returns the save string of this. save string only includes information that was modifiable and modified

Parameters:
conKind - String containing if this is a socket or plug
Returns:
the save string of this

getState

public java.lang.Object getState()
Specified by:
getState in interface ISupportMemento

loadState

public void loadState(java.lang.Object memento)
Specified by:
loadState in interface ISupportMemento

instantiateFromState

public static BlockConnector instantiateFromState(java.lang.Object memento)
This is a way of generating a BlockConnector from a memento. It's a bit weird since other objects don't have this method, however, it makes the best sense here since BlockConnector is essentially a struct.

Parameters:
memento - The state to load
Returns:
An instance of BlockConnector