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

The following examples show how to use com.intellij.util.ui.UIUtil#changeBackGround() . 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: ContentChooser.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
  setIcon(myListEntryIcon);
  if (myUseIdeaEditor) {
    int max = list.getModel().getSize();
    String indexString = String.valueOf(index + 1);
    int count = String.valueOf(max).length() - indexString.length();
    char[] spaces = new char[count];
    Arrays.fill(spaces, ' ');
    String prefix = indexString + new String(spaces) + "  ";
    append(prefix, SimpleTextAttributes.GRAYED_ATTRIBUTES);
  }
  else if (UIUtil.isUnderGTKLookAndFeel()) {
    // Fix GTK background
    Color background = selected ? UIUtil.getListSelectionBackground() : UIUtil.getListBackground();
    UIUtil.changeBackGround(this, background);
  }
  String text = ((Item)value).shortText;

  FontMetrics metrics = list.getFontMetrics(list.getFont());
  int charWidth = metrics.charWidth('m');
  int maxLength = list.getParent().getParent().getWidth() * 3 / charWidth / 2;
  text = StringUtil.first(text, maxLength, true); // do not paint long strings
  append(text, SimpleTextAttributes.REGULAR_ATTRIBUTES);
}
 
Example 2
Source File: IgnoredSettingsPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
  if (UIUtil.isUnderGTKLookAndFeel()) {
    final Color background = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
    UIUtil.changeBackGround(this, background);
  }

  IgnoredFileBean bean = (IgnoredFileBean)value;
  final String path = bean.getPath();
  if (path != null) {
    if (path.endsWith("/")) {
      append(VcsBundle.message("ignored.configure.item.directory", path), SimpleTextAttributes.REGULAR_ATTRIBUTES);
    }
    else {
      append(VcsBundle.message("ignored.configure.item.file", path), SimpleTextAttributes.REGULAR_ATTRIBUTES);
    }
  }
  else if (bean.getMask() != null) {
    append(VcsBundle.message("ignored.configure.item.mask", bean.getMask()), SimpleTextAttributes.REGULAR_ATTRIBUTES);
  }
}
 
Example 3
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 4
Source File: CheckboxTreeNoPolicy.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredUIAccess
public final Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
  invalidate();
  if (value instanceof CheckedTreeNode) {
    CheckedTreeNode node = (CheckedTreeNode)value;

    NodeState state = getNodeStatus(node);
    myCheckbox.setVisible(true);
    myCheckbox.setSelected(state != NodeState.CLEAR);
    myCheckbox.setEnabled(node.isEnabled() && state != NodeState.PARTIAL);
    myCheckbox.setOpaque(false);
    myCheckbox.setBackground(null);
    setBackground(null);
  }
  else {
    myCheckbox.setVisible(false);
  }
  myTextRenderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);

  if (UIUtil.isUnderGTKLookAndFeel()) {
    final Color background = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
    UIUtil.changeBackGround(this, background);
  }
  else if (UIUtil.isUnderNimbusLookAndFeel()) {
    UIUtil.changeBackGround(this, UIUtil.TRANSPARENT_COLOR);
  }
  customizeRenderer(tree, value, selected, expanded, leaf, row, hasFocus);
  revalidate();

  return this;
}
 
Example 5
Source File: XDebuggerFramesList.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void customizeCellRenderer(@Nonnull final JList list,
                                     final Object value,
                                     final int index,
                                     final boolean selected,
                                     final boolean hasFocus) {
  // Fix GTK background
  if (UIUtil.isUnderGTKLookAndFeel()){
    final Color background = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
    UIUtil.changeBackGround(this, background);
  }
  if (value == null) {
    append(XDebuggerBundle.message("stack.frame.loading.text"), SimpleTextAttributes.GRAY_ATTRIBUTES);
    return;
  }
  if (value instanceof String) {
    append((String)value, SimpleTextAttributes.ERROR_ATTRIBUTES);
    return;
  }

  XStackFrame stackFrame = (XStackFrame)value;
  if (!selected) {
    Color c = getFrameBgColor(stackFrame);
    if (c != null) {
      setBackground(c);
    }
  }
  stackFrame.customizePresentation(this);
}
 
Example 6
Source File: IntentionSettingsTree.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void initTree() {
  myTree = new CheckboxTree(new CheckboxTree.CheckboxTreeCellRenderer(true) {
    @Override
    public void customizeRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
      if (!(value instanceof CheckedTreeNode)) return;
      CheckedTreeNode node = (CheckedTreeNode)value;
      SimpleTextAttributes attributes = node.getUserObject() instanceof IntentionActionMetaData ? SimpleTextAttributes.REGULAR_ATTRIBUTES : SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES;
      final String text = getNodeText(node);
      final Color background = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
      UIUtil.changeBackGround(this, background);
      if (text != null) {
        SearchUtil.appendFragments(myFilter != null ? myFilter.getFilter() : null, text, attributes.getStyle(), attributes.getFgColor(), background, getTextRenderer());
      }
    }
  }, new CheckedTreeNode(null));

  myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(TreeSelectionEvent e) {
      TreePath path = e.getPath();
      Object userObject = ((DefaultMutableTreeNode)path.getLastPathComponent()).getUserObject();
      selectionChanged(userObject);
    }
  });

  myFilter = new MyFilterComponent();
  myComponent = new JPanel(new BorderLayout());
  JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree, true);
  myComponent.add(myFilter, BorderLayout.NORTH);
  myComponent.add(scrollPane, BorderLayout.CENTER);

  myFilter.reset();
}