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);
}
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;
}
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());
}
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));
}
}
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();
}
Aggregations