Java Code Examples for javax.swing.JTree#isExpanded()

The following examples show how to use javax.swing.JTree#isExpanded() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TreeExpansionUtil.java    From CQL with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 *
 *
 * @param tree
 * @param row
 *
 * @return
 */
public static String getExpansionState(JTree tree, int row) {
	TreePath rowPath = tree.getPathForRow(row);
	StringBuffer buf = new StringBuffer();
	int rowCount = tree.getRowCount();

	for (int i = row; i < rowCount; i++) {
		TreePath path = tree.getPathForRow(i);

		if ((i == row) || isDescendant(path, rowPath)) {
			if (tree.isExpanded(path)) {
				buf.append("," + String.valueOf(i - row));
			}
		} else {
			break;
		}
	}

	return buf.toString();
}
 
Example 2
Source File: IMContactDoubleClicker.java    From SmartIM with Apache License 2.0 6 votes vote down vote up
@Override
public void mouseClicked(MouseEvent e) {
    super.mouseClicked(e);
    JTree tree = (JTree)e.getSource();
    int selRow = tree.getRowForLocation(e.getX(), e.getY());
    TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
    if (selRow != -1 && selPath != null) {
        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)selPath.getLastPathComponent();
        if (selectedNode.getChildCount() > 0) {
            if (tree.isExpanded(selPath)) {
                tree.collapsePath(selPath);
            } else {
                tree.expandPath(selPath);
            }
            return;
        }
        if (imPanel != null && e.getClickCount() == 2) {
            imPanel.onDoubleClick(((DefaultMutableTreeNode)selectedNode).getUserObject());
        }
    }
}
 
Example 3
Source File: ViewTooltips.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Configures a tree cell renderer and sets up sizing and the 
 * backing image from it */
public boolean configure (Object nd, JScrollPane tv, JTree tree, TreePath path, int row) {
    boolean sameVn = setLastRendereredObject(nd);
    boolean sameComp = setLastRenderedScrollPane (tv);
    Component renderer = null;
    bg = tree.getBackground();
    boolean sel = tree.isSelectionEmpty() ? false :
        tree.getSelectionModel().isPathSelected(path);
    boolean exp = tree.isExpanded(path);
    boolean leaf = !exp && tree.getModel().isLeaf(nd);
    boolean lead = path.equals(tree.getSelectionModel().getLeadSelectionPath());
    renderer = tree.getCellRenderer().getTreeCellRendererComponent(tree, nd, sel, exp, leaf, row, lead);
    if (renderer != null) {
        setComponent (renderer, tree);
    }
    return true;
}
 
Example 4
Source File: RepositoryTreeUtil.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Saves the currently selected paths and saves all expanded repositories and nodes.
 *
 * @param tree
 *            The related tree, containing the path(s)
 */
public void saveExpansionState(JTree tree) {


	expandedNodes = new LinkedHashSet<>();
	selectedNodes = new LinkedHashSet<>();

	for (int i = 0; i < tree.getRowCount(); i++) {
		TreePath path = tree.getPathForRow(i);
		boolean isExpanded = tree.isExpanded(path);
		boolean isSelected = tree.isPathSelected(path);
		Object entryObject = path.getLastPathComponent();
		if ((isExpanded || isSelected) && entryObject instanceof Entry) {
			Entry entry = (Entry) entryObject;
			RepositoryLocation absoluteLocation = entry.getLocation();
			if (isExpanded) {
				expandedNodes.add(absoluteLocation);
			}
			if (isSelected) {
				selectedNodes.add(absoluteLocation);
			}
		}
	}

}
 
Example 5
Source File: TreeHelpers.java    From binnavi with Apache License 2.0 6 votes vote down vote up
public static String getExpansionState(final JTree tree, final int row) {
  final TreePath rowPath = tree.getPathForRow(row);
  final StringBuffer buf = new StringBuffer();
  final int rowCount = tree.getRowCount();

  for (int i = row; i < rowCount; i++) {
    final TreePath path = tree.getPathForRow(i);
    if ((i == row) || isDescendant(path, rowPath)) {
      if (tree.isExpanded(path)) {
        buf.append(",");
        buf.append(String.valueOf(i - row));
      }
    } else {
      break;
    }
  }
  return buf.toString();
}
 
Example 6
Source File: View.java    From jpexs-decompiler with GNU General Public License v3.0 6 votes vote down vote up
public static List<List<String>> getExpandedNodes(JTree tree) {
    List<List<String>> expandedNodes = new ArrayList<>();
    int rowCount = tree.getRowCount();
    for (int i = 0; i < rowCount; i++) {
        try {
            TreePath path = tree.getPathForRow(i);
            if (tree.isExpanded(path)) {
                List<String> pathAsStringList = new ArrayList<>();
                for (Object pathCompnent : path.getPath()) {
                    pathAsStringList.add(pathCompnent.toString());
                }
                expandedNodes.add(pathAsStringList);
            }
        } catch (IndexOutOfBoundsException | NullPointerException ex) {
            // TreeNode was removed, ignore
        }
    }
    return expandedNodes;
}
 
Example 7
Source File: StoredObjectsTreeModel.java    From swift-explorer with Apache License 2.0 5 votes vote down vote up
public static List<TreePath> getTreeExpansionState (JTree tree)
{
	if (tree == null)
		return null ;
	List<TreePath> ret = new ArrayList<TreePath> () ;
	for (int i = 0 ; i < tree.getRowCount() ; i++)
	{
		TreePath path = tree.getPathForRow(i) ;
		if (tree.isExpanded(path))
			ret.add (path) ;
	}
	return ret ;
}
 
Example 8
Source File: StoredObjectsTreeModel.java    From swift-explorer with Apache License 2.0 5 votes vote down vote up
public static void getTreeExpansionState (JTree tree, List<TreePath> list)
{
	if (list == null)
		return ;
	list.clear();
	if (tree == null)
		return ;
	for (int i = 0 ; i < tree.getRowCount() ; i++)
	{
		TreePath path = tree.getPathForRow(i) ;
		if (tree.isExpanded(path))
			list.add (path) ;
	}
}
 
Example 9
Source File: MainWindow.java    From jadx with Apache License 2.0 5 votes vote down vote up
public static void getExpandedPaths(JTree tree, TreePath path, List<TreePath> list) {
	if (tree.isExpanded(path)) {
		list.add(path);

		TreeNode node = (TreeNode) path.getLastPathComponent();
		for (int i = node.getChildCount() - 1; i >= 0; i--) {
			TreeNode n = node.getChildAt(i);
			TreePath child = path.pathByAddingChild(n);
			getExpandedPaths(tree, child, list);
		}
	}
}