Java Code Examples for com.intellij.util.ui.UIUtil#getTreeSelectionForeground()

The following examples show how to use com.intellij.util.ui.UIUtil#getTreeSelectionForeground() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TemplateTreeRenderer.java    From idea-gitignore with MIT License 5 votes vote down vote up
/**
 * Renders checkbox tree cell filled with @{link TemplateTreeNode} data.
 *
 * @param tree     current working tree
 * @param value    template data
 * @param selected node is selected
 * @param expanded node is expanded
 * @param leaf     node is a leaf
 * @param row      node is a row
 * @param hasFocus node has focus
 */
public void customizeRenderer(final JTree tree, final Object value, final boolean selected, final boolean expanded,
                              final boolean leaf, final int row, final boolean hasFocus) {
    if (!(value instanceof TemplateTreeNode)) {
        return;
    }
    TemplateTreeNode node = (TemplateTreeNode) value;

    final Color background = selected ? UIUtil.getTreeSelectionBackground(true) : UIUtil.getTreeBackground();
    UIUtil.changeBackGround(this, background);
    Color foreground = selected ? UIUtil.getTreeSelectionForeground(true) : node.getTemplate() == null ?
            PlatformColors.BLUE : UIUtil.getTreeForeground();
    int style = SimpleTextAttributes.STYLE_PLAIN;

    String text = "", hint = "";
    if (node.getTemplate() != null) { // template leaf
        text = node.getTemplate().getName();
    } else if (node.getContainer() != null) { // container group
        hint = IgnoreBundle.message("template.container." + node.getContainer().toString().toLowerCase());
        getCheckbox().setVisible(false);
    }

    SearchUtil.appendFragments(getFilter(), text, style, foreground, background, getTextRenderer());
    getTextRenderer().append(hint, selected
            ? new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, foreground)
            : SimpleTextAttributes.GRAYED_ATTRIBUTES
    );
    setForeground(foreground);
}
 
Example 2
Source File: ColoredTreeCellRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * When the item is selected then we use default tree's selection foreground.
 * It guaranties readability of selected text in any LAF.
 */
@Override
public void append(@Nonnull @Nls String fragment, @Nonnull SimpleTextAttributes attributes, boolean isMainText) {
  if (mySelected && isFocused()) {
    super.append(fragment, new SimpleTextAttributes(attributes.getStyle(), UIUtil.getTreeSelectionForeground()), isMainText);
  }
  else if (mySelected && UIUtil.isUnderAquaBasedLookAndFeel()) {
    super.append(fragment, new SimpleTextAttributes(attributes.getStyle(), UIUtil.getTreeForeground()), isMainText);
  }
  else {
    super.append(fragment, attributes, isMainText);
  }
}
 
Example 3
Source File: JBDefaultTreeCellRenderer.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected Color getSelectionForeground(@Nonnull final JTree tree) {
  return myMacTreeUI && !tree.hasFocus() ? UIUtil.getTreeForeground() : UIUtil.getTreeSelectionForeground();
}
 
Example 4
Source File: GroupedElementsRenderer.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected Color getSelectionForeground() {
  return UIUtil.getTreeSelectionForeground();
}
 
Example 5
Source File: ActionsTree.java    From consulo with Apache License 2.0 4 votes vote down vote up
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;

  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().getActionOrStub(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;
        }
      }
      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 AnSeparator) {
      // 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 = JBColor.BLUE;
      }
      else {
        foreground = UIUtil.getTreeForeground();
      }

      if (bound) {
        foreground = JBColor.MAGENTA;
      }
    }
    SearchUtil.appendFragments(myFilter, text, Font.PLAIN, foreground,
                               selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground(), this);
  }
}
 
Example 6
Source File: MultilineTreeCellRenderer.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void paint(Graphics g) {
  int height = getHeight();
  int width = getWidth();
  int borderX = myLabelInsets.left - 1;
  int borderY = myLabelInsets.top - 1;
  int borderW = width - borderX - myLabelInsets.right + 2;
  int borderH = height - borderY - myLabelInsets.bottom + 1;

  if (myIcon != null) {
    int verticalIconPosition = (height - myIcon.getIconHeight())/2;
    myIcon.paintIcon(this, g, 0, verticalIconPosition);
    borderX += myIcon.getIconWidth();
    borderW -= myIcon.getIconWidth();
  }

  Color bgColor;
  Color fgColor;
  if (mySelected && myHasFocus){
    bgColor = UIUtil.getTreeSelectionBackground();
    fgColor = UIUtil.getTreeSelectionForeground();
  }
  else{
    bgColor = UIUtil.getTreeTextBackground();
    fgColor = getForeground();
  }

  // fill background
  if (!(myTree.getUI() instanceof WideSelectionTreeUI) || !((WideSelectionTreeUI)myTree.getUI()).isWideSelection()) {
    g.setColor(bgColor);
    g.fillRect(borderX, borderY, borderW, borderH);

    // draw border
    if (mySelected) {
      g.setColor(UIUtil.getTreeSelectionBorderColor());
      UIUtil.drawDottedRectangle(g, borderX, borderY, borderX + borderW - 1, borderY + borderH - 1);
    }
  }

  // paint text
  recalculateWraps();

  if (myTooSmall) { // TODO ???
    return;
  }

  int fontHeight = getCurrFontMetrics().getHeight();
  int currBaseLine = getCurrFontMetrics().getAscent();
  currBaseLine += myTextInsets.top;
  g.setFont(getFont());
  g.setColor(fgColor);
  UISettings.setupAntialiasing(g);

  if (!StringUtil.isEmpty(myPrefix)) {
    g.drawString(myPrefix, myTextInsets.left - myPrefixWidth + 1, currBaseLine);
  }

  for (int i = 0; i < myWraps.size(); i++) {
    String currLine = (String)myWraps.get(i);
    g.drawString(currLine, myTextInsets.left, currBaseLine);
    currBaseLine += fontHeight;  // first is getCurrFontMetrics().getAscent()
  }
}
 
Example 7
Source File: UiInspectorAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@RequiredUIAccess
@Override
public void customizeCellRenderer(@Nonnull JTree tree,
                                  Object value,
                                  boolean selected,
                                  boolean expanded,
                                  boolean leaf,
                                  int row,
                                  boolean hasFocus) {
  Color foreground = selected ? UIUtil.getTreeSelectionForeground() : UIUtil.getTreeForeground();
  Color background = selected ? UIUtil.getTreeSelectionBackground() : null;
  if (value instanceof HierarchyTree.ComponentNode) {
    HierarchyTree.ComponentNode componentNode = (HierarchyTree.ComponentNode)value;
    Component component = componentNode.getComponent();

    if (!selected) {
      if (!component.isVisible()) {
        foreground = JBColor.GRAY;
      }
      else if (component.getWidth() == 0 || component.getHeight() == 0) {
        foreground = new JBColor(new Color(128, 10, 0), JBColor.BLUE);
      }
      else if (component.getPreferredSize() != null &&
               (component.getSize().width < component.getPreferredSize().width
                || component.getSize().height < component.getPreferredSize().height)) {
        foreground = JBColor.BLUE;
      }

      if (myInitialSelection == componentNode.getComponent()) {
        background = new Color(31, 128, 8, 58);
      }
    }
    append(getComponentName(component));
    append(": " + RectangleRenderer.toString(component.getBounds()), SimpleTextAttributes.GRAYED_ATTRIBUTES);
    if (component.isOpaque()) {
      append(", opaque", SimpleTextAttributes.GRAYED_ATTRIBUTES);
    }
    if (component.isDoubleBuffered()) {
      append(", double-buffered", SimpleTextAttributes.GRAYED_ATTRIBUTES);
    }
    componentNode.setText(toString());
    setIcon(createColorIcon(component.getForeground(), component.getBackground()));
  }
  if (value instanceof HierarchyTree.ClickInfoNode) {
    append(value.toString());
    setIcon(AllIcons.Ide.Rating);
  }

  setForeground(foreground);
  setBackground(background);

  SpeedSearchUtil.applySpeedSearchHighlighting(tree, this, false, selected);
}