code: private static int countNodes(TreeModel treeModel, Object node)
      {
          int sum = 1;
          int n = treeModel.getChildCount(node);
          for (int i=0; i<n; i++)
          {
              sum += countNodes(treeModel, treeModel.getChild(node, i));
          }
          return sum;
      }
docs: Recursively count the number of nodes in the given tree model,
  starting with the given node
  
  @param treeModel The tree model
  @param node The node
  @return The number of nodes