Search in sources :

Example 1 with TreeWillExpandListener

use of javax.swing.event.TreeWillExpandListener in project jadx by skylot.

the class MainWindow method initUI.

private void initUI() {
    mainPanel = new JPanel(new BorderLayout());
    JSplitPane splitPane = new JSplitPane();
    splitPane.setResizeWeight(SPLIT_PANE_RESIZE_WEIGHT);
    mainPanel.add(splitPane);
    DefaultMutableTreeNode treeRoot = new DefaultMutableTreeNode(NLS.str("msg.open_file"));
    treeModel = new DefaultTreeModel(treeRoot);
    tree = new JTree(treeModel);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            treeClickAction();
        }
    });
    tree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                treeClickAction();
            }
        }
    });
    tree.setCellRenderer(new DefaultTreeCellRenderer() {

        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean isLeaf, int row, boolean focused) {
            Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, isLeaf, row, focused);
            if (value instanceof JNode) {
                setIcon(((JNode) value).getIcon());
            }
            return c;
        }
    });
    tree.addTreeWillExpandListener(new TreeWillExpandListener() {

        @Override
        public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
            TreePath path = event.getPath();
            Object node = path.getLastPathComponent();
            if (node instanceof JClass) {
                JClass cls = (JClass) node;
                cls.getRootClass().load();
            }
        }

        @Override
        public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
        }
    });
    progressPane = new ProgressPanel(this, true);
    JPanel leftPane = new JPanel(new BorderLayout());
    leftPane.add(new JScrollPane(tree), BorderLayout.CENTER);
    leftPane.add(progressPane, BorderLayout.PAGE_END);
    splitPane.setLeftComponent(leftPane);
    tabbedPane = new TabbedPane(this);
    splitPane.setRightComponent(tabbedPane);
    dropTarget = new DropTarget(this, DnDConstants.ACTION_COPY, new MainDropTarget(this));
    setContentPane(mainPanel);
    setTitle(DEFAULT_TITLE);
}
Also used : JPanel(javax.swing.JPanel) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) KeyAdapter(java.awt.event.KeyAdapter) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) ExpandVetoException(javax.swing.tree.ExpandVetoException) KeyEvent(java.awt.event.KeyEvent) BorderLayout(java.awt.BorderLayout) JNode(jadx.gui.treemodel.JNode) Component(java.awt.Component) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent) TreeWillExpandListener(javax.swing.event.TreeWillExpandListener) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) JClass(jadx.gui.treemodel.JClass) MouseAdapter(java.awt.event.MouseAdapter) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) CacheObject(jadx.gui.utils.CacheObject) DropTarget(java.awt.dnd.DropTarget) JSplitPane(javax.swing.JSplitPane)

Example 2 with TreeWillExpandListener

use of javax.swing.event.TreeWillExpandListener in project intellij-plugins by JetBrains.

the class DartConfigurable method createUIComponents.

private void createUIComponents() {
    mySdkPathComboWithBrowse = new ComboboxWithBrowseButton(new ComboBox<>());
    myDartiumPathComboWithBrowse = new ComboboxWithBrowseButton(new ComboBox<>());
    final CheckboxTree.CheckboxTreeCellRenderer checkboxTreeCellRenderer = new CheckboxTree.CheckboxTreeCellRenderer() {

        @Override
        public void customizeRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            if (!(value instanceof CheckedTreeNode))
                return;
            final boolean dartSupportEnabled = myEnableDartSupportCheckBox.isSelected();
            final CheckedTreeNode node = (CheckedTreeNode) value;
            final Object userObject = node.getUserObject();
            if (userObject instanceof Project) {
                if (!dartSupportEnabled) {
                    //disabled state is also used as partially selected, that's why we do not change 'enabled' state if dartSupportEnabled
                    getCheckbox().setEnabled(false);
                }
                getTextRenderer().setEnabled(dartSupportEnabled);
                getTextRenderer().append(DartBundle.message("project.0", ((Project) userObject).getName()));
            } else if (userObject instanceof Module) {
                getCheckbox().setEnabled(dartSupportEnabled);
                getTextRenderer().setEnabled(dartSupportEnabled);
                final Icon moduleIcon = ModuleType.get((Module) userObject).getIcon();
                getTextRenderer().setIcon(dartSupportEnabled ? moduleIcon : IconLoader.getDisabledIcon(moduleIcon));
                getTextRenderer().append(((Module) userObject).getName());
            }
        }
    };
    myModulesCheckboxTreeTable = new CheckboxTreeTable(null, checkboxTreeCellRenderer, new ColumnInfo[] { new TreeColumnInfo("") });
    myModulesCheckboxTreeTable.addCheckboxTreeListener(new CheckboxTreeAdapter() {

        @Override
        public void nodeStateChanged(@NotNull CheckedTreeNode node) {
            updateErrorLabel();
        }
    });
    //myModulesCheckboxTreeTable.setRowHeight(myModulesCheckboxTreeTable.getRowHeight() + 2);
    myModulesCheckboxTreeTable.getTree().addTreeWillExpandListener(new TreeWillExpandListener() {

        public void treeWillExpand(final TreeExpansionEvent event) throws ExpandVetoException {
        }

        public void treeWillCollapse(final TreeExpansionEvent event) throws ExpandVetoException {
            throw new ExpandVetoException(event);
        }
    });
}
Also used : TreeWillExpandListener(javax.swing.event.TreeWillExpandListener) ComboBox(com.intellij.openapi.ui.ComboBox) ColumnInfo(com.intellij.util.ui.ColumnInfo) TreeColumnInfo(com.intellij.ui.treeStructure.treetable.TreeColumnInfo) ExpandVetoException(javax.swing.tree.ExpandVetoException) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent) TreeColumnInfo(com.intellij.ui.treeStructure.treetable.TreeColumnInfo)

Example 3 with TreeWillExpandListener

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

the class SmartExpander method installOn.

public static void installOn(final JTree tree) {
    tree.addTreeWillExpandListener(new TreeWillExpandListener() {

        @Override
        public void treeWillCollapse(TreeExpansionEvent event) {
            TreePath path = event.getPath();
            Enumeration children = ((TreeNode) path.getLastPathComponent()).children();
            while (children.hasMoreElements()) {
                TreePath childPath = path.pathByAddingChild(children.nextElement());
                if (tree.isExpanded(childPath)) {
                    tree.collapsePath(childPath);
                }
            }
        }

        @Override
        public void treeWillExpand(TreeExpansionEvent event) {
        }
    });
    tree.addTreeExpansionListener(new TreeExpansionListener() {

        @Override
        public void treeCollapsed(TreeExpansionEvent event) {
        }

        @Override
        public void treeExpanded(TreeExpansionEvent event) {
            TreePath path = event.getPath();
            TreeNode lastPathComponent = (TreeNode) path.getLastPathComponent();
            if (lastPathComponent.getChildCount() == 1) {
                TreePath firstChildPath = path.pathByAddingChild(lastPathComponent.getChildAt(0));
                tree.expandPath(firstChildPath);
            }
        }
    });
}
Also used : TreeWillExpandListener(javax.swing.event.TreeWillExpandListener) TreeExpansionListener(javax.swing.event.TreeExpansionListener) Enumeration(java.util.Enumeration) TreePath(javax.swing.tree.TreePath) TreeNode(javax.swing.tree.TreeNode) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent)

Example 4 with TreeWillExpandListener

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

the class SlicePanel method createTree.

@NotNull
private JTree createTree() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    final Tree tree = new Tree(new DefaultTreeModel(root));
    tree.setOpaque(false);
    tree.setToggleClickCount(-1);
    SliceUsageCellRendererBase renderer = myProvider.getRenderer();
    renderer.setOpaque(false);
    tree.setCellRenderer(renderer);
    UIUtil.setLineStyleAngled(tree);
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setSelectionPath(new TreePath(root.getPath()));
    //ActionGroup group = (ActionGroup)ActionManager.getInstance().getAction(IdeActions.GROUP_METHOD_HIERARCHY_POPUP);
    //PopupHandler.installPopupHandler(tree, group, ActionPlaces.METHOD_HIERARCHY_VIEW_POPUP, ActionManager.getInstance());
    EditSourceOnDoubleClickHandler.install(tree);
    new TreeSpeedSearch(tree);
    TreeUtil.installActions(tree);
    ToolTipManager.sharedInstance().registerComponent(tree);
    myAutoScrollToSourceHandler.install(tree);
    tree.getSelectionModel().addTreeSelectionListener(e -> treeSelectionChanged());
    tree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (KeyEvent.VK_ENTER == e.getKeyCode()) {
                List<Navigatable> navigatables = getNavigatables();
                if (navigatables.isEmpty())
                    return;
                for (Navigatable navigatable : navigatables) {
                    if (navigatable instanceof AbstractTreeNode && ((AbstractTreeNode) navigatable).getValue() instanceof Usage) {
                        navigatable = (Usage) ((AbstractTreeNode) navigatable).getValue();
                    }
                    if (navigatable.canNavigateToSource()) {
                        navigatable.navigate(false);
                        if (navigatable instanceof Usage) {
                            ((Usage) navigatable).highlightInEditor();
                        }
                    }
                }
                e.consume();
            }
        }
    });
    tree.addTreeWillExpandListener(new TreeWillExpandListener() {

        @Override
        public void treeWillCollapse(TreeExpansionEvent event) {
        }

        @Override
        public void treeWillExpand(TreeExpansionEvent event) {
            TreePath path = event.getPath();
            SliceNode node = fromPath(path);
            node.calculateDupNode();
        }
    });
    return tree;
}
Also used : TreeWillExpandListener(javax.swing.event.TreeWillExpandListener) Usage(com.intellij.usages.Usage) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) KeyAdapter(java.awt.event.KeyAdapter) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) Navigatable(com.intellij.pom.Navigatable) KeyEvent(java.awt.event.KeyEvent) TreePath(javax.swing.tree.TreePath) Tree(com.intellij.ui.treeStructure.Tree) ArrayList(java.util.ArrayList) List(java.util.List) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

TreeExpansionEvent (javax.swing.event.TreeExpansionEvent)4 TreeWillExpandListener (javax.swing.event.TreeWillExpandListener)4 TreePath (javax.swing.tree.TreePath)3 KeyAdapter (java.awt.event.KeyAdapter)2 KeyEvent (java.awt.event.KeyEvent)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)2 ExpandVetoException (javax.swing.tree.ExpandVetoException)2 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 ComboBox (com.intellij.openapi.ui.ComboBox)1 Navigatable (com.intellij.pom.Navigatable)1 Tree (com.intellij.ui.treeStructure.Tree)1 TreeColumnInfo (com.intellij.ui.treeStructure.treetable.TreeColumnInfo)1 Usage (com.intellij.usages.Usage)1 ColumnInfo (com.intellij.util.ui.ColumnInfo)1 JClass (jadx.gui.treemodel.JClass)1 JNode (jadx.gui.treemodel.JNode)1 CacheObject (jadx.gui.utils.CacheObject)1