public Component getTreeCellRendererComponent( JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); if (value instanceof DefaultMutableTreeNode) { Object userObject = ((DefaultMutableTreeNode) value).getUserObject(); Icon icon = null; if (userObject instanceof Group) { Group group = (Group) userObject; String name = group.getName(); setText(name != null ? name : group.getId()); icon = group.getIcon(); if (icon == null) { icon = getClosedIcon(); } } else if (userObject instanceof String) { String actionId = (String) userObject; AnAction action = ActionManager.getInstance().getAction(actionId); String name = action != null ? action.getTemplatePresentation().getText() : null; setText(!StringUtil.isEmptyOrSpaces(name) ? name : actionId); if (action != null) { Icon actionIcon = action.getTemplatePresentation().getIcon(); if (actionIcon != null) { icon = actionIcon; } } } else if (userObject instanceof Pair) { String actionId = (String) ((Pair) userObject).first; AnAction action = ActionManager.getInstance().getAction(actionId); setText(action != null ? action.getTemplatePresentation().getText() : actionId); icon = (Icon) ((Pair) userObject).second; } else if (userObject instanceof Separator) { setText("-------------"); } else if (userObject instanceof QuickList) { setText(((QuickList) userObject).getDisplayName()); icon = AllIcons.Actions.QuickList; } else { throw new IllegalArgumentException("unknown userObject: " + userObject); } setIcon(ActionsTree.getEvenIcon(icon)); if (sel) { setForeground(UIUtil.getTreeSelectionForeground()); } else { setForeground(UIUtil.getTreeForeground()); } } return this; }
// Make sure that the text rendered by this method is 'searchable' via // com.intellij.openapi.keymap.impl.ui.ActionsTree.filter method. public void customizeCellRenderer( JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { final boolean showIcons = UISettings.getInstance().SHOW_ICONS_IN_MENUS; Keymap originalKeymap = myKeymap != null ? myKeymap.getParent() : null; Icon icon = null; String text; boolean bound = false; setToolTipText(null); if (value instanceof DefaultMutableTreeNode) { Object userObject = ((DefaultMutableTreeNode) value).getUserObject(); boolean changed; if (userObject instanceof Group) { Group group = (Group) userObject; text = group.getName(); changed = originalKeymap != null && isGroupChanged(group, originalKeymap, myKeymap); icon = group.getIcon(); if (icon == null) { icon = CLOSE_ICON; } } else if (userObject instanceof String) { String actionId = (String) userObject; bound = myShowBoundActions && ((KeymapImpl) myKeymap).isActionBound(actionId); AnAction action = ActionManager.getInstance().getAction(actionId); if (action != null) { text = action.getTemplatePresentation().getText(); if (text == null || text.length() == 0) { // fill dynamic presentation gaps text = actionId; } Icon actionIcon = action.getTemplatePresentation().getIcon(); if (actionIcon != null) { icon = actionIcon; } setToolTipText(action.getTemplatePresentation().getDescription()); } else { text = actionId; } changed = originalKeymap != null && isActionChanged(actionId, originalKeymap, myKeymap); } else if (userObject instanceof QuickList) { QuickList list = (QuickList) userObject; icon = AllIcons.Actions.QuickList; text = list.getDisplayName(); changed = originalKeymap != null && isActionChanged(list.getActionId(), originalKeymap, myKeymap); } else if (userObject instanceof Separator) { // TODO[vova,anton]: beautify changed = false; text = "-------------"; } else { throw new IllegalArgumentException("unknown userObject: " + userObject); } if (showIcons) { setIcon(ActionsTree.getEvenIcon(icon)); } Color foreground; if (selected) { foreground = UIUtil.getTreeSelectionForeground(); } else { if (changed) { foreground = PlatformColors.BLUE; } else { foreground = UIUtil.getTreeForeground(); } if (bound) { foreground = JBColor.MAGENTA; } } SearchUtil.appendFragments( myFilter, text, Font.PLAIN, foreground, selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground(), this); } }