Example #1
0
 /**
  * Returns a collection of the subsets within this
  *
  * @return a collection of the subsets within this
  */
 public Collection<Subset> getSubsets() {
   Collection<Subset> subsets = new ArrayList<Subset>();
   for (FactoryCanvas subset : subsetCanvases) {
     Iterable<RenderableBlock> blocks = subset.getBlocks();
     subsets.add(new Subset(subset.getName(), subset.getColor(), blocks));
   }
   return subsets;
 }
Example #2
0
 /** Relayout all the drawers */
 public void relayoutBlocks() {
   for (FactoryCanvas canvas : this.staticCanvases) {
     canvas.layoutBlocks();
   }
   for (FactoryCanvas canvas : this.dynamicCanvases) {
     canvas.layoutBlocks();
   }
 }
Example #3
0
 /**
  * @return all blocks in all drawers. If no blocks found, return an empty set. Ifno drawers exists
  *     in either factories, return an empty set.
  */
 public Collection<RenderableBlock> getBlocks() {
   ArrayList<RenderableBlock> blocks = new ArrayList<RenderableBlock>();
   for (FactoryCanvas canvas : this.staticCanvases) {
     blocks.addAll(canvas.getBlocks());
   }
   for (FactoryCanvas canvas : this.dynamicCanvases) {
     blocks.addAll(canvas.getBlocks());
   }
   return blocks;
 }
Example #4
0
 public Collection<RenderableBlock> getDynamicBlocks(String name) {
   ArrayList<RenderableBlock> blocks = new ArrayList<RenderableBlock>();
   for (FactoryCanvas canvas : this.dynamicCanvases) {
     if (canvas.getName().equals(name)) {
       blocks.addAll(canvas.getBlocks());
       return blocks;
     }
   }
   this.printError("Drawer not found: " + name);
   return blocks;
 }
Example #5
0
 public void removeDynamicBlock(RenderableBlock block, String drawer) {
   // find canvas
   for (FactoryCanvas canvas : this.dynamicCanvases) {
     if (canvas.getName().equals(drawer)) {
       canvas.removeBlock(block);
       // DO NOT THROW AN EVENT FOR REMOVING DRAWER BLOCKS!!!
       // Workspace.getInstance().notifyListeners(new WorkspaceEvent(FactoryManager.this,
       // block.getBlockID(), WorkspaceEvent.BLOCK_REMOVED));
       canvas.layoutBlocks();
       return;
     }
   }
   this.printError("Drawer not found: " + drawer);
   return;
 }
Example #6
0
 public void removeDynamicDrawer(String name) {
   FactoryCanvas canvas = null;
   for (FactoryCanvas c : this.dynamicCanvases) {
     if (c.getName().equals(name)) {
       canvas = c;
     }
   }
   if (canvas != null) {
     this.dynamicCanvases.remove(canvas);
     this.navigator.setCanvas(this.dynamicCanvases, DYNAMIC_NAME);
     return;
   }
   this.printError("No Drawer found with name: " + name);
   return;
 }
Example #7
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();
 }
Example #8
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;
 }
Example #9
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;
 }
Example #10
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;
 }
Example #11
0
 public void renameDynamicDrawer(String oldName, String newName) {
   // check rep
   if (oldName == null || newName == null) {
     this.printError("Drawers may not have a null instance for a name.");
     return;
   }
   for (FactoryCanvas duplicateCanvas : this.dynamicCanvases) {
     if (duplicateCanvas.getName().equals(newName)) {
       this.printError("Drawer already exists with name: " + newName);
       return;
     }
   }
   // rename
   for (FactoryCanvas oldCanvas : this.dynamicCanvases) {
     if (oldCanvas.getName().equals(oldName)) {
       oldCanvas.setName(newName);
       return;
     }
   }
   this.printError("No Drawer was found with the name: " + oldName);
   return;
 }