Example usage for javax.swing.event TreeModelEvent getTreePath

List of usage examples for javax.swing.event TreeModelEvent getTreePath

Introduction

In this page you can find the example usage for javax.swing.event TreeModelEvent getTreePath.

Prototype

public TreePath getTreePath() 

Source Link

Document

For all events, except treeStructureChanged, returns the parent of the changed nodes.

Usage

From source file:org.languagetool.gui.ConfigurationDialog.java

@NotNull
private DefaultTreeModel getTreeModel(DefaultMutableTreeNode rootNode) {
    DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);
    treeModel.addTreeModelListener(new TreeModelListener() {
        @Override/*from   www  . ja v  a  2s .c o m*/
        public void treeNodesChanged(TreeModelEvent e) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getTreePath().getLastPathComponent();
            int index = e.getChildIndices()[0];
            node = (DefaultMutableTreeNode) node.getChildAt(index);
            if (node instanceof RuleNode) {
                RuleNode o = (RuleNode) node;
                if (o.getRule().isDefaultOff() || o.getRule().getCategory().isDefaultOff()) {
                    if (o.isEnabled()) {
                        config.getEnabledRuleIds().add(o.getRule().getId());
                        config.getDisabledRuleIds().remove(o.getRule().getId());
                    } else {
                        config.getEnabledRuleIds().remove(o.getRule().getId());
                        config.getDisabledRuleIds().add(o.getRule().getId());
                    }
                } else {
                    if (o.isEnabled()) {
                        config.getDisabledRuleIds().remove(o.getRule().getId());
                    } else {
                        config.getDisabledRuleIds().add(o.getRule().getId());
                    }
                }
            }
            if (node instanceof CategoryNode) {
                CategoryNode o = (CategoryNode) node;
                if (o.getCategory().isDefaultOff()) {
                    if (o.isEnabled()) {
                        config.getDisabledCategoryNames().remove(o.getCategory().getName());
                        config.getEnabledCategoryNames().add(o.getCategory().getName());
                    } else {
                        config.getDisabledCategoryNames().add(o.getCategory().getName());
                        config.getEnabledCategoryNames().remove(o.getCategory().getName());
                    }
                } else {
                    if (o.isEnabled()) {
                        config.getDisabledCategoryNames().remove(o.getCategory().getName());
                    } else {
                        config.getDisabledCategoryNames().add(o.getCategory().getName());
                    }
                }
            }
        }

        @Override
        public void treeNodesInserted(TreeModelEvent e) {
        }

        @Override
        public void treeNodesRemoved(TreeModelEvent e) {
        }

        @Override
        public void treeStructureChanged(TreeModelEvent e) {
        }
    });
    return treeModel;
}

From source file:org.trianacode.gui.hci.ApplicationFrame.java

public void treeNodesInserted(TreeModelEvent event) {
    TreePath path = event.getTreePath();
    if (path.getPathCount() >= 2) {
        toolboxTree.scrollPathToVisible(event.getTreePath());
        toolboxTree.getModel().removeTreeModelListener(this);
    }//from www  .  j ava2 s.co m
}