Ejemplo n.º 1
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));
 }
Ejemplo n.º 2
0
 private void removeChildrenBlock(
     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 : workspace.getEnv().getBlock(renderable.getBlockID()).getSockets()) {
     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 it is a procedure block, we want to delete the entire stack
   if (workspace.getEnv().getBlock(renderable.getBlockID()).isProcedureDeclBlock()) {
     if (workspace.getEnv().getBlock(renderable.getBlockID()).getAfterBlockID() != Block.NULL) {
       removeAfterBlock(
           workspace
               .getEnv()
               .getRenderableBlock(
                   workspace.getEnv().getBlock(renderable.getBlockID()).getAfterBlockID()),
           widget,
           container);
       this.disconnectBlock(
           workspace
               .getEnv()
               .getBlock(workspace.getEnv().getBlock(renderable.getBlockID()).getAfterBlockID()),
           widget);
     }
   }
   if (renderable.hasComment()) {
     renderable.removeComment();
   }
   workspace.notifyListeners(
       new WorkspaceEvent(
           workspace, widget, renderable.getBlockID(), WorkspaceEvent.BLOCK_REMOVED));
 }
Ejemplo n.º 3
0
  /** @overrides WorkspaceWidget.addBlock() */
  @Override
  public void addBlock(RenderableBlock block) {
    // update parent widget if dropped block
    WorkspaceWidget oldParent = block.getParentWidget();
    if (oldParent != this) {
      if (oldParent != null) {
        oldParent.removeBlock(block);
        if (block.hasComment()) {
          block.getComment().getParent().remove(block.getComment());
        }
      }
      block.setParentWidget(this);
      if (block.hasComment()) {
        block.getComment().setParent(block.getParentWidget().getJComponent());
      }
    }

    this.getRBParent().addToBlockLayer(block);
    block.setHighlightParent(this.getRBParent());

    // if block has page labels enabled, in other words, if it can, then set page label to this
    if (workspace.getEnv().getBlock(block.getBlockID()).isPageLabelSetByPage()) {
      workspace.getEnv().getBlock(block.getBlockID()).setPageLabel(this.getPageName());
    }

    // notify block to link default args if it has any
    block.linkDefArgs();

    // fire to workspace that block was added to canvas if oldParent != this
    if (oldParent != this) {
      workspace.notifyListeners(
          new WorkspaceEvent(workspace, oldParent, block.getBlockID(), WorkspaceEvent.BLOCK_MOVED));
      workspace.notifyListeners(
          new WorkspaceEvent(
              workspace, this, block.getBlockID(), WorkspaceEvent.BLOCK_ADDED, true));
    }

    // if the block is off the edge, shift everything or grow as needed to fully show it
    this.reformBlockPosition(block);

    this.pageJComponent.setComponentZOrder(block, 0);
  }