Package edu.mit.blocks.codeblocks

Examples of edu.mit.blocks.codeblocks.Block$BlockState


        if (invalidBlock(focusBlock) || !workspace.getEnv().getRenderableBlock(focusBlock).isVisible()) {
            //return focus to canvas if no focusblock does not exist
            setFocus(canvasFocusPoint, Block.NULL);
            return false;
        }
        Block currentBlock = getBlock(focusBlock);
        while (currentBlock != null) {
            if (getBeforeBlock(currentBlock) != null) {
                //return focus to before block
                setFocus(getBeforeBlock(currentBlock));
                return true;
View Full Code Here


        //check invarient
        if (invalidBlock(currentBlock)) {
            throw new RuntimeException("Invariant Violated: may not resurve over a null instance of currentBlock");
        }
        //if plug not null, then let plug be parent of current block
        Block parentBlock = getBlock(currentBlock.getPlugBlockID());
        //otherwise if after not null, then let after be parent of current block
        if (invalidBlock(parentBlock)) {
            parentBlock = getBlock(currentBlock.getBeforeBlockID());
        }
        //if plug and after are both null, then return currentBlock
        if (invalidBlock(parentBlock)) {
            return currentBlock;
        }
        //socket index of current block with respect to its parent
        int i = parentBlock.getSocketIndex(parentBlock.getConnectorTo(currentBlock.getBlockID()));
        //return socket block of parent if one exist
        //int i == 0 if not current block not a socket of parent
        if (i != -1 && i >= 0) {
            for (BlockConnector parentSocket : parentBlock.getSockets()) {
                if (parentSocket == null || invalidBlock(parentSocket.getBlockID()) || parentBlock.getSocketIndex(parentSocket) <= i) {
                    continue;
                } else {
                    return getBlock(parentSocket.getBlockID());
                }
            }
        }
        //return afterblock of parent
        if (invalidBlock(parentBlock.getAfterBlockID())) {
            return getNextNode(parentBlock);
        }
        if (parentBlock.getAfterBlockID().equals(currentBlock.getBlockID())) {
            return getNextNode(parentBlock);
        }
        //This is top of the block, so return currentBlock
        return getBlock(parentBlock.getAfterBlockID());
    }
View Full Code Here

        if (blockID == null || blockID == Block.NULL || workspace.getEnv().getBlock(blockID) == null) {
            throw new RuntimeException("Invariant Violated: may not"
                    + "iterate for outermost block over a null instance of Block");
        }
        //parentBlock is the topmost block in stack
        Block parentBlock = null;
        //go the top most block
        parentBlock = getBeforeBlock(blockID);
        if (parentBlock != null) {
            return getTopOfStack(parentBlock.getBlockID());
        }
        //go to the left most block
        parentBlock = getPlugBlock(blockID);
        if (parentBlock != null) {
            return getTopOfStack(parentBlock.getBlockID());
        }
        //check invariant
        if (parentBlock != null) {
            throw new RuntimeException("Invariant Violated: may not "
                    + "return a null instance of block as the outermost block");
View Full Code Here

        if (block == null || block.getBlockID() == Block.NULL) {
            throw new RuntimeException("Invariant Violated: may not"
                    + "iterate for innermost block over a null instance of Block");
        }
        //returnblock = next deepest node on far right
        Block returnBlock = null;
        // find deepest node, that is, bottom most block in stack.
        returnBlock = getAfterBlock(block);
        if (returnBlock != null) {
            return getBottomRightBlock(returnBlock);
        }
        // move to the next socket in line:
        for (BlockConnector socket : block.getSockets()) {//assumes socket!=null
            Block socketBlock = getBlock(socket.getBlockID());
            if (socketBlock != null) {
                returnBlock = socketBlock;
            }
        }
        if (returnBlock != null) {
View Full Code Here

     *       collection if no blocks are found on this page.
     */
    public Collection<RenderableBlock> getTopLevelBlocks() {
        List<RenderableBlock> topBlocks = new ArrayList<RenderableBlock>();
        for (RenderableBlock renderable : this.getBlocks()) {
            Block block = workspace.getEnv().getBlock(renderable.getBlockID());
            if (block.getPlug() == null || block.getPlugBlockID() == null || block.getPlugBlockID().equals(Block.NULL)) {
                if (block.getBeforeConnector() == null || block.getBeforeBlockID() == null || block.getBeforeBlockID().equals(Block.NULL)) {
                    topBlocks.add(renderable);
                    continue;
                }
            }
        }
View Full Code Here

        if (!labelWithIndex.equals(label)) //only set it if the label actually changed...
        {
            label = labelWithIndex;
        }

        Block block;
        if (myblock instanceof BlockStub) {
            Block parent = ((BlockStub) myblock).getParent();
            block = new BlockStub(workspace, parent.getBlockID(), parent.getGenusName(), parent.getBlockLabel(), myblock.getGenusName());
        } else {
            block = new Block(workspace, myblock.getGenusName(), label);
        }

        // TODO - djwendel - create a copy of the RB properties too, using an RB copy constructor.  Don't just use the genus.
        //RenderableBlock renderable = new RenderableBlock(this.getParentWidget(), block.getBlockID());
        RenderableBlock renderable = new RenderableBlock(workspace, null, block.getBlockID());
View Full Code Here

                    //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;
View Full Code Here

    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;
View Full Code Here

    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;
    }
View Full Code Here

        String genusName = node.getGenusName(); //genusName may not be null
        RenderableBlock renderable = BlockUtilities.getBlock(workspace, genusName, node.getLabel());
        if (renderable == null) {
            throw new RuntimeException("No children block exists for this genus: " + genusName);
        }
        Block block = workspace.getEnv().getBlock(renderable.getBlockID()); //assume not null
        widget.blockDropped(renderable);
        for (int i = 0; i < node.getChildren().size(); i++) {
            BlockConnector socket = block.getSocketAt(i);
            BlockNode child = node.getChildren().get(i);
            RenderableBlock childRenderable = makeRenderable(workspace, child, widget);
            Block childBlock = workspace.getEnv().getBlock(childRenderable.getBlockID());

            //link blocks
            BlockLink link;
            if (childBlock.hasPlug()) {
                link = BlockLinkChecker.canLink(workspace, block, childBlock, socket, childBlock.getPlug());
            } else if (childBlock.hasBeforeConnector()) {
                link = BlockLinkChecker.canLink(workspace, block, childBlock, socket, childBlock.getBeforeConnector());
            } else {
                link = null;
            }//assume link is not null
            link.connect();
            workspace.notifyListeners(new WorkspaceEvent(workspace, workspace.getEnv().getRenderableBlock(link.getPlugBlockID()).getParentWidget(), link, WorkspaceEvent.BLOCKS_CONNECTED));

        }
        if (node.getAfterNode() != null) {
            BlockConnector socket = block.getAfterConnector(); //assume has after connector
            BlockNode child = node.getAfterNode();
            RenderableBlock childRenderable = makeRenderable(workspace, child, widget);
            Block childBlock = workspace.getEnv().getBlock(childRenderable.getBlockID());

            //link blocks
            BlockLink link;
            if (childBlock.hasPlug()) {
                link = BlockLinkChecker.canLink(workspace, block, childBlock, socket, childBlock.getPlug());
            } else if (childBlock.hasBeforeConnector()) {
                link = BlockLinkChecker.canLink(workspace, block, childBlock, socket, childBlock.getBeforeConnector());
            } else {
                link = null;
            }//assume link is not null
            link.connect();
            workspace.notifyListeners(new WorkspaceEvent(workspace, workspace.getEnv().getRenderableBlock(link.getPlugBlockID()).getParentWidget(), link, WorkspaceEvent.BLOCKS_CONNECTED));
View Full Code Here

TOP

Related Classes of edu.mit.blocks.codeblocks.Block$BlockState

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.