Package edu.mit.blocks.codeblocks

Examples of edu.mit.blocks.codeblocks.Block


    /**
     * Updates the renderable block with the underlying block's before,
     * after, and plug connectors.
     */
    public void updateConnectors() {
        Block b = workspace.getEnv().getBlock(blockID);
        afterTag.setSocket(b.getAfterConnector());
        beforeTag.setSocket(b.getBeforeConnector());
        plugTag.setSocket(b.getPlug());
    }
View Full Code Here


     */
    private Dimension calcDimensionOfSocket(BlockConnector socket) {
        Dimension finalDimension = new Dimension(0, 0);
        long curBlockID = socket.getBlockID();
        while (curBlockID != Block.NULL) {
            Block curBlock = workspace.getEnv().getBlock(curBlockID);
            //System.out.println("evaluating block :" + curBlock.getBlockLabel());
            RenderableBlock curRenderableBlock = workspace.getEnv().getRenderableBlock(curBlockID);
            Dimension curRBSize = curRenderableBlock.getBlockSize();

            //add height
            finalDimension.height += curRBSize.height;
            //subtract after plug
            if (curBlock.hasAfterConnector()) {
                finalDimension.height -= BlockConnectorShape.CONTROL_PLUG_HEIGHT;
            }
            //set largest width by iterating through to sockets and getting
            //the max width ONLY if curBlockID == connectedToBlockID
            int width = curRBSize.width;

            if (curBlock.getNumSockets() > 0 && !curBlock.isInfix()) {
                int maxSocWidth = getMaxWidthOfSockets(curBlockID);
                //need to add the placeholder width within bottom sockets if maxSocWidth is zero
                if (maxSocWidth == 0) {
                    // Adjust for zoom
                    width += 2 * BlockShape.BOTTOM_SOCKET_SIDE_SPACER * curRenderableBlock.getZoom();
 
View Full Code Here

     * Returns the maximum width of the specified blockID's socket blocks
     * @param blockID the Long blockID of the desired block
     */
    public int getMaxWidthOfSockets(Long blockID) {
        int width = 0;
        Block block = workspace.getEnv().getBlock(blockID);
        RenderableBlock rb = workspace.getEnv().getRenderableBlock(blockID);

        for (BlockConnector socket : block.getSockets()) {
            Dimension socketDim = rb.getSocketSpaceDimension(socket);
            if (socketDim != null) {
                if (socketDim.width > width) {
                    width = socketDim.width;
                }
View Full Code Here

        // if this hasn't been added anywhere, asking its location will break stuff
        if (getParent() == null) {
            return;
        }

        Block b = workspace.getEnv().getBlock(blockID);
        Point socketLocation;
        Point plugLocation;
        RenderableBlock rb;
        Point myScreenOffset = getLocation();
        Point otherScreenOffset;
View Full Code Here

                    return;
                }

                //if this is the first call to mouseDragged
                if (!dragging) {
                    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));
                    }
                    startDragging(this, widget);
View Full Code Here

        }
    }

    protected void genusChanged(String genus) {
        if (widget.hasSiblings()) {
            Block oldBlock = workspace.getEnv().getBlock(blockID);
            oldBlock.changeGenusTo(genus);
            RenderableBlock rb = workspace.getEnv().getRenderableBlock(blockID);
            rb.repaintBlock();
            workspace.notifyListeners(new WorkspaceEvent(workspace, rb.getParentWidget(), blockID, WorkspaceEvent.BLOCK_GENUS_CHANGED));
        }
    }
View Full Code Here

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

    /**
     * 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());
            }
        }
View Full Code Here

            reformBlockShape();
            commentLabelChanged = false;
        }
        if (BlockLinkChecker.hasPlugEquivalent(getBlock())) {
            BlockConnector plug = BlockLinkChecker.getPlugEquivalent(getBlock());
            Block plugBlock = workspace.getEnv().getBlock(plug.getBlockID());
            if (plugBlock != null) {
                if (plugBlock.getConnectorTo(blockID) == null) {
                    throw new RuntimeException("one-sided connection from " + getBlock().getBlockLabel() + " to " + workspace.getEnv().getBlock(blockID).getBlockLabel());
                }
                workspace.getEnv().getRenderableBlock(plug.getBlockID()).updateSocketSpace(plugBlock.getConnectorTo(blockID), blockID, true);
            }
        }
        return false;
    }
View Full Code Here

    public void addBlock(Block block) {

      long id = block.getBlockID();

        if (this.allBlocks.containsKey(id)) {
            Block dup = this.allBlocks.get(id);
            System.out.println("pre-existing block is: " + dup + " with genus " + dup.getGenusName() + " and label " + dup.getBlockLabel());
            assert !this.allBlocks.containsKey(id) : "Block id: " + id + " already exists!  BlockGenus " + block.getGenusName() + " label: " + block.getBlockLabel();
        }

      this.allBlocks.put(id, block);
    }
View Full Code Here

TOP

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

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.