當前位置: 首頁>>代碼示例>>Java>>正文


Java TreePath.isDescendant方法代碼示例

本文整理匯總了Java中javax.swing.tree.TreePath.isDescendant方法的典型用法代碼示例。如果您正苦於以下問題:Java TreePath.isDescendant方法的具體用法?Java TreePath.isDescendant怎麽用?Java TreePath.isDescendant使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.tree.TreePath的用法示例。


在下文中一共展示了TreePath.isDescendant方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: hasAsParent

import javax.swing.tree.TreePath; //導入方法依賴的package包/類
/**
 * implementation of JTreeOperator.TreePathChooser
 *
 * @param path TreePath
 * @param indexInParent int
 * @return boolean
 */
@Override
public boolean hasAsParent(TreePath path, int indexInParent) {
    if (path.getPathCount() <= parentPathCount) {
        return path.isDescendant(parentPath);
    }
    if (arr.length + parentPathCount < path.getPathCount()) {
        return (false);
    }
    if (indices.length >= path.getPathCount() - parentPathCount
            && indices[path.getPathCount() - parentPathCount - 1] != indexInParent) {
        return (false);
    }
    Object[] comps = path.getPath();
    for (int i = parentPathCount; i < comps.length; i++) {
        if (!comparator.equals(comps[i].toString(), arr[i - parentPathCount])) {
            return (false);
        }
    }
    return (true);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:28,代碼來源:Node.java

示例2: removedNodes

import javax.swing.tree.TreePath; //導入方法依賴的package包/類
void removedNodes(List<VisualizerNode> removed) {
       TreeSelectionModel sm = tree.getSelectionModel();
TreePath[] selPaths = (sm != null) ? sm.getSelectionPaths() : null;
       
       List<TreePath> remSel = null;
       for (VisualizerNode vn : removed) {
           visHolder.removeRecur(vn.getChildren(false));
           if (selPaths != null) {
               TreePath path = new TreePath(vn.getPathToRoot());
               for(TreePath tp : selPaths) {
                   if (path.isDescendant(tp)) {
                       if (remSel == null) {
                           remSel = new ArrayList<TreePath>();
                       }
                       remSel.add(tp);
                   }
               }
           }
       }
       
       removedNodeWasSelected = remSel != null;
       if (remSel != null) {
           try {
               sm.removeSelectionPaths(remSel.toArray(new TreePath[remSel.size()]));
           } catch (NullPointerException e) {
               // if editing of label of removed node was in progress
               // BasicTreeUI will try to cancel editing and repaint node 
               // which fails because node is already removed so it cannot get bounds of it
               // catch and ignore (issue #136123)
           }
       }
   }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:33,代碼來源:TreeView.java

示例3: getTreeCommonAncestors

import javax.swing.tree.TreePath; //導入方法依賴的package包/類
/**
 * Finds the common ancestors from the given selected paths
 * 
 * @param selectedPaths
 *          - The paths selected
 * @return A List containing the common ancestors
 */
public static List<TreePath> getTreeCommonAncestors(TreePath[] selectedPaths) {
	List<TreePath> commonAncestors = new ArrayList<TreePath>();
	if (selectedPaths != null) {
		commonAncestors.add(selectedPaths[0]);
		for (int i = 0; i < selectedPaths.length; i++) {
			boolean newPathToAdd = false;
			List<TreePath> pathsToRemove = new ArrayList<TreePath>();
			for (TreePath treePath : commonAncestors) {
				if (treePath.isDescendant(selectedPaths[i])) {
					newPathToAdd = false;
					break;
				} else if (selectedPaths[i].isDescendant(treePath)) {
					pathsToRemove.add(treePath);
					newPathToAdd = false;
				} else {
					newPathToAdd = true;
				}
			}
			if (!pathsToRemove.isEmpty()) {
				commonAncestors.removeAll(pathsToRemove);
				commonAncestors.add(selectedPaths[i]);
			} else if (newPathToAdd) {
				commonAncestors.add(selectedPaths[i]);
			}
		}
	}
	return commonAncestors;
}
 
開發者ID:oxygenxml,項目名稱:oxygen-git-plugin,代碼行數:36,代碼來源:TreeFormatter.java

示例4: compare

import javax.swing.tree.TreePath; //導入方法依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public int compare(RowMapping rm1, RowMapping rm2) {
    int index1 = rm1.getModelRowIndex();
    int index2 = rm2.getModelRowIndex();
    if (index1 == index2) {
        return 0;
    }
    TreePath tp1 = getLayoutCache().getPathForRow(index1);
    TreePath tp2 = getLayoutCache().getPathForRow(index2);
    if (tp1 == null) {
        if (tp2 == null) {
            return 0;
        } else {
            return -1;
        }
    } else if (tp2 == null) {
        return 1;
    }
    if (tp1.isDescendant(tp2)) {
        return -1;
    }
    if (tp2.isDescendant(tp1)) {
        return 1;
    }
    boolean tp1Changed = false;
    boolean tp2Changed = false;
    TreePath parent1 = tp1.getParentPath();
    TreePath parent2 = tp2.getParentPath();
    if (parent1 != null && parent2 != null && parent1.equals(parent2) &&
            getOutlineModel().isLeaf(tp1.getLastPathComponent()) &&
            getOutlineModel().isLeaf(tp2.getLastPathComponent())) {
        return ascending ? super.compare(rm1, rm2) : - super.compare(rm1, rm2);
    }
    while (tp1.getPathCount() < tp2.getPathCount()) {
        tp2 = tp2.getParentPath();
        tp2Changed = true;
    }
    while (tp1.getPathCount() > tp2.getPathCount()) {
        tp1 = tp1.getParentPath();
        tp1Changed = true;
    }
    parent1 = tp1.getParentPath();
    parent2 = tp2.getParentPath();
    while (parent1 != null && parent2 != null && !parent1.equals(parent2)) {
        tp1 = parent1;
        tp2 = parent2;
        parent1 = tp1.getParentPath();
        parent2 = tp2.getParentPath();
        tp1Changed = true;
        tp2Changed = true;
    }
    if (tp1Changed || tp2Changed) {
        return compare(tempSortMap.get(tp1), tempSortMap.get(tp2));
    } else {
        return ascending ? super.compare(rm1, rm2) : - super.compare(rm1, rm2);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:59,代碼來源:Outline.java


注:本文中的javax.swing.tree.TreePath.isDescendant方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。