本文整理汇总了Java中javax.swing.tree.TreePath.getPathCount方法的典型用法代码示例。如果您正苦于以下问题:Java TreePath.getPathCount方法的具体用法?Java TreePath.getPathCount怎么用?Java TreePath.getPathCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.tree.TreePath
的用法示例。
在下文中一共展示了TreePath.getPathCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: actionProduced
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
@Override
public Object actionProduced(Object anObject) {
TreePath lrPath;
Point lrFindPoint = findCell(name, getRowsToSearch(), new int[]{getTreeColumnIndex()}, index);
//no cell found
if (lrFindPoint.equals(new Point(-1, -1))) {
return null;
}
//y is row, x is not important since we're asking for a row in the tree
lrPath = getOutline().getLayoutCache().getPathForRow(lrFindPoint.y);
//path for the specified row not found or it is not visible
if (lrPath == null) {
return null;
}
//found a cell that is a not a direct child of the parent path
if (lrPath.getPathCount() != parentPath.getPathCount() + 1) {
return null;
}
return lrPath;
}
示例4: collapseAll
import javax.swing.tree.TreePath; //导入方法依赖的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();
}
}
示例5: keyPressed
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
TreePath[] paths = getSelectionPaths();
if ((paths != null) && (paths.length > 0)) {
Collection changedNodes = new ArrayList();
for (int i = 0; i < paths.length; i++) {
TreePath path = paths[i];
if ((path != null) && (path.getPathCount() > 0) && path.getLastPathComponent() instanceof CheckTreeNode
&& (((CheckTreeNode) path.getLastPathComponent()).isLeaf() || (i == (paths.length - 1)))) {
fireNodeToggled(path, true);
}
changedNodes.addAll(togglePathState(path));
fireNodeToggled(path, false);
}
treeDidChange();
fireCheckTreeChanged(changedNodes);
}
}
}
示例6: removeSelectionPaths
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
@Override
public void removeSelectionPaths(TreePath[] paths) {
for (int i = 0; i < paths.length; i++) {
TreePath path = paths[i];
if (path.getPathCount() == 1) {
super.removeSelectionPaths(new TreePath[]{path});
} else {
toggleRemoveSelection(path);
}
}
}
示例7: expandSelection
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
/**
* Tries to expand nodes selected in the explorer manager.
*/
private void expandSelection() {
Node[] arr = manager.getSelectedNodes ();
for (int i = 0; i < arr.length; i++) {
if ( (arr[i].getParentNode() == null) && (! outline.isRootVisible())) {
// don't try to show root if it is invisible
continue;
}
TreeNode tn = Visualizer.findVisualizer(arr[i]);
if (tn != null) {
ArrayList<TreeNode> al = new ArrayList<TreeNode> ();
while (tn != null) {
al.add(tn);
tn = tn.getParent();
}
Collections.reverse(al);
TreePath tp = new TreePath(al.toArray());
Deque<TreePath> pathsStack = new ArrayDeque<TreePath>(al.size());
while ((tp != null) && (tp.getPathCount() > 0)) {
tp = tp.getParentPath();
if (tp != null) {
pathsStack.addFirst(tp);
}
}
for (TreePath etp : pathsStack) {
outline.expandPath(etp);
}
}
}
}
示例8: isEditEvent
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
private boolean isEditEvent(int row, int column, MouseEvent me) {
if (me.getClickCount() > 1) {
return true;
}
boolean noModifiers = me.getModifiersEx() == MouseEvent.BUTTON1_DOWN_MASK;
if (lastEditPosition != null && selectedRow == row && noModifiers &&
lastEditPosition[0] == row && lastEditPosition[1] == column) {
int handleWidth = DefaultOutlineCellRenderer.getExpansionHandleWidth();
Insets ins = getInsets();
TreePath path = getLayoutCache().getPathForRow(convertRowIndexToModel(row));
int nd = path.getPathCount() - (isRootVisible() ? 1 : 2);
if (nd < 0) {
nd = 0;
}
int handleStart = ins.left + (nd * DefaultOutlineCellRenderer.getNestingWidth());
int handleEnd = ins.left + handleStart + handleWidth;
// Translate 'x' to position of column if non-0:
int columnStart = getCellRect(row, column, false).x;
handleStart += columnStart;
handleEnd += columnStart;
if (me.getX() >= handleEnd) {
lastEditPosition = null;
return true;
}
}
lastEditPosition = new int[] { row, column };
return false;
}
示例9: convertPath
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
private static String convertPath(TreePath path) {
if (path == null) {
return null;
}
int pathCount = path.getPathCount();
if (pathCount < 2) {
return "";
}
StringBuilder bufResult = new StringBuilder(path.getPathComponent(1).toString());
for (int i = 2; i < pathCount; i++) {
bufResult.append("|").append(path.getPathComponent(i).toString());
}
return bufResult.toString();
}
示例10: getRowPathStr
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
private String getRowPathStr(TreePath trp) {
String pathStr = "";
if (trp.getPathCount() > 1) {
for (int i = 1; i < trp.getPathCount(); i++) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) trp.getPathComponent(i);
TreeNodeUserObject userObject = (TreeNodeUserObject) node.getUserObject();
pathStr = pathStr + userObject.getOriginalName() + "/";
}
}
return pathStr;
}
示例11: getMaxValue
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
private long getMaxValue(int row, int val) {
TreePath path = treeTable.getPathForRow(row);
if (path == null) return Long.MIN_VALUE; // TODO: prevents NPE from export but doesn't provide the actual value!
if (path.getPathCount() < 2) return 1;
PrestimeCPUCCTNode node = (PrestimeCPUCCTNode)path.getPathComponent(1);
if (val == 0) return Math.abs(node.getTotalTime0());
else if (val == 1) return Math.abs(node.getTotalTime1());
else return Math.abs(node.getNCalls());
}
示例12: 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;
}
示例13: actionPerformed
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent event) {
TreePath path = getSelectionPath();
if (listener != null && path != null && path.getPathCount() == 2) {
listener.deleteRequested(new Event(path));
}
ProjectExplorer.this.requestFocus();
}
示例14: getRowPathStr
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
private String getRowPathStr(TreePath trp) {
String pathStr = "";
if (trp.getPathCount() > 1) {
for (int i = 1; i < trp.getPathCount(); i++) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) trp.getPathComponent(i);
TreeNodeUserObject userObject = (TreeNodeUserObject) node.getUserObject();
pathStr = pathStr + userObject.getOriginalName() + "/";
}
}
return pathStr;
}
示例15: isRootSelected
import javax.swing.tree.TreePath; //导入方法依赖的package包/类
public Boolean isRootSelected() {
TreePath path = tree.getSelectionPath();
if (path != null) {
return path.getPathCount() == 1;
}
return true;
}