/**
  * @param workspace The workspace in use
  * @param genusName
  * @param label
  * @requires if (label != null) then associated block.isLabelEditable() should return true
  * @modifies focusManager.focusblock && focusManager.focuspoint && blockCanvas
  * @effects Do nothing if "genusName" does not map to a valid block. Otherwise, create and add a
  *     new block with matching genus and label properties to one of the following: 1. the current
  *     block with focus at (0,0) relative to that block. 2. the current block with focus at next
  *     applicable socket location 3. the canvas at the last mouse click point. Then update any
  *     focus and block connections.
  */
 protected void automateBlockInsertion(Workspace workspace, String genusName, String label) {
   TypeBlockManager typeBlockManager = workspace.getTypeBlockManager();
   if (!typeBlockManager.isEnabled()) {
     System.err.println("AutoMateBlockInsertion invoked but typeBlockManager is disabled.");
     return;
   }
   // 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);
   }
 }
 /**
  * @requires none
  * @modifies focusManager.focusblock && focusManager.focuspoint && blockCanvas
  * @effects Do nothing if "genusName" does not map to a valid block. Otherwise, create and add a
  *     new block with matching genus and label properties to one of the following: 1. the current
  *     block with focus at (0,0) relative to that block. 2. the current block with focus at next
  *     applicable socket location 3. the canvas at the last mouse click point. If label is not an
  *     empty string, then set the block label to that string. Then update any focus and block
  *     connections.
  */
 protected void automateBlockInsertion(
     Workspace workspace, TextualFactoryBlock block, String label) {
   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);
   }
 }
  /** 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", "-");
      }
    }
  }
 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);
     }
   }
 }
 /**
  * Displays an assisting AutoCompletePanel.
  *
  * @param workspace
  * @param character
  */
 protected void automateAutoComplete(Workspace workspace, char character) {
   TypeBlockManager typeBlockManager = workspace.getTypeBlockManager();
   if (!typeBlockManager.isEnabled()) {
     System.err.println("AutoMateAutoComplete invoked but typeBlockManager is disabled.");
     return;
   }
   typeBlockManager.displayAutoCompletePanel(character);
 }
 /**
  * Traverses the block tree structure to move in the direction of the input argument.
  *
  * @param workspace
  * @param dir
  */
 protected static void automateFocusTraversal(Workspace workspace, Direction dir) {
   TypeBlockManager typeBlockManager = workspace.getTypeBlockManager();
   if (!typeBlockManager.isEnabled()) {
     System.err.println("AutoMateFocusTraversal invoked but typeBlockManager is disabled.");
     return;
   }
   typeBlockManager.traverseFocus(dir);
 }
  /**
   * @param workspace
   * @requires whatever is requires for AutomatedBlockInsertion
   */
  protected static void automatePasteBlock(Workspace workspace) {
    TypeBlockManager typeBlockManager = workspace.getTypeBlockManager();
    if (!typeBlockManager.isEnabled()) {
      System.err.println("AutoMatePasteBlock invoked but typeBlockManager is disabled.");
      return;
    }

    typeBlockManager.pasteStack(typeBlockManager.bufferedBlock);
  }
 protected static void automateCopyAll(Workspace workspace) {
   TypeBlockManager typeBlockManager = workspace.getTypeBlockManager();
   if (!typeBlockManager.isEnabled()) {
     System.err.println("AutoMatePasteBlock invoked but typeBlockManager is disabled.");
     return;
   }
   typeBlockManager.bufferedBlock =
       BlockUtilities.makeNodeWithStack(
           workspace, typeBlockManager.focusManager.getFocusBlockID());
 }
 /**
  * @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 all its children from the GUI and destroys
  *     the link between the block with focus and it's parent block if one exists
  */
 protected void automateBlockDeletion(Workspace workspace) {
   TypeBlockManager typeBlockManager = workspace.getTypeBlockManager();
   if (!typeBlockManager.isEnabled()) {
     System.err.println("AutoMateBlockDeletion invoked but typeBlockManager is disabled.");
     return;
   }
   if (!isNullBlockInstance(typeBlockManager.focusManager.getFocusBlockID())) {
     typeBlockManager.deleteBlockAndChildren();
     PageChangeEventManager.notifyListeners();
   }
 }
 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;
 }
 public static void cutBlock(Workspace workspace) {
   // copy then delete the highlighted block
   TypeBlockManager.automateCopyBlock(workspace);
   workspace.getTypeBlockManager().automateBlockDeletion(workspace);
 }
 public static void pasteBlock(Workspace workspace) {
   TypeBlockManager.automatePasteBlock(workspace);
 }
 public static void copyBlock(Workspace workspace) {
   TypeBlockManager.automateCopyBlock(workspace);
 }