本文整理匯總了Java中edu.mit.blocks.codeblocks.BlockStub類的典型用法代碼示例。如果您正苦於以下問題:Java BlockStub類的具體用法?Java BlockStub怎麽用?Java BlockStub使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
BlockStub類屬於edu.mit.blocks.codeblocks包,在下文中一共展示了BlockStub類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: makeNodeWithChildren
import edu.mit.blocks.codeblocks.BlockStub; //導入依賴的package包/類
public static BlockNode makeNodeWithChildren(Workspace workspace, Long blockID) {
if (isNullBlockInstance(workspace, blockID)) {
return null;
}
Block block = workspace.getEnv().getBlock(blockID);
String genus = block.getGenusName();
String parentGenus = block instanceof BlockStub ? ((BlockStub) block).getParentGenus() : null;
String label;
if (!block.labelMustBeUnique() || block instanceof BlockStub) {
label = block.getBlockLabel();
} else {
label = null;
}
BlockNode node = new BlockNode(genus, parentGenus, label);
for (BlockConnector socket : block.getSockets()) {
if (socket.hasBlock()) {
node.addChild(makeNodeWithStack(workspace, socket.getBlockID()));
}
}
return node;
}
示例2: makeNodeWithStack
import edu.mit.blocks.codeblocks.BlockStub; //導入依賴的package包/類
public static BlockNode makeNodeWithStack(Workspace workspace, Long blockID) {
if (isNullBlockInstance(workspace, blockID)) {
return null;
}
Block block = workspace.getEnv().getBlock(blockID);
String genus = block.getGenusName();
String parentGenus = block instanceof BlockStub ? ((BlockStub) block).getParentGenus() : null;
String label;
if (!block.labelMustBeUnique() || block instanceof BlockStub) {
label = block.getBlockLabel();
} else {
label = null;
}
BlockNode node = new BlockNode(genus, parentGenus, label);
for (BlockConnector socket : block.getSockets()) {
if (socket.hasBlock()) {
node.addChild(makeNodeWithStack(workspace, socket.getBlockID()));
}
}
if (block.hasAfterConnector()) {
node.setAfter(makeNodeWithStack(workspace, block.getAfterBlockID()));
}
return node;
}
示例3: revertPoly
import edu.mit.blocks.codeblocks.BlockStub; //導入依賴的package包/類
/**
* The initiation step. We first check that the initial connector (the connector that was disconnected)
* is POLY and can be reverted. If we pass the check, we set the initial connector to its INITIAL TYPE.
* If the block is PROC-RELATED, we stop the recursion. Otherwise, we use the initial connector as the
* SETTER CONN to revert the other POLY connectors. Then we call recursion on connected blocks, with the
* newly reverted POLY CONNs as SETTER CONNs.
*
* (See "Reverting type specifics: " for details on why we need an initial round before recursion.)
*
* @param polyBlock is the block containing the initial connector
* @param polyConn is the initial connector
*/
private void revertPoly(Block polyBlock, BlockConnector polyConn) {
// Check that we can revert the initial connector.
if (!(isInitPoly(polyConn) && canRevertPolyConnectors(polyBlock, Block.NULL)))
return;
// Revert the initial to its INITIAL TYPE
polyConn.setKind(polyConn.initKind());
// Stop recursion if block is PROC-RELATED
if (isProcRelated(polyBlock.getBlockID())) {
polyBlock.notifyRenderable();
if(polyBlock.hasStubs())
BlockStub.parentConnectorsChanged(workspace, polyBlock.getBlockID());
}
// Otherwise set all POLY connectors in the block and begin recursion
else {
for (BlockConnector nextConn : getPolyConnectors(polyBlock)) {
revertPolyKind(nextConn,polyConn);
// Excludes initial connector, which doesn't have a connected block
if (nextConn.hasBlock())
revertPolyConnectors(nextConn,polyBlock.getBlockID());
}
polyBlock.notifyRenderable();
}
}
示例4: staticdrawer
import edu.mit.blocks.codeblocks.BlockStub; //導入依賴的package包/類
private String staticdrawer(BlockStub stub) {
for (FactoryCanvas canvas : this.staticCanvases) {
for (RenderableBlock bl : canvas.getBlocks()) {
if (bl.getGenus().equals(stub.getParentGenus())) {
return canvas.getName();
}
}
}
return null;
}
示例5: textChanged
import edu.mit.blocks.codeblocks.BlockStub; //導入依賴的package包/類
protected void textChanged(String text) {
if ((this.labelType.equals(BlockLabel.Type.NAME_LABEL) || this.labelType.equals(BlockLabel.Type.PORT_LABEL))
&& workspace.getEnv().getBlock(blockID).isLabelEditable()) {
if (this.labelType.equals(BlockLabel.Type.NAME_LABEL)) {
workspace.getEnv().getBlock(blockID).setBlockLabel(text);
}
BlockConnector plug = workspace.getEnv().getBlock(blockID).getPlug();
// Check if we're connected to a block. If we are and the the block we're connected to
// has stubs, update them.
if (plug != null && plug.getBlockID() != Block.NULL) {
if (workspace.getEnv().getBlock(plug.getBlockID()) != null) {
if (workspace.getEnv().getBlock(plug.getBlockID()).isProcedureDeclBlock()
&& workspace.getEnv().getBlock(plug.getBlockID()).hasStubs()) {
// Blocks already store their socket names when saved so it is not necessary
// nor desired to call the connectors changed event again.
if (workspace.getEnv().getRenderableBlock(plug.getBlockID()).isLoading()) {
BlockStub.parentConnectorsChanged(workspace, plug.getBlockID());
}
}
}
}
RenderableBlock rb = workspace.getEnv().getRenderableBlock(blockID);
if (rb != null) {
workspace.notifyListeners(new WorkspaceEvent(workspace, rb.getParentWidget(), blockID, WorkspaceEvent.BLOCK_RENAMED));
}
}
}
示例6: finishLoad
import edu.mit.blocks.codeblocks.BlockStub; //導入依賴的package包/類
/**
* After loading canvas, does a final sweep of all procedures to update
* myProcInfo. It does this by going through each output block and seeing
* if that output contributes any information to a procedure.
* Then it updates the procedure's stubs if the procedure type changes.
*
* Called after regular loading is finished (WorkspaceController.LoadSaveString()).
*
* Updating myProcInfo depends on one crucial assumption:
* The types of all outputs should be consistent because they were handled
* prior to the original saving with the POM (so the loaded version is correct).
* Therefore, we DO NOT need to:
* change the types of empty output sockets
* revert the types of incorrect output sockets
* disconnect incorrect output types
*/
public static void finishLoad() {
// Create new output info for each procedure on the canvas.
for(Block p : workspace.getBlocksFromGenus("procedure")) {
myProcInfo.put(p.getBlockID(), new OutputInfo());
}
// Update myProcInfo by checking each output.
for(Block b : workspace.getBlocksFromGenus("return")) {
// Only handle the output blocks that are connected to a procedure.
Long top = getTopBlockID(b.getBlockID());
if (top != null && workspace.getEnv().getBlock(top).isProcedureDeclBlock()) {
//System.out.println("procedure (top) number "+top);
OutputInfo info = myProcInfo.get(top);
// Check that the output hasn't already been visited (shouldn't have but just to be safe...)
if (!info.outputs.contains(b)) {
// Change the procedure type if it has not been set and is not of the generic type poly.
if (info.type == null && !b.getSocketAt(0).getKind().equals("poly")) {
info.type = b.getSocketAt(0).getKind();
// Update stubs due to change in type
BlockStub.parentPlugChanged(workspace, top, info.type);
}
// Increase the number of typed outputs (aka connected outputs without empty sockets).
if (b.getSocketAt(0).getBlockID() != -1) {
info.numTyped++;
}
// Add all outputs that have not already been added (regardless of type or empty/nonempty sockets).
info.outputs.add(b.getBlockID());
}
//System.out.println("numtyped "+info.numTyped+" type "+info.type);
}
}
}
示例7: blocksDisconnected
import edu.mit.blocks.codeblocks.BlockStub; //導入依賴的package包/類
/**
* When blocks are disconnected, update the proc stack and revert any
* affected output blocks/callers.
*/
private static void blocksDisconnected(WorkspaceWidget w, Long socket, Long plug) {
// Don't do anything if we're not in a procedure stack.
Long top = getTopBlockID(socket);
if (top == null || !workspace.getEnv().getBlock(top).isProcedureDeclBlock()) return;
// Revert any output blocks in the disconnected stack.
OutputInfo info = myProcInfo.get(top);
if (isOutput(workspace.getEnv().getBlock(socket)) && info.type != null) {
// PolyRule reverts this to "poly" so we have to change it
// back to whatever type it should be.
info.numTyped--;
workspace.getEnv().getBlock(socket).getSocketAt(0).setKind(info.type);
workspace.getEnv().getBlock(socket).notifyRenderable();
}
else
revertType(workspace.getEnv().getBlock(plug), info, true);
// If there are no more connected blocks in this procedure, remove
// the type and revert current output blocks.
if (info.numTyped == 0) {
info.type = null;
revertType(workspace.getEnv().getBlock(top), info, false);
BlockStub.parentPlugChanged(workspace, top, null);
}
}
示例8: getParent
import edu.mit.blocks.codeblocks.BlockStub; //導入依賴的package包/類
/** Returns parent of stub, or null if parent does not exist or if b is not a stub. */
public static Block getParent(Block b) {
if (b instanceof BlockStub) {
Block parent = ((BlockStub) b).getParent();
if (parent != null &&
workspace.getEnv().getRenderableBlock(parent.getBlockID()).getParentWidget() != null)
{
return parent;
}
}
return null;
}
示例9: getBlock
import edu.mit.blocks.codeblocks.BlockStub; //導入依賴的package包/類
/**
* Returns a new RenderableBlock instance with the matching genusName.
* New block will also have matching label is label is not-null. May return null.
*
* @param workspace The workspace to use
* @param genusName
* @param label
*
* @requires if block associated with genusName has a non editable
* or unique block label, then "label" MUST BE NULL.
* @return A new RenderableBlock with matching genusName and label (if label is not-null).
* If no matching blocks were found, return null.
*/
public static RenderableBlock getBlock(Workspace workspace, String genusName, String label) {
if (genusName == null) {
return null;
}
// find all blocks on the page and look for any match
for (Block block : workspace.getBlocks()) {
//make sure we're not dealing with null blocks
if (block == null || block.getBlockID() == null || block.getBlockID().equals(Block.NULL)) {
continue;
}
//find the block with matching genus and either a matching label or an editable label
if (block.getGenusName().equals(genusName) && (block.isLabelEditable() || block.getBlockLabel().equals(label)
|| block.isInfix())) {
//for block stubs, need to make sure that the label matches because stubs of the same kind
//(i.e. global var getters, agent var setters, etc.) have the same genusName
//but stubs of different parents do not share the same label
if (block instanceof BlockStub && !block.getBlockLabel().equals(label)) {
continue;
}
//create new renderable block instance
RenderableBlock renderable = BlockUtilities.cloneBlock(block);
//make sure renderable block is not a null instance of a block
if (renderable == null || renderable.getBlockID().equals(Block.NULL)) {
throw new RuntimeException("Invariant Violated: a valid non null blockID just"
+ "returned a null instance of RenderableBlock");
//please throw an exception here because it wouldn't make any sense
//if the Block is valid but it's associated RenderableBlock is not
}
//do not drop down default arguments
renderable.ignoreDefaultArguments();
//get corresponding block
Block newblock = workspace.getEnv().getBlock(renderable.getBlockID());
//make sure corresponding block is not a null instance of block
if (newblock == null || newblock.getBlockID().equals(Block.NULL)) {
throw new RuntimeException("Invariant Violated: a valid non null blockID just"
+ "returned a null instance of Block");
//please throw an exception here because it wouldn't make any sense
//if the Block is valid but it's associated RenderableBlock is not
}
//attempt to set the label text if possible as defined by the specs
//should not set the labels of block stubs because their labels are determined by their parent
if ((block.isLabelEditable() || block.getBlockLabel().equals(label))) {
if (label != null && !(block instanceof BlockStub)) {
if (newblock.isLabelEditable() && !newblock.labelMustBeUnique()) {
newblock.setBlockLabel(label);
}
}
}
//return renderable block
return renderable;
}
/////////////////////////////////////
//TODO: Add code here for nicknames//
/////////////////////////////////////
}
//TODO: the part below is a hack. If there are other types of blocks, we need to account for them
return null;
}
示例10: blocksConnected
import edu.mit.blocks.codeblocks.BlockStub; //導入依賴的package包/類
/**
* When blocks are connected, check to see whether we are in a proc
* stack. If so, check to see whether we should update the output type,
* and if any existing blocks are affected by this change.
*/
private static void blocksConnected(WorkspaceWidget w, Long socket, Long plug) {
// Don't do anything if we're not in a procedure stack.
Long top = getTopBlockID(socket);
if (top == null || !workspace.getEnv().getBlock(top).isProcedureDeclBlock()) return;
// If the proc stack already has a type, change all outputs in the
// new part to that type and disconnect anything that doesn't fit.
OutputInfo info = myProcInfo.get(top);
List<WorkspaceEvent> events = new ArrayList<WorkspaceEvent>();
Block b = workspace.getEnv().getBlock(socket);
// If the block was added to an output block,
// then b is the parent block (socket = output) and add is false.
// else b is the current block (plug) and add is true.
// in changeType, we check if b is type output before proceeding.
boolean add = true;
if (isOutput(b))
add = false; // don't add the output twice to the list
else
b = workspace.getEnv().getBlock(plug);
if (info.type != null)
changeType(add, b, info.type, info, w, events);
else {
// Examine the type. If there is a type in the new portion of
// the stack, reset all the previous output blocks to that type.
examineType(add, b, info);
if (info.type != null) {
changeType(info, w, events);
BlockStub.parentPlugChanged(workspace, top, info.type);
}
}
// Fire events.
if (!events.isEmpty()) {
//WorkspaceController.getInstance().notifyListeners(events);
for (WorkspaceEvent e : events) {
workspace.notifyListeners(e);
}
}
}
示例11: isProcedureCall
import edu.mit.blocks.codeblocks.BlockStub; //導入依賴的package包/類
/** returns true if "vm-command-name" property = "eval-procedure" */
public static boolean isProcedureCall(Block b) {
return b != null &&
CMD_EVAL_PROCEDURE.equals(b.getProperty(VM_COMMAND_NAME)) &&
b instanceof BlockStub;
}