com.jgraph.graph
Class GraphView

java.lang.Object
  extended byjava.util.Observable
      extended bycom.jgraph.graph.GraphView
All Implemented Interfaces:
CellMapper, java.io.Serializable

public class GraphView
extends java.util.Observable
implements CellMapper, java.io.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 GraphView.GraphViewEdit
          An implementation of GraphViewChange.
static class GraphView.GraphViewLayerEdit
          An implementation of GraphViewChange.
 
Field Summary
protected  CellViewFactory factory
           
protected  GraphModel graphModel
           
protected  CellMapper mapper
           
protected  java.util.Map mapping
           
protected  PortView[] ports
           
protected  java.util.List roots
           
 
Constructor Summary
GraphView(GraphModel model, CellViewFactory factory)
          Constructs a view for the specified model that uses factory to create its views.
 
Method Summary
 GraphView.GraphViewEdit createEdit(java.util.Map viewAttributeMap)
           
 void edit(java.util.Map viewAttributeMap)
          Applies the specified (cellView, attribute) pairs.
 CellView[] getAllDescendants(CellView[] views)
          Returns all views, including descendants that have a parent in views, especially the PortViews.
 java.lang.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.
 CellView[] getMapping(java.lang.Object[] cells)
          Returns the views for the specified array of cells.
 CellView[] getMapping(java.lang.Object[] cells, boolean create)
          Returns the views for the specified array of cells.
 CellView getMapping(java.lang.Object cell, boolean create)
          Returns the view for the specified cell.
 GraphModel getModel()
          Returns the current model.
 PortView[] getPorts()
          Returns the ports of the view.
 CellView[] getRoots()
          Returns the roots of the view.
 CellView[] getRoots(java.awt.Rectangle clip)
          Return all cells that intersect the given rectangle.
 void graphChanged(GraphModelEvent.GraphModelChange change)
          Called from BasicGraphUI.ModelHandler to update the view based on the specified GraphModelEvent.
 void insertRoots(CellView[] views)
          Adds the specified model root cells to the view.
 java.lang.Object[] order(java.lang.Object[] cells)
          Returns the specified cells in view-order if the model is not ordered.
 void putMapping(java.lang.Object cell, CellView view)
          Associates the specified model cell with the specified view.
protected  void refreshAndUpdate(CellView view, boolean create, boolean recurse)
          Refresh and then update view.
 CellView removeMapping(java.lang.Object cell)
          Removes the associaten for the specified model cell and returns the view that was previously associated with the cell.
 CellView[] removeRoots(java.lang.Object[] cells)
          Removes the specified model root cells from the view by removing the mapping between the cell and its view.
protected  void setAttributesWithModelKeys(java.util.Map map)
          Handles an attributeMap that uses cells as keys.
 void setFactory(CellViewFactory factory)
          Sets the factory that creates the cell views.
 void setModel(GraphModel model)
          Sets the current model.
 void toBack(CellView[] views)
          Sends the specified views to back.
 void toFront(CellView[] views)
          Brings the specified views to front.
static void translateViews(CellView[] views, int dx, int dy)
          Translates the specified views by the given amount.
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

graphModel

protected GraphModel graphModel

mapping

protected java.util.Map mapping

mapper

protected CellMapper mapper

factory

protected CellViewFactory factory

roots

protected java.util.List roots

ports

protected PortView[] ports
Constructor Detail

GraphView

public GraphView(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
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.


getModel

public GraphModel getModel()
Returns the current model.


getRoots

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


getRoots

public CellView[] getRoots(java.awt.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.


refreshAndUpdate

protected void refreshAndUpdate(CellView view,
                                boolean create,
                                boolean recurse)
Refresh and then update view. create is passed to the refresh invocation. recurse is used to indicate if this method should also be applied to all child views. (Ports are no child views!)


graphChanged

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


setAttributesWithModelKeys

protected void setAttributesWithModelKeys(java.util.Map map)
Handles an attributeMap that uses cells as keys.


insertRoots

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


removeRoots

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


getMapping

public CellView getMapping(java.lang.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(java.lang.Object[] cells)
Returns the views for the specified array of cells.


getMapping

public CellView[] getMapping(java.lang.Object[] cells,
                             boolean create)
Returns the views for the specified array of cells.


putMapping

public void putMapping(java.lang.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(java.lang.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.


edit

public void edit(java.util.Map viewAttributeMap)
Applies the specified (cellView, attribute) pairs.


createEdit

public GraphView.GraphViewEdit createEdit(java.util.Map viewAttributeMap)

toBack

public void toBack(CellView[] views)
Sends the specified views to back.


toFront

public void toFront(CellView[] views)
Brings the specified views to front.


getCells

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


order

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


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.