Package org.jgraph.graph
Class GraphLayoutCache
java.lang.Object
org.jgraph.graph.GraphLayoutCache
- All Implemented Interfaces:
Serializable
,CellMapper
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
An implementation of GraphLayoutCacheChange. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
Controls if all attributes are local.protected boolean
True if the cells should be auto-sized when their values change.protected double
Specified the initial x- and y-scaling factor for initial collapsed group bounds.protected double
Specified the initial x- and y-scaling factor for initial collapsed group bounds.protected CellViewFactory
Factory to create the views.protected GraphModel
Reference to the graphModelprotected Map
Maps cells to views.protected boolean
Boolean indicating whether existing connections should be hidden if their source or target port is removed from the model.protected boolean
Boolean indicating whether existing connections should be hidden if their source or target and no parent of the ports is visible, either by hiding the cell or by changing the source or target of the edge to a hidden cell.protected EventListenerList
The list of listeners that listen to the GraphLayoutCache.protected Set
A set containing all attribute keys that are stored in the cell views, in other words, the view-local attributes.protected Map
Maps cells to views.protected boolean
Boolean indicating whether children should be moved to the parent group's origin on expand.protected boolean
Boolean indicating whether parents should be moved to the child area origin on collapse.protected boolean
Only portions of the model are visible.protected PortView[]
Cached array of all ports for the view.protected boolean
Deprecated.edges are moved to parent view and back automaticallyprotected boolean
Boolean indicating whether cellviews should be remembered once visible in this GraphLayoutCache.protected boolean
Boolean indicating whether parents should always be resized to the child area on collapse.protected List
Ordered list of roots for the view.protected boolean
Boolean indicating whether inserted cells should automatically be selected.protected boolean
Boolean indicating whether cells that are inserted using the local insert method should automatically be selected.protected boolean
Boolean indicating whether connections should be made visible when reconnected and their source and target port is visible.protected boolean
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
Boolean indicating whether inserted should be made visible if they are inserted viainsert(Object[], Map, ConnectionSet, ParentMap, UndoableEdit[])
.protected boolean
Boolean indicating whether inserted edges should me made visible if their sources or targets are already visible.protected boolean
Boolean indicating whether edited cells should be made visible if they are changed viaedit(Map, ConnectionSet, ParentMap, UndoableEdit[])
.protected Set
The set of visible cells. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a graph layout cache.GraphLayoutCache
(GraphModel model, CellViewFactory factory) Constructs a view for the specified model that usesfactory
to create its views.GraphLayoutCache
(GraphModel model, CellViewFactory factory, boolean partial) Constructs a view for the specified model that usesfactory
to create its views.GraphLayoutCache
(GraphModel model, CellViewFactory factory, CellView[] cellViews, CellView[] hiddenCellViews, boolean partial) Constructs a view for the specified model that usesfactory
to create its views. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a listener for the GraphLayoutCacheEvent posted after the graph layout cache changes.protected 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 void
cellExpanded
(Object cell) Called when a child has been made visible by expanding its parent.void
cellViewsChanged
(CellView[] cellViews) Invoke this method after you've changed how the cells are to be represented in the graph.protected void
cellWillCollapse
(Object cell) void
Collapses all groups by hiding all their descendants.protected GraphLayoutCache.GraphLayoutCacheEdit
createLocalEdit
(Object[] inserted, Map nested, Object[] visible, Object[] invisible) Creates a local edit for the specified change.Returns a nested map of (cell, map) pairs that represent all attributes of all cell views in this view.void
Applies theattributes
to allcells
by creating a map that contains the attributes for each cell and passing it to edit on this layout cache.void
A shortcut method that takes a nested map and passes it to the edit method.void
edit
(Map attributes, ConnectionSet cs, ParentMap pm, UndoableEdit[] e) Applies thepropertyMap
and the connection changes to the model.void
Applies theattributes
to a singlecell
by creating a map that contains the attributes for this cell and passing it to edit on this layout cache.void
Expands all groups by showing all children.protected void
CellView[]
getAllDescendants
(CellView[] views) Returns all views, including descendants that have a parent inviews
, especially the PortViews.CellView[]
Returns all views, shortcut to getAllDescendants(getRoots())static Rectangle2D
Returns the bounding box for the specified cell views.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.Object[]
Takes an array of views and returns the array of the corresponding cells by usinggetCell
for each view.CellView[]
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.double
double
protected Object[]
Hook for subclassers to augment the context for a graphChange.protected List
Returns the incoming or outgoing edges for cell.Returns the factory that was passed to the constructor.Return an array of all GraphLayoutCacheListener that were added to this model.CellView[]
Returns the hiddenMapping.getIncomingEdges
(Object cell, Set exclude, boolean visibleCells, boolean selfLoops) Returns the incoming edges for cell.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.getMapping
(Object cell, boolean create) Returns the view for the specified cell.getModel()
Returns the current model.getNeighbours
(Object cell, Set exclude, boolean directed, boolean visibleCells) Returns a collection of cells that are connected to the specified cell by edges.getOutgoingEdges
(Object cell, Set exclude, boolean visibleCells, boolean selfLoops) Returns the outgoing edges for cell.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.protected Collection
getParentPorts
(Object cell) boolean
Required for XML persistencePortView[]
getPorts()
Returns the ports of the view.protected Collection
CellView[]
getRoots()
Returns the roots of the view.CellView[]
getRoots
(Rectangle2D clip) Return all root cells that intersect the given rectangle.Object[]
getVisibleCells
(Object[] cells) Returns a an array with the visible cells incells
.Returns the set of visible sets in this view.void
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 boolean
hasVisibleParent
(Object cell, Set invisible) Checks if the port or one of its parents is visible.void
Hides the specified cells with all children ifdescandants
is true.protected void
void
Inserts the specified vertex into the graph model.void
Inserts the specified cells into the graph model.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.void
insert
(Object[] roots, Map attributes, ConnectionSet cs, ParentMap pm, UndoableEdit[] e) Inserts thecells
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
insertEdge
(Object edge, Object source, Object target) Inserts the specified edge into the graph model.void
insertGroup
(Object group, Object[] children) Inserts the specified cell as a parent of children.void
insertViews
(CellView[] views) Adds the specified model root cells to the view.boolean
boolean
Returns true if cells should be auto-sized when their values changeprotected boolean
isControlAttribute
(Object cell, Object key, Object value) Returns true ifkey
is a control attributeboolean
Returns the hidesDanglingConnections.boolean
Returns the hidesExistingConnections.protected boolean
isLocalAttribute
(Object cell, Object key, Object value) Returns true if the set of local attributes containskey
boolean
boolean
boolean
boolean
Deprecated.edges are moved to parent view and back automaticallyboolean
Returns the remembersCellViews.boolean
boolean
boolean
boolean
boolean
Returns the showsExistingConnections.boolean
Returns the showsInsertedConnections.boolean
boolean
Whether or not the specified cell is visible.void
putMapping
(Object cell, CellView view) Associates the specified model cell with the specified view.void
void
void
reload()
Remaps all existing views using the CellViewFactory and replaces the respective root views.protected void
Completely reloads all roots from the model in the order returned by DefaultGraphModel.getAll.void
Removescells
from the model.void
Removes cells from the model, including all children and connected edges ifchildren
oredges
is true, respectively.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.void
Removes a listener previously added with addGraphLayoutCacheListener() .removeMapping
(Object cell) Removes the association for the specified model cell and returns the view that was previously associated with the cell.boolean
removeViewLocalAttribute
(Object key, boolean addToModel, boolean override) Handles the removal of view local attributes.void
setAllAttributesLocal
(boolean allAttributesLocal) void
setAutoSizeOnValueChange
(boolean flag) Determines whether cells should be auto-sized when their values change.void
setCollapsedState
(Object[] collapse, Object[] expand) Collapses and/or expands the specified cell(s) NOTE: Your GraphLayoutCache must bepartial
(setpartial
totrue
in the constructor) in order to use the visibility functionality of expand/collapse, setVisible, etc.void
setCollapseXScale
(double collapseXScale) void
setCollapseYScale
(double collapseYScale) void
setFactory
(CellViewFactory factory) Sets the factory that creates the cell views.void
setHiddenSet
(Map hiddenSet) Sets the hiddenSet.void
setHidesDanglingConnections
(boolean hidesDanglingConnections) Sets the hidesDanglingConnectionsvoid
setHidesExistingConnections
(boolean hidesExistingConnections) Sets the hidesExistingConnectionsvoid
setLocalAttributes
(Set localAttributes) void
setModel
(GraphModel model) Sets the current model.void
setMovesChildrenOnExpand
(boolean moveChildrenOnExpand) void
setMovesParentsOnCollapse
(boolean movesParentsOnCollapse) void
setReconnectsEdgesToVisibleParent
(boolean reconnectsEdgesToVisibleParent) Deprecated.edges are moved to parent view and back automaticallyvoid
setRemembersCellViews
(boolean rememberCellViews) Sets the rememberCellViews.void
setResizesParentsOnCollapse
(boolean resizesParentsOnCollapse) void
setSelectsAllInsertedCells
(boolean selectsAllInsertedCells) void
setSelectsLocalInsertedCells
(boolean selectsLocalInsertedCells) void
setShowsChangedConnections
(boolean showsChangedConnections) void
setShowsExistingConnections
(boolean showsExistingConnections) Sets the showsExistingConnectionsvoid
setShowsInsertedConnections
(boolean showsInsertedConnections) Sets the showsInsertedConnectionsvoid
setShowsInvisibleEditedCells
(boolean showsInvisibleEditedCells) void
setVisible
(Object[] cells, boolean visible) Makes the specified cells visible or invisible depending on the flag passed in.void
setVisible
(Object[] visible, Object[] invisible) Changes the visibility state of the cells passed in.void
setVisible
(Object[] visible, Object[] invisible, Map attributes, ConnectionSet cs) Changes the visibility state of the cells passed in.void
setVisible
(Object[] visible, Object[] invisible, ConnectionSet cs) Changes the visibility state of the cells passed in.void
setVisible
(Object cell, boolean visible) Makes the specified cell visible or invisible depending on the flag passed in.boolean
setVisibleImpl
(Object[] cells, boolean visible) The actual implementation of changing cells' visibility state.void
setVisibleSet
(Set visible) Applies the specified set of cells as being those visiblevoid
Shows the specified cells with all children ifdescandants
is true.protected void
void
Sendscells
to back.void
Bringscells
to front.void
toggleCollapsedState
(Object[] cells, boolean collapseOnly, boolean expandOnly) Toggles the collapsed state of the specified cells.static void
translateViews
(CellView[] views, double dx, double dy) Translates the specified views by the given amount.Object[]
Ungroups all groups in cells and returns the children that are not ports.void
update()
Sets the current model.void
void
protected void
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.
-
Field Details
-
autoSizeOnValueChange
protected boolean autoSizeOnValueChangeTrue if the cells should be auto-sized when their values change. Default is false. -
showsExistingConnections
protected boolean showsExistingConnectionsBoolean 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. -
showsChangedConnections
protected boolean showsChangedConnectionsBoolean indicating whether connections should be made visible when reconnected and their source and target port is visible. Default is true. -
showsInvisibleEditedCells
protected boolean showsInvisibleEditedCellsBoolean indicating whether edited cells should be made visible if they are changed viaedit(Map, ConnectionSet, ParentMap, UndoableEdit[])
. Default is false. -
showsInsertedCells
protected boolean showsInsertedCellsBoolean indicating whether inserted should be made visible if they are inserted viainsert(Object[], Map, ConnectionSet, ParentMap, UndoableEdit[])
. Default is true. -
showsInsertedConnections
protected boolean showsInsertedConnectionsBoolean indicating whether inserted edges should me made visible if their sources or targets are already visible. Default is true. -
hidesExistingConnections
protected boolean hidesExistingConnectionsBoolean indicating whether existing connections should be hidden if their source or target and no parent of the ports is visible, 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 hidesDanglingConnectionsBoolean indicating whether existing connections should be hidden if their source or target port is removed from the model. Default is false. -
remembersCellViews
protected boolean remembersCellViewsBoolean indicating whether cellviews should be remembered once visible in this GraphLayoutCache. Default is true. -
selectsAllInsertedCells
protected boolean selectsAllInsertedCellsBoolean 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 selectsLocalInsertedCellsBoolean 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. -
movesChildrenOnExpand
protected boolean movesChildrenOnExpandBoolean indicating whether children should be moved to the parent group's origin on expand. Default is true. -
movesParentsOnCollapse
protected boolean movesParentsOnCollapseBoolean indicating whether parents should be moved to the child area origin on collapse. Default is true. -
resizesParentsOnCollapse
protected boolean resizesParentsOnCollapseBoolean indicating whether parents should always be resized to the child area on collapse. If false the size is only initially updated if it has not yet been assigned. Default is false. -
collapseXScale
protected double collapseXScaleSpecified the initial x- and y-scaling factor for initial collapsed group bounds. Default is 1.0, ie. no scaling. -
collapseYScale
protected double collapseYScaleSpecified the initial x- and y-scaling factor for initial collapsed group bounds. Default is 1.0, ie. no scaling. -
reconnectsEdgesToVisibleParent
protected boolean reconnectsEdgesToVisibleParentDeprecated.edges are moved to parent view and back automaticallyBoolean indicating whether edges should be reconneted to visible parents on collapse/expand. Default is false. -
listenerList
The list of listeners that listen to the GraphLayoutCache. -
graphModel
Reference to the graphModel -
mapping
Maps cells to views. -
factory
Factory to create the views. -
visibleSet
The set of visible cells. -
roots
Ordered list of roots for the view. -
ports
Cached array of all ports for the view. -
partial
protected boolean partialOnly portions of the model are visible. -
allAttributesLocal
protected boolean allAttributesLocalControls if all attributes are local. If this is false then the createLocalEdit will check the localAttributes set to see if a specific attribute is local, otherwise it will assume that all attributes are local. This allows to make all attributes local without actually knowing them. Default is false. -
localAttributes
A set containing all attribute keys that are stored in the cell views, in other words, the view-local attributes.
-
-
Constructor Details
-
GraphLayoutCache
public GraphLayoutCache()Constructs a graph layout cache. -
GraphLayoutCache
Constructs a view for the specified model that usesfactory
to create its views.- Parameters:
model
- the model that constitues the data source
-
GraphLayoutCache
Constructs a view for the specified model that usesfactory
to create its views.- Parameters:
model
- the model that constitues the data source
-
GraphLayoutCache
public GraphLayoutCache(GraphModel model, CellViewFactory factory, CellView[] cellViews, CellView[] hiddenCellViews, boolean partial) Constructs a view for the specified model that usesfactory
to create its views.- Parameters:
model
- the model that constitues the data source
-
-
Method Details
-
addGraphLayoutCacheListener
Adds a listener for the GraphLayoutCacheEvent posted after the graph layout cache changes.- Parameters:
l
- the listener to add- See Also:
-
removeGraphLayoutCacheListener
Removes a listener previously added with addGraphLayoutCacheListener() .- Parameters:
l
- the listener to remove- See Also:
-
cellViewsChanged
Invoke this method after you've changed how the cells are to be represented in the graph. -
fireGraphLayoutCacheChanged
protected void fireGraphLayoutCacheChanged(Object source, GraphLayoutCacheEvent.GraphLayoutCacheChange edit) -
getGraphLayoutCacheListeners
Return an array of all GraphLayoutCacheListener that were added to this model. -
setFactory
Sets the factory that creates the cell views. -
getFactory
Returns the factory that was passed to the constructor. -
setModel
Sets the current model. -
update
public void update()Sets the current model. -
getCellViews
- Returns:
- Returns an unordered array of all visible cellviews.
-
getBounds
Returns the bounding box for the specified cell views. -
getCells
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, dograph.getSelectionCells(graph.getGraphLayoutCache().getCells(false, true, false, false));
-
createNestedMap
Returns a nested map of (cell, map) pairs that represent all attributes of all cell views in this view.- See Also:
-
getHiddenCellViews
- Returns:
- Returns an unordered array of all hidden cellviews.
-
reload
public void reload()Remaps all existing views using the CellViewFactory and replaces the respective root views. -
getModel
Returns the current model. -
getRoots
Returns the roots of the view. -
getRoots
Return all root cells that intersect the given rectangle. -
getVisibleCells
Returns a an array with the visible cells incells
. -
getPorts
Returns the ports of the view. -
updatePorts
protected void updatePorts()Updates the cached array of ports. -
refresh
-
refresh
-
update
-
update
-
graphChanged
Called from BasicGraphUI.ModelHandler to update the view based on the specified GraphModelEvent. -
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. -
getContext
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
-
hasVisibleParent
Checks if the port or one of its parents is visible. -
showCellsForChange
-
insertViews
Adds the specified model root cells to the view. Do not add a view that is already in roots. -
removeCells
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
Takes an array of views and returns the array of the corresponding cells by usinggetCell
for each view. -
getMapping
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 interfaceCellMapper
create
- whether a new view should created if a view does not already exist
-
getMapping
Returns the views for the specified array of cells without creating these views on the fly. -
getMapping
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 andcreate
isfalse
. -
putMapping
Associates the specified model cell with the specified view.- Specified by:
putMapping
in interfaceCellMapper
- Parameters:
cell
- the cell that constitutes the model elementview
- the view that constitutes the view element
-
removeMapping
Removes the association for the specified model cell and returns the view that was previously associated with the cell. Updates the portlist if necessary. -
isVisible
Whether or not the specified cell is visible. NOTE: Your GraphLayoutCache must bepartial
(setpartial
totrue
in the constructor) in order to use the visibility functionality of expand/collapse, setVisible, etc. null is always visible- Parameters:
cell
- the whose visibility to determine- Returns:
- whether or not the cell is visible
-
getVisibleSet
Returns the set of visible sets in this view.- Returns:
- the set of visible sets in this view.
-
setVisibleSet
Applies the specified set of cells as being those visible- Parameters:
visible
- the set of visible cells
-
setVisible
Makes the specified cell visible or invisible depending on the flag passed in. Note the cell really is a cell, not a cell view. NOTE: Your GraphLayoutCache must bepartial
(setpartial
totrue
in the constructor) in order to use the visibility functionality of expand/collapse, setVisible, etc.- Parameters:
cell
- the cell whose visibility is to be changedvisible
-true
if cell is to be made visible
-
setVisible
Makes the specified cells visible or invisible depending on the flag passed in. Note the cells really are cells, not cell views. NOTE: Your GraphLayoutCache must bepartial
(setpartial
totrue
in the constructor) in order to use the visibility functionality of expand/collapse, setVisible, etc.- Parameters:
cells
- the cells whose visibility is to be changedvisible
-true
if the cells are to be made visible
-
setVisible
Changes the visibility state of the cells passed in. Note that the arrays must contain cells, not cell views. NOTE: Your GraphLayoutCache must bepartial
(setpartial
totrue
in the constructor) in order to use the visibility functionality of expand/collapse, setVisible, etc.- Parameters:
visible
- cells to be made visibleinvisible
- cells to be made invisible
-
setVisible
Changes the visibility state of the cells passed in. Note that the arrays must contain cells, not cell views. NOTE: Your GraphLayoutCache must bepartial
(setpartial
totrue
in the constructor) in order to use the visibility functionality of expand/collapse, setVisible, etc.- Parameters:
visible
- cells to be made visibleinvisible
- cells to be made invisiblecs
- aConnectionSet
describing the new state of edge connections in the graph
-
setVisible
Changes the visibility state of the cells passed in. Note that the arrays must contain cells, not cell views. NOTE: Your GraphLayoutCache must bepartial
(setpartial
totrue
in the constructor) in order to use the visibility functionality of expand/collapse, setVisible, etc.- Parameters:
visible
- cells to be made visibleinvisible
- cells to be made invisibleattributes
- a nested attribute map of cells/attribute mapscs
- aConnectionSet
describing the new state of edge connections in the graph
-
addVisibleDependencies
-
setVisibleImpl
The actual implementation of changing cells' visibility state. This method does not deal with creating the undo or updating the GraphLayoutCache correctly. ThesetVisible
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 callupdatePorts
if this method returns true. NOTE: Your GraphLayoutCache must bepartial
(setpartial
totrue
in the constructor) in order to use the visibility functionality of expand/collapse, setVisible, etc.- Parameters:
cells
-visible
-- Returns:
- whether or not the ports needed updating in the calling method
-
getParentPorts
-
getPorts
-
isPartial
public boolean isPartial() -
getPartial
public boolean getPartial()Required for XML persistence- Returns:
- whether or not the cache is partial
-
valueForCellChanged
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
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 thecells
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);
-
insert
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);
- Parameters:
cell
- inserts the specified cell in the cache
-
insertEdge
Inserts the specified edge into the graph model. This method does in fact nothing, it calls insert with a default connection set.- Parameters:
edge
- the edge to be insertedsource
- the source port this edge is connected totarget
- the target port this edge is connected to
-
insert
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
Variant of the insert method that allows to pass a default connection set and parent map and nested map. -
insertGroup
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);
-
remove
Removescells
from the model. -
remove
Removes cells from the model, including all children and connected edges ifchildren
oredges
is true, respectively.- Parameters:
cells
- The cells to remove.descendants
- Whether to remove all descendants as well.edges
- Whether to remove all connected edges as well.
-
hideCells
Hides the specified cells with all children ifdescandants
is true. NOTE: Your GraphLayoutCache must bepartial
(setpartial
totrue
in the constructor) in order to use the visibility functionality of expand/collapse, setVisible, etc. -
showCells
Shows the specified cells with all children ifdescandants
is true. NOTE: Your GraphLayoutCache must bepartial
(setpartial
totrue
in the constructor) in order to use the visibility functionality of expand/collapse, setVisible, etc. -
ungroup
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. -
toggleCollapsedState
Toggles the collapsed state of the specified cells. NOTE: Your GraphLayoutCache must bepartial
(setpartial
totrue
in the constructor) in order to use the visibility functionality of expand/collapse, setVisible, etc.- Parameters:
cells
- The cells to toggle the collapsed state for.collapseOnly
- Whether cells should only be collapsed.expandOnly
- Whether cells should only be expanded.
-
collapse
Collapses all groups by hiding all their descendants. NOTE: Your GraphLayoutCache must bepartial
(setpartial
totrue
in the constructor) in order to use the visibility functionality of expand/collapse, setVisible, etc.- Parameters:
groups
-
-
expand
Expands all groups by showing all children. (Note: This does not show all descandants, but only the first generation of children.) NOTE: Your GraphLayoutCache must bepartial
(setpartial
totrue
in the constructor) in order to use the visibility functionality of expand/collapse, setVisible, etc. -
setCollapsedState
Collapses and/or expands the specified cell(s) NOTE: Your GraphLayoutCache must bepartial
(setpartial
totrue
in the constructor) in order to use the visibility functionality of expand/collapse, setVisible, etc.- Parameters:
collapse
- the cells to be collapsedexpand
- the cells to be expanded
-
getParentPort
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. -
getChildPort
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 onsource
. -
edit
Applies thepropertyMap
and the connection changes to the model. The initialedits
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
A shortcut method that takes a nested map and passes it to the edit method. -
edit
Applies theattributes
to allcells
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
Applies theattributes
to a singlecell
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);
-
augment
-
toBack
Sendscells
to back. Note: This expects an array of cells! -
toFront
Bringscells
to front. Note: This expects an array of cells! -
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. -
isLocalAttribute
Returns true if the set of local attributes containskey
-
isControlAttribute
Returns true ifkey
is a control attribute -
removeViewLocalAttribute
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.- Parameters:
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- Returns:
- whether or not the operation completed sucessfully
-
cellExpanded
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 (seemovesChildrenOnExpand
). -
cellWillCollapse
-
handleAttributes
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
Translates the specified views by the given amount.- Parameters:
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
-
getNeighbours
Returns a collection of cells that are connected to the specified cell by edges. Any cells specified in the exclude set will be ignored.- Parameters:
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:
- Returns the list of neighbours for
cell
-
getOutgoingEdges
Returns the outgoing edges for cell. Cell should be a port or a vertex.- Parameters:
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:
- Returns the list of outgoing edges for
cell
-
getIncomingEdges
Returns the incoming edges for cell. Cell should be a port or a vertex.- Parameters:
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:
- Returns the list of incoming edges for
cell
-
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.- Parameters:
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:
- Returns the list of incoming or outgoing edges for
cell
-
getAllViews
Returns all views, shortcut to getAllDescendants(getRoots()) -
getAllDescendants
Returns all views, including descendants that have a parent inviews
, especially the PortViews. Note: Iterative Implementation using model.getChild and getMapping on this cell mapper. -
getHiddenMapping
Returns the hiddenMapping.- Returns:
- Map
-
setShowsExistingConnections
public void setShowsExistingConnections(boolean showsExistingConnections) Sets the showsExistingConnections- Parameters:
showsExistingConnections
-
-
isShowsExistingConnections
public boolean isShowsExistingConnections()Returns the showsExistingConnections.- Returns:
- boolean
-
setShowsInsertedConnections
public void setShowsInsertedConnections(boolean showsInsertedConnections) Sets the showsInsertedConnections- Parameters:
showsInsertedConnections
-
-
isShowsInsertedConnections
public boolean isShowsInsertedConnections()Returns the showsInsertedConnections.- Returns:
- boolean
-
setHidesExistingConnections
public void setHidesExistingConnections(boolean hidesExistingConnections) Sets the hidesExistingConnections- Parameters:
hidesExistingConnections
-
-
isHidesExistingConnections
public boolean isHidesExistingConnections()Returns the hidesExistingConnections.- Returns:
- boolean
-
setHidesDanglingConnections
public void setHidesDanglingConnections(boolean hidesDanglingConnections) Sets the hidesDanglingConnections- Parameters:
hidesDanglingConnections
-
-
isHidesDanglingConnections
public boolean isHidesDanglingConnections()Returns the hidesDanglingConnections.- Returns:
- boolean
-
setRemembersCellViews
public void setRemembersCellViews(boolean rememberCellViews) Sets the rememberCellViews.- Parameters:
rememberCellViews
- The rememberCellViews to set
-
isRemembersCellViews
public boolean isRemembersCellViews()Returns the remembersCellViews.- Returns:
- boolean
-
setHiddenSet
Sets the hiddenSet. NOTE: Your GraphLayoutCache must bepartial
(setpartial
totrue
in the constructor) in order to use the visibility functionality of expand/collapse, setVisible, etc.- Parameters:
hiddenSet
- The hiddenSet to set
-
getLocalAttributes
- Returns:
- Returns the localAttributes.
-
setLocalAttributes
- Parameters:
localAttributes
- The localAttributes to set.
-
isAllAttributesLocal
public boolean isAllAttributesLocal()- Returns:
- Returns the askLocalAttribute.
-
setAllAttributesLocal
public void setAllAttributesLocal(boolean allAttributesLocal) - Parameters:
allAttributesLocal
- The allAttributesLocal 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()- Returns:
- Returns the selectsAllInsertedCells.
-
setSelectsAllInsertedCells
public void setSelectsAllInsertedCells(boolean selectsAllInsertedCells) - Parameters:
selectsAllInsertedCells
- The selectsAllInsertedCells to set.
-
isSelectsLocalInsertedCells
public boolean isSelectsLocalInsertedCells()- Returns:
- Returns the selectsLocalInsertedCells.
-
setSelectsLocalInsertedCells
public void setSelectsLocalInsertedCells(boolean selectsLocalInsertedCells) - Parameters:
selectsLocalInsertedCells
- The selectsLocalInsertedCells to set.
-
isReconnectsEdgesToVisibleParent
public boolean isReconnectsEdgesToVisibleParent()Deprecated.edges are moved to parent view and back automatically- Returns:
- Returns the reconnectsEdgesToVisibleParent.
-
setReconnectsEdgesToVisibleParent
public void setReconnectsEdgesToVisibleParent(boolean reconnectsEdgesToVisibleParent) Deprecated.edges are moved to parent view and back automatically- Parameters:
reconnectsEdgesToVisibleParent
- The reconnectsEdgesToVisibleParent to set.
-
isShowsChangedConnections
public boolean isShowsChangedConnections()- Returns:
- Returns the showsChangedConnections.
-
setShowsChangedConnections
public void setShowsChangedConnections(boolean showsChangedConnections) - Parameters:
showsChangedConnections
- The showsChangedConnections to set.
-
isMovesChildrenOnExpand
public boolean isMovesChildrenOnExpand()- Returns:
- Returns the moveChildrenOnExpand.
-
setMovesChildrenOnExpand
public void setMovesChildrenOnExpand(boolean moveChildrenOnExpand) - Parameters:
moveChildrenOnExpand
- The moveChildrenOnExpand to set.
-
isShowsInvisibleEditedCells
public boolean isShowsInvisibleEditedCells() -
setShowsInvisibleEditedCells
public void setShowsInvisibleEditedCells(boolean showsInvisibleEditedCells) -
getCollapseXScale
public double getCollapseXScale()- Returns:
- Returns the collapseXScale.
-
setCollapseXScale
public void setCollapseXScale(double collapseXScale) - Parameters:
collapseXScale
- The collapseXScale to set.
-
getCollapseYScale
public double getCollapseYScale()- Returns:
- Returns the collapseYScale.
-
setCollapseYScale
public void setCollapseYScale(double collapseYScale) - Parameters:
collapseYScale
- The collapseYScale to set.
-
isMovesParentsOnCollapse
public boolean isMovesParentsOnCollapse()- Returns:
- Returns the movesParentsOnCollapse.
-
setMovesParentsOnCollapse
public void setMovesParentsOnCollapse(boolean movesParentsOnCollapse) - Parameters:
movesParentsOnCollapse
- The movesParentsOnCollapse to set.
-
isResizesParentsOnCollapse
public boolean isResizesParentsOnCollapse()- Returns:
- Returns the resizesParentsOnCollapse.
-
setResizesParentsOnCollapse
public void setResizesParentsOnCollapse(boolean resizesParentsOnCollapse) - Parameters:
resizesParentsOnCollapse
- The resizesParentsOnCollapse to set.
-