Package edu.mit.blocks.codeblocks

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


        //Do not delete null block references.  Otherwise, get Block and RenderableBlock instances.
        if (isNullBlockInstance(focusManager.getFocusBlockID())) {
            throw new RuntimeException("TypeBlockManager: deleting a null block references.");
        }
        Block block = workspace.getEnv().getBlock(focusManager.getFocusBlockID());
        RenderableBlock renderable = workspace.getEnv().getRenderableBlock(block.getBlockID());

        //get workspace widget associated with current focus
        WorkspaceWidget widget = renderable.getParentWidget();
        //do not delete block instances in null widgets
        if (widget == null) {
            throw new RuntimeException("TypeBlockManager: do not delete blocks with no parent widget.");
            //return;
        }
        //get parent container of this graphical representation
        Container container = renderable.getParent();
        //do not delete block instances in null parents
        if (container == null) {
            throw new RuntimeException("TypeBlockManager: do not delete blocks with no parent container.");
            //return;
        }
        //get the Block's location on the canvas
        Point location = SwingUtilities.convertPoint(
                renderable, new Point(0, 0), this.blockCanvas.getCanvas());

        //for every valid and active connection, disconnect it.
        Long parentID = null;
        if (validConnection(block.getPlug())) {
            parentID = block.getPlugBlockID();
            this.disconnectBlock(block, widget);
            if (validConnection(block.getAfterConnector())) {
                disconnectBlock(workspace.getEnv().getBlock(block.getAfterBlockID()), widget);
            }
        } else if (validConnection(block.getBeforeConnector())) {
            parentID = block.getBeforeBlockID();
            BlockConnector parentConnectorToBlock = workspace.getEnv().getBlock(parentID).getConnectorTo(block.getBlockID());
            this.disconnectBlock(block, widget);
            if (validConnection(block.getAfterConnector())) {
                Long afterBlockID = block.getAfterBlockID();
                disconnectBlock(workspace.getEnv().getBlock(afterBlockID), widget);
                if (parentID != null) {
                    BlockLink link = BlockLinkChecker.canLink(
                            workspace,
                            workspace.getEnv().getBlock(parentID),
                            workspace.getEnv().getBlock(afterBlockID),
                            parentConnectorToBlock,
                            workspace.getEnv().getBlock(afterBlockID).getBeforeConnector());
                    if (link != null) {
                        link.connect();
                        workspace.notifyListeners(new WorkspaceEvent(
                                workspace,
                                workspace.getEnv().getRenderableBlock(link.getPlugBlockID()).getParentWidget(),
                                link, WorkspaceEvent.BLOCKS_CONNECTED));
                        workspace.getEnv().getRenderableBlock(link.getPlugBlockID()).repaintBlock();
                        workspace.getEnv().getRenderableBlock(link.getPlugBlockID()).repaint();
                        workspace.getEnv().getRenderableBlock(link.getPlugBlockID()).moveConnectedBlocks();
                        workspace.getEnv().getRenderableBlock(link.getSocketBlockID()).repaintBlock();
                        workspace.getEnv().getRenderableBlock(link.getSocketBlockID()).repaint();

                    }
                }
            }
        } else if (validConnection(block.getAfterConnector())) {
            parentID = block.getAfterBlockID();
        }

        //remove form widget and container
        this.removeChildrenBlock(renderable, widget, container);
View Full Code Here


        }
        BlockConnector childPlug = BlockLinkChecker.getPlugEquivalent(childBlock);
        if (childPlug == null || !childPlug.hasBlock() || isNullBlockInstance(childPlug.getBlockID())) {
            return;
        }
        Block parentBlock = workspace.getEnv().getBlock(childPlug.getBlockID());
        BlockConnector parentSocket = parentBlock.getConnectorTo(childBlock.getBlockID());
        if (parentSocket == null) {
            return;
        }
        //disconector if child connector exists and has a block connected to it
        BlockLink link = BlockLink.getBlockLink(workspace, childBlock, parentBlock, childPlug, parentSocket);
        if (link == null) {
            return;
        }

        link.disconnect();

        RenderableBlock parentRenderable = workspace.getEnv().getRenderableBlock(parentBlock.getBlockID());
        if (parentRenderable == null) {
            throw new RuntimeException("INCONSISTANCY VIOLATION: "
                    + "parent block was valid, non-null, and existed.\n\tBut yet, when we get it's renderable"
                    + "representation, we recieve a null instance.\n\tIf the Block instance of an ID is non-null"
                    + "then its graphical RenderableBlock should be non-null as well");
View Full Code Here

        if (isNullBlockInstance(parentBlockID)) {
            //focus on canvas
            automateBlockInsertion(workspace, "number", "-");

        } else {
            Block parentBlock = workspace.getEnv().getBlock(parentBlockID);
            if (parentBlock.isDataBlock()) {
                //focus on a data block
                automateBlockInsertion(workspace, "difference", null);
            } else {
                //focus on a non-data block
                automateBlockInsertion(workspace, "number", "-");
View Full Code Here

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

        Long parentBlockID = typeBlockManager.focusManager.getFocusBlockID();
        if (isNullBlockInstance(parentBlockID)) {
            //focus on canvas
            automateBlockInsertion(workspace, "sum", null);
        } else {
            Block parentBlock = workspace.getEnv().getBlock(parentBlockID);
            if (parentBlock.getGenusName().equals("string")) {
                //focus on string block
                automateBlockInsertion(workspace, "string-append", null);
            } else if (parentBlock.getGenusName().equals("string-append")) {
                //focus on string append block
                automateBlockInsertion(workspace, "string-append", null);
            } else {
                //focus on any other block
                automateBlockInsertion(workspace, "sum", null);
View Full Code Here

     */
    public Iterable<Block> getBlocksFromGenus(String genusName) {
        //TODO: performance issue, must iterate through all blocks
        ArrayList<Block> blocks = new ArrayList<Block>();
        for (RenderableBlock renderable : blockCanvas.getBlocks()) {
            Block block = getEnv().getBlock(renderable.getBlockID());
            if (block.getGenusName().equals(genusName)) {
                blocks.add(block);
            }
        }
        return blocks;
    }
View Full Code Here

        assert memento instanceof WorkspaceState : "";
        if (memento instanceof WorkspaceState) {
            WorkspaceState state = (WorkspaceState) memento;
            //Load the blocks state
            for (Long blockID : state.blockStates.keySet()) {
                Block toBeUpdated = getEnv().getBlock(blockID);
                toBeUpdated.loadState(state.blockStates.get(blockID));
            }
            //Load the canvas state
            blockCanvas.loadState(state.blockCanvasState);
        }
    }
View Full Code Here

        if (invalidBlock(focusBlock) || !workspace.getEnv().getRenderableBlock(focusBlock).isVisible()) {
            setFocus(canvasFocusPoint, Block.NULL);
            return false;
        }
        //give focus to any preceeding socket of current block
        Block currentBlock = getBlock(focusBlock);
        for (BlockConnector socket : currentBlock.getSockets()) {
            if (socket != null && !invalidBlock(socket.getBlockID())) {
                //give focus to socket block
                setFocus(socket.getBlockID());
                return true;
            }
        }
        //give focus to after block of current block
        Long afterBlock = currentBlock.getAfterBlockID();
        if (!invalidBlock(afterBlock)) {
            setFocus(afterBlock);
            return true;
        }
        //current block != null.....invariant checke in getNextNode()
        Block nextBlock = this.getNextNode(currentBlock);
        //check invariant
        if (nextBlock == null) {
            throw new RuntimeException("Invariant Violated: return value of getNextNode() may not be null");
        }
        //set focus
        setFocus(nextBlock.getBlockID());
        return true;
    }
View Full Code Here

        if (invalidBlock(focusBlock) || !workspace.getEnv().getRenderableBlock(focusBlock).isVisible()) {
            setFocus(canvasFocusPoint, Block.NULL);
            return false;
        }

        Block currentBlock = getBlock(focusBlock);
        //set plug to be previous block
        Block previousBlock = getPlugBlock(currentBlock);
        //if plug is null, set before to be previous block
        if (previousBlock == null) {
            previousBlock = getBeforeBlock(currentBlock);
        }
        //If before is ALSO null, jump to bottom of the stack;
        if (previousBlock == null) {
            previousBlock = getBottomRightBlock(currentBlock);
        } else {
            //If at least a plug block OR (but not both) before block exist,
            //then get innermost block of the previous socket of the previous block
            //assumes previousBlock.getSockets is not empty, not null
            Block beforeBlock = previousBlock;
            //ASSUMPTION BEING MADE: assume that the list below is constructed to
            //have all the sockets FOLLOWED by FOLLOWED by the after connector
            //THE ORDER MUST BE KEPT TO WORK CORRECTLY!  We cannot use
            //BlockLinkChecker.getSocketEquivalents because the specification does
            //not guarantee this precise ordering.  Futhermore, an interable
            //has no defined order.  However, as of this writing, the current implementation
            //of that method does seem to produce this ordering.  But we're still not using it.
            List<BlockConnector> connections = new ArrayList<BlockConnector>();
            for (BlockConnector socket : previousBlock.getSockets()) {
                connections.add(socket); //add sockets
            }
            connections.add(previousBlock.getAfterConnector()); //add after connector
            //now traverse the connections
            for (BlockConnector connector : connections) {
                if (connector == null || connector.getBlockID() == Block.NULL || getBlock(connector.getBlockID()) == null) {
                    continue; //if null socket, move on to next socket
                }
                if (connector.getBlockID().equals(currentBlock.getBlockID())) { //reached back to current block
                    if (!beforeBlock.getBlockID().equals(previousBlock.getBlockID())) {
                        //if previous block was never updated, go to bottom of stack
                        previousBlock = getBottomRightBlock(previousBlock);
                    }
                    setFocus(previousBlock.getBlockID());
                    return true;
View Full Code Here

        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 (getAfterBlock(currentBlock) != null) {
                //return focus to before block
                setFocus(getAfterBlock(currentBlock));
                return true;
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.