Search in sources :

Example 11 with TreeModel

use of javax.swing.tree.TreeModel in project intellij-community by JetBrains.

the class HierarchyBrowserBase method getAvailableElements.

public PsiElement[] getAvailableElements() {
    final JTree tree = getCurrentTree();
    if (tree == null) {
        return PsiElement.EMPTY_ARRAY;
    }
    final TreeModel model = tree.getModel();
    final Object root = model.getRoot();
    if (!(root instanceof DefaultMutableTreeNode)) {
        return PsiElement.EMPTY_ARRAY;
    }
    final DefaultMutableTreeNode node = (DefaultMutableTreeNode) root;
    final HierarchyNodeDescriptor descriptor = getDescriptor(node);
    final Set<PsiElement> result = new HashSet<>();
    collectElements(descriptor, result);
    return result.toArray(PsiElement.EMPTY_ARRAY);
}
Also used : TreeModel(javax.swing.tree.TreeModel) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) PsiElement(com.intellij.psi.PsiElement) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement) HashSet(java.util.HashSet)

Example 12 with TreeModel

use of javax.swing.tree.TreeModel in project jdk8u_jdk by JetBrains.

the class SynthTreeUI method paint.

/**
     * Paints the specified component.
     *
     * @param context context for the component being painted
     * @param g the {@code Graphics} object used for painting
     * @see #update(Graphics,JComponent)
     */
protected void paint(SynthContext context, Graphics g) {
    paintContext = context;
    updateLeadSelectionRow();
    Rectangle paintBounds = g.getClipBounds();
    Insets insets = tree.getInsets();
    TreePath initialPath = getClosestPathForLocation(tree, 0, paintBounds.y);
    Enumeration paintingEnumerator = treeState.getVisiblePathsFrom(initialPath);
    int row = treeState.getRowForPath(initialPath);
    int endY = paintBounds.y + paintBounds.height;
    TreeModel treeModel = tree.getModel();
    SynthContext cellContext = getContext(tree, Region.TREE_CELL);
    drawingCache.clear();
    setHashColor(context.getStyle().getColor(context, ColorType.FOREGROUND));
    if (paintingEnumerator != null) {
        // First pass, draw the rows
        boolean done = false;
        boolean isExpanded;
        boolean hasBeenExpanded;
        boolean isLeaf;
        Rectangle rowBounds = new Rectangle(0, 0, tree.getWidth(), 0);
        Rectangle bounds;
        TreePath path;
        TreeCellRenderer renderer = tree.getCellRenderer();
        DefaultTreeCellRenderer dtcr = (renderer instanceof DefaultTreeCellRenderer) ? (DefaultTreeCellRenderer) renderer : null;
        configureRenderer(cellContext);
        while (!done && paintingEnumerator.hasMoreElements()) {
            path = (TreePath) paintingEnumerator.nextElement();
            bounds = getPathBounds(tree, path);
            if ((path != null) && (bounds != null)) {
                isLeaf = treeModel.isLeaf(path.getLastPathComponent());
                if (isLeaf) {
                    isExpanded = hasBeenExpanded = false;
                } else {
                    isExpanded = treeState.getExpandedState(path);
                    hasBeenExpanded = tree.hasBeenExpanded(path);
                }
                rowBounds.y = bounds.y;
                rowBounds.height = bounds.height;
                paintRow(renderer, dtcr, context, cellContext, g, paintBounds, insets, bounds, rowBounds, path, row, isExpanded, hasBeenExpanded, isLeaf);
                if ((bounds.y + bounds.height) >= endY) {
                    done = true;
                }
            } else {
                done = true;
            }
            row++;
        }
        // Draw the connecting lines and controls.
        // Find each parent and have them draw a line to their last child
        boolean rootVisible = tree.isRootVisible();
        TreePath parentPath = initialPath;
        parentPath = parentPath.getParentPath();
        while (parentPath != null) {
            paintVerticalPartOfLeg(g, paintBounds, insets, parentPath);
            drawingCache.put(parentPath, Boolean.TRUE);
            parentPath = parentPath.getParentPath();
        }
        done = false;
        paintingEnumerator = treeState.getVisiblePathsFrom(initialPath);
        while (!done && paintingEnumerator.hasMoreElements()) {
            path = (TreePath) paintingEnumerator.nextElement();
            bounds = getPathBounds(tree, path);
            if ((path != null) && (bounds != null)) {
                isLeaf = treeModel.isLeaf(path.getLastPathComponent());
                if (isLeaf) {
                    isExpanded = hasBeenExpanded = false;
                } else {
                    isExpanded = treeState.getExpandedState(path);
                    hasBeenExpanded = tree.hasBeenExpanded(path);
                }
                // See if the vertical line to the parent has been drawn.
                parentPath = path.getParentPath();
                if (parentPath != null) {
                    if (drawingCache.get(parentPath) == null) {
                        paintVerticalPartOfLeg(g, paintBounds, insets, parentPath);
                        drawingCache.put(parentPath, Boolean.TRUE);
                    }
                    paintHorizontalPartOfLeg(g, paintBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf);
                } else if (rootVisible && row == 0) {
                    paintHorizontalPartOfLeg(g, paintBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf);
                }
                if (shouldPaintExpandControl(path, row, isExpanded, hasBeenExpanded, isLeaf)) {
                    paintExpandControl(g, paintBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf);
                }
                if ((bounds.y + bounds.height) >= endY) {
                    done = true;
                }
            } else {
                done = true;
            }
            row++;
        }
    }
    cellContext.dispose();
    paintDropLine(g);
    // Empty out the renderer pane, allowing renderers to be gc'ed.
    rendererPane.removeAll();
    paintContext = null;
}
Also used : TreeCellRenderer(javax.swing.tree.TreeCellRenderer) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) TreeModel(javax.swing.tree.TreeModel) Insets(java.awt.Insets) Enumeration(java.util.Enumeration) TreePath(javax.swing.tree.TreePath) Rectangle(java.awt.Rectangle) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer)

Example 13 with TreeModel

use of javax.swing.tree.TreeModel in project intellij-community by JetBrains.

the class CheckboxTreeHelper method setNodeState.

public void setNodeState(Tree tree, CheckedTreeNode node, boolean checked) {
    changeNodeState(node, checked);
    adjustParentsAndChildren(node, checked);
    tree.repaint();
    // notify model listeners about model change
    final TreeModel model = tree.getModel();
    model.valueForPathChanged(new TreePath(node.getPath()), node.getUserObject());
}
Also used : TreeModel(javax.swing.tree.TreeModel) TreePath(javax.swing.tree.TreePath)

Example 14 with TreeModel

use of javax.swing.tree.TreeModel in project intellij-community by JetBrains.

the class GradleProjectCompositeSelectorDialog method walkTree.

private void walkTree(Consumer<CheckedTreeNode> consumer) {
    final TreeModel treeModel = myTree.getModel();
    final Object root = treeModel.getRoot();
    if (!(root instanceof CheckedTreeNode))
        return;
    for (TreeNode node : TreeUtil.listChildren((CheckedTreeNode) root)) {
        if (!(node instanceof CheckedTreeNode))
            continue;
        consumer.consume(((CheckedTreeNode) node));
    }
}
Also used : TreeModel(javax.swing.tree.TreeModel) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreeNode(javax.swing.tree.TreeNode)

Example 15 with TreeModel

use of javax.swing.tree.TreeModel in project adempiere by adempiere.

the class DefaultTreeCheckingModel method setTreeModel.

/**
         * Sets the specified tree model. The current cheking is cleared.
         */
public void setTreeModel(TreeModel newModel) {
    TreeModel oldModel = this.model;
    if (oldModel != null) {
        oldModel.removeTreeModelListener(this.propagateCheckingListener);
    }
    this.model = newModel;
    if (newModel != null) {
        newModel.addTreeModelListener(this.propagateCheckingListener);
    }
    clearChecking();
}
Also used : TreeModel(javax.swing.tree.TreeModel)

Aggregations

TreeModel (javax.swing.tree.TreeModel)17 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)8 TreePath (javax.swing.tree.TreePath)4 Test (org.junit.Test)4 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)3 NavigatablePsiElement (com.intellij.psi.NavigatablePsiElement)1 PsiElement (com.intellij.psi.PsiElement)1 Insets (java.awt.Insets)1 Rectangle (java.awt.Rectangle)1 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 HashSet (java.util.HashSet)1 JLabel (javax.swing.JLabel)1 TreeModelEvent (javax.swing.event.TreeModelEvent)1 TreeModelListener (javax.swing.event.TreeModelListener)1 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)1 TreeSelectionListener (javax.swing.event.TreeSelectionListener)1 Element (javax.swing.text.Element)1 DefaultTreeCellRenderer (javax.swing.tree.DefaultTreeCellRenderer)1 TreeCellRenderer (javax.swing.tree.TreeCellRenderer)1