public DefaultMutableTreeNode addObject(
      DefaultMutableTreeNode parent, MenuItem child, boolean shouldBeVisible) {
    JscTreeNode childNode = new JscTreeNode(child);

    if (parent == null) {
      parent = rootNode;
    }

    // It is key to invoke this on the TreeModel, and NOT DefaultMutableTreeNode
    treeModel.insertNodeInto(childNode, parent, parent.getChildCount());

    // Make sure the user can see the lovely new node.
    if (shouldBeVisible) {
      tree.scrollPathToVisible(new TreePath(childNode.getPath()));
    }
    return childNode;
  }
示例#2
0
 private DefaultMutableTreeNode findIDorURL(DefaultMutableTreeNode node, ID id, URL url) {
   SearchTOCItem item = (SearchTOCItem) node.getUserObject();
   if (item != null) {
     ID testID = item.getID();
     if (testID != null && id != null && testID.equals(id)) {
       return node;
     } else {
       URL testURL = item.getURL();
       if (testURL != null && url != null && url.sameFile(testURL)) {
         return node;
       }
     }
   }
   int size = node.getChildCount();
   for (int i = 0; i < size; i++) {
     DefaultMutableTreeNode tmp = (DefaultMutableTreeNode) node.getChildAt(i);
     DefaultMutableTreeNode test = findIDorURL(tmp, id, url);
     if (test != null) {
       return test;
     }
   }
   return null;
 }