Search in sources :

Example 1 with TreeModelListener

use of javax.swing.event.TreeModelListener in project languagetool by languagetool-org.

the class ConfigurationDialog method getTreeModel.

@NotNull
private DefaultTreeModel getTreeModel(DefaultMutableTreeNode rootNode) {
    DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);
    treeModel.addTreeModelListener(new TreeModelListener() {

        @Override
        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.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;
}
Also used : TreeModelEvent(javax.swing.event.TreeModelEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeModelListener(javax.swing.event.TreeModelListener) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with TreeModelListener

use of javax.swing.event.TreeModelListener in project pcgen by PCGen.

the class EquipmentTreeTableModel method fireTreeNodesRemoved.

/**
	 * Notifies all listeners that have registered interest for
	 * notification on this event type.  The event instance
	 * is lazily created using the parameters passed into
	 * the fire method.
	 *
	 * @param source the node where elements are being removed
	 * @param path the path to the root node
	 * @param childIndices the indices of the removed elements
	 * @param children the removed elements
	 * @see EventListenerList
	 */
protected void fireTreeNodesRemoved(Object source, Object[] path, int[] childIndices, Object[] children) {
    // Guaranteed to return a non-null array
    Object[] listeners = listenerList.getListenerList();
    TreeModelEvent e = null;
    // those that are interested in this event
    for (int i = listeners.length - 2; i >= 0; i -= 2) {
        if (listeners[i] == TreeModelListener.class) {
            // Lazily create the event:
            if (e == null) {
                e = new TreeModelEvent(source, path, childIndices, children);
            }
            ((TreeModelListener) listeners[i + 1]).treeNodesRemoved(e);
        }
    }
}
Also used : TreeModelEvent(javax.swing.event.TreeModelEvent) TreeModelListener(javax.swing.event.TreeModelListener)

Example 3 with TreeModelListener

use of javax.swing.event.TreeModelListener in project pcgen by PCGen.

the class NotesView method initTree.

//Initialization methods
private void initTree() {
    dataDir.listFiles();
    root = new NotesTreeNode(dataDir.getName(), dataDir, notesTree);
    TreeModel model = new DefaultTreeModel(root);
    notesTree.setModel(model);
    notesTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent evt) {
            notesTreeActionPerformed();
        }
    });
    notesTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    notesTree.setEditable(true);
    model.addTreeModelListener(new TreeModelListener() {

        @Override
        public void treeNodesChanged(TreeModelEvent e) {
            notesTreeNodesChanged();
        }

        @Override
        public void treeNodesInserted(TreeModelEvent e) {
        // TODO:  Method does nothing?
        }

        @Override
        public void treeNodesRemoved(TreeModelEvent e) {
        // TODO:  Method does nothing?
        }

        @Override
        public void treeStructureChanged(TreeModelEvent e) {
        // TODO:  Method does nothing?
        }
    });
}
Also used : TreeModel(javax.swing.tree.TreeModel) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreeModelEvent(javax.swing.event.TreeModelEvent) TreeModelListener(javax.swing.event.TreeModelListener) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 4 with TreeModelListener

use of javax.swing.event.TreeModelListener in project intellij-community by JetBrains.

the class AbstractProjectViewPSIPane method initTree.

private void initTree() {
    myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    UIUtil.setLineStyleAngled(myTree);
    myTree.setRootVisible(false);
    myTree.setShowsRootHandles(true);
    myTree.expandPath(new TreePath(myTree.getModel().getRoot()));
    myTree.setSelectionPath(new TreePath(myTree.getModel().getRoot()));
    EditSourceOnDoubleClickHandler.install(myTree);
    ToolTipManager.sharedInstance().registerComponent(myTree);
    TreeUtil.installActions(myTree);
    myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            fireTreeChangeListener();
        }
    });
    myTree.getModel().addTreeModelListener(new TreeModelListener() {

        @Override
        public void treeNodesChanged(TreeModelEvent e) {
            fireTreeChangeListener();
        }

        @Override
        public void treeNodesInserted(TreeModelEvent e) {
            fireTreeChangeListener();
        }

        @Override
        public void treeNodesRemoved(TreeModelEvent e) {
            fireTreeChangeListener();
        }

        @Override
        public void treeStructureChanged(TreeModelEvent e) {
            fireTreeChangeListener();
        }
    });
    new MySpeedSearch(myTree);
    myTree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (KeyEvent.VK_ENTER == e.getKeyCode()) {
                final DefaultMutableTreeNode selectedNode = ((ProjectViewTree) myTree).getSelectedNode();
                if (selectedNode != null && !selectedNode.isLeaf()) {
                    return;
                }
                DataContext dataContext = DataManager.getInstance().getDataContext(myTree);
                OpenSourceUtil.openSourcesFrom(dataContext, ScreenReader.isActive());
            } else if (KeyEvent.VK_ESCAPE == e.getKeyCode()) {
                if (e.isConsumed())
                    return;
                PsiCopyPasteManager copyPasteManager = PsiCopyPasteManager.getInstance();
                boolean[] isCopied = new boolean[1];
                if (copyPasteManager.getElements(isCopied) != null && !isCopied[0]) {
                    copyPasteManager.clear();
                    e.consume();
                }
            }
        }
    });
    CustomizationUtil.installPopupHandler(myTree, IdeActions.GROUP_PROJECT_VIEW_POPUP, ActionPlaces.PROJECT_VIEW_POPUP);
}
Also used : TreeModelEvent(javax.swing.event.TreeModelEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeModelListener(javax.swing.event.TreeModelListener) KeyAdapter(java.awt.event.KeyAdapter) PsiCopyPasteManager(com.intellij.ide.PsiCopyPasteManager) TreeSelectionListener(javax.swing.event.TreeSelectionListener) KeyEvent(java.awt.event.KeyEvent) DataContext(com.intellij.openapi.actionSystem.DataContext) TreePath(javax.swing.tree.TreePath) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 5 with TreeModelListener

use of javax.swing.event.TreeModelListener in project cytoscape-api by cytoscape.

the class AbstractTreeTableModel method fireTreeStructureChanged.

/**
	 * Notify all listeners that have registered interest for
	 * notification on this event type.  The event instance
	 * is lazily created using the parameters passed into
	 * the fire method.
	 * @see EventListenerList
	 */
protected void fireTreeStructureChanged(Object source, Object[] path, int[] childIndices, Object[] children) {
    // Guaranteed to return a non-null array
    Object[] listeners = listenerList.getListenerList();
    TreeModelEvent e = null;
    // those that are interested in this event
    for (int i = listeners.length - 2; i >= 0; i -= 2) {
        if (listeners[i] == TreeModelListener.class) {
            // Lazily create the event:
            if (e == null)
                e = new TreeModelEvent(source, path, childIndices, children);
            ((TreeModelListener) listeners[i + 1]).treeStructureChanged(e);
        }
    }
}
Also used : TreeModelEvent(javax.swing.event.TreeModelEvent) TreeModelListener(javax.swing.event.TreeModelListener)

Aggregations

TreeModelEvent (javax.swing.event.TreeModelEvent)17 TreeModelListener (javax.swing.event.TreeModelListener)17 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)2 TreeSelectionListener (javax.swing.event.TreeSelectionListener)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)2 PsiCopyPasteManager (com.intellij.ide.PsiCopyPasteManager)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 KeyAdapter (java.awt.event.KeyAdapter)1 KeyEvent (java.awt.event.KeyEvent)1 TreeModel (javax.swing.tree.TreeModel)1 TreePath (javax.swing.tree.TreePath)1 NotNull (org.jetbrains.annotations.NotNull)1