in idea-plugin/src/main/java/com/jetbrains/ide/streamdeck/keymap/ActionsTree.java [84:172]
public ActionsTree() {
myRoot = new DefaultMutableTreeNode(ROOT);
myTree = new Tree(new MyModel(myRoot)) {
@Override
public void paint(Graphics g) {
super.paint(g);
Rectangle visibleRect = getVisibleRect();
Insets insets = getInsets();
if (insets != null && insets.right > 0) {
visibleRect.width -= JBUIScale.scale(9);
}
Rectangle clip = g.getClipBounds();
for (int row = 0; row < getRowCount(); row++) {
Rectangle rowBounds = getRowBounds(row);
rowBounds.x = 0;
rowBounds.width = Integer.MAX_VALUE;
if (rowBounds.intersects(clip)) {
Object node = getPathForRow(row).getLastPathComponent();
if (node instanceof DefaultMutableTreeNode) {
Object data = ((DefaultMutableTreeNode)node).getUserObject();
if (!(data instanceof Hyperlink)) {
Rectangle fullRowRect = new Rectangle(visibleRect.x, rowBounds.y, visibleRect.width, rowBounds.height);
paintRowData(this, data, fullRowRect, (Graphics2D)g);
}
}
}
}
}
@Override
public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
if (value instanceof DefaultMutableTreeNode) {
String path = ActionsTree.this.getPath((DefaultMutableTreeNode)value, true);
return StringUtil.notNullize(path);
}
return super.convertValueToText(value, selected, expanded, leaf, row, hasFocus);
}
};
myTree.setRootVisible(false);
myTree.setShowsRootHandles(true);
myTree.putClientProperty(WideSelectionTreeUI.STRIPED_CLIENT_PROPERTY, Boolean.TRUE);
myTree.setCellRenderer(new KeymapsRenderer());
new TreeLinkMouseListener(new KeymapsRenderer()) {
@Override
protected boolean doCacheLastNode() {
return false;
}
@Override
protected void handleTagClick(@Nullable Object tag, @NotNull MouseEvent event) {
if (tag instanceof Hyperlink) {
((Hyperlink)tag).onClick(event);
}
else {
super.handleTagClick(tag, event);
}
}
}.installOn(myTree);
myTree.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
String description = getDescription(e);
ActionMenu.showDescriptionInStatusBar(description != null, myTree, description);
}
@Nullable
@NlsActions.ActionDescription
private String getDescription(@NotNull MouseEvent e) {
TreePath path = myTree.getPathForLocation(e.getX(), e.getY());
DefaultMutableTreeNode node = path == null ? null : (DefaultMutableTreeNode)path.getLastPathComponent();
Object userObject = node == null ? null : node.getUserObject();
if (!(userObject instanceof String)) {
return null;
}
AnAction action = ActionManager.getInstance().getActionOrStub((String)userObject);
return action == null ? null : action.getTemplatePresentation().getDescription();
}
});
myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
myComponent = ScrollPaneFactory.createScrollPane(myTree,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
}