protected void automateAddition(Workspace workspace, char character) {
   TypeBlockManager typeBlockManager = workspace.getTypeBlockManager();
   if (!typeBlockManager.isEnabled()) {
     System.err.println("AutoMateMultiplication invoked but typeBlockManager is disabled.");
     return;
   }
   // get focus block
   Long parentBlockID = typeBlockManager.focusManager.getFocusBlockID();
   if (isNullBlockInstance(parentBlockID)) {
     // focus on canvas
     automateBlockInsertion(workspace, "sum", null);
   } else {
     Block parentBlock = workspace.getEnv().getBlock(parentBlockID);
     if (parentBlock.getGenusName().equals("string")) {
       // focus on string block
       automateBlockInsertion(workspace, "string-append", null);
     } else if (parentBlock.getGenusName().equals("string-append")) {
       // focus on string append block
       automateBlockInsertion(workspace, "string-append", null);
     } else {
       // focus on any other block
       automateBlockInsertion(workspace, "sum", null);
     }
   }
 }
  /**
   * @param childBlock
   * @param widget
   * @requires widget != null
   * @modifies
   * @effects Does nothing if: childBlock is invalid (null) Otherwise, remove childBlock from it's
   *     parent block if the childBlock has a parent. If it does not have a parent, do nothing.
   */
  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);
    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"
              + "representation, we recieve a null instance.\n\tIf the Block instance of an ID is non-null"
              + "then its graphical RenderableBlock should be non-null as well");
    }
    parentRenderable.blockDisconnected(parentSocket);
    workspace.notifyListeners(
        new WorkspaceEvent(workspace, widget, link, WorkspaceEvent.BLOCKS_DISCONNECTED));
  }
  /** assumes number and differen genus exist and number genus has ediitabel lable */
  protected void automateNegationInsertion(Workspace workspace) {
    TypeBlockManager typeBlockManager = workspace.getTypeBlockManager();
    if (!typeBlockManager.isEnabled()) {
      System.err.println("AutoMateNegationInsertion invoked but typeBlockManager is disabled.");
      return;
    }

    //		====================>>>>>>>>>>>>>>>>>>>>>>>>>
    //		====================focus coming in>>>>>>>>>> TODO
    //		====================>>>>>>>>>>>>>>>>>>>>>>>>>

    // get focus block
    Long parentBlockID = typeBlockManager.focusManager.getFocusBlockID();
    if (isNullBlockInstance(parentBlockID)) {
      // focus on canvas
      automateBlockInsertion(workspace, "number", "-");

    } else {
      Block parentBlock = workspace.getEnv().getBlock(parentBlockID);
      if (parentBlock.isDataBlock()) {
        // focus on a data block
        automateBlockInsertion(workspace, "difference", null);
      } else {
        // focus on a non-data block
        automateBlockInsertion(workspace, "number", "-");
      }
    }
  }
示例#4
0
 public String translate(Long blockId) throws SocketNullException, SubroutineNotDeclaredException {
   TranslatorBlockFactory translatorBlockFactory = new TranslatorBlockFactory();
   Block block = workspace.getEnv().getBlock(blockId);
   TranslatorBlock rootTranslatorBlock =
       translatorBlockFactory.buildTranslatorBlock(
           this, blockId, block.getGenusName(), "", "", block.getBlockLabel());
   return rootTranslatorBlock.toCode();
 }
示例#5
0
  private void loadDefaultArdublockProgram() {
    /*
    InputStream defaultArdublockProgram = this.getClass().getResourceAsStream(DEFAULT_ARDUBLOCK_PROGRAM_PATH);

    final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
          factory.setNamespaceAware(true);
          final DocumentBuilder builder;
          final Document doc;
    try
    {
    	builder = factory.newDocumentBuilder();
    	doc = builder.parse(defaultArdublockProgram);
    	final Element projectRoot = doc.getDocumentElement();
    	workspaceController.resetWorkspace();
    	workspaceController.loadProjectFromElement(projectRoot);
    }
    catch (ParserConfigurationException e)
    {
    	// TODO Auto-generated catch block
    	e.printStackTrace();
    }
    catch (SAXException e)
    {
    	// TODO Auto-generated catch block
    	e.printStackTrace();
    }
    catch (IllegalArgumentException e)
    {
    	// TODO Auto-generated catch block
    	e.printStackTrace();
    	workspaceController.loadFreshWorkspace();
    }
    catch (IOException e)
    {
    	// TODO Auto-generated catch block
    	e.printStackTrace();
    	workspaceController.loadFreshWorkspace();
    }
          */

    Workspace workspace = workspaceController.getWorkspace();
    Page page = workspace.getPageNamed("Main");

    FactoryManager manager = workspace.getFactoryManager();
    Block newBlock;
    newBlock = new Block(workspace, "loop", false);
    FactoryRenderableBlock factoryRenderableBlock =
        new FactoryRenderableBlock(workspace, manager, newBlock.getBlockID());
    RenderableBlock renderableBlock = factoryRenderableBlock.createNewInstance();
    renderableBlock.setLocation(100, 100);
    page.addBlock(renderableBlock);
  }
示例#6
0
 public static boolean isLabelValid(Block block, String label) {
   if (block == null || label == null) {
     return false;
   } else if (block.labelMustBeUnique()) {
     Workspace workspace = block.getWorkspace();
     // search through the current block instances active in the workspace
     for (RenderableBlock rb : workspace.getRenderableBlocksFromGenus(block.getGenusName())) {
       if (label.equals(rb.getBlock().getBlockLabel())) {
         return false;
       }
     }
   }
   // either label doesn't have to be unique or
   // label was found to be unique in the search
   return true;
 }
示例#7
0
 /**
  * @return a collection of top level blocks within this page (blocks with no parents that and are
  *     the first block of each stack) or an empty collection if no blocks are found on this page.
  */
 public Collection<RenderableBlock> getTopLevelBlocks() {
   List<RenderableBlock> topBlocks = new ArrayList<RenderableBlock>();
   for (RenderableBlock renderable : this.getBlocks()) {
     Block block = workspace.getEnv().getBlock(renderable.getBlockID());
     if (block.getPlug() == null
         || block.getPlugBlockID() == null
         || block.getPlugBlockID().equals(Block.NULL)) {
       if (block.getBeforeConnector() == null
           || block.getBeforeBlockID() == null
           || block.getBeforeBlockID().equals(Block.NULL)) {
         topBlocks.add(renderable);
         continue;
       }
     }
   }
   return topBlocks;
 }
 protected void automateMultiplication(Workspace workspace, char character) {
   TypeBlockManager typeBlockManager = workspace.getTypeBlockManager();
   if (!typeBlockManager.isEnabled()) {
     System.err.println("AutoMateMultiplication invoked but typeBlockManager is disabled.");
     return;
   }
   if (!isNullBlockInstance(typeBlockManager.focusManager.getFocusBlockID())) {
     Block parentBlock =
         workspace.getEnv().getBlock(typeBlockManager.focusManager.getFocusBlockID());
     if (parentBlock.getGenusName().equals("number")) {
       automateBlockInsertion(workspace, "product", null);
       return;
     }
   }
   automateAutoComplete(workspace, character);
   return;
 }
示例#9
0
 private static boolean isNullBlockInstance(Long blockID) {
   if (blockID == null) {
     return true;
   } else if (blockID.equals(Block.NULL)) {
     return true;
   } else if (Block.getBlock(blockID) == null) {
     return true;
   } else if (Block.getBlock(blockID).getBlockID() == null) {
     return true;
   } else if (Block.getBlock(blockID).getBlockID().equals(Block.NULL)) {
     return true;
   } else if (RenderableBlock.getRenderableBlock(blockID) == null) {
     return true;
   } else if (RenderableBlock.getRenderableBlock(blockID).getBlockID() == null) {
     return true;
   } else if (RenderableBlock.getRenderableBlock(blockID).getBlockID().equals(Block.NULL)) {
     return true;
   } else {
     return false;
   }
 }
示例#10
0
 public static BlockNode makeNodeWithStack(Long blockID) {
   if (isNullBlockInstance(blockID)) {
     return null;
   }
   Block block = Block.getBlock(blockID);
   String genus = block.getGenusName();
   String parentGenus = block instanceof BlockStub ? ((BlockStub) block).getParentGenus() : null;
   String label;
   if (!block.labelMustBeUnique() || block instanceof BlockStub) {
     label = block.getBlockLabel();
   } else {
     label = null;
   }
   BlockNode node = new BlockNode(genus, parentGenus, label);
   for (BlockConnector socket : block.getSockets()) {
     if (socket.hasBlock()) {
       node.addChild(makeNodeWithStack(socket.getBlockID()));
     }
   }
   if (block.hasAfterConnector()) {
     node.setAfter(makeNodeWithStack(block.getAfterBlockID()));
   }
   return node;
 }
示例#11
0
  public static RenderableBlock cloneBlock(Block myblock) {
    String mygenusname = myblock.getGenusName();
    String label = myblock.getBlockLabel();
    final Workspace workspace = myblock.getWorkspace();

    // sometimes the factory block will have an assigned label different
    // from its genus label.
    if (!myblock.getInitialLabel().equals(myblock.getBlockLabel())) {
      // acquire prefix and suffix length from myblock label
      int prefixLength = myblock.getLabelPrefix().length();
      int suffixLength = myblock.getLabelSuffix().length();
      // we need to set the block label without the prefix and suffix attached because those
      // values are automatically concatenated to the string specified in setBlockLabel.  I know its
      // weird, but its the way block labels were designed.
      if (prefixLength > 0
          || suffixLength > 0) // TODO we could do this outside of this method, even in constructor
      {
        label =
            myblock
                .getBlockLabel()
                .substring(prefixLength, myblock.getBlockLabel().length() - suffixLength);
      }
    }

    // check genus instance counter and if label unique - change label accordingly
    // also check if label already has a value at the end, if so update counter to have the max
    // value
    // TODO ria need to make this smarter
    // some issues to think about:
    // - what if they throw out an instance, such as setup2? should the next time they take out
    //   a setup block, should it have setup2 on it?  but wouldn't that be confusing?
    // - when we load up a new project with some instances with numbered labels, how do we keep
    //   track of new instances relative to these old ones?
    // - the old implementation just iterated through all the instances of a particular genus in the
    //   workspace and compared a possible label to the current labels of that genus.  if there
    // wasn't
    //   any current label that matched the possible label, it returned that label.  do we want to
    // do this?
    //   is there something more efficient?

    String labelWithIndex = label; // labelWithIndex will have the instance value

    int value;
    // initialize value that will be appended to the end of the label
    if (instanceCounter.containsKey(mygenusname)) {
      value = instanceCounter.get(mygenusname).intValue();
    } else {
      value = 0;
    }
    // begin check for validation of label
    // iterate until label is valid
    while (!isLabelValid(myblock, labelWithIndex)) {
      value++;
      labelWithIndex = labelWithIndex + value;
    }

    // set valid label and save current instance number
    instanceCounter.put(mygenusname, new Integer(value));
    if (!labelWithIndex.equals(label)) // only set it if the label actually changed...
    {
      label = labelWithIndex;
    }

    Block block;
    if (myblock instanceof BlockStub) {
      Block parent = ((BlockStub) myblock).getParent();
      block =
          new BlockStub(
              workspace,
              parent.getBlockID(),
              parent.getGenusName(),
              parent.getBlockLabel(),
              myblock.getGenusName());
    } else {
      block = new Block(workspace, myblock.getGenusName(), label);
    }

    // TODO - djwendel - create a copy of the RB properties too, using an RB copy constructor.
    // Don't just use the genus.
    // RenderableBlock renderable = new RenderableBlock(this.getParentWidget(), block.getBlockID());
    RenderableBlock renderable = new RenderableBlock(workspace, null, block.getBlockID());
    renderable.setZoomLevel(BlockUtilities.zoom);
    renderable.redrawFromTop();
    renderable.repaint();
    return renderable;
  }
示例#12
0
  public static RenderableBlock makeRenderable(
      Workspace workspace, BlockNode node, WorkspaceWidget widget) {
    String genusName = node.getGenusName(); // genusName may not be null
    RenderableBlock renderable = BlockUtilities.getBlock(workspace, genusName, node.getLabel());
    if (renderable == null) {
      throw new RuntimeException("No children block exists for this genus: " + genusName);
    }
    Block block = Block.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 = Block.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,
              RenderableBlock.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 = Block.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,
              RenderableBlock.getRenderableBlock(link.getPlugBlockID()).getParentWidget(),
              link,
              WorkspaceEvent.BLOCKS_CONNECTED));
    }
    return renderable;
  }
示例#13
0
  /**
   * Returns a new RenderableBlock instance with the matching genusName. New block will also have
   * matching label is label is not-null. May return null.
   *
   * @param workspace The workspace to use
   * @param genusName
   * @param label
   * @requires if block associated with genusName has a non editable or unique block label, then
   *     "label" MUST BE NULL.
   * @return A new RenderableBlock with matching genusName and label (if label is not-null). If no
   *     matching blocks were found, return null.
   */
  public static RenderableBlock getBlock(Workspace workspace, String genusName, String label) {
    if (genusName == null) {
      return null;
    }

    //		find all blocks on the page and look for any match
    for (Block block : workspace.getBlocks()) {
      // make sure we're not dealing with null blocks
      if (block == null || block.getBlockID() == null || block.getBlockID().equals(Block.NULL)) {
        continue;
      }
      // find the block with matching genus and either a matching label or an editable label
      if (block.getGenusName().equals(genusName)
          && (block.isLabelEditable() || block.getBlockLabel().equals(label) || block.isInfix())) {
        // for block stubs, need to make sure that the label matches because stubs of the same kind
        // (i.e. global var getters, agent var setters, etc.) have the same genusName
        // but stubs of different parents do not share the same label
        if (block instanceof BlockStub && !block.getBlockLabel().equals(label)) {
          continue;
        }
        // create new renderable block instance
        RenderableBlock renderable = BlockUtilities.cloneBlock(block);
        // make sure renderable block is not a null instance of a block
        if (renderable == null || renderable.getBlockID().equals(Block.NULL)) {
          throw new RuntimeException(
              "Invariant Violated: a valid non null blockID just"
                  + "returned a null instance of RenderableBlock");
          // please throw an exception here because it wouldn't make any sense
          // if the Block is valid but it's associated RenderableBlock is not
        }
        // do not drop down default arguments
        renderable.ignoreDefaultArguments();
        // get corresponding block
        Block newblock = Block.getBlock(renderable.getBlockID());
        // make sure corresponding block is not a null instance of block
        if (newblock == null || newblock.getBlockID().equals(Block.NULL)) {
          throw new RuntimeException(
              "Invariant Violated: a valid non null blockID just"
                  + "returned a null instance of Block");
          // please throw an exception here because it wouldn't make any sense
          // if the Block is valid but it's associated RenderableBlock is not
        }
        // attempt to set the label text if possible as defined by the specs
        // should not set the labels of block stubs because their labels are determined by their
        // parent
        if ((block.isLabelEditable() || block.getBlockLabel().equals(label))) {
          if (label != null && !(block instanceof BlockStub)) {
            if (newblock.isLabelEditable() && !newblock.labelMustBeUnique()) {
              newblock.setBlockLabel(label);
            }
          }
        }
        // return renderable block
        return renderable;
      }

      /////////////////////////////////////
      // TODO: Add code here for nicknames//
      /////////////////////////////////////

    }
    // TODO: the part below is a hack. If there are other types of blocks, we need to account for
    // them
    return null;
  }
  public static void loadBlockDrawerSets(
      Workspace workspace, Element root, FactoryManager manager) {
    Pattern attrExtractor = Pattern.compile("\"(.*)\"");
    Matcher nameMatcher;
    NodeList drawerSetNodes = root.getElementsByTagName("BlockDrawerSet");
    Node drawerSetNode;
    for (int i = 0; i < drawerSetNodes.getLength(); i++) {
      drawerSetNode = drawerSetNodes.item(i);
      if (drawerSetNode.getNodeName().equals("BlockDrawerSet")) {
        NodeList drawerNodes = drawerSetNode.getChildNodes();
        Node drawerNode;
        // retreive drawer information of this bar
        for (int j = 0; j < drawerNodes.getLength(); j++) {
          drawerNode = drawerNodes.item(j);
          if (drawerNode.getNodeName().equals("BlockDrawer")) {
            String drawerName = null;
            Color buttonColor = Color.blue;
            StringTokenizer col;
            nameMatcher =
                attrExtractor.matcher(drawerNode.getAttributes().getNamedItem("name").toString());
            if (nameMatcher.find()) { // will be true
              drawerName = nameMatcher.group(1);
            }

            // get drawer's color:
            Node colorNode = drawerNode.getAttributes().getNamedItem("button-color");
            //    					if(colorNode == null){
            //    						buttonColor = Color.blue;
            //    						System.out.println("Loading a drawer without defined color: ");
            //    						for(int ai=0; ai<drawerNode.getAttributes().getLength(); ai++){
            //
            //	System.out.println("\t"+drawerNode.getAttributes().item(ai).getNodeName()+
            //        								", "+drawerNode.getAttributes().item(ai).getNodeValue());
            //        					}
            //    					}else{
            if (colorNode != null) {
              nameMatcher = attrExtractor.matcher(colorNode.toString());
              if (nameMatcher.find()) { // will be true
                col = new StringTokenizer(nameMatcher.group(1));
                if (col.countTokens() == 3) {
                  buttonColor =
                      new Color(
                          Integer.parseInt(col.nextToken()),
                          Integer.parseInt(col.nextToken()),
                          Integer.parseInt(col.nextToken()));
                } else {
                  buttonColor = Color.BLACK;
                }
              }
            }

            manager.addStaticDrawer(drawerName, buttonColor);

            // get block genuses in drawer and create blocks
            NodeList drawerBlocks = drawerNode.getChildNodes();
            Node blockNode;
            ArrayList<RenderableBlock> drawerRBs = new ArrayList<RenderableBlock>();
            for (int k = 0; k < drawerBlocks.getLength(); k++) {
              blockNode = drawerBlocks.item(k);
              if (blockNode.getNodeName().equals("BlockGenusMember")) {
                String genusName = blockNode.getTextContent();
                assert BlockGenus.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);
          }
        }
      }
    }
  }
示例#15
0
 /**
  * Returns true if the specified label is valid according to the specifications of this block's
  * genus. For example, if this block's label must be unique (as specified from its genus), this
  * method verifies that its label is unique relative to the other instances present.
  *
  * @param label the String block label to test
  * @return true if the specified label is valid according to the specifications of this block's
  *     genus.
  */
 public static boolean isLabelValid(Long blockID, String label) {
   return isLabelValid(Block.getBlock(blockID), label);
 }
  public static void loadPagesAndDrawers(
      Workspace workspace, Element root, FactoryManager manager) {
    List<Page> pageList = new ArrayList<Page>();
    // pagesToAdd is needed so that we can add pages all at once
    // to the page bar once all the the pages been loaded
    // Before adding all the pages, this method makes a check
    // if there is only one page with an empty name - if so, it will just
    // add the page to the workspace/block canvas but not add it to this
    // LinkedHashMap<Page, PageBlockDrawer> pagesToAdd = new LinkedHashMap<Page, PageBlockDrawer>();
    LinkedHashMap<String, ArrayList<RenderableBlock>> blocksForDrawers =
        new LinkedHashMap<String, ArrayList<RenderableBlock>>();
    LinkedHashMap<Page, ArrayList<RenderableBlock>> blocksForPages =
        new LinkedHashMap<Page, ArrayList<RenderableBlock>>();

    NodeList pagesRoot = root.getElementsByTagName("Pages");
    if (pagesRoot != null) {
      // isBlankPage denotes if the page being loaded is a default blank page
      // in other words, the project did not specify any pages for their environment.
      // EvoBeaker does this
      boolean isBlankPage = false;
      Node pagesNode = pagesRoot.item(0);
      if (pagesNode == null) {
        return; // short-circuit exit if there's nothing to load
      }
      Node opt_item = pagesNode.getAttributes().getNamedItem("drawer-with-page");
      if (opt_item != null) {
        Matcher nameMatcher = attrExtractor.matcher(opt_item.toString());
        if (nameMatcher.find()) // will be true
        {
          Workspace.everyPageHasDrawer = nameMatcher.group(1).equals("yes") ? true : false;
        }
      }
      opt_item = pagesNode.getAttributes().getNamedItem("is-blank-page");
      if (opt_item != null) {
        Matcher nameMatcher = attrExtractor.matcher(opt_item.toString());
        if (nameMatcher.find()) // will be true
        {
          isBlankPage = nameMatcher.group(1).equals("yes") ? true : false;
        }
      }

      // whether pages should show a control to collapse them or not
      boolean collapsiblePages = getBooleanValue(pagesNode, "collapsible-pages");

      Page page;
      NodeList pages = pagesNode.getChildNodes();
      Node pageNode;
      String pageName = "";
      String pageDrawer = null;
      Color pageColor = null;
      boolean pageInFullView = true;
      int pageWidth = -1;
      String pageId = null;
      for (int i = 0; i < pages.getLength(); i++) { // find them
        pageNode = pages.item(i);
        if (pageNode.getNodeName().equals("Page")) { // a page entry
          pageName = getNodeValue(pageNode, "page-name");
          pageColor = getColorValue(pageNode, "page-color");
          pageWidth = getIntValue(pageNode, "page-width");
          pageDrawer = getNodeValue(pageNode, "page-drawer");
          pageInFullView = getBooleanValue(pageNode, "page-infullview");
          pageId = getNodeValue(pageNode, "page-id");
          page =
              new Page(
                  workspace,
                  pageName,
                  pageWidth,
                  0,
                  pageDrawer,
                  pageInFullView,
                  pageColor,
                  collapsiblePages);
          page.setPageId(pageId);

          NodeList pageNodes = pageNode.getChildNodes();
          String drawer = null;
          if (Workspace.everyPageHasDrawer) {
            // create drawer instance
            manager.addDynamicDrawer(page.getPageDrawer());
            ArrayList<RenderableBlock> drawerBlocks = new ArrayList<RenderableBlock>();

            for (int k = 0; k < pageNodes.getLength(); k++) {
              Node drawerNode = pageNodes.item(k);
              if (drawerNode.getNodeName().equals("PageDrawer")) {
                NodeList genusMembers = drawerNode.getChildNodes();
                String genusName;
                for (int j = 0; j < genusMembers.getLength(); j++) {
                  Node genusMember = genusMembers.item(j);
                  if (genusMember.getNodeName().equals("BlockGenusMember")) {
                    genusName = genusMember.getTextContent();
                    assert BlockGenus.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
              }
            }
          }

          if (isBlankPage) {
            // place a blank page as the first page
            workspace.putPage(page, 0);
            // if the system uses blank pages, then we expect only one page
            break; // we anticipate only one page
          } else {
            // we add to the end of the set of pages
            int position = pageList.size();
            // add to workspace
            if (position == 0) {
              // replace the blank default page
              workspace.putPage(page, 0);
            } else {
              workspace.addPage(page, position);
            }
            pageList.add(position, page);
          }

          blocksForPages.put(page, page.loadPageFrom(pageNode, false));
        }
      }
      // add blocks in drawers
      for (String d : blocksForDrawers.keySet()) {
        manager.addDynamicBlocks(blocksForDrawers.get(d), d);
      }
      // blocks in pages
      for (Page p : blocksForPages.keySet()) {
        p.addLoadedBlocks(blocksForPages.get(p), false);
      }
    }
  }
  /**
   * @requires the current block with focus must exist with non-null ID in a non-null widget with a
   *     non-null parent
   * @modifies the current block with focus
   * @effects removes the current block with focus and children from the GUI and destroys the link
   *     between the block with focus and it's parent block if one exist and children blocks if it
   *     has childrens.
   */
  private void deleteBlockAndChildren() {
    //		====================>>>>>>>>>>>>>>>>>>>>>>>>>
    //		====================focus coming in>>>>>>>>>>TODO
    //		====================>>>>>>>>>>>>>>>>>>>>>>>>>

    // Do not delete null block references.  Otherwise, get Block and RenderableBlock instances.
    if (isNullBlockInstance(focusManager.getFocusBlockID())) {
      throw new RuntimeException("TypeBlockManager: deleting a null block references.");
    }
    Block block = workspace.getEnv().getBlock(focusManager.getFocusBlockID());
    RenderableBlock renderable = workspace.getEnv().getRenderableBlock(block.getBlockID());

    // get workspace widget associated with current focus
    WorkspaceWidget widget = renderable.getParentWidget();
    // do not delete block instances in null widgets
    if (widget == null) {
      throw new RuntimeException("TypeBlockManager: do not delete blocks with no parent widget.");
      // return;
    }
    // get parent container of this graphical representation
    Container container = renderable.getParent();
    // do not delete block instances in null parents
    if (container == null) {
      throw new RuntimeException(
          "TypeBlockManager: do not delete blocks with no parent container.");
      // return;
    }
    // get the Block's location on the canvas
    Point location =
        SwingUtilities.convertPoint(renderable, new Point(0, 0), this.blockCanvas.getCanvas());

    // for every valid and active connection, disconnect it.
    Long parentID = null;
    if (validConnection(block.getPlug())) {
      parentID = block.getPlugBlockID();
      this.disconnectBlock(block, widget);
      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) {
          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())) {
      parentID = block.getAfterBlockID();
    }

    // remove form widget and container
    this.removeChildrenBlock(renderable, widget, container);

    //		<<<<<<<<<<<<<<<<<<<<<<<<<<==========================
    //		<<<<<<<<<<<<<<<<<<<<<<<<<<focus changing, coming out TODO
    //		<<<<<<<<<<<<<<<<<<<<<<<<<<==========================
    // If the deleted block had a parent, give the parent the focus,
    // Otherwise, give the focus to the canvas (NOT BLOCK CANVAS)
    if (invalidBlockID(parentID)) {
      this.focusManager.setFocus(location, Block.NULL);
      this.blockCanvas.getCanvas().requestFocus();
      return;
    } else {
      this.focusManager.setFocus(parentID);
      this.blockCanvas.getCanvas().requestFocus();
      return;
    }
  }