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