Package edu.mit.blocks.codeblocks

Examples of edu.mit.blocks.codeblocks.BlockConnector$DefArgument


            if (tag.getLabel() != null) {
                this.remove(tag.getLabel().getJComponent());
            }
        }
        for (int i = 0; i < getBlock().getNumSockets(); i++) {
            BlockConnector socket = getBlock().getSocketAt(i);
            ConnectorTag tag = this.getConnectorTag(socket);
            if (tag == null) {
                tag = new ConnectorTag(socket);
                if (SocketLabel.ignoreSocket(socket)) {
                    tag.setLabel(null); //ignored sockets have no labels
                } else {
                    SocketLabel label = new SocketLabel(workspace, socket, socket.getLabel(), BlockLabel.Type.PORT_LABEL, socket.isLabelEditable(), blockID);
                    String argumentToolTip = getBlock().getArgumentDescription(i);
                    if (argumentToolTip != null) {
                        label.setToolTipText(getBlock().getArgumentDescription(i).trim());
                    }
                    tag.setLabel(label);
                    label.setZoomLevel(this.getZoom());
                    label.setText(socket.getLabel());
                    this.add(label.getJComponent());
                    changed = true;
                }
            } else {
                SocketLabel label = tag.getLabel();
                if (!SocketLabel.ignoreSocket(socket)) {
                    //ignored bottom sockets or sockets with label == ""
                    if (label == null) {
                        label = new SocketLabel(workspace, socket, socket.getLabel(), BlockLabel.Type.PORT_LABEL, socket.isLabelEditable(), blockID);
                        String argumentToolTip = getBlock().getArgumentDescription(i);
                        if (argumentToolTip != null) {
                            label.setToolTipText(getBlock().getArgumentDescription(i).trim());
                        }
                        tag.setLabel(label);
                        label.setText(socket.getLabel());
                        this.add(label.getJComponent());
                        changed = true;
                    } else {
                        label.setText(socket.getLabel());
                        this.add(label.getJComponent());
                        changed = true;
                    }
                    label.setZoomLevel(this.getZoom());
                }
View Full Code Here


        // May possibly be done better if synchronizeSockets is rewritten. It has to be written such that
        // it doesn't remove the sockets' JComponents/remake them. Currently relies on the synchronizeSockets()
        // call in getSocketPixelPoint(BlockConnector) to make sure the dimensions and number of sockets
        // are consistent.
        for (int i = 0; i < getBlock().getNumSockets(); i++) {
            BlockConnector socket = getBlock().getSocketAt(i);
            ConnectorTag tag = this.getConnectorTag(socket);
            if (tag != null) {
                if (tag.getLabel() != null) {
                    if (!tag.getLabel().getText().equals(socket.getLabel())) {
                        socketLabelsChanged = synchronizeSockets();
                        break;
                    }
                }
            }
            if (!socket.isLabelEditable()) {
                socketLabelsChanged = synchronizeSockets();
                break;
            }
        }
        if (blockLabelChanged) {
            blockLabel.setText(getBlock().getBlockLabel());
        }
        if (pageLabelChanged) {
            pageLabel.setText(getBlock().getPageLabel());
        }
        if (blockLabelChanged || pageLabelChanged || socketLabelsChanged || commentLabelChanged) {
            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 linkDefArgs() {
        if (!linkedDefArgsBefore && getBlock().hasDefaultArgs()) {
            Iterator<Long> ids = getBlock().linkAllDefaultArgs().iterator();
            Iterator<BlockConnector> sockets = getBlock().getSockets().iterator();
            Long id;
            BlockConnector socket;

            // Store the ids, sockets, and blocks we need to update.
            List<Long> idList = new ArrayList<Long>();
            List<BlockConnector> socketList = new ArrayList<BlockConnector>();
            List<RenderableBlock> argList = new ArrayList<RenderableBlock>();
View Full Code Here

                    && BlockConnectorShape.isCommandConnector(connectedSocket)
                    && connectedSocket.getPositionType() == BlockConnector.PositionType.BOTTOM) {

                //get before connector
                Long beforeID = getBlock().getBeforeBlockID();
                BlockConnector beforeSocket = workspace.getEnv().getBlock(beforeID).getConnectorTo(getBlockID());
                workspace.getEnv().getRenderableBlock(beforeID).updateSocketSpace(beforeSocket, getBlockID(), true);
                return;
            }

            //add dimension to the mapping
            this.getConnectorTag(connectedSocket).setDimension(calcDimensionOfSocket(connectedSocket));
        }

        //reform shape with new socket dimension
        reformBlockShape();
        //next time, redraw with new positions and moving children blocks
        clearBufferedImage();

        //after everything on this block has been updated, recurse upward if possible
        BlockConnector plugEquiv = BlockLinkChecker.getPlugEquivalent(getBlock());
        if (plugEquiv != null && plugEquiv.hasBlock()) {
            Long plugID = plugEquiv.getBlockID();
            BlockConnector socketEquiv = workspace.getEnv().getBlock(plugID).getConnectorTo(getBlockID());
            //update the socket space of a connected before/parent block
            workspace.getEnv().getRenderableBlock(plugID).updateSocketSpace(socketEquiv, getBlockID(), true);
        }
    }
View Full Code Here

        }
        if (comment != null) {
            comment.update();
        }
        for (ConnectorTag tag : socketTags) {
            BlockConnector socket = tag.getSocket();
            SocketLabel label = tag.getLabel();
            if (label == null || SocketLabel.ignoreSocket(socket)) {
                continue;
            }
            label.update(getSocketAbstractPoint(socket));
View Full Code Here

                }

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

        if ((this.labelType.equals(BlockLabel.Type.NAME_LABEL) || this.labelType.equals(BlockLabel.Type.PORT_LABEL))
                && workspace.getEnv().getBlock(blockID).isLabelEditable()) {
            if (this.labelType.equals(BlockLabel.Type.NAME_LABEL)) {
                workspace.getEnv().getBlock(blockID).setBlockLabel(text);
            }
            BlockConnector plug = workspace.getEnv().getBlock(blockID).getPlug();
            // Check if we're connected to a block. If we are and the the block we're connected to
            // has stubs, update them.
            if (plug != null && plug.getBlockID() != Block.NULL) {
                if (workspace.getEnv().getBlock(plug.getBlockID()) != null) {
                    if (workspace.getEnv().getBlock(plug.getBlockID()).isProcedureDeclBlock()
                            && workspace.getEnv().getBlock(plug.getBlockID()).hasStubs()) {
                        // Blocks already store their socket names when saved so it is not necessary
                        // nor desired to call the connectors changed event again.
                        if (workspace.getEnv().getRenderableBlock(plug.getBlockID()).isLoading()) {
                            BlockStub.parentConnectorsChanged(workspace, plug.getBlockID());
                        }
                    }
                }
            }
            RenderableBlock rb = workspace.getEnv().getRenderableBlock(blockID);
View Full Code Here

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

     */
    private void disconnectBlock(Block childBlock, WorkspaceWidget widget) {
        if (childBlock == null || invalidBlockID(childBlock.getBlockID())) {
            return;
        }
        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);
View Full Code Here

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

TOP

Related Classes of edu.mit.blocks.codeblocks.BlockConnector$DefArgument

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.