workspace
Class BlockCanvas

java.lang.Object
  extended by workspace.BlockCanvas
All Implemented Interfaces:
ISupportMemento, PageChangeListener

public class BlockCanvas
extends java.lang.Object
implements PageChangeListener, ISupportMemento

A BlockCanvas is a container of Pages and is a scrollable panel. When a page is added to a BlockCanvas, that particular new page must be added to both the data structure holding the set of pages and the scrollable panel that renders the page. A BlockCanvas is also a PageChangeListener. When any pages are changed, the Blockcanvas must update itself appropriately to reflect this change. As of the current implementation, the BlockCanvas must have at least one Page when it becomes visible (that is, when it’s viewable JComponent becomes visible).


Nested Class Summary
 class BlockCanvas.Canvas
          The graphical representation of the block canvas's Swng Container of pages.
 
Constructor Summary
BlockCanvas()
          Constructs BlockCanvas and subscribes this BlockCanvas to PageChange events
 
Method Summary
 void addPage(Page page)
           
 void addPage(Page page, int position)
           
 void arrangeAllBlocks()
           
 java.lang.Iterable<RenderableBlock> getBlocks()
           
 javax.swing.JComponent getCanvas()
           
 int getHeight()
           
 javax.swing.BoundedRangeModel getHorizontalModel()
           
 javax.swing.JComponent getJComponent()
           
 java.util.List<Page> getLeftmostPages(int left)
           
protected  Page getPageAt(int position)
           
 Page getPageNamed(java.lang.String name)
           
 java.util.List<Page> getPages()
           
 java.lang.String getSaveString()
          Returns an XML String describing all the blocks and pages within the BlockCanvas
 java.lang.Object getState()
           
 java.lang.Iterable<RenderableBlock> getTopLevelBlocks()
           
 javax.swing.BoundedRangeModel getVerticalModel()
           
 int getWidth()
           
 int getX()
           
 int getY()
           
 boolean hasPageAt(int position)
           
protected  void loadSaveString(org.w3c.dom.Element root)
          Loads all the RenderableBlocks and their associated Blocks that reside within the block canvas.
 void loadState(java.lang.Object memento)
           
 int numOfPages()
           
 void reformBlockCanvas()
           
 Page removePage(int position)
           
 Page removePage(Page page)
           
 Page renamePage(java.lang.String oldName, java.lang.String newName)
           
 void reset()
           
 void scrollToComponent(javax.swing.JComponent c)
           
 void scrollToShowBlock(RenderableBlock block)
           
 void switchViewToPage(Page page)
           
 java.lang.String toString()
           
 void update()
          notifies this PageChangeListener that at least one of the pages have changed states.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BlockCanvas

public BlockCanvas()
Constructs BlockCanvas and subscribes this BlockCanvas to PageChange events

Method Detail

reset

public void reset()

getX

public int getX()

getY

public int getY()

getWidth

public int getWidth()

getHeight

public int getHeight()

getVerticalModel

public javax.swing.BoundedRangeModel getVerticalModel()

getHorizontalModel

public javax.swing.BoundedRangeModel getHorizontalModel()

getCanvas

public javax.swing.JComponent getCanvas()

getJComponent

public javax.swing.JComponent getJComponent()

toString

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

getLeftmostPages

public java.util.List<Page> getLeftmostPages(int left)

getBlocks

public java.lang.Iterable<RenderableBlock> getBlocks()
Returns:
the RendearbleBlocks that are contained within this widget or an empty Iterable if no blocks exists

arrangeAllBlocks

public void arrangeAllBlocks()

getTopLevelBlocks

public java.lang.Iterable<RenderableBlock> getTopLevelBlocks()
Returns:
a collection of top level blocks within this page (blocks with no parents that and are the first block of each stack) or an empty collection if no blocks are found on this page.

scrollToShowBlock

public void scrollToShowBlock(RenderableBlock block)
Parameters:
block - - the RenderableBlock to make sure is shown in the viewport

scrollToComponent

public void scrollToComponent(javax.swing.JComponent c)

numOfPages

public int numOfPages()

hasPageAt

public boolean hasPageAt(int position)
Parameters:
position - - 0 is the left most position
Returns:
true if there exists a page at the specified position

getPageAt

protected Page getPageAt(int position)
Parameters:
position - - 0 is the left most position
Returns:
page at position or null if non exists at position

getPageNamed

public Page getPageNamed(java.lang.String name)
Parameters:
name - - name of page
Returns:
FIRST page with matchng name (if more than one page has matching name, it returns the first) or null if no matching name exists.

getPages

public java.util.List<Page> getPages()
Returns:
List of pages or an empty list if no pages exists

addPage

public void addPage(Page page)
Parameters:
page - the page to add to the BlockCanvas

addPage

public void addPage(Page page,
                    int position)
Parameters:
page - - page to be added
position - - the index at which to add the page where 0 is rightmost
Throws:
java.lang.RuntimeException - if (position < 0 || position > pages.size() || page == null)

removePage

public Page removePage(Page page)
Parameters:
page - - the page to be removed

removePage

public Page removePage(int position)
Parameters:
position - - 0 is the left most page

switchViewToPage

public void switchViewToPage(Page page)
Parameters:
page - the desired page to switch view to

renamePage

public Page renamePage(java.lang.String oldName,
                       java.lang.String newName)
Parameters:
oldName - - the original name of the page
newName - - the String name to rename the page to
Returns:
If a matching page was found, return the renamed Page. Otherwise, return null.

update

public void update()
Description copied from interface: PageChangeListener
notifies this PageChangeListener that at least one of the pages have changed states.

Specified by:
update in interface PageChangeListener

reformBlockCanvas

public void reformBlockCanvas()

getSaveString

public java.lang.String getSaveString()
Returns an XML String describing all the blocks and pages within the BlockCanvas


loadSaveString

protected void loadSaveString(org.w3c.dom.Element root)
Loads all the RenderableBlocks and their associated Blocks that reside within the block canvas. All blocks will have their nessary data populated including connection information, stubs, etc. Note: This method should only be called if this language only uses the BlockCanvas to work with blocks and no pages. Otherwise, workspace live blocks are loaded from Pages.

Parameters:
root - the Document Element containing the desired information

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