use of edu.mit.blocks.codeblocks.Block in project openblocks by mikaelhg.
the class FactoryManager method workspaceEventOccurred.
public void workspaceEventOccurred(WorkspaceEvent event) {
//IT DOES SOME PREETY STRANGE THINGS
if (event.getEventType() == WorkspaceEvent.BLOCK_ADDED) {
if (event.getSourceWidget() instanceof Page) {
Page page = (Page) event.getSourceWidget();
Block block = workspace.getEnv().getBlock(event.getSourceBlockID());
//block may not be null if this is a block added event
if (block.hasStubs()) {
for (BlockStub stub : block.getFreshStubs()) {
this.addDynamicBlock(new FactoryRenderableBlock(event.getWorkspace(), this, stub.getBlockID()), page.getPageDrawer());
}
}
}
} else if (event.getEventType() == WorkspaceEvent.BLOCK_REMOVED) {
//may not be removing a null stanc eof block, so DO NOT check for it
Block block = workspace.getEnv().getBlock(event.getSourceBlockID());
if (block.hasStubs()) {
for (Long stub : BlockStub.getStubsOfParent(event.getWorkspace(), block)) {
RenderableBlock rb = workspace.getEnv().getRenderableBlock(stub);
if (rb != null && !rb.getBlockID().equals(Block.NULL) && rb.getParentWidget() != null && rb.getParentWidget().equals(this)) {
//rb.getParent() should not be null
rb.getParent().remove(rb);
rb.setParentWidget(null);
}
}
}
this.relayoutBlocks();
} else if (event.getEventType() == WorkspaceEvent.BLOCK_MOVED) {
Block block = workspace.getEnv().getBlock(event.getSourceBlockID());
if (block != null && block.hasStubs()) {
for (Long stub : BlockStub.getStubsOfParent(event.getWorkspace(), block)) {
RenderableBlock rb = workspace.getEnv().getRenderableBlock(stub);
if (rb != null && !rb.getBlockID().equals(Block.NULL) && rb.getParentWidget() != null && rb.getParentWidget().equals(this)) {
//rb.getParent() should not be null
rb.getParent().remove(rb);
rb.setParentWidget(null);
}
}
this.relayoutBlocks();
}
} else if (event.getEventType() == WorkspaceEvent.PAGE_RENAMED) {
//this.relayoutBlocks();
}
}
use of edu.mit.blocks.codeblocks.Block in project openblocks by mikaelhg.
the class BlockUtilities method makeNodeWithChildren.
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;
}
use of edu.mit.blocks.codeblocks.Block in project openblocks by mikaelhg.
the class CollapseLabel method collapseAfterBlocks.
/**
* Toggles visibility of all afterBlocks and their sockets of the given blockID
*/
void collapseAfterBlocks(long blockID) {
Block block = workspace.getEnv().getBlock(blockID);
if (block.getAfterBlockID() != Block.NULL) {
do {
block = workspace.getEnv().getBlock(block.getAfterBlockID());
collapseBlock(block.getBlockID());
} while (block.getAfterBlockID() != Block.NULL);
}
}
use of edu.mit.blocks.codeblocks.Block in project openblocks by mikaelhg.
the class CollapseLabel method collapseSockets.
/**
* Toggles visibility of all blocks connected to sockets
* NB Sockets on procedure blocks do not have afterBlocks
*/
void collapseSockets(Long block_id) {
Block block = workspace.getEnv().getBlock(block_id);
for (BlockConnector socket : block.getSockets()) {
if (socket.getBlockID() != Block.NULL) {
collapseBlock(socket.getBlockID());
collapseAfterBlocks(socket.getBlockID());
}
}
}
use of edu.mit.blocks.codeblocks.Block in project openblocks by mikaelhg.
the class TypeBlockManager method automateMultiplication.
protected void automateMultiplication(Workspace workspace, char character) {
TypeBlockManager typeBlockManager = workspace.getTypeBlockManager();
if (!typeBlockManager.isEnabled()) {
System.err.println("AutoMateMultiplication invoked but typeBlockManager is disabled.");
return;
}
if (!isNullBlockInstance(typeBlockManager.focusManager.getFocusBlockID())) {
Block parentBlock = workspace.getEnv().getBlock(typeBlockManager.focusManager.getFocusBlockID());
if (parentBlock.getGenusName().equals("number")) {
automateBlockInsertion(workspace, "product", null);
return;
}
}
automateAutoComplete(workspace, character);
return;
}
Aggregations