// =============================================================== // =============================================================== public Component getTreeCellRendererComponent( JTree tree, Object obj, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { super.getTreeCellRendererComponent(tree, obj, sel, expanded, leaf, row, hasFocus); setBackgroundNonSelectionColor(background); setForeground(Color.black); setBackgroundSelectionColor(Color.lightGray); if (row == 0) { // ROOT setFont(fonts[TITLE]); setIcon(tango_icon); } else { DefaultMutableTreeNode node = (DefaultMutableTreeNode) obj; if (node.getUserObject() instanceof PollThread) { setFont(fonts[THREAD]); setIcon(class_icon); } else { setFont(fonts[DEVICE]); setIcon(cmd_icon); } } return this; }
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; }