本文整理汇总了Java中javax.swing.tree.TreePath.getPath方法的典型用法代码示例。如果您正苦于以下问题:Java TreePath.getPath方法的具体用法?Java TreePath.getPath怎么用?Java TreePath.getPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.tree.TreePath
的用法示例。
在下文中一共展示了TreePath.getPath方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例2: getSelectedNodes
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
/**
* @return {@link List} of the currently selected nodes
*/
public List<String> getSelectedNodes() {
TreePath[] paths = tree.getSelectionPaths();
List<String> selectedNodes = new ArrayList<String>();
if (paths != null) {
for (TreePath path : paths) {
StringBuilder sb = new StringBuilder();
Object[] pathArray = path.getPath();
for (Object o : pathArray) {
String nodeName = o.toString();
if (nodeName.length() > 0) {
sb.append("/");
sb.append(o.toString());
}
}
selectedNodes.add(sb.toString());
}
}
return selectedNodes;
}
示例3: hasAsParent
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
@Override
public boolean hasAsParent(TreePath path, int indexInParent) {
Object[] comps = path.getPath();
Object node;
for (int i = 1; i < comps.length; i++) {
if (arr.length < path.getPathCount() - 1) {
return false;
}
/*
if(!comparator.equals(comps[i].toString(), arr[i - 1])) {
return false;
}
*/
if (indices.length >= path.getPathCount() - 1) {
node = chooseSubnode(comps[i - 1], arr[i - 1], indices[i - 1], comparator);
} else {
node = chooseSubnode(comps[i - 1], arr[i - 1], comparator);
}
if (node != comps[i]) {
return false;
}
}
return true;
}
示例4: isDescendant
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
private boolean isDescendant(TreePath path1, TreePath path2) {
Object obj1[] = path1.getPath();
Object obj2[] = path2.getPath();
for (int i = 0; i < obj2.length; i++) {
if (obj1[i] != obj2[i]) {
return false;
}
}
return true;
}
示例5: addObject
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
/**
* Add child to the currently selected node.
*
* @param child the node to be added to the selected node
* @return the node which was inserted in the tree
*/
public gui.support.CustomTreeNode addObject(String child) {
gui.support.CustomTreeNode parentNode;
gui.support.CustomTreeNode childNode;
TreePath parentPath = tree.getSelectionPath();
if (parentPath == null) {
parentNode = rootNode;
} else // the tree has a limited depth!
{
if (parentPath.getPath().length < treeDepth) {
parentNode = (gui.support.CustomTreeNode) (parentPath.getLastPathComponent());
} else {
// Either there was no selection, or the root was selected.
toolkit.beep();
return null;
}
}
// add the child to the list of children
childNode = parentNode.addChild(child);
// update gui
treeModel.fireTreeStructureChanged(parentNode,
new int[]{parentNode.getIndexOfChild(childNode)},
new Object[]{childNode},
CustomTreeModel.TreeActions.NODE_INSERTED);
tree.expandPath(parentNode.getTreePath());
tree.scrollPathToVisible(childNode.getTreePath());
return childNode;
}
示例6: ensurePathComputed
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
public static TreePath ensurePathComputed(HeapWalkerNode root, TreePath path, Set<HeapWalkerNode> processed) {
List p = new ArrayList();
Object[] obj = path.getPath();
if (root == null || !root.equals(obj[0])) return null;
p.add(root);
for (int i = 1; i <= obj.length; i++) {
HeapWalkerNode[] ch = null;
if (root instanceof AbstractHeapWalkerNode && !processed.contains(root)) {
AbstractHeapWalkerNode a = (AbstractHeapWalkerNode)root;
ChildrenComputer c = a.getChildrenComputer();
if (c != null) ch = c.computeChildren();
a.setChildren(ch);
processed.add(root);
}
if (ch == null) ch = root.getChildren();
root = null;
if (i < obj.length) for (HeapWalkerNode x : ch)
if (x.equals(obj[i])) {
root = x;
p.add(root);
break;
}
if (root == null) break;
}
return new TreePath(p.toArray());
}
示例7: pathFromRoot
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
private static String pathFromRoot(TreePath path) {
int m = ((HeapWalkerNode)path.getLastPathComponent()).getMode();
Object[] nodes = path.getPath();
StringBuilder b = new StringBuilder();
int s = nodes.length;
for (int i = 0; i < s; i++) {
HeapWalkerNode n = (HeapWalkerNode)nodes[i];
if (m == HeapWalkerNode.MODE_FIELDS) fieldFromRoot(n, b, i, s);
else referenceFromRoot(n, b, i, s);
b.append("\n"); // NOI18N
}
return b.toString().replace("].[", ""); // NOI18N
}
示例8: getSimilarPath
import javax.swing.tree.TreePath; //导入方法依赖的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;
}
示例9: valueChanged
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
public void valueChanged(TreeSelectionEvent e) {
TreePath[] paths = e.getPaths();
selectedNodes.clear();
for (TreePath path : paths) {
boolean appended = false;
StringBuilder sb = new StringBuilder();
Object[] pathArray = path.getPath();
for (Object o : pathArray) {
if (o != null) {
String nodeName = o.toString();
if (nodeName != null) {
if (nodeName.length() > 0) {
appended = true;
sb.append("/"); //$NON-NLS-1$
sb.append(o.toString());
}
}
}
}
if (appended) {
selectedNodes.add(sb.toString());
}
}
for (int i = 0; i < needsReload.size(); i++) {
this.needsReload.set(i, true);
}
reloadSelectedViewer();
}
示例10: isDescendant
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
private boolean isDescendant(TreePath path1, TreePath path2) {
Object obj1[] = path1.getPath();
Object obj2[] = path2.getPath();
if (obj1.length <= obj2.length) {
return false;
}
for (int i = 0; i < obj2.length; i++) {
if (obj1[i] != obj2[i]) {
return false;
}
}
return true;
}
示例11: recordAction
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
private void recordAction(int action) {
TreePath[] selectionPaths = assertionTree.getSelectionPaths();
for (TreePath path : selectionPaths) {
Object[] objects = path.getPath();
final StringBuffer sb = new StringBuffer();
RComponent forComponent = rcomponent;
for (int j = 1; j < objects.length; j++) {
final AssertionTreeNode node = (AssertionTreeNode) objects[j];
if (node.getObject() instanceof RComponent) {
forComponent = (RComponent) node.getObject();
sb.setLength(0);
continue;
}
sb.append(node.getProperty());
if (j < objects.length - 1) {
if (!((AssertionTreeNode) objects[j + 1]).getProperty().startsWith("[")) {
sb.append(".");
}
} else {
String property = sb.toString();
Object value = null;
if (property.equals("Content")) {
value = forComponent.getContent();
} else {
if (property.equals("Text")) {
value = forComponent.getText();
} else {
value = forComponent.getAttribute(property);
}
}
getRecorder().recordAction(forComponent, action == ASSERT_ACTION ? "assert" : "wait", property, value);
}
}
}
}
示例12: getStringPath
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
/**
* Generates an equivalent String path from a given TreePath
*
* @param treePath
* - The path that will be converted to String
* @return The String path
*/
public static String getStringPath(TreePath treePath) {
StringBuilder fullPath = new StringBuilder();
Object[] pathNodes = treePath.getPath();
for (int j = 1; j < pathNodes.length; j++) {
if (j == pathNodes.length - 1) {
fullPath.append(pathNodes[j]);
} else {
fullPath.append(pathNodes[j]).append("/");
}
}
return fullPath.toString();
}
示例13: createFilePath
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
public static String createFilePath(TreePath treePath) {
StringBuilder sb = new StringBuilder();
Object[] nodes = treePath.getPath();
for (int i = 0; i < nodes.length; i++) {
sb.append(File.separatorChar).append(nodes[i].toString());
}
return sb.toString();
}
示例14: jTreeFileSelect_mouseClicked
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
public void jTreeFileSelect_mouseClicked(MouseEvent me) {
StringWriter writer = new StringWriter();
try {
TreePath tp = ((FileTree)me.getSource()).getPathForLocation(me.getX(), me.getY());
PathNode node = (PathNode)tp.getPath()[tp.getPathCount() -1];
String fileName = node.getValue();
ExampleDefine define = ReadExample.readExampleDefine(fileName);
jTextAreaScript.setText(define.getScript());
jTextAreaContext.setText(define.getContext());
} catch (Exception e) {
e.printStackTrace(new PrintWriter(writer));
}
}