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.
addGraphLayoutCacheListener
public void addGraphLayoutCacheListener(GraphLayoutCacheListener l)
Adds a listener for the GraphLayoutCacheEvent posted after the graph
layout cache changes.
addVisibleDependencies
protected Object[] addVisibleDependencies(Object[] cells,
boolean visible)
augment
protected UndoableEdit[] augment(UndoableEdit[] e,
UndoableEdit edit)
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.
cellExpanded
protected void cellExpanded(Object cell)
Called when a child has been made visible by expanding its parent. This
implementation translates the child so that it reflects the offset of the
parent group since the child was last visible (see
movesChildrenOnExpand
).
cellViewsChanged
public void cellViewsChanged(CellView[] cellViews)
Invoke this method after you've changed how the cells are to be
represented in the graph.
cellWillCollapse
protected void cellWillCollapse(Object cell)
collapse
public void collapse(Object[] groups)
Collapses all groups by hiding all their descendants.
createLocalEdit
protected GraphLayoutCache.GraphLayoutCacheEdit 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.
createNestedMap
public Map createNestedMap()
Returns a nested map of (cell, map) pairs that represent all attributes
of all cell views in this view.
edit
public void edit(Map attributes)
A shortcut method that takes a nested map and passes it to the edit
method.
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 passing it
to edit on this layout cache. Example:
Map attrs = new java.util.Hashtable();
GraphConstants.setBackground(attrs, Color.RED);
graph.getGraphLayoutCache().edit(graph.getSelectionCells(), attrs);
editCell
public void editCell(Object cell,
Map attributes)
Applies the
attributes
to a single
cell
by
creating a map that contains the attributes for this cell and passing it
to edit on this layout cache. Example:
Map attrs = new java.util.Hashtable();
GraphConstants.setBackground(attrs, Color.RED);
graph.getGraphLayoutCache().editCell(graph.getSelectionCell(), attrs);
expand
public void expand(Object[] cells)
Expands all groups by showing all children. (Note: This does not show all
descandants, but only the first generation of children.)
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.
getAllViews
public CellView[] getAllViews()
Returns all views, shortcut to getAllDescendants(getRoots())
getBounds
public static Rectangle2D getBounds(CellView[] views)
Returns the bounding box for the specified cell views.
getCellViews
public CellView[] getCellViews()
- Returns an unordered array of all visible cellviews.
getCells
public Object[] getCells(boolean groups,
boolean vertices,
boolean ports,
boolean edges)
A helper method to return various arrays of cells that are visible in
this cache. For example, to get all selected vertices in a graph, do
graph.getSelectionCells(graph.getGraphLayoutCache().getCells(false, true,
false, false));
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.
getChildPort
protected Object getChildPort(Object edge,
boolean source)
Hook for subclassers to return the port to be used for edges that have
been connected to the group. This is called from expand. This returns the
first port of the first or last vertex depending on source
.
getCollapseXScale
public double getCollapseXScale()
- Returns the collapseXScale.
getCollapseYScale
public double getCollapseYScale()
- Returns the collapseYScale.
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.
getEdges
protected List getEdges(Object cell,
Set exclude,
boolean visibleCells,
boolean selfLoops,
boolean incoming)
Returns the incoming or outgoing edges for cell. Cell should be a port or
a vertex.
cell
- The cell from which the edges will be determinedexclude
- The set of edges to ignore when searchingvisibleCells
- whether or not only visible cells should be processedselfLoops
- whether or not to include self loops in the returned listincoming
- true
if incoming edges are to be obtained,
false
if outgoing edges are to be obtained
- Returns the list of incoming or outgoing edges for
cell
getFactory
public CellViewFactory getFactory()
Returns the factory that was passed to the constructor.
getGraphLayoutCacheListeners
public GraphLayoutCacheListener[] getGraphLayoutCacheListeners()
Return an array of all GraphLayoutCacheListener that were added to this
model.
getHiddenCellViews
public CellView[] getHiddenCellViews()
- Returns an unordered array of all hidden cellviews.
getHiddenMapping
public Map getHiddenMapping()
Returns the hiddenMapping.
getIncomingEdges
public List getIncomingEdges(Object cell,
Set exclude,
boolean visibleCells,
boolean selfLoops)
Returns the incoming edges for cell. Cell should be a port or a vertex.
cell
- The cell from which the incoming edges will be determinedexclude
- The set of edges to ignore when searchingvisibleCells
- whether or not only visible cells should be processedselfLoops
- whether or not to include self loops in the returned list
- Returns the list of incoming edges for
cell
getLocalAttributes
public Set getLocalAttributes()
- Returns the localAttributes.
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).
- getMapping in interface CellMapper
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
.
getModel
public GraphModel getModel()
Returns the current model.
getNeighbours
public List getNeighbours(Object cell,
Set exclude,
boolean directed,
boolean visibleCells)
Returns a collection of cells that are connected to the specified cell by
edges. Any cells specified in the exclude set will be ignored.
cell
- The cell from which the neighbours will be determinedexclude
- The set of cells to ignore when searchingdirected
- whether or not direction of edges should be taken into accountvisibleCells
- whether or not to only consider visible cells
- Returns the list of neighbours for
cell
getOutgoingEdges
public List getOutgoingEdges(Object cell,
Set exclude,
boolean visibleCells,
boolean selfLoops)
Returns the outgoing edges for cell. Cell should be a port or a vertex.
cell
- The cell from which the outgoing edges will be determinedexclude
- The set of edges to ignore when searchingvisibleCells
- whether or not only visible cells should be processedselfLoops
- whether or not to include self loops in the returned list
- Returns the list of outgoing edges for
cell
getParentPort
protected Object getParentPort(Object edge,
boolean source)
Hook for subclassers to return the first or last visible port to replace
the current source or target port of the edge. This is called when groups
are collapsed for the edges that cross the group, ie. go from a child
cell to a cell which is outside the group. This implementation returns
the first port of the parent group if source is true, otherwise it
returns the last port of the parent group.
getParentPorts
protected Collection getParentPorts(Object cell)
getPartial
public boolean getPartial()
Required for XML persistence
- whether or not the cache is partial
getPorts
public PortView[] getPorts()
Returns the ports of the view.
getPorts
protected Collection getPorts(Object cell)
getRoots
public CellView[] getRoots()
Returns the roots of the view.
getRoots
public CellView[] getRoots(Rectangle2D clip)
Return all root cells that intersect the given rectangle.
getVisibleCells
public Object[] getVisibleCells(Object[] cells)
Returns a an array with the visible cells in cells
.
getVisibleSet
public Set getVisibleSet()
graphChanged
public void graphChanged(GraphModelEvent.GraphModelChange change)
Called from BasicGraphUI.ModelHandler to update the view based on the
specified GraphModelEvent.
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).
hasVisibleParent
protected boolean hasVisibleParent(Object cell,
Set invisible)
Checks if the port or one of its parents is visible.
hideCells
public void hideCells(Object[] cells,
boolean descandants)
Hides the specified cells with all children if descandants
is true.
insert
public void insert(Object cell)
Inserts the specified vertex into the graph model. This method does in
fact nothing, it calls insert edge with the vertex and the source and
target port set to null. This example shows how to add a vertex with a
port and a black border:
DefaultGraphCell vertex = new DefaultGraphCell("Hello, world!");
Map attrs = vertex.getAttributes();
GraphConstants.setOpaque(attrs, false);
GraphConstants.setBorderColor(attrs, Color.black);
DefaultPort port = new DefaultPort();
vertex.add(port);
port.setParent(vertex);
graph.getGraphLayoutCache().insert(vertex);
cell
- inserts the specified cell in the cache
insert
public void insert(Object[] cells)
Inserts the specified cells into the graph model. This method is a
general implementation of cell insertion. If the source and target port
are null, then no connection set is created. The method uses the
attributes from the specified edge and the egdge's children to construct
the insert call. This example shows how to insert an edge with a special
arrow between two known vertices:
Object source = graph.getDefaultPortForCell(sourceVertex).getCell();
Object target = graph.getDefaultPortForCell(targetVertex).getCell();
DefaultEdge edge = new DefaultEdge("Hello, world!");
edge.setSource(source);
edge.setTarget(target);
Map attrs = edge.getAttributes();
GraphConstants.setLineEnd(attrs, GraphConstants.ARROW_TECHNICAL);
graph.getGraphLayoutCache().insert(edge);
insert
public void insert(Object[] cells,
Map nested,
ConnectionSet cs,
ParentMap pm)
Variant of the insert method that allows to pass a default connection set
and parent map and nested map.
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. This example shows how to clone the current
selection and get a reference to the clones:
Object[] cells = graph.getDescendants(graph.order(graph.getSelectionCells()));
ConnectionSet cs = ConnectionSet.create(graphModel, cells, false);
ParentMap pm = ParentMap.create(graphModel, cells, false, true);
cells = graphLayoutCache.insertClones(cells, graph.cloneCells(cells),
attributes, cs, pm, 0, 0);
insertEdge
public void insertEdge(Object edge,
Object source,
Object target)
Inserts the specified edge into the graph model. This method does in fact
nothing, it calls insert with a default connection set.
edge
- the edge to be insertedsource
- the source port this edge is connected totarget
- the target port this edge is connected to
insertGroup
public void insertGroup(Object group,
Object[] children)
Inserts the specified cell as a parent of children. Note: All cells that
are not yet in the model will be inserted. This example shows how to
group the current selection and pass the group default bounds in case it
is later collapsed:
DefaultGraphCell group = new DefaultGraphCell("Hello, world!");
Object[] cells = DefaultGraphModel.order(graph.getModel(), graph
.getSelectionCells());
Rectangle2D bounds = graph.getCellBounds(cells);
if (bounds != null) {
bounds = new Rectangle2D.Double(bounds.getX() + bounds.getWidth() / 4,
bounds.getY() + bounds.getHeight() / 4, bounds.getWidth() / 2,
bounds.getHeight() / 2);
GraphConstants.setBounds(group.getAttributes(), bounds);
}
graph.getGraphLayoutCache().insertGroup(group, cells);
insertViews
public void insertViews(CellView[] views)
Adds the specified model root cells to the view. Do not add a view that
is already in roots.
isAllAttributesLocal
public boolean isAllAttributesLocal()
- Returns the askLocalAttribute.
isAutoSizeOnValueChange
public boolean isAutoSizeOnValueChange()
Returns true if cells should be auto-sized when their values change
- true if cells should be auto-sized when their values change
isControlAttribute
protected boolean isControlAttribute(Object cell,
Object key,
Object value)
Returns true if key
is a control attribute
isHidesDanglingConnections
public boolean isHidesDanglingConnections()
Returns the hidesDanglingConnections.
isHidesExistingConnections
public boolean isHidesExistingConnections()
Returns the hidesExistingConnections.
isLocalAttribute
protected boolean isLocalAttribute(Object cell,
Object key,
Object value)
Returns true if the set of local attributes contains key
isMovesChildrenOnExpand
public boolean isMovesChildrenOnExpand()
- Returns the moveChildrenOnExpand.
isMovesParentsOnCollapse
public boolean isMovesParentsOnCollapse()
- Returns the movesParentsOnCollapse.
isPartial
public boolean isPartial()
isReconnectsEdgesToVisibleParent
public boolean isReconnectsEdgesToVisibleParent()
edges are moved to parent view and back automatically
- Returns the reconnectsEdgesToVisibleParent.
isRemembersCellViews
public boolean isRemembersCellViews()
Returns the remembersCellViews.
isResizesParentsOnCollapse
public boolean isResizesParentsOnCollapse()
- Returns the resizesParentsOnCollapse.
isSelectsAllInsertedCells
public boolean isSelectsAllInsertedCells()
- Returns the selectsAllInsertedCells.
isSelectsLocalInsertedCells
public boolean isSelectsLocalInsertedCells()
- Returns the selectsLocalInsertedCells.
isShowsChangedConnections
public boolean isShowsChangedConnections()
- Returns the showsChangedConnections.
isShowsExistingConnections
public boolean isShowsExistingConnections()
Returns the showsExistingConnections.
isShowsInsertedConnections
public boolean isShowsInsertedConnections()
Returns the showsInsertedConnections.
isShowsInvisibleEditedCells
public boolean isShowsInvisibleEditedCells()
isVisible
public boolean isVisible(Object cell)
putMapping
public void putMapping(Object cell,
CellView view)
Associates the specified model cell with the specified view.
- putMapping in interface CellMapper
refresh
public void refresh(CellView view,
boolean create)
refresh
public void refresh(CellView[] views,
boolean create)
reload
public void reload()
Remaps all existing views using the CellViewFactory
and replaces the respective root views.
reloadRoots
protected void reloadRoots()
Completely reloads all roots from the model in the order returned by
DefaultGraphModel.getAll. This uses the current visibleSet and mapping to
fetch the cell views for the cells.
remove
public void remove(Object[] cells)
Removes cells
from the model.
remove
public void remove(Object[] cells,
boolean descendants,
boolean edges)
Removes cells from the model, including all children and connected edges
if children
or edges
is true, respectively.
cells
- The cells to remove.descendants
- Whether to remove all descendants as well.edges
- Whether to remove all connected edges as well.
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.
removeGraphLayoutCacheListener
public void removeGraphLayoutCacheListener(GraphLayoutCacheListener l)
Removes a listener previously added with addGraphLayoutCacheListener()
.
l
- the listener to remove
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.
removeViewLocalAttribute
public boolean removeViewLocalAttribute(Object key,
boolean addToModel,
boolean override)
Handles the removal of view local attributes. Since these attributes are
only being stored in the view, the option is provided to copy the values
for that key into the model. Without this, those values are lost.
key
- the key of the view local attributeaddToModel
- whether or not to move the attribute values to the graph modeloverride
- whether or not to override the key's value in the model cell's
attribute map if it exists
- whether or not the operation completed sucessfully
setAllAttributesLocal
public void setAllAttributesLocal(boolean allAttributesLocal)
allAttributesLocal
- The allAttributesLocal to set.
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.
flag
- a boolean value, true if cells should be auto-sized when their
values change
setCollapseXScale
public void setCollapseXScale(double collapseXScale)
collapseXScale
- The collapseXScale to set.
setCollapseYScale
public void setCollapseYScale(double collapseYScale)
collapseYScale
- The collapseYScale to set.
setCollapsedState
public void setCollapsedState(Object[] collapse,
Object[] expand)
Collapses and/or expands the specified cell(s)
collapse
- the cells to be collapsedexpand
- the cells to be expanded
setFactory
public void setFactory(CellViewFactory factory)
Sets the factory that creates the cell views.
setHiddenSet
public void setHiddenSet(Map hiddenSet)
Sets the hiddenSet.
hiddenSet
- The hiddenSet to set
setHidesDanglingConnections
public void setHidesDanglingConnections(boolean hidesDanglingConnections)
Sets the hidesDanglingConnections
hidesDanglingConnections
-
setHidesExistingConnections
public void setHidesExistingConnections(boolean hidesExistingConnections)
Sets the hidesExistingConnections
hidesExistingConnections
-
setLocalAttributes
public void setLocalAttributes(Set localAttributes)
localAttributes
- The localAttributes to set.
setModel
public void setModel(GraphModel model)
Sets the current model.
setMovesChildrenOnExpand
public void setMovesChildrenOnExpand(boolean moveChildrenOnExpand)
moveChildrenOnExpand
- The moveChildrenOnExpand to set.
setMovesParentsOnCollapse
public void setMovesParentsOnCollapse(boolean movesParentsOnCollapse)
movesParentsOnCollapse
- The movesParentsOnCollapse to set.
setReconnectsEdgesToVisibleParent
public void setReconnectsEdgesToVisibleParent(boolean reconnectsEdgesToVisibleParent)
edges are moved to parent view and back automatically
reconnectsEdgesToVisibleParent
- The reconnectsEdgesToVisibleParent to set.
setRemembersCellViews
public void setRemembersCellViews(boolean rememberCellViews)
Sets the rememberCellViews.
rememberCellViews
- The rememberCellViews to set
setResizesParentsOnCollapse
public void setResizesParentsOnCollapse(boolean resizesParentsOnCollapse)
resizesParentsOnCollapse
- The resizesParentsOnCollapse to set.
setSelectsAllInsertedCells
public void setSelectsAllInsertedCells(boolean selectsAllInsertedCells)
selectsAllInsertedCells
- The selectsAllInsertedCells to set.
setSelectsLocalInsertedCells
public void setSelectsLocalInsertedCells(boolean selectsLocalInsertedCells)
selectsLocalInsertedCells
- The selectsLocalInsertedCells to set.
setShowsChangedConnections
public void setShowsChangedConnections(boolean showsChangedConnections)
showsChangedConnections
- The showsChangedConnections to set.
setShowsExistingConnections
public void setShowsExistingConnections(boolean showsExistingConnections)
Sets the showsExistingConnections
showsExistingConnections
-
setShowsInsertedConnections
public void setShowsInsertedConnections(boolean showsInsertedConnections)
Sets the showsInsertedConnections
showsInsertedConnections
-
setShowsInvisibleEditedCells
public void setShowsInvisibleEditedCells(boolean showsInvisibleEditedCells)
setVisible
public void setVisible(Object cell,
boolean visible)
Makes the specified cell visible or invisible depending on the flag
passed in. Note the cell really is a cell, not a cell view.
cell
- the cell whose visibility is to be changedvisible
- true
if cell is to be made visible
setVisible
public void setVisible(Object[] visible,
Object[] invisible)
Changes the visibility state of the cells passed in. Note that the arrays
must contain cells, not cell views.
visible
- cells to be made visibleinvisible
- cells to be made invisible
setVisible
public void setVisible(Object[] visible,
Object[] invisible,
Map attributes,
ConnectionSet cs)
Changes the visibility state of the cells passed in. Note that the arrays
must contain cells, not cell views.
visible
- cells to be made visibleinvisible
- cells to be made invisibleattributes
- a nested attribute map of cells/attribute mapscs
- a ConnectionSet
describing the new state of
edge connections in the graph
setVisible
public void setVisible(Object[] visible,
Object[] invisible,
ConnectionSet cs)
Changes the visibility state of the cells passed in. Note that the arrays
must contain cells, not cell views.
visible
- cells to be made visibleinvisible
- cells to be made invisiblecs
- a ConnectionSet
describing the new state of
edge connections in the graph
setVisible
public void setVisible(Object[] cells,
boolean visible)
Makes the specified cells visible or invisible depending on the flag
passed in. Note the cells really are cells, not cell views.
cells
- the cells whose visibility is to be changedvisible
- true
if the cells are to be made visible
setVisibleImpl
public boolean setVisibleImpl(Object[] cells,
boolean visible)
The actual implementation of changing cells' visibility state. This
method does not deal with creating the undo or updating the
GraphLayoutCache correctly. The setVisible
methods in this
class are intended to be the main public way to change visiblilty.
However, if you do not require the undo to be formed, this method is much
quicker, just note that you must call updatePorts
if this
method returns true.
- whether or not the ports needed updating in the calling method
setVisibleSet
public void setVisibleSet(Set visible)
showCells
public void showCells(Object[] cells,
boolean descandants)
Shows the specified cells with all children if descandants
is true.
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!
toggleCollapsedState
public void toggleCollapsedState(Object[] cells,
boolean collapseOnly,
boolean expandOnly)
Toggles the collapsed state of the specified cells.
cells
- The cells to toggle the collapsed state for.collapseOnly
- Whether cells should only be collapsed.expandOnly
- Whether cells should only be expanded.
translateViews
public static void translateViews(CellView[] views,
double dx,
double dy)
Translates the specified views by the given amount.
views
- an array of cell view to each be translateddx
- the amount to translate the views in the x-axisdy
- the amount to translate the views in the x-axis
ungroup
public Object[] ungroup(Object[] cells)
Ungroups all groups in cells and returns the children that are not ports.
Note: This replaces the parents with their group cells in the group
structure.
update
public void update(CellView[] views)
updatePorts
protected void updatePorts()
Updates the cached array of ports.
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.