Package edu.mit.blocks.renderable

Examples of edu.mit.blocks.renderable.RenderableBlock


        //if genus is null, DO NOT insert a new block, DO NOT change the focus
        if (genusName == null) {
            return;
        }
        //get matching textual Block
        RenderableBlock createdRB = BlockUtilities.getBlock(workspace, genusName, null);
        if (createdRB == null) {
            return;
        } else {
            //change name of block IF AN DONLY IFF a label was passed
            //and the block's label was editable and the block
            //does not need to have a unique label
            if (label != null && workspace.getEnv().getBlock(createdRB.getBlockID()).isLabelEditable() && !workspace.getEnv().getBlock(createdRB.getBlockID()).labelMustBeUnique()) {
              workspace.getEnv().getBlock(createdRB.getBlockID()).setBlockLabel(label);
            }
            //add block
            typeBlockManager.addBlock(createdRB);
        }
    }
View Full Code Here


        TypeBlockManager typeBlockManager = workspace.getTypeBlockManager();
        if (!typeBlockManager.isEnabled()) {
            System.err.println("AutoMateBlockInsertion invoked but typeBlockManager is disabled.");
            return;
        }
        RenderableBlock createdRB = createRenderableBlock(block);
        // sets the label of the block to whatever the user typed (should only be numbers)
        if (label != EMPTY_LABEL_NAME) {
            createdRB.getBlock().setBlockLabel(label);
        }
        // changes the plus number labels back to +
        if (label.equals(NUMBER_PLUS_OPERATION_LABEL)) {
            createdRB.getBlock().setBlockLabel(PLUS_OPERATION_LABEL);
        }
        // changes the plus text labels back to +
        if (label.equals(TEXT_PLUS_OPERATION_LABEL)) {
            createdRB.getBlock().setBlockLabel(PLUS_OPERATION_LABEL);
        }
        if (createdRB == null) {
            return;
        } else {
            typeBlockManager.addBlock(createdRB);
View Full Code Here

        //if FactoryBlock wrapped in textual wrapper is invalid, return null RenderableBlock instance.
        if (block.getfactoryBlock() == null || block.getfactoryBlock().getBlockID().equals(Block.NULL)) {
            return null;
        }
        //create and get the RenderableBloc instance associated with the Textual wrapper's FactoryBlock
        RenderableBlock createdRB = block.getfactoryBlock().createNewInstance();
        //if the above instance of RenderableBlock is invalid (null or points to null)
        //then DO NOT insert a new block, DO NOT change the focus.
        if (createdRB == null || isNullBlockInstance(createdRB.getBlockID())) {
            throw new RuntimeException("Invariant Violated:"
                    + "May not drop null instances of Renderable Blocks");
        }
        //Please keep the above check rep because it does not
        //make any sense to have an exisitn valid
View Full Code Here

                    workspace,
                    this.focusManager.getCanvasPoint(),
                    block,
                    workspace.getEnv().getRenderableBlock(parentBlockID));
        } else {
            RenderableBlock parentBlock = workspace.getEnv().getRenderableBlock(parentBlockID);
            new BlockDropAnimator(
                    workspace,
                    SwingUtilities.convertPoint(parentBlock,
                    this.focusManager.getBlockPoint(),
                    this.blockCanvas.getCanvas()),
View Full Code Here

                //System.out.println("FocusManager: Block_Added Event at of "+event.getSourceBlockID()+" on "+event.getSourceWidget());
                //only add focus manager as listener to blocks added to pages
                if (!(event.getSourceWidget() instanceof Page)) {
                    break;
                }
                RenderableBlock rb = workspace.getEnv().getRenderableBlock(event.getSourceBlockID());
                if (rb == null) {
                    break;
                }

                //only add once
                for (MouseListener l : rb.getMouseListeners()) {
                    if (l.equals(this)) {
                        return;
                        //TODO: this shouldn't return, it should break
                        //but you can't double break in java
                    }
                }
                rb.addMouseListener(this);
                rb.addKeyListener(this);
                setFocus(event.getSourceBlockID());
                rb.grabFocus();
                break;
        }
    }
View Full Code Here

        } else if (event.getEventType() == WorkspaceEvent.BLOCK_REMOVED) {
            //may not be removing a null stanc eof block, so DO NOT check for it
            Block block = workspace.getEnv().getBlock(event.getSourceBlockID());
            if (block.hasStubs()) {
                for (Long stub : BlockStub.getStubsOfParent(event.getWorkspace(), block)) {
                    RenderableBlock rb = workspace.getEnv().getRenderableBlock(stub);
                    if (rb != null && !rb.getBlockID().equals(Block.NULL)
                            && rb.getParentWidget() != null && rb.getParentWidget().equals(this)) {
                        //rb.getParent() should not be null
                        rb.getParent().remove(rb);
                        rb.setParentWidget(null);

                    }
                }
            }
            this.relayoutBlocks();
        } else if (event.getEventType() == WorkspaceEvent.BLOCK_MOVED) {
            Block block = workspace.getEnv().getBlock(event.getSourceBlockID());
            if (block != null && block.hasStubs()) {
                for (Long stub : BlockStub.getStubsOfParent(event.getWorkspace() ,block)) {
                    RenderableBlock rb = workspace.getEnv().getRenderableBlock(stub);
                    if (rb != null && !rb.getBlockID().equals(Block.NULL)
                            && rb.getParentWidget() != null && rb.getParentWidget().equals(this)) {
                        //rb.getParent() should not be null
                        rb.getParent().remove(rb);
                        rb.setParentWidget(null);

                    }
                }
                this.relayoutBlocks();
            }
View Full Code Here

        block.setHighlightParent(this);
        block.removeComponentListener(this);
    }

    void layoutBlocks() {
        RenderableBlock rb;
        int maxWidth = 20;
        int tx = BORDER_WIDTH;
        int ty = BORDER_WIDTH;
        for (Component c : this.getComponents()) {
            if (c instanceof RenderableBlock) {
                rb = (RenderableBlock) c;
                rb.setBounds(tx, ty, rb.getBlockWidth(), rb.getBlockHeight());
                ty = ty + BORDER_WIDTH + rb.getBlockHeight();
                rb.repaint();
                if (maxWidth < rb.getBlockWidth() + BORDER_WIDTH) {
                    maxWidth = rb.getBlockWidth() + BORDER_WIDTH;
                }
            }
        }
        this.setPreferredSize(new Dimension(maxWidth, ty));
    }
View Full Code Here

                    //draw first socket - down right side
                    BCS.addDataSocket(gpBottom, curSocket.getKind(), false);
                    //rb.updateSocketPoint(curSocket, rightSocket);
                } else { //there is a connected block
                    Block connectedBlock = rb.getWorkspace().getEnv().getBlock(curSocket.getBlockID());
                    RenderableBlock connectedRBlock = rb.getWorkspace().getEnv().getRenderableBlock(curSocket.getBlockID());

                    //calculate and update the new socket point
                    //update the socket point of this cursocket which should now adopt the plug socket point of its
                    //connected block since we're also adopting the left side of its shape

                    //Use coordinates when the zoom level is 1.0 to calculate socket point
                    double unzoomX = connectedRBlock.getSocketPixelPoint(connectedBlock.getPlug()).getX() / connectedRBlock.getZoom();
                    double unzoomY = connectedRBlock.getSocketPixelPoint(connectedBlock.getPlug()).getY() / connectedRBlock.getZoom();
                    Point2D connectedBlockSocketPoint = new Point2D.Double(unzoomX, unzoomY);
                    Point2D currentPoint = gpBottom.getCurrentPoint();
                    double newX = connectedBlockSocketPoint.getX() + Math.abs(connectedBlockSocketPoint.getX() - currentPoint.getX());
                    double newY = connectedBlockSocketPoint.getY() + Math.abs(connectedRBlock.getBlockHeight() / connectedRBlock.getZoom() - currentPoint.getY());
                    rb.updateSocketPoint(curSocket, new Point2D.Double(newX, newY));


                    BlockShape connectedBlockShape = rb.getWorkspace().getEnv().getRenderableBlock(curSocket.getBlockID()).getBlockShape();
                    //append left side of connected block
View Full Code Here

    private void disconnectBlock(Long id) {
        Block b2 = workspace.getEnv().getBlock(id);
        BlockConnector conn2 = b2.getConnectorTo(getBlockID());
        BlockConnector conn = getConnectorTo(id);
        BlockLink link = BlockLink.getBlockLink(workspace, this, b2, conn, conn2);
        RenderableBlock rb = workspace.getEnv().getRenderableBlock(link.getSocketBlockID());
        link.disconnect();
        rb.blockDisconnected(link.getSocket());
        workspace.notifyListeners(
                new WorkspaceEvent(workspace, rb.getParentWidget(), link, WorkspaceEvent.BLOCKS_DISCONNECTED));

    }
View Full Code Here

        // actually form the connection
        plug.setConnectorBlockID(socketBlockID);
        socket.setConnectorBlockID(plugBlockID);

        //notify renderable block of connection so it can redraw with stretching
        RenderableBlock socketRB = workspace.getEnv().getRenderableBlock(socketBlockID);
        socketRB.blockConnected(socket, plugBlockID);

        if (clickSound != null) {
            //System.out.println("playing click sound");
            clickSound.play();
        }
View Full Code Here

TOP

Related Classes of edu.mit.blocks.renderable.RenderableBlock

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.