/** * @requires none * @modifies focusManager.focusblock && focusManager.focuspoint && blockCanvas * @effects Do nothing if "genusName" does not map to a valid block. Otherwise, create and add a * new block with matching genus and label properties to one of the following: 1. the current * block with focus at (0,0) relative to that block. 2. the current block with focus at next * applicable socket location 3. the canvas at the last mouse click point. If label is not an * empty string, then set the block label to that string. Then update any focus and block * connections. */ protected void automateBlockInsertion( Workspace workspace, TextualFactoryBlock block, String label) { TypeBlockManager typeBlockManager = workspace.getTypeBlockManager(); if (!typeBlockManager.isEnabled()) { System.err.println("AutoMateBlockInsertion invoked but typeBlockManager is disabled."); return; } RenderableBlock createdRB = createRenderableBlock(block); // sets the label of the block to whatever the user typed (should only be numbers) if (label != EMPTY_LABEL_NAME) { createdRB.getBlock().setBlockLabel(label); } // changes the plus number labels back to + if (label.equals(NUMBER_PLUS_OPERATION_LABEL)) { createdRB.getBlock().setBlockLabel(PLUS_OPERATION_LABEL); } // changes the plus text labels back to + if (label.equals(TEXT_PLUS_OPERATION_LABEL)) { createdRB.getBlock().setBlockLabel(PLUS_OPERATION_LABEL); } if (createdRB == null) { return; } else { typeBlockManager.addBlock(createdRB); } }