Connection

public class Connection extends Object
implements Cloneable

Describes a connection on a Block. This can be a previous/next connection, an output, or the connection on an Input.

Nested Class Summary

@interface Connection.CheckResultType  
@interface Connection.ConnectionType  

Constant Summary

int CAN_CONNECT
int CONNECTION_TYPE_INPUT An input connection on a block.
int CONNECTION_TYPE_NEXT A next connection on a block.
int CONNECTION_TYPE_OUTPUT An output connection on a block.
int CONNECTION_TYPE_PREVIOUS A previous connection on a block.
int REASON_CHECKS_FAILED
int REASON_MUST_DISCONNECT
int REASON_SELF_CONNECTION
int REASON_TARGET_NULL
int REASON_WRONG_TYPE

Public Constructor Summary

Connection(int type, String[] checks)

Public Method Summary

boolean
canConnect(Connection target)
Check if this can be connected to the target connection.
int
Connection
clone()
static Connection
void
connect(Connection target)
Connect this to another connection.
void
disconnect()
Removes the connection between this and the Connection this is connected to.
double
distanceFrom(Connection other)
Returns the distance between this connection and another connection.
Block
String[]
getConnectionChecks()
Gets the set of checks for this connection.
Input
InputView
getInputView()
Checks if the connection is an input.
WorkspacePoint
Block
Connection
Block
Connection
int
getType()
Gets the type of this connection.
boolean
boolean
boolean
boolean
void
setBlock(Block block)
Sets the block that this connection is part of.
void
setDragMode(boolean dragMode)
void
setInput(Input input)
Sets the input this connection is part of.
void
setPosition(float x, float y)
Sets the position of this connection in the workspace.
void
setShadowConnection(Connection target)
Sets the connection (and shadow block) to use when a normal block isn't connected.

Inherited Method Summary

Constants

public static final int CAN_CONNECT

Constant Value: 0

public static final int CONNECTION_TYPE_INPUT

An input connection on a block. May only be connected to an output connection. This is used by inputs that take a single value block.

Constant Value: 2

public static final int CONNECTION_TYPE_NEXT

A next connection on a block. May only be connected to a previous connection. This is used for the next link on a block and for inputs that connect to a set of statement blocks.

Constant Value: 1

public static final int CONNECTION_TYPE_OUTPUT

An output connection on a block. May only be connected to an input connection. A block may not have both an output and a previous connection. This is only used for the output link on a block.

Constant Value: 3

public static final int CONNECTION_TYPE_PREVIOUS

A previous connection on a block. May only be connected to a next connection. A block may not have both a previous and an output connection. This is only used for the previous link on a block.

Constant Value: 0

public static final int REASON_CHECKS_FAILED

Constant Value: 5

public static final int REASON_MUST_DISCONNECT

Constant Value: 3

public static final int REASON_SELF_CONNECTION

Constant Value: 1

public static final int REASON_TARGET_NULL

Constant Value: 4

public static final int REASON_WRONG_TYPE

Constant Value: 2

Public Constructors

public Connection (int type, String[] checks)

Parameters
type
checks

Public Methods

public boolean canConnect (Connection target)

Check if this can be connected to the target connection.

Parameters
target The connection to check.
Returns
  • True if the target can be connected, false otherwise.

public int canConnectWithReason (Connection target)

Parameters
target The Connection to check compatibility with.
Returns
  • CAN_CONNECT if the connection is legal, an error code otherwise.

public Connection clone ()

Returns
  • A new Connection with the same type and checks but with null block, input and target connection.

public static Connection cloneConnection (Connection conn)

Parameters
conn

public void connect (Connection target)

Connect this to another connection. If the connection is not valid a RuntimeException will be thrown.

Parameters
target The connection to connect to.

public void disconnect ()

Removes the connection between this and the Connection this is connected to. If this is not connected disconnect() does nothing.

public double distanceFrom (Connection other)

Returns the distance between this connection and another connection.

Parameters
other The other Connection to measure the distance to.
Returns
  • The distance between connections.

public Block getBlock ()

Returns
  • The Block this connection belongs to.

public String[] getConnectionChecks ()

Gets the set of checks for this connection. Two Connections may be connected if one of them supports any connection (when this is null) or if they share at least one common check value. For example, {"Number", "Integer", "MyValueType"} and {"AnotherType", "Integer"} would be valid since they share "Integer" as a check.

Returns
  • The set of checks for this connection.

public Input getInput ()

Returns
  • The Input for this connection or null.

public InputView getInputView ()

Checks if the connection is an input. If so, returns the input's view. Otherwise returns null.

Returns
  • The InputView of the Input on this connection, or null if it doesn't have one.

public WorkspacePoint getPosition ()

Returns
  • The input's position in workspace coordinates.

public Block getShadowBlock ()

Returns
  • The shadow Block that is used when no other block is connected or null if it has no shadow block.

public Connection getShadowConnection ()

Returns
  • The shadow block Connection that is used when no other block is connected or null if it has no shadow block.

public Block getTargetBlock ()

Returns
  • The Block this is connected to or null if it is not connected.

public Connection getTargetConnection ()

Returns
  • The Connection this is connected to.

public int getType ()

Returns
  • The type of this connection.

public boolean inDragMode ()

public boolean isConnected ()

Returns
  • True if the target connection is non-null, false otherwise.

public boolean isHighPriority ()

Returns
  • Whether the connection has high priority in the context of bumping connections away.

public boolean isStatementInput ()

public void setBlock (Block block)

Sets the block that this connection is part of.

Parameters
block

public void setDragMode (boolean dragMode)

Parameters
dragMode

public void setInput (Input input)

Sets the input this connection is part of.

Parameters
input

public void setPosition (float x, float y)

Sets the position of this connection in the workspace. An input position only makes sense as part of a rendered block, but workspace coordinates are used to avoid having to update every connection when the scaling of the view changes.

Parameters
x The x position in workspace coordinates.
y The y position in workspace coordinates.

public void setShadowConnection (Connection target)

Sets the connection (and shadow block) to use when a normal block isn't connected. This may only be called on connections that belong to an input (value or statement). This method does not connect the shadow to the visible connection. For that, follow this call with connect():

parentConnection.setShadowConnection(childConnection)
 if (!parentConnection.isConnected()) {
     // If there is no standard child block, so connect the shadow
     parentConnection.connect(childConnection);
 }
 

Parameters
target The connection on the shadow block to use.