public class GraphModelManager extends Object
IGraph
instance in a CanvasControl
.
This class monitors the structural changes of an IGraph
implementation and installs the necessary ICanvasObject
instance in the canvas for each item in the graph. Note that GraphControl
has an instance of this type built-in
already and usually it is not necessary to create an own one. This class will also use the node hierarchy
to nest the nodes and edges
accordingly.
Modifier and Type | Field and Description |
---|---|
static ICanvasObjectDescriptor |
DEFAULT_EDGE_DESCRIPTOR
The immutable instance of the default
ICanvasObjectDescriptor for IEdge s which simply defers to the
edge's IEdgeStyle . |
static ICanvasObjectDescriptor |
DEFAULT_LABEL_DESCRIPTOR
The immutable instance of the default
ICanvasObjectDescriptor for ILabel s which simply defers to the
label's ILabelStyle . |
static ICanvasObjectDescriptor |
DEFAULT_NODE_DESCRIPTOR
The immutable instance of the default
ICanvasObjectDescriptor for INode s which simply defers to the
node's INodeStyle . |
static ICanvasObjectDescriptor |
DEFAULT_PORT_DESCRIPTOR
The immutable instance of the default
ICanvasObjectDescriptor for IPort s which simply defers to the
port's IPortStyle . |
Constructor and Description |
---|
GraphModelManager(CanvasControl canvas)
Creates a manager instance for the given control.
|
GraphModelManager(CanvasControl canvas,
ICanvasObjectGroup contentGroup)
Creates a manager instance for the given control.
|
Modifier and Type | Method and Description |
---|---|
int |
compare(IModelItem item1,
IModelItem item2)
Compares two items with respect to their visibility order.
|
protected ICanvasObjectGroup |
createContentGroup()
Factory method that creates the
ContentGroup . |
protected ICanvasObjectGroup |
createEdgeGroup()
Factory method for the
EdgeGroup property. |
protected ICanvasObjectGroup |
createEdgeLabelGroup()
Factory method for the
EdgeLabelGroup property. |
<T extends IModelItem> |
createHitTester(Class<T> itemType)
Gets a
IHitTester that can be used to enumerate hits on the canvas at a given world coordinate position. |
protected ICanvasObjectGroup |
createNodeGroup()
Factory method for the
NodeGroup property. |
protected ICanvasObjectGroup |
createNodeLabelGroup()
Factory method for the
NodeLabelGroup property. |
protected ICanvasObjectGroup |
createPortGroup()
Factory method for the
PortGroup property. |
ICanvasObject |
getCanvasObject(IModelItem item)
Retrieves the
ICanvasObject for a given model item managed by this instance. |
protected ICanvasObjectGroup |
getCanvasObjectGroup(IEdge edge)
Retrieves the Canvas Object group to use for the given edge.
|
protected ICanvasObjectGroup |
getCanvasObjectGroup(ILabel label)
Retrieves the Canvas Object group to use for the given label.
|
protected ICanvasObjectGroup |
getCanvasObjectGroup(INode node)
Retrieves the Canvas Object group to use for the given node.
|
protected ICanvasObjectGroup |
getCanvasObjectGroup(IPort port)
Retrieves the Canvas Object group to use for the given port.
|
Comparator<IModelItem> |
getComparator()
Gets an
Comparator instance that can be used to compare two model items with respect to their visual display
order. |
ICanvasObjectGroup |
getContentGroup()
Gets the content group this manager instance uses to add visual representation of the graph to.
|
ICanvasObjectDescriptor |
getEdgeDescriptor()
Gets the
ICanvasObjectDescriptor instance used for installing an IEdge into the canvas. |
ICanvasObjectGroup |
getEdgeGroup()
Gets the
ICanvasObjectGroup instance that will be used for installing edge styles. |
ICanvasObjectDescriptor |
getEdgeLabelDescriptor()
Gets the
ICanvasObjectDescriptor instance used for installing an ILabel of an IEdge into the
canvas. |
ICanvasObjectGroup |
getEdgeLabelGroup()
Gets the
ICanvasObjectGroup instance that will be used for installing edge label styles. |
IGraph |
getGraph()
Gets the graph this manager manages.
|
IHitTester<IModelItem> |
getHitTester()
Gets a
IHitTester that can be used to enumerate hits on the canvas at a given world coordinate position. |
IModelItem |
getModelItem(ICanvasObject canvasObject)
Retrieves the corresponding
IModelItem for the given canvas object. |
ICanvasObjectDescriptor |
getNodeDescriptor()
Gets the
ICanvasObjectDescriptor instance used for installing an INode into the canvas. |
ICanvasObjectGroup |
getNodeGroup()
Gets the
ICanvasObjectGroup instance that will be used for installing node styles. |
ICanvasObjectDescriptor |
getNodeLabelDescriptor()
Gets the
ICanvasObjectDescriptor instance used for installing an ILabel of an INode into the
canvas. |
ICanvasObjectGroup |
getNodeLabelGroup()
Gets the
ICanvasObjectGroup instance that will be used for installing node label styles. |
ICanvasObjectDescriptor |
getPortDescriptor()
Gets the
ICanvasObjectDescriptor instance used for installing an IPort into the canvas. |
ICanvasObjectGroup |
getPortGroup()
Gets the
ICanvasObjectGroup instance that will be used for installing port styles. |
IEnumerable<IModelItem> |
hitElementsAt(IInputModeContext context,
PointD location,
ICanvasObjectGroup root)
Enumerates hits on the canvas at a given world coordinate position for a given context.
|
IEnumerable<IModelItem> |
hitElementsAt(PointD location)
Enumerates hits on the canvas at a given world coordinate position.
|
boolean |
isHierarchicEdgeNestingEnabled()
Determines whether this instance should nest the edges accordingly if the graph is grouped.
|
boolean |
isHierarchicNodeNestingEnabled()
Determines whether this instance should nest the nodes
and optionally edges
accordingly if the graph is grouped. |
protected void |
onGraphChanged(IGraph oldGraph,
IGraph newGraph)
Called when the
Graph property changes. |
void |
setContentGroup(ICanvasObjectGroup value)
Sets the content group this manager instance uses to add visual representation of the graph to.
|
void |
setEdgeDescriptor(ICanvasObjectDescriptor value)
Sets the
ICanvasObjectDescriptor instance used for installing an IEdge into the canvas. |
void |
setEdgeLabelDescriptor(ICanvasObjectDescriptor value)
Sets the
ICanvasObjectDescriptor instance used for installing an ILabel of an IEdge into the
canvas. |
void |
setGraph(IGraph value)
Sets the graph this manager manages.
|
void |
setHierarchicEdgeNestingEnabled(boolean value)
Determines whether this instance should nest the edges accordingly if the graph is grouped.
|
void |
setHierarchicNodeNestingEnabled(boolean value)
Determines whether this instance should nest the nodes
and optionally edges
accordingly if the graph is grouped. |
void |
setNodeDescriptor(ICanvasObjectDescriptor value)
Sets the
ICanvasObjectDescriptor instance used for installing an INode into the canvas. |
void |
setNodeLabelDescriptor(ICanvasObjectDescriptor value)
Sets the
ICanvasObjectDescriptor instance used for installing an ILabel of an INode into the
canvas. |
void |
setPortDescriptor(ICanvasObjectDescriptor value)
Sets the
ICanvasObjectDescriptor instance used for installing an IPort into the canvas. |
<T extends IModelItem> |
typedHitElementsAt(Class<T> modelItemType,
IInputModeContext context,
PointD location,
ICanvasObjectGroup root)
Enumerates hits on the canvas at a given world coordinate position in a given context.
|
<T extends IModelItem> |
typedHitElementsAt(Class<T> itemType,
PointD location)
Enumerates hits on the canvas at a given world coordinate position.
|
void |
updateDescriptor(IModelItem item)
Updates the visual representation of the given
item. |
public static final ICanvasObjectDescriptor DEFAULT_EDGE_DESCRIPTOR
ICanvasObjectDescriptor
for IEdge
s which simply defers to the
edge's IEdgeStyle
.public static final ICanvasObjectDescriptor DEFAULT_LABEL_DESCRIPTOR
ICanvasObjectDescriptor
for ILabel
s which simply defers to the
label's ILabelStyle
.public static final ICanvasObjectDescriptor DEFAULT_NODE_DESCRIPTOR
ICanvasObjectDescriptor
for INode
s which simply defers to the
node's INodeStyle
.public static final ICanvasObjectDescriptor DEFAULT_PORT_DESCRIPTOR
ICanvasObjectDescriptor
for IPort
s which simply defers to the
port's IPortStyle
.public GraphModelManager(CanvasControl canvas)
The contents of the graph will be added to a newly created group that is added to the root of the scene graph.
In order to get anything useful out of this instance the Graph
property should be set to an instance
after construction.
canvas
- the canvas to manage the visual appearance of a graph for.public GraphModelManager(CanvasControl canvas, ICanvasObjectGroup contentGroup)
The contents of the graph will be added to given group that is must be part of the canvas.
In order to get anything useful out of this instance the Graph
property should be set to an instance
after construction.
canvas
- the canvas to manage the visual appearance of a graph for.contentGroup
- the group to add the graph's visual content to. Can be null, in which case ContentGroup
should be set afterwards or createContentGroup()
will automatically create a group lazily.public int compare(IModelItem item1, IModelItem item2)
item1
- the first item to compareitem2
- the second item to comparegetComparator()
protected ICanvasObjectGroup createContentGroup()
ContentGroup
.
The default implementation will just add another group to the CanvasControl
.
protected ICanvasObjectGroup createEdgeGroup()
EdgeGroup
property.
This method will be called upon first access to the property.
ContentGroup
protected ICanvasObjectGroup createEdgeLabelGroup()
EdgeLabelGroup
property.
This method will be called upon first access to the property.
ContentGroup
public <T extends IModelItem> IHitTester<T> createHitTester(Class<T> itemType)
IHitTester
that can be used to enumerate hits on the canvas at a given world coordinate position.
This enumerator will enumerate hits in the order so that the visually topmost element will be reported first.
protected ICanvasObjectGroup createNodeGroup()
NodeGroup
property.
This method will be called upon first access to the property.
ContentGroup
protected ICanvasObjectGroup createNodeLabelGroup()
NodeLabelGroup
property.
This method will be called upon first access to the property.
ContentGroup
protected ICanvasObjectGroup createPortGroup()
PortGroup
property.
This method will be called upon first access to the property.
ContentGroup
public ICanvasObject getCanvasObject(IModelItem item)
ICanvasObject
for a given model item managed by this instance.item
- the itemnull
ItemModelManager.getCanvasObject(Object)
protected ICanvasObjectGroup getCanvasObjectGroup(IEdge edge)
This implementation is called by the default EdgeDescriptor
instance.
edge
- The edge that will be installed in the canvas.protected ICanvasObjectGroup getCanvasObjectGroup(ILabel label)
This implementation is called by the default NodeLabelDescriptor
and EdgeLabelDescriptor
instances.
label
- The label that will be installed in the canvas.protected ICanvasObjectGroup getCanvasObjectGroup(INode node)
This implementation is called by the default NodeDescriptor
instance.
node
- The node that will be installed in the canvas.protected ICanvasObjectGroup getCanvasObjectGroup(IPort port)
This implementation is called by the default PortDescriptor
instance.
port
- The port that will be installed in the canvas.public final Comparator<IModelItem> getComparator()
Comparator
instance that can be used to compare two model items with respect to their visual display
order.
An item is considered to be greater than another item if it is rendered on top of it.
public final ICanvasObjectGroup getContentGroup()
setContentGroup(ICanvasObjectGroup)
public final ICanvasObjectDescriptor getEdgeDescriptor()
ICanvasObjectDescriptor
instance used for installing an IEdge
into the canvas.setEdgeDescriptor(ICanvasObjectDescriptor)
public final ICanvasObjectGroup getEdgeGroup()
ICanvasObjectGroup
instance that will be used for installing edge styles.
If the field has not yet been initialized upon first access, the factory method createEdgeGroup()
will be
called. Note that in the case of hierarchically nested graphs
edges will only
be put directly in this ICanvasObjectGroup
, if the HierarchicEdgeNestingEnabled
property is set to false
. Otherwise edges will actually be nested in the subtree of the NodeGroup
according to the node nesting.
getCanvasObjectGroup(IEdge)
,
getEdgeDescriptor()
public final ICanvasObjectDescriptor getEdgeLabelDescriptor()
ICanvasObjectDescriptor
instance used for installing an ILabel
of an IEdge
into the
canvas.setEdgeLabelDescriptor(ICanvasObjectDescriptor)
public final ICanvasObjectGroup getEdgeLabelGroup()
ICanvasObjectGroup
instance that will be used for installing edge label styles.
If the field has not yet been initialized upon first access, the factory method createEdgeLabelGroup()
will be
called.
getCanvasObjectGroup(ILabel)
,
getEdgeLabelDescriptor()
public final IGraph getGraph()
onGraphChanged(IGraph, IGraph)
,
setGraph(IGraph)
public final IHitTester<IModelItem> getHitTester()
IHitTester
that can be used to enumerate hits on the canvas at a given world coordinate position.
This enumerator will enumerate hits in the order so that the visually topmost element will be reported first.
public IModelItem getModelItem(ICanvasObject canvasObject)
IModelItem
for the given canvas object.canvasObject
- the instance to use for the querynull
.public final ICanvasObjectDescriptor getNodeDescriptor()
ICanvasObjectDescriptor
instance used for installing an INode
into the canvas.setNodeDescriptor(ICanvasObjectDescriptor)
public final ICanvasObjectGroup getNodeGroup()
ICanvasObjectGroup
instance that will be used for installing node styles.
If the field has not yet been initialized upon first access, the factory method createNodeGroup()
will be
called. Note that in the case of hierarchic node nesting
, nodes will not be
installed at the top-level of this group. Rather a more complicated nesting of dynamically created
ICanvasObjectGroup
s will be used.
getCanvasObjectGroup(INode)
,
getNodeDescriptor()
public final ICanvasObjectDescriptor getNodeLabelDescriptor()
ICanvasObjectDescriptor
instance used for installing an ILabel
of an INode
into the
canvas.setNodeLabelDescriptor(ICanvasObjectDescriptor)
public final ICanvasObjectGroup getNodeLabelGroup()
ICanvasObjectGroup
instance that will be used for installing node label styles.
If the field has not yet been initialized upon first access, the factory method createNodeLabelGroup()
will be
called.
getCanvasObjectGroup(ILabel)
,
getNodeLabelDescriptor()
public final ICanvasObjectDescriptor getPortDescriptor()
ICanvasObjectDescriptor
instance used for installing an IPort
into the canvas.setPortDescriptor(ICanvasObjectDescriptor)
public final ICanvasObjectGroup getPortGroup()
ICanvasObjectGroup
instance that will be used for installing port styles.
If the field has not yet been initialized upon first access, the factory method createPortGroup()
will be
called.
getCanvasObjectGroup(IPort)
,
getPortDescriptor()
public IEnumerable<IModelItem> hitElementsAt(IInputModeContext context, PointD location, ICanvasObjectGroup root)
The instance returned will enumerate hits in the order so that the topmost visual element will be reported first. The enumeration is performed lazily.
context
- The context to provide to IHitTestable.isHit(IInputModeContext, PointD)
location
- the world coordinates to perform the hit testroot
- The group to search the subtree of.public IEnumerable<IModelItem> hitElementsAt(PointD location)
The instance returned will enumerate hits in the order so that the topmost visual element will be reported first. The enumeration is performed lazily.
location
- the world coordinates to perform the hit testpublic final boolean isHierarchicEdgeNestingEnabled()
Hierarchic nesting for edges requires that hierarchic nesting for nodes
is
enabled as well. If both properties are enabled (the default) the edges will actually be interleaved with the nodes in
the nested canvas object subtree so the EdgeGroup
will be empty.
isHierarchicNodeNestingEnabled()
,
setHierarchicEdgeNestingEnabled(boolean)
public final boolean isHierarchicNodeNestingEnabled()
and optionally edges
accordingly if the graph is grouped.true
(the default) iff the hierarchy should be queried.setHierarchicNodeNestingEnabled(boolean)
protected void onGraphChanged(IGraph oldGraph, IGraph newGraph)
Graph
property changes.
This method registers the collections of the graph instance with the mechanism
that manages the mapping between the elements and the
ICanvasObject
s. Subclasses should call the base method if they want to use the default mechanisms.
oldGraph
- The old graph instance.newGraph
- The new graph instance.public final void setContentGroup(ICanvasObjectGroup value)
value
- The ContentGroup to set.getContentGroup()
public final void setEdgeDescriptor(ICanvasObjectDescriptor value)
ICanvasObjectDescriptor
instance used for installing an IEdge
into the canvas.value
- The EdgeDescriptor to set.getEdgeDescriptor()
public final void setEdgeLabelDescriptor(ICanvasObjectDescriptor value)
ICanvasObjectDescriptor
instance used for installing an ILabel
of an IEdge
into the
canvas.value
- The EdgeLabelDescriptor to set.getEdgeLabelDescriptor()
public final void setGraph(IGraph value)
value
- The Graph to set.onGraphChanged(IGraph, IGraph)
,
getGraph()
public final void setHierarchicEdgeNestingEnabled(boolean value)
Hierarchic nesting for edges requires that hierarchic nesting for nodes
is
enabled as well. If both properties are enabled (the default) the edges will actually be interleaved with the nodes in
the nested canvas object subtree so the EdgeGroup
will be empty.
value
- The HierarchicEdgeNestingEnabled to set.isHierarchicNodeNestingEnabled()
,
isHierarchicEdgeNestingEnabled()
public final void setHierarchicNodeNestingEnabled(boolean value)
and optionally edges
accordingly if the graph is grouped.value
- true
(the default) iff the hierarchy should be queried.isHierarchicNodeNestingEnabled()
public final void setNodeDescriptor(ICanvasObjectDescriptor value)
ICanvasObjectDescriptor
instance used for installing an INode
into the canvas.value
- The NodeDescriptor to set.getNodeDescriptor()
public final void setNodeLabelDescriptor(ICanvasObjectDescriptor value)
ICanvasObjectDescriptor
instance used for installing an ILabel
of an INode
into the
canvas.value
- The NodeLabelDescriptor to set.getNodeLabelDescriptor()
public final void setPortDescriptor(ICanvasObjectDescriptor value)
ICanvasObjectDescriptor
instance used for installing an IPort
into the canvas.value
- The PortDescriptor to set.getPortDescriptor()
public <T extends IModelItem> IEnumerable<T> typedHitElementsAt(Class<T> modelItemType, IInputModeContext context, PointD location, ICanvasObjectGroup root)
The instance returned will enumerate hits in the order so that the topmost visual element will be reported first. The enumeration is performed lazily.
context
- The context to provide to IHitTestable.isHit(IInputModeContext, PointD)
location
- the world coordinates to perform the hit testroot
- The group to search the subtree of.public <T extends IModelItem> IEnumerable<T> typedHitElementsAt(Class<T> itemType, PointD location)
The instance returned will enumerate hits in the order so that the topmost visual element will be reported first. The enumeration is performed lazily.
location
- the world coordinates to perform the hit testpublic void updateDescriptor(IModelItem item)
Updates
the visual representation of the given
item.item
- The item to update the visual representationCollectionModelManager.update(Object)