Exemplo n.º 1
0
  /** 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", "-");
      }
    }
  }
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);
   }
 }
Exemplo n.º 3
0
  /**
   * @param block
   * @requires block must be a valid block. That is, block may not be such that block == null ||
   *     block.getBlockID() == null || block.getBlockID() == Block.NULL || block.getBlockID() == -1
   *     || Block.getBlock(block.getBlockID()) == null ||
   *     Block.getBlock(block.getBlockID()).getGenusName() == null ||
   *     Block.getBlock(block.getBlockID()).getGenusName().length() == 0 ||
   *     Block.getBlock(block.getBlockID()).getBlockLabel() == null
   * @modifies Objects modified by this method is undefined
   * @effects The effects of this method is unknown
   */
  private void addBlock(RenderableBlock block) {
    // check invariant
    if (block == null
        || block.getBlockID() == null
        || block.getBlockID().equals(Block.NULL)
        || workspace.getEnv().getBlock(block.getBlockID()) == null
        || workspace.getEnv().getBlock(block.getBlockID()).getGenusName() == null
        || workspace.getEnv().getBlock(block.getBlockID()).getGenusName().length() == 0
        || workspace.getEnv().getBlock(block.getBlockID()).getBlockLabel() == null) {
      throw new RuntimeException(
          "Invariant Violated: may not pass an invalid instance of renderabel block");
    }

    // ignore default arguments
    block.ignoreDefaultArguments();
    this.blockCanvas.getCanvas().add(block, 0);
    block.setLocation(0, 0);
    Long parentBlockID = this.focusManager.getFocusBlockID();
    if (invalidBlockID(parentBlockID)) {
      new BlockDropAnimator(
          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()),
          block,
          workspace.getEnv().getRenderableBlock(parentBlockID));
    }
    this.focusManager.setFocus(block.getBlockID());
  }
Exemplo n.º 4
0
  /**
   * @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));
  }
Exemplo n.º 5
0
 /**
  * @param renderable
  * @param widget
  * @param container
  * @requires renderable != null && renderable.blockID != null && renderable.blockID != Block.NULL
  *     && widget != null && container != null
  * @modifies renderable && children blocks connected to renderable
  * @effects removes renderable from container and widget and re-renders renderable block, widget,
  *     and container appropriately. Repeats for all of renderable's children.
  */
 private void removeBlock(
     RenderableBlock renderable, WorkspaceWidget widget, Container container) {
   widget.removeBlock(renderable);
   container.remove(renderable);
   container.validate();
   container.repaint();
   renderable.setParentWidget(null);
   // Workspace.getInstance().notifyListeners(new WorkspaceEvent(widget, renderable.getBlockID(),
   // WorkspaceEvent.BLOCK_REMOVED));
   for (BlockConnector child :
       BlockLinkChecker.getSocketEquivalents(
           workspace.getEnv().getBlock(renderable.getBlockID()))) {
     if (child == null || child.getBlockID().equals(Block.NULL)) {
       continue;
     }
     RenderableBlock childRenderable = workspace.getEnv().getRenderableBlock(child.getBlockID());
     if (childRenderable == null) {
       continue;
     }
     removeBlock(childRenderable, widget, container);
   }
   if (renderable.hasComment()) {
     renderable.removeComment();
   }
   workspace.notifyListeners(
       new WorkspaceEvent(
           workspace, widget, renderable.getBlockID(), WorkspaceEvent.BLOCK_REMOVED));
 }
Exemplo n.º 6
0
 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);
     }
   }
 }
Exemplo n.º 7
0
 /**
  * Enables/disables the keyboard support
  *
  * @param enabled
  */
 public void setEnabled(boolean enabled) {
   this.enabled = enabled;
   if (enabled) {
     blockCanvas.getCanvas().addMouseListener(focusManager);
     blockCanvas.getCanvas().addKeyListener(focusManager);
     workspace.addWorkspaceListener(focusManager);
   } else {
     blockCanvas.getCanvas().removeMouseListener(focusManager);
     blockCanvas.getCanvas().removeKeyListener(focusManager);
     workspace.removeWorkspaceListener(focusManager);
   }
 }
Exemplo n.º 8
0
  private void pasteStack(BlockNode node) {
    //		====================>>>>>>>>>>>>>>>>>>>>>>>>>
    //		====================focus coming in>>>>>>>>>> TODO
    //		====================>>>>>>>>>>>>>>>>>>>>>>>>>
    if (node == null) {
      return;
    }
    WorkspaceWidget widget = null;
    Iterable<WorkspaceWidget> widgets = null;
    Point spot = null;
    if (invalidBlockID(focusManager.getFocusBlockID())) {
      // canvas has focus
      Point location =
          SwingUtilities.convertPoint(
              this.blockCanvas.getCanvas(), this.focusManager.getCanvasPoint(), workspace);
      widget = workspace.getWidgetAt(location);
      spot =
          SwingUtilities.convertPoint(
              this.blockCanvas.getCanvas(),
              this.focusManager.getCanvasPoint(),
              widget.getJComponent());
    } else {
      RenderableBlock focusRenderable =
          workspace.getEnv().getRenderableBlock(focusManager.getFocusBlockID());
      widget = focusRenderable.getParentWidget();
      spot = focusRenderable.getLocation();
    }

    if (widget == null) {
      // TODO: To be examined and fixed, occurs on macs
      JOptionPane.showMessageDialog(
          frame, "Please click somewhere on the canvas first.", "Error", JOptionPane.PLAIN_MESSAGE);
      // throw new RuntimeException("Why are we adding a block to a null widget?");
    } else {
      // checks to see if the copied block still exists
      if (BlockUtilities.blockExists(workspace, node)) {
        // create mirror block and mirror childrens
        spot.translate(10, 10);
        RenderableBlock mirror = BlockUtilities.makeRenderable(workspace, node, widget);
        mirror.setLocation(spot);
        mirror.moveConnectedBlocks(); // make sure the childrens are placed correctly
      } else {
        // TODO: future version, allow them to paste
        JOptionPane.showMessageDialog(
            frame,
            "You cannot paste blocks that are currently NOT on the canvas."
                + "\nThis function will be available in a future version.\n",
            "Error",
            JOptionPane.PLAIN_MESSAGE);
      }
    }
  }
Exemplo n.º 9
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);
  }
Exemplo n.º 10
0
 /**
  * Helper method that recursively finds and removes all the blocks connected to the bottom of this
  * block, including this block.
  *
  * @param afterBlock - RenderableBlock we start removing at
  * @param widget - WorkspaceWidget that the block is using
  * @param container - Container the block is stored in
  */
 private void removeAfterBlock(
     RenderableBlock afterBlock, WorkspaceWidget widget, Container container) {
   if (workspace.getEnv().getBlock(afterBlock.getBlockID()).getAfterBlockID() != Block.NULL) {
     removeAfterBlock(
         workspace
             .getEnv()
             .getRenderableBlock(
                 workspace.getEnv().getBlock(afterBlock.getBlockID()).getAfterBlockID()),
         widget,
         container);
   }
   removeChildrenBlock(afterBlock, widget, container);
 }
Exemplo n.º 11
0
 /** Implement MouseListener interface toggle collapse state of block if button pressed */
 public void mouseClicked(MouseEvent e) {
   toggle();
   RenderableBlock rb = workspace.getEnv().getRenderableBlock(getBlockID());
   rb.getComment().setVisible(isActive());
   workspace.notifyListeners(
       new WorkspaceEvent(
           workspace,
           rb.getComment().getCommentSource().getParentWidget(),
           WorkspaceEvent.BLOCK_COMMENT_VISBILITY_CHANGE));
   update();
   rb.revalidate();
   rb.repaint();
   workspace.getMiniMap().repaint();
 }
Exemplo n.º 12
0
 /** Implement MouseListener interface highlight button state */
 public void mouseEntered(MouseEvent e) {
   super.mouseEntered(e);
   this.setBorder(BorderFactory.createLineBorder(Color.yellow));
   Comment comment = workspace.getEnv().getRenderableBlock(getBlockID()).getComment();
   comment.setVisible(true);
   comment.showOnTop();
 }
Exemplo n.º 13
0
  /**
   * @param workspace
   * @param digits
   * @requires digits != null
   * @return List containing a number TextualFactoryBlock and any other blocks containing the
   *     numbers
   */
  public static List<TextualFactoryBlock> getDigits(Workspace workspace, String digits) {
    Set<TextualFactoryBlock> matchingBlocks =
        new TreeSet<TextualFactoryBlock>(new MatchingComparator(digits));
    // looks through the factory blocks
    for (RenderableBlock renderable : workspace.getFactoryManager().getBlocks()) {
      if (renderable == null
          || renderable.getBlockID().equals(Block.NULL)
          || !(renderable instanceof FactoryRenderableBlock)) {
        continue;
      }

      // TODO genus name are based from TNG, need to figure out a workaround
      // selects the number block
      if (renderable.getBlock().getGenusName().equalsIgnoreCase("number")) {
        matchingBlocks.add(new TextualFactoryBlock((FactoryRenderableBlock) renderable, digits));
      }
      // selects any other block that contains the number (for variables that contains the number)
      if (renderable.getKeyword().toLowerCase().contains(digits.toLowerCase())) {
        matchingBlocks.add(
            new TextualFactoryBlock(
                (FactoryRenderableBlock) renderable, renderable.getBlock().getBlockLabel()));
      }
    }
    return new ArrayList<TextualFactoryBlock>(matchingBlocks);
  }
Exemplo n.º 14
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;
 }
Exemplo n.º 15
0
  /**
   * Loads the programming project from the specified file path. This method assumes that a Language
   * Definition File has already been specified for this programming project.
   *
   * @param path String file path of the programming project to load
   */
  public void loadProjectFromPath(final String path) {
    final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    final DocumentBuilder builder;
    final Document doc;
    try {
      builder = factory.newDocumentBuilder();
      doc = builder.parse(new File(path));

      // XXX here, we could be strict and only allow valid documents...
      // validate(doc);
      final Element projectRoot = doc.getDocumentElement();
      // load the canvas (or pages and page blocks if any) blocks from the save file
      // also load drawers, or any custom drawers from file.  if no custom drawers
      // are present in root, then the default set of drawers is loaded from
      // langDefRoot
      workspace.loadWorkspaceFrom(projectRoot, langDefRoot);
      workspaceLoaded = true;
    } catch (ParserConfigurationException e) {
      throw new RuntimeException(e);
    } catch (SAXException e) {
      throw new RuntimeException(e);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
Exemplo n.º 16
0
  /**
   * @param plus
   * @requires plus != null
   * @return List containing the two "+" TextualFactoryBlocks and any other blocks containing "+"
   */
  public static List<TextualFactoryBlock> getPlusBlocks(Workspace workspace, String plus) {
    Set<TextualFactoryBlock> matchingBlocks = new HashSet<TextualFactoryBlock>();
    // looks through the factory blocks
    for (RenderableBlock renderable : workspace.getFactoryManager().getBlocks()) {
      if (renderable == null
          || renderable.getBlockID().equals(Block.NULL)
          || !(renderable instanceof FactoryRenderableBlock)) {
        continue;
      }
      // TODO genus names are based from TNG, need to figure out a workaround
      // grabs the "+" number and text blocks
      if (renderable.getBlock().getGenusName().equalsIgnoreCase("sum")) {
        // changes the label so that the search result will not be ambiguous
        matchingBlocks.add(
            new TextualFactoryBlock((FactoryRenderableBlock) renderable, "+ [number]"));
      }
      if (renderable.getBlock().getGenusName().equalsIgnoreCase("string-append")) {
        // changes the label so that the search result will not be ambiguous
        matchingBlocks.add(
            new TextualFactoryBlock((FactoryRenderableBlock) renderable, "+ [text]"));
      }
      // selects any other block that contains the number (for variables that contains the number)
      if (renderable.getKeyword().toLowerCase().contains(plus.toLowerCase())) {
        matchingBlocks.add(
            new TextualFactoryBlock(
                (FactoryRenderableBlock) renderable, renderable.getBlock().getBlockLabel()));
      }
    }

    return new ArrayList<TextualFactoryBlock>(matchingBlocks);
  }
Exemplo n.º 17
0
 /**
  * Loads the programming project specified in the projectContents String, which is associated with
  * the language definition file contained in the specified langDefContents. All the blocks
  * contained in projectContents must have an associted block genus defined in langDefContents.
  *
  * <p>If the langDefContents have any workspace settings such as pages or drawers and
  * projectContents has workspace settings as well, the workspace settings within the
  * projectContents will override the workspace settings in langDefContents.
  *
  * <p>NOTE: The language definition contained in langDefContents does not replace the default
  * language definition file set by: setLangDefFilePath() or setLangDefFile().
  *
  * @param projectContents
  * @param langDefContents String XML that defines the language of projectContents
  */
 public void loadProject(String projectContents, String langDefContents) {
   final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
   final DocumentBuilder builder;
   final Document projectDoc;
   final Document langDoc;
   try {
     builder = factory.newDocumentBuilder();
     projectDoc = builder.parse(new InputSource(new StringReader(projectContents)));
     final Element projectRoot = projectDoc.getDocumentElement();
     langDoc = builder.parse(new InputSource(new StringReader(projectContents)));
     final Element langRoot = langDoc.getDocumentElement();
     if (workspaceLoaded) {
       resetWorkspace();
     }
     if (langDefContents == null) {
       loadBlockLanguage(langDefRoot);
     } else {
       loadBlockLanguage(langRoot);
     }
     workspace.loadWorkspaceFrom(projectRoot, langRoot);
     workspaceLoaded = true;
   } catch (ParserConfigurationException e) {
     throw new RuntimeException(e);
   } catch (SAXException e) {
     throw new RuntimeException(e);
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
 }
Exemplo n.º 18
0
  /**
   * Returns a DOM node for the entire workspace. This includes the block workspace, any custom
   * factories, canvas view state and position, pages
   *
   * @return the DOM node for the entire workspace.
   */
  public Node getSaveNode() {
    try {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      factory.setNamespaceAware(true);

      DocumentBuilder builder = factory.newDocumentBuilder();
      Document document = builder.newDocument();

      Element documentElement =
          document.createElementNS(Constants.XML_CODEBLOCKS_NS, "cb:CODEBLOCKS");
      // schema reference
      documentElement.setAttributeNS(
          XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI,
          "xsi:schemaLocation",
          Constants.XML_CODEBLOCKS_NS + " " + Constants.XML_CODEBLOCKS_SCHEMA_URI);

      Node workspaceNode = workspace.getSaveNode(document);
      if (workspaceNode != null) {
        documentElement.appendChild(workspaceNode);
      }

      document.appendChild(documentElement);
      validate(document);

      return document;
    } catch (ParserConfigurationException e) {
      throw new RuntimeException(e);
    }
  }
Exemplo n.º 19
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.º 20
0
 /** Implement MouseListener interface de-highlight button state */
 public void mouseExited(MouseEvent e) {
   super.mouseExited(e);
   this.setBorder(BorderFactory.createLineBorder(Color.gray));
   Comment comment = workspace.getEnv().getRenderableBlock(getBlockID()).getComment();
   if (!isActive()) {
     comment.setVisible(false);
   }
 }
Exemplo n.º 21
0
 /**
  * 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);
 }
Exemplo n.º 22
0
 /**
  * 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);
 }
Exemplo n.º 23
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();
 }
Exemplo n.º 24
0
 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;
 }
Exemplo n.º 25
0
  /** TypeBlockManager Constructor */
  public TypeBlockManager(Workspace workspace, BlockCanvas component) {
    this.workspace = workspace;

    // turned off the automated block placements
    KeyInputMap.enableDefaultKeyMapping(false);
    this.autoCompletePanel = new AutoCompletePanel(workspace);
    this.blockCanvas = component;
    this.focusManager = workspace.getFocusManager();
  }
Exemplo n.º 26
0
  /**
   * @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);
  }
Exemplo n.º 27
0
 /**
  * Loads a fresh workspace based on the default specifications in the language definition file.
  * The block canvas will have no live blocks.
  */
 public void loadFreshWorkspace() {
   if (workspaceLoaded) {
     resetWorkspace();
   }
   if (langDefDirty) {
     loadBlockLanguage(langDefRoot);
   }
   workspace.loadWorkspaceFrom(null, langDefRoot);
   workspaceLoaded = true;
 }
Exemplo n.º 28
0
 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());
 }
Exemplo n.º 29
0
  public static void deleteBlock(RenderableBlock block) {
    block.setLocation(0, 0);

    WorkspaceWidget widget = block.getParentWidget();
    if (widget != null) {
      widget.removeBlock(block);
    }

    Container parent = block.getParent();
    if (parent != null) {
      parent.remove(block);
      parent.validate();
    }

    block.setParentWidget(null);
    Workspace workspace = block.getWorkspace();
    workspace.notifyListeners(
        new WorkspaceEvent(workspace, widget, block.getBlockID(), WorkspaceEvent.BLOCK_REMOVED));
  }
Exemplo n.º 30
0
 /**
  * @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();
   }
 }