Ejemplo n.º 1
0
  public void workspaceEventOccurred(WorkspaceEvent event) {
    // THIS ENTIRE METHOD IS A HACK!
    // PLEASE CHANGE WITH CAUTION
    // IT DOES SOME PREETY STRANGE THINGS
    if (event.getEventType() == WorkspaceEvent.BLOCK_ADDED) {
      if (event.getSourceWidget() instanceof Page) {
        Page page = (Page) event.getSourceWidget();
        Block block = Block.getBlock(event.getSourceBlockID());
        // block may not be null if this is a block added event
        if (block.hasStubs()) {
          for (BlockStub stub : block.getFreshStubs()) {
            this.addDynamicBlock(
                new FactoryRenderableBlock(this, stub.getBlockID()), page.getPageDrawer());
          }
        }
      }
    } else if (event.getEventType() == WorkspaceEvent.BLOCK_REMOVED) {
      // may not be removing a null stanc eof block, so DO NOT check for it
      Block block = Block.getBlock(event.getSourceBlockID());
      if (block.hasStubs()) {
        for (Long stub : BlockStub.getStubsOfParent(block.getBlockID())) {
          RenderableBlock rb = RenderableBlock.getRenderableBlock(stub);
          if (rb != null
              && !rb.getBlockID().equals(Block.NULL)
              && rb.getParentWidget() != null
              && rb.getParentWidget().equals(this)) {
            // rb.getParent() should not be null
            rb.getParent().remove(rb);
            rb.setParentWidget(null);
          }
        }
      }
      this.relayoutBlocks();
    } else if (event.getEventType() == WorkspaceEvent.BLOCK_MOVED) {
      Block block = Block.getBlock(event.getSourceBlockID());
      if (block != null && block.hasStubs()) {
        for (Long stub : BlockStub.getStubsOfParent(block.getBlockID())) {
          RenderableBlock rb = RenderableBlock.getRenderableBlock(stub);
          if (rb != null
              && !rb.getBlockID().equals(Block.NULL)
              && rb.getParentWidget() != null
              && rb.getParentWidget().equals(this)) {
            // rb.getParent() should not be null
            rb.getParent().remove(rb);
            rb.setParentWidget(null);
          }
        }
        this.relayoutBlocks();
      }

    } else if (event.getEventType() == WorkspaceEvent.PAGE_RENAMED) {
      // this.relayoutBlocks();
    }
  }
Ejemplo n.º 2
0
 public void addDynamicBlocks(Collection<RenderableBlock> blocks, String drawer) {
   // find canvas
   for (FactoryCanvas canvas : this.dynamicCanvases) {
     if (canvas.getName().equals(drawer)) {
       for (RenderableBlock block : blocks) {
         if (block == null || Block.NULL.equals(block.getBlockID())) continue;
         canvas.addBlock(block);
         Workspace.getInstance()
             .notifyListeners(
                 new WorkspaceEvent(this, block.getBlockID(), WorkspaceEvent.BLOCK_ADDED));
       }
       canvas.layoutBlocks();
       return;
     }
   }
   this.printError("Drawer not found: " + drawer);
   return;
 }
Ejemplo n.º 3
0
 /**
  * Adds the specified RenderableBlocks to the drawer with the specified drawerName. Do nothing if
  * the drawer with the specified drawerName does not exist.
  *
  * @param blocks Collection of RenderableBlocks to the drawer with name: drawerName
  * @param drawerName String name of the drawer to add blocks to
  */
 public void addSubsetBlocks(Collection<RenderableBlock> blocks, String drawerName) {
   // find canvas //TODO generalize the following code to one method where you pass in the blocks,
   // drawername, and canvas types
   for (FactoryCanvas canvas : this.subsetCanvases) {
     if (canvas.getName().equals(drawerName)) {
       for (RenderableBlock block : blocks) {
         if (block == null || Block.NULL.equals(block.getBlockID())) continue;
         canvas.addBlock(block);
         Workspace.getInstance()
             .notifyListeners(
                 new WorkspaceEvent(this, block.getBlockID(), WorkspaceEvent.BLOCK_ADDED));
       }
       canvas.layoutBlocks();
       return;
     }
   }
   this.printError("Drawer not found: " + drawerName);
   return;
 }
Ejemplo n.º 4
0
 public void addDynamicBlock(RenderableBlock block, String drawer) {
   for (FactoryCanvas canvas : this.dynamicCanvases) {
     if (canvas.getName().equals(drawer)) {
       if (block == null || Block.NULL.equals(block.getBlockID())) {
         printError("Attempting to add a null instance of block");
         return;
       } else {
         canvas.addBlock(block);
         Workspace.getInstance()
             .notifyListeners(
                 new WorkspaceEvent(this, block.getBlockID(), WorkspaceEvent.BLOCK_ADDED));
         canvas.layoutBlocks();
         return;
       }
     }
   }
   this.printError("Drawer not found: " + drawer);
   return;
 }
Ejemplo n.º 5
0
 /**
  * Sets up the subsets by clearing all subsets and installing the new collection of subsets. If
  * "usingSys" is true, the the factory and myblocks drawers will be accessible. If "usingSubs" is
  * true, then the subset drawers will be accessible.
  *
  * @param subsets - collection of subsets
  * @param usingSys - true for factory and myblocks
  * @param usingSubs - true for subsets
  */
 public void setupSubsets(Collection<Subset> subsets, boolean usingSys, boolean usingSubs) {
   if (usingSubs) {
     this.subsetCanvases.clear();
     for (Subset subset : subsets) {
       FactoryCanvas canvas = new FactoryCanvas(subset.getName(), subset.getColor());
       for (RenderableBlock frb : subset.getBlocks()) {
         canvas.addBlock(frb);
         Workspace.getInstance()
             .notifyListeners(
                 new WorkspaceEvent(this, frb.getBlockID(), WorkspaceEvent.BLOCK_ADDED));
       }
       canvas.layoutBlocks();
       this.subsetCanvases.add(canvas);
     }
     this.navigator.setCanvas(this.subsetCanvases, SUBSETS_NAME);
     if (usingSys) {
       this.factorySwicther.removeAll();
       this.factorySwicther.add(this.navigator.getSwitcher());
     } else {
       this.factorySwicther.removeAll();
       this.factorySwicther.add(new CLabel(SUBSETS_NAME));
     }
     this.viewSubsetsDrawers();
   } else if (usingSys) {
     this.factorySwicther.removeAll();
     final CBorderlessButton factoryButton = new CBorderlessButton(STATIC_NAME);
     final CBorderlessButton myblocksButton = new CBorderlessButton(DYNAMIC_NAME);
     ActionListener listener =
         new ActionListener() {
           public void actionPerformed(ActionEvent e) {
             if (factoryButton.equals(e.getSource())) {
               FactoryManager.this.viewStaticDrawers();
             } else if (myblocksButton.equals(e.getSource())) {
               FactoryManager.this.viewDynamicDrawers();
             }
           }
         };
     factoryButton.addActionListener(listener);
     myblocksButton.addActionListener(listener);
     this.factorySwicther.add(factoryButton, BorderLayout.WEST);
     this.factorySwicther.add(myblocksButton, BorderLayout.EAST);
     this.viewStaticDrawers();
   }
   this.factorySwicther.revalidate();
   this.factorySwicther.repaint();
 }
Ejemplo n.º 6
0
  public void blockDropped(RenderableBlock block) {
    // remove block
    WorkspaceWidget oldParent = block.getParentWidget();
    if (oldParent != null) oldParent.removeBlock(block);

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

    // fire to workspace that block was removed
    // DO FIRE AN EVENT IF BLOCK IS REMOVED BY USER!!!!
    // NOTE however that we do not throw na event for adding internally
    Workspace.getInstance()
        .notifyListeners(
            new WorkspaceEvent(this, block.getBlockID(), WorkspaceEvent.BLOCK_REMOVED));
  }