org.netbeans.api.visual 2.10

org.netbeans.api.visual.graph
Class GraphScene<N,E>

java.lang.Object
  extended by org.netbeans.api.visual.widget.Widget
      extended by org.netbeans.api.visual.widget.Scene
          extended by org.netbeans.api.visual.model.ObjectScene
              extended by org.netbeans.api.visual.graph.GraphScene<N,E>
All Implemented Interfaces:
Accessible
Direct Known Subclasses:
GraphScene.StringGraph

public abstract class GraphScene<N,E>
extends ObjectScene

This class holds and manages graph-oriented model.

In comparison with the GraphScene class, in this class the graph consists of nodes and edges. Each edge could be attach to a single source and target node.

The class is abstract and manages only data model and mapping with widgets. The graphics (widgets) has to be supplied by a developer by overriding the attachNodeWidget, attachEdgeWidget, attachEdgeSourceAnchor and attachEdgeTargetAnchor abstract methods.

This class is using generics and allows you to specify type representation for nodes and edges in the graph model. Example:

 class MyGraph extends GraphScene<MyNode, MyEdge> { ... }
 
Since the type of nodes and edges could be the same, all node and edge instances has to be unique within the whole scene.

Node and Edge should not be a Widget. It should work properly but in that case the ObjectScene class is loosing its purpose because there is no need to manage a mapping of an instance to the same instance.


Nested Class Summary
static class GraphScene.StringGraph
          This class is a particular GraphScene where nodes and edges are represented with String class.
 
Nested classes/interfaces inherited from class org.netbeans.api.visual.widget.Scene
Scene.SceneListener
 
Nested classes/interfaces inherited from class org.netbeans.api.visual.widget.Widget
Widget.Dependency
 
Constructor Summary
GraphScene()
          Creates a graph scene.
 
Method Summary
 Widget addEdge(E edge)
          Adds an edge.
 Widget addNode(N node)
          Adds a node.
protected abstract  void attachEdgeSourceAnchor(E edge, N oldSourceNode, N sourceNode)
          Called by the setEdgeSource method to notify about the changing the edge source in the graph model.
protected abstract  void attachEdgeTargetAnchor(E edge, N oldTargetNode, N targetNode)
          Called by the setEdgeTarget method to notify about the changing the edge target in the graph model.
protected abstract  Widget attachEdgeWidget(E edge)
          Called by the addEdge method before the edge is registered to acquire a widget that is going to represent the edge in the scene.
protected abstract  Widget attachNodeWidget(N node)
          Called by the addNode method before the node is registered to acquire a widget that is going to represent the node in the scene.
protected  void detachEdgeWidget(E edge, Widget widget)
          Called by the removeEdge method to notify that an edge is removed from the graph model.
protected  void detachNodeWidget(N node, Widget widget)
          Called by the removeNode method to notify that a node is removed from the graph model.
 Collection<E> findEdgesBetween(N sourceNode, N targetNode)
          Returns a collection of edges that are between a specified source and target nodes.
 Collection<E> findNodeEdges(N node, boolean allowOutputEdges, boolean allowInputEdges)
          Returns a collection of edges that are attached to a specified node.
 Collection<E> getEdges()
          Returns a collection of all edges registered in the graph model.
 N getEdgeSource(E edge)
          Returns an edge source.
 N getEdgeTarget(E edge)
          Returns an edge target.
 Collection<N> getNodes()
          Returns a collection of all nodes registered in the graph model.
 boolean isEdge(Object object)
          Checks whether an object is registered as a edge in the graph model.
 boolean isNode(Object object)
          Checks whether an object is registered as a node in the graph model.
protected  void notifyEdgeAdded(E edge, Widget widget)
          Called by the addEdge method to notify that an edge is added into the graph model.
protected  void notifyNodeAdded(N node, Widget widget)
          Called by the addNode method to notify that a node is added into the graph model.
 void removeEdge(E edge)
          Removes an edge and detaches it from its source and target nodes.
 void removeNode(N node)
          Removes a node.
 void removeNodeWithEdges(N node)
          Removes a specified node with all edges that are attached to the node.
 void setEdgeSource(E edge, N sourceNode)
          Sets an edge source.
 void setEdgeTarget(E edge, N targetNode)
          Sets an edge target.
 
Methods inherited from class org.netbeans.api.visual.model.ObjectScene
addObject, addObjectSceneListener, createObjectHoverAction, createSelectAction, findObject, findStoredObject, findWidget, findWidgets, getFocusedObject, getHighlightedObjects, getHoveredObject, getIdentityCode, getObjects, getObjectState, getSelectedObjects, isObject, removeObject, removeObjectSceneListener, setFocusedObject, setHighlightedObjects, setHoveredObject, setSelectedObjects, userSelectionSuggested
 
Methods inherited from class org.netbeans.api.visual.widget.Scene
addSceneListener, convertSceneToView, convertSceneToView, convertViewToScene, createBirdView, createSatelliteView, createView, createWidgetHoverAction, getActiveTool, getDefaultFont, getFocusedWidget, getGraphics, getInputBindings, getKeyEventProcessingType, getLookFeel, getMaximumBounds, getPriorActions, getSceneAnimator, getView, getZoomFactor, isRepaintRequiredForRevalidating, isValidated, paint, removeSceneListener, setActiveTool, setFocusedWidget, setKeyEventProcessingType, setLookFeel, setMaximumBounds, setZoomFactor, validate, validate
 
Methods inherited from class org.netbeans.api.visual.widget.Widget
addChild, addChild, addChild, addChild, addChildren, addDependency, bringToBack, bringToFront, calculateClientArea, convertLocalToScene, convertLocalToScene, convertSceneToLocal, convertSceneToLocal, createActions, equals, getAccessibleContext, getActions, getActions, getBackground, getBorder, getBounds, getChildConstraint, getChildren, getClientArea, getCursor, getCursorAt, getDependencies, getFont, getForeground, getLayout, getLocation, getLookup, getMaximumSize, getMinimumSize, getParentWidget, getPreferredBounds, getPreferredLocation, getPreferredSize, getScene, getState, getToolTipText, hashCode, isCheckClipping, isEnabled, isHitAt, isOpaque, isPreferredBoundsSet, isVisible, notifyAdded, notifyRemoved, notifyStateChanged, paint, paintBackground, paintBorder, paintChildren, paintWidget, removeChild, removeChildren, removeChildren, removeDependency, removeFromParent, repaint, resolveBounds, revalidate, revalidate, setAccessibleContext, setBackground, setBorder, setBorder, setCheckClipping, setChildConstraint, setCursor, setEnabled, setFont, setForeground, setLayout, setMaximumSize, setMinimumSize, setOpaque, setPreferredBounds, setPreferredLocation, setPreferredSize, setState, setToolTipText, setVisible
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphScene

public GraphScene()
Creates a graph scene.

Method Detail

addNode

public final Widget addNode(N node)
Adds a node.

Parameters:
node - the node to be added; the node must not be null, must not be already in the model, must be unique in the model (means: there is no other node or edge in the model has is equal to this node) and must not be a Widget
Returns:
the widget that is created by attachNodeWidget; null if the node is non-visual

removeNode

public final void removeNode(N node)
Removes a node.

Parameters:
node - the node to be removed; the node must not be null and must be already in the model

removeNodeWithEdges

public final void removeNodeWithEdges(N node)
Removes a specified node with all edges that are attached to the node.

Parameters:
node - the node to be removed

getNodes

public final Collection<N> getNodes()
Returns a collection of all nodes registered in the graph model.

Returns:
the collection of all nodes registered in the graph model

addEdge

public final Widget addEdge(E edge)
Adds an edge.

Parameters:
edge - the edge to be added; the edge must not be null, must not be already in the model, must be unique in the model (means: there is no other node or edge in the model has is equal to this edge) and must not be a Widget
Returns:
the widget that is created by attachEdgeWidget; null if the edge is non-visual

removeEdge

public final void removeEdge(E edge)
Removes an edge and detaches it from its source and target nodes.

Parameters:
edge - the edge to be removed; the edge must not be null and must be already in the model

getEdges

public final Collection<E> getEdges()
Returns a collection of all edges registered in the graph model.

Returns:
the collection of all edges registered in the graph model

setEdgeSource

public final void setEdgeSource(E edge,
                                N sourceNode)
Sets an edge source.

Parameters:
edge - the edge which source is going to be changed
sourceNode - the source node; if null, then the edge source will be detached

setEdgeTarget

public final void setEdgeTarget(E edge,
                                N targetNode)
Sets an edge target.

Parameters:
edge - the edge which target is going to be changed
targetNode - the target node; if null, then the edge target will be detached

getEdgeSource

public final N getEdgeSource(E edge)
Returns an edge source.

Parameters:
edge - the edge
Returns:
the edge source; null, if edge does not have source attached

getEdgeTarget

public final N getEdgeTarget(E edge)
Returns an edge target.

Parameters:
edge - the edge
Returns:
the edge target; null, if edge does not have target attached

findNodeEdges

public final Collection<E> findNodeEdges(N node,
                                         boolean allowOutputEdges,
                                         boolean allowInputEdges)
Returns a collection of edges that are attached to a specified node.

Parameters:
node - the node which edges connections are searched for
allowOutputEdges - if true, the output edges are included in the collection; if false, the output edges are not included
allowInputEdges - if true, the input edges are included in the collection; if false, the input edges are not included
Returns:
the collection of edges

findEdgesBetween

public final Collection<E> findEdgesBetween(N sourceNode,
                                            N targetNode)
Returns a collection of edges that are between a specified source and target nodes.

Parameters:
sourceNode - the source node
targetNode - the target node
Returns:
the collection of edges with the specified source and target nodes

isNode

public boolean isNode(Object object)
Checks whether an object is registered as a node in the graph model.

Parameters:
object - the object; must not be a Widget
Returns:
true, if the object is registered as a node

isEdge

public boolean isEdge(Object object)
Checks whether an object is registered as a edge in the graph model.

Parameters:
object - the object; must not be a Widget
Returns:
true, if the object is registered as a edge

notifyNodeAdded

protected void notifyNodeAdded(N node,
                               Widget widget)
Called by the addNode method to notify that a node is added into the graph model.

Parameters:
node - the added node
widget - the widget created by the attachNodeWidget method as a visual representation of the node

notifyEdgeAdded

protected void notifyEdgeAdded(E edge,
                               Widget widget)
Called by the addEdge method to notify that an edge is added into the graph model.

Parameters:
edge - the added node
widget - the widget created by the attachEdgeWidget method as a visual representation of the edge

detachNodeWidget

protected void detachNodeWidget(N node,
                                Widget widget)
Called by the removeNode method to notify that a node is removed from the graph model. The default implementation removes the node widget from its parent widget.

Parameters:
node - the removed node
widget - the removed node widget; null if the node is non-visual

detachEdgeWidget

protected void detachEdgeWidget(E edge,
                                Widget widget)
Called by the removeEdge method to notify that an edge is removed from the graph model. The default implementation removes the edge widget from its parent widget.

Parameters:
edge - the removed edge
widget - the removed edge widget; null if the edge is non-visual

attachNodeWidget

protected abstract Widget attachNodeWidget(N node)
Called by the addNode method before the node is registered to acquire a widget that is going to represent the node in the scene. The method is responsible for creating the widget, adding it into the scene and returning it from the method.

Parameters:
node - the node that is going to be added
Returns:
the widget representing the node; null, if the node is non-visual

attachEdgeWidget

protected abstract Widget attachEdgeWidget(E edge)
Called by the addEdge method before the edge is registered to acquire a widget that is going to represent the edge in the scene. The method is responsible for creating the widget, adding it into the scene and returning it from the method.

Parameters:
edge - the edge that is going to be added
Returns:
the widget representing the edge; null, if the edge is non-visual

attachEdgeSourceAnchor

protected abstract void attachEdgeSourceAnchor(E edge,
                                               N oldSourceNode,
                                               N sourceNode)
Called by the setEdgeSource method to notify about the changing the edge source in the graph model. The method is responsible for attaching a new source node to the edge in the visual representation.

Usually it is implemented as:

 Widget sourceNodeWidget = findWidget (sourceNode);
 Anchor sourceAnchor = AnchorFactory.createRectangularAnchor (sourceNodeWidget)
 ConnectionWidget edgeWidget = (ConnectionWidget) findWidget (edge);
 edgeWidget.setSourceAnchor (sourceAnchor);
 

Parameters:
edge - the edge which source is changed in graph model
oldSourceNode - the old source node
sourceNode - the new source node

attachEdgeTargetAnchor

protected abstract void attachEdgeTargetAnchor(E edge,
                                               N oldTargetNode,
                                               N targetNode)
Called by the setEdgeTarget method to notify about the changing the edge target in the graph model. The method is responsible for attaching a new target node to the edge in the visual representation.

Usually it is implemented as:

 Widget targetNodeWidget = findWidget (targetNode);
 Anchor targetAnchor = AnchorFactory.createRectangularAnchor (targetNodeWidget)
 ConnectionWidget edgeWidget = (ConnectionWidget) findWidget (edge);
 edgeWidget.setTargetAnchor (targetAnchor);
 

Parameters:
edge - the edge which target is changed in graph model
oldTargetNode - the old target node
targetNode - the new target node

org.netbeans.api.visual 2.10

Built on May 30 2008.  |  Portions Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.