javax.swing.tree.TreePath#getLastPathComponent ( )源码实例Demo

下面列出了javax.swing.tree.TreePath#getLastPathComponent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: consulo   文件: TreeExpandCollapse.java
public int expand(JTree tree, TreePath path) {
  if (myLevelsLeft == 0) return myExpansionLimit;
  TreeModel model = tree.getModel();
  Object node = path.getLastPathComponent();
  int levelDecrement = 0;
  if (!tree.isExpanded(path) && !model.isLeaf(node)) {
    tree.expandPath(path);
    levelDecrement = 1;
    myExpansionLimit--;
  }
  for (int i = 0; i < model.getChildCount(node); i++) {
    Object child = model.getChild(node, i);
    if (model.isLeaf(child)) continue;
    ExpandContext childContext = new ExpandContext(myExpansionLimit, myLevelsLeft - levelDecrement);
    myExpansionLimit = childContext.expand(tree, path.pathByAddingChild(child));
    if (myExpansionLimit <= 0) return 0;
  }
  return myExpansionLimit;
}
 
源代码2 项目: dragonwell8_jdk   文件: ElementTreePanel.java
/**
 * Called whenever the value of the selection changes.
 * @param e the event that characterizes the change.
 */
public void valueChanged(TreeSelectionEvent e) {

    if (!updatingSelection && tree.getSelectionCount() == 1) {
        TreePath selPath = tree.getSelectionPath();
        Object lastPathComponent = selPath.getLastPathComponent();

        if (!(lastPathComponent instanceof DefaultMutableTreeNode)) {
            Element selElement = (Element) lastPathComponent;

            updatingSelection = true;
            try {
                getEditor().select(selElement.getStartOffset(),
                        selElement.getEndOffset());
            } finally {
                updatingSelection = false;
            }
        }
    }
}
 
源代码3 项目: visualvm   文件: ProfilerTreeTable.java
public void collapseChildren(TreePath tpath) {
        if (tree != null) try {
            markExpansionTransaction();
            
            if (tpath == null || tree.isCollapsed(tpath)) return;
            
            TreeModel tmodel = tree.getModel();
            Object selected = tpath.getLastPathComponent();
            
            int nchildren = tmodel.getChildCount(selected);
            for (int i = 0; i < nchildren; i++) {
                TreePath tp = tpath.pathByAddingChild(tmodel.getChild(selected, i));
                tree.collapsePath(tp);
//                tree.resetExpandedState(tp);
            }
        
        } finally {
            clearExpansionTransaction();
        }
    }
 
源代码4 项目: mzmine2   文件: ProjectTreeMouseHandler.java
private void handlePopupTriggerEvent(MouseEvent e) {
  TreePath clickedPath = tree.getPathForLocation(e.getX(), e.getY());
  if (clickedPath == null)
    return;
  DefaultMutableTreeNode node = (DefaultMutableTreeNode) clickedPath.getLastPathComponent();
  Object clickedObject = node.getUserObject();

  if (clickedObject instanceof RawDataFile)
    dataFilePopupMenu.show(e.getComponent(), e.getX(), e.getY());
  if (clickedObject instanceof Scan)
    scanPopupMenu.show(e.getComponent(), e.getX(), e.getY());
  if (clickedObject instanceof MassList)
    massListPopupMenu.show(e.getComponent(), e.getX(), e.getY());
  if (clickedObject instanceof PeakList)
    peakListPopupMenu.show(e.getComponent(), e.getX(), e.getY());
  if (clickedObject instanceof PeakListRow)
    peakListRowPopupMenu.show(e.getComponent(), e.getX(), e.getY());
}
 
源代码5 项目: rapidminer-studio   文件: NewOperatorGroupTree.java
@Override
public void valueChanged(final String value) {
	TreePath[] selectionPaths = operatorGroupTree.getSelectionPaths();

	List<TreePath> expandedPaths = model.applyFilter(value);

	for (TreePath expandedPath : expandedPaths) {
		int row = this.operatorGroupTree.getRowForPath(expandedPath);
		this.operatorGroupTree.expandRow(row);
	}

	GroupTree root = (GroupTree) this.operatorGroupTree.getModel().getRoot();
	TreePath path = new TreePath(root);
	showNodes(root, path, expandedPaths);
	if (selectionPaths != null) {
		for (TreePath selectionPath : selectionPaths) {
			Object lastPathComponent = selectionPath.getLastPathComponent();
			if (model.contains(lastPathComponent)) {
				operatorGroupTree.addSelectionPath(selectionPath);
			}
		}
	}
}
 
源代码6 项目: consulo   文件: ScopeTreeViewPanel.java
@Nullable
private Module[] getSelectedModules() {
  final TreePath[] treePaths = myTree.getSelectionPaths();
  if (treePaths != null) {
    Set<Module> result = new HashSet<Module>();
    for (TreePath path : treePaths) {
      PackageDependenciesNode node = (PackageDependenciesNode)path.getLastPathComponent();
      if (node instanceof ModuleNode) {
        result.add(((ModuleNode)node).getModule());
      }
      else if (node instanceof ModuleGroupNode) {
        final ModuleGroupNode groupNode = (ModuleGroupNode)node;
        final ModuleGroup moduleGroup = groupNode.getModuleGroup();
        result.addAll(moduleGroup.modulesInGroup(myProject, true));
      }
    }
    return result.isEmpty() ? null : result.toArray(new Module[result.size()]);
  }
  return null;
}
 
源代码7 项目: java-swing-tips   文件: MainPanel.java
public static void searchTree(JTree tree, TreePath path, String q, List<TreePath> rollOverPathLists) {
  Object o = path.getLastPathComponent();
  if (o instanceof TreeNode) {
    TreeNode node = (TreeNode) o;
    if (node.toString().startsWith(q)) {
      rollOverPathLists.add(path);
      tree.expandPath(path.getParentPath());
    }
    if (!node.isLeaf()) {
      // Java 9: Collections.list(node.children())
      Collections.list((Enumeration<?>) node.children())
          .forEach(n -> searchTree(tree, path.pathByAddingChild(n), q, rollOverPathLists));
    }
  }
}
 
源代码8 项目: osp   文件: LaunchSaver.java
/**
 * Gets the selected node.
 *
 * @return the selected node
 */
public Node getSelectedNode() {
  TreePath path = tree.getSelectionPath();
  if(path==null) {
    return null;
  }
  return(Node) path.getLastPathComponent();
}
 
源代码9 项目: java-swing-tips   文件: MainPanel.java
public static void visitAll(JTree tree, TreePath parent, boolean expand) {
  TreeNode node = (TreeNode) parent.getLastPathComponent();
  if (!node.isLeaf()) {
    // Java 9: Collections.list(node.children())
    Collections.list((Enumeration<?>) node.children())
        .forEach(n -> visitAll(tree, parent.pathByAddingChild(n), expand));
  }
  if (expand) {
    tree.expandPath(parent);
  } else {
    tree.collapsePath(parent);
  }
}
 
@Override
public void mouseClicked(MouseEvent event) {
    JTree tree = (JTree)event.getSource();
    int x = event.getX();
    int y = event.getY();
    int row = tree.getRowForLocation(x, y);
    TreePath path = tree.getPathForRow(row);
    if (path != null) {
        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)path.getLastPathComponent();
        if (selectedNode != null && selectedNode.getChildCount() > 0 && event.getClickCount() > 1) {
            // if (tree.isExpanded(path)) {
            // tree.collapsePath(path);
            // }
            // else {
            // tree.expandPath(path);
            // }
            return;
        } else if (selectedNode instanceof CheckBoxTreeNode && event.getClickCount() == 1) {
            CheckBoxTreeNode node = (CheckBoxTreeNode)selectedNode;
            if (node != null) {
                boolean isSelected = !node.isSelected();
                node.setSelected(isSelected);
                ((DefaultTreeModel)tree.getModel()).nodeStructureChanged(node);
            }
        }
    }
}
 
源代码11 项目: consulo   文件: VisibleTreeState.java
public void setSelectionPaths(final TreePath[] selectionPaths) {
  mySelectedNodes.clear();
  if (selectionPaths != null) {
    for (TreePath selectionPath : selectionPaths) {
      final InspectionConfigTreeNode node = (InspectionConfigTreeNode)selectionPath.getLastPathComponent();
      mySelectedNodes.add(getState(node));
    }
  }
}
 
源代码12 项目: scelight   文件: XTree.java
@Override
public void collapsePathRecursive( final TreePath path ) {
	final TreeNode node = (TreeNode) path.getLastPathComponent();
	
	// Going downward is faster because collapsing needs to update row indices of rows that follow
	// and this way there are less rows to follow when collapsing a node
	for ( int i = node.getChildCount() - 1; i >= 0; i-- )
		collapsePathRecursive( path.pathByAddingChild( node.getChildAt( i ) ) );
	
	collapsePath( path );
}
 
/**
 * Preforms selected refactoring.
 */
private void refactorSelected() {
    TreePath selectedPath = treeTable.getTree().getSelectionPath();
    if (selectedPath != null && selectedPath.getPathCount() == refactorDepth) {
        AbstractCandidateRefactoring computationSlice = (AbstractCandidateRefactoring) selectedPath.getLastPathComponent();
        removeSelection();
        doRefactor(computationSlice);
    }
}
 
源代码14 项目: Spark   文件: JavaMixer.java
public Component getPrefferedInputVolume() {
    TreePath path = findByName(new TreePath(root), new String[]{"MICROPHONE", "Volume"});

    if (path == null) {
        path = findByName(new TreePath(root), new String[]{"Capture source", "Capture", "Volume"});
    }

    if (path != null) {
        if (path.getLastPathComponent() instanceof JavaMixer.ControlNode)
            return ((JavaMixer.ControlNode) path.getLastPathComponent()).getComponent();
    }
    return null;
}
 
源代码15 项目: ghidra   文件: CollapseAllArchivesAction.java
@Override
public void actionPerformed(ActionContext context) {
	// This actions does double duty.  When invoked from the icon, it closes all nodes.
	// When invoked from the popup, it only closes selected nodes.

	if (!(context instanceof DataTypesActionContext)) {
		collapseAll(plugin.getProvider().getGTree()); // on the toolbar or filter field--collapse all
	}

	DataTypesActionContext dataTypeContext = (DataTypesActionContext) context;
	if (dataTypeContext.isToolbarAction()) {
		collapseAll(plugin.getProvider().getGTree()); // on the toolbar or filter field--collapse all
	}
	else {
		DataTypeArchiveGTree gtree = (DataTypeArchiveGTree) context.getContextObject();
		TreePath[] selectionPaths = gtree.getSelectionPaths();
		if (selectionPaths == null || selectionPaths.length != 1) {
			// no paths selected; close all paths
			collapseAll(plugin.getProvider().getGTree());
		}

		if (selectionPaths != null) {
			for (TreePath path : selectionPaths) {
				GTreeNode node = (GTreeNode) path.getLastPathComponent();
				if (node instanceof ArchiveRootNode) { // if the root is selected collapseAll
					collapseAll(gtree);
					return;
				}
				gtree.collapseAll(node);
			}
		}
	}
}
 
源代码16 项目: consulo   文件: BaseStructureConfigurable.java
@Override
protected boolean isEnabled() {
  final TreePath selectionPath = myTree.getSelectionPath();
  if (selectionPath != null) {
    final MyNode node = (MyNode)selectionPath.getLastPathComponent();
    return !node.isDisplayInBold();
  }
  else {
    return false;
  }
}
 
源代码17 项目: spotbugs   文件: MainFrameTree.java
@SwingThread
boolean leavesShown() {
    JTree jTree = getTree();

    int rows = jTree.getRowCount();
    for (int i = 0; i < rows; i++) {
        TreePath treePath = jTree.getPathForRow(i);
        Object lastPathComponent = treePath.getLastPathComponent();
        if (lastPathComponent instanceof BugLeafNode) {
            return true;
        }
    }
    return false;
}
 
源代码18 项目: java-swing-tips   文件: MainPanel.java
@Override public boolean isCellEditable(EventObject e) {
  // return e instanceof MouseEvent;
  Object source = e.getSource();
  if (!(source instanceof JTree) || !(e instanceof MouseEvent)) {
    return false;
  }
  JTree tree = (JTree) source;
  Point p = ((MouseEvent) e).getPoint();
  TreePath path = tree.getPathForLocation(p.x, p.y);
  if (Objects.isNull(path)) {
    return false;
  }
  Rectangle r = tree.getPathBounds(path);
  if (Objects.isNull(r)) {
    return false;
  }
  // r.width = panel.getButtonAreaWidth();
  // return r.contains(p);
  if (r.contains(p)) {
    TreeNode node = (TreeNode) path.getLastPathComponent();
    int row = tree.getRowForLocation(p.x, p.y);
    TreeCellRenderer renderer = tree.getCellRenderer();
    Component c = renderer.getTreeCellRendererComponent(tree, " ", true, true, node.isLeaf(), row, true);
    c.setBounds(r);
    c.setLocation(0, 0);
    // tree.doLayout();
    tree.revalidate();
    p.translate(-r.x, -r.y);
    return SwingUtilities.getDeepestComponentAt(c, p.x, p.y) instanceof JButton;
  }
  return false;
}
 
/**
        * Unchecks the subtree with root path.
        * 
        * @param path root of the tree to be unchecked
        */
   public void uncheckSubTree(TreePath path) {
removeFromCheckedPathsSet(path);
removeFromGreyedPathsSet(path);
Object node = path.getLastPathComponent();
int childrenNumber = this.model.getChildCount(node);
for (int childIndex = 0; childIndex < childrenNumber; childIndex++) {
    TreePath childPath = path.pathByAddingChild(this.model.getChild(node, childIndex));
    uncheckSubTree(childPath);
}
   }
 
源代码20 项目: IntelliJDeodorant   文件: ExtractMethodPanel.java
/**
 * Opens the definition of appropriate method for the selected suggestion by double-clicking or Enter key pressing.
 */
private void openMethodDefinition(InputEvent e) {
    TreeTableTree treeTableTree = treeTable.getTree();
    TreePath selectedPath = treeTableTree.getSelectionModel().getSelectionPath();
    if (selectedPath != null) {
        Object o = selectedPath.getLastPathComponent();
        if (o instanceof ASTSlice) {
            openDefinition(((ASTSlice) o).getSourceMethodDeclaration(), scope, (ASTSlice) o);
        } else if (o instanceof ExtractMethodCandidateGroup) {
            expandOrCollapsePath(e, treeTableTree, selectedPath);
        }
    }
}