workspace.typeblocking
Class FocusTraversalManager

java.lang.Object
  extended by workspace.typeblocking.FocusTraversalManager
All Implemented Interfaces:
java.awt.event.KeyListener, java.awt.event.MouseListener, java.util.EventListener, WorkspaceListener

public class FocusTraversalManager
extends java.lang.Object
implements java.awt.event.MouseListener, java.awt.event.KeyListener, WorkspaceListener

The FocusTraversalManager has two function. First, it maintains a pointer to the block, if any, that has focus and the corresponding focus point on that block. If the focus is not on the block, then it must be set to some point of the block canvas. The second primary function of the FocusTraversalManager is to redirect the focus to the next appropriate block in a particular stack. One could "traverse" the stack by moving the focus to one of the following: 1. the block after 2. the block before 3. the next block 4. the previous block The exact definition of what "next", "previous", "after", and "before" is described in details in their corresponding method summary. As a focus manager of the entire system, the class must maintain particular invariants at all time. Clients of this module may obtain the focus through three observer (getter) methods. Clients may also manualy mutate the focus through three modifier (setter) methods. However, BOTH the value returned in the observer methods and the value passed in the modifier methods MUST maintain particular invariants described below. These invariants must hold at all time and check reps should be imposed to ensure that any changes to the system still holds these crucial invariants. Clients of this module may assume that the invariants mentioned below will always hold. INVARIANT I. If the canvas has focus, then the block does not. Thus 1. focusBlock == Block.null 2. canvasFocusPoint != null 3. blockFocusPoint == null INVARIANT II. If the block has focus, then the canvas does not. Thus 1. focusBlock != Block.null 2. canvasFocusPoint == null 3. blockFocusPoint != null


Constructor Summary
FocusTraversalManager()
           
 
Method Summary
 boolean focusAfterBlock()
          Gives focus to the first after block down the tree, that is, the next control block in the stack.
 boolean focusBeforeBlock()
          Gives focus to the first beforeblock up the tree, that is, the previous control block in the stack.
 boolean focusNextBlock()
          Reassigns the focus to the "next block" of the current focusBlock.
 boolean focusPrevBlock()
          Reassigns the focus to the "previous block" of the current focusBlock.
 java.awt.Point getBlockPoint()
           
 java.awt.Point getCanvasPoint()
           
 java.lang.Long getFocusBlockID()
           
(package private)  java.lang.Long getTopOfStack(java.lang.Long blockID)
          For a given block, returns the outermost (top-leftmost) block in the stack.
 void keyPressed(java.awt.event.KeyEvent e)
           
 void keyReleased(java.awt.event.KeyEvent e)
           
 void keyTyped(java.awt.event.KeyEvent e)
           
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
 void setFocus(Block block)
          Sets focus to block
 void setFocus(java.lang.Long blockID)
           
(package private)  void setFocus(java.awt.Point location)
           
 void setFocus(java.awt.Point canvasPoint, java.lang.Long blockID)
          Set Focus to canvas at canvasPoint.
 java.lang.String toString()
           
 void workspaceEventOccurred(WorkspaceEvent event)
          Subscription: BLOCK_ADDED events.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FocusTraversalManager

public FocusTraversalManager()
Method Detail

getFocusBlockID

public java.lang.Long getFocusBlockID()
Returns:
the block that has focus, if any. TODO: finish method documentation

getCanvasPoint

public java.awt.Point getCanvasPoint()
Returns:
point of focus on canvas TODO: finish method documentation

getBlockPoint

public java.awt.Point getBlockPoint()
Returns:
point of focus on block TODO: finish method documentation

setFocus

public void setFocus(Block block)
Sets focus to block


setFocus

public void setFocus(java.lang.Long blockID)

setFocus

public void setFocus(java.awt.Point canvasPoint,
                     java.lang.Long blockID)
Set Focus to canvas at canvasPoint. THE BLOCKID MUST BE BLOCK.NULL!!!

Parameters:
canvasPoint -
blockID - TODO: finish method documentation

setFocus

void setFocus(java.awt.Point location)

focusNextBlock

public boolean focusNextBlock()
Reassigns the focus to the "next block" of the current focusBlock. If the current focusblock is at location n of the flatten linear vector of the block tree structure, then the "next block" is located at n+1. In other words, the previous block is the parent block of the next socket of the parent block of the focusblock.


focusPrevBlock

public boolean focusPrevBlock()
Reassigns the focus to the "previous block" of the current focusBlock. If the current focusblock is at location n of the flatten linear vector of the block tree structure, then the "previous block" is located at n-1. In other words, the previous block is the innermost block of the previous socket of the parent block of the focusblock.


focusAfterBlock

public boolean focusAfterBlock()
Gives focus to the first after block down the tree, that is, the next control block in the stack. If next control block does not exist, then give focus to current focusblock. Otherwise, give focus to block canvas.


focusBeforeBlock

public boolean focusBeforeBlock()
Gives focus to the first beforeblock up the tree, that is, the previous control block in the stack. If no previous control block exists, then give focus to current focusblock. Otherwise, give focus to block canvas.


getTopOfStack

java.lang.Long getTopOfStack(java.lang.Long blockID)
For a given block, returns the outermost (top-leftmost) block in the stack.

Parameters:
blockID - any block in a stack.
Returns:
the outermost block (or Top-of-Stack) such that the outermost block != null

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Specified by:
keyReleased in interface java.awt.event.KeyListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Specified by:
keyTyped in interface java.awt.event.KeyListener

workspaceEventOccurred

public void workspaceEventOccurred(WorkspaceEvent event)
Subscription: BLOCK_ADDED events. Action: add this.mouselistener to the block referanced by event

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