// ===============================================================
    // ===============================================================
    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;
    }
Beispiel #2
0
    /**
     * updateUI is overridden to set the colors of the Tree's renderer to match that of the table.
     */
    public void updateUI() {
      super.updateUI();

      // Make the tree's cell renderer use the table's cell selection
      // colors.
      TreeCellRenderer tcr = getCellRenderer();

      if (tcr instanceof DefaultTreeCellRenderer) {
        DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
        // For 1.1 uncomment this, 1.2 has a bug that will cause an
        // exception to be thrown if the border selection color is
        // null.
        // dtcr.setBorderSelectionColor(null);
        dtcr.setTextSelectionColor(UIManager.getColor("Table.selectionForeground"));
        dtcr.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground"));
      }
    }
    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;
    }
Beispiel #4
0
 @Override
 protected void paintComponent(Graphics g) {
   GuiUtil.makeTextLookLessRubbish(g);
   super.paintComponent(g);
 }