Search in sources :

Example 6 with Block

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();
    }
}
Also used : FactoryRenderableBlock(edu.mit.blocks.renderable.FactoryRenderableBlock) RenderableBlock(edu.mit.blocks.renderable.RenderableBlock) FactoryRenderableBlock(edu.mit.blocks.renderable.FactoryRenderableBlock) Block(edu.mit.blocks.codeblocks.Block) RenderableBlock(edu.mit.blocks.renderable.RenderableBlock) FactoryRenderableBlock(edu.mit.blocks.renderable.FactoryRenderableBlock) BlockStub(edu.mit.blocks.codeblocks.BlockStub)

Example 7 with Block

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;
}
Also used : Block(edu.mit.blocks.codeblocks.Block) BlockStub(edu.mit.blocks.codeblocks.BlockStub) BlockConnector(edu.mit.blocks.codeblocks.BlockConnector)

Example 8 with Block

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);
    }
}
Also used : Block(edu.mit.blocks.codeblocks.Block)

Example 9 with Block

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());
        }
    }
}
Also used : Block(edu.mit.blocks.codeblocks.Block) BlockConnector(edu.mit.blocks.codeblocks.BlockConnector)

Example 10 with Block

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;
}
Also used : Block(edu.mit.blocks.codeblocks.Block) RenderableBlock(edu.mit.blocks.renderable.RenderableBlock) TextualFactoryBlock(edu.mit.blocks.renderable.TextualFactoryBlock)

Aggregations

Block (edu.mit.blocks.codeblocks.Block)29 RenderableBlock (edu.mit.blocks.renderable.RenderableBlock)15 BlockConnector (edu.mit.blocks.codeblocks.BlockConnector)14 Point (java.awt.Point)7 BlockStub (edu.mit.blocks.codeblocks.BlockStub)5 TextualFactoryBlock (edu.mit.blocks.renderable.TextualFactoryBlock)5 WorkspaceEvent (edu.mit.blocks.workspace.WorkspaceEvent)5 BlockLink (edu.mit.blocks.codeblocks.BlockLink)4 FactoryRenderableBlock (edu.mit.blocks.renderable.FactoryRenderableBlock)3 ArrayList (java.util.ArrayList)3 WorkspaceWidget (edu.mit.blocks.workspace.WorkspaceWidget)2 Color (java.awt.Color)2 Dimension (java.awt.Dimension)2 Matcher (java.util.regex.Matcher)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 Workspace (edu.mit.blocks.workspace.Workspace)1 Container (java.awt.Container)1 LinkedHashMap (java.util.LinkedHashMap)1 StringTokenizer (java.util.StringTokenizer)1