workspace
Class Page

java.lang.Object
  extended by workspace.Page
All Implemented Interfaces:
ISupportMemento, SearchableContainer, WorkspaceWidget

public class Page
extends java.lang.Object
implements WorkspaceWidget, SearchableContainer, ISupportMemento

A Page serves as both an abstract container of blocks and also a graphical panel that renders its collection of blocks. Abstractly, a page has seven abstract fields: a color, a name, a font, a drawer, width, a height, and a set of blocks. How it renders these abstract fields depends on the state of the page, including: zoom level, and minimumPixelWidth. A Page exists as a WorkspaceWidget, a SearchableContainer, ISupportMemento, an RBParent, a Zoomable object, and a JPanel. As a WorkspaceWidget, it can add, remove, blocks and manage block manipulations within itself. As a searchableContainer, it can notify users that certain blocks have been queried. As an ISupportMomento, it can undo the current values of abstract fields. As an RBParent, it can highlight blocks. Since a Page is both a Zoomable object and JPanel, Pages separate its abstract model and view by allowing clients to mutate its abstract fields directly. But clients must remember to reform the pages in order to synchronize the data between the model and view. A page’s abstract color is rendered the same no matter what state the page is in. A page’s abstract name is rendered thrice centered at every fourth of the page. The name is rendered with a size depending on the zoom level of that page (it tries to maintain a constant aspect ratio). The drawer name is not rendered. The width and height of the page is rendered differently depending on the zoom level and minimumPixelWidth. Using the zoom level, it tries to maintain a constant aspect ratio but the absolute sizes varies with a bigger/smaller zoom level. the minimumPixelWidth limits the width from going below a certain size, no matter what the system tries to set the abstract width to be. Finally the set of blocks are rendered directly onto the page with the same transformation as the ones imposed on the width and height of the page. As an implementation detail, a page tries to maintain a separation between its abstract states and its view. Clients of Pages should use reform*() methods to validate information between the abstract states and view. Clients of Pages are warned against accessing Page.getJComponent(), as the method provides clients a way to unintentionally mutate an implementation specific detail of Pages. A Page implements ExplorerListener i.e. it listens for possible changes in an explorer that affects the display of the page. When an explorer event happens the page changes its display accordingly


Field Summary
static int DEFAULT_ABSTRACT_HEIGHT
          The default abstract height
(package private) static double zoom
          this.zoomLevel: zoom level state
 
Constructor Summary
Page(java.lang.String name)
          Constructs a new Page
Page(java.lang.String name, int pageWidth, int pageHeight, java.lang.String pageDrawer)
          Constructs a new Page
Page(java.lang.String name, int pageWidth, int pageHeight, java.lang.String pageDrawer, boolean inFullview, java.awt.Color defaultColor)
           
 
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 addLoadedBlocks(java.util.Collection<RenderableBlock> loadedBlocks, boolean importingPage)
           
 void addPixelWidth(int deltaPixelWidth)
           
 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 clearPage()
          Destructs this Page by setting its set of blocks to empty.
 boolean contains(int x, int y)
          Widgets must be able to report whether a given point is inside them
 boolean contains(java.awt.Point p)
           
 void disableMinimize()
           
 void enableMinimize()
           
 double getAbstractHeight()
           
 double getAbstractWidth()
           
static Page getBlankPage()
          Constructs a new Page
 java.util.Collection<RenderableBlock> getBlocks()
          Returns the set of blocks that abstract "lives" inside this widget.
 java.awt.Color getDefaultPageColor()
           
 java.awt.Image getIcon()
           
 javax.swing.JComponent getJComponent()
          Very Java Swing dependent method
 java.awt.Color getPageColor()
           
 java.lang.String getPageDrawer()
           
 java.lang.String getPageId()
          Returns this page's id.
 java.lang.String getPageName()
           
 RBParent getRBParent()
           
 java.lang.String getSaveString()
           
 java.lang.Iterable<RenderableBlock> getSearchableElements()
          Returns all of the searchable elements within this Searchable.
 java.lang.Object getState()
           
 java.util.Collection<RenderableBlock> getTopLevelBlocks()
           
static double getZoomLevel()
           
 boolean isInFullview()
           
 java.util.ArrayList<RenderableBlock> loadPageFrom(org.w3c.dom.Node pageNode, boolean importingPage)
           
 void loadState(java.lang.Object memento)
           
 void reformBlockOrdering()
           
 void reformBlockPosition(RenderableBlock block)
           
 int reformBounds(double pixelXCor)
           
 void reformMinimumPixelWidth()
           
 void removeBlock(RenderableBlock block)
          Used by RenderableBlocks to tell their originating Widgets that they're moving somewhere else and so should be removed.
 void reset()
          TODO: THIS METHOD NOT YET DOCUMENTED OR IMPLEMENTED Removes all the RenderableBlock content of this.
 void setHide(boolean hide)
           
 void setIcon(java.awt.Image image)
           
 void setPageColor(java.awt.Color newColor)
           
 void setPageId(java.lang.String id)
          Sets the page id.
 void setPageName(java.lang.String newName)
           
 void setPixelWidth(int pixelWidth)
           
static void setZoomLevel(double newZoom)
           
 java.lang.String toString()
          Returns string representation of this
 void updateContainsSearchResults(boolean containsSearchResults)
          Called by the search bar to update the Searchable of whether it currently belongs to the search bar's results.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_ABSTRACT_HEIGHT

public static final int DEFAULT_ABSTRACT_HEIGHT
The default abstract height

See Also:
Constant Field Values

zoom

static double zoom
this.zoomLevel: zoom level state

Constructor Detail

Page

public Page(java.lang.String name,
            int pageWidth,
            int pageHeight,
            java.lang.String pageDrawer)
Constructs a new Page

Parameters:
name - - name of this page (this.name)
pageWidth - - the abstract width of this page (this.width)
pageHeight - - the abstract height of this page (this.height)
pageDrawer - - the name of the page drawer that this page refers to

Page

public Page(java.lang.String name,
            int pageWidth,
            int pageHeight,
            java.lang.String pageDrawer,
            boolean inFullview,
            java.awt.Color defaultColor)

Page

public Page(java.lang.String name)
Constructs a new Page

Parameters:
name - - name of this page (this.name)
Method Detail

disableMinimize

public void disableMinimize()

enableMinimize

public void enableMinimize()

setHide

public void setHide(boolean hide)

getBlankPage

public static Page getBlankPage()
Constructs a new Page


reset

public void reset()
TODO: THIS METHOD NOT YET DOCUMENTED OR IMPLEMENTED Removes all the RenderableBlock content of this. Called when the Workspace is being reset. Does not fire block removed events.


clearPage

public void clearPage()
Destructs this Page by setting its set of blocks to empty. Does NOT fire block removed events.


setPageId

public void setPageId(java.lang.String id)
Sets the page id. Consider the page id "final" but settable - once set, it cannot be modified or unset.


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 the RenderableBlocks that reside within this page

getTopLevelBlocks

public java.util.Collection<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.

getPageId

public java.lang.String getPageId()
Returns this page's id. Can be null, if id is not yet set.


getPageName

public java.lang.String getPageName()
Returns:
this page's name

getPageColor

public java.awt.Color getPageColor()
Returns:
this page's color. MAY RETURN NULL.

getDefaultPageColor

public java.awt.Color getDefaultPageColor()
Returns:
this page's default color. MAY RETURN NULL.

getAbstractWidth

public double getAbstractWidth()
Returns:
this page's abstract width

getAbstractHeight

public double getAbstractHeight()
Returns:
this page's abstract height

getPageDrawer

public java.lang.String getPageDrawer()
Returns:
this page drawer that this page refers to or null if non exists. MAY RETURN NULL.

getIcon

public java.awt.Image getIcon()

isInFullview

public boolean isInFullview()

setPageName

public void setPageName(java.lang.String newName)
Parameters:
newName - - the new name of this page.

setIcon

public void setIcon(java.awt.Image image)
Parameters:
image - - the new icon of this. May be null

setPageColor

public void setPageColor(java.awt.Color newColor)
Parameters:
newColor - - the new color of this page

addPixelWidth

public void addPixelWidth(int deltaPixelWidth)
Parameters:
deltaPixelWidth -

setPixelWidth

public void setPixelWidth(int pixelWidth)

reformBounds

public int reformBounds(double pixelXCor)
Parameters:
pixelXCor - - the new X location of page's JComponent in terms of pixels
Returns:
the current width of this page in terms of pixels

reformBlockPosition

public void reformBlockPosition(RenderableBlock block)
Parameters:
block - - the new block being added whose position must be revalidated

reformMinimumPixelWidth

public void reformMinimumPixelWidth()

reformBlockOrdering

public void reformBlockOrdering()

setZoomLevel

public static void setZoomLevel(double newZoom)
Parameters:
newZoom - - the new zoom level

getZoomLevel

public static double getZoomLevel()

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

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

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

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

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

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.

getRBParent

public RBParent getRBParent()
Returns:
the RBParent representation of this Page

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

contains

public boolean contains(java.awt.Point p)

toString

public java.lang.String toString()
Returns string representation of this

Overrides:
toString in class java.lang.Object

getSearchableElements

public java.lang.Iterable<RenderableBlock> getSearchableElements()
Description copied from interface: SearchableContainer
Returns all of the searchable elements within this Searchable. For example, the MiniMap contains RenderableBlocks, which may be searched.

Specified by:
getSearchableElements in interface SearchableContainer
Returns:
the SearchableElements contained within this SearchableContainer.

updateContainsSearchResults

public void updateContainsSearchResults(boolean containsSearchResults)
Description copied from interface: SearchableContainer
Called by the search bar to update the Searchable of whether it currently belongs to the search bar's results. Guaranteed to be called on the Swing thread. It is the responsibility of this SearchableContainer to update any necessary state and repaint any necessary components as a result of a call to this method.

Specified by:
updateContainsSearchResults in interface SearchableContainer
Parameters:
containsSearchResults - true when the SearchableContainer is part of the current results.

loadPageFrom

public java.util.ArrayList<RenderableBlock> loadPageFrom(org.w3c.dom.Node pageNode,
                                                         boolean importingPage)

addLoadedBlocks

public void addLoadedBlocks(java.util.Collection<RenderableBlock> loadedBlocks,
                            boolean importingPage)

getSaveString

public java.lang.String getSaveString()

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