workspace
Class FactoryManager

java.lang.Object
  extended by workspace.FactoryManager
All Implemented Interfaces:
java.awt.event.ComponentListener, java.util.EventListener, WorkspaceListener, WorkspaceWidget

public class FactoryManager
extends java.lang.Object
implements WorkspaceWidget, java.awt.event.ComponentListener, WorkspaceListener

***********************OVERVIEW************************** The FactoryManager manages all block factories in the workspace. It has three main functions: to control and display all factories in one simple UI design, to manage the additions of new drawers, and to add blocks to throse drawers appropriately. The FactoryManager manages two factories: the static factory and dynamic factory. Each factory has a set of drawers. NO TWO DRAWERS WITHIN ANY FACTORY MAY SHARE the same name. ********************FACTORY STRUCTURE*********************** Let's take a look into the stucture of a factory. Factory is a pallete that sits on the far left side of the workspace. It has a bunch of drawers that slides up and down. Each drawer contains a bunch of related blocks that can be dragged out. The FactoryManager has two types of drawers: static and dynamic. To add, remove, rename, drawers of either type, users should invoke the name that specifies a particular drawer. Users may also add blocks to the drawers or retrieve the set of blocks that each drawer holds. *************IMPLEMENTATION DETAIL****************** How the FactoryManager implements this UI is implementation dependant. Right now, it uses the Navigator-Explorer-Canvas deisgn. Clients of the FactoryManager should know nothing about the internal GUIs used to control the interface. Internally, a Canvas (rahter than an instance of Drawer) is created for every "drawer" that the user wishes to add. But this is an implementation detail that the user should not be bothered with. All the user should know is that a "drawer" specified by some String object was created. The handling of the drawers themselves are dealt with internally. In a previous design of the factories, developers had to create instance of Drawers and pass them along to the the factories. In the NEW design, we remove that burden from the developer and allow the developer to access drawers by calling its name only. This may limit extensibility but keeps the system more robust. *********************A WORD ON DRAWER********************** Please note that the word "drawer" as it is used by the FactoryManager refers to the object that holds blocks. A factory holds a bunch of drawers, which in turn holds a bunch of blocks. Please do not mix this definition with the CSwing Drawer class. A CSwing Drawer is a low-level component that is used in a CSwing Exlorer. Here, when the documentation refers to drawers, it is NOT refering to the CSwing Drawer. Rather, when we say "drawer", we are referign to that object that holds blocks. *****************NAMING OF DRAWERS************************* Each factory may have only ONE drawer with a particular name. Two different factories may NOT share a name. If we have a static drawer named "FOO", we may not have another drawer named "FOO" in the dynamic drawers.


Constructor Summary
FactoryManager(boolean hasStatic, boolean hasDynamic)
          Constucts new Factorymanager
 
Method Summary
 void addBlock(RenderableBlock block)
          Adds the specified block to this widget interally and graphically.
 void addBlocks(java.util.Collection<RenderableBlock> blocks)
          Adds a collection of blocks to this widget internally and graphically.
 void addDynamicBlock(RenderableBlock block, java.lang.String drawer)
           
 void addDynamicBlocks(java.util.Collection<RenderableBlock> blocks, java.lang.String drawer)
           
 void addDynamicDrawer(java.lang.String name)
          Adds a static drawer if no drawer with the specified name already exists.
 void addDynamicDrawer(java.lang.String name, int position)
          Adds a duynamic drawer if no drawer with the specified name already exists.
 void addStaticBlock(RenderableBlock block, java.lang.String drawer)
          Add blocks to drawer if drawer can be found.
 void addStaticBlocks(java.util.Collection<RenderableBlock> blocks, java.lang.String drawer)
          Add blocks to drawer if drawer can be found.
 void addStaticDrawer(java.lang.String name, java.awt.Color color)
          Adds a static drawer if no drawer with the specified name already exists.
 void addStaticDrawer(java.lang.String name, int position, java.awt.Color color)
          Adds a static drawer if no drawer with the specified name already exists.
 void addSubsetBlocks(java.util.Collection<RenderableBlock> blocks, java.lang.String drawerName)
          Adds the specified RenderableBlocks to the drawer with the specified drawerName.
 void addSubsetDrawer(java.lang.String name, java.awt.Color color)
          Adds a new Subset drawer with the specified name and button color.
 void addSubsetDrawer(java.lang.String name, int position, java.awt.Color color)
          Adds a new Subset drawer with the specified name and button color at the specified position.
 void blockDragged(RenderableBlock block)
          Called by RenderableBlocks as they are dragged over this Widget.
 void blockDropped(RenderableBlock block)
          Called by RenderableBlocks that get "dropped" onto this Widget
 void blockEntered(RenderableBlock block)
          Called when a RenderableBlock is being dragged and goes from being outside this Widget to being inside the Widget.
 void blockExited(RenderableBlock block)
          Called when a RenderableBlock that was being dragged over this Widget goes from being inside this Widget to being outside the Widget.
 void componentHidden(java.awt.event.ComponentEvent e)
           
 void componentMoved(java.awt.event.ComponentEvent e)
           
 void componentResized(java.awt.event.ComponentEvent e)
           
 void componentShown(java.awt.event.ComponentEvent e)
           
 boolean contains(int x, int y)
          Widgets must be able to report whether a given point is inside them
 java.util.Collection<RenderableBlock> getBlocks()
          Returns the set of blocks that abstract "lives" inside this widget.
 java.util.Collection<RenderableBlock> getDynamicBlocks(java.lang.String name)
           
 java.util.Collection<java.lang.String> getDynamicDrawers()
           
 javax.swing.JComponent getFactorySwitcher()
           
 javax.swing.JComponent getJComponent()
          Very Java Swing dependent method
 Navigator getNavigator()
           
 java.util.Collection<SearchableContainer> getSearchableContainers()
           
 java.util.Collection<RenderableBlock> getStaticBlocks(java.lang.String name)
           
 java.util.Collection<java.lang.String> getStaticDrawers()
           
 java.util.Collection<Subset> getSubsets()
          Returns a collection of the subsets within this
 void relayoutBlocks()
          Relayout all the drawers
 void removeBlock(RenderableBlock block)
          Used by RenderableBlocks to tell their originating Widgets that they're moving somewhere else and so should be removed.
 void removeDynamicBlock(RenderableBlock block, java.lang.String drawer)
           
 void removeDynamicDrawer(java.lang.String name)
           
 void removeStaticBlock(RenderableBlock block, java.lang.String drawer)
          Removes block from specified drawer.
 void removeStaticDrawer(java.lang.String name)
          removes drawer with specified name.
 void renameDynamicDrawer(java.lang.String oldName, java.lang.String newName)
           
 void renameStaticDrawer(java.lang.String oldName, java.lang.String newName)
          Renames drawer from oldName to newName.
 void reset()
          Resets FactoryManager
 void setupSubsets(java.util.Collection<Subset> subsets, boolean usingSys, boolean usingSubs)
          Sets up the subsets by clearing all subsets and installing the new collection of subsets.
 java.lang.String toString()
           
 void viewDynamicDrawers()
          Switch view to the set of dynamic drawers
 void viewStaticDrawers()
          Swicth view to the set of static drawers
 void viewSubsetsDrawers()
           
 void workspaceEventOccurred(WorkspaceEvent event)
          Invoked whenever any of the enumerated events specified within WorkspaceEvent occur.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FactoryManager

public FactoryManager(boolean hasStatic,
                      boolean hasDynamic)
Constucts new Factorymanager

Parameters:
hasStatic -
hasDynamic -
Method Detail

reset

public void reset()
Resets FactoryManager


setupSubsets

public void setupSubsets(java.util.Collection<Subset> subsets,
                         boolean usingSys,
                         boolean usingSubs)
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.

Parameters:
subsets - - collection of subsets
usingSys - - true for factory and myblocks
usingSubs - - true for subsets

componentResized

public void componentResized(java.awt.event.ComponentEvent e)
Specified by:
componentResized in interface java.awt.event.ComponentListener

componentHidden

public void componentHidden(java.awt.event.ComponentEvent e)
Specified by:
componentHidden in interface java.awt.event.ComponentListener

componentMoved

public void componentMoved(java.awt.event.ComponentEvent e)
Specified by:
componentMoved in interface java.awt.event.ComponentListener

componentShown

public void componentShown(java.awt.event.ComponentEvent e)
Specified by:
componentShown in interface java.awt.event.ComponentListener

relayoutBlocks

public void relayoutBlocks()
Relayout all the drawers


getNavigator

public Navigator getNavigator()

getSearchableContainers

public java.util.Collection<SearchableContainer> getSearchableContainers()
Returns:
the set of searchable contianers in all factories

getSubsets

public java.util.Collection<Subset> getSubsets()
Returns a collection of the subsets within this

Returns:
a collection of the subsets within this

getStaticDrawers

public java.util.Collection<java.lang.String> getStaticDrawers()
Returns:
an array containing the set of drawers in no particular order. If no drawers exists, then an empty set is returned. The return value MAY NOT BE NULL.

getDynamicDrawers

public java.util.Collection<java.lang.String> getDynamicDrawers()

viewStaticDrawers

public void viewStaticDrawers()
Swicth view to the set of static drawers


viewDynamicDrawers

public void viewDynamicDrawers()
Switch view to the set of dynamic drawers


viewSubsetsDrawers

public void viewSubsetsDrawers()

addStaticDrawer

public void addStaticDrawer(java.lang.String name,
                            java.awt.Color color)
Adds a static drawer if no drawer with the specified name already exists. If one alreaedy exist, then do ntohing. If the name is null, do nothing

Parameters:
name - - name os drawer, may not be null
color -

addStaticDrawer

public void addStaticDrawer(java.lang.String name,
                            int position,
                            java.awt.Color color)
Adds a static drawer if no drawer with the specified name already exists. If one alreaedy exist, then do ntohing. If the name is null, do nothing

Parameters:
name - - name os drawer, may not be null
color -
position -

addSubsetDrawer

public void addSubsetDrawer(java.lang.String name,
                            java.awt.Color color)
Adds a new Subset drawer with the specified name and button color. Places the drawer button below the last added subset drawer

Parameters:
name - String name of new subset drawer, should not be null
color - Color of drawer button

addSubsetDrawer

public void addSubsetDrawer(java.lang.String name,
                            int position,
                            java.awt.Color color)
Adds a new Subset drawer with the specified name and button color at the specified position.

Parameters:
name - String name of the new subset drawer, should not be null.
position - index of drawer button position in block drawer set
color - button color of drawer

addDynamicDrawer

public void addDynamicDrawer(java.lang.String name)
Adds a static drawer if no drawer with the specified name already exists. If one alreaedy exist, then do ntohing. If the name is null, do nothing

Parameters:
name - - name os drawer, may not be null

addDynamicDrawer

public void addDynamicDrawer(java.lang.String name,
                             int position)
Adds a duynamic drawer if no drawer with the specified name already exists. If one alreaedy exist, then do ntohing. If the name is null, do nothing

Parameters:
name - - name os drawer, may not be null
position -

renameStaticDrawer

public void renameStaticDrawer(java.lang.String oldName,
                               java.lang.String newName)
Renames drawer from oldName to newName. Only perform this action if: (1) there exists a drawer specified by oldName, (2) there exists no drawers specified by newName (3) oldName and newName != null

Parameters:
oldName -
newName -

renameDynamicDrawer

public void renameDynamicDrawer(java.lang.String oldName,
                                java.lang.String newName)

removeStaticDrawer

public void removeStaticDrawer(java.lang.String name)
removes drawer with specified name. Only perform this action if: (1) there exists a drawer specified by name, (3) name != null

Parameters:
name -

removeDynamicDrawer

public void removeDynamicDrawer(java.lang.String name)

getStaticBlocks

public java.util.Collection<RenderableBlock> getStaticBlocks(java.lang.String name)

getDynamicBlocks

public java.util.Collection<RenderableBlock> getDynamicBlocks(java.lang.String name)

getBlocks

public java.util.Collection<RenderableBlock> getBlocks()
Description copied from interface: WorkspaceWidget
Returns the set of blocks that abstract "lives" inside this widget. Does not return all the blocks that exists in thsi component, or return all the blocks that are handled by this widget. Rather, the set of blocks returned all the blocks that "lives" in this widget.

Specified by:
getBlocks in interface WorkspaceWidget
Returns:
all blocks in all drawers. If no blocks found, return an empty set. Ifno drawers exists in either factories, return an empty set.

addStaticBlock

public void addStaticBlock(RenderableBlock block,
                           java.lang.String drawer)
Add blocks to drawer if drawer can be found. Do nothing if no drawer if specified name is found.

Parameters:
block -
drawer -

addDynamicBlock

public void addDynamicBlock(RenderableBlock block,
                            java.lang.String drawer)

addStaticBlocks

public void addStaticBlocks(java.util.Collection<RenderableBlock> blocks,
                            java.lang.String drawer)
Add blocks to drawer if drawer can be found. Add graphically and alos throw event. Do nothing if no drawer if specified name is found.

Parameters:
blocks -
drawer -

addDynamicBlocks

public void addDynamicBlocks(java.util.Collection<RenderableBlock> blocks,
                             java.lang.String drawer)

addSubsetBlocks

public void addSubsetBlocks(java.util.Collection<RenderableBlock> blocks,
                            java.lang.String drawerName)
Adds the specified RenderableBlocks to the drawer with the specified drawerName. Do nothing if the drawer with the specified drawerName does not exist.

Parameters:
blocks - Collection of RenderableBlocks to the drawer with name: drawerName
drawerName - String name of the drawer to add blocks to

removeStaticBlock

public void removeStaticBlock(RenderableBlock block,
                              java.lang.String drawer)
Removes block from specified drawer. DO nothing if no drawer is found with specified name.

Parameters:
block -
drawer -

removeDynamicBlock

public void removeDynamicBlock(RenderableBlock block,
                               java.lang.String drawer)

blockEntered

public void blockEntered(RenderableBlock block)
Description copied from interface: WorkspaceWidget
Called when a RenderableBlock is being dragged and goes from being outside this Widget to being inside the Widget.

Specified by:
blockEntered in interface WorkspaceWidget
Parameters:
block - the RenderableBlock being dragged

blockExited

public void blockExited(RenderableBlock block)
Description copied from interface: WorkspaceWidget
Called when a RenderableBlock that was being dragged over this Widget goes from being inside this Widget to being outside the Widget.

Specified by:
blockExited in interface WorkspaceWidget
Parameters:
block - the RenderableBlock being dragged

blockDragged

public void blockDragged(RenderableBlock block)
Description copied from interface: WorkspaceWidget
Called by RenderableBlocks as they are dragged over this Widget.

Specified by:
blockDragged in interface WorkspaceWidget
Parameters:
block - the RenderableBlock being dragged

removeBlock

public void removeBlock(RenderableBlock block)
Description copied from interface: WorkspaceWidget
Used by RenderableBlocks to tell their originating Widgets that they're moving somewhere else and so should be removed.

Specified by:
removeBlock in interface WorkspaceWidget
Parameters:
block - the RenderableBlock

addBlock

public void addBlock(RenderableBlock block)
Description copied from interface: WorkspaceWidget
Adds the specified block to this widget interally and graphically. The difference between this method and blockDropped is that blockDropped is activated by user actions, such as mouse drag and drop or typeblocking. Use this method only for single blocks, as it may cause repainting! For adding several blocks at once use addBlocks, which delays graphical updates until after the blocks have all been added.

Specified by:
addBlock in interface WorkspaceWidget
Parameters:
block - the desired RenderableBlock to add to this

addBlocks

public void addBlocks(java.util.Collection<RenderableBlock> blocks)
Description copied from interface: WorkspaceWidget
Adds a collection of blocks to this widget internally and graphically. This method adds blocks internally first, and only updates graphically once all of the blocks have been added. It is therefore preferable to use this method rather than addBlock whenever multiple blocks will be added.

Specified by:
addBlocks in interface WorkspaceWidget
Parameters:
blocks - the Collection of RenderableBlocks to add

blockDropped

public void blockDropped(RenderableBlock block)
Description copied from interface: WorkspaceWidget
Called by RenderableBlocks that get "dropped" onto this Widget

Specified by:
blockDropped in interface WorkspaceWidget
Parameters:
block - the RenderableBlock that is "dropped" onto this Widget

getJComponent

public javax.swing.JComponent getJComponent()
Description copied from interface: WorkspaceWidget
Very Java Swing dependent method

Specified by:
getJComponent in interface WorkspaceWidget
Returns:
the JComponent-ized cast of this widget.

getFactorySwitcher

public javax.swing.JComponent getFactorySwitcher()

contains

public boolean contains(int x,
                        int y)
Description copied from interface: WorkspaceWidget
Widgets must be able to report whether a given point is inside them

Specified by:
contains in interface WorkspaceWidget

workspaceEventOccurred

public void workspaceEventOccurred(WorkspaceEvent event)
Description copied from interface: WorkspaceListener
Invoked whenever any of the enumerated events specified within WorkspaceEvent occur. We leave it to the implementor to look at the event type and determine what to do from there. We chose this design so that listeners need not implement all X methods, where X is the number of workspace events.

Specified by:
workspaceEventOccurred in interface WorkspaceListener
Parameters:
event - WorkspaceEvent object holding information regarding the triggered event.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object