org.jgraph.graph
Class GraphLayoutCache

java.lang.Object
  extended by java.util.Observable
      extended by org.jgraph.graph.GraphLayoutCache
All Implemented Interfaces:
Serializable, CellMapper

public class GraphLayoutCache
extends Observable
implements CellMapper, Serializable

An object that defines the view of a graphmodel. This object maps between model cells and views and provides a set of methods to change these views. The view may also contain its own set of attributes and is therefore an extension of an Observable, which may be observed by the GraphUI. It uses the model to send its changes to the command history.

Version:
1.0 1/1/02
Author:
Gaudenz Alder
See Also:
Serialized Form

Nested Class Summary
 class GraphLayoutCache.GraphViewEdit
          An implementation of GraphViewChange.
static class GraphLayoutCache.GraphViewLayerEdit
          An implementation of GraphViewChange.
 
Field Summary
protected  CellViewFactory factory
           
protected  GraphModel graphModel
           
protected  Map hiddenSet
          Remebered cell views.
 boolean hideEdgesOnBecomeInvisible
           
 boolean hideEdgesOnHide
           
protected  CellMapper mapper
           
protected  Map mapping
           
protected  boolean ordered
           
protected  boolean partial
           
protected  PortView[] ports
           
 boolean rememberCellViews
           
protected  List roots
           
 boolean showAllEdgesForVisibleVertices
           
 boolean showEdgesOnShow
           
protected  Set visibleSet
           
 
Constructor Summary
GraphLayoutCache(GraphModel model, CellViewFactory factory)
          Constructs a view for the specified model that uses factory to create its views.
GraphLayoutCache(GraphModel model, CellViewFactory factory, boolean ordered, boolean partial)
          Constructs a view for the specified model that uses factory to create its views.
GraphLayoutCache(GraphModel model, CellViewFactory factory, boolean ordered, boolean partial, boolean rememberCellViews, boolean showAllEdgesForVisibleVertices, boolean showEdgesOnShow, boolean hideEdgesOnHide, boolean hideEdgesOnBecomeInvisible)
          Constructs a view for the specified model that uses factory to create its views.
 
Method Summary
 Object[] addVisibleDependencies(Object[] cells, boolean visible)
           
protected  UndoableEdit[] augment(UndoableEdit[] e, UndoableEdit edit)
           
protected  GraphLayoutCache.GraphViewEdit createLocalEdit(Map nested, Object[] visible, Object[] invisible)
           
 void edit(Map attributes, ConnectionSet cs, ParentMap pm, UndoableEdit[] e)
          Applies the propertyMap and the connection changes to the model.
 CellView[] getAllDescendants(CellView[] views)
          Returns all views, including descendants that have a parent in views, especially the PortViews.
 Object[] getCells(CellView[] views)
          Takes an array of views and returns the array of the corresponding cells by using getCell for each view.
 CellViewFactory getFactory()
          Returns the factory that was passed to the constructor.
 Map getHiddenSet()
          Returns the hiddenSet.
 CellView[] getMapping(Object[] cells)
          Returns the views for the specified array of cells without creating these views on the fly.
 CellView[] getMapping(Object[] cells, boolean create)
          Returns the views for the specified array of cells.
 CellView getMapping(Object cell, boolean create)
          Returns the view for the specified cell.
 GraphModel getModel()
          Returns the current model.
protected  Collection getParentPorts(Object cell)
           
 PortView[] getPorts()
          Returns the ports of the view.
protected  Collection getPorts(Object cell)
           
 CellView[] getRoots()
          Returns the roots of the view.
 CellView[] getRoots(Rectangle clip)
          Return all cells that intersect the given rectangle.
 Set getVisibleSet()
           
 void graphChanged(GraphModelEvent.GraphModelChange change)
          Called from BasicGraphUI.ModelHandler to update the view based on the specified GraphModelEvent.
protected  Map handleAttributes(Map attributes)
          Attention: Undo will not work for routing-change if ROUTING and POINTS are stored in different locations.
protected  void hideCellsForChange(GraphModelEvent.GraphModelChange change)
           
 void insert(Object[] roots, Map attributes, ConnectionSet cs, ParentMap pm, UndoableEdit[] e)
          Inserts the cells and connections into the model, and absorbs the local attributes.
 void insertRoots(CellView[] views)
          Adds the specified model root cells to the view.
 boolean isHideEdgesOnBecomeInvisible()
          Returns the hideEdgesOnBecomeInvisible.
 boolean isHideEdgesOnHide()
          Returns the hideEdgesOnHide.
 boolean isOrdered()
           
 boolean isPartial()
           
 boolean isRememberCellViews()
          Returns the rememberCellViews.
 boolean isShowAllEdgesForVisibleVertices()
          Returns the showAllEdgesForVisibleVertices.
 boolean isShowEdgesOnShow()
          Returns the showEdgesOnShow.
 boolean isVisible(Object cell)
           
 Object[] order(Object[] cells)
          Returns the specified cells in view-order if the model is not ordered.
 void putMapping(Object cell, CellView view)
          Associates the specified model cell with the specified view.
 void refresh(CellView[] views, boolean create)
           
 void refresh(CellView view, boolean create)
           
 void reload()
           
 void remove(Object[] roots)
          Removes cells from the model.
 CellView removeMapping(Object cell)
          Removes the associaten for the specified model cell and returns the view that was previously associated with the cell.
 CellView[] removeRoots(Object[] cells)
          Removes the specified model root cells from the view by removing the mapping between the cell and its view and makes the cells invisible.
 void setFactory(CellViewFactory factory)
          Sets the factory that creates the cell views.
 void setHiddenSet(Map hiddenSet)
          Sets the hiddenSet.
 void setHideEdgesOnBecomeInvisible(boolean hideEdgesOnBecomeInvisible)
          Sets the hideEdgesOnBecomeInvisible.
 void setHideEdgesOnHide(boolean hideEdgesOnHide)
          Sets the hideEdgesOnHide.
 void setModel(GraphModel model)
          Sets the current model.
 void setRememberCellViews(boolean rememberCellViews)
          Sets the rememberCellViews.
 void setShowAllEdgesForVisibleVertices(boolean showAllEdgesForVisibleVertices)
          Sets the showAllEdgesForVisibleVertices.
 void setShowEdgesOnShow(boolean showEdgesOnShow)
          Sets the showEdgesOnShow.
 void setVisible(Object[] cells, boolean visible)
           
 void setVisible(Object[] visible, Object[] invisible)
           
 void setVisible(Object cell, boolean visible)
           
 boolean setVisibleImpl(Object[] cells, boolean visible)
           
 void setVisibleSet(Set visible)
           
protected  void showCellsForChange(GraphModelEvent.GraphModelChange change)
           
 void toBack(Object[] cells)
          Sends cells to back.
 void toFront(Object[] cells)
          Brings cells to front.
static void translateViews(CellView[] views, int dx, int dy)
          Translates the specified views by the given amount.
 void update(CellView view)
           
 void update(CellView[] views)
           
protected  void updatePorts()
          Updates the cached array of ports.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

showAllEdgesForVisibleVertices

public boolean showAllEdgesForVisibleVertices

showEdgesOnShow

public boolean showEdgesOnShow

hideEdgesOnHide

public boolean hideEdgesOnHide

hideEdgesOnBecomeInvisible

public boolean hideEdgesOnBecomeInvisible

rememberCellViews

public boolean rememberCellViews

graphModel

protected GraphModel graphModel

mapping

protected Map mapping

mapper

protected CellMapper mapper

factory

protected CellViewFactory factory

visibleSet

protected Set visibleSet

roots

protected List roots

ports

protected PortView[] ports

hiddenSet

protected transient Map hiddenSet
Remebered cell views.


ordered

protected boolean ordered

partial

protected boolean partial
Constructor Detail

GraphLayoutCache

public GraphLayoutCache(GraphModel model,
                        CellViewFactory factory)
Constructs a view for the specified model that uses factory to create its views.

Parameters:
model - the model that constitues the data source

GraphLayoutCache

public GraphLayoutCache(GraphModel model,
                        CellViewFactory factory,
                        boolean ordered,
                        boolean partial)
Constructs a view for the specified model that uses factory to create its views.

Parameters:
model - the model that constitues the data source

GraphLayoutCache

public GraphLayoutCache(GraphModel model,
                        CellViewFactory factory,
                        boolean ordered,
                        boolean partial,
                        boolean rememberCellViews,
                        boolean showAllEdgesForVisibleVertices,
                        boolean showEdgesOnShow,
                        boolean hideEdgesOnHide,
                        boolean hideEdgesOnBecomeInvisible)
Constructs a view for the specified model that uses factory to create its views.

Parameters:
model - the model that constitues the data source
Method Detail

setFactory

public void setFactory(CellViewFactory factory)
Sets the factory that creates the cell views.


getFactory

public CellViewFactory getFactory()
Returns the factory that was passed to the constructor.


setModel

public void setModel(GraphModel model)
Sets the current model.


reload

public void reload()

getModel

public GraphModel getModel()
Returns the current model.


getRoots

public CellView[] getRoots()
Returns the roots of the view.


getRoots

public CellView[] getRoots(Rectangle clip)
Return all cells that intersect the given rectangle.


getPorts

public PortView[] getPorts()
Returns the ports of the view.


updatePorts

protected void updatePorts()
Updates the cached array of ports.


refresh

public void refresh(CellView[] views,
                    boolean create)

refresh

public void refresh(CellView view,
                    boolean create)

update

public void update(CellView[] views)

update

public void update(CellView view)

graphChanged

public void graphChanged(GraphModelEvent.GraphModelChange change)
Called from BasicGraphUI.ModelHandler to update the view based on the specified GraphModelEvent.


hideCellsForChange

protected void hideCellsForChange(GraphModelEvent.GraphModelChange change)

showCellsForChange

protected void showCellsForChange(GraphModelEvent.GraphModelChange change)

insertRoots

public void insertRoots(CellView[] views)
Adds the specified model root cells to the view.


removeRoots

public CellView[] removeRoots(Object[] cells)
Removes the specified model root cells from the view by removing the mapping between the cell and its view and makes the cells invisible.


getCells

public Object[] getCells(CellView[] views)
Takes an array of views and returns the array of the corresponding cells by using getCell for each view.


getMapping

public CellView getMapping(Object cell,
                           boolean create)
Returns the view for the specified cell. If create is true and no view is found then a view is created using createView(Object).

Specified by:
getMapping in interface CellMapper
create - whether a new view should created

getMapping

public CellView[] getMapping(Object[] cells)
Returns the views for the specified array of cells without creating these views on the fly.


getMapping

public CellView[] getMapping(Object[] cells,
                             boolean create)
Returns the views for the specified array of cells. Returned array may contain null pointers if the respective cell is not mapped in this view and create is false.


putMapping

public void putMapping(Object cell,
                       CellView view)
Associates the specified model cell with the specified view. Updates the portlist if necessary.

Specified by:
putMapping in interface CellMapper
Parameters:
cell - the cell that constitutes the model element
view - the view that constitutes the view element

removeMapping

public CellView removeMapping(Object cell)
Removes the associaten for the specified model cell and returns the view that was previously associated with the cell. Updates the portlist if necessary.


isVisible

public boolean isVisible(Object cell)

getVisibleSet

public Set getVisibleSet()

setVisibleSet

public void setVisibleSet(Set visible)

setVisible

public void setVisible(Object cell,
                       boolean visible)

setVisible

public void setVisible(Object[] cells,
                       boolean visible)

setVisible

public void setVisible(Object[] visible,
                       Object[] invisible)

addVisibleDependencies

public Object[] addVisibleDependencies(Object[] cells,
                                       boolean visible)

setVisibleImpl

public boolean setVisibleImpl(Object[] cells,
                              boolean visible)

getParentPorts

protected Collection getParentPorts(Object cell)

getPorts

protected Collection getPorts(Object cell)

isOrdered

public boolean isOrdered()

isPartial

public boolean isPartial()

insert

public void insert(Object[] roots,
                   Map attributes,
                   ConnectionSet cs,
                   ParentMap pm,
                   UndoableEdit[] e)
Inserts the cells and connections into the model, and absorbs the local attributes. This implementation sets the inserted cells visible. (Note: No undo required for this visibility change.)


remove

public void remove(Object[] roots)
Removes cells from the model. If removeChildren is true, the children are also removed. Notifies the model- and undo listeners of the change.


edit

public void edit(Map attributes,
                 ConnectionSet cs,
                 ParentMap pm,
                 UndoableEdit[] e)
Applies the propertyMap and the connection changes to the model. The initial edits that triggered the call are considered to be part of this transaction. Notifies the model- and undo listeners of the change. Note: The passed in attributes may contain PortViews.


augment

protected UndoableEdit[] augment(UndoableEdit[] e,
                                 UndoableEdit edit)

toBack

public void toBack(Object[] cells)
Sends cells to back. Note: This expects an array of cells!


toFront

public void toFront(Object[] cells)
Brings cells to front. Note: This expects an array of cells!


createLocalEdit

protected GraphLayoutCache.GraphViewEdit createLocalEdit(Map nested,
                                                         Object[] visible,
                                                         Object[] invisible)

order

public Object[] order(Object[] cells)
Returns the specified cells in view-order if the model is not ordered.


handleAttributes

protected Map handleAttributes(Map attributes)
Attention: Undo will not work for routing-change if ROUTING and POINTS are stored in different locations. This happens if the model holds the routing attribute and the routing changes from unrouted to routed. In this case the points in the view are already routed according to the new scheme when written to the command history (-> no undo).


translateViews

public static void translateViews(CellView[] views,
                                  int dx,
                                  int dy)
Translates the specified views by the given amount.


getAllDescendants

public CellView[] getAllDescendants(CellView[] views)
Returns all views, including descendants that have a parent in views, especially the PortViews. Note: Iterative Implementation using model.getChild and getMapping on this cell mapper.


getHiddenSet

public Map getHiddenSet()
Returns the hiddenSet.

Returns:
Map

isHideEdgesOnBecomeInvisible

public boolean isHideEdgesOnBecomeInvisible()
Returns the hideEdgesOnBecomeInvisible.

Returns:
boolean

isHideEdgesOnHide

public boolean isHideEdgesOnHide()
Returns the hideEdgesOnHide.

Returns:
boolean

isRememberCellViews

public boolean isRememberCellViews()
Returns the rememberCellViews.

Returns:
boolean

isShowAllEdgesForVisibleVertices

public boolean isShowAllEdgesForVisibleVertices()
Returns the showAllEdgesForVisibleVertices.

Returns:
boolean

isShowEdgesOnShow

public boolean isShowEdgesOnShow()
Returns the showEdgesOnShow.

Returns:
boolean

setHiddenSet

public void setHiddenSet(Map hiddenSet)
Sets the hiddenSet.

Parameters:
hiddenSet - The hiddenSet to set

setHideEdgesOnBecomeInvisible

public void setHideEdgesOnBecomeInvisible(boolean hideEdgesOnBecomeInvisible)
Sets the hideEdgesOnBecomeInvisible.

Parameters:
hideEdgesOnBecomeInvisible - The hideEdgesOnBecomeInvisible to set

setHideEdgesOnHide

public void setHideEdgesOnHide(boolean hideEdgesOnHide)
Sets the hideEdgesOnHide.

Parameters:
hideEdgesOnHide - The hideEdgesOnHide to set

setRememberCellViews

public void setRememberCellViews(boolean rememberCellViews)
Sets the rememberCellViews.

Parameters:
rememberCellViews - The rememberCellViews to set

setShowAllEdgesForVisibleVertices

public void setShowAllEdgesForVisibleVertices(boolean showAllEdgesForVisibleVertices)
Sets the showAllEdgesForVisibleVertices.

Parameters:
showAllEdgesForVisibleVertices - The showAllEdgesForVisibleVertices to set

setShowEdgesOnShow

public void setShowEdgesOnShow(boolean showEdgesOnShow)
Sets the showEdgesOnShow.

Parameters:
showEdgesOnShow - The showEdgesOnShow to set