예제 #1
0
  public void load(JarIndex index, boolean recurse) {
    // get all the child nodes
    for (EntryReference<BehaviorEntry, BehaviorEntry> reference :
        index.getBehaviorReferences(m_entry)) {
      add(
          new BehaviorReferenceTreeNode(
              m_deobfuscatingTranslator, reference, index.getAccess(m_entry)));
    }

    if (recurse && children != null) {
      for (Object child : children) {
        if (child instanceof BehaviorReferenceTreeNode) {
          BehaviorReferenceTreeNode node = (BehaviorReferenceTreeNode) child;

          // don't recurse into ancestor
          Set<Entry> ancestors = Sets.newHashSet();
          TreeNode n = (TreeNode) node;
          while (n.getParent() != null) {
            n = n.getParent();
            if (n instanceof BehaviorReferenceTreeNode) {
              ancestors.add(((BehaviorReferenceTreeNode) n).getEntry());
            }
          }
          if (ancestors.contains(node.getEntry())) {
            continue;
          }

          node.load(index, true);
        }
      }
    }
  }
예제 #2
0
  /**
   * Builds the parents of node up to and including the root node, where the original node is the
   * last element in the returned array. The length of the returned array gives the node's depth in
   * the tree.
   *
   * @param aNode the TreeNode to get the path for
   * @param depth an int giving the number of steps already taken towards the root (on recursive
   *     calls), used to size the returned array
   * @return an array of TreeNodes giving the path from the root to the specified node
   */
  protected TreeNode[] getPathToRoot(TreeNode aNode, int depth) {
    TreeNode[] retNodes;
    // This method recurses, traversing towards the root in order
    // size the array. On the way back, it fills in the nodes,
    // starting from the root and working back to the original node.

    /* Check for null, in case someone passed in a null node, or
    they passed in an element that isn't rooted at root. */
    if (aNode == null) {
      if (depth == 0) {
        return null;
      } else {
        retNodes = new TreeNode[depth];
      }
    } else {
      depth++;
      if (aNode == getRoot()) {
        retNodes = new TreeNode[depth];
      } else {
        retNodes = getPathToRoot(aNode.getParent(), depth);
      }
      retNodes[retNodes.length - depth] = aNode;
    }
    return retNodes;
  }
 private TreePath getPathForNode(TreeNode current) {
   // Get node depth
   int depth = 0;
   for (TreeNode node = current; node != null; node = node.getParent()) depth++;
   // Construct node path
   // First scan helped us, now we can directly allocate array of exact
   // size => no extra objects created (be kind to your local gc, it has
   // hard job cleaning that mess already), no collection reverse.
   // Price is doubling path construction time.
   // But in many situations you know the depth already. In such case
   // Only code below applies and time complexity is O(depth) not
   // O(2*depth)
   TreeNode[] path = new TreeNode[depth];
   for (TreeNode node = current; node != null; node.getParent())
     path[--depth] = node; // invert fill array
   return new TreePath(path);
 }
예제 #4
0
파일: TreeUtil.java 프로젝트: jexp/idea2
  private static void addEach(
      final TreeNode aRootNode, final TreeNode aNode, final List<TreeNode> aPathStack) {
    aPathStack.add(aNode);

    if (aNode != aRootNode) {
      addEach(aRootNode, aNode.getParent(), aPathStack);
    }
  }
예제 #5
0
파일: TreeUtil.java 프로젝트: jexp/idea2
 public static boolean isAncestor(final TreeNode ancestor, final TreeNode node) {
   TreeNode parent = node;
   while (parent != null) {
     if (parent == ancestor) return true;
     parent = parent.getParent();
   }
   return false;
 }
예제 #6
0
파일: TreeUtil.java 프로젝트: jexp/idea2
 public static TreePath getPathFromRoot(TreeNode node) {
   final ArrayList<TreeNode> path = new ArrayList<TreeNode>();
   do {
     path.add(node);
     node = node.getParent();
   } while (node != null);
   Collections.reverse(path);
   return new TreePath(path.toArray());
 }
예제 #7
0
  public static TreePath getPath(TreeNode treeNode) {
    List<TreeNode> nodes = new ArrayList<TreeNode>();

    while (treeNode != null) {
      nodes.add(0, treeNode);
      treeNode = treeNode.getParent();
    }

    return nodes.isEmpty() ? null : new TreePath(nodes.toArray());
  }
예제 #8
0
 /**
  * 刷新节点中文名称
  *
  * @param node
  */
 private void refreshNodeChName(TreeNode node) {
   TreeNode parNode = node.getParent();
   int index = parNode.getIndex(node);
   Caliber cal = (Caliber) ((DefaultMutableTreeNode) node).getUserObject();
   if (index == 0) {
     cal.setFirstNode(true);
   } else {
     cal.setFirstNode(false);
   }
 }
예제 #9
0
  TreePath getTreePath(TreeNode treeNode) {

    TreeNode parent = treeNode.getParent();
    if (parent == null) {
      return new TreePath(treeNode);
    } else {
      TreePath ptp = getTreePath(parent);
      ptp = ptp.pathByAddingChild(treeNode);
      return ptp;
    }
  }
예제 #10
0
 public boolean isNodeAncestor(TreeableReportRow anotherNode) {
   if (anotherNode == null) {
     return false;
   }
   TreeNode ancestor = this;
   do {
     if (ancestor == anotherNode) {
       return true;
     }
   } while ((ancestor = ancestor.getParent()) != null);
   return false;
 }
예제 #11
0
  /** *************************************************** */
  public String rename(TreeNode node, String newName) {
    if (node != null) {
      File file = node.getFile();
      String path = ((TreeNode) node.getParent()).getPath() + File.separator + newName;

      file.renameTo(new File(path));

      return path;
    } else {
      return "";
    }
  }
예제 #12
0
 private boolean isNodeChild(TreeNode aNode) {
   boolean retval;
   if (aNode == null) {
     retval = false;
   } else {
     if (getChildCount() == 0) {
       retval = false;
     } else {
       retval = (aNode.getParent() == this);
     }
   }
   return retval;
 }
예제 #13
0
 private void adjustParentsAndChildren(final CheckedTreeNode node, final boolean checked) {
   changeNodeState(node, checked);
   if (!checked) {
     TreeNode parent = node.getParent();
     while (parent != null) {
       if (parent instanceof CheckedTreeNode) {
         changeNodeState((CheckedTreeNode) parent, false);
       }
       parent = parent.getParent();
     }
     uncheckChildren(node);
   } else {
     checkChildren(node);
   }
   repaint();
 }
예제 #14
0
 public Component getTreeCellRendererComponent(
     JTree tree,
     Object value,
     boolean sel,
     boolean expanded,
     boolean leaf,
     int row,
     boolean hasFocus) {
   final TreeNode node = (TreeNode) value;
   final JLabel lbl =
       (JLabel)
           super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
   boolean useBold = false;
   boolean useRed = false;
   if (node instanceof PlaylistTreeNode) {
     PlaylistTreeNode ptn = (PlaylistTreeNode) node;
     Icon specIcon = specIcons.get(ptn.getPlaylist().getTitle().toLowerCase());
     if (specIcon != null) lbl.setIcon(specIcon);
     else lbl.setIcon(playlistIcon);
     lbl.setMaximumSize(MAX_LVL2_SZ);
     lbl.setPreferredSize(MAX_LVL2_SZ);
     int unseen = ptn.numUnseenTracks;
     if (!sel && unseen > 0) {
       lbl.setText("[" + unseen + "] " + lbl.getText());
       useBold = true;
     }
     if (ptn.hasComments) {
       useRed = true;
       useBold = true;
     }
   } else if (node instanceof LibraryTreeNode) {
     lbl.setIcon(libraryIcon);
     lbl.setMaximumSize(MAX_LVL2_SZ);
     lbl.setPreferredSize(MAX_LVL2_SZ);
     LibraryTreeNode ltn = (LibraryTreeNode) node;
     int unseen = ltn.numUnseenTracks;
     if (!sel && unseen > 0) {
       lbl.setText("[" + unseen + "] " + lbl.getText());
       useBold = true;
     }
     if (ltn.hasComments) {
       useRed = true;
       useBold = true;
     }
   } else if (node instanceof FriendTreeNode) {
     lbl.setIcon(friendIcon);
     lbl.setMaximumSize(MAX_LVL1_SZ);
     lbl.setPreferredSize(MAX_LVL1_SZ);
     int unseen = getTotalUnseen(node);
     if (!sel && unseen > 0) {
       lbl.setText("[" + unseen + "] " + lbl.getText());
       useBold = true;
     }
     if (anyComments(node)) {
       useBold = true;
       useRed = true;
     }
   } else if (node instanceof AddFriendsTreeNode) {
     lbl.setIcon(addFriendsIcon);
     lbl.setMaximumSize(MAX_LVL1_SZ);
     lbl.setPreferredSize(MAX_LVL1_SZ);
   } else if (node.getParent() == null) {
     lbl.setIcon(rootIcon);
     lbl.setMaximumSize(MAX_LVL0_SZ);
     lbl.setPreferredSize(MAX_LVL0_SZ);
     // Are there any unseen tracks at all?
     int unseen = getTotalUnseen(node);
     if (unseen > 0) useBold = true;
     if (anyComments(node)) {
       useBold = true;
       useRed = true;
     }
   }
   if (useBold) lbl.setFont(boldFont);
   else lbl.setFont(normalFont);
   if (sel) {
     lbl.setForeground(BLUE_GRAY);
     lbl.setBackground(LIGHT_GRAY);
   } else {
     lbl.setForeground(DARK_GRAY);
     lbl.setBackground(MID_GRAY);
   }
   if (useRed) lbl.setForeground(GREEN);
   return lbl;
 }
예제 #15
0
  @Override
  public void valueChanged(TreeSelectionEvent e) {
    // TODO Auto-generated method stub
    try {
      currentPath = tree.getSelectionPath();
      currentnode = (FileTreeNode) e.getPath().getLastPathComponent();
      currentfile = currentnode.GetFile();
      tree.scrollPathToVisible(currentPath); // 确保路径中所有的路径组件均展开(最后一个路径组件除外)并滚动,以便显示curpath路径标识的节点
      addressText.setText(currentnode.GetFile().getAbsolutePath()); // 将点击的节点的路径在地址栏中显示出来
      isTable = false;

      if (!currentfile.getName().equals("Desktop")) {
        Vector files = treeview.GetAll(currentnode.GetFile()); // 获取点击节点下的所有文件
        tablemodel.addAllFiles(files); // 将这些文件加到列表中
        upbtn.setEnabled(true);
        FileNewFolder.setEnabled(true);
        NewFolder.setEnabled(true);
        FileNewFile.setEnabled(true);
        FileNature.setEnabled(true);
        FileRename.setEnabled(true);
        EditCut.setEnabled(true);
        EditCopy.setEnabled(true);
        EditPaste.setEnabled(true);
        NewFile.setEnabled(true);
        Nature.setEnabled(true);
        Rename.setEnabled(true);
        Cut.setEnabled(true);
        Copy.setEnabled(true);
        Paste.setEnabled(true);
        if (!(currentnode.getParent().toString()).equals(File.listRoots())
            && (currentnode.toString() != "网络")
            && (currentnode.toString() != "库")
            && (currentnode.toString() != "家庭组")) // 不是根节点
        {
          FileDelete.setEnabled(true);
          Delete.setEnabled(true);
        } else {
          FileDelete.setEnabled(false);
          Delete.setEnabled(true);
        }
      } else {
        downbtn.setEnabled(false);
        upbtn.setEnabled(false);
        FileNewFolder.setEnabled(false); //  菜单栏中的菜单选项
        FileNewFile.setEnabled(false);
        FileNature.setEnabled(false);
        FileRename.setEnabled(false);
        FileDelete.setEnabled(false);
        EditCut.setEnabled(false);
        EditCopy.setEnabled(false);
        NewFolder.setEnabled(false); //  右键菜单中的菜单选项
        NewFile.setEnabled(false);
        Nature.setEnabled(false);
        Rename.setEnabled(false);
        Delete.setEnabled(false);
        Cut.setEnabled(false);
        Copy.setEnabled(false);
        currentnode = (TreeNode) treemodel.getRoot();
        tablemodel.addAllFiles(treeview.GetRoot());
      }
    } catch (Exception ee) {
      JOptionPane.showMessageDialog(null, "读取文件错误!", "Error", JOptionPane.ERROR_MESSAGE);
      ee.printStackTrace();
    }
  }