Exemplo n.º 1
0
 /**
  * @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);
   }
 }
Exemplo n.º 2
0
 /**
  * @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);
   }
 }