本文整理汇总了Java中javax.swing.tree.TreeModel.getRoot方法的典型用法代码示例。如果您正苦于以下问题:Java TreeModel.getRoot方法的具体用法?Java TreeModel.getRoot怎么用?Java TreeModel.getRoot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.tree.TreeModel
的用法示例。
在下文中一共展示了TreeModel.getRoot方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: collapseAll
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
public void collapseAll() {
if (tree != null) try {
markExpansionTransaction();
TreePath selected = tree.getSelectionPath();
if (selected != null && selected.getPathCount() > 2) {
tree.setSelectionPath(new TreePath(new Object[] {
selected.getPathComponent(0), selected.getPathComponent(1)
}));
}
TreeModel tmodel = tree.getModel();
Object root = tmodel.getRoot();
int nchildren = tmodel.getChildCount(root);
for (int i = 0; i < nchildren; i++)
tree.collapsePath(new TreePath(new Object[] {
root, tmodel.getChild(root, i)
}));
tree.resetExpandedNodes();
} finally {
clearExpansionTransaction();
}
}
示例2: populateTrees
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
private void populateTrees() {
licenseFilterMenu.setLicenses();
TreeModel issuesTreeModel = new DefaultTreeModel(new ScanTreeNode("SeveritiesTree"));
TreeModel licensesTreeModel = new DefaultTreeModel(new ScanTreeNode("LicensesTree"));
ScanManager scanManager = ScanManagerFactory.getScanManager(project);
if (scanManager != null) {
scanManager.filterAndSort(issuesTreeModel, licensesTreeModel);
}
ScanTreeNode root = (ScanTreeNode) issuesTreeModel.getRoot();
issuesCount.setText("Issues (" + root.getIssueCount() + ") ");
issuesComponentsTree.setModel(issuesTreeModel);
issuesComponentsTree.validate();
issuesComponentsTree.repaint();
licensesComponentsTree.setModel(licensesTreeModel);
licensesComponentsTree.validate();
licensesComponentsTree.repaint();
issuesTreeExpansionListener.setIssuesCountPanel();
}
示例3: getSimilarPath
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
private TreePath getSimilarPath(TreePath oldPath) {
if (oldPath == null || oldPath.getPathCount() < 1) return null;
TreeModel currentModel = getModel();
Object currentRoot = currentModel.getRoot();
if (!currentRoot.equals(oldPath.getPathComponent(0))) return null;
TreePath p = new TreePath(currentRoot);
Object[] op = oldPath.getPath();
Object n = currentRoot;
for (int i = 1; i < op.length; i++) {
Object nn = null;
for (int ii = 0; ii < currentModel.getChildCount(n); ii++) {
Object c = currentModel.getChild(n, ii);
if (c.equals(op[i])) {
nn = c;
break;
}
}
if (nn == null) return null;
n = nn;
p = p.pathByAddingChild(n);
}
return p;
}
示例4: expandAll
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
/**
* Expands all paths in the tree.
*
* @see JTree#expandPath(TreePath)
*/
public void expandAll() {
cancelEditing();
final TreeModel tm = getModel();
final Object root = tm.getRoot();
/* nothing to expand, if no root */
if (root != null) {
expandAllPaths(new TreePath(root), tm);
}
}
示例5: getPath
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
private TreePath getPath(JTree tree, String path) {
String[] tokens = path.substring(1).split("(?<!\\\\)/");
TreeModel treeModel = tree.getModel();
if (treeModel == null) {
throw new RuntimeException("Could not find model for tree");
}
Object rootNode = treeModel.getRoot();
int start = tree.isRootVisible() ? 1 : 0;
TreePath treePath = new TreePath(rootNode);
StringBuilder searchedPath = new StringBuilder();
if (tree.isRootVisible()) {
String rootNodeText = unescapeSpecialCharacters(tokens[0]);
searchedPath.append("/" + rootNodeText);
assertTrue("JTree does not have a root node!", rootNode != null);
assertTrue("JTree root node does not match: Expected </" + getPathText(tree, treePath) + "> Actual: <"
+ searchedPath.toString() + ">", searchedPath.toString().equals("/" + getPathText(tree, treePath)));
}
for (int i = start; i < tokens.length; i++) {
String childText = unescapeSpecialCharacters(tokens[i]);
searchedPath.append("/" + childText);
boolean matched = false;
tree.expandPath(treePath);
for (int j = 0; j < treeModel.getChildCount(treePath.getLastPathComponent()); j++) {
Object child = treeModel.getChild(treePath.getLastPathComponent(), j);
TreePath childPath = treePath.pathByAddingChild(child);
if (childText.equals(getPathText(tree, childPath))) {
treePath = childPath;
matched = true;
break;
}
}
if (!matched) {
return null;
}
}
return treePath;
}
示例6: filterAndSort
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
/**
* filter scan components tree model according to the user filters and sort the issues tree.
*/
public void filterAndSort(TreeModel issuesTreeModel, TreeModel licensesTreeModel) {
if (scanResults == null) {
return;
}
FilterManager filterManager = FilterManager.getInstance(project);
ScanTreeNode issuesFilteredRoot = (ScanTreeNode) issuesTreeModel.getRoot();
ScanTreeNode licenseFilteredRoot = (ScanTreeNode) licensesTreeModel.getRoot();
filterManager.applyFilters((ScanTreeNode) scanResults.getRoot(), issuesFilteredRoot, licenseFilteredRoot);
issuesFilteredRoot.setIssues(issuesFilteredRoot.processTreeIssues());
}
示例7: updateTree
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
/**
* Updates the tree based on the event type. This will invoke either
* updateTree with the root element, or handleChange.
*/
protected void updateTree(DocumentEvent event) {
updatingSelection = true;
try {
TreeModel model = getTreeModel();
Object root = model.getRoot();
for (int counter = model.getChildCount(root) - 1; counter >= 0;
counter--) {
updateTree(event, (Element) model.getChild(root, counter));
}
} finally {
updatingSelection = false;
}
}
示例8: getTreePath
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
/**
* Converts a file path to the TreePath that indentifies the file in the tree model.
*
* @param model The tree model.
* @param path File path from the working copy.
*
* @return A file path to the TreePath.
*/
public static TreePath getTreePath(TreeModel model, String path) {
String[] strings = path.split("/");
Object[] parts = new Object[1 + strings.length];
parts[0] = model.getRoot();
for (int i = 0; i < strings.length; i++) {
parts[i + 1] = new GitTreeNode(strings[i]);
}
return new TreePath(parts);
}
示例9: browseRoot
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
protected void browseRoot(JTree tree) {
TreeModel model = tree.getModel();
Object root = model.getRoot();
browseChildren(model, root, 0);
}
示例10: caretUpdate
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
/**
* Messaged when the selection in the editor has changed. Will update
* the selection in the tree.
*/
public void caretUpdate(CaretEvent e) {
if (!updatingSelection) {
int selBegin = Math.min(e.getDot(), e.getMark());
int end = Math.max(e.getDot(), e.getMark());
List<TreePath> paths = new ArrayList<TreePath>();
TreeModel model = getTreeModel();
Object root = model.getRoot();
int rootCount = model.getChildCount(root);
// Build an array of all the paths to all the character elements
// in the selection.
for (int counter = 0; counter < rootCount; counter++) {
int start = selBegin;
while (start <= end) {
TreePath path = getPathForIndex(start, root,
(Element) model.getChild(root, counter));
Element charElement = (Element) path.getLastPathComponent();
paths.add(path);
if (start >= charElement.getEndOffset()) {
start++;
} else {
start = charElement.getEndOffset();
}
}
}
// If a path was found, select it (them).
int numPaths = paths.size();
if (numPaths > 0) {
TreePath[] pathArray = new TreePath[numPaths];
paths.toArray(pathArray);
updatingSelection = true;
try {
getTree().setSelectionPaths(pathArray);
getTree().scrollPathToVisible(pathArray[0]);
} finally {
updatingSelection = false;
}
}
}
}