Node and VisualNode Creation

In this section, you will learn how to create two Node instances and two VisualNode instances. Together these classes lay more foundations of the Tensegrity Graph Framework.

Node Creation

We've already explained what nodes are. In the Tensegrity Graph API, the Node interface represents the functionality of any potential vertex in a graph. We call this vertex a “node” because the former tends to confuse fewer non-technical people who come into contact with graph theory and our framework.

You will eventually want to view the javadocs for more detailed information about creating nodes. There are several overloaded methods which allow more precise control over the creational process. Below is one of the utility methods that allows you to delegate some creational information to the factory.

Example 3.3. Creating two Node instances

// create three nodes with one port each
GraphModelFactory modelFactory = GraphModelFactory.newInstance();
nodeA= GraphModelFactory.makeDefaultNode(modelFactory, "a");
nodeB= GraphModelFactory.makeDefaultNode(modelFactory, "b");
nodeC= GraphModelFactory.makeDefaultNode(modelFactory, "c");

In the example above, we repeatedly show that a new Node instance is created through a method call to a factory object. Also note that exception handling has been ignored in this and other examples in this tutorial. Exception handling is, of course, coded into the executables we have provided you with.

VisualNode Creation

A VisualNode is the visual representation of a Node. There can be more than one VisualNode instance which references a unique Node instance. Each of these VisualNode instances, however, must belong to a unique instance of class VisualGraphView.

VisualNode instances do not have to be created explicitly. If you are using the ModelBasedGraphController class, visual nodes are automatically created and inserted into a VisualGraphView the moment you create Node instances in the model.