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

The following examples show how to use com.intellij.util.ui.UIUtil#getListSelectionBackground() . 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: ShowUsagesTableCellRenderer.java    From dagger-intellij-plugin with Apache License 2.0 6 votes vote down vote up
private Color getBackgroundColor(boolean isSelected, Usage usage) {
  Color fileBgColor = null;
  if (isSelected) {
    fileBgColor = UIUtil.getListSelectionBackground();
  } else {
    VirtualFile virtualFile =
        usage instanceof UsageInFile ? ((UsageInFile) usage).getFile() : null;
    if (virtualFile != null) {
      Project project = myUsageView.getProject();
      PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
      if (psiFile != null && psiFile.isValid()) {
        final Color color = FileColorManager.getInstance(project).getRendererBackground(psiFile);
        if (color != null) fileBgColor = color;
      }
    }
  }
  return fileBgColor;
}
 
Example 2
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 3
Source File: ShowUsagesTableCellRenderer.java    From consulo with Apache License 2.0 6 votes vote down vote up
private Color getBackgroundColor(boolean isSelected, Usage usage) {
  Color fileBgColor = null;
  if (isSelected) {
    fileBgColor = UIUtil.getListSelectionBackground();
  }
  else {
    VirtualFile virtualFile = usage instanceof UsageInFile ? ((UsageInFile)usage).getFile() : null;
    if (virtualFile != null) {
      Project project = myUsageView.getProject();
      PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
      if (psiFile != null && psiFile.isValid()) {
        final Color color = FileColorManager.getInstance(project).getRendererBackground(psiFile);
        if (color != null) fileBgColor = color;
      }
    }
  }
  return fileBgColor;
}
 
Example 4
Source File: ShowUsagesTableCellRenderer.java    From otto-intellij-plugin with Apache License 2.0 6 votes vote down vote up
private Color getBackgroundColor(boolean isSelected, Usage usage) {
  Color fileBgColor = null;
  if (isSelected) {
    fileBgColor = UIUtil.getListSelectionBackground();
  }
  else {
    VirtualFile virtualFile = usage instanceof UsageInFile ? ((UsageInFile)usage).getFile() : null;
    if (virtualFile != null) {
      Project project = myUsageView.getProject();
      PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
      if (psiFile != null && psiFile.isValid()) {
        final Color color = FileColorManager.getInstance(project).getRendererBackground(psiFile);
        if (color != null) fileBgColor = color;
      }
    }
  }
  return fileBgColor;
}
 
Example 5
Source File: StringElementListCellRenderer.java    From android-strings-search-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList list, Object value, int index,
                                              boolean isSelected, boolean cellHasFocus) {
    removeAll();

    // Right
    DefaultListCellRenderer rightRenderer = new RightCellRenderer();
    Component rightComponent = rightRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    add(rightComponent, BorderLayout.EAST);

    // Space
    JPanel spacer = new JPanel();
    spacer.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2));
    add(spacer, BorderLayout.CENTER);

    // Left
    ListCellRenderer leftRenderer = new LeftCellRenderer(matcher);
    Component leftComponent = leftRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    add(leftComponent, BorderLayout.WEST);

    // Background color
    Color bg = isSelected ? UIUtil.getListSelectionBackground() : leftComponent.getBackground();
    setBackground(bg);
    rightComponent.setBackground(bg);
    spacer.setBackground(bg);

    return this;
}
 
Example 6
Source File: InspectionListCellRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
public InspectionListCellRenderer() {
  SELECTED = new SimpleTextAttributes(UIUtil.getListSelectionBackground(),
                                      UIUtil.getListSelectionForeground(),
                                      JBColor.RED,
                                      SimpleTextAttributes.STYLE_PLAIN);
  PLAIN = new SimpleTextAttributes(UIUtil.getListBackground(),
                                   UIUtil.getListForeground(),
                                   JBColor.RED,
                                   SimpleTextAttributes.STYLE_PLAIN);
}
 
Example 7
Source File: InspectionListCellRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean sel, boolean focus) {
  final JPanel panel = new JPanel(new BorderLayout());
  panel.setOpaque(true);

  final Color bg = sel ? UIUtil.getListSelectionBackground() : UIUtil.getListBackground();
  final Color fg = sel ? UIUtil.getListSelectionForeground() : UIUtil.getListForeground();
  panel.setBackground(bg);
  panel.setForeground(fg);

  SimpleTextAttributes attr = sel ? SELECTED : PLAIN;
  if (value instanceof InspectionToolWrapper) {
    final InspectionToolWrapper toolWrapper = (InspectionToolWrapper)value;
    final SimpleColoredComponent c = new SimpleColoredComponent();
    SpeedSearchUtil.appendColoredFragmentForMatcher("  " + toolWrapper.getDisplayName(), c, attr, myMatcher, bg, sel);
    panel.add(c, BorderLayout.WEST);

    final SimpleColoredComponent group = new SimpleColoredComponent();
    SpeedSearchUtil.appendColoredFragmentForMatcher(toolWrapper.getGroupDisplayName() + "  ", group, attr, myMatcher, bg, sel);
    final JPanel right = new JPanel(new BorderLayout());
    right.setBackground(bg);
    right.setForeground(fg);
    right.add(group, BorderLayout.CENTER);
    final JLabel icon = new JLabel(TargetAWT.to(getIcon(toolWrapper)));
    icon.setBackground(bg);
    icon.setForeground(fg);
    right.add(icon, BorderLayout.EAST);
    panel.add(right, BorderLayout.EAST);
  }
  else {
    // E.g. "..." item
    return super.getListCellRendererComponent(list, value, index, sel, focus);
  }

  return panel;
}
 
Example 8
Source File: ManagePackagesDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList list,
                                              Object value,
                                              int index,
                                              boolean isSelected,
                                              boolean cellHasFocus) {
  if (value instanceof RepoPackage) {
    RepoPackage repoPackage = (RepoPackage) value;
    String name = repoPackage.getName();
    if (myCurrentlyInstalling.contains(name)) {
      final String colorCode = UIUtil.isUnderDarcula() ? "589df6" : "0000FF";
      name = "<html><body>" + repoPackage.getName() + " <font color=\"#" + colorCode + "\">(installing)</font></body></html>";
    }
    myNameLabel.setText(name);
    myRepositoryLabel.setText(repoPackage.getRepoUrl());
    Component orig = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    final Color fg = orig.getForeground();
    myNameLabel.setForeground(myInstalledPackages.contains(name) ? JBColor.BLUE : fg);
  }
  myRepositoryLabel.setForeground(JBColor.GRAY);

  final Color bg;
  if (isSelected) {
    bg = UIUtil.getListSelectionBackground();
  }
  else {
    bg = index % 2 == 1 ? UIUtil.getListBackground() : UIUtil.getDecoratedRowColor();
  }
  myPanel.setBackground(bg);
  myNameLabel.setBackground(bg);
  myRepositoryLabel.setBackground(bg);
  return myPanel;
}
 
Example 9
Source File: PsiElementListCellRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
  removeAll();
  myRightComponentWidth = 0;
  DefaultListCellRenderer rightRenderer = getRightCellRenderer(value);
  Component rightCellRendererComponent = null;
  JPanel spacer = null;
  if (rightRenderer != null) {
    rightCellRendererComponent = rightRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    add(rightCellRendererComponent, BorderLayout.EAST);
    spacer = new JPanel();
    spacer.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2));
    add(spacer, BorderLayout.CENTER);
    myRightComponentWidth = rightCellRendererComponent.getPreferredSize().width;
    myRightComponentWidth += spacer.getPreferredSize().width;
  }

  ListCellRenderer leftRenderer = new LeftRenderer(null, value == null ? new ItemMatchers(null, null) : getItemMatchers(list, value));
  final Component leftCellRendererComponent = leftRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
  add(leftCellRendererComponent, LEFT);
  final Color bg = isSelected ? UIUtil.getListSelectionBackground(true) : leftCellRendererComponent.getBackground();
  setBackground(bg);
  if (rightCellRendererComponent != null) {
    rightCellRendererComponent.setBackground(bg);
  }
  if (spacer != null) {
    spacer.setBackground(bg);
  }
  return this;
}
 
Example 10
Source File: GroupedElementsRenderer.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected final Color getSelectionBackground() {
  return UIUtil.getListSelectionBackground();
}
 
Example 11
Source File: AbstractNavBarUI.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public Color getBackground(boolean selected, boolean focused) {
  return selected && focused ? UIUtil.getListSelectionBackground(true) : UIUtil.getListBackground();
}
 
Example 12
Source File: AbstractNavBarUI.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static BufferedImage drawToBuffer(NavBarItem item, JBUI.ScaleContext ctx, boolean floating, boolean toolbarVisible, boolean selected, NavBarPanel navbar) {
  int w = item.getWidth();
  int h = item.getHeight();
  int offset = (w - getDecorationOffset());
  int h2 = h / 2;

  BufferedImage result = UIUtil.createImage(ctx, w, h, BufferedImage.TYPE_INT_ARGB, PaintUtil.RoundingMode.FLOOR);

  Color defaultBg = UIUtil.isUnderDarcula() ? Gray._100 : JBColor.WHITE;
  final Paint bg = floating ? defaultBg : null;
  final Color selection = UIUtil.getListSelectionBackground(true);

  Graphics2D g2 = result.createGraphics();
  g2.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);


  Path2D.Double shape = new Path2D.Double();
  shape.moveTo(0, 0);

  shape.lineTo(offset, 0);
  shape.lineTo(w, h2);
  shape.lineTo(offset, h);
  shape.lineTo(0, h);
  shape.closePath();

  Path2D.Double endShape = new Path2D.Double();
  endShape.moveTo(offset, 0);
  endShape.lineTo(w, 0);
  endShape.lineTo(w, h);
  endShape.lineTo(offset, h);
  endShape.lineTo(w, h2);
  endShape.closePath();

  if (bg != null && toolbarVisible) {
    g2.setPaint(bg);
    g2.fill(shape);
    g2.fill(endShape);
  }

  if (selected) {
    Path2D.Double focusShape = new Path2D.Double();
    if (toolbarVisible || floating) {
      focusShape.moveTo(offset, 0);
    }
    else {
      focusShape.moveTo(0, 0);
      focusShape.lineTo(offset, 0);
    }
    focusShape.lineTo(w - 1, h2);
    focusShape.lineTo(offset, h - 1);
    if (!toolbarVisible && !floating) {
      focusShape.lineTo(0, h - 1);

    }

    g2.setColor(selection);
    if (floating && item.isLastElement()) {
      g2.fillRect(0, 0, w, h);
    }
    else {
      g2.fill(shape);
    }
  }

  if (item.isNextSelected() && navbar.isFocused()) {
    g2.setColor(selection);
    g2.fill(endShape);
  }

  if (!item.isLastElement()) {
    if (!selected && (!navbar.isFocused() | !item.isNextSelected())) {
      Icon icon = AllIcons.Ide.NavBarSeparator;
      icon.paintIcon(item, g2, w - icon.getIconWidth() - JBUIScale.scale(1), h2 - icon.getIconHeight() / 2);
    }
  }

  g2.dispose();
  return result;
}