Package edu.mit.blocks.codeblocks

Examples of edu.mit.blocks.codeblocks.BlockLink


            if (pickedUp) {
                dragHandler.mouseReleased(e);

                //if the block was dragged before...then
                if (dragging) {
                    BlockLink link = getNearbyLink(); //look for nearby link opportunities
                    WorkspaceWidget widget = null;

                    // if a suitable link wasn't found, just drop the block
                    if (link == null) {
                        widget = lastDragWidget;
                        stopDragging(this, widget);
                    } // otherwise, if a link WAS found...
                    else {

                        /* Make sure that no matter who's connecting to whom, the block
                        * that's being dragged gets dropped on the parent widget of the
                        * block that's already on the canvas.
                        */
                        if (blockID.equals(link.getSocketBlockID())) {
                            // dragged block is the socket block, so take plug's parent.
                            widget = workspace.getEnv().getRenderableBlock(link.getPlugBlockID()).getParentWidget();
                        } else {
                            // dragged block is the plug block, so take the socket block's parent.
                            widget = workspace.getEnv().getRenderableBlock(link.getSocketBlockID()).getParentWidget();
                        }

                        // drop the block and connect its link
                        stopDragging(this, widget);
                        link.connect();
                        workspace.notifyListeners(new WorkspaceEvent(workspace, widget, link, WorkspaceEvent.BLOCKS_CONNECTED));
                        workspace.getEnv().getRenderableBlock(link.getSocketBlockID()).moveConnectedBlocks();
                    }

                    //set the locations for X and Y based on zoom at 1.0
                    this.unzoomedX = this.calculateUnzoomedX(this.getX());
                    this.unzoomedY = this.calculateUnzoomedY(this.getY());
View Full Code Here


                    Block block = getBlock();
                    BlockConnector plug = BlockLinkChecker.getPlugEquivalent(block);
                    if (plug != null && plug.hasBlock()) {
                        Block parent = workspace.getEnv().getBlock(plug.getBlockID());
                        BlockConnector socket = parent.getConnectorTo(blockID);
                        BlockLink link = BlockLink.getBlockLink(workspace, block, parent, plug, socket);
                        link.disconnect();
                        //socket is removed internally from block's socket list if socket is expandable
                        workspace.getEnv().getRenderableBlock(parent.getBlockID()).blockDisconnected(socket);

                        //NOTIFY WORKSPACE LISTENERS OF DISCONNECTION
                        workspace.notifyListeners(new WorkspaceEvent(workspace, widget, link, WorkspaceEvent.BLOCKS_DISCONNECTED));
View Full Code Here

                //continue for invalid sockets
                if (invalidConnector(socket)) {
                    continue;
                }
                //if valid, then get link
                BlockLink link = BlockLinkChecker.canLink(workspace, child, parent, socket, parent.getPlug());
                //if link is invalid, continue
                if (link == null) {
                    continue;
                }
                //if link is valid, then rturn it
                return link;
            }
        }

        //for every socket in parent, see if it can connect
        //to the child's plug:
        // P-socket <====== C-plug
        if (child.hasPlug()) {
            for (BlockConnector socket : parent.getSockets()) {
                //continue if invalid socket
                //Since we want block insertion between blocks, we don't
                //want to do a total invaliCOnector check (which tests for hasBlock())
                //if (invalidConnector(socket)) continue;
                if (socket == null) {
                    continue;
                }

                if (child.isInfix()) {
                    //TAKE SPECIAL CARE FOR INFIX BLOCKS
                    //we want to recurse to the top level infix block
                    if (parent.isInfix()) {
                        continue;
                    }
                    //if valid, the get link
                    BlockLink link = BlockLinkChecker.canLink(workspace, parent, child, socket, child.getPlug());
                    //if link is invalid, continue
                    if (link == null) {
                        continue;
                    }
                    //if link is valid, then rturn it
                    return link;
                } else {
                    //Don't NEED TO RECURSE for non-infix blocks
                    //if valid, the get link
                    BlockLink link = BlockLinkChecker.canLink(workspace, parent, child, socket, child.getPlug());
                    //if link is invalid, continue
                    if (link == null) {
                        continue;
                    }
                    //if link is valid, then rturn it
                    return link;
                }
            }
        }

        //for every socket in parent, see if it can connect
        //to the child's before
        // P-socket <======= C-before
        if (child.hasBeforeConnector()) {
            for (BlockConnector socket : parent.getSockets()) {
                //continue if invalid socket
                if (invalidConnector(socket)) {
                    continue;
                }
                //if valid, the get link
                BlockLink link = BlockLinkChecker.canLink(workspace, parent, child, socket, child.getBeforeConnector());
                //if link is invalid, continue
                if (link == null) {
                    continue;
                }
                //if link is valid, then rturn it
                return link;
            }
        }


        //see if we can connect the child's before
        //to the parent's after
        // P-after <===== C-before
        if (child.hasBeforeConnector()) {
            if (parent.hasAfterConnector()) {
                //before and after connectors exists
                BlockLink link = BlockLinkChecker.canLink(workspace, parent, child, parent.getAfterConnector(), child.getBeforeConnector());
                //if link is invalid, continue
                if (link == null) {
                    //continue;
                } else {
                    //if link is valid, then rturn it
                    return link;
                }
            }
        }


        //see if we can connect the child's after to
        //the parent's before
        // C-after <====== P-before
        if (child.hasAfterConnector()) {
            if (parent.hasBeforeConnector()) {
                //before and after connectors exists
                BlockLink link = BlockLinkChecker.canLink(workspace, child, parent, child.getAfterConnector(), parent.getBeforeConnector());
                //if link is invalid, continue
                if (link == null) {
                    //continue;
                } else {
                    //if link is valid, then rturn it
View Full Code Here

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

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

    public void actionPerformed(ActionEvent e) {
        if (childBlock.getLocation().distance(focusPoint) < 75) {
            //if parent block exist, then preform automatic linking
            childBlock.setLocation(focusPoint);
            if (parentBlock != null && parentBlock.getBlockID() != null && !parentBlock.getBlockID().equals(Block.NULL)) {
                BlockLink link = LinkFinderUtil.connectBlocks(workspace, workspace.getEnv().getBlock(childBlock.getBlockID()), workspace.getEnv().getBlock(parentBlock.getBlockID()));
                if (link == null) {
                    dropBlock(childBlock);
                    childBlock.repaintBlock();
                    childBlock.repaint();
                } else {
                    // drop and link the new block
                    link.connect();
                    dropBlock(childBlock);

                    workspace.notifyListeners(new WorkspaceEvent(
                            workspace,
                            workspace.getEnv().getRenderableBlock(link.getPlugBlockID()).getParentWidget(),
                            link, WorkspaceEvent.BLOCKS_CONNECTED));
                    workspace.getEnv().getRenderableBlock(link.getSocketBlockID()).moveConnectedBlocks();
                    workspace.getEnv().getRenderableBlock(link.getSocketBlockID()).repaintBlock();
                    workspace.getEnv().getRenderableBlock(link.getSocketBlockID()).repaint();
                }
            } else {
                dropBlock(childBlock);
                childBlock.repaintBlock();
                childBlock.repaint();
View Full Code Here

            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));

        }
        return renderable;
    }
View Full Code Here

TOP

Related Classes of edu.mit.blocks.codeblocks.BlockLink

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.