use of javax.swing.event.TreeExpansionEvent 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);
}
}
});
}
use of javax.swing.event.TreeExpansionEvent in project intellij-community by JetBrains.
the class UsageViewImpl method initTree.
private void initTree() {
ApplicationManager.getApplication().assertIsDispatchThread();
myTree.setShowsRootHandles(true);
SmartExpander.installOn(myTree);
TreeUtil.installActions(myTree);
EditSourceOnDoubleClickHandler.install(myTree);
myTree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (KeyEvent.VK_ENTER == e.getKeyCode()) {
TreePath leadSelectionPath = myTree.getLeadSelectionPath();
if (leadSelectionPath == null)
return;
DefaultMutableTreeNode node = (DefaultMutableTreeNode) leadSelectionPath.getLastPathComponent();
if (node instanceof UsageNode) {
final Usage usage = ((UsageNode) node).getUsage();
usage.navigate(false);
usage.highlightInEditor();
} else if (node.isLeaf()) {
Navigatable navigatable = getNavigatableForNode(node);
if (navigatable != null && navigatable.canNavigate()) {
navigatable.navigate(false);
}
}
}
}
});
TreeUtil.selectFirstNode(myTree);
PopupHandler.installPopupHandler(myTree, IdeActions.GROUP_USAGE_VIEW_POPUP, ActionPlaces.USAGE_VIEW_POPUP);
myTree.addTreeExpansionListener(new TreeExpansionListener() {
@Override
public void treeExpanded(TreeExpansionEvent event) {
clearRendererCache();
TreePath path = event.getPath();
Object component = path.getLastPathComponent();
if (component instanceof Node) {
Node node = (Node) component;
if (!expandingAll && node.needsUpdate()) {
checkNodeValidity(node, path);
}
}
}
@Override
public void treeCollapsed(TreeExpansionEvent event) {
clearRendererCache();
}
});
TreeUIHelper.getInstance().installTreeSpeedSearch(myTree, o -> {
Object value = o.getLastPathComponent();
TreeCellRenderer renderer = myTree.getCellRenderer();
if (renderer instanceof UsageViewTreeCellRenderer) {
UsageViewTreeCellRenderer coloredRenderer = (UsageViewTreeCellRenderer) renderer;
return coloredRenderer.getPlainTextForNode(value);
}
return value == null ? null : value.toString();
}, true);
}
use of javax.swing.event.TreeExpansionEvent in project CCDD by nasa.
the class CcddTableTreeHandler method createTreePanel.
/**
********************************************************************************************
* Create a table tree panel. The table tree is placed in a scroll pane. A check box is added
* that allows tree expansion/collapse
*
* @param label
* table tree title
*
* @param selectionMode
* tree item selection mode (single versus multiple)
*
* @param parent
* GUI component calling this method
*
* @return JPanel containing the table tree components
********************************************************************************************
*/
protected JPanel createTreePanel(String label, int selectionMode, final Component parent) {
// Create an empty border
Border emptyBorder = BorderFactory.createEmptyBorder();
// Set the initial layout manager characteristics
GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2, 0), 0, 0);
// Set the table tree selection mode
getSelectionModel().setSelectionMode(selectionMode);
// Create a panel to contain the table tree
JPanel treePnl = new JPanel(new GridBagLayout());
treePnl.setBorder(emptyBorder);
// Check if a label is provided
if (label != null && !label.isEmpty()) {
// Create the tree labels
JLabel treeLbl = new JLabel(label);
treeLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
treeLbl.setForeground(ModifiableColorInfo.SPECIAL_LABEL_TEXT.getColor());
treePnl.add(treeLbl, gbc);
gbc.gridy++;
}
// Create the tree scroll pane
JScrollPane treeScroll = new JScrollPane(this);
treeScroll.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED, Color.LIGHT_GRAY, Color.GRAY), BorderFactory.createEmptyBorder(ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing())));
// Add the tree to the panel
gbc.weighty = 1.0;
treePnl.add(treeScroll, gbc);
// Set the table tree font and number of rows to display
setFont(ModifiableFontInfo.TREE_NODE.getFont());
setVisibleRowCount(10);
// Add a listener for changes to the table tree
addTreeSelectionListener(new TreeSelectionListener() {
/**
************************************************************************************
* Handle a change to the table tree selection
************************************************************************************
*/
@Override
public void valueChanged(TreeSelectionEvent lse) {
// tree selection value changes that should not be processed
if (!isBuilding) {
// Update the groups based on the tables selected
updateTableSelection();
}
}
});
// Add a listener for table tree expand and collapse events
addTreeExpansionListener(new TreeExpansionListener() {
/**
************************************************************************************
* Handle an expansion of the table tree
************************************************************************************
*/
@Override
public void treeExpanded(TreeExpansionEvent tee) {
// Update the table selection based on the selected group
updateGroupSelection();
}
/**
************************************************************************************
* Handle a collapse of the table tree
************************************************************************************
*/
@Override
public void treeCollapsed(TreeExpansionEvent tee) {
// Update the table selection based on the selected group
updateGroupSelection();
}
});
// Create a tree expansion check box
expandChkBx = new JCheckBox("Expand all");
expandChkBx.setBorder(emptyBorder);
expandChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
expandChkBx.setSelected(false);
// Check if this is the last component to add
if (!showGroupFilter && !showTypeFilter && !addHiddenCheckBox) {
gbc.insets.bottom = 0;
}
gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
gbc.weighty = 0.0;
gbc.gridy++;
treePnl.add(expandChkBx, gbc);
// Create a listener for changes in selection of the tree expansion check box
expandChkBx.addActionListener(new ActionListener() {
/**
************************************************************************************
* Handle a change to the tree expansion check box selection
************************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
setTreeExpansion(expandChkBx.isSelected());
}
});
// Check if instance tables are displayed in the tree
if (treeType != TableTreeType.PROTOTYPE_TABLES) {
// Create a hide data type check box
final JCheckBox hideTypeChkBx = new JCheckBox("Hide data type");
hideTypeChkBx.setBorder(emptyBorder);
hideTypeChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
hideTypeChkBx.setSelected(false);
// Check if this is the last component to add
if (!showGroupFilter && !showTypeFilter && !addHiddenCheckBox) {
gbc.insets.bottom = 0;
}
gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
gbc.weighty = 0.0;
gbc.gridy++;
treePnl.add(hideTypeChkBx, gbc);
// Create a listener for changes in selection of the hide data type check box
hideTypeChkBx.addActionListener(new ActionListener() {
/**
********************************************************************************
* Handle a change to the hide data type check box selection
********************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
setEnableDataType(!hideTypeChkBx.isSelected());
// Store the tree's current expansion state
String expState = getExpansionState();
// Force the root node to draw with the node additions
((DefaultTreeModel) treeModel).nodeStructureChanged(root);
setExpansionState(expState);
}
});
}
// Create the filtering node prefix storage and check boxes
final List<String> prefixes = new ArrayList<String>();
final JCheckBox groupFilterChkBx = new JCheckBox("Filter by group");
final JCheckBox typeFilterChkBx = new JCheckBox("Filter by type");
// table/variable divisions (e.g., 'Prototype', 'Parents & Children')
for (int index = 0; index < root.getChildCount(); index++) {
// Add the child node name with its path to the prefix list
prefixes.add("[" + root.getUserObject() + ", " + ((ToolTipTreeNode) root.getChildAt(index)).getUserObject());
}
// Check if the group check box is valid for this tree type
if (showGroupFilter) {
// Create a group filter check box
groupFilterChkBx.setBorder(emptyBorder);
groupFilterChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
groupFilterChkBx.setSelected(false);
groupFilterChkBx.setEnabled(!groupHandler.getGroupInformation().isEmpty());
// Check if this is the last component to add
if (!showTypeFilter && !addHiddenCheckBox) {
gbc.insets.bottom = 0;
}
gbc.gridy++;
treePnl.add(groupFilterChkBx, gbc);
// Create a listener for changes in selection of the group filter check box
groupFilterChkBx.addActionListener(new ActionListener() {
/**
********************************************************************************
* Handle a change to the group filter check box selection
********************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// Set the filter by group flag based on the check box status
isByGroup = groupFilterChkBx.isSelected();
// Store the tree's current expansion state
String expState = getExpansionState();
// Rebuild the tree based on the filter selection
buildTableTree(expandChkBx.isSelected(), rateName, rateFilter, parent);
// Adjust the expansion state to account for the change in filtering, then
// restore the expansion state
expState = adjustExpansionState(expState, groupFilterChkBx.isSelected(), true, typeFilterChkBx.isSelected(), false, false, prefixes, groupHandler, tableTypeHandler);
setExpansionState(expState);
}
});
}
// Check if the type check box is valid for this tree type
if (showTypeFilter) {
// Create a type filter check box
typeFilterChkBx.setBorder(emptyBorder);
typeFilterChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
typeFilterChkBx.setSelected(false);
// Check if this is the last component to add
if (!addHiddenCheckBox) {
gbc.insets.bottom = 0;
}
gbc.gridy++;
treePnl.add(typeFilterChkBx, gbc);
// Create a listener for changes in selection of the type filter check box
typeFilterChkBx.addActionListener(new ActionListener() {
/**
********************************************************************************
* Handle a change to the type filter check box selection
********************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// Set the filter by type flag based on the check box status
isByType = typeFilterChkBx.isSelected();
// Store the tree's current expansion state
String expState = getExpansionState();
// Rebuild the tree based on the filter selection
buildTableTree(expandChkBx.isSelected(), rateName, rateFilter, parent);
// Adjust the expansion state to account for the change in filtering, then
// restore the expansion state
expState = adjustExpansionState(expState, groupFilterChkBx.isSelected(), false, typeFilterChkBx.isSelected(), true, false, prefixes, groupHandler, tableTypeHandler);
setExpansionState(expState);
}
});
}
// tree panel. Check if the flag is set to add this check box
if (addHiddenCheckBox) {
// Create the hidden check box. To prevent display of the check box components an empty
// panel is placed over it
JPanel hiddenPnl = new JPanel(new FlowLayout(FlowLayout.LEFT));
hiddenPnl.setBorder(emptyBorder);
JCheckBox hiddenChkBx = new JCheckBox(" ");
hiddenChkBx.setBorder(emptyBorder);
gbc.insets.bottom = 0;
gbc.gridy++;
treePnl.add(hiddenPnl, gbc);
hiddenChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
hiddenChkBx.setFocusable(false);
hiddenChkBx.setDisabledIcon(null);
hiddenChkBx.setEnabled(false);
treePnl.add(hiddenChkBx, gbc);
}
return treePnl;
}
use of javax.swing.event.TreeExpansionEvent in project cayenne by apache.
the class ProjectTreeView method initTreeExpandListener.
private void initTreeExpandListener() {
treeWillExpandListener = new TreeWillExpandListener() {
@Override
public void treeWillExpand(TreeExpansionEvent e) {
TreePath path = e.getPath();
if (!isPathSelected(path) && !isSelectionEmpty()) {
setSelectionPath(path);
}
}
@Override
public void treeWillCollapse(TreeExpansionEvent e) {
TreePath path = e.getPath();
if (!isPathSelected(path) && !isSelectionEmpty()) {
setSelectionPath(path);
}
}
};
addTreeWillExpandListener(treeWillExpandListener);
}
use of javax.swing.event.TreeExpansionEvent in project jadx by skylot.
the class QuarkReportPanel method buildTree.
private JTree buildTree() {
JTree tree = new JTree(treeRoot);
tree.setLayout(new BorderLayout());
tree.setBorder(BorderFactory.createEmptyBorder());
tree.setShowsRootHandles(false);
tree.setScrollsOnExpand(false);
tree.setSelectionModel(null);
tree.setCellRenderer(cellRenderer);
tree.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent event) {
if (SwingUtilities.isLeftMouseButton(event)) {
Object node = getNodeUnderMouse(tree, event);
if (node instanceof MethodTreeNode) {
JMethod method = ((MethodTreeNode) node).getJMethod();
BackgroundExecutor executor = tabbedPane.getMainWindow().getBackgroundExecutor();
executor.execute("Decompiling class", () -> tabbedPane.codeJump(method), // TODO: fix bug with incorrect jump on just decompiled code
status -> tabbedPane.codeJump(method));
}
}
}
});
tree.addTreeExpansionListener(new TreeExpansionListener() {
@Override
public void treeExpanded(TreeExpansionEvent event) {
TreePath path = event.getPath();
Object leaf = path.getLastPathComponent();
if (leaf instanceof CrimeTreeNode) {
CrimeTreeNode node = (CrimeTreeNode) leaf;
Enumeration<TreeNode> children = node.children();
while (children.hasMoreElements()) {
TreeNode child = children.nextElement();
tree.expandPath(path.pathByAddingChild(child));
}
}
}
@Override
public void treeCollapsed(TreeExpansionEvent event) {
}
});
return tree;
}
Aggregations