workspace
Class Workspace

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JLayeredPane
                  extended by workspace.Workspace
All Implemented Interfaces:
ExplorerListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.ChangeListener, ISupportMemento, RBParent

public class Workspace
extends javax.swing.JLayeredPane
implements ISupportMemento, RBParent, javax.swing.event.ChangeListener, ExplorerListener

The Workspace is the main block area, where blocks are manipulated and assembled. This class governs the blocks, the world, the view, drawing, dragging, animating.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JLayeredPane
javax.swing.JLayeredPane.AccessibleJLayeredPane
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static java.lang.Integer BLOCK_HIGHLIGHT_LAYER
           
static java.lang.Integer BLOCK_LAYER
           
static java.lang.Integer DRAGGED_BLOCK_HIGHLIGHT_LAYER
           
static java.lang.Integer DRAGGED_BLOCK_LAYER
           
static boolean everyPageHasDrawer
           
static java.lang.Integer PAGE_LAYER
           
static java.lang.Integer WIDGET_LAYER
           
 
Fields inherited from class javax.swing.JLayeredPane
DEFAULT_LAYER, DRAG_LAYER, FRAME_CONTENT_LAYER, LAYER_PROPERTY, MODAL_LAYER, PALETTE_LAYER, POPUP_LAYER
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Method Summary
 void addPage(Page page)
          Adds the specified page to the Workspace at the right end of the canvas
 void addPage(Page page, int position)
          Adds the specified page to the Workspace at the specified position on the canvas
 void addToBlockLayer(java.awt.Component c)
          RBParent implemented methods
 void addToHighlightLayer(java.awt.Component c)
          Add this Component to the HighlightLayer, which is understood to be directly and completely beneath the BlockLayer, such that all Components on the HighlightLayer are rendered behind ALL Components on the BlockLayer.
 void addWidget(WorkspaceWidget widget, boolean addGraphically, boolean floatOverCanvas)
          Adds the specified widget to this Workspace
 void addWorkspaceListener(WorkspaceListener listener)
          Adds the specified WorkspaceListener
 void cleanUpAllBlocks()
          Cleans up all the blocks within the block canvas using the default arrangement algorithm.
 void copyBlocks()
          calls TypeBlockManager to copy the highlighted blocks on the canvas
 void disableMiniMap()
          Disables the MiniMap from canvas
 void enableTypeBlocking(boolean enabled)
          Enables TypeBLocking if and only if enabled == true
 void explorerEventOccurred(ExplorerEvent event)
           
 java.lang.Iterable<SearchableContainer> getAllSearchableContainers()
          Returns an unmodifiable Iterable of all the SearchableContainers within this workspace.
 BlockCanvas getBlockCanvas()
           
 java.lang.Iterable<Block> getBlocks()
          Returns the set of all Blocks in the Workspace.
 java.lang.Iterable<Block> getBlocksFromGenus(java.lang.String genusName)
          Returns all the Blocks of the specified genus.
 java.awt.Dimension getCanvasOffset()
           
 java.awt.Dimension getCanvasSize()
           
 Page getCurrentPage(RenderableBlock block)
          Find the page that lies underneath this block CAN RETURN NULL
 double getCurrentWorkspaceZoom()
          Returns the current workspace zoom
 FactoryManager getFactoryManager()
           
 FocusTraversalManager getFocusManager()
          Returns the FocusTraversalManager instance
static Workspace getInstance()
          Returns the one Workspace instance
 MiniMap getMiniMap()
           
 int getNumPages()
          Returns the number of pages contained within this.
 Page getPageNamed(java.lang.String pageName)
           
 java.lang.Iterable<RenderableBlock> getRenderableBlocks()
          Returns the set of all RenderableBlocks in the Workspace.
 java.lang.Iterable<RenderableBlock> getRenderableBlocksFromGenus(java.lang.String genusName)
          Returns all the RenderableBlocks of the specified genus.
 java.lang.String getSaveString()
          Returns the save String of this.
 java.lang.Object getState()
           
 java.lang.Iterable<RenderableBlock> getTopLevelBlocks()
          Returns the top level blocks in the Workspace (blocks that are parents of stacks)
 WorkspaceWidget getWidgetAt(java.awt.Point point)
          Returns the WorkspaceWidget currently at the specified point
 java.lang.Iterable<WorkspaceWidget> getWorkspaceWidgets()
          Returns an unmodifiable Iterable over all the WorkspaceWidgets
 void loadState(java.lang.Object memento)
           
 void loadWorkspaceFrom(org.w3c.dom.Element newRoot, org.w3c.dom.Element originalLangRoot)
          Loads the workspace with the following content: - RenderableBlocks and their associated Block instances that reside within the BlockCanvas
 void notifyListeners(WorkspaceEvent event)
          Notifies all Workspace listeners of the workspace event
 void pageSelected(Page page, boolean byUser)
          Marks the page of the specified name as being selected.
 void pasteBlocks()
          calls TypeBlockManager to pastes the highlighted blocks on the canvas
 void putPage(Page page, int position)
          Places the specified page at the specified index.
 void redo()
           
 void removePage(Page page)
          Removes the specified page from the Workspace
 void removePageAt(int position)
          Removes the specified page from the Workspace at the specified position, where position 0 is the left most page
 void removeWidget(WorkspaceWidget widget)
          Removes the specified widget from this Workspace
 void removeWorkspaceListener(WorkspaceListener listener)
          Removes the specified WorkspaceListener
 void renamePage(java.lang.String oldName, java.lang.String newName)
          Renames the page with the specified oldName to the specified newName.
 void reset()
          Clears the Workspace of: - all the live blocks in the BlockCanvas.
 void scrollToComponent(javax.swing.JComponent c)
           
 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.
 void setWorkspaceZoom(double newZoom)
          Sets the Workspace zoom at the specified zoom level
 void setWorkspaceZoomToDefault()
          Resets the workspace zoom to the default level
 void stateChanged(javax.swing.event.ChangeEvent e)
           
 void undo()
           
 
Methods inherited from class javax.swing.JLayeredPane
addImpl, getAccessibleContext, getComponentCountInLayer, getComponentsInLayer, getComponentToLayer, getIndexOf, getLayer, getLayer, getLayeredPaneAbove, getObjectForLayer, getPosition, highestLayer, insertIndexForLayer, isOptimizedDrawingEnabled, lowestLayer, moveToBack, moveToFront, paint, paramString, putLayer, remove, removeAll, setLayer, setLayer, setPosition
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

everyPageHasDrawer

public static boolean everyPageHasDrawer

PAGE_LAYER

public static final java.lang.Integer PAGE_LAYER

BLOCK_HIGHLIGHT_LAYER

public static final java.lang.Integer BLOCK_HIGHLIGHT_LAYER

BLOCK_LAYER

public static final java.lang.Integer BLOCK_LAYER

WIDGET_LAYER

public static final java.lang.Integer WIDGET_LAYER

DRAGGED_BLOCK_HIGHLIGHT_LAYER

public static final java.lang.Integer DRAGGED_BLOCK_HIGHLIGHT_LAYER

DRAGGED_BLOCK_LAYER

public static final java.lang.Integer DRAGGED_BLOCK_LAYER
Method Detail

explorerEventOccurred

public void explorerEventOccurred(ExplorerEvent event)
Specified by:
explorerEventOccurred in interface ExplorerListener

getInstance

public static Workspace getInstance()
Returns the one Workspace instance

Returns:
the one Workspace instance

getCanvasSize

public java.awt.Dimension getCanvasSize()

getCanvasOffset

public java.awt.Dimension getCanvasOffset()

getPageNamed

public Page getPageNamed(java.lang.String pageName)

getBlockCanvas

public BlockCanvas getBlockCanvas()

getMiniMap

public MiniMap getMiniMap()
Returns:
MiniMap associated with this.blockcanvas

getFocusManager

public FocusTraversalManager getFocusManager()
Returns the FocusTraversalManager instance

Returns:
FocusTraversalManager instance

disableMiniMap

public void disableMiniMap()
Disables the MiniMap from canvas


getWidgetAt

public WorkspaceWidget getWidgetAt(java.awt.Point point)
Returns the WorkspaceWidget currently at the specified point

Parameters:
point - the Point2D to get the widget at, given in Workspace (i.e. window) coordinates
Returns:
the WorkspaceWidget currently at the specified point

addWidget

public void addWidget(WorkspaceWidget widget,
                      boolean addGraphically,
                      boolean floatOverCanvas)
Adds the specified widget to this Workspace

Parameters:
widget - the desired widget to add
floatOverCanvas - if true, the Workspace will add and render this widget such that it "floats" above the canvas and its set of blocks. If false, the widget will be laid out beside the canvas. This feature only applies if the specified widget is added graphically to the workspace (addGraphically = true)
addGraphically - a Swing dependent parameter to tell the Workspace whether or not to add the specified widget as a child component. This parameter should be false for widgets that have a parent already specified

removeWidget

public void removeWidget(WorkspaceWidget widget)
Removes the specified widget from this Workspace

Parameters:
widget - the desired widget to remove

getWorkspaceWidgets

public java.lang.Iterable<WorkspaceWidget> getWorkspaceWidgets()
Returns an unmodifiable Iterable over all the WorkspaceWidgets

Returns:
an unmodifiable Iterable over all the WorkspaceWidgets

getRenderableBlocks

public java.lang.Iterable<RenderableBlock> getRenderableBlocks()
Returns the set of all RenderableBlocks in the Workspace. Includes all live blocks on all pages. Does NOT include: (1) Factory blocks, (2) dead blocks, (3) or subset blocks. If no blocks are found, it returns an empty set.

Returns:
all the RenderableBlocks in the Workspace or an empty set if none exists.

getBlocks

public java.lang.Iterable<Block> getBlocks()
Returns the set of all Blocks in the Workspace. Includes all live blocks on all pages. Does NOT include: (1) Factory blocks, (2) dead blocks, (3) or subset blocks. If no blocks are found, it returns an empty set.

Returns:
all the Blocks in the Workspace or an empty set if none exists.

getRenderableBlocksFromGenus

public java.lang.Iterable<RenderableBlock> getRenderableBlocksFromGenus(java.lang.String genusName)
Returns all the RenderableBlocks of the specified genus. Include all live blocks on all pages. Does NOT include: (1) all blocks of a different genus (2) Factory blocks, (3) dead blocks, (4) or subset blocks. If no blocks are found, it returns an empty set.

Parameters:
genusName - - the genus name of the blocks to return
Returns:
all the RenderableBlocks of the specified genus or an empty set if none exists.

getBlocksFromGenus

public java.lang.Iterable<Block> getBlocksFromGenus(java.lang.String genusName)
Returns all the Blocks of the specified genus. Include all live blocks on all pages. Does NOT include: (1) all blocks of a different genus (2) Factory blocks, (3) dead blocks, (4) or subset blocks. If no blocks are found, it returns an empty set.

Parameters:
genusName - - the genus name of the blocks to return
Returns:
all the Blocks of the specified genus or an empty set if none exists.

getTopLevelBlocks

public java.lang.Iterable<RenderableBlock> getTopLevelBlocks()
Returns the top level blocks in the Workspace (blocks that are parents of stacks)

Returns:
the top level blocks in the Workspace

cleanUpAllBlocks

public void cleanUpAllBlocks()
Cleans up all the blocks within the block canvas using the default arrangement algorithm. TODO ria for now its the naive arranger that uses just the y-coor.


copyBlocks

public void copyBlocks()
calls TypeBlockManager to copy the highlighted blocks on the canvas


pasteBlocks

public void pasteBlocks()
calls TypeBlockManager to pastes the highlighted blocks on the canvas


addWorkspaceListener

public void addWorkspaceListener(WorkspaceListener listener)
Adds the specified WorkspaceListener


removeWorkspaceListener

public void removeWorkspaceListener(WorkspaceListener listener)
Removes the specified WorkspaceListener

Parameters:
listener -

notifyListeners

public void notifyListeners(WorkspaceEvent event)
Notifies all Workspace listeners of the workspace event

Parameters:
event -

enableTypeBlocking

public void enableTypeBlocking(boolean enabled)
Enables TypeBLocking if and only if enabled == true


setWorkspaceZoom

public void setWorkspaceZoom(double newZoom)
Sets the Workspace zoom at the specified zoom level

Parameters:
newZoom - the desired zoom level

getCurrentWorkspaceZoom

public double getCurrentWorkspaceZoom()
Returns the current workspace zoom

Returns:
the current workspace zoom

setWorkspaceZoomToDefault

public void setWorkspaceZoomToDefault()
Resets the workspace zoom to the default level


scrollToComponent

public void scrollToComponent(javax.swing.JComponent c)

stateChanged

public void stateChanged(javax.swing.event.ChangeEvent e)
Specified by:
stateChanged in interface javax.swing.event.ChangeListener

addPage

public void addPage(Page page)
Adds the specified page to the Workspace at the right end of the canvas

Parameters:
page - the desired page to add

addPage

public void addPage(Page page,
                    int position)
Adds the specified page to the Workspace at the specified position on the canvas

Parameters:
page - the desired page to add

putPage

public void putPage(Page page,
                    int position)
Places the specified page at the specified index. If a page already exists at that index, this method will replace it.

Parameters:
page - the Page to place
position - - the position to place the specified page, where 0 is the leftmost page

removePageAt

public void removePageAt(int position)
Removes the specified page from the Workspace at the specified position, where position 0 is the left most page

Parameters:
position -

removePage

public void removePage(Page page)
Removes the specified page from the Workspace

Parameters:
page - the desired page to remove

renamePage

public void renamePage(java.lang.String oldName,
                       java.lang.String newName)
Renames the page with the specified oldName to the specified newName.

Parameters:
oldName - the oldName of the page to rename
newName - the String name to change the page name to

getNumPages

public int getNumPages()
Returns the number of pages contained within this. By default will always have a page even if a page was not specified. The page will just be blank.

Returns:
the number of pages contained within this

getCurrentPage

public Page getCurrentPage(RenderableBlock block)
Find the page that lies underneath this block CAN RETURN NULL

Parameters:
block -

pageSelected

public void pageSelected(Page page,
                         boolean byUser)
Marks the page of the specified name as being selected. The workspace view may shift to that page.

Parameters:
page - the Page selected
byUser - true if Page was selected by the User

getFactoryManager

public FactoryManager getFactoryManager()

getAllSearchableContainers

public java.lang.Iterable<SearchableContainer> getAllSearchableContainers()
Returns an unmodifiable Iterable of all the SearchableContainers within this workspace.


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

getSaveString

public java.lang.String getSaveString()
Returns the save String of this. Currently returns the BlockCanvas save String only.

Returns:
the save String of this.

loadWorkspaceFrom

public void loadWorkspaceFrom(org.w3c.dom.Element newRoot,
                              org.w3c.dom.Element originalLangRoot)
Loads the workspace with the following content: - RenderableBlocks and their associated Block instances that reside within the BlockCanvas

Parameters:
newRoot - the XML Element containing the new desired content. Some of the content in newRoot may override the content in originalLangRoot. (For now, pages are automatically overwritten. In the future, will allow drawers to be optionally overriden or new drawers to be inserted.)
originalLangRoot - the original language/workspace specification content

reset

public void reset()
Clears the Workspace of: - all the live blocks in the BlockCanvas. - all the pages on the BlockCanvas - all its BlockDrawers and the RB's that reside within them - clears all the BlockDrawer bars of its drawer references and their associated buttons - clears all RenderableBlock instances (which clears their associated Block instances.) Note: we want to get rid of all RendereableBlocks and their references. Want to get the Workspace ready to load another workspace


getState

public java.lang.Object getState()
Specified by:
getState in interface ISupportMemento

loadState

public void loadState(java.lang.Object memento)
Specified by:
loadState in interface ISupportMemento

undo

public void undo()

redo

public void redo()

addToBlockLayer

public void addToBlockLayer(java.awt.Component c)
RBParent implemented methods

Specified by:
addToBlockLayer in interface RBParent
Parameters:
c - the Component to add

addToHighlightLayer

public void addToHighlightLayer(java.awt.Component c)
Description copied from interface: RBParent
Add this Component to the HighlightLayer, which is understood to be directly and completely beneath the BlockLayer, such that all Components on the HighlightLayer are rendered behind ALL Components on the BlockLayer.

Specified by:
addToHighlightLayer in interface RBParent
Parameters:
c - the Component to add