Beispiel #1
0
  /**
   * Visit each scene graph element ordered by BFS
   *
   * @param visitor
   */
  public void breadthFirstTraversal(SceneGraphVisitor visitor) {
    Queue<Spatial> queue = new LinkedList<Spatial>();
    queue.add(this);

    while (!queue.isEmpty()) {
      Spatial s = queue.poll();
      visitor.visit(s);
      s.breadthFirstTraversal(visitor, queue);
    }
  }
  public static <T extends Control> T findFirstControl(Spatial sp, final Class<T> aClass) {
    controlResult = null;
    sp.breadthFirstTraversal(
        new SceneGraphVisitor() {
          @Override
          public void visit(Spatial spatial) {
            if (spatial.getControl(aClass) != null) {
              controlResult = spatial.getControl(aClass);
            }
          }
        });

    return (T) controlResult;
  }