Node Models

JBotSim allows you to register classes of node, to be used automatically when new nodes are added to the topology.

Setting the default node model

Let's say that you have created a new type of node called MyNode that extends class Node.

You can register MyNode as the default model by calling setDefaultNodeModel(MyNode.class) on the topology object. Typically, your main() method would look like this:

import io.jbotsim.core.Topology;
import io.jbotsim.ui.JViewer;

public class Main{
    public static void main(String[] args){
        Topology tp = new Topology();
        // ...

Now, whenever the user adds a node through the viewer, this node will be of type MyNode. Likewise, the nodes added through calling .addNode() on the topology will be of type MyNode (unless otherwise specified).

Using several node models

When your scenario uses several types of nodes, you can register them with a name as follows:

    tp.setNodeModel("name1", TypeOfNode.class);
    tp.setNodeModel("name2", AnotherTypeOfNode.class);

In this case, whenever a node is added through the viewer, a menu asks the user which of the models should be used.