Package edu.mit.blocks.codeblocks

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


                                for (int j = 0; j < genusMembers.getLength(); j++) {
                                    Node genusMember = genusMembers.item(j);
                                    if (genusMember.getNodeName().equals("BlockGenusMember")) {
                                        genusName = genusMember.getTextContent();
                                        assert workspace.getEnv().getGenusWithName(genusName) != null : "Unknown BlockGenus: " + genusName;
                                        Block block = new Block(workspace, genusName);
                                        drawerBlocks.add(new FactoryRenderableBlock(workspace, manager, block.getBlockID()));
                                    }
                                }
                                blocksForDrawers.put(drawer, drawerBlocks);
                                break//there can only be one drawer for this page
                            }
View Full Code Here


                        for (int k = 0; k < drawerBlocks.getLength(); k++) {
                            blockNode = drawerBlocks.item(k);
                            if (blockNode.getNodeName().equals("BlockGenusMember")) {
                                String genusName = blockNode.getTextContent();
                                assert workspace.getEnv().getGenusWithName(genusName) != null : "Unknown BlockGenus: " + genusName;
                                Block newBlock;
                                //don't link factory blocks to their stubs because they will
                                //forever remain inside the drawer and never be active
                                newBlock = new Block(workspace, genusName, false);
                                drawerRBs.add(new FactoryRenderableBlock(workspace, manager, newBlock.getBlockID()));
                            }
                        }
                        manager.addStaticBlocks(drawerRBs, drawerName);
                    }
                }
View Full Code Here

        //PLEASE CHANGE WITH CAUTION
        //IT DOES SOME PREETY STRANGE THINGS
        if (event.getEventType() == WorkspaceEvent.BLOCK_ADDED) {
            if (event.getSourceWidget() instanceof Page) {
                Page page = (Page) event.getSourceWidget();
                Block block = workspace.getEnv().getBlock(event.getSourceBlockID());
                //block may not be null if this is a block added event
                if (block.hasStubs()) {
                    for (BlockStub stub : block.getFreshStubs()) {
                        this.addDynamicBlock(
                                new FactoryRenderableBlock(event.getWorkspace(), this, stub.getBlockID()),
                                page.getPageDrawer());
                    }
                }
            }
        } 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
View Full Code Here

    translatorBlockFactory = new TranslatorBlockFactory();
  }
 
  public TranslatorBlock nextTranslatorBlock(Translator translator, Long blockId, String codePrefix, String codeSuffix)
  {
    Block block = translator.getBlock(blockId);
    blockId = block.getAfterBlockID();
    if (Block.NULL.equals(blockId))
    {
      return null;
    }
    else
    {
      block = translator.getBlock(blockId);
      TranslatorBlock translatorBlock = translatorBlockFactory.buildTranslatorBlock(translator, blockId, block.getGenusName(), codePrefix, codeSuffix, block.getBlockLabel());
      return translatorBlock;
    }
  }
View Full Code Here

    }
  }
 
  public TranslatorBlock getTranslatorBlockAtSocket(Translator translator, Long blockId, int i, String codePrefix, String codeSuffix)
  {
    Block block = translator.getBlock(blockId);
    if (block == null)
    {
      return null;
    }
   
    BlockConnector blockConnector = block.getSocketAt(i);
    blockId = blockConnector.getBlockID();
    if (Block.NULL.equals(blockId))
    {
      return null;
    }
    else
    {
      block = translator.getBlock(blockId);
//      System.out.println("name: " + block.getGenusName() + "      | label: " + block.getBlockLabel());
      TranslatorBlock translatorBlock = translatorBlockFactory.buildTranslatorBlock(translator, blockId, block.getGenusName(), codePrefix, codeSuffix, block.getBlockLabel());
      return translatorBlock;
    }
   
  }
View Full Code Here

    StringBuilder code = new StringBuilder();
   
   
    for (RenderableBlock renderableBlock:renderableBlocks)
    {
      Block block = renderableBlock.getBlock();
     
      if (!block.hasPlug() && (Block.NULL.equals(block.getBeforeBlockID())))
      {
       
        if(block.getGenusName().equals("loop"))
        {
          loopBlockSet.add(renderableBlock);
        }
        if(block.getGenusName().equals("loop1"))
        {
          loopBlockSet.add(renderableBlock);
        }
        if(block.getGenusName().equals("loop2"))
        {
          loopBlockSet.add(renderableBlock);
        }
        if(block.getGenusName().equals("loop3"))
        {
          loopBlockSet.add(renderableBlock);
        }
        if(block.getGenusName().equals("program"))
        {
          loopBlockSet.add(renderableBlock);
        }
        if(block.getGenusName().equals("setup"))
        {
          loopBlockSet.add(renderableBlock);
        }
        if (block.getGenusName().equals("subroutine"))
        {
          String functionName = block.getBlockLabel().trim();
          try
          {
            translator.addFunctionName(block.getBlockID(), functionName);
          }
          catch (SubroutineNameDuplicatedException e1)
          {
            context.highlightBlock(renderableBlock);
            //find the second subroutine whose name is defined, and make it highlight. though it cannot happen due to constraint of OpenBlocks -_-
            JOptionPane.showMessageDialog(parentFrame, uiMessageBundle.getString("ardublock.translator.exception.subroutineNameDuplicated"), "Error", JOptionPane.ERROR_MESSAGE);
            return ;
          }
          subroutineBlockSet.add(renderableBlock);
        }
        if (block.getGenusName().equals("scoop_task"))
        {
          translator.setScoopProgram(true);
          scoopBlockSet.add(renderableBlock);
        }
        if (block.getGenusName().equals("scoop_loop"))
        {
          translator.setScoopProgram(true);
          scoopBlockSet.add(renderableBlock);
        }
        if (block.getGenusName().equals("scoop_pin_event"))
        {
          translator.setScoopProgram(true);
          scoopBlockSet.add(renderableBlock);
        }
       
      }
    }
    if (loopBlockSet.size() == 0) {
      JOptionPane.showMessageDialog(parentFrame, uiMessageBundle.getString("ardublock.translator.exception.noLoopFound"), "Error", JOptionPane.ERROR_MESSAGE);
      return ;
    }
    if (loopBlockSet.size() > 1) {
      for (RenderableBlock rb : loopBlockSet)
      {
        context.highlightBlock(rb);
      }
      JOptionPane.showMessageDialog(parentFrame, uiMessageBundle.getString("ardublock.translator.exception.multipleLoopFound"), "Error", JOptionPane.ERROR_MESSAGE);
      return ;
    }

    try
    {
     
      for (RenderableBlock renderableBlock : loopBlockSet)
      {
        translator.setRootBlockName("loop");
        Block loopBlock = renderableBlock.getBlock();
        code.append(translator.translate(loopBlock.getBlockID()));
      }
     
      for (RenderableBlock renderableBlock : scoopBlockSet)
      {
        translator.setRootBlockName("scoop");
        Block scoopBlock = renderableBlock.getBlock();
        code.append(translator.translate(scoopBlock.getBlockID()));
      }
     
      for (RenderableBlock renderableBlock : subroutineBlockSet)
      {
        translator.setRootBlockName("subroutine");
        Block subroutineBlock = renderableBlock.getBlock();
        code.append(translator.translate(subroutineBlock.getBlockID()));
      }
     
      translator.beforeGenerateHeader();
      code.insert(0, translator.genreateHeaderCommand());
    }
    catch (SocketNullException e1)
    {
      e1.printStackTrace();
      success = false;
      Long blockId = e1.getBlockId();
      Iterable<RenderableBlock> blocks = workspace.getRenderableBlocks();
      for (RenderableBlock renderableBlock2 : blocks)
      {
        Block block2 = renderableBlock2.getBlock();
        if (block2.getBlockID().equals(blockId))
        {
          context.highlightBlock(renderableBlock2);
          break;
        }
      }
      JOptionPane.showMessageDialog(parentFrame, uiMessageBundle.getString("ardublock.translator.exception.socketNull"), "Error", JOptionPane.ERROR_MESSAGE);
    }
    catch (BlockException e2)
    {
      e2.printStackTrace();
      success = false;
      Long blockId = e2.getBlockId();
      Iterable<RenderableBlock> blocks = workspace.getRenderableBlocks();
      for (RenderableBlock renderableBlock2 : blocks)
      {
        Block block2 = renderableBlock2.getBlock();
        if (block2.getBlockID().equals(blockId))
        {
          context.highlightBlock(renderableBlock2);
          break;
        }
      }
      JOptionPane.showMessageDialog(parentFrame, e2.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
    catch (SubroutineNotDeclaredException e3)
    {
      e3.printStackTrace();
      success = false;
      Long blockId = e3.getBlockId();
      Iterable<RenderableBlock> blocks = workspace.getRenderableBlocks();
      for (RenderableBlock renderableBlock3 : blocks)
      {
        Block block2 = renderableBlock3.getBlock();
        if (block2.getBlockID().equals(blockId))
        {
          context.highlightBlock(renderableBlock3);
          break;
        }
      }
View Full Code Here

  }
 
  public String translate(Long blockId) throws SocketNullException, SubroutineNotDeclaredException, BlockException
  {
    TranslatorBlockFactory translatorBlockFactory = new TranslatorBlockFactory();
    Block block = workspace.getEnv().getBlock(blockId);
    TranslatorBlock rootTranslatorBlock = translatorBlockFactory.buildTranslatorBlock(this, blockId, block.getGenusName(), "", "", block.getBlockLabel());
    return rootTranslatorBlock.toCode();
  }
View Full Code Here

    Set<RenderableBlock> loopBlockSet = new HashSet<RenderableBlock>();
    Iterable<RenderableBlock> renderableBlocks = workspace.getRenderableBlocks();
   
    for (RenderableBlock renderableBlock:renderableBlocks)
    {
      Block block = renderableBlock.getBlock();
     
      if (!block.hasPlug() && (Block.NULL.equals(block.getBeforeBlockID())))
      {
        if(block.getGenusName().equals("loop"))
        {
          loopBlockSet.add(renderableBlock);
        }
        if(block.getGenusName().equals("loop1"))
        {
          loopBlockSet.add(renderableBlock);
        }
        if(block.getGenusName().equals("loop2"))
        {
          loopBlockSet.add(renderableBlock);
        }
        if(block.getGenusName().equals("loop3"))
        {
          loopBlockSet.add(renderableBlock);
        }
        if(block.getGenusName().equals("program"))
        {
          loopBlockSet.add(renderableBlock);
        }
        if(block.getGenusName().equals("setup"))
        {
          loopBlockSet.add(renderableBlock);
        }
      }
    }
View Full Code Here

    Set<RenderableBlock> subroutineBlockSet = new HashSet<RenderableBlock>();
    Iterable<RenderableBlock> renderableBlocks = workspace.getRenderableBlocks();
   
    for (RenderableBlock renderableBlock:renderableBlocks)
    {
      Block block = renderableBlock.getBlock();
     
      if (!block.hasPlug() && (Block.NULL.equals(block.getBeforeBlockID())))
      {
        if (block.getGenusName().equals("subroutine"))
        {
          String functionName = block.getBlockLabel().trim();
          this.addFunctionName(block.getBlockID(), functionName);
          subroutineBlockSet.add(renderableBlock);
        }
       
      }
    }
View Full Code Here

  {
    StringBuilder code = new StringBuilder();
   
    for (RenderableBlock renderableBlock : loopBlocks)
    {
      Block loopBlock = renderableBlock.getBlock();
      code.append(translate(loopBlock.getBlockID()));
    }
   
    for (RenderableBlock renderableBlock : subroutineBlocks)
    {
      Block subroutineBlock = renderableBlock.getBlock();
      code.append(translate(subroutineBlock.getBlockID()));
    }
    beforeGenerateHeader();
    code.insert(0, genreateHeaderCommand());
   
    return code.toString();
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.