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

The following examples show how to use com.intellij.util.ui.UIUtil#isUnderAquaBasedLookAndFeel() . 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: TestTreeView.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void paintRowData(Tree tree, String duration, Rectangle bounds, Graphics2D g, boolean isSelected, boolean hasFocus) {
  final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
  g.setFont(tree.getFont().deriveFont(Font.PLAIN, UIUtil.getFontSize(UIUtil.FontSize.SMALL)));
  final FontMetrics metrics = tree.getFontMetrics(g.getFont());
  int totalWidth = metrics.stringWidth(duration) + 2;
  int x = bounds.x + bounds.width - totalWidth;
  g.setColor(isSelected ? UIUtil.getTreeSelectionBackground(hasFocus) : UIUtil.getTreeBackground());
  final int leftOffset = 5;
  g.fillRect(x - leftOffset, bounds.y, totalWidth + leftOffset, bounds.height);
  g.translate(0, bounds.y - 1);
  if (isSelected) {
    if (!hasFocus && UIUtil.isUnderAquaBasedLookAndFeel()) {
      g.setColor(UIUtil.getTreeForeground());
    }
    else {
      g.setColor(UIUtil.getTreeSelectionForeground());
    }
  }
  else {
    g.setColor(new JBColor(0x808080, 0x808080));
  }
  g.drawString(duration, x, SimpleColoredComponent.getTextBaseLine(tree.getFontMetrics(tree.getFont()), bounds.height) + 1);
  g.translate(0, -bounds.y + 1);
  config.restore();
}
 
Example 2
Source File: WideSelectionTreeUI.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void paint(Graphics g, JComponent c) {
  if (myWideSelection && !UIUtil.isUnderAquaBasedLookAndFeel() && !UIUtil.isUnderDarcula() && !UIUtil.isUnderIntelliJLaF()) {
    paintSelectedRows(g, ((JTree)c));
  }
  if (myWideSelection) {
    final int containerWidth = tree.getParent() instanceof JViewport ? tree.getParent().getWidth() : tree.getWidth();
    final int xOffset = tree.getParent() instanceof JViewport ? ((JViewport)tree.getParent()).getViewPosition().x : 0;
    final Rectangle bounds = g.getClipBounds();

    // draw background for the given clip bounds
    final Object sourceList = tree.getClientProperty(SOURCE_LIST_CLIENT_PROPERTY);
    if (sourceList != null && (Boolean)sourceList) {
      Graphics2D backgroundGraphics = (Graphics2D)g.create();
      backgroundGraphics.setClip(xOffset, bounds.y, containerWidth, bounds.height);
      LIST_BACKGROUND_PAINTER.paintBorder(tree, backgroundGraphics, xOffset, bounds.y, containerWidth, bounds.height);
      backgroundGraphics.dispose();
    }
  }

  super.paint(g, c);
}
 
Example 3
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 4
Source File: ProgressStripeIcon.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static AsyncProcessIcon generateIcon(@Nonnull JComponent component) {
  List<Icon> result = ContainerUtil.newArrayList();
  if (UIUtil.isUnderAquaBasedLookAndFeel() && !UIUtil.isUnderDarcula()) {
    for (int i = 0; i < 2 * JBUI.scale(GradientIcon.GRADIENT); i += JBUI.scale(TRANSLATE)) {
      result.add(new GradientIcon(component, i));
    }
  }
  else {
    for (int i = 0; i < JBUI.scale(StripeIcon.WIDTH); i += JBUI.scale(TRANSLATE)) {
      result.add(new StripeIcon(component, i));
    }
    result = ContainerUtil.reverse(result);
  }

  Icon passive = result.get(0);
  AsyncProcessIcon icon = new AsyncProcessIcon("ProgressWithStripes", result.toArray(new Icon[result.size()]), passive) {
    @Override
    public Dimension getPreferredSize() {
      return new Dimension(component.getWidth(), passive.getIconHeight());
    }
  };
  component.addComponentListener(new ComponentAdapter() {
    @Override
    public void componentResized(ComponentEvent e) {
      super.componentResized(e);
      icon.revalidate();
    }
  });
  return icon;
}
 
Example 5
Source File: InspectorTreeUI.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected void paintRow(final Graphics g,
                        final Rectangle clipBounds,
                        final Insets insets,
                        final Rectangle bounds,
                        final TreePath path,
                        final int row,
                        final boolean isExpanded,
                        final boolean hasBeenExpanded,
                        final boolean isLeaf) {
  final int containerWidth = tree.getParent() instanceof JViewport ? tree.getParent().getWidth() : tree.getWidth();
  final int xOffset = tree.getParent() instanceof JViewport ? ((JViewport)tree.getParent()).getViewPosition().x : 0;

  if (path != null && myWideSelection) {
    boolean selected = tree.isPathSelected(path);
    Graphics2D rowGraphics = (Graphics2D)g.create();
    rowGraphics.setClip(clipBounds);

    final Object sourceList = tree.getClientProperty(SOURCE_LIST_CLIENT_PROPERTY);
    Color background = tree.getBackground();

    if ((row % 2) == 0 && Boolean.TRUE.equals(tree.getClientProperty(STRIPED_CLIENT_PROPERTY))) {
      background = UIUtil.getDecoratedRowColor();
    }

    if (sourceList != null && (Boolean)sourceList) {
      if (selected) {
        if (tree.hasFocus()) {
          LIST_FOCUSED_SELECTION_BACKGROUND_PAINTER.paintBorder(tree, rowGraphics, xOffset, bounds.y, containerWidth, bounds.height);
        }
        else {
          LIST_SELECTION_BACKGROUND_PAINTER.paintBorder(tree, rowGraphics, xOffset, bounds.y, containerWidth, bounds.height);
        }
      }
      else if (myWideSelectionCondition.value(row)) {
        rowGraphics.setColor(background);
        rowGraphics.fillRect(xOffset, bounds.y, containerWidth, bounds.height);
      }
    }
    else {
      if (selected && (UIUtil.isUnderAquaBasedLookAndFeel() || UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF())) {
        Color bg = getSelectionBackground(tree, true);

        if (myWideSelectionCondition.value(row)) {
          rowGraphics.setColor(bg);
          rowGraphics.fillRect(xOffset, bounds.y, containerWidth, bounds.height);
        }
      }
    }

    if (shouldPaintExpandControl(path, row, isExpanded, hasBeenExpanded, isLeaf)) {
      paintExpandControl(rowGraphics, bounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf);
    }

    super.paintRow(rowGraphics, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf);
    rowGraphics.dispose();
  }
  else {
    super.paintRow(g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf);
  }
}
 
Example 6
Source File: InspectorColoredTreeCellRenderer.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public final Component getTreeCellRendererComponent(JTree tree,
                                                    Object value,
                                                    boolean selected,
                                                    boolean expanded,
                                                    boolean leaf,
                                                    int row,
                                                    boolean hasFocus) {
  myTree = tree;

  clear();

  myFocusedCalculated = false;

  // We paint background if and only if tree path is selected and tree has focus.
  // If path is selected and tree is not focused then we just paint focused border.
  if (UIUtil.isFullRowSelectionLAF()) {
    setBackground(selected ? UIUtil.getTreeSelectionBackground() : null);
  }
  else if (WideSelectionTreeUI.isWideSelection(tree)) {
    setPaintFocusBorder(false);
    if (selected) {
      setBackground(hasFocus ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeUnfocusedSelectionBackground());
    }
  }
  else if (selected) {
    setPaintFocusBorder(true);
    if (isFocused()) {
      setBackground(UIUtil.getTreeSelectionBackground());
    }
    else {
      setBackground(null);
    }
  }
  else {
    setBackground(null);
  }

  if (value instanceof LoadingNode) {
    setForeground(JBColor.GRAY);
  }
  else {
    setForeground(tree.getForeground());
    setIcon(null);
  }

  super.setOpaque(myOpaque || selected && hasFocus || selected && isFocused()); // draw selection background even for non-opaque tree


  if (tree.getUI() instanceof InspectorTreeUI && UIUtil.isUnderAquaBasedLookAndFeel()) {
    setMyBorder(null);
    setIpad(JBUI.insets(0, 2));
  }

  customizeCellRenderer(tree, value, selected, expanded, leaf, row, hasFocus);

  return this;
}
 
Example 7
Source File: InspectorTreeUI.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected void paintRow(final Graphics g,
                        final Rectangle clipBounds,
                        final Insets insets,
                        final Rectangle bounds,
                        final TreePath path,
                        final int row,
                        final boolean isExpanded,
                        final boolean hasBeenExpanded,
                        final boolean isLeaf) {
  final int containerWidth = tree.getParent() instanceof JViewport ? tree.getParent().getWidth() : tree.getWidth();
  final int xOffset = tree.getParent() instanceof JViewport ? ((JViewport)tree.getParent()).getViewPosition().x : 0;

  if (path != null && myWideSelection) {
    boolean selected = tree.isPathSelected(path);
    Graphics2D rowGraphics = (Graphics2D)g.create();
    rowGraphics.setClip(clipBounds);

    final Object sourceList = tree.getClientProperty(SOURCE_LIST_CLIENT_PROPERTY);
    Color background = tree.getBackground();

    if ((row % 2) == 0 && Boolean.TRUE.equals(tree.getClientProperty(STRIPED_CLIENT_PROPERTY))) {
      background = UIUtil.getDecoratedRowColor();
    }

    if (sourceList != null && (Boolean)sourceList) {
      if (selected) {
        if (tree.hasFocus()) {
          LIST_FOCUSED_SELECTION_BACKGROUND_PAINTER.paintBorder(tree, rowGraphics, xOffset, bounds.y, containerWidth, bounds.height);
        }
        else {
          LIST_SELECTION_BACKGROUND_PAINTER.paintBorder(tree, rowGraphics, xOffset, bounds.y, containerWidth, bounds.height);
        }
      }
      else if (myWideSelectionCondition.value(row)) {
        rowGraphics.setColor(background);
        rowGraphics.fillRect(xOffset, bounds.y, containerWidth, bounds.height);
      }
    }
    else {
      if (selected && (UIUtil.isUnderAquaBasedLookAndFeel() || UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF())) {
        Color bg = getSelectionBackground(tree, true);

        if (myWideSelectionCondition.value(row)) {
          rowGraphics.setColor(bg);
          rowGraphics.fillRect(xOffset, bounds.y, containerWidth, bounds.height);
        }
      }
    }

    if (shouldPaintExpandControl(path, row, isExpanded, hasBeenExpanded, isLeaf)) {
      paintExpandControl(rowGraphics, bounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf);
    }

    super.paintRow(rowGraphics, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf);
    rowGraphics.dispose();
  }
  else {
    super.paintRow(g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf);
  }
}
 
Example 8
Source File: InspectorColoredTreeCellRenderer.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public final Component getTreeCellRendererComponent(JTree tree,
                                                    Object value,
                                                    boolean selected,
                                                    boolean expanded,
                                                    boolean leaf,
                                                    int row,
                                                    boolean hasFocus) {
  myTree = tree;

  clear();

  myFocusedCalculated = false;

  // We paint background if and only if tree path is selected and tree has focus.
  // If path is selected and tree is not focused then we just paint focused border.
  if (UIUtil.isFullRowSelectionLAF()) {
    setBackground(selected ? UIUtil.getTreeSelectionBackground() : null);
  }
  else if (WideSelectionTreeUI.isWideSelection(tree)) {
    setPaintFocusBorder(false);
    if (selected) {
      setBackground(hasFocus ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeUnfocusedSelectionBackground());
    }
  }
  else if (selected) {
    setPaintFocusBorder(true);
    if (isFocused()) {
      setBackground(UIUtil.getTreeSelectionBackground());
    }
    else {
      setBackground(null);
    }
  }
  else {
    setBackground(null);
  }

  if (value instanceof LoadingNode) {
    setForeground(JBColor.GRAY);
  }
  else {
    setForeground(tree.getForeground());
    setIcon(null);
  }

  super.setOpaque(myOpaque || selected && hasFocus || selected && isFocused()); // draw selection background even for non-opaque tree


  if (tree.getUI() instanceof InspectorTreeUI && UIUtil.isUnderAquaBasedLookAndFeel()) {
    setMyBorder(null);
    setIpad(JBUI.insets(0, 2));
  }

  customizeCellRenderer(tree, value, selected, expanded, leaf, row, hasFocus);

  return this;
}
 
Example 9
Source File: ColoredTreeCellRenderer.java    From consulo with Apache License 2.0 4 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){
  myTree = tree;

  clear();

  mySelected = selected;
  myFocusedCalculated = false;

  // We paint background if and only if tree path is selected and tree has focus.
  // If path is selected and tree is not focused then we just paint focused border.
  if (UIUtil.isFullRowSelectionLAF()) {
    setBackground(selected ? UIUtil.getTreeSelectionBackground() : null);
  }
  else if (tree.getUI() instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)tree.getUI()).isWideSelection()) {
    setPaintFocusBorder(false);
    if (selected) {
      setBackground(hasFocus ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeUnfocusedSelectionBackground());
    }
  }
  else if (selected) {
    setPaintFocusBorder(true);
    if (isFocused()) {
      setBackground(UIUtil.getTreeSelectionBackground());
    }
    else {
      setBackground(null);
    }
  }
  else {
    setBackground(null);
  }

  if (value instanceof LoadingNode) {
    setForeground(JBColor.GRAY);
    setIcon(LOADING_NODE_ICON);
  }
  else {
    setForeground(tree.getForeground());
    setIcon(null);
  }

  if (UIUtil.isUnderGTKLookAndFeel()){
    super.setOpaque(false);  // avoid nasty background
    super.setIconOpaque(false);
  }
  else if (UIUtil.isUnderNimbusLookAndFeel() && selected && hasFocus) {
    super.setOpaque(false);  // avoid erasing Nimbus focus frame
    super.setIconOpaque(false);
  }
  else if (tree.getUI() instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)tree.getUI()).isWideSelection()) {
    super.setOpaque(false);  // avoid erasing Nimbus focus frame
    super.setIconOpaque(false);
  }
  else {
    super.setOpaque(myOpaque || selected && hasFocus || selected && isFocused()); // draw selection background even for non-opaque tree
  }

  if (tree.getUI() instanceof WideSelectionTreeUI && UIUtil.isUnderAquaBasedLookAndFeel()) {
    setMyBorder(null);
    setIpad(new Insets(0, 2,  0, 2));
  }

  customizeCellRenderer(tree, value, selected, expanded, leaf, row, hasFocus);

  return this;
}
 
Example 10
Source File: WideSelectionTreeUI.java    From consulo with Apache License 2.0 4 votes vote down vote up
private boolean shouldPaintLines() {
  if (UIUtil.isUnderAquaBasedLookAndFeel() || UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF()) {
    return false;
  }
  return myForceDontPaintLines || !"None".equals(tree.getClientProperty("JTree.lineStyle"));
}
 
Example 11
Source File: WideSelectionTreeUI.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected void paintRow(final Graphics g,
                        final Rectangle clipBounds,
                        final Insets insets,
                        final Rectangle bounds,
                        final TreePath path,
                        final int row,
                        final boolean isExpanded,
                        final boolean hasBeenExpanded,
                        final boolean isLeaf) {
  final int containerWidth = tree.getParent() instanceof JViewport ? tree.getParent().getWidth() : tree.getWidth();
  final int xOffset = tree.getParent() instanceof JViewport ? ((JViewport)tree.getParent()).getViewPosition().x : 0;

  if (path != null && myWideSelection) {
    boolean selected = tree.isPathSelected(path);
    Graphics2D rowGraphics = (Graphics2D)g.create();
    rowGraphics.setClip(clipBounds);

    final Object sourceList = tree.getClientProperty(SOURCE_LIST_CLIENT_PROPERTY);
    Color background = tree.getBackground();

    if ((row % 2) == 0 && Boolean.TRUE.equals(tree.getClientProperty(STRIPED_CLIENT_PROPERTY))) {
      background = UIUtil.getDecoratedRowColor();
    }

    if (sourceList != null && (Boolean)sourceList) {
      if (selected) {
        if (tree.hasFocus()) {
          LIST_FOCUSED_SELECTION_BACKGROUND_PAINTER.paintBorder(tree, rowGraphics, xOffset, bounds.y, containerWidth, bounds.height);
        }
        else {
          LIST_SELECTION_BACKGROUND_PAINTER.paintBorder(tree, rowGraphics, xOffset, bounds.y, containerWidth, bounds.height);
        }
      }
      else if (myWideSelectionCondition.value(row)) {
        rowGraphics.setColor(background);
        rowGraphics.fillRect(xOffset, bounds.y, containerWidth, bounds.height);
      }
    }
    else {
      if (selected && (UIUtil.isUnderAquaBasedLookAndFeel() || UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF())) {
        Color bg = getSelectionBackground(tree, true);

        if (myWideSelectionCondition.value(row)) {
          rowGraphics.setColor(bg);
          rowGraphics.fillRect(xOffset, bounds.y, containerWidth, bounds.height);
        }
      }
    }

    if (shouldPaintExpandControl(path, row, isExpanded, hasBeenExpanded, isLeaf)) {
      paintExpandControl(rowGraphics, bounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf);
    }

    super.paintRow(rowGraphics, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf);
    rowGraphics.dispose();
  }
  else {
    super.paintRow(g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf);
  }
}