JGraph
v5.2.1


org.jgraph.graph
Class GraphLayoutCache

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

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.

See Also:
Serialized Form

Nested Class Summary
 class GraphLayoutCache.GraphViewEdit
          An implementation of GraphViewChange.
 
Field Summary
protected  boolean askLocalAttribute
          May be used to disable the creation of local edits independently.
protected  boolean autoSizeOnValueChange
          True if the cells should be auto-sized when their values change.
protected  List changed
          An extension of the observable pattern that contains the cellviews that have changed and should be checked for auto sizing.
protected  CellViewFactory factory
          Factory to create the views.
protected  GraphModel graphModel
          Reference to the graphModel
protected  Map hiddenSet
          Remebered cell views.
protected  boolean hidesDanglingConnections
          Boolean indicating whether existing connections should be hidden if their source or target port is removed from the model.
protected  boolean hidesExistingConnections
          Boolean indicating whether existing connections should be hidden if their source or target is hidden, either by hiding the cell or by changing the source or target of the edge to a hidden cell.
protected  boolean inserted
          Specify if the last change was an insert.
protected  Set localAttributes
          A set containing all attribute keys that are stored in the cell views, in other words, the view-local attributes.
protected  Map mapping
          Maps cells to views.
protected  boolean partial
          Only portions of the model are visible.
protected  PortView[] ports
          Cached array of all ports for the view.
protected  boolean remembersCellViews
          Boolean indicating whether cellviews should be remembered once visible in this GraphLayoutCache.
protected  List roots
          Ordered list of roots for the view.
protected  boolean selectsAllInsertedCells
          Boolean indicating whether inserted cells should automatically be selected.
protected  boolean selectsLocalInsertedCells
          Boolean indicating whether cells that are inserted using the local insert method should automatically be selected.
protected  boolean showsExistingConnections
          Boolean indicating whether existing connections should me made visible if their sources or targets are made visible, given the opposite end of the edge is already visible or made visible, too.
protected  boolean showsInsertedConnections
          Boolean indicating whether inserted edges should me made visible if their sources or targets are already visible.
protected  Set visibleSet
          The set of visible cells.
 
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 partial)
          Constructs a view for the specified model that uses factory to create its views.
GraphLayoutCache(GraphModel model, CellViewFactory factory, CellView[] cellViews, boolean partial)
          Constructs a view for the specified model that uses factory to create its views.
 
Method Summary
protected  void addChanged(CellView view)
           
 void addChanged(CellView[] cellViews)
          Adds the specified cell views to the changed cell views.
 Object[] addVisibleDependencies(Object[] cells, boolean visible)
           
protected  UndoableEdit[] augment(UndoableEdit[] e, UndoableEdit edit)
           
protected  void augmentNestedMapForValueChange(Map nested, Object cell, Object newValue)
          Hook for subclassers to add more stuff for value changes.
protected  GraphLayoutCache.GraphViewEdit createLocalEdit(Object[] inserted, Map nested, Object[] visible, Object[] invisible)
          Creates a local edit for the specified change.
 void edit(Map attributes, ConnectionSet cs, ParentMap pm, UndoableEdit[] e)
          Applies the propertyMap and the connection changes to the model.
 void edit(Object[] cells, Map attributes)
          Applies the attributes to all cells by creating a map that contains the attributes for each cell and calling edit on this layout cache.
 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.
 CellView[] getCellViews()
           
 CellView[] getChanged()
           
protected  Object[] getContext(GraphModelEvent.GraphModelChange change)
          Hook for subclassers to augment the context for a graphChange.
 CellViewFactory getFactory()
          Returns the factory that was passed to the constructor.
 Map getHiddenSet()
          Returns the hiddenSet.
 boolean getInserted()
           
 Set getLocalAttributes()
           
 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(Rectangle2D clip)
          Return all cells that intersect the given rectangle.
 Object[] getVisibleCells(Object[] cells)
          Returns a an array with the visible cells in cells.
 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.
 Object[] insertClones(Object[] cells, Map clones, Map nested, ConnectionSet cs, ParentMap pm, double dx, double dy)
          Inserts the cloned cells from the clone map and clones the passed-in arguments according to the clone map before insertion and returns the clones in order of the cells.
 void insertViews(CellView[] views)
          Adds the specified model root cells to the view.
 boolean isAskLocalAttribute()
           
 boolean isAutoSizeOnValueChange()
          Returns true if cells should be auto-sized when their values change
protected  boolean isControlAttribute(Object cell, Object key, Object value)
          Returns true if key is a control attribute
protected  boolean isLocalAttribute(Object cell, Object key, Object value)
          Returns true if the set of local attributes contains key
 boolean isPartial()
           
 boolean isSelectsAllInsertedCells()
           
 boolean isSelectsLocalInsertedCells()
           
 boolean isVisible(Object cell)
           
 void notifyObservers(Object arg)
           
 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[] removeCells(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.
 CellView removeMapping(Object cell)
          Removes the associaten for the specified model cell and returns the view that was previously associated with the cell.
protected  void resetChanged()
           
 void setAskLocalAttribute(boolean askLocalAttribute)
           
 void setAutoSizeOnValueChange(boolean flag)
          Determines whether cells should be auto-sized when their values change.
 void setFactory(CellViewFactory factory)
          Sets the factory that creates the cell views.
 void setHiddenSet(Map hiddenSet)
          Sets the hiddenSet.
 void setHidesDanglingConnections(boolean hidesDanglingConnections)
          Returns the showEdgesOnShow.
 void setHidesExistingConnections(boolean hidesExistingConnections)
          Returns the showEdgesOnShow.
 void setInserted()
           
 void setLocalAttributes(Set localAttributes)
           
 void setModel(GraphModel model)
          Sets the current model.
 void setRemembersCellViews(boolean rememberCellViews)
          Sets the rememberCellViews.
 void setSelectLocalInsertedCells(boolean selectsLocalInsertedCells)
           
 void setSelectsAllInsertedCells(boolean selectsAllInsertedCells)
           
 void setShowsExistingConnections(boolean showsExistingConnections)
          Returns the showEdgesOnShow.
 void setShowsInsertedConnections(boolean showsInsertedConnections)
          Returns 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, double dx, double 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.
 void valueForCellChanged(Object cell, Object newValue)
          Messaged when the user has altered the value for the item identified by cell to newValue.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

autoSizeOnValueChange

protected boolean autoSizeOnValueChange
True if the cells should be auto-sized when their values change. Default is false.


showsExistingConnections

protected boolean showsExistingConnections
Boolean indicating whether existing connections should me made visible if their sources or targets are made visible, given the opposite end of the edge is already visible or made visible, too. Default is true.


showsInsertedConnections

protected boolean showsInsertedConnections
Boolean indicating whether inserted edges should me made visible if their sources or targets are already visible. Default is true.


hidesExistingConnections

protected boolean hidesExistingConnections
Boolean indicating whether existing connections should be hidden if their source or target is hidden, either by hiding the cell or by changing the source or target of the edge to a hidden cell. Default is true.


hidesDanglingConnections

protected boolean hidesDanglingConnections
Boolean indicating whether existing connections should be hidden if their source or target port is removed from the model. Default is false.


remembersCellViews

protected boolean remembersCellViews
Boolean indicating whether cellviews should be remembered once visible in this GraphLayoutCache. Default is true.


selectsAllInsertedCells

protected boolean selectsAllInsertedCells
Boolean indicating whether inserted cells should automatically be selected. Default is true. This is ignored if the cache is partial. Note: Despite the name of this field the implementation is located in the BasicGraphUI.GraphModelHandler.graphChanged method.


selectsLocalInsertedCells

protected boolean selectsLocalInsertedCells
Boolean indicating whether cells that are inserted using the local insert method should automatically be selected. Default is true. This is ignored if the cache is not partial and selectsAllInsertedCells is true, in which case the cells will be selected through another mechanism. Note: Despite the name of this field the implementation is located in the BasicGraphUI.GraphLayoutCacheObserver.changed method.


graphModel

protected GraphModel graphModel
Reference to the graphModel


mapping

protected transient Map mapping
Maps cells to views.


factory

protected CellViewFactory factory
Factory to create the views.


visibleSet

protected transient Set visibleSet
The set of visible cells.


roots

protected transient List roots
Ordered list of roots for the view.


ports

protected transient PortView[] ports
Cached array of all ports for the view.


changed

protected transient List changed
An extension of the observable pattern that contains the cellviews that have changed and should be checked for auto sizing. This is accumulated with addChange() and cleared with clearChanged().


hiddenSet

protected transient Map hiddenSet
Remebered cell views.


partial

protected boolean partial
Only portions of the model are visible.


inserted

protected transient boolean inserted
Specify if the last change was an insert.


askLocalAttribute

protected boolean askLocalAttribute
May be used to disable the creation of local edits independently.


localAttributes

protected Set localAttributes
A set containing all attribute keys that are stored in the cell views, in other words, the view-local attributes.

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 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,
                        CellView[] cellViews,
                        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
Method Detail

addChanged

protected void addChanged(CellView view)

addChanged

public void addChanged(CellView[] cellViews)
Adds the specified cell views to the changed cell views.


setInserted

public void setInserted()

getInserted

public boolean getInserted()

getChanged

public CellView[] getChanged()

resetChanged

protected void resetChanged()

notifyObservers

public void notifyObservers(Object arg)

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.


getCellViews

public CellView[] getCellViews()
Returns:
Returns an unordered array of all cellviews.

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(Rectangle2D clip)
Return all cells that intersect the given rectangle.


getVisibleCells

public Object[] getVisibleCells(Object[] cells)
Returns a an array with the visible cells in cells.


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.


getContext

protected Object[] getContext(GraphModelEvent.GraphModelChange change)
Hook for subclassers to augment the context for a graphChange. This means you can add additional cells that should be refreshed on a special change event. eg. parallel edges when one is removed or added.


hideCellsForChange

protected void hideCellsForChange(GraphModelEvent.GraphModelChange change)

showCellsForChange

protected void showCellsForChange(GraphModelEvent.GraphModelChange change)

insertViews

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


removeCells

public CellView[] removeCells(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
Parameters:
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.

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)

isPartial

public boolean isPartial()

valueForCellChanged

public void valueForCellChanged(Object cell,
                                Object newValue)
Messaged when the user has altered the value for the item identified by cell to newValue. If newValue signifies a truly new value the model should post a graphCellsChanged event. This calls augmentNestedMapForValueChange.


augmentNestedMapForValueChange

protected void augmentNestedMapForValueChange(Map nested,
                                              Object cell,
                                              Object newValue)
Hook for subclassers to add more stuff for value changes. Currently this adds the new value to the change.


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 and selects the new roots depending on graph.selectNewCells.


insertClones

public Object[] insertClones(Object[] cells,
                             Map clones,
                             Map nested,
                             ConnectionSet cs,
                             ParentMap pm,
                             double dx,
                             double dy)
Inserts the cloned cells from the clone map and clones the passed-in arguments according to the clone map before insertion and returns the clones in order of the cells.


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.


edit

public void edit(Object[] cells,
                 Map attributes)
Applies the attributes to all cells by creating a map that contains the attributes for each cell and calling edit on this layout cache.


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(Object[] inserted,
                                                         Map nested,
                                                         Object[] visible,
                                                         Object[] invisible)
Creates a local edit for the specified change. A local operation contains all visibility changes, as well as all changes to attributes that are local, and all control attributes.
Note: You must use cells as keys for the nested map, not cell views.


isLocalAttribute

protected boolean isLocalAttribute(Object cell,
                                   Object key,
                                   Object value)
Returns true if the set of local attributes contains key


isControlAttribute

protected boolean isControlAttribute(Object cell,
                                     Object key,
                                     Object value)
Returns true if key is a control attribute


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,
                                  double dx,
                                  double 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

setShowsExistingConnections

public void setShowsExistingConnections(boolean showsExistingConnections)
Returns the showEdgesOnShow.

Returns:
boolean

setShowsInsertedConnections

public void setShowsInsertedConnections(boolean showsInsertedConnections)
Returns the showEdgesOnShow.

Returns:
boolean

setHidesExistingConnections

public void setHidesExistingConnections(boolean hidesExistingConnections)
Returns the showEdgesOnShow.

Returns:
boolean

setHidesDanglingConnections

public void setHidesDanglingConnections(boolean hidesDanglingConnections)
Returns the showEdgesOnShow.

Returns:
boolean

setRemembersCellViews

public void setRemembersCellViews(boolean rememberCellViews)
Sets the rememberCellViews.

Parameters:
rememberCellViews - The rememberCellViews to set

setHiddenSet

public void setHiddenSet(Map hiddenSet)
Sets the hiddenSet.

Parameters:
hiddenSet - The hiddenSet to set

getLocalAttributes

public Set getLocalAttributes()
Returns:
Returns the localAttributes.

setLocalAttributes

public void setLocalAttributes(Set localAttributes)
Parameters:
localAttributes - The localAttributes to set.

isAskLocalAttribute

public boolean isAskLocalAttribute()
Returns:
Returns the askLocalAttribute.

setAskLocalAttribute

public void setAskLocalAttribute(boolean askLocalAttribute)
Parameters:
askLocalAttribute - The askLocalAttribute to set.

isAutoSizeOnValueChange

public boolean isAutoSizeOnValueChange()
Returns true if cells should be auto-sized when their values change

Returns:
true if cells should be auto-sized when their values change

setAutoSizeOnValueChange

public void setAutoSizeOnValueChange(boolean flag)
Determines whether cells should be auto-sized when their values change. Fires a property change event if the new setting is different from the existing setting.

Parameters:
flag - a boolean value, true if cells should be auto-sized when their values change

isSelectsAllInsertedCells

public boolean isSelectsAllInsertedCells()

setSelectsAllInsertedCells

public void setSelectsAllInsertedCells(boolean selectsAllInsertedCells)

isSelectsLocalInsertedCells

public boolean isSelectsLocalInsertedCells()

setSelectLocalInsertedCells

public void setSelectLocalInsertedCells(boolean selectsLocalInsertedCells)

JGraph
v5.2.1


Copyright (C) 2001-2004 Gaudenz Alder. All rights reserved.